Difference between revisions of "Arduino: Simple LCD Thermometer with USB interface"
Lukas Dzunko (talk | contribs) (→Diagnostic screen) |
Lukas Dzunko (talk | contribs) (→Screen position) |
||
Line 257: | Line 257: | ||
</pre> | </pre> | ||
If there is no action for 10 minutes then screen move back to "Normal screen". | If there is no action for 10 minutes then screen move back to "Normal screen". | ||
+ | |||
+ | TODO: big numbers | ||
== Serial (USB) interface == | == Serial (USB) interface == |
Revision as of 14:21, 25 April 2016
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)
- 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 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: there is no direct response to this command.
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 PD4 -> DB4 PD5 -> DB5 PD6 -> DB6 PD7 -> DB7
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 |
---|---|---|---|---|---|
Select | 1K | 0R | 0.00 V | 0.01 V | 000 |
Right | 1K | 330R | 1.24 V | 1.26 V | 063 |
Up | 1K | 950R | 2.44 V | 2.47 V | 125 |
Down | 1K | 1K95 | 3.31 V | 3.33 V | 169 |
Left | 1K | 5K25 | 4.20 V | 4.23 V | 215 |
Note: Apparently I have at least one LCD Shield for Arduino with different internal connection (No, it is not Chines one).
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 | 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 | 99 % | handler for sub zero temperature | - |
serial.c | serial interface including text protocol | 100 % | - | - |
timer.c | timer for scheduler / up-time clock | 100 % | - | - |