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
main.cpp@1:7008e7b00996, 2014-08-11 (annotated)
- Committer:
- mbn12
- Date:
- Mon Aug 11 13:50:16 2014 +0000
- Revision:
- 1:7008e7b00996
- Parent:
- 0:9ce639d07eeb
Updated version, working.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbn12 | 0:9ce639d07eeb | 1 | /* |
mbn12 | 0:9ce639d07eeb | 2 | |
mbn12 | 0:9ce639d07eeb | 3 | Program to read temperature and humidity over I2C |
mbn12 | 0:9ce639d07eeb | 4 | from the GE ChipCap2 sensor, using the MBED LPC11U24 board. |
mbn12 | 0:9ce639d07eeb | 5 | |
mbn12 | 0:9ce639d07eeb | 6 | Autor: Mario Baldini <mario@baldini.systems> |
mbn12 | 0:9ce639d07eeb | 7 | 2014/08 |
mbn12 | 0:9ce639d07eeb | 8 | |
mbn12 | 0:9ce639d07eeb | 9 | Reading the output (in linux): sudo screen /dev/ttyACM0 115200 |
mbn12 | 0:9ce639d07eeb | 10 | |
mbn12 | 0:9ce639d07eeb | 11 | |
mbn12 | 0:9ce639d07eeb | 12 | */ |
mbn12 | 0:9ce639d07eeb | 13 | |
mbn12 | 0:9ce639d07eeb | 14 | #include "mbed.h" |
mbn12 | 0:9ce639d07eeb | 15 | |
mbn12 | 0:9ce639d07eeb | 16 | Serial pc(USBTX, USBRX); |
mbn12 | 0:9ce639d07eeb | 17 | I2C i2c(p28,p27); //sda,scl |
mbn12 | 0:9ce639d07eeb | 18 | |
mbn12 | 0:9ce639d07eeb | 19 | |
mbn12 | 0:9ce639d07eeb | 20 | int main() { |
mbn12 | 1:7008e7b00996 | 21 | |
mbn12 | 0:9ce639d07eeb | 22 | pc.baud(115200); |
mbn12 | 0:9ce639d07eeb | 23 | |
mbn12 | 1:7008e7b00996 | 24 | i2c.frequency(400000); |
mbn12 | 1:7008e7b00996 | 25 | char wake_cmd[3]; |
mbn12 | 0:9ce639d07eeb | 26 | char data[4]; |
mbn12 | 1:7008e7b00996 | 27 | float humidity; |
mbn12 | 1:7008e7b00996 | 28 | float temperatureC; |
mbn12 | 1:7008e7b00996 | 29 | const int addr = 0x28 << 1; |
mbn12 | 0:9ce639d07eeb | 30 | |
mbn12 | 0:9ce639d07eeb | 31 | while(true) { |
mbn12 | 1:7008e7b00996 | 32 | |
mbn12 | 0:9ce639d07eeb | 33 | data[0] = 0x00; |
mbn12 | 0:9ce639d07eeb | 34 | data[1] = 0x00; |
mbn12 | 0:9ce639d07eeb | 35 | data[2] = 0x00; |
mbn12 | 0:9ce639d07eeb | 36 | data[3] = 0x00; |
mbn12 | 1:7008e7b00996 | 37 | |
mbn12 | 1:7008e7b00996 | 38 | wake_cmd[0] = 0xA0; |
mbn12 | 1:7008e7b00996 | 39 | wake_cmd[1] = 0x00; |
mbn12 | 1:7008e7b00996 | 40 | wake_cmd[1] = 0x00; |
mbn12 | 1:7008e7b00996 | 41 | i2c.write(addr, wake_cmd, 3); |
mbn12 | 0:9ce639d07eeb | 42 | |
mbn12 | 0:9ce639d07eeb | 43 | wait_ms(50); |
mbn12 | 0:9ce639d07eeb | 44 | |
mbn12 | 0:9ce639d07eeb | 45 | |
mbn12 | 1:7008e7b00996 | 46 | i2c.read(addr, data, 4); |
mbn12 | 1:7008e7b00996 | 47 | |
mbn12 | 1:7008e7b00996 | 48 | pc.printf("Raw Data[]\t 0x%X 0x%X 0x%X 0x%X \r\n", data[0],data[1],data[2],data[3]); |
mbn12 | 0:9ce639d07eeb | 49 | |
mbn12 | 1:7008e7b00996 | 50 | humidity = (((data[0] & 63) << 8) + data[1]) / 163.84; |
mbn12 | 1:7008e7b00996 | 51 | temperatureC = (((data[2] << 6) + (data[3] / 4)) / 99.29) - 40; |
mbn12 | 1:7008e7b00996 | 52 | pc.printf("Humidity: %.2f \t Temperature (C): %.2f \r\n\n", humidity, temperatureC); |
mbn12 | 1:7008e7b00996 | 53 | |
mbn12 | 1:7008e7b00996 | 54 | wait_ms(1000); |
mbn12 | 0:9ce639d07eeb | 55 | } |
mbn12 | 0:9ce639d07eeb | 56 | } |