Learning Outcome
In this chapter, we learn to
program light sensor to measure ambient brightness.
program AHT20 sensor for humidity and temperature measurement.
perform basic data logging on Raspberry Pi Pico W local storage.
Introduction: Light Sensor, Humidity and Temperature Sensor, and Data Logging.
Activities: Build a climate control greenhouse while integrating temperature and humidity sensor, light sensor, DC and servo motor, NeoPixel and OLED.
Bonus: Program an IoT enabled greenhouse with data logging capability.
Introduction to Light Sensor
By now you have probably noticed the APDS9960 sensor on the EDU PICO offers several advantages for your project. Here's one last feature we have yet to explore from this powerful sensor, it is none other than the commonly used, light sensor. In this activity, we will learn how to measure different level of ambient light, allowing you to create project that respond to changes in lighting conditions!
> Libraries <
-> Libraries: board, time, digitalio, adafruit_apds9960.
-> Light Sensor I2C Pins Configuration: SCL = GP5 and SDA = GP4.
-> Input:
Shine light to the light sensor to increase the brightness level.
Block light from entering the light sensor to decrease the brightness level.
< Expected Output >
Upon completion of the activity, you should be able to:
-> The program will print brightness percentile in shell console.
Introduction to
Temperature & Humidity Sensor (AHT20)
Temperature & Humidity Sensor (AHT20)
The AHT20 sensor is a powerful component that provides accurate measurements for both humidity and temperature. Imagine having the ability to monitor and respond to changes in your project's environment, whether its a home automation system, a weather station, or a smart gardening project.
> Libraries <
-> Libraries: board, time, digitalio, adafruit_ahtx0.
-> AHT20 I2C Pins Configuration: SCL = GP5 and SDA = GP4.
< Expected Output >
Upon completion of the activity, you should be able to:
-> Program will print temperature in Celcius and relative humidity percentile in the shell console.
-> Enable view > plotter in Thonny IDE to allow you to visualize the temperature and humidity data in the same graph, making graph analysis easier.
Climate Control Greenhouse
In this project, you will learn how to construct a control system that regulates the humidity and temperature of a closed greenhouse environment. To achieve that, you are required to integrate AHT20 temperature humidity sensor and APDS9960 light sensor as input devices; RGB LEDs (for light), servo motor (for rooftop control), DC motor (for the fan), and OLED screen for printing the greenhouse status.
> Libraries <
-> Libraries: board, busio, time, adafruit_ssd1306, neopixel, PWMOut, adafruit_ahtx0, adafruit_motor, adafruit_apds9960.
-> I2C Pins Configuration: SCL = GP5 and SDA = GP4.
APDS9960 light sensor, AHT20 temperature humidity sensor, and SSD1306 OLED share similar I2C pins configuration.
-> Input:
Shine a light on the APDS9960 light sensor to simulate surrounding brightness in the greenhouse.
Test the AHT20 temperature humidity sensor by placing your finger on the sensor module. The temperature should rise gradually.
< Expected Output >
Upon completion of the activity, you should be able to:
-> If the surroundings are bright, the RGB LEDs remain off; whereas if the surroundings are dark, the RBG LEDs will light up in violet.
-> If the surroundings are hot, the servo will activate to 60 degrees (opening the rooftop), and the DC motor fan will activate to ventilate the area to cool down the environment.
< Components >
Introduction to Internet of Things (IOT)
Imagine if everyday objects could connect to the internet and communicate with each other. IoT is all about linking things together via the internet to make them smarter and more useful. In this activity, we will turn the EDU PICO into an Iot-enabled device by reading the Raspberry Pi Pico W onboard temperature and controlling the EDU PICO's USB relay output through a webpage.
> Libraries <
-> Libraries: board, digitalio, wifi, socketpool, os, adafruit_httpserver, microcontroller.
-> USB Relay Configuration:
Assign to GP22, and connect USB light stick to the USB port.
-> Create Wifi configuration file "settings.toml":
Enable view > File name extensions to show the file extension.
Create a new Text Document in the CircuitPython drive and name the Text Document as "settings.toml"
Type the text below and replace "your_wifi_ssid" with your WiFi ID and "your_wifi_password" with your WiFi password.
Save the file, you're all set!
[Note: If you want to use AP-Mode (Chapter 7 Bonus) on the Raspberry Pi Pico W, make sure to delete the settings.toml file.]
-> Connect your PC to WiFi:
Connect your PC to the same WiFi network as connected by the Raspberry Pi Pico W.
< Expected Output >
Upon completion of the activity, you should be able to:
-> The program begins by connecting to the WiFi with the SSID and Password preset in the settings.toml file.
-> Type your IP address into your browser.
-> Clicking the buttons will send a signal to either turn ON or OFF the USB relay.
-> Message like "Light ON" and "Light OFF" will be printed on the shell console when the buttons are clicked.
Introduction to Data Logging
In this topic, we will learn how to use CircuitPython to read the Raspberry Pi Pico W internal temperature data and write it to a file on the CircuitPython drive. This will enable you to create your own temperature data logger.
> Libraries <
-> Libraries: boot.py, board, digitalio, time, microcontroller, os.
-> Data Logging Configuration File:
Create a new Python script named boot.py and type in the code provided.
Save boot.py in the CircuitPython drive.
Flip the "LOG DATA TO PICO'S FLASH" switch to "ENABLE".
NOTE: The CircuitPython drive will become non-writable when data logging mode is enabled. This means you won't be able to save, create a new file, or delete files in the CircuitPython drive.
Restart your EDU PICO by pressing the Reset (RST) button.
The boot_out.txt file will appear in the CIRCUITPY drive, you will see "boot.py output:" inside the text file.
Execute the BONUS_DATALOGGING.py code to start the data logger. The Pico will record 1 temperature data point every 1 second.
< CircuitPython Code >
< Expected Output >
Upon completion of the activity, you should be able to:
-> After resetting the EDU PICO, a file named temperature.csv will appear in the CircuitPython drive.
CONGRATULATIONS!
You have completed your educational journey.
We can't wait to see what you will be building with the EDU PICO