It's easy to use the Adafruit Bonsai Buckaroo with CircuitPython. This example uses the Adafruit CircuitPython CLUE library to display soil moisture level and the status of the pump motor on the CLUE display. Connect your Bonsai Buckaroo to your CLUE, and connect the motor and plant to the Bonsai Buckaroo, and you're on your way to automatic plant care. Let's take a look!

Wiring up your Bonsai Buckaroo

For this project, you'll need a Bonsai Buckaroo, a CLUE, a water pump, some tubing, alligator clips, and two nails (or something else conductive will work too!). It's super simple to connect them up.

  • Mount the Bonsai Buckaroo to the CLUE using the included mounting hardware.
  • Connect the red wire of the water pump to the top of the motor controller terminal.
  • Connect the black wire of the water pump to the bottom of the motor controller terminal.
  • Connect an alligator clip to the 3V pad on the Bonsai Buckaroo.
  • Connect an alligator clip to the PIN#1 pad of the Bonsai Buckaroo.
  • Connect the other end of the alligator clip wires to nails stuck into the soil of your plant.
  • Connect the tubing to the water pump
  • Place the other end of the tubing in the soil of the plant.

Wire the Pump Driver Terminal

The Bonsai Buckaroo terminal connectors are spring-loaded press-fit connectors. Push down on one tab to separate the internal connector a bit and then push in the wire. Release the pressure on the tab and the terminal will grip the wire.

Repeat for the second terminal.

The image at the top of the page shows the CLUE connected to a AA battery pack. If you find that battery pack isn't lasting long enough for your needs, consider using a larger battery, or using a USB cable plugged into the wall to provide longer usage.

Installing CircuitPython Libraries

The Adafruit CircuitPython CLUE library requires a number of other libraries to work. Please follow the instructions on the CLUE CircuitPython Libraries page to ensure you have all the necessary libraries installed.

Before continuing, ensure that your lib folder looks like the one in the CLUE guide Libraries page!

Bonsai Buckaroo Plant Care Helper

Save the following as code.py on your CIRCUITPY drive.

# SPDX-FileCopyrightText: 2020 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time
import board
import digitalio
import analogio
from adafruit_clue import clue

# Turn off the NeoPixel
clue.pixel.fill(0)

# Motor setup
motor = digitalio.DigitalInOut(board.P2)
motor.direction = digitalio.Direction.OUTPUT

# Soil sense setup
analog = analogio.AnalogIn(board.P1)

def read_and_average(analog_in, times, wait):
    analog_sum = 0
    for _ in range(times):
        analog_sum += analog_in.value
        time.sleep(wait)
    return analog_sum / times

clue_display = clue.simple_text_display(title=" CLUE Plant", title_scale=1, text_scale=3)
clue_display.show()

while True:
    # Take 100 readings and average them
    analog_value = read_and_average(analog, 100, 0.01)
    # Calculate a percentage (analog_value ranges from 0 to 65535)
    percentage = analog_value / 65535 * 100
    # Display the percentage
    clue_display[0].text = "Soil: {} %".format(int(percentage))
    # Print the values to the serial console
    print((analog_value, percentage))

    if percentage < 50:
        motor.value = True
        clue_display[1].text = "Motor ON"
        clue_display[1].color = (0, 255, 0)
        time.sleep(0.5)

    # always turn off quickly
    motor.value = False
    clue_display[1].text = "Motor OFF"
    clue_display[1].color = (255, 0, 0)

Let's take a look at the code.

First we import all the necessary libraries, and turn off the NeoPixel on the back of the board.

Next we set up the motor on Pin 2, and setup Pin 1 as an analog pin.

Then we have a helper function designed to read an analog pin, and take a number of readings over a given period of time.

The last thing we do before the loop is set up to display text on the CLUE display using the CLUE library, with the title "CLUE Plant".

Inside the loop, we first use the helper function to take 100 readings and average them. Then we use that average to calculate a percentage, and display that percentage. We also print the average and percentage to the serial console.

If the percentage is less than 50, we turn on the motor and display "Motor ON" in green, and then pause for 0.5 seconds.

Otherwise, we turn the motor off and display "Motor OFF" in red.

That's all there is to automated plant care using CircuitPython, the Bonsai Buckaroo, and CLUE!

This guide was first published on Mar 19, 2020. It was last updated on Mar 19, 2020.

This page (CLUE and CircuitPython Usage) was last updated on Mar 29, 2023.

Text editor powered by tinymce.