This article will guide you to build your weather station using a Raspberry Pi 5, the Lark Weather Station, and Qubitro. This is an exciting project that allows you to collect local climate and environmental data. Let’s dive into the details of creating the personalized weather station:
Before we begin, gather the following components:
- Raspberry Pi 5
- Lark Weather Station
- Qubitro IoT Platform (for data collection and visualization)
- Jumper wires
- Power supply for the Raspberry Pi
Let’s walk through the steps to install Raspberry Pi OS (formerly known as Raspbian) on your Raspberry Pi 5. This process will get your Pi up and running with the official supported operating system. 🍓🖥️
1️⃣Installing Raspberry Pi OS on Raspberry Pi 51. Download Raspberry Pi Imager:
- First, download the Raspberry Pi Imager installer for your operating system from the Raspberry Pi downloads page.
2. Prepare the microSD Card:
- Insert the microSD card into a card reader connected to your computer.
- Run the Raspberry Pi Imager you just installed.
3. Choose the Pi Version:
- Launch the image and click on “Choose Device”.
- Select “Raspberry Pi version” from the list.
4. Choose the Operating System:
- Next, click on “Choose OS”.
- Select “Raspberry Pi OS” from the list.
5. Select the microSD Card:
- Choose the microSD card you want to install Raspberry Pi OS on.
- Double-check that it’s the correct drive, as this process will select the card.
- Then click next and choose the customization you want.
- Click ok Edit Settings, and enter the wifi and user credentials.
6. Flash the Image:
- Confirm the image and the drive.
- Click “Flash” to write the Raspberry Pi OS image to the microSD card.
7. Eject and Insert the microSD Card:
- Eject the microSD card from your computer once it finishes the writing.
- Insert it into your Raspberry Pi 5.
8. Boot Up Your Raspberry Pi:
- Connect your Raspberry Pi 5 to a monitor, keyboard, mouse, and power supply.
8. Optional: Update Software:
Once the setup is complete, you can optionally update the software using the terminal:
sudo apt update
sudo apt upgrade
9. Enjoy Your Raspberry Pi 5:
- Your Raspberry Pi 5 is now running Raspberry Pi OS!
- Connect the Raspberry Pi to monitor and explore the desktop features.
- The Lark Weather Station typically includes sensors for temperature, humidity, pressure, and wind speed and direction also it allows us to add some additional sensors.
- Connect the Lark sensors to the Raspberry Pi GPIO pins 2 and 3.
- Here we are going to use the i2c communication.
Enabling the I2C on Raspberry Pi 5:
- Before executing the script, we need to enable the I2C on Raspberry Pi.
Run sudo raspi-config on the terminal
- Then select the interface setting.
- Enable the I2C and reboot the Pi.
Python Script:
- Next, we have to clone the Python library for the Lark weather station from DFRobot's Git Hub.
- Run the below command to copy the Lark library to the Raspberry Pi.
git clone https://github.com/DFRobot/DFRobot_LarkWeatherStation
- This library uses
RPi.GPIO
to interface with the GPIO pins to read the I2C data. - Navigate to the Python examples and this example script will read temperature, humidity, pressure, speed, and direction from the Lark.
Test the Sensors:
- Run your Python script to verify that the sensors are working correctly.
python get_data.py
- It will print the sensor readings to the console for testing purposes.
Create an Account:
- Sign up for an account on the Qubitro website.
Create a Project & Device:
- In Qubitro, create a new project and device for your weather station.
- Note down the device ID and access token.
Look at my previous tutorial to get to know more about Qubitro
Testing a demo project:
- Before going to send our sensor data, first, let's check the connection using the demo sketch which you can refer to from your project.
- Click on the code snippet copy the Python sketch and paste it on the Raspberry Pi.
- Install Paho MQTT on the RPI.
pip install paho-mqtt
- Finally, run the Qubitro script.
- Let's check our data in the Qubitro portal.
Final Integration:
- Execute the below python sketch this can directly send our Lark data to Qubitro.
- Finally, look at the Qubitro portal you can see the incoming sensor data
from __future__ import print_function
import sys
import os
sys.path.append("../")
import time
import paho.mqtt.client as mqtt
import json
import time
import ssl
from DFRobot_LarkWeatherStation import *
ADDRESS = 0x42
# I2C mode
EDU0157 = DFRobot_LarkWeatherStation_I2C(ADDRESS)
broker_host = "broker.qubitro.com"
broker_port = 8883
device_id = ""
device_token = ""
payload={}
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to Qubitro!")
client.on_subscribe = on_subscribe
client.on_message = on_message
else:
print("Failed to connect, visit: https://docs.qubitro.com/platform/mqtt/examples return code:", rc)
def on_subscribe(mqttc, obj, mid, granted_qos):
print("Subscribed, " + "qos: " + str(granted_qos))
def on_message(client, userdata, message):
print("received message =",str(message.payload.decode("utf-8")))
def on_publish(client, obj, publish):
print("Published: " + str(payload))
client = mqtt.Client(client_id=device_id)
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
client.tls_set_context(context)
client.username_pw_set(username=device_id, password=device_token)
client.connect(broker_host, broker_port, 60)
client.on_connect = on_connect
client.on_publish = on_publish
client.subscribe(device_id, 0)
client.loop_start()
#uart mode
#EDU0157 = DFRobot_LarkWeatherStation_UART()
def setup():
while EDU0157.begin() != 0:
print("Sensor initialize failed!!")
time.sleep(1)
print("Sensor initialize success!!")
EDU0157.set_time(2023,1,11,23,59,0)
time.sleep(1)
def loop():
print("------------------")
print("Speed=",EDU0157.get_value("Speed"),EDU0157.get_unit("Speed"))
print("DIR=",EDU0157.get_value("Dir"))
print("Temp=",EDU0157.get_value("Temp"),EDU0157.get_unit("Temp"))
print("Humi=",EDU0157.get_value("Humi"),EDU0157.get_unit("Humi"))
print("Temp=",EDU0157.get_value("Pressure"),EDU0157.get_unit("Pressure"))
print("Humi=",EDU0157.get_value("Altitude"),EDU0157.get_unit("Altitude"))
print(EDU0157.get_information(True))
tmp=float(EDU0157.get_value("Speed"))
tmp1=float(EDU0157.get_value("Temp"))
tmp2=float(EDU0157.get_value("Humi"))
tmp3=float(EDU0157.get_value("Pressure"))
tmp4=float(EDU0157.get_value("Altitude"))
payload = {"Speed": tmp,"Temp": tmp1,"Humi": tmp2,"Pressure":tmp3,"Altitude":tmp4 }
client.publish(device_id, payload=json.dumps(payload))
time.sleep(1)
if __name__ == "__main__":
setup()
while True:
loop()
5️⃣Visualize DataQubitro Dashboard:
- Log in to your Qubitro account navigate to the dashboard and create a new dashboard.
- Create widgets to display temperature, humidity, and pressure data.
- Customize the dashboard layout to your liking.
Real-Time Updates:
- Qubitro provides real-time data visualization.
- Monitor your weather station’s data from anywhere using the Qubitro dashboard or mobile dashboard.
Weatherproof Enclosure: If you plan to deploy your weather station outdoors, consider using a weatherproof enclosure for your Raspberry Pi 5.
Power Supply: Use a reliable power supply for continuous operation. Solar panels with battery backup are ideal for remote locations.
🌎ConclusionBuilding your own weather station is an excellent project that combines hardware, software, and data visualization. With the Raspberry Pi 5, Lark Weather Station, and Qubitro, you’ll have a powerful setup to monitor local weather conditions. Happy making! 🌦️🌡️💨
Comments