Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 6 months ago.
Struggling to get updates from this library
So I'm trying to get this library working on my Happy Gecko dev board (first ever cortex development). I used the MemLCD-Temperature-Humidity-Demo as an example. I get the first temperature reading over serial, but each reading after is exactly the same value. Only after you hit reset on the board you get a real up to date reading from the sensor.
I'm calling the rhtSensor.measure method and waiting for the callback until I call rhtSensor.get_temperature() but it's never different. Am I doing something stupid here?
#include "SILABS_RHT.h"
DigitalOut status(LED1); // Status LED 1
Serial serial(USBTX, USBRX); // Setup USB serial
// Setup sensor
I2C sensorI2C(PD6, PD7);
DigitalOut SENS_EN(PC8);
silabs::SILABS_RHT rhtSensor(&sensorI2C);
// Variables
volatile bool busChecked = false;
// Functions
void respondedCallback(void) {
busChecked = true;
}
int getTemp(void) {
status = 1; // Turn on status LED
busChecked = false;
rhtSensor.measure(si7021, respondedCallback);
while(busChecked == false) sleep();
while(rhtSensor.get_temperature() == 0);
status = 0; // Turn on status LED
return rhtSensor.get_temperature();
// return rhtSensor.get_humidity()
}
int main() {
SENS_EN = 1; // Enable sensor
wait(1);
rhtSensor.check_availability(si7021, respondedCallback);
while(busChecked == false) sleep();
while(1) {
serial.printf("%02d.%01d\n", getTemp() / 1000);
wait(3);
}
}