0

I am new to the topic of raspberry and sensors, I am doing a project with a raspberry pi 4 and a temperature sensor DS18B20, I created a small project in python to display the temperature in real time.

import time
from w1thermsensor import W1ThermSensor
sensor = W1ThermSensor()

while True:
      temperature = sensor.get_temperature()
      print("The temperature is %s celsius" % temperature)
      time.sleep(1)

Now what I need is to display the temperature on a nextion screen, I already loaded the interface to the screen, I created a variable called "celcius.val". but I don't know how to get the temperature from the sensor and print it in the variable.

enter image description here

3
  • 2
    I have never heard of a nextion screen or the interface to the nextion screen. This seems to be a general programming question, not specific to the Pi.
    – joan
    Aug 10 at 12:18
  • definitely not about Raspberry Pi ... nexion screen is irrelevant ... the actual question is how to send serial data from Python?
    – jsotola
    Aug 10 at 18:09
  • yes please, I am new at this
    – Lucas
    Aug 11 at 22:37
1

Since Nextion instruction sets are sent over serial, you would need to:

  1. Connect your Pi to the Nextion screen through serial.
  2. Connect to the screen in Python.
  3. Assign your temperature reading to your variable:
command = "celcius.val=" + temperature
ser.write(command.encode('utf-8'))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.