jdolecki
Posts: 13
Joined: Tue Jan 02, 2018 2:55 pm
Contact: YouTube

displaying temp sensor on LCD

Mon Sep 20, 2021 2:42 am

I'm trying to display 1wire temp sensor data on my LCD.
For temp sensor I'm using the W1Thermsensor libary
For the LCD I'm using the I2C lcd driver

The print (temperature_in_celsius) will display the temp
When i try to send it to the lcd is were the trouble is??

help or suggestions would be grateful.
Thanks John

Code: Select all

import I2C_LCD_driver
from time import *


from w1thermsensor import W1ThermSensor
mylcd = I2C_LCD_driver.lcd()

sensor= W1ThermSensor (sensor_id="062017f57999")
temperature_in_celsius = sensor.get_temperature()


print (temperature_in_celsius)

mylcd.lcd_display_string(temperature_in_celsius) 

User avatar
B.Goode
Posts: 13023
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: displaying temp sensor on LCD

Mon Sep 20, 2021 6:59 am

jdolecki wrote:
Mon Sep 20, 2021 2:42 am
I'm trying to display 1wire temp sensor data on my LCD.
For temp sensor I'm using the W1Thermsensor libary
For the LCD I'm using the I2C lcd driver

The print (temperature_in_celsius) will display the temp
When i try to send it to the lcd is were the trouble is??

help or suggestions would be grateful.
Thanks John

Code: Select all

import I2C_LCD_driver
from time import *


from w1thermsensor import W1ThermSensor
mylcd = I2C_LCD_driver.lcd()

sensor= W1ThermSensor (sensor_id="062017f57999")
temperature_in_celsius = sensor.get_temperature()


print (temperature_in_celsius)

mylcd.lcd_display_string(temperature_in_celsius) 


"help or suggestions would be grateful. "


Check the API documentation for the w1thermsensor and I2C_LCD_driver library modules you have installed. (You don't say where you found them.)


It seems likely that the function W1ThermSensor.get_temperature() will return a Number, while the function I2C_LCD_driver.lcd().lcd_display_string() will almost certainly expect to display a String?


Try converting temperature_in_celsius to a string prior to displaying it.

pcmanbob
Posts: 11802
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: displaying temp sensor on LCD

Tue Sep 21, 2021 8:11 am

Use " str " to convert your number to a string , most if not all LCD drivers required the information to be displayed to be in the for of text.

like this

Code: Select all

import I2C_LCD_driver
from time import *


from w1thermsensor import W1ThermSensor
mylcd = I2C_LCD_driver.lcd()

sensor= W1ThermSensor (sensor_id="062017f57999")
temperature_in_celsius = sensor.get_temperature()


print (temperature_in_celsius)
display_temperature = str(temperature_in_celsius)
mylcd.lcd_display_string(display_temperature) 
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Automation, sensing and robotics”