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)

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

  • 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
    Commented Aug 10, 2021 at 12:18
  • definitely not about Raspberry Pi ... nexion screen is irrelevant ... the actual question is how to send serial data from Python?
    – jsotola
    Commented Aug 10, 2021 at 18:09
  • yes please, I am new at this
    – Lucas
    Commented Aug 11, 2021 at 22:37

1 Answer 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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