Build your own weather machine

5 min read

PI PICO

Les Pounder is normally a ray of sunshine, but is feeling a little under the weather. Perhaps this project will lift the clouds.

The Raspberry Pi Pico W excels at being used with online APIs for a myriad of data sources. T We’ve used it to read the news, tell us who is on the International Space Station, and now we are building a portable weather station that uses OpenWeather’s API to tell us if we need an umbrella.

W is for weather

Holding the BOOTSEL button, connect your Pi Pico to your computer. Go to https://bit.ly/LXF306Micro Python and download the version of MicroPython for your Pico/Pico W. Open your file manager, go to the downloaded file and copy it to the root of the RPI-RP2 drive. This flashes the new firmware to the Pico.

Using your distro’s package manager, install Thonny. For the latest Ubuntu release, we have to use a Snap: $ sudo snap install thonny

Open Thonny and connect the Pico to your machine. Go to Tools > Options > Interpreter tab. Set the interpreter to MicroPython (Raspberry Pi Pico) and Port to match the Pico’s location. Click OK. Thonny connects to the board and we can start writing code.

First we need to install libraries (modules) to enable the Pico to talk to the I2C LCD screen. You can use Pip/ Mip or Pypi to install, but we encountered issues, so we chose to install by recreating the files on the Pico.

We’re using dhylands’ Python_lcd project (https://github.com/dhylands/python_lcd). Create a new blank file in Thonny, then open a browser to https://bit.ly/ LXF316dhylands and copy the contents to Thonny. Save the file to the Raspberry Pi Pico as lcd_api.py.

Create another blank file, go to https://bit.ly/ LXF316pico_i2c_lcd and copy the contents to Thonny. Save the file as pico_i2c_lcd.py to the Pi Pico.

Create another blank file to contain any passwords or API keys we need. In the file create three objects for your Wi-Fi SSID, password and your OpenWeather API key. Replace the text inside the quotation marks with your Wi-Fi details, do not delete the quotation marks as this tells Python that the data inside are strings: SSID = “WIFI SSID”

PW = “WIFI PASSWORD” openweather = “OPENWEATHER API”

How can we get an API key for OpenWeather? Take a look at the boxout (right) for more information.

This simple build shows how few components we need to build a weather station using an online API.

Save the file to the Raspberry Pi Pico as secrets.py and now we can move on to the main section of code.

Create a new blank file on the Pico and import a series of modules.