We started 2022 with a project that has been in the works for a while. This project is centered around the third goal of the United Nations' Sustainable Development Goals, "Ensure healthy lives and promote well-being for all at all ages". Taking someone's temperature may warrant an action at that moment, but collecting temperature readings will give a better picture to epidemiologist and public health decision makers.
We bought a Smart Mobile Phone Thermometer because it was cheaper than buying a sensor by itself. The Thermometer has a USB connector for power only, so readings need to be captured some other way.
If that USB Type-C transmitted data to the phone our project would have been a lot shorter. Spoiler alert: we will have to hack the Thermometer. This may sound similar to “The AVR-IoT WG: Out for Blood Pressure Monitoring in Google” project winner of Smart Medical Design Challenge, where we tapped into UART of a cheap Blood Pressure Monitor and sent the readings to Google Sheets via Google Cloud Platform and Firebase. However, we don't have the luxury of UART in the Thermometer, and we'll bypass Google Cloud Platform and Firebase for simplicity.
The U2 Integrated Circuit (IC) on the right is TM1650 which is a 7-segment display driver i.e. we tell it a number from 0 - 9 in couple of lines and based on that it will light up LEDs.
The couple of lines here called Inter-Integrated Circuit (I2C). The pinout is one of very few things we could gather from the datasheet because there is no English copy. There is also a repository to work with TM1650, but it is for writing to the IC, not reading from it.
Found good information at the resources mentioned above, but we need to intercept I2C traffic between the two chips. We started with Arduino Uno to find out I2C addresses using I2C Scanner sketch.
The tricky part is we can’t make Arduino Uno pretend to be multiple addresses (actually four: 0x34, 0x35, 0x36, and 0x37) at the same time. We said pretend here because we can write data to the addresses, but we can't read what we just wrote.
The Logic Analyzer helped bringing pieces of information together. Every time the Thermometer takes a reading, it beeps and then sends the following on I2C lines.
If we zoom into one of the parts we will see that information is transmitted as address followed by data to be displayed in that address in this exact sequence:
0x36 data 0x35 data 0x34 data 0x37data 0x35 data 0x34 data
0x36 data 0x35 data 0x34 data 0x37data 0x35 data 0x34 data
The two parts might look identical, but we found that the second part is a more accurate representation of the numbers displayed on LED. To be more specific, we are interested in data following 0x36, 0x35, and 0x34 addresses.
The 7-segment display shows temperature like so:
0x34 0x35. 0x36
We only need to find the data value of the last time those addresses received values. For example, this is how 97.3 is transmitted:
01101100 //0x36
0001000000
00110101 //0x35
00001000000
00110100 //0x34
00001000000
00110111 //0x37
00000000000
00110101 //0x35
00101000000
00110100 //0x34
000010000000
01101100 //0x36
01
0101111 //3
0
00110101 //0x35
000
0001110 //7
0
00110100 //0x34
000
0111111 //9
0
00110111 //0x37
00000000000
00110101 //0x35
001
0001110 //7
0
00110100 //0x34
000
0111111 //9
00
Take a look at the line before last where we represented 9 as 0111111. One out of the seven LED to display number 9 is off and all others are on.
More details on why digits have those 0/1 combinations are included in the code.
We used PlatformIO to build this project, but Arduino IDE could be used as well. The only library used here is WiFiManager to make the project portable and avoid hardcoding Wi-Fi credentials,
Back to Arduino Uno, we need to read the data at 19 clock pulses for each of the 6 address/data blocks twice. Wired SCL to an interrupt pin in Arduino Uno and started reading the data at SDA with port manipulation since digitalRead is too slow for I2C in that board.
WeMos D1 Mini has faster digitalRead, but we still had to use interrupt for the clock. WeMos D1 Mini posts to a URL of Google Apps Script and that in turn will append Thermometer readings to Google Sheets. Each record will contain three values: Temperature, chip id, and timestamp.
A little bit of hot glue at the top and we'll be done.
Comments