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