Welcome to a small Raspberry Pi project that was part of the IS-311 course. This guide will show you step by step how to configure your Raspberry Pi to get sensor data stored locally and to an IoT dashboard. There are some technical prerequisite before using this guide. Example: know how to use terminal, edit code and general knowledge about Raspberry Pi & IT.
Note - This project used Raspberry Pi 3 instead of Zero, due to not having some of the parts necessary.
Thanks to InitialState for guide.
Libraries used |
---|
adafruit-blinka |
adafruit-circuitpython-seesaw |
adafruit-circuitpython-bh1750 |
mysql connector |
ISStreamer |
Components used |
---|
Raspberry Pi Zero WH OR Raspberry Pi 3 |
Switching PowerSupply with 20AWG |
16GB Card with NOOBS 3.1 for Raspberry Pi |
Adafruit STEMMA Soil Sensor |
Adafruit BH1750 Light Sensor |
Qwiic JST SH 4 pin |
JST PH 4 pin FEMALE |
InitialState Subscription |
Check what Python version you have, if this says <3.9 follow the next 2 steps.
$ python3 --version
This general purpose command for updating apt (package manager for Ubuntu and Raspbian).
$ sudo apt-get update
This updates to the latest version of Python. Change the 3.9 if there is a newer version.
$ sudo apt-get install python3.9
Updates the package manager for Python (used for downloading libraries).
$ python3 -m pip install --upgrade pip
Run these commands to install the libraries
$ sudo pip3 install adafruit-blinka
$ sudo pip3 install adafruit-circuitpython-seesaw
$ sudo pip3 install adafruit-circuitpython-bh1750
$ sudo pip3 install ISStreamer
The figure down below shows how to connect the sensors. Both the moisture and ambient light sensor could be found inside the diagrams folder, these models/diagrams have a larger resolution. Note - The white dot is for the white cable.
We need to access the I2C to get data from the sensors. The commands to do so are:
$ sudo raspi-config
Select the fifth option 5 Interfacing Options
then P5 I2C
and click <YES>
. You have to reboot for the changes to take into effect.
To check if the setting is correct, you can write the following command:
$ sudo i2cdetect -y 1
This should prompt you to a screen that looks like this:
If it does not show up, try to reconfigure or re-seat the sensor connectors. If it shows 0X76 OR 0X77 OR 0X38
it is correct and you can continue.
This is needed if store the data locally. Use the following commands in the terminal:
$ sudo apt install mariadb-server
If you want to have an secure database, you need to install mysql_secure_installation
. Answer Y
to all the prompts. This will make it harder to access the database.
$ sudo mysql_secure_installation
After everything is installed, you can now login to the database with:
$ sudo mysql -u root -p
You can now run the SQL-script that is included in the repository (plantsiodb.sql).
This requires that you either buy InitialState or have 7-day trial available and created an account. When you are at the frontage of the app, you need to click in the top right and then click my settings. This prompt you to create an Access Keys
that should start with ist-
and a lot of random characters. After configuring the script with your own "Bucket key" and running the script, it should pop-up a Bucket at the left menu. If you click that Bucket, it should look like this:
If you don't like the line, you could always change it to something more fun, such as:
This is done by right-clicking the tile and choosing edit tile. if you want it to look the same, go to Tile Type and change it to Gauge Chart, and then change the Gauge Style to Liquid or Thermometer. Here is the settings used for this project:
Moisture
Temperature
If everything is working as intended, it is finally the time to run the script! CD
to the place where you downloaded the repository and write:
$ python3 plantsiot.py
This should show you what the moisture and temperature, and what is sent to the database.