Pages: [1]   Go Down
Author Topic: DS18B20 sensor temperature display with 9 bit precision  (Read 979 times)
0 Members and 1 Guest are viewing this topic.
Lithuania
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Gentlemen’s,
I’m developing a small project with three DS18B20 temperature sensors in 9 bit resolution mode and 16x2 LCD display. Using 'OneWire.h' + 'DallasTemperature.h' + 'LiquidCrystal.h' libraries without modification. All works fine.
The issue I have is related to the fact that I have quite limited display space to indicate temperatures (I want to display some other text also). Standard libraries by default shows temperature in format (-)XX.XX, for example 23.50 or 23.00 Celsius . Since I need only 9 bit temp resolutions it would be enough to have one digit after comma, like 23.0 or 23.5 Celsius. That would save me some space on the LCD screen.
Any ideas how to do it in elegant way?
Thank a lot!
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
float temperature = 4.5267;
char buffer[5];
snprintf(buffer, sizeof(buffer), "%.01f", temperature);
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13702
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

assuming lcd inherits from Print class
Code:
float temperatureC = getTempC();

lcd.print(temperature, 1); // for float the param means the # decimals
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Lithuania
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot! This is super easy way of fixing it! smiley
Logged

Pages: [1]   Go Up
Jump to: