adding library to toolchain

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
p0lyg0n1
Posts: 160
Joined: 04 Aug 2016 07:14

Re: adding library to toolchain

Post by p0lyg0n1 » 19 Oct 2016 16:59

First of all:
- don't pass parameters by reference, use pointers instead. uCxx doesn't support references yet.
- don't use "double". It's not an error cause SDCC will automatically replace it with "float", but you have to know. i8051 too small to deal with 64bit float point values.

Please use fix-point match if you can. Just look in BM180 lib. I rewrite it significantly to reduce amount of code. Use long instead of float for math.

For example:

optimal variant of readUInt will be:

Code: Select all

char BMP280::readUInt(char address, word * value)
{
	byte data[2];
	data[0] = address;
	if (readBytes(data,2))
	{
		*value = (((word)data[1]) << 8) + data[0];
		return 1;
	}
	*value = 0;
	return 0;
}
Then you can go deeper =) Use the same strategy for another functions.

p0lyg0n1
Posts: 160
Joined: 04 Aug 2016 07:14

Re: adding library to toolchain

Post by p0lyg0n1 » 19 Oct 2016 21:19

I found datasheet for BMP280 which contains fix-math code for it. http://ru.mouser.com/ds/2/621/BST-BMP28 ... 371189.pdf I think it will be helpful for you.
See section 8.2 Compensation formula in 32 bit fixed point. This code uses types BMP280_S32_t and BMP280_U32_t. In our case it will be long and unsigned long.

michap
Posts: 321
Joined: 26 Mar 2013 10:35
Contact:

Re: adding library to toolchain

Post by michap » 30 Nov 2016 22:26

@ftrueck - any progress with BMP280? ;)
Maybe lib is ready?

Michael

p0lyg0n1
Posts: 160
Joined: 04 Aug 2016 07:14

Re: adding library to toolchain

Post by p0lyg0n1 » 16 Jun 2018 17:57

Finally I have a little time to port the library. I completely reworked code from Bosh & Ada Fruit. I hope It have to be the most compact one... ;) The library attached to this message. I tried it with BME280 & BMP280. It works ok with my devices. If anyone could try it I'll be glad )
The example:

Code: Select all

#include <ZUNO_BMP280.h>

ZUNO_BMP280 bmp280;

#define MY_SERIAL Serial

void setup() {
    
    MY_SERIAL.begin(115200);
    if(!bmp280.begin()){
        MY_SERIAL.println("Can't detect a sensor!");
    }
    
}
void loop() {
    
    MY_SERIAL.print("Temperature:");
    MY_SERIAL.fixPrint(bmp280.readTemperatureC100(), 2);
    MY_SERIAL.println(" *C");
    
    MY_SERIAL.print("Pressure:");
    MY_SERIAL.fixPrint(bmp280.readPressureHgMM10(), 1);
    MY_SERIAL.println(" HgMM");

    MY_SERIAL.print("Humidity:");
    MY_SERIAL.fixPrint(bmp280.readHumidityH10(), 1);
    MY_SERIAL.println(" %");

    delay(5000);
    
}
Attachments
ZUNO_BMP280.zip
(4.64 KiB) Downloaded 41 times

Miklux
Posts: 2
Joined: 01 Oct 2018 17:02

Re: adding library to toolchain

Post by Miklux » 22 Oct 2018 18:41

Hi all,
I have a similar problem compiling my sketch.
I'm trying to read temperature values from AMG8833 via I2C using the SparkFun_GridEYE_Arduino_Library.h (it working fine!).

If I try to use this library with Z-Uno something goes wrong and I receive this error (verbose mode):

Code: Select all


