Reader small image

You're reading from  Raspberry Pi Pico DIY Workshop

Product typeBook
Published inMay 2022
PublisherPackt
ISBN-139781801814812
Edition1st Edition
Right arrow
Authors (2):
Sai Yamanoor
Sai Yamanoor
author image
Sai Yamanoor

Sai Yamanoor is an embedded systems engineer working for a private startup school in the San Francisco Bay Area, where he builds devices that help students achieve their full potential. He completed his undergraduate work in mechatronics engineering from Sri Krishna College of Engineering and Technology, Coimbatore, India and his graduate studies in mechanical engineering at Carnegie Mellon University, Pittsburgh PA. His interests, deeply rooted in DIY and open software and hardware cultures, include developing gadgets and apps that improve the quality of life, Internet of Things, crowdfunding, education, and new technologies. In his spare time, he plays with various devices and architectures, such as the Raspberry Pi, Arduino, Galileo, Android devices and others. Sai has earlier published a book titled Raspberry Pi Mechatronics Projects.
Read more about Sai Yamanoor

Srihari Yamanoor
Srihari Yamanoor
author image
Srihari Yamanoor

Srihari Yamanoor is a mechanical engineer, working on medical devices, sustainability, and robotics in the San Francisco Bay Area. He completed his undergraduate studies in mechanical engineering from PSG College of Technology, Coimbatore, India and graduate studies in mechanical engineering at Stanford University. He is certified in SolidWorks, simulation, sustainable design, PDM as well as in quality and reliability engineering and auditing. His has a wide range of interests, from DIY, crowdfunding, AI, travelling, photography to gardening and ecology.
Read more about Srihari Yamanoor

View More author details
Right arrow

Chapter 4: Fun with Gardening!

