Introduction: Fish Feeder Arduino Raspberry Pi Link
"What a boring black box"
Yes it is, but:
– It feeds my fish when I'm not there.
– It feeds at a predefined time.
– It senses the food given to the fish
– You can login remotely into the raspberry pi to see the status.
– It can send an e-mail when something is wrong.
Step 1: Introduction
Why this project
My aquarium is a Juwel Rekord 800 and has a Juwel feeding machine. I bought the machine to be able to feed my fish on regular times when I'm not around. It's a great machine, but as an engineer I see some room for improvement.
For example:
– There is no way to see when there will be a next feeding.
– You have only 1 feed per day or 2 feedings per day with an interval of 6 hours.
– To store a time of feeding you have to physically push a button at that time.
– I have children who like to push buttons, so I have to reset the machine.
In short I don't know for sure when and much the fish are fed when I'm not around.
This subproject
This project is divided in several subproject:
- The build of the feeding machine
- The build of the sensor
- The link between Raspberry Pi and Arduino
The build of the feeding machine can be found here:
https://www.instructables.com/id/Fish-Feeder-1/
The build of the sensor can be found here:
https://www.instructables.com/id/Fish-Feeder-Sensor-Array/
This project only describes the link between Raspberry PI and the Arduino.
Step 2: Components
Components
- PC or phone capable of running Remote Desktop Viewer
- Network WLAN / LAN
- Raspberry PI with installed SSH, VNCServer
- Fishfeeder
- VNCviewer
- Python
- Arduino IDE
PC or phone
The Raspberry PI is used without a monitor. The LCD on the FishFeeder shows data, also the PC or phone is used to run a VCNviewer to acces the Raspberry PI. Data from the fishfeeder is stored in a data-folder.
The PC is used to upload the .ino file to the Arduino
Network
To be able to connect to the Raspberry PI remotely you must have a network.
Raspberry PI
The Raspberry PI is a nice, small, cheap computer with a low power consumption. In this project I used a Raspberry PI 2B, but any other will do. The Raspberry PI needs to be prepared:
- Get the latest image Raspbian:
https://www.raspberrypi.org/downloads/
- Turn SSH on:
https://www.raspberrypi.org/documentation/remote-...
- Install VNCserver for remote acces see:
https://www.raspberrypi.org/documentation/remote-...
- I prefer to activate VNCserver by SSH:
Remote Desktop Viewer → Connect
Protocol → SSH
Host → IP-adres Raspberry PI
SSH Options -> Username "pi"
Password "raspberry"
pi@raspberrypi ~ $ vncserver :0 -geometry 1024x768 -depth 16
pi@raspberrypi ~ $ startx (ignore errors)
- The next step is graphical login:
Remote Desktop Viewer → Connect
Protocol → VNC
Host → IP-adres Raspberry PI
Password "raspberry"
FishFeeder
The FishFeeder is the machine that delivers food into the aquarium. It is controlled by the Arduino. The Arduino is instructed by the Raspberry PI. The build of the FishFeeder is documented see links in STEP1.
Step 3: Serial Link Raspberry PI & Arduino
For the Raspberry PI the program is written in Python3. Respect the licence.
PySerial
To make the Raspberry Pi talk to the Arduino you need to import the serial module (pyserial):
http://pyserial.readthedocs.org/en/latest/pyserial...
Raspbberry PI serial example
The serial link between Raspberry Pi and Arduino is a bit troubled. The Raspberry site has a nice tutorial:
https://www.raspberrypi.org/blog/cas-educational-m...
http://vx2-downloads.raspberrypi.org/Raspberry_Pi_...
After some testing the baudrate is upgraded from 9600bps to 115200bps. At low baudrates the data was received but not displayed. If there is a problem with displaying data to lcd, increase the delay or time.sleep after a write
Test programs
To verify that the Raspberry PI and the Arduino are talking over the USB these 2 small test-programs are used.
USB Device folder
There are various methods to find the device folder of your Arduino:
- pi@easpberrypi ~ $ dmesg
- pi@easpberrypi ~ $ lsusb
- pi@easpberrypi ~ $ ls -l /dev/ttyACM*
- pi@easpberrypi ~ $ ls -l /dev/ttyUSB*
Step 4: Operating Modes
Most of the time both the Raspberry PI and Arduino are waiting. The Raspberry keeps the time and the Arduino controls the FishFeeder machine.
Feeding
The Raspberry Pi has the connection to the internet and most accurate time. When it is time to feed the Raspberry Pi send the commands for the feeding process. At the end of the process the Arduino return the food index
See Arduino program : 20160402 FishFeeder revA.ino
void loop() { LDR_clean(); // clean the variabels for the LDR array servo_on(); // power on to the servo blink_led(); openhatch(); // open the hatch blink_led(); feeding(); // turn the feeding tube blink_led(); closehatch(); // close the hatch blink_led(); servo_off(); // power off to the servo LDR_calc(); // calculating the food index }
Display when idle
Between the feeding the Raspberry Pi provides the Arduino with accurate info to display.
Step 5: Communication Protocol
See also https://www.arduino.cc/en/Reference/ASCIIchart
The Raspberry PI is the sender, the Arduino is the receiver. Only on command of the Raspberry PI the Arduino start to send. To avoid problem that bytes are interpreted as a commands e.g. <NULL>, <TAB>, <LINE FEED>, the commands are sent as a string converted to byte.
Step 6: Arduino Memory
The memory of the Arduino is not large. The Arduino Uno which I use as controller inside the FishFeeder has the following memory:
- 32kB Flash – Program space
- 2kB SRAM – Create and manipulate variables
- 1kB EEPROM – Storage for long-term information
The program memory is sufficient for this project. EEPROM memory is not used. The SRAM memory is critical.
Arduino variables
The SRAM memory is used for:
- Sensor values storage.
- Strings to display on LCD screen.
- String to send over serial.
- Import of modules, e.g. Serial, LCD, Servo
If you modify the Arduino program, you can run out of SRAM, your program fails in unexpected ways. At startup of the Arduino program there is a handshake and a report of available SRAM in the terminal.
Note : The use of F() Macro resulted in a scrambled output to the LCD.
Step 7: Flowchart & Program
I prefer to keep my projects simple and clean. For programs it's easy to track & trace errors. Probably there are many improvements possible.
I have added the flowcharts of the 3 programs. The E-mail program is seperate because it could be used by other programs also running on my Raspberry PI.
The login-name and login-password in the e-mail program are *starred* for obvious reasons. Request your e-mail address at Yahoo, Gmail, or other supplier.
VNC-viewer
See screenshot : If everything works all-right, you can use a phone or pc to login in the Raspberry PI and see the status of the feeding machine.
- On the left the data-file of the feedings, the date, time and food index is stored.
- On the right the terminal of the FishFeeder program.I pulled the sensor out of the water, the sensor registered a temperature below 20C, an error-file is written.
- In the middle the terminal of the E-mail program. It found the error-file and has sent an e-mail.
Video
In the video the LCD-screen.