Difference between revisions of "Arduino: Simple LCD Thermometer with USB interface"
Lukas Dzunko (talk | contribs) (→Technical specification) |
Lukas Dzunko (talk | contribs) (→LCD Interface) |
||
Line 34: | Line 34: | ||
Blinking text indicate out of range condition (hot/cold, wet/dry, reading out of range). | Blinking text indicate out of range condition (hot/cold, wet/dry, reading out of range). | ||
− | '''Note:''' all display examples use illustration values. For more details check ranges in technical specification. | + | '''Note:''' all display examples use illustration values. For more details check ranges in technical specification. TODO: replace with real values during testing. |
=== Startup screen === | === Startup screen === |
Revision as of 09:22, 26 May 2014
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
- 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 30 minute interval (up to 24 hours)
- Minimum and Maximum values
- Temperature range: +1C - +50C, Resolution: 0.1C
- Humidity range: 1% - 99%, Resolution: 1% (display), 0.1% (USB)
- Dew point range: -65C - +50C, Resolution: 0.1C
- Internal mCPU temperature monitoring
- Ranges indicating "normal" condition:
- temperature: 20 - 25C
- humidity: 40 - 70%
- dew point: 10 - 16C
Note: Ranges represent values accepted by board from sensor. It may not be possible for board to survive values close to edges of range.
Note: Temperature or humidity set to "0" (zero) mean failed reading or missing data. Dew point is calculated only if temperature and humidity reading success.
Note: Temperature of +51C and humidity of 100% is used as "reset" value for minimum data function.
LCD Interface
Temperature sensor need at least two seconds to settle down. This make space to display reboot source. If it is necessary to wait, then it is possible to use this time to show why device was rebooted.
Startup screen stay for approximately 5 seconds and then device move to "Normal screen". If there is no activity for 60 seconds then device automatically move back to "Normal screen".
Blinking text indicate out of range condition (hot/cold, wet/dry, reading out of range).
Note: all display examples use illustration values. For more details check ranges in technical specification. TODO: replace with real values during testing.
Startup screen
Displayed up on device reboot. Indicate source of reboot.
+----------------+ +----------------+ +----------------+ +----------------+ |Please wait ... | |Please wait ... | |Please wait ... | |Please wait ... | |(Watchdog) WDRF| |(Brown-out) BORF| |(External) EXTRF| |(Power-on) PORF| +----------------+ +----------------+ +----------------+ +----------------+
Normal screen
Displayed during "normal" operation. First two characters on second line show device status:
- position 1: "heart" show sensor / device activity (♡ is altering with ♥ after each successful sensor read).
- position 2: "arrows" indicate USB activity (⇅ pop up if there is USB activity).
+----------------+ +----------------+ +----------------+ |T: 21.3C H: 50% | |T: 28.8C H: 90% | |T: 10.2C H: 10% | |♡⇅ NORM NORM| |♥⇅ HOT WET | |♡⇅ COLD DRY | +----------------+ +----------------+ +----------------+
Dew point
+----------------+ +----------------+ +----------------+ |Dew point: 14.1C| |Dew point: 20.2C| |Dew point: 9.1C| | Comfortable| | Too high| | Too low| +----------------+ +----------------+ +----------------+
History + min/max
Minimum/Maximum and value from past (history) is indicated in left down corner of screen.
Temperature and humidity:
+----------------+ +----------------+ +----------------+ +----------------+ |T: 21.3C H: 50% | |T: 21.3C H: 50% | |T: 21.3C H: 50% | |T: 21.3C H: 50% | |-05m NORM NORM| |-55m NORM NORM| |-01h NORM NORM| |-72h 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| |-05m Comfortable| |-55m Comfortable| |-01h Comfortable| |-72h Comfortable| +----------------+ +----------------+ +----------------+ +----------------+ +----------------+ +----------------+ |Dew point: 12.1C| |Dew point: 16.1C| |MIN Comfortable| |MAX Comfortable| +----------------+ +----------------+
Diagnostic screen
System support following diagnostic screens:
+----------------+ +----------------+ +----------------+ +----------------+ +----------------+ |Diag: uptime | |Diag: history | |Diag: history | |Diag: CPU temp | |Diag: version | | 1234d 21h 45m| | m: 30 h: 20 | | m: ok h: ok | | | |Sys: AA Boot: AA| +----------------+ +----------------+ +----------------+ +----------------+ +----------------+
From left to right:
- device uptime
- position of first unknown history data (due to sensor problem or device reboot). "m" is for minute history and "h" for hour history.
- all history data valid
- internal CPU temperature (approximate)
- system and bootloader version
Screen position
Screen can be selected by tactile keyboard and position of screens are following:
+----------------+ +----------------+ |T: 25.0C H: 50% | |Dew point: 16.1C| |MAX NORM NORM| |MAX Comfortable| +----------------+ +----------------+ ↑ ↓ ↑ ↓ +----------------+ +----------------+ |T: 20.0C H: 30% | |Dew point: 12.1C| |MIN NORM NORM| |MIN Comfortable| Device boot-up +----------------+ +----------------+ ↓ ↓ ↑ ↓ ↑ ↓ +----------------+ +----------------+ +----------------+ +----------------+ |Please wait ... | → |T: 21.3C H: 50% | → |Dew point: 14.1C| → |Diag: uptime | → |(Power-on) PORF| → |♡⇅ NORM NORM| ← | Comfortable| ← | 123d 21h 45m| ← all other diag screens +----------------+ +----------------+ +----------------+ +----------------+ ↑ ↓ ↑ ↓ +----------------+ +----------------+ |T: 21.3C H: 50% | |Dew point: 14.1C| |-05m NORM NORM| |-05m Comfortable| +----------------+ +----------------+ ↑ ↓ ↑ ↓ history up to history up to 72 hours 72 hours for temperature for dew point and humidity
If there is no action for 60 seconds then screen move back to "Normal screen".
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.
Format of response
Example:
TEMP: 12.3C, HUM: 70.1%, 1 *CC
- all values are send in format: "
type: value unit
" - more values in one message are separated by coma (
,
) - last value is message sequential id. Number from 0 to 3.
- CRC is separated by asterisk (
*
) and is calculated as simple 8bit CRC
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.
- Device respond immediately after request (interrupt driven logic).
- Additional response lines are requested by issuing requests once more. Issuing different command reset internal response line counter.
- Version command can be used as "ping" to check if device is alive.
Version
System and bootloader version:
V -> Sys: AA, Boot: AA, 0 *CC
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: there is no response to this command
Temperature / Humidity / Dew point
Last temperature, humidity and dew point reading (up to 10 second old).
T -> Temp: 12.3 C, HUM 70.1%, Dew: 12.3C, 0 *CC
Note: Numbers are for illustration only. Dew point is not calculated in this example.
Alarms
Current alarm condition.
A -> Temp: NORM, Hum: NORM, Dew: Comfortable, 0 *CC
TODO: clear alarm condition only after several "normal" reads ?
History
History from 5 minutes to 72 hours in past (temperature, humidity, dew point). Repeat command to get more data.
H -> -05m, Temp: 12.3C, Hum: 70.1%, Dew: 10.0C, 0 *CC . . H -> -72h, Temp: 12.3C, Hum: 70.1%, Dew: 10.0C, 0 *CC
Note: Numbers are for illustration only. Dew point is not calculated in this example.
Minimum / Maximum + clear
Minimum and maximum values + command to clear data.
M -> Temp/Min: 12.3C, Hum/Min: 30.1%, Dew/Min: 10.0C, 0 *CC M -> Temp/Max: 23.1C, Hum/Max: 70.1%, Dew/Max: 21.3C, 1 *CC M -> Min/Max cleared ... , 2 *CC
Note: Numbers are for illustration only. Dew point is not calculated in this example.
Diag
Show diagnostic data in same format as on screen.
D -> UptimeD: 1234, UptimeH: 21, UptimeM: 45, 0 *CC D -> HistoryM: ok, HistoryH: ok, 1 *CC D -> CPUTemp: ...., 2 *CC
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 PD4 -> DB4 PD5 -> DB5 PD6 -> DB6 PD7 -> DB7
Note: I am using shield without BL control on Digital pin 10.
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 readout |
---|---|---|---|---|---|
Right | ??? | ??? | ?.??? V | 1.26 V | 0x4 |
Up | ??? | ??? | ?.??? V | 2.47 V | 0x7 |
Down | ??? | ??? | ?.??? V | 3.33 V | 0xD |
Left | ??? | ??? | ?.??? V | 4.23 V | 0xF |
Select | ??? | ??? | ?.??? V | 0.01 V | 0x0 |
Note1: Apparently I have at least one LCD Shield for Arduino with different internal connection (no, it is not Chines one). I update table once I manually verify resistors on board (all of them are hidden under LCD module).
Note2: ADC configuration: 10-bit, triggered by scheduler, only 4 most significant bits are kept after readout.
Temperature and humidity sensor
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 | 90 % | num-to-str | - |
history.c | historical data management | 100 % | - | not tested yet |
keyboard.c | - | 0 % | - | - |
lcd.c | - | 0 % | - | - |
main.c | board initialization / scheduler / watchdog | 100 % | - | - |
menu.c | - | 0 % | - | - |
sensor.c | - | 0 % | dew point calc. | - |
serial.c | serial interface including text protocol | 99 % | - | cputemp missing |
timer.c | uptime + timer for scheduler | 100 % | - | - |