In this chapter, we will discuss interfacing a soil sensor to a Raspberry Pi Pico and publishing the soil moisture and temperature values to ThingSpeak (https://thingspeak.com), an Internet of Things (IoT) platform that enables you to visualize collected data. By the end of this chapter, you should be able to build something like this:

Figure 4.1 – Fun with gardening

In the preceding photo, a STEMMA soil sensor from Adafruit Industries is inserted next to a small potted plant. The soil sensor is interfaced to a Raspberry Pi Pico. The Pico is mounted onto a Dual Expander pack. A Pico wireless pack is interfaced to the left of the Pico for uploading soil moisture values to ThingSpeak.

We are going to discuss the following topics in this chapter:

  • Why gardening?
  • Installing the requisite libraries
  • Setting up the soil sensor
  • Setting up the wireless pack
  • Setting up the NeoPixel light-emitting diode ...

Technical requirements

The following hardware is recommended for this chapter:

You will also need a potted plant of your choice. The code samples for this chapter are available at the following link: https://github.com/PacktPublishing/Raspberry-Pi-Pico-DIY-Workshop/tree/main/chapter_04.

Code in Action videos for this chapter can be viewed at https://bit.ly/3w3CqY9.

CircuitPython Installation

We are assuming that you have installed CircuitPython on your Pico. If you are not familiar with the installation...

Why gardening?

Why did we choose gardening for our project in this chapter?

Gardening is one of the oldest hobbies. It has periods of upswings, as was the case with the pandemic. While gardening can be embraced at many levels, technology can enhance it, reduce fear of failure, and serve as an educational tool. Sensors and response mechanisms such as watering or lighting tools can help with plants that require extra care, including some houseplants, water plants, orchids, and bonsai trees.

Besides being a generic hobby, gardening can also be used to grow food efficiently in resource-starved environments such as urban settings. With more people living in such settings, it is increasingly important for people to be able to grow at least some of their own food. Homegrown food can also lead to healthy eating and living habits and provide other advantages such as reducing stress and improving mental health. Gardening and urban agriculture on any scale can also help endangered bees...

Installing the requisite libraries

In this section, we will install the requisite libraries needed for interfacing the soil sensor, NeoPixel LED, and the wireless pack to the Raspberry Pi Pico. The libraries are all part of the Adafruit CircuitPython bundle. The latest bundle can be downloaded as a ZIP file from https://circuitpython.org/libraries. We used the bundle version meant for CircuitPython 6.x.x.

After downloading the ZIP file, extract its contents so that we can copy the libraries we need for the project.

Soil sensor

We are using a capacitive soil sensor based on the Adafruit seesaw framework. You can see this in the following screenshot:

Figure 4.2 – Capacitive soil sensor from Adafruit

If you are not familiar with Adafruit seesaw, this is a framework that enables the interfacing of any type of sensor, drive motor, control pulse-width modulation (PWM) output, and so on via the I2C interface. This is especially helpful in scenarios...

Setting up the soil sensor

In this section, we will interface and test the soil sensor to the Pico. A Fritzing schematic of the soil sensor is shown here:

Figure 4.5 – Fritzing schematic to interface the soil sensor to the Pico

Pico Pinout

A pinout reference card for the Pico will come in handy while wiring up components. We provided a link to the pinout card in Chapter 1, Getting Started with the Raspberry Pi Pico.

The soil sensor comes with an I2C interface, and the STEMMA soil sensor connector consists of four pins—namely SCL, SDA, VIN, and GND. If you are not familiar with the I2C interface, we recommend reading Chapter 2 of this book, Serial Interfaces and Applications. In the Fritzing schematic, looking from left to right, the soil sensor is connected to the Pico as follows:

  • SCL to the GP9 pin of the Pico.
  • SDA to the GP8 pin of the Pico.
  • VIN to the 3.3V pin of the Pico.
  • The GND pins are tied together.

    Pull-Up Resistors...

Setting up the wireless pack

In this section, we will discuss setting up and testing the wireless pack. For the sake of convenience, we will make use of Pico Omnibus (Dual Expander) from Pimoroni. The Pico and the wireless pack are mounted onto the expander, as shown in the following screenshot:

Figure 4.7 – Pico and wireless pack mounted onto Pico Omnibus (Dual Expander)

Breadboard Connections

If you don't have an expander, the following pins are used to communicate with the ESP32: CS → GP7; Ready → GP10; Reset → GP11; Clock → GP18; Master Out Slave In (MOSI) → GP19; Master In Slave Out (MISO) → GP16. A Fritzing schematic of the interface is shown here:

Figure 4.8 – Interfacing an ESP32 co-processor to the Raspberry Pi Pico

To connect to a Wi-Fi network using the wireless pack, create a file called secrets.py on your Pico and store the following information in it:

...

Setting up the NeoPixel LED

In this section, we will interface and test a NeoPixel LED. We are adding an LED to the project because it could be used as a visual aid to let you know if your soil is too dry. If you are not familiar with NeoPixel LEDs, these are individually addressable RGB LEDs. You can find more information about them here: https://bit.ly/3sin0x5.

The NeoPixel is connected to GP0, as shown in Figure 4.7. The connections between the Pico and the NeoPixel are listed as follows:

  • GP0 → In pin of NeoPixel.
  • VBUS → + pin.
  • The GND pins are tied together.

An interface diagram is shown here:

Figure 4.10 – NeoPixel interface to the Pico

Now, let's test if everything is in working order. The first step is to import the requisite modules, as follows:

import time
import board
import neopixel

Now, let's initialize an object belonging to the Neopixel class by running the following code:

pixel_pin...

Publishing data to ThingSpeak

In this section, we will discuss publishing our data to ThingSpeak. If you are not familiar with ThingSpeak, this is an open source software that enables the uploading of data from devices with internet connectivity, such as in our current project. This enables data to be collected from sensors and then analyzed. We chose ThingSpeak as an example of the various toolsets available for developers. Create a free account on https://thingspeak.com and create a new channel, as illustrated in the following screenshot:

Figure 4.12 – Creating a new channel

Give a name to your channel, fill in Field 1 (as shown in the following screenshot), and save the channel:

Figure 4.13 – Naming the channel

The channel has now been created. Make a note of the Write API Key value from the API Keys tab, as illustrated in the following screenshot:

Figure 4.14 – Recording the Write API Key value

Figure 4.14 – Recording the Write...

Putting it all together

Once you have adjusted the thresholds, insert the soil sensor next to your potted plant and power up your Pico. You should have something that looks like this:

Figure 4.15 – Fun with gardening

You can also monitor your published data on ThingSpeak, as illustrated in the following screenshot:

Figure 4.16 – Soil sensor data

ThingSpeak is an analytics platform that lets you aggregate data from your sensors. You can expand this project by creating a dashboard for all the sensors in your garden and remotely control valves from your dashboard. Platforms such as ThingSpeak enable scaling from one sensor to an array of sensors and actuators.

Summary

In this chapter, we discussed interfacing a soil sensor to the Pico and monitoring the moisture levels of potted plants. We also discussed publishing the moisture level to ThingSpeak and triggering an LED when the moisture falls below a certain threshold. This project demonstrates the use of the Pico in gardening activities. You could take this project further by turning on a sprinkler valve when the moisture levels fall below a certain threshold. You could also change the NeoPixel behavior based upon the measured moisture levels—for example, you could make use of a NeoPixel LED strip and make it glow amber when your plant needs watering.

In the next chapter, we will discuss building a weather station using the Pico!

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Pico DIY Workshop
Published in: May 2022Publisher: PacktISBN-13: 9781801814812
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Sai Yamanoor

Sai Yamanoor is an embedded systems engineer working for a private startup school in the San Francisco Bay Area, where he builds devices that help students achieve their full potential. He completed his undergraduate work in mechatronics engineering from Sri Krishna College of Engineering and Technology, Coimbatore, India and his graduate studies in mechanical engineering at Carnegie Mellon University, Pittsburgh PA. His interests, deeply rooted in DIY and open software and hardware cultures, include developing gadgets and apps that improve the quality of life, Internet of Things, crowdfunding, education, and new technologies. In his spare time, he plays with various devices and architectures, such as the Raspberry Pi, Arduino, Galileo, Android devices and others. Sai has earlier published a book titled Raspberry Pi Mechatronics Projects.
Read more about Sai Yamanoor

author image
Srihari Yamanoor

Srihari Yamanoor is a mechanical engineer, working on medical devices, sustainability, and robotics in the San Francisco Bay Area. He completed his undergraduate studies in mechanical engineering from PSG College of Technology, Coimbatore, India and graduate studies in mechanical engineering at Stanford University. He is certified in SolidWorks, simulation, sustainable design, PDM as well as in quality and reliability engineering and auditing. His has a wide range of interests, from DIY, crowdfunding, AI, travelling, photography to gardening and ecology.
Read more about Srihari Yamanoor