Raspi-Nextion Weather Clock

Introduction: Raspi-Nextion Weather Clock

Seeing so many different clocks built with arduino and raspberry Pi's inspired me. I wanted to make one too.

I started by using an arduino mega with a ESP8266 but found the 8266 wifi to have too many hiccups. I decided to use a spare Pi I had (Raspberry Pi3 Model B) even though I had never used Python. I found some tutorials for using the arduino code on the Pi, but this all seemed to be bandaids.

The Raspi-Nextion Weather Clock uses the Pi running Raspian connected to a Nextion 5" enhanced screen.thru the serial port with the program written in Python.

I also 3D printed (with the help of some friends) the case.

As soon as the program boots - it gets the date & time from Google

It will also get the weather using thingspeak.com

You will need to signup at https://thingspeak.com/apps and use a ThingHTTP

The screen will change as the weather changes - ie: if its sunny out the screen will have a sunny background, if its snowing, the screen will have a snow filled background

The screen will dim at night so you can sleep - this is adjustable in the program as to what time it dims and undims

When its a holiday, you will see a holiday background and the screen will undim later so you can sleep in...

All backgrounds are editable using the nextion software

make custom screen for birthdays, anniversaries, important dates...

Step 1: Parts List

Here is the list of parts and software I used:

Hardware

1. Raspberry Pi 3 Model B ($50 on Amazon) https://www.amazon.com/CanaKit-Raspberry-Clear-Pow...

1a. You will need a microSD - I had a spare with a usb to microSD adapter

2. Nextion 5" Enhanced Screen ($72 from ITead) https://www.itead.cc/nextion-nx8048k050.html

3. 2 small speakers - optional - I wanted to add 2 bluetooth speakers

4. Bluetooth audio amp - optional - https://www.amazon.com/INSMA-Amplifier-TDA7492P-Re...

5. power supply - optional - if you add the speakers its nice to add a power supply that will supply the Raspberry and the audio amp - https://www.coolerguys.com/products/100-240v-ac-to...

6. I also added the 3D printer files for anyone interested

Software:

1 Raspian - https://www.raspberrypi.org/downloads/raspbian/

2. Win32 Disk Imager - used to write raspian to microSD for Raspberry Pi - https://sourceforge.net/projects/win32diskimager/

3. Nextion Editor - for creating custom screen layouts - https://nextion.itead.cc/resources/download/nextio...

Extras:

1. computer screen to connect to the PI - temporarily

2 usb keyboard and mouse to connect to the pi - temporarily

Step 2: Install Raspbian & Load the Nextion Screen

Once you have downloaded the raspian image, unzip the iso to your pc.

Place the microSD card into a USB adapter and plug in your pc

Perform a quick format on the sd card (fs=fat32)

Load the screen:

1. plug the SD card into your pc and place the attached hmi file on the card

2. install the microSD into the Nextion screen and power up

3. wait for the image to load. When done remove power from the screen and remove the card

4. Perform a quick format on the sd card (fs=fat32)

Load Rapian to microSD:

Start Win32 disk imager and write the image to the microSD

1. choose the letter of your microSD

2. select the raspian image iso file you unzipped

3. Click write

4. Once done you can close Win32 disk imager and unplug the microSD from your pc.

5. Plug the microSD into the raspberry Pi

Step 3: Boot the Raspberry Pi & Connect the Nextion

There are a few configuration changes that need to be made on the Raspberry Pi.

For instance, to use the serial output on the Pi3 Model B, you must disable the bluetooth.

Assemble the PI and plug in your keyboard, mouse, SD card and pc screen using the hdmi output of the PI

1. Once you plug the power into the Pi, it will start to boot. Once booted, you will find you have a nice desktop with everything you need already installed.

1A. Click the wifi icon in the top right corner of the screen and attach the Pi to your wifi and save the settings

2.The serial on GPIO 14 & 15 is disabled because it is used by the bluetooth. To enable the serial interface, you must add the lines below to /boot/config.txt you must do this thru the terminal using sudo nano /boot/config.txt

  • click the terminal icon (black screen icon) on the top of the screen
  • type sudo nano /boot/config.txt
  • using you arrows, scroll to the bottom of the screen and add the lines below to the bottom of the files

#disable bluetooth so nextion can work on serial 0

dtoverlay=pi3-disable-bt enable_uart=1

