How to Make a Raspberry Pi Pico Weather Station.
by willrank in Circuits > Microcontrollers
20 Views, 0 Favorites, 0 Comments
How to Make a Raspberry Pi Pico Weather Station.
In this tutorial you will be guided through every step to make a simple, Wireless Weather Station using a Raspberry Pi pico.
Supplies
- Raspberry Pi pico W
- AHT 20 Environmental Sensor
- Jumper cables
- Solderless Breadboard Half Size (optional)
- 16 X 2 LCD screen
Wiring Pi Pico to Environmental Sensor
(Before you connect anything make sure the Raspberry Pi pico is unpowered!) Make sure to place the Raspberry Pi pico long ways with the USB port facing outwards on the breadboard (breadboard optional). Do not have the Raspberry Pi Pico directly plugged into positive or negative on the breadboard unless specifically instructed to!
(Refer to diagram for assistance)
Now place the environmental sensor with its pins three rows away from the center off the breadboard (Row C) and have the (VIN) pin in row 28. (As seen in diagram)
Connecting LCD Screen
First connect ground on the LCD screen to Pin 3 on the Pi Pico then connect the VCC pin on the LCD screen to the VBUS pin on the Raspberry Pi Pico. Connect SDA on the LCD Two GP-0 or pin 1 then connect SCL on the LCD to GP-1 or pin 2.
Libraries
Now that you have fully wired your Raspberry Pi Picot weather Station we can get to coding. But before we do any of that we need to download these libraries.
Make sure to copy and paste or download these libraries into Thonny and then save them on your Raspberry Pi pico as they are named. These are needed for the function of the weather station!
The Code
I don't believe you will have to do any coding yourself to get the weather station to work, but you can modify my code, in any which way you like.
Just copy and paste my code into an empty file in Thonny.
import utime
from machine import Pin, I2C
import lcd_api
import pico_i2c_lcd
import ahtx0
from machine import Pin, SoftI2C
from pico_i2c_lcd import I2cLcd
from time import sleep
# I2C for the Wemos D1 Mini with ESP8266
i2c = I2C(id=0, scl=Pin(21), sda=Pin(20), freq=400000)
# Create the sensor object using I2C
sensor = ahtx0.AHT10(i2c)
I2C_ADDR = 0x27
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16
i2c = SoftI2C(sda=Pin(0), scl=Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
lcd.putstr("It's working :)")
sleep(4)
try:
while True:
# Clear the LCD
lcd.clear()
# Display two different messages on different lines
# By default, it will start at (0,0) if the display is empty
lcd.putstr("\nTemp: %0.2f C " % sensor.temperature)
lcd.putstr("Hum: %0.2f %%" % sensor.relative_humidity)
sleep(2)
lcd.clear()
except KeyboardInterrupt:
# Turn off the display
print("Keyboard interrupt")
lcd.backlight_off()
lcd.display_off()
(End of Code)
If you think the refresh rate is too fast, you can adjust, it by changing the sleep value in the while true loop.
If you want your weather station to work without needing your laptop to power it, you can simply use a power bank. You will also have to save the code onto the Raspberry pi pico as main.py
Production Journal
I started the production of my weather station by researching all the necessary parts I would need. This led me to use the AHT20 Temperature and humidity sensor. I already knew I'd be using a Raspberry Pi Pico and I knew I'd need an LCD, screen.
I began constructing my weather station by connecting the electrical circuit. I started by connecting the Raspberry Pi Pico to the temperature and humidity sensor and then made sure everything worked with a bit of code in Thonny. I then tried to get it to work on the LCD screen but every time I tried, it didn't work even though when checking with chat GPT and other coding software's my code was fine I made sure to cheque all the physical connexons and nothing was wrong. It turned out I accidentally misspelt one of the library names. after this it worked flawlessly it just updated a little fast, so I reduced the update speed.