You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/projects/make-a-plant-watering-robot.md
+19-79Lines changed: 19 additions & 79 deletions
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ Make sure your Pi is flashed with a Viam-compatible operating system, and that y
58
58
## Set up your plant watering robot
59
59
60
60
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.
62
62
63
63
### Full wiring diagram
64
64
@@ -140,7 +140,7 @@ You can either bend or soldier the jumper wire here to make the connection betwe
140
140
141
141
{{% /alert %}}
142
142
143
-
## Program your plant watering robot
143
+
## Get ready to program your plant watering robot
144
144
145
145
{{<gifwebm_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.">}}
146
146
@@ -170,17 +170,22 @@ Now, select **Yes** to enable SPI:
170
170
Finally, select **Finish**.
171
171
Restart your Pi using `sudo reboot` to make these changes take effect.
172
172
173
-
### Test your soil moisture readings on your Pi
173
+
### Install the Python SDK
174
174
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/).)
176
176
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:
178
178
179
179
```shell
180
180
sudo apt update
181
181
sudo apt upgrade
182
182
```
183
183
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
+
184
189
Make sure you have `pip` installed for Python 3:
185
190
186
191
```shell
@@ -193,78 +198,12 @@ If not, run the following command:
193
198
sudo apt install python3-pip
194
199
```
195
200
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:
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
-

267
-
268
207
### Configure the components of your robot in the Viam app
269
208
270
209
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:
393
332
394
333
{{% snippet "show-secret.md" %}}
395
334
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.
397
336
5. Name the file <file>plant-watering-robot.py</file>, and save it.
398
337
399
338
For example, run the following commands on your Pi to create and open the file:
400
339
401
340
```shell
402
-
cd plant-watering-robot
341
+
source .venv/bin/activate
403
342
touch plant-watering-robot.py
404
343
nano plant-watering-robot.py
405
344
```
@@ -426,7 +365,7 @@ while True:
426
365
readings =await sensor.get_readings()
427
366
soil_moisture = readings.get('moisture')
428
367
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
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.
461
401
Also, consider how often you would like to check the moisture levels of the plant, and how long the plant should be watered.
0 commit comments