/makers-beehives-hardware

Raspberry pi & Arduino scripts for uploading data from Makers'Beehives

Primary LanguageC++

makers' beehives - hardware

This beehive project is dedicated to remotely monitoring a beehive's activity :

Several sensors collect data. This data is then sent through WiFi to a database, and made accessible on a website.

In this repository, we will focus on collecting and sending the data.

The data visualisation on the website is dealt with on another repository

Summary :

1. Global setup

2. Power supply

3. Raspberry Pi setup

4. Arduino Trinket setup

5. Arduino Uno setup

1. Global setup

Edition du diagramme (drive makers lab)

This system is designed to run periodic measurement cycles and send the results online.

For each cycle, we will:

  • produce and upload a gif from pictures from the beehive's entrance
  • read several parameters about the beehive's environment and conditions :
    • Temperature
    • Humidity
    • Noise
    • Weight
    • Light
    • CO
    • NO2

All of this data will then be stored on a online database.

For this project, we use :

  • a solar panel and a powerbank for power supply.
  • an Arduino Trinket, which will trigger and power on the system for 10 minutes, once an hour.
  • an Arduino Uno and a series of sensors. The Arduino Uno will read data from its sensors and send them when requested through a serial port.
  • a Raspberry Pi which will read data from the Arduino Uno, take pictures from a camera, transform them into a gif, and then upload all the data online.

2. Power supply

To power the system, we use a solar panel and a powerbank.

3. Raspberry Pi setup

Install Raspbian OS

  1. Connect the SD card to your computer
  2. Open Raspberry Pi Imager
  3. Choose the last version of Raspberry Pi OS Lite and write it on SD card.

Turn the device on

  1. Insert the micro SD into the Raspberry Pi
  2. Plug a keyboard and a screen to the device.
  3. Plug the power supply : the device should boot now !
  4. Follow the prompts :
    • Keyboard configuration
    • username : choose 'beeN', with N being the number of your beehive. This will be used to track the beehive's data.

You might notice some intermittent warnings : "Undervoltage detected!". In that case :

  • check that you are using a 3A power supply.
  • check that there is no bad contact on the board If everything else keeps working, you can ignore them.

Configure Wifi:

Run

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

and add

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="makerslab"
    psk="makerslab"
}

Where ssid and psk are the Wi-Fi network's name and password.

If you see the following message, you need some extra config to enable Wi-fi connection

Wi-Fi is currently blocked by rfkill.

--> Use raspi-config to set the country before use.

For an easier setup, use ssh connection

That way, you can use your own computer to edit settings and code on the device.

It is faster, you can use a decent text editor and use copy-paste. To do so, you need to use the same wifi network.

SSH Setup - full process

sudo raspi-config
  1. Interface Options
  2. I2 SSH > Enable SSH

Get the hostname :

hostname -I

The output should look like this :

172.XX.XX.XX

Then you should be able to connect from your computer :

ssh beeN@172.XX.XX.XX

Install dependencies

sudo apt update && sudo apt upgrade -y

Git

Git should already be installed. To check it : git If not :

sudo apt-get install git

pip

Python package manager

sudo apt install python3-pip

PySerial

Enables serial communication on Pi.

pySerial

PiCamera

Picamera - Doc

sudo pip install picamera

imageMagick

Enables image manipulation.

Resize image from CLI with imagemagick Doc - imageMagick CLI

sudo apt-get install imagemagick

PyImgur

Enables the upload of pictures (and gifs) on Imgur.

PyImgur - Doc

pip install pyimgur

firebase_admin

Access a firebase DB with Python SDK

  1. Parmi les dépendances de firebase admin, on trouve le paquet cryptography, dont firebase exige une version récente (cryptography>=3.4.0)
  2. Les dernières version de ce paquet ont besoin d’une version récente du langage Rust (This package requires Rust >=1.56.0.)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
  1. Avant de lancer l’installation de firebase_admin, il faut installer les dépendances nécessaires à l’installation de cryptography. a. Install dependencies for cryptography

    sudo apt-get install build-essential libssl-dev libffi-dev \
    	python3-dev cargo pkg-config
    

    b. Install cryptography

    pip install cryptography
    

    This step will probably last quite a long time, while prompting the following information :

Building wheel for cryptography (PEP 517) ... |

  1. Enfin, on peut lancer l’installation de firebase_admin :
pip install firebase_admin

Enable RaspiCam

Type sudo raspi-config and enable RaspiCam: Interfacing Options -> Camera -> Yes

Clone the repository:

cd && git clone https://github.com/emlyon/makers-beehives-hardware.git

Add Imgur & Firebase secret keys :

Create secret keys files within the repository:

To move within the repository, type

cd makers-beehives-hardware/
  1. firebase-secrets.json
touch firebase-secrets.json
nano firebase-secrets.json

https://console.firebase.google.com/project/makerslab-beehives/settings/serviceaccounts/adminsdk

  1. imgur-secrets.json
touch imgur-secrets.json
nano imgur-secrets.json

https://imgur.com/account/settings/apps

{
	"imgurClientID": "xxxxxxxxxxxxxxx",
	"imgurClientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

Run script on Boot

Edit the .bashrc file, which will enable to run a script after autologin.

nano ~/.bashrc

Add this line at the bottom of the file :

python makers-beehives-hardware/beehives.py

References

Legacy references :

4. Arduino Trinket setup

The Arduino Trinket will control a relay, in order to power the system on for 10 minutes once an hour.

We will follow this documentation to set up the trinket

  1. Open Arduino IDE

  2. Install Adafruit's board manager (if not already installed) : Adafruit Arduino AVR Boards

  3. Select the Pro Trinket 5V/16MHz (USB) board :

    Tools > Board > Adafruit AVR Boards > Pro Trinket 5V/16MHz

  4. Next select the USBtinyISP programmer : Tools > Programmer > USBtinyISP

  5. Paste the code from trinketRelay.ino file into the IDE window

  6. Plug in the Arduino Trinket, make sure you see the green LED lit (power good) and the red LED pulsing. Press the button if the red LED is not pulsing, to get into bootloader mode.

  7. Upload the code to the board : Sketch > Upload using programmer

5. Arduino Uno setup

  1. Open Arduino IDE

  2. Install Adafruit's board manager (if not already installed) : Adafruit Arduino AVR Boards

  3. Plug in the Arduino Uno board

  4. Paste the code from arduino_beehive.ino into the IDE window

  5. Install required libraries from the library interface :

  6. Download and install the sensors' custom libraries

    For the project's needs, we had to customize some existing libraries :

    For each of the following :

    1. access to the github repository

    2. click on Code, and Downlod ZIP

    3. Install the library into Arduino IDE:

      Click on Sketch > Include library > Add .ZIP library, then choose the downloaded .ZIP library.

    4. Upload the code to the Arduino Uno board.

      If you access the serial monitor, you should see some information about the sensors, which will depend on whether the sensors are plugged or not.

  7. Using the same process as custom libraries, install the following libraries if needed :

Now, you can wire up the sensors on your board, following our documentation on Notion:

Then, you should be able to fetch data from the sensors :

From the serial monitor, you can request data from the sensors by sending the following serial message : DATA?

Load sensors

Based on https://www.instructables.com/id/Arduino-Bathroom-Scale-With-50-Kg-Load-Cells-and-H/

Seed Studio Base Shield wiring