a test program to read temperature from TI TMP102 sensor, and then display on OLED screen.

Dependencies:   TMP102 eeprom mbed oled_i2c

Committer:
poushen
Date:
Fri Jun 29 22:03:18 2018 +0000
Revision:
1:8e6b9978a4d0
Parent:
0:1b2565997ba9
add remark for i2c pin of different mcu

Who changed what in which revision?

UserRevisionLine numberNew 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 1:8e6b9978a4d0 15 I2C i2c(dp5, dp27); // NXP LPC1114
poushen 1:8e6b9978a4d0 16 //I2C i2c(I2C_SDA, I2C_SCL); // ST F401
poushen 1:8e6b9978a4d0 17 //I2C i2c(PA_10, PA_9); // ST L031
poushen 0:1b2565997ba9 18 oled_i2c oled(i2c);
poushen 0:1b2565997ba9 19 test_TMP102 temp1(i2c);
poushen 0:1b2565997ba9 20
poushen 0:1b2565997ba9 21 int main() {
poushen 0:1b2565997ba9 22 myled = 1;
poushen 0:1b2565997ba9 23 printf("LPC1114 demo \r\n");
poushen 0:1b2565997ba9 24 i2c.frequency(1000 * 1000);
poushen 0:1b2565997ba9 25
poushen 0:1b2565997ba9 26 // ------------ tmp102 --------------
poushen 0:1b2565997ba9 27 temp1.setExtendedMode(1);
poushen 0:1b2565997ba9 28 temp1.setConversionRate(2);
poushen 0:1b2565997ba9 29 temp1.sleep();
poushen 0:1b2565997ba9 30
poushen 0:1b2565997ba9 31 // ------------ oled ----------------
poushen 0:1b2565997ba9 32 oled.init_oled();
poushen 0:1b2565997ba9 33 //oled.fillScr();
poushen 0:1b2565997ba9 34
poushen 0:1b2565997ba9 35 while(1)
poushen 0:1b2565997ba9 36 {
poushen 0:1b2565997ba9 37 myled = 1;
poushen 0:1b2565997ba9 38
poushen 0:1b2565997ba9 39 temp1.oneShot();
poushen 0:1b2565997ba9 40 float t1 = temp1;
poushen 0:1b2565997ba9 41
poushen 0:1b2565997ba9 42 //oled.clrScr();
poushen 0:1b2565997ba9 43 oled.setFont(BigNumbers);
poushen 0:1b2565997ba9 44 //oled.print("27", 20, 10);
poushen 0:1b2565997ba9 45 //oled.printNumI(27, 0, 0);
poushen 0:1b2565997ba9 46 oled.printNumF(t1, 2, 0, 0);
poushen 0:1b2565997ba9 47 oled.setFont(SmallFont);
poushen 0:1b2565997ba9 48 oled.print("~c", 60, 30);
poushen 0:1b2565997ba9 49 oled.update();
poushen 0:1b2565997ba9 50 myled = 0;
poushen 0:1b2565997ba9 51 wait(0.5);
poushen 0:1b2565997ba9 52 }
poushen 0:1b2565997ba9 53 }