adding library to toolchain

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
p0lyg0n1
Posts: 149
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: 149
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: 302
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: 149
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 13 times

Post Reply