enable_uart=1

  • Once these lines are added, next we save and exit
  • press control x to exit
  • press Y to save
  • press [enter] to save file

shutdown & remove pwr from the pi

restart.

open the terminal and type pinout

we will be using GPIO 14 & 15 for serial comms to the nextion

You will see which pins on the Raspberrys GPIO are GPIO 14 & 15 on the screen

3. Shutdown the Pi and connect the screen as shown in the attached pic

4. Reboot the Pi

5. Open the terminal and type sudo raspi-config

6. go to Interfacing options, then serial and enable the serial port and disable the shell

7. Tab to finish

8. Reboot one more time

Step 4: Writing Your Python Program

Choose your favorite python IDE and get to coding...

I chose Geany as it was already installed on the Raspian image. Its also very easy to use and testing the program couldnt be easier. All you have to do is click the paper plane icon at the top of the Geany screen and it starts the program

I have attached my program as an example. This will help show you how to access the serial port and the different functions of the Nextion screen. Feel free to edit as you see fit

Step 5: Start Program When Raspberry Boots...

By this time, you should be able to run the program on your screen

If you want to be able to run your raspberry pi clock program without the keyboard, mouse and pc screen follow the steps below.

1.add this line to top of your program --> #!/usr/bin/python

2. make your program executable by using the chmod command in the terminal.

  • click the folder icon at the top of the Raspian screen and navigate to the folder where your program is. Mine is on the desktop in a folder named py
  • Right click on the folder (i will right click on the py folder and choose open terminal)
  • Type the command sudo chmod +x followed by the path to the program and click [enter]
  • sudo chmod +x /home/pi/Desktop/py/NameOfProgram.py
  • close the terminal when done

3. Now navigate to the /etc folder

4. Right click on the etc folder and choose open ternal

5. In terminal type--> sudo nano rc.local

6. Using your arrows, scroll to the bottom of the page, to the line above exit 0

7. Add a path to your executable program --> /home/pi/Desktop/py/NameOfProgram.py

8. Click control + x to exit, Y to save and click [enter]

8a. [EDIT] - You must also make the rc.local file executable by now typing sudo chmod a+X rc.local

9. Reboot the pi by typing reboot in the terminal and when it reboots the program should auto-start :)

Step 6: Optional Bluetooth Speakers

The bluetooth audio amp was needed as we disabled bluetooth to use the serial port

If using the suggested power supply, you will need to break out the wires and use the 5V for the Raspberry and the 12V for the bluetooth audio amp.

Connect the power and speakers according to the attached pic.

The speakers I used were taken from an old failed bluetooth bathroom fan/speaker setup

Step 7: Using ThingSpeak

You will need to signup at https://thingspeak.com/apps and use a ThingHTTP

I started one for the temp and another for the weather condition ie: sunny. foggy, snow...

When setting up the ThingHttp, you will need a URL to send a get request to

I use - https://www.wunderground.com/weather/us/in/Indianapolis

The method is Get

HTTP ver - 1.0

The parse string is a little tricky

1. Go to the weather underground site for your city

2. In google chrome, press F12 (go to step 3 or 3a)

3. On the right side of the screen, look for and click the icon for "select an element in the page to inspect"

3a. Or highlight and right click on the text you want to get and select "Inspect" (skip to step 5)

4. Now highlight the temp

5. On the right you will see a line get highlighted - Right click on this line, go to copy and select Copy XPath

6. Save this as your parse string in your thingHTTP setup

7. Save the thingHTTP and you will be given a link to use for the program with your API Key

8. Setup your link just as I have in the program.

9. You can test requests easily with a program called Insomnia, but thats a whole other tutorial..

First Time Author

Participated in the
First Time Author

2 People Made This Project!

Recommendations

  • Tinkercad Student Design Contest

    Tinkercad Student Design Contest
  • Halloween Contest

    Halloween Contest
  • Back to School: Student Design Challenge

    Back to School: Student Design Challenge

38 Comments

0
aleks.sim2016
aleks.sim2016

Question 6 days ago

Hello! been doing good work with the project lately, when suddenly, this Monday, my Raspberry Pi stopped recognizing Nextion Screen. I tried different ways, including, but not limited to: Buying new screen and Raspberry PI, updating Raspbian, redoing the whole project from zero. Nothing worked, even though no changes were done since it worked last time. Any help would really be nice!

0
TeeMick
TeeMick

