![](/media/cache/profiles/17a98ed636b0294602e63e75d11339a2.jpg.50x50_q85.jpg)
a test program to read temperature from TI TMP102 sensor, and then display on OLED screen.
Dependencies: TMP102 eeprom mbed oled_i2c
main.cpp@0:1b2565997ba9, 2018-06-19 (annotated)
- Committer:
- poushen
- Date:
- Tue Jun 19 06:06:05 2018 +0000
- Revision:
- 0:1b2565997ba9
- Child:
- 1:8e6b9978a4d0
add code test oled and tmp102
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
poushen | 0:1b2565997ba9 | 1 | #include "mbed.h" |
poushen | 0:1b2565997ba9 | 2 | #include "oled_i2c.h" |
poushen | 0:1b2565997ba9 | 3 | #include "oled_font.h" |
poushen | 0:1b2565997ba9 | 4 | #include "test_TMP102.h" |
poushen | 0:1b2565997ba9 | 5 | |
poushen | 0:1b2565997ba9 | 6 | DigitalOut myled(LED2); |
poushen | 0:1b2565997ba9 | 7 | |
poushen | 0:1b2565997ba9 | 8 | // for LPCXpresso LPC1114 board |
poushen | 0:1b2565997ba9 | 9 | // UART TX: xp9, dp16 |
poushen | 0:1b2565997ba9 | 10 | // UART RX: xp10, dp15 |
poushen | 0:1b2565997ba9 | 11 | // ************************************* |
poushen | 0:1b2565997ba9 | 12 | // ** serial port: 9600, 8, N, 1, N |
poushen | 0:1b2565997ba9 | 13 | // ************************************* |
poushen | 0:1b2565997ba9 | 14 | //Serial pc(xp9, xp10); |
poushen | 0:1b2565997ba9 | 15 | I2C i2c(dp5, dp27); |
poushen | 0:1b2565997ba9 | 16 | oled_i2c oled(i2c); |
poushen | 0:1b2565997ba9 | 17 | test_TMP102 temp1(i2c); |
poushen | 0:1b2565997ba9 | 18 | |
poushen | 0:1b2565997ba9 | 19 | int main() { |
poushen | 0:1b2565997ba9 | 20 | myled = 1; |
poushen | 0:1b2565997ba9 | 21 | printf("LPC1114 demo \r\n"); |
poushen | 0:1b2565997ba9 | 22 | i2c.frequency(1000 * 1000); |
poushen | 0:1b2565997ba9 | 23 | |
poushen | 0:1b2565997ba9 | 24 | // ------------ tmp102 -------------- |
poushen | 0:1b2565997ba9 | 25 | temp1.setExtendedMode(1); |
poushen | 0:1b2565997ba9 | 26 | temp1.setConversionRate(2); |
poushen | 0:1b2565997ba9 | 27 | temp1.sleep(); |
poushen | 0:1b2565997ba9 | 28 | |
poushen | 0:1b2565997ba9 | 29 | // ------------ oled ---------------- |
poushen | 0:1b2565997ba9 | 30 | oled.init_oled(); |
poushen | 0:1b2565997ba9 | 31 | //oled.fillScr(); |
poushen | 0:1b2565997ba9 | 32 | |
poushen | 0:1b2565997ba9 | 33 | while(1) |
poushen | 0:1b2565997ba9 | 34 | { |
poushen | 0:1b2565997ba9 | 35 | myled = 1; |
poushen | 0:1b2565997ba9 | 36 | |
poushen | 0:1b2565997ba9 | 37 | temp1.oneShot(); |
poushen | 0:1b2565997ba9 | 38 | float t1 = temp1; |
poushen | 0:1b2565997ba9 | 39 | |
poushen | 0:1b2565997ba9 | 40 | //oled.clrScr(); |
poushen | 0:1b2565997ba9 | 41 | oled.setFont(BigNumbers); |
poushen | 0:1b2565997ba9 | 42 | //oled.print("27", 20, 10); |
poushen | 0:1b2565997ba9 | 43 | //oled.printNumI(27, 0, 0); |
poushen | 0:1b2565997ba9 | 44 | oled.printNumF(t1, 2, 0, 0); |
poushen | 0:1b2565997ba9 | 45 | oled.setFont(SmallFont); |
poushen | 0:1b2565997ba9 | 46 | oled.print("~c", 60, 30); |
poushen | 0:1b2565997ba9 | 47 | oled.update(); |
poushen | 0:1b2565997ba9 | 48 | myled = 0; |
poushen | 0:1b2565997ba9 | 49 | wait(0.5); |
poushen | 0:1b2565997ba9 | 50 | } |
poushen | 0:1b2565997ba9 | 51 | } |