Giter Site home page Giter Site logo

greenico's Introduction

Greenico on Raspberry Pi Pico

Weather station with Raspberry Pi Pico - "Greenico"

Greenico on Raspberry Pi Pico is only a part of Greenico project.

The second part is GreenicoAPI. Be sure to check it out also.

Table of contents

  1. The purpose of the project
  2. Schema
  3. Description
  4. Technical information
  5. Contact

Purpose

The aim of the project is to allow the user to view the current state of the weather by designing and building a weather station. The preview will be possible through a browser, i.e. a web application in the form of clear graphs and on the display attached to the weather station.

Schema

img.png

Schema is in polish

Description

The purpose of the project was to build a platform that allows the user to observe the current conditions of weather. For this purpose, it was decided to use the Raspberry Pi Pico W microcontroller with the kit of environmental sensors and an OLED display. In addition, to make it easier to view the results, they were supposed to be sent over the network to a server where the results would be stored in a database and displayed in an accessible way in the form of graphs. As part of the project, it was possible to build and program a weather station that performs measurements with appropriate sensors. These are measurements of air pollution, temperature, humidity, illuminance, atmospheric pressure and UV. Current measurements are displayed on the OLED display attached to the weather station and sent over the network to the server via the HTTP protocol (REST).

Technical

Technologies used

Hardware platform used
Raspberry Pi Pico W programmed in MicroPython

Sensors
TSL25911FN, BME280, LTR390-UV-1, SGP40

Display
2.23inch OLED Display Module for Raspberry Pi Pico

The most important code snippets with comments

import network
import urequests
import ujson
import utime
from machine import I2C, Pin
import config
from oled_display.oled_spi import OLED_2inch23
from environmentSensor.BME280 import BME280  # pressure, temp, hum
from environmentSensor.LTR390 import LTR390  # UV
from environmentSensor.SGP40 import SGP40
from environmentSensor.TSL2591 import TSL2591
from environmentSensor.voc_algorithm import VOCAlgorithm

At the beginning of the program, the appropriate libraries should be imported - first available directly in MicroPython and then files from the project:

  • config, which contains the SSID and password for the wifi network, as well as the server address
  • oled_spi from the oled_display directory, where there is a class that facilitates work with the OLED display
  • classes from the environmentSensor directory that facilitate working with sensors
  • voc_algorithm from the environmentSensor directory where the responsible class is located converting readings from SGP40 sensor to VOC index
bme280 = BME280()
bme280.get_calib_param()
light = TSL2591()
sgp = SGP40()
uv = LTR390()
voc = VOCAlgorithm()
voc.vocalgorithm_init()

Create appropriate objects for sensors and initialize them if necessary

screen = OLED_2inch23()
screen.fill(screen.black)
screen.text(f'Conn to wifi...', 1, 12, screen.white)
screen.show()

Creating an object for the OLED display and displaying the inscription about connecting to the network wireless.

lan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(config.ssid, config.password)

Connecting to the wireless network (later in the program, the correctness of the connection is checked)

Main loop:

for i in range(20):
    bme = bme280.readData()
    pressure.append(round(bme[0], 2))
    temp.append(round(bme[1], 2))
    hum.append(round(bme[2], 2))
    lux.append(round(light.Lux(), 2))
    uvs.append(round(uv.UVS(), 2))
    gas_raw.append(round(sgp.raw(), 2))
    screen.fill(screen.black)
    screen.text(f'Data gathering' + '.' * (i % 3), 1, 12, screen.white)
    screen.show()
    utime.sleep(4)

Getting the readings from the sensors (then the program rejects the values of the largest and the smallest and averaging of the readings taken) and displaying information about data collection on display.

post_data = ujson.dumps({
    "id": 1,
    "temperature": temp,
    "humidity": hum,
    "pressure": pressure,
    "voc": gas,
    "uv": uvs,
    "light": lux
})
r = urequests.post(f"{config.URL_API}/api/reading", headers={'content-type':
                                                                 'application/json'}, data=post_data)
r.close()

Preparing data to be sent to the server using the ujson library and sending them using urequests library. Closing the variable storing data obtained in response from the server.

for i in range(48):
    if i % 2:
        screen.fill(screen.black)
        screen.text(f'Temp: {temp}', 1, 2, screen.white)
        screen.text(f'Hum: {hum}', 1, 12, screen.white)
        screen.text(f'Pres: {pressure}', 1, 22, screen.white)
        screen.show()
    else:
        screen.fill(screen.black)
        screen.text(f'VOC: {gas}', 1, 2, screen.white)
        screen.text(f'UV: {uvs}', 1, 12, screen.white)
        screen.text(f'Light: {lux}', 1, 22, screen.white)
        screen.show()
    utime.sleep(5)

Displaying of retrieved values on the display.

End of main loop

How to run the app

  1. Download .uf2 file with MicroPython for Raspberry Pi Pico W binary on your computer from Micropython with urequests and upip
  2. Follow steps from documentation-,Then%20go%20ahead%20and%3A,-Push%20and%20hold)
  3. Upload environmentSensor and oled_display folders to your Pico.
  4. Create config.py file which should look like this:
ssid = "YOUR_SSID"
password = "YOUR_PASSWORD"
URL_API = "URL_OF_SERVER"
  1. Flash main.py file to your Pico.
  2. Done!

Contact

Contact me at:
[email protected]

greenico's People

Contributors

anras5 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.