Difference between revisions of "Arduino: Simple LCD Thermometer with USB interface"

From Luky-Wiki
Jump to: navigation, search
(Minimum / Maximum + clear)
(Technical specification)
Line 21: Line 21:
 
** dew point: 10 - 16C
 
** dew point: 10 - 16C
  
''Note:'' DODO: dew point range.
+
''' ''Note:'' ''' Dew point range reflect possible values for accepted sensor readout (temperature / humidity). TODO: ...
  
 
== LCD Interface ==
 
== LCD Interface ==

Revision as of 16:37, 25 April 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.

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 5 minute interval (up to 55 minutes) and 1 hour interval (up to 72 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: Dew point range reflect possible values for accepted sensor readout (temperature / humidity). TODO: ...

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.

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 (display)

+----------------+ +----------------+ +----------------+
|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

Last temperature and humidity reading (up to 10 second old).

C -> Temp: 12.3 C, HUM 70.1%, 0 *CC

Temperature only

Last temperature reading (up to 10 second old, not suitable for dew point calculation).

T -> Temp: 12.3C, 0 *CC

Humidity only

Last humidity reading (up to 10 second old, not suitable for dew point calculation).

H -> Hum: 70.1%, 0 *CC

Dew point

Last dew point calculated from recent temperature and humidity (internally calculated by board).

D -> Dew: 12.3C, 0 *CC

Alarms

Current alarm condition.

S -> Temp: NORM, Hum: NORM, Dew: Comfortable, 0 *CC

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: dew point is not calculated. Number is for illustration only.

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: dew point is not calculated for particular Min/Max Temp/Hum combination. Value represent minimum or maximum for dew point itself.

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