C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\Michele\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\Michele\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\Michele\Documents\Arduino\libraries -fqbn=Z-Uno:zw8051:zuno:Frequency=Eu,Security=Off,MuliCommand=Off,LogOutput=Off,NVMClean=Off -vid-pid=0X0658_0X0200 -ide-version=10807 -build-path C:\Users\Michele\AppData\Local\Temp\arduino_build_931779 -warnings=none -build-cache C:\Users\Michele\AppData\Local\Temp\arduino_cache_616339 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.zuno_toolchain.path=C:\Users\Michele\Documents\ArduinoData\packages\Z-Uno\tools\zuno_toolchain\00.08.70 -prefs=runtime.tools.zuno_toolchain-00.08.70.path=C:\Users\Michele\Documents\ArduinoData\packages\Z-Uno\tools\zuno_toolchain\00.08.70 -verbose C:\Users\Michele\Documents\Arduino\test_AMG8833_ZWAVE\test_AMG8833_ZWAVE.ino
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\arduino-builder -compile -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\Michele\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\Michele\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\Michele\Documents\Arduino\libraries -fqbn=Z-Uno:zw8051:zuno:Frequency=Eu,Security=Off,MuliCommand=Off,LogOutput=Off,NVMClean=Off -vid-pid=0X0658_0X0200 -ide-version=10807 -build-path C:\Users\Michele\AppData\Local\Temp\arduino_build_931779 -warnings=none -build-cache C:\Users\Michele\AppData\Local\Temp\arduino_cache_616339 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.zuno_toolchain.path=C:\Users\Michele\Documents\ArduinoData\packages\Z-Uno\tools\zuno_toolchain\00.08.70 -prefs=runtime.tools.zuno_toolchain-00.08.70.path=C:\Users\Michele\Documents\ArduinoData\packages\Z-Uno\tools\zuno_toolchain\00.08.70 -verbose C:\Users\Michele\Documents\Arduino\test_AMG8833_ZWAVE\test_AMG8833_ZWAVE.ino
Using board 'zuno' from platform in folder: C:\Users\Michele\Documents\ArduinoData\packages\Z-Uno\hardware\zw8051\2.1.4
Using core 'zuno' from platform in folder: C:\Users\Michele\Documents\ArduinoData\packages\Z-Uno\hardware\zw8051\2.1.4
Detecting libraries used...
"C:\\Users\\Michele\\Documents\\ArduinoData\\packages\\Z-Uno\\tools\\zuno_toolchain\\00.08.70/zuno_toolchain/compiler" arduino_preproc "C:\\Users\\Michele\\AppData\\Local\\Temp\\arduino_build_931779\\sketch\\test_AMG8833_ZWAVE.ino.cpp" -r "C:\\Users\\Michele\\Documents\\ArduinoData\\packages\\Z-Uno\\hardware\\zw8051\\2.1.4"
C:\Users\Michele\AppData\Local\Temp\arduino_build_931779

Found 1.8.x project structure (File:test_AMG8833_ZWAVE.ino.cpp). Converting it...

Error while detecting libraries included by C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\sketch\test_AMG8833_ZWAVE.ino.cpp
Generating function prototypes...
"C:\\Users\\Michele\\Documents\\ArduinoData\\packages\\Z-Uno\\tools\\zuno_toolchain\\00.08.70/zuno_toolchain/compiler" arduino_preproc "C:\\Users\\Michele\\AppData\\Local\\Temp\\arduino_build_931779\\sketch\\test_AMG8833_ZWAVE.ino.cpp" -r "C:\\Users\\Michele\\Documents\\ArduinoData\\packages\\Z-Uno\\hardware\\zw8051\\2.1.4"
C:\Users\Michele\AppData\Local\Temp\arduino_build_931779

Found 1.8.x project structure (File:test_AMG8833_ZWAVE.ino.cpp). Converting it...       

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\Michele\\AppData\\Local\\Temp\\arduino_build_931779\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Sto compilando lo sketch...
"C:\\Users\\Michele\\Documents\\ArduinoData\\packages\\Z-Uno\\tools\\zuno_toolchain\\00.08.70/zuno_toolchain/compiler" build "C:\\Users\\Michele\\AppData\\Local\\Temp\\arduino_build_931779/test_AMG8833_ZWAVE.ino" -r "C:\\Users\\Michele\\Documents\\ArduinoData\\packages\\Z-Uno\\hardware\\zw8051\\2.1.4" -i1_8 -idv 10807

	************* Building Arduino Sketch *************

	C:\Users\Michele\AppData\Local\Temp\arduino_build_931779/test_AMG8833_ZWAVE.ino

	***************************************************

	 --- USING a list of libraries from:

		C:\Users\Michele\Documents\ArduinoData\packages\Z-Uno\hardware\zw8051\2.1.4\libraries

		C:\Users\Michele\Documents\Arduino\libraries

	*** Collecting prototypes...