Reply 5 days ago

Please let me know what model screen and raspberry Pi you have. If you want to send me your program, that will help. I can even upload to a RPi and try it here.

0
TeeMick
TeeMick

Reply 4 days ago

Ok, I did not see anything that stands out.
If you change your RPI code so that your python code never starts, does the display work?
You can even just rename your python program and restart the Pi to see if the display comes on.
Have you tried connecting an external display to the PI?

0
david.molevelt
david.molevelt

Question 1 year ago on Introduction

HiTeeMick,
Can you please instruct me why my Pi does not accept Unicode in the serial instructions?
You suggest port.write "page0" . My serial port definition is ttys0 and using pi 3

Best regards,
David

0
Vamoski
Vamoski

Answer 4 months ago

Hi, did you manage to fix it? I looked all over and managed to find nothing to fix it on my side
+ for whatever reason RPi won't see connection in serial

0
TeeMick
TeeMick

Reply 4 months ago

Can you send me your program? - Id be happy to take a look..

0
Vamoski
Vamoski

Reply 4 months ago

I am also not sure, but it may have changed on weather website, since it sends not only a number now, but other info too

0
TeeMick
TeeMick

Reply 4 months ago

Try using something like "temp = temp[:-3]" when getting the temp
This will get all characters and cut off the last three. Try cutting the string to keep only the characters you want

0
Vamoski
Vamoski

Reply 4 months ago

Thanks for a tip! Most of the stuff works now, only temp, cond and WDesc returns b'MyData'
is there any way to get rid of b' '?

0
TeeMick
TeeMick

Reply 4 months ago

sure, try using this format
after temp (or cond or WDesc) is loaded with the data do this
temp = temp[1:]
cond = cond[1:]
WDesc = WDesc[1:]
this will remove only the first character

0
Vamoski
Vamoski

Reply 4 months ago

thanks for the tip
for me temp = temp.decode ('utf-8')
and cond = cond.decode ('utf-8')
after formatting them fixed the issue

0
DannyM62
DannyM62

Question 2 years ago

Thanks again for a great project. I have the project working but would like to make a couple of changes. I want to add buttons to call functions in my python program, I use them to turn on and off a Wemo switch. I can put the buttons on the display, but not sure how to send the data to the program that would call the function. I can see how you used the port.write command to send data to the display. I am just trying to understand how to do the reverse. Thanks again in advance for your help.
Danny

0
TeeMick
TeeMick

Reply 2 years ago

How did you fix the serial problem?
For creating on-screen buttons, look at the section of code below. There is a clear button in the bottom right of the screen.
Each pass of the program the code is looking for a button press. When It reads the button was pressed, the screen is dimmed or undimmed depending on the original state of the screen.
Create a button, then use print(ord(line1[0])) in your program to see the result of a button press.
See the attached pic.

<code>
line1 = port.read(1)
#print(ord(line1[0]))
if (line1 != ""):
if ((ord(line1[0])) == 101) and (IsDim == 0):
IsDim = 1
port.write(dimCmd + eof)
overRide = 1
pic = 0
Opic = 0
elif ((ord(line1[0])) == 101) and (IsDim == 1):
IsDim = 0
port.write(undimCmd + eof)
overRide = 0
pic = 0
Opic = 0
DimCntr = 0
</code>

Untitled.png
0
DannyM62
DannyM62

Reply 2 years ago

Do you have a different piece of code in python to read the data sent by the pressing of a command button? I have searched and searched and have not come up with any examples. I have found a similar example using Arduino IDE, but not sure how to convert it. On the Button I am using I have set up "Touch Press Event" and even tried to enter a line "print 1", but I cannot get the piece of code to appear trying to use the print command . I tried using your code but never could get anything to work properly. What I would like to happen is when I press the Command Button my python code would be looking for the button press and through an if statement check the output from the Nextion Button and execute another piece of code. Sounds easy but I have yet get it to work.
Thanks for your help.
Danny

0
DannyM62
DannyM62

Reply 2 years ago

Is the code part of the python program or set up on the Nextion?

0
TeeMick
TeeMick

Reply 2 years ago

The code is part of the python program. You might find that snippet in the program ur running. The only thing to do in nextion is create the button and check the box for the button to send its Id. Then your python program must have code looking for that particular Id

0
DannyM62
DannyM62

Reply 2 years ago

Thanks