Arduino: Simple LCD Thermometer with USB interface
Attention: this page is work in progress.
My motivation for "Simple LCD Thermometer with USB interface" is my server room. It is important to keep temperature and humidity in correct range. I am using automatic monitoring to be sure that everything is in "green" state. Previously I was using Conrad TFD 128 logger. It is good product but it have several design problems. To fulfill my needs I created my own device.
Contents
Technical specification
- Temperature and humidity collected in 10 second interval
- LCD interface with warnings (Temperature: hot / cold, Humidity: wet / dry, Dew point: Too high / Too low)
- LCD interface with 5 tactile keys (+1 reset)
- History and diagnostic information on LCD
- USB interface with simple text oriented protocol
- Historical data stored in RAM memory readable via LCD and USB interface
- Historical data with 60 minutes interval (display) and 30 minutes interval (USB)
- Historical data up to 24 hours
- Minimum and Maximum (cleared during boot or on user request)
- Reading range (indoor use):
- Temperature: +1C - +50C, Resolution: 0.1C
- Humidity: 1% - 99%, Resolution: 1% (display), 0.1% (USB)
- Dew point: -65C - +50C, Resolution: 0.1C
- Internal monitoring of voltage for mCPU and sensor (Vcc between 4.8V and 5.2V reported as good)
- Range indicating "normal" condition:
- temperature: 20 - 25C
- humidity: 40 - 70%
- dew point: 10 - 16C
- Device is pooling sensor for new data each 10 seconds. Displayed data may be up to 20 seconds old due to nature of selected sensor chip.
Note 1: Selected temperature range is based on expected usage pattern (indoor only). Temperature sensor can measure wider range of temperature but this may complicate code a bit (especially negative temperature).
Note 2: Selected temperature and humidity range is not proof that Arduino UNO board will survive it (e.g. high temperature and/or humidity).
Note 3: Values outside of range are internally used to indicate problem with sensor reading or reading outside of bounds.
LCD Interface
Most of the details are accessible via LCD interface. "Startup screen" is displayed during boot-up. After successful initialization device move to "Normal screen".
Startup screen
During boot-up device show source code and build date. I may change this to some kind of version numbers in future.
+----------------+ |sTemp_LCD_USB | |Jan 17 2016 | +----------------+
Device show also reboot source. If there is more that one reboot source set then device cycle through all of them. It is common to see BORF and PORF after device power up.
+----------------+ +----------------+ +----------------+ +----------------+ |sTemp_LCD_USB | |sTemp_LCD_USB | |sTemp_LCD_USB | |sTemp_LCD_USB | |(Watchdog) WDRF| |(Brown-out) BORF| |(External) EXTRF| |(Power-on) PORF| +----------------+ +----------------+ +----------------+ +----------------+
Presence of boot loader (if detected) is indicated by separate screen.
+----------------+ |sTemp_LCD_USB | |(Loader) LOADER| +----------------+
Note: For details about boot loader see Note 1 at end of page.
Normal screen
Displayed during regular operation. Left part of second line show device status:
- First part:
- Everything looks good -> ♡ altering with ♥ after each successful sensor read
- Minor problem reported (warning) -> exclamation mark
- Serious problem reported (error) -> exclamation mark using negative font
- Second part:
- Up and Down arrows are on display when there is activity on serial (USB) interface.
+----------------+ +----------------+ +----------------+ |T: 21.3C H: 50% | |T: 28.8C H: 90% | |T: 10.2C H: 10% | |♡↑↓ NORM NORM| |♥↑↓ HOT WET | |♡↑↓ COLD DRY | +----------------+ +----------------+ +----------------+
Note 1: If keyboard is not used for 10 minutes and display is not on "Normal screen" or "Big Numbers" then device automatically return to it.
Note 2: All text indicators are blinking when displaying other that normal condition (Hot, Cold, etc.)
Dew point
Show current dew point value.
+----------------+ +----------------+ +----------------+ |Dew point: 14.1| |Dew point: 20.2| |Dew point: - 9.1| | Comfortable| | Too high| | Too low| +----------------+ +----------------+ +----------------+
Note: minus sign to indicate negative value is on fixed position. It is not aligned with number. I will not change this in near future
History + min/max
This set of screens to show minimum, maximum and historical values. Left down corner of screen show selected mode:
Temperature and humidity:
+----------------+ +----------------+ +----------------+ +----------------+ |T: 21.3C H: 50% | |T: 21.3C H: 50% | |T: 21.3C H: 50% | |T: 21.3C H: 50% | |-01h NORM NORM| |-02h NORM NORM| |-23h NORM NORM| |-24h NORM NORM| +----------------+ +----------------+ +----------------+ +----------------+ +----------------+ +----------------+ |T: 20.0C H: 30% | |T: 25.0C H: 30% | |MIN NORM NORM| |MAX NORM NORM| +----------------+ +----------------+
Dew point:
+----------------+ +----------------+ +----------------+ +----------------+ |Dew point: 14.1C| |Dew point: 14.1C| |Dew point: 14.1C| |Dew point: 14.1C| |-01h Comfortable| |-02h Comfortable| |-23h Comfortable| |-24h Comfortable| +----------------+ +----------------+ +----------------+ +----------------+ +----------------+ +----------------+ |Dew point: 12.1C| |Dew point: 16.1C| |MIN Comfortable| |MAX Comfortable| +----------------+ +----------------+
Diagnostic screen
System support following diagnostic screens:
Diag: uptime
Time since last reboot (uptime):
+----------------+ |Diag: uptime | | 1234d 21h 45m| +----------------+
Note: Values are Day, Hour, Minute
Diag: sensor
Current status and status in past:
+----------------+ |Diag: sensor | |OK Mising| +----------------+
- Text on left show current status (last reading).
- Test on right show if there was problem in past (value is not reset upon successful reading)
Possible values:
- OK -> sensor is properly wired and responding
- Missing -> no response from sensor at all or wrong start sequence received
- CRC Err -> all data received but CRC or Parity don't match
- Timeout -> timeout while receiving data
Diag: history
Numbers of consecutive history banks populated with valid data:
+----------------+ |Diag: history | | 03 | +----------------+
All history banks contain valid data:
+----------------+ |Diag: history | | ok | +----------------+
Diag: reboot by
Show reboot source type.
-
W--
reboot source is not indicated by hardware. -
WDR
reboot source is indicated by hardware.
+----------------+ |Diag: reboot by | |W-- B-- E-- P-- | +----------------+
+----------------+ |Diag: reboot by | |WDR BOR EXT POR<| +----------------+
Note 1: this is example. There is no possibility that hardware indicate all reboot sources at once.
Note 2: "<" is shown when device detect bootloader.
Note 3: check Startup screen for more details.
Diag: Power
Show voltage for mCPU and sensor measured by Armel itself.
- Normal condition:
+----------------+ |Diag: Power | |Vcc: 4.9 V OK | +----------------+
- Error condition (voltage too low):
+----------------+ |Diag: Power | |Vcc: 4.0 V Err | +----------------+
Diag: version
Build date of code. This may change to some kind of version number in future.
+----------------+ |Diag: version | |Jan 17 2016 | +----------------+
Big Numbers screen
TODO:
Screen position
Screen can be selected by tactile keyboard and position of screens are following:
return back to return back to temp/hum display temp/hum display | | | | +----------------+ +----------------+ |Min/Max cleared | |Min/Max cleared | | any key to ret.| | any key to ret.| +----------------+ +----------------+ | | | | +----------------+ +----------------+ |T: 25.0C H: 50% | - |Dew point: 16.1| |MAX NORM NORM| - |MAX Comfortable| +----------------+ +----------------+ | | | | +----------------+ +----------------+ |T: 20.0C H: 30% | - |Dew point: 12.1| |MIN NORM NORM| - |MIN Comfortable| Device boot-up +----------------+ +----------------+ | | | | | | +----------------+ +----------------+ +----------------+ +----------------+ |sTemp_LCD_USB | - |T: 21.3C H: 50% | - |Dew point: 14.1| - |Diag: uptime | - - "Normal screen" |(Power-on) PORF| - |♡↑↓ NORM NORM| - | Comfortable| - | 123d 21h 45m| - all other diag screens - +----------------+ +----------------+ +----------------+ +----------------+ | | | | +----------------+ +----------------+ |T: 21.3C H: 50% | - |Dew point: 14.1| |-01h NORM NORM| - |-01h Comfortable| +----------------+ +----------------+ | | | | history up to history up to 24 hours - 24 hours for temperature - for dew point and humidity
If there is no action for 10 minutes then screen move back to "Normal screen".
TODO: big numbers
Serial (USB) interface
Device use virtual serial port over USB. Protocol is text oriented and request is made by sending upper case character. All undefinied characters are silently ignored. Additional requests are ignored while device is sending response. Configuration of serial port is 9600, 8-N-1, flow control: no
. Device send blank (space) character before responding to query. Maximum size of response is: 64 characters.
Format of response
Example:
Temp: 10.1 C, HUM: 36.1 %, Dew: - 4.2 C, 1 *E62D
- all values are send in format: "
type: value unit
" - more values in one message are separated by coma (
,
) - last value in message is sequential id. Number from 0 to 3.
- CRC is separated by asterisk (
*
) and is calculated as CRC-16.
Message id start at 0. Increment sequentially to 3 and then wrap around to 0. This ensure that each message is unique even when temperature / humidity reading result in same number.
Commands / data query
Communication rules:
- Wait for "silence" before requesting data.
- Request data by issuing one upper case character.
- Device schedule response using internal scheduler. Response is send once all higher priority tasks are done.
- Additional response lines are can be requested by issuing same request again.
- Version command can be used as "ping" to check if device is alive (it use smallest amount of CPU cycles to provide response). It can be also used to reset internal counter on multi line responses.
Help
List of commands:
? -> Help 1/2: Ver., Reboot, Temp., Alarms, History, 0 *7F6D ? -> Help 2/2: MinMax, Diag, Lcd, 1 *236C
Version
Build date / time. I may change this to version number in future.
V -> Version: Jan 17 2016, 20:48:03, 2 *6018
Reboot
This command force device reboot by disabling interrupts and initiating endless loop. In such a condition device is automatically restarted by watchdog.
R -> (no response by device)
Note: Display show "Reboot ..."
Flash
This command force device reboot using connection to external reset pin. After reset boot loader is invoked and can accept new firmware
F -> (no response by device)
Note: Display show "Flash FW ..."
Temperature / Humidity / Dew point
Last temperature, humidity and dew point reading.
T -> Temp: 21.1 C, HUM: 47.1 %, Dew: 9.4 C, 3 *542B
Alarms
Current alarm condition.
A -> Temp: NORM, Hum: NORM, Dew: Too low , 0 *66F0
History
Historical data (up to 24 hours in 30 minutes increments).
H -> -00.5h, Temp: 14.6 C, Hum: 40.6 %, Dew: 1.4 C, 1 *E823 H -> -01.0h, Temp: 14.1 C, Hum: 40.1 %, Dew: 0.8 C, 2 *1B46 . . H -> -23.5h, Temp: 15.6 C, Hum: 41.6 %, Dew: 2.6 C, 3 *863E H -> -24.0h, Temp: 15.1 C, Hum: 41.1 %, Dew: 2.0 C, 0 *83E4
Minimum / Maximum + clear
Minimum and maximum values + command to clear data.
M -> Temp/MIN: 10.1 C, Hum/MIN: 36.1 %, Dew/MIN: - 4.2C, 1 *13B0 M -> Temp/MAX: 22.2 C, Hum/MAX: 42.1 %, Dew/MAX: 8.7C, 2 *0B01 M -> Clear MIN/MAX ?, 3 *3AB0 M -> MIN/MAX cleared, 0 *118E
Diag
Show diagnostic data in similar format as on screen.
D -> UpD: 0002, UpH: 02, UpM: 56, UpS: 38, 1 *F4B3 D -> Sensor: OK , Missing, 3 *7810 D -> History: ok, 2 *B419 D -> Power: 4.9 V, OK , 3 *956E D -> Status: Warning, 0 *4F74
Note: See Diagnostic screen for more details.
Internal details
I decided to use fixed connection layout to simplify code. System is internally "task" oriented.
Physical connections
Serial (USB) interface (connection)
Serial converter is connected to PD0 / PD1
on micro-controller. Internal serial logic handle serial interface.
Display
Character display (16x2) in 4bit mode is connected in following way:
PB0 -> RS PB1 -> E PB2 -> backlight PD4 -> DB4 PD5 -> DB5 PD6 -> DB6 PD7 -> DB7
TODO: DF robot / modify of shield
Keyboard
Keyboard is connected to analog input on pin AD0
. Internally it acts as voltage divider.
Function | Resistor H | Resistor L | Voltage (expected) | Voltage (measured) | ADC (expected) |
---|---|---|---|---|---|
Right | 3K | 0R | 0.00 V | 0.00 V | 000 |
Up | 3K | 330R | 0.50 V | 0.49 V | 025 |
Down | 3K | 680R | 1.26 V | 1.24 V | 064 |
Left | 3K | 1K | 2.01 V | 2.00 V | 102 |
Select | 3K | 3K | 3.13 V | 3.12 V | 159 |
(none) | 3K | inf | 5.00 V | 4.98 V | 255 |
(vcc) | - | - | 5.00 V | 4.98 V | 255 |
Note: It looks like resistor matrix is not standardized along different vendors. Current configuration is for DF-Robot style LCD shield. I may add auto-learn capability in future.
Temperature and humidity sensor
Code expect AM2301 or AM2302 connected to "Analog 5" / PC5
pin on Arduino UNO board.
PC5 / A5 -> bidirectional data
Reset
Software way of "jump" to boot loader may fail under certain condition. Additionally "optiboot" is ignoring all reset sources except external reset. It is not easy to simulate this using software.
Arduino UNO board have connection from DTR signal of serial line to reset pin. This add possibility to reset mCPU remotely and enter boot loader. Unfortunately this may cause unwanted reset (for example if OS is scanning ports or app wrongly use modem signals). I cut "reset-en" on board to fix this problem.
Unattended FW update is not possible with "reset-en" disconnected. To fix this I connected "Analog 1" / PC1
pin to reset pin on board. This add possibility to reset mCPU if flash of firmware is required. Reset is controlled using SW and requested by "F
" via serial line.
PC1 / A1 -> connected to reset on mCPU
Timer (wall clock)
Scheduler
Serial interface
Display
Sensor reading
Development status
Source file | Module | Completed | WIP | Note |
---|---|---|---|---|
global.c | global variables and number to string functions | 100 % | - | - |
history.c | historical data management | 100 % | - | - |
keyboard.c | keyboard read / de-bounce | 100 % | - | - |
lcd.c | lcd interface | 100 % | - | - |
main.c | board initialization / scheduler / watchdog | 100 % | - | - |
menu.c | menu handler + code to prepare data for display | 100 % | - | - |
sensor.c | sensor read / dew point calculation | 100 % | - | - |
serial.c | serial interface including text protocol | 100 % | - | - |
timer.c | timer for scheduler / up-time clock | 100 % | - | - |
Notes / Errata
Note 1 - Boot loader
Assembly instructions
TODO: fix details ...
Step 1
Cut / De-solder "Digital 10" pin from LCD shield.
Step 2 (optional)
Cut / De-solder ISP header on LCD shield. (it may not fit to case with ISP header in place)
Step 3
Solder connection from "Analog 1" to "Reset" on LCD shield.
Step 4
Cut "reset-en" on Arduino UNO board.
Step 5
Power-up Arduino UNO board and connect to AVR Dragon using ISP. Flash boot loader using:
cd loader ./burn_loader.sh
Step 6
Stack LCD shield on top of Arduino UNO.
Step 7
Solder rectifying diode between "Digital 10" on LCD Shield and Arduino UNO (TODO: Polarity ?)
Step 8
Connect / solder AM2301 or AM2302 to "Analog 5" and Power/GND pin.
Step 9
Connect Arduino UNO board to PC using USB. Flash FW using following commands: (TODO: how to use reset button ?)
./burn_arduino.sh
Step 10
Install thermometer in case. ( I like this one -> Cade Case )