diff --git a/extra/Grove_Capacitive_Soil_Moisture_Sensor.ipynb b/extra/Grove_Capacitive_Soil_Moisture_Sensor.ipynb new file mode 100755 index 0000000..337fb15 --- /dev/null +++ b/extra/Grove_Capacitive_Soil_Moisture_Sensor.ipynb @@ -0,0 +1,268 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Grove Soil Moisture Sensor\n", + "\n", + "This example shows how to use the Grove Corrosion-resistant Capacitive Soil Moisture Sensor.\n", + "The Grove Soil Moisture Sensor produces an analog signal, and requires an ADC. \n", + "\n", + "A Pynq Grove Adapter, or Pynq Shield and a Grove I2C ADC are required for this example. \n", + "\n", + "In the example, the ADC is initialized, a test read is done, and then the sensor is set to log a reading every 100 milliseconds. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Overview\n", + "\n", + "The Grove - Capacitive Moisture Sensor (Corrosion Resistant) is a soil moisture sensor based on capacitance changes. Compared with resistive sensors, capacitive sensors do not require direct exposure of the metal electrodes, which can significantly reduce the erosion of the electrodes. Hence, we call it Corrosion Resistant.\n", + "\n", + "It is important to note that this sensor can only qualitatively test the humidity of the soil and cannot measure quantitatively. Which means when the humidity of the soil rises, the value of the output decreases; conversely, when the humidity decreases, the output value becomes higher.\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Helpful Links\n", + "\n", + "[Sensor webpage](https://wiki.seeedstudio.com/Grove-Capacitive_Moisture_Sensor-Corrosion-Resistant/)\n", + "\n", + "[PMOD to Grove adapter webpage](https://store.digilentinc.com/pynq-grove-system-add-on-board/)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using the Sensor" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Attention\n", + "\n", + "The part of the sensor inserted into the soil cannot exceed the highest position line (the white line).\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### For this example, the PYNQ PMOD to Grove adapter is connected to PMODA, and the grove ADC is connected to group 'G4' on the adapter.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1. Load the base Overlay" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "from pynq.overlays.base import BaseOverlay\n", + "base = BaseOverlay(\"base.bit\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2. ADC read from sensor" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2.029834 V\n" + ] + } + ], + "source": [ + "from pynq.lib.pmod import Grove_ADC\n", + "from pynq.lib.pmod import PMOD_GROVE_G4 \n", + "\n", + "grove_adc = Grove_ADC(base.PMODA,PMOD_GROVE_G4)\n", + "print(\"{} V\".format(round(grove_adc.read(),6)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3. Scale Voltage value for ease of use" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "686\n" + ] + } + ], + "source": [ + "# We assume output is 1-2.5V\n", + "# We scale it to 0-1000 for \"ease\" of use\n", + "\n", + "v = round(grove_adc.read(),6) - 1\n", + "if v<0:\n", + " print(\"Sensor not connected\")\n", + "else:\n", + " print(int(v* 666.666))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4. Starting logging once every 100 milliseconds and print recorded values" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [], + "source": [ + "grove_adc.set_log_interval_ms(100)\n", + "grove_adc.start_log()" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938, 0.0938]\n" + ] + } + ], + "source": [ + "log = grove_adc.get_log()\n", + "print(log)\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. Get the average voltage value and scale it\n" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.09379999999999994\n", + "-604\n" + ] + } + ], + "source": [ + "av = sum(log)/len(log)\n", + "print(av)\n", + "final = int((round(av,6) - 1)*666.666)\n", + "print(final)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 6. Final humidity output" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sensor is not connected.\n" + ] + } + ], + "source": [ + "if (final >0 and final <300):\n", + " print (\"Soil Humidity is high.\")\n", + "elif (final >300 and final <600):\n", + " print (\"Soil Humidity is normal.\")\n", + "elif final >600:\n", + " print (\"Soil Humidity is low. Watering is required.\")\n", + "else:\n", + " print (\"Sensor is not connected.\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +}