Skip to content

Commit f18e040

Browse files
authored
Update make-a-plant-watering-robot.md
took out the test part
1 parent 00264ef commit f18e040

File tree

1 file changed

+19
-79
lines changed

1 file changed

+19
-79
lines changed

docs/tutorials/projects/make-a-plant-watering-robot.md

Lines changed: 19 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Make sure your Pi is flashed with a Viam-compatible operating system, and that y
5858
## Set up your plant watering robot
5959

6060
Before programming the Pi to make the plant watering robot functional, you need to physically set up the plant watering robot by wiring the different components together.
61-
You will set up the robot to receive signals from the resistive soil moisture sensor and signal to the peristaltic pump when it is time to pump water from the water's container to the plant's container.
61+
You will set up the robot to receive signals from the resistive soil moisture sensor and signal to the peristaltic pump when it is time to pump water from the water container to the plant's container.
6262

6363
### Full wiring diagram
6464

@@ -140,7 +140,7 @@ You can either bend or soldier the jumper wire here to make the connection betwe
140140

141141
{{% /alert %}}
142142

143-
## Program your plant watering robot
143+
## Get ready to program your plant watering robot
144144

145145
{{<gif webm_src="/tutorials/plant-watering-pi/plant-watering-video.webm" mp4_src="/tutorials/plant-watering-pi/plant-watering-video.mp4" alt="The plant watering robot on a white desk. Camera goes up to the watering tube and pulls it out, showing the drip.">}}
146146

@@ -170,17 +170,22 @@ Now, select **Yes** to enable SPI:
170170
Finally, select **Finish**.
171171
Restart your Pi using `sudo reboot` to make these changes take effect.
172172

173-
### Test your soil moisture readings on your Pi
173+
### Install the Python SDK
174174

175-
Next, install the Adafruit ADC library [`Adafruit_CircuitPython_MCP3xxx`](https://github.com/adafruit/Adafruit_CircuitPython_MCP3xxx/) on your Pi.
175+
Next, set up a virtual environment and install the SDK. (If you want to read more on virtual environments, check out [the documentation](https://docs.viam.com/build/program/python-venv/).)
176176

177-
Before installation, make sure any packages on your Pi are up to date:
177+
Make sure any packages on your Pi are up to date, while connected to your Pi with SSH run:
178178

179179
```shell
180180
sudo apt update
181181
sudo apt upgrade
182182
```
183183

184+
Then run the following command to create and activate the virtual environment:
185+
186+
python3 -m venv .venv
187+
source .venv/bin/activate
188+
184189
Make sure you have `pip` installed for Python 3:
185190

186191
```shell
@@ -193,78 +198,12 @@ If not, run the following command:
193198
sudo apt install python3-pip
194199
```
195200

196-
Run the following command while connected to your Pi with SSH to install [`Adafruit_CircuitPython_MCP3xxx`](https://github.com/adafruit/Adafruit_CircuitPython_MCP3xxx/):
197-
198-
```shell
199-
sudo pip3 install adafruit-circuitpython-mcp3xxx
200-
```
201-
202-
Create a new directory for your plant watering robot's files and navigate to this directory in your terminal session.
203-
For example, run the following commands:
204-
205-
```shell
206-
mkdir plant-watering-robot
207-
cd plant-watering-robot
208-
```
209-
210-
After navigating to this directory, create a new Python file called <file>adctesting.py</file> and open up the file.
211-
For example, run the following commands:
212-
213-
```shell
214-
touch adctesting.py
215-
nano adctesting.py
216-
```
217-
218-
Now, add the following Python code to <file>adctesting.py</file> to test reading values from your resistive soil moisture sensor through your MCP3008 ADC:
219-
220-
```python
221-
import time
222-
import busio
223-
import digitalio
224-
import board
225-
import adafruit_mcp3xxx.mcp3008 as MCP
226-
from adafruit_mcp3xxx.analog_in import AnalogIn
227-
228-
# Create the SPI bus
229-
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
230-
231-
# Create the cs (chip select)
232-
cs = digitalio.DigitalInOut(board.D8)
233-
234-
# Create the MCP3008 object
235-
mcp = MCP.MCP3008(spi, cs)
236-
237-
# Create an analog input channel on Pin 0
238-
chan = AnalogIn(mcp, MCP.P0)
239-
240-
print('Reading MCP3008 values, press Ctrl-C to quit...')
241-
while True:
242-
print('Raw ADC Value: ', chan.value)
243-
time.sleep(1)
244-
```
245-
246-
Run the code as follows:
201+
Run the following command to install the SDK:
247202

248203
```shell
249-
sudo python3 adctesting.py
204+
pip3 install viam-sdk
250205
```
251206

252-
{{% alert title="Tip" color="tip" %}}
253-
254-
If running this code returns `ImportError: No module named busio`, try again after reinstalling `adafruit-blinka`:
255-
256-
```shell
257-
sudo pip3 install --force-reinstall adafruit-blinka
258-
```
259-
260-
{{% /alert %}}
261-
262-
Now, you should see the moisture sensor values outputted by the MCP3008.
263-
264-
Test your sensor by putting it in air, water, and different soils to see how the values change to determine your baseline for wet and dry values.
265-
266-
![Terminal output of resistive soil moisture sensor values.](/tutorials/plant-watering-pi/moisture-sensor-output.png)
267-
268207
### Configure the components of your robot in the Viam app
269208

270209
Follow [this guide](/get-started/installation/#install-viam-server) to install `viam-server` on your Pi, create a new robot, and connect to it on [the Viam app](https://app.viam.com).
@@ -393,13 +332,13 @@ Follow these instructions to start working on your Python control code:
393332

394333
{{% snippet "show-secret.md" %}}
395334

396-
4. Paste this code sample into a new file in the `plant-watering-robot` directory you created on your Pi.
335+
4. Paste this code sample into a new file in the virtual directory you created on your Pi.
397336
5. Name the file <file>plant-watering-robot.py</file>, and save it.
398337

399338
For example, run the following commands on your Pi to create and open the file:
400339

401340
```shell
402-
cd plant-watering-robot
341+
source .venv/bin/activate
403342
touch plant-watering-robot.py
404343
nano plant-watering-robot.py
405344
```
@@ -426,7 +365,7 @@ while True:
426365
readings = await sensor.get_readings()
427366
soil_moisture = readings.get('moisture')
428367

429-
# Calculate average moisture reading from the list of readings, to account
368+
# Calculate the average moisture reading from the list of readings, to account
430369
# for outliers
431370
avg_moisture = sum(soil_moisture) / len(soil_moisture)
432371

@@ -435,18 +374,17 @@ while True:
435374
if (avg_moisture > 60000):
436375
print('this plant is too thirsty! giving it more water')
437376

438-
# Run the water pump for 100 rev. at 1000 rpm
377+
# Run the water pump for 100 revs. at 1000 rpm
439378
await water_pump.go_for(rpm=1000, revolutions=100)
440379

441380
# Wait 60 seconds so that the water can soak into the soil a bit before
442381
# trying to water again
443-
print('waiting a little bit for water to soak in')
382+
print('waiting a little bit for the water to soak in')
444383
time.sleep(60)
445384
```
446385

447386
{{% alert title="Tip" color="tip" %}}
448387
Make sure to import `time` at the beginning of your version of <file>plant-watering-robot.py</file> to be able to use `sleep()`!
449-
Also, make sure to import `viam.components.sensor`.
450388
{{% /alert %}}
451389

452390
See the motor component's [API documentation](/components/motor/#gofor) for more information about `water_pump.go_for()`.
@@ -458,6 +396,8 @@ sudo python3 plant-watering-robot.py
458396
```
459397

460398
To tinker this example code to work best for you, determine at what [analog value from the soil moisture readings](#test-your-soil-moisture-readings-on-your-pi) you want to water your plant, as your thirsty plant's average moisture reading might differ from our example value of `60000`.
399+
400+
Test your sensor by putting it in air, water, and different soils to see how the values change to determine your baseline for wet and dry values.
461401
Also, consider how often you would like to check the moisture levels of the plant, and how long the plant should be watered.
462402

463403
## Next steps

0 commit comments

Comments
 (0)