BMP180 ZUNO_SETUP_CHANNELS

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
CaptainIgloo
Posts: 11
Joined: 02 Oct 2016 21:58

BMP180 ZUNO_SETUP_CHANNELS

Post by CaptainIgloo » 02 Oct 2016 22:10

Hi all
I would like to send an atmospheric pressure sensor BMP180 to my controller. Here is my code:

Code: Select all

#include <Wire.h>
#include <ZUNO_BMP180.h>
ZUNO_BMP180 bmp;

ZUNO_SETUP_CHANNELS(
    ZUNO_SENSOR_MULTILEVEL(
        ZUNO_SENSOR_MULTILEVEL_TYPE_BAROMETRIC_PRESSURE,
        SENSOR_MULTILEVEL_SCALE_KILO_PASCAL, // or 0 ?
        SENSOR_MULTILEVEL_SIZE_TWO_BYTES, // or 4 bytes ?
        2, // two decimals after dot
        getter
    )
);

word lastValue;

void setup() {
  Serial.begin();
  if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP180 sensor, check wiring!");
  }
}
  
void loop() {
    
    delay(1000);
    // Get Temperature
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
        
    // Get Pressure
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure()+800);
    Serial.println(" Pa");
    
    lastValue = (bmp.readPressure()+800);
    Serial.println(lastValue);
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");

  // you can get a more precise measurement of altitude
  // if you know the current sea level pressure which will
  // vary with weather and such. If it is 1015 millibars
  // that is equal to 101500 Pascals.
    Serial.print("Real altitude = ");
    Serial.print(bmp.readAltitude(99082));
    Serial.println(" meters");
  
    Serial.println();
    // send report to controller (Life Line group)
    zunoSendReport(1);
    delay(2000);
}
word getter() {
  return lastValue;
}
My console return this :
Temperature = 26.30 *C > check ok ;)
Pressure = 101912 Pa > check ok with 800 Pa of compensation. ;)
-29159 > Why ? What's variable type ? long ? :(
Altitude = 17.83 meters > check ok ;)
Real altitude = -171.42 meters > check ok

- Should I use 2 bytes or 4 bytes in my ZUNO_SETUP_CHANNELS ?
- Should I use 0 or Scale type ?

Someone can help me ?

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

Re: BMP180 ZUNO_SETUP_CHANNELS

Post by PoltoS » 02 Oct 2016 23:11

This is because lastValue is word (two bytes). 101912 do not fit inside!

101912 & 0xffff = 36376. Once you print it as signed, you get -(65535-36376) = -29159.

You need to use 4 bytes value (dword) instead for lastValue and for your channel.

Also in your report you send lastValue as is, so digits after dot should be 0. If you want 2, you need to multiply your value by 100 before sending.

CaptainIgloo
Posts: 11
Joined: 02 Oct 2016 21:58

Re: BMP180 ZUNO_SETUP_CHANNELS

Post by CaptainIgloo » 02 Oct 2016 23:22

Thanks ! @PoltoS

Post Reply