Program to read temperature and humidity over I2C from the GE ChipCap2 sensor, using the MBED LPC11U24 board. !!! NOT WORKING !!! This reference program for Arduino DO work: http://hastebin.com/tilolukave.go If you locate the error please let me know at mario@baldini.systems
Diff: main.cpp
- Revision:
- 1:7008e7b00996
- Parent:
- 0:9ce639d07eeb
--- a/main.cpp Fri Aug 08 01:03:08 2014 +0000 +++ b/main.cpp Mon Aug 11 13:50:16 2014 +0000 @@ -6,12 +6,6 @@ Autor: Mario Baldini <mario@baldini.systems> 2014/08 -!!! NOT WORKING !!! -This reference program for Arduino DO work: http://hastebin.com/tilolukave.go - -If you locate the error in this mbed version, -please e-mail me at mario@baldini.systems - Reading the output (in linux): sudo screen /dev/ttyACM0 115200 @@ -24,80 +18,39 @@ int main() { + pc.baud(115200); - pc.printf("begin\r\n"); - int address = 0x28; + i2c.frequency(400000); + char wake_cmd[3]; char data[4]; - data[0] = 0x00; - data[1] = 0x00; - data[2] = 0x00; - data[3] = 0x00; - - char data_write[3]; - data_write[0] = 0xA0; - data_write[1] = 0x00; - data_write[2] = 0x00; - - - i2c.frequency(400000); - + float humidity; + float temperatureC; + const int addr = 0x28 << 1; while(true) { - pc.printf("loop()\r\n"); + data[0] = 0x00; data[1] = 0x00; data[2] = 0x00; data[3] = 0x00; + + wake_cmd[0] = 0xA0; + wake_cmd[1] = 0x00; + wake_cmd[1] = 0x00; + i2c.write(addr, wake_cmd, 3); - - // TRY 1 - i2c.start(); - i2c.write(address, data_write, 3); - wait_ms(50); - i2c.stop(); - - i2c.start(); - i2c.read(address, data, 4); - i2c.stop(); - - pc.printf("Ver.1 Data[]\t 0x%X 0x%X 0x%X 0x%X \r\n\n", data[0],data[1],data[2],data[3]); - - - - - // TRY 2 - i2c.start(); - i2c.write(0xA0); - i2c.write(0x00); - i2c.write(0x00); - i2c.stop(); - wait_ms(50); - - i2c.start(); - i2c.read(address, data, 4); - i2c.stop(); - pc.printf("Ver.2 Data[]\t 0x%X 0x%X 0x%X 0x%X \r\n\n", data[0],data[1],data[2],data[3]); - - - - // TRY 3 - i2c.write(address, data_write, 3); - i2c.write(0xA0); - i2c.write(0x00); - i2c.write(0x00); wait_ms(50); - i2c.read(address, data, 4); - data[0] = i2c.read(0x01); - data[1] = i2c.read(0x01); - data[2] = i2c.read(0x00); - data[3] = i2c.read(0x00); - pc.printf("Ver.3 Data[]\t 0x%X 0x%X 0x%X 0x%X \r\n\n", data[0],data[1],data[2],data[3]); + i2c.read(addr, data, 4); + + pc.printf("Raw Data[]\t 0x%X 0x%X 0x%X 0x%X \r\n", data[0],data[1],data[2],data[3]); - - - wait_ms(2000); + humidity = (((data[0] & 63) << 8) + data[1]) / 163.84; + temperatureC = (((data[2] << 6) + (data[3] / 4)) / 99.29) - 40; + pc.printf("Humidity: %.2f \t Temperature (C): %.2f \r\n\n", humidity, temperatureC); + + wait_ms(1000); } }