This project contains firmware for the Raspberry Pi Pico. It includes source files for core logic, display handling, and network features.
- CYW43 is the onboard network chip, we interface with this using wifi_handler.
- LWIP is used in the construction of the UDP stack.
- ST7789 and XPT2046 are the display controllers for render and touch respectively, we have a custom driver for the display.
pico_files
– All files pertaining to the Pi Picosensors
– Program for reading sensor datasrc
– Image processing and analysis algorithm
You can flash the firmware to your Raspberry Pi Pico in two main ways:
-
Build the UF2 File
Make sure you have the Pico SDK and CMake toolchain set up correctly.
cd pico_files mkdir build cd build cmake -DPICO_BOARD=pico_w -DWIFI_SSID="ssid_here" -DWIFI_PASSWORD="top_secret" .. make
After the build, you'll find the
.uf2
file in thebuild
directory. (Compiler flag for board type to be removed in a future version.) -
Put the Pico into Bootloader Mode
- Hold down the BOOTSEL button on the Pico.
- Plug it into your computer via USB.
- Release the button once it's connected.
- A new mass storage device (RPI-RP2) should appear.
-
Copy the UF2
- Drag and drop the
.uf2
file onto the RPI-RP2 drive. - The Pico will reboot and start running the flashed firmware.
- Drag and drop the
-
Build the ELF File
cd pico_files mkdir build cd build cmake ../pico_files make
This will generate a
.elf
file in thebuild
directory. -
Connect the Pico Normally (no BOOTSEL)
- Plug in the Pico (no need to hold BOOTSEL if already flashed before).
- Make sure
picotool
is installed (Install Instructions).
-
Use
picotool
to Flashsudo picotool load your_program.elf -f
-
Verify Flash
picotool info
- CMake (for pico-sdk)
- GCC for ARM (
arm-none-eabi-gcc
) - Pico SDK
picotool
(for SDK flashing, optional)- A Raspberry Pi Pico W or equivalent RP2040 device with CYW43 WiFi chip.
- If
cmake
fails, ensure the Pico SDK path is set correctly (PICO_SDK_PATH
). - If RPI-RP2 doesn’t appear, try another USB cable or port. Or Pi.
- For
picotool
to work, make surepico_enable_stdio_usb()
is set in yourCMakeLists.txt
. - You can view the debug output using a serial connection, for example:
sudo screen /dev/ttyACM0 115200
.
It's best to begin by monitoring the serial output, a delay is included in the main loop to give you time to connect and see the output. The WiFi network should connect and return an IP, Gateway and Subnet Mask. If not, please check the credentials, or use the optional scan_networks() function. (scan_networks() is not included in this version to save space, see version history, scan_networks.c.)
Once the WiFi connection is established, the program attempts to start a UDP server. The output is verbose, so if this fails, debug at the current step.
Once the UDP server is active, the display will load the default monitoring page, and you're ready to move onto the next step!
The program expects the sensors to be connected in the following arrangement:
SHT30-D I2C Temperature and Humidity Sensor: SAA - GPIO 8 SCL - GPIO 9
LDR: Connect in RC charging circuit, connect +ve leg of capacitor to GPIO 0
Moisture Sensor: As above, but connect to GPIO 2.
Relay for pump: Connect to GPIO 3.
You are now ready to run the algorithm, simply point the camera at the plant, make extension
and voila!