Preprocessing file: C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\Custom.c with SDCPP... 



Preprocessing file: C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\Print.cpp with SDCPP... 

Compiling C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\Print_sdcpp_.cpp ...

Preprocessing file: C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\Stream.cpp with SDCPP... 

Compiling C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\Stream_sdcpp_.cpp ...

Preprocessing file: C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\HardwareSerial.cpp with SDCPP... 

Compiling C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\HardwareSerial_sdcpp_.cpp ...

Preprocessing file: C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\HLCore.cpp with SDCPP... 

Compiling C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\HLCore_sdcpp_.cpp ...

Preprocessing file: C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\Wire.cpp with SDCPP... 

Compiling C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\Wire_sdcpp_.cpp ...

Preprocessing file: C:\Users\Michele\AppData\Local\Temp\arduino_build_931779\test_AMG8833_ZWAVE.cpp with SDCPP... 

compilation terminated.

Preprocessor failed!uCxx returned error code:1

exit status 1
processing.app.debug.RunnerException
	at cc.arduino.Compiler.lambda$callArduinoBuilder$3(Compiler.java:309)
	at processing.app.debug.MessageSiphon.run(MessageSiphon.java:96)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
	at cc.arduino.Compiler.message(Compiler.java:525)
	at cc.arduino.i18n.I18NAwareMessageConsumer.message(I18NAwareMessageConsumer.java:80)
	at cc.arduino.MessageConsumerOutputStream.flush(MessageConsumerOutputStream.java:71)
	at cc.arduino.MessageConsumerOutputStream.write(MessageConsumerOutputStream.java:54)
	at java.io.OutputStream.write(OutputStream.java:75)
	at cc.arduino.Compiler.lambda$callArduinoBuilder$3(Compiler.java:307)
	... 2 more
I'm Sure my code or my environment are wrong but I'm not very experienced in Arduino programming and I need some help...

This is the code I want to compile:

Code: Select all

#include <Wire.h>
#include <SparkFun_GridEYE_Arduino_Library.h>

word hotPixelValue;
word hotPixelIndex;

// set up channel
ZUNO_SETUP_CHANNELS(
      ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE,
                             SENSOR_MULTILEVEL_SCALE_CELSIUS,  
                             SENSOR_MULTILEVEL_SIZE_TWO_BYTES, 
                             SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, 
                             getterHotPixel)
);


void setup() {
  // Start your preferred I2C object 
  Wire.begin();
  // Library assumes "Wire" for I2C but you can pass something else with begin() if you like
  grideye.begin();
  // Pour a bowl of serial
  Serial.begin(115200);
}

void loop() {
  // variables to store temperature values
  testPixelValue = 0;
  hotPixelValue = 0;
  hotPixelIndex = 0;

  // for each of the 64 pixels, record the temperature and compare it to the 
  // hottest pixel that we've tested. If it's hotter, that becomes the new
  // king of the hill and its index is recorded. At the end of the loop, we 
  // should have the index and temperature of the hottest pixel in the frame
  for(unsigned char i = 0; i < 64; i++){
    testPixelValue = grideye.getPixelTemperature(i);
      if(testPixelValue > hotPixelValue){
        hotPixelValue = testPixelValue;
        hotPixelIndex = i;
      }
  }

  zunoSendReport(1); 
  Serial.println(hotPixelValue);
  Serial.println(hotPixelIndex);
  // send every 30 sec
  delay(10);
}

word getterHotPixel() {
  return hotPixelValue;
}
Where is(are) the error(s) ?! :?:
Could you help me please?

User avatar
PoltoS
Posts: 4334
Joined: 26 Jan 2011 19:36

Re: adding library to toolchain

Post by PoltoS » 28 Oct 2018 13:12

Put you library in the same folder as the .ino or in the lib folder

Post Reply