Serial communications

A project log for R'lieh - Aquarium/ closed ecosystem management

An automated and connected aquarium management system

Audrey RobinelAudrey Robinel 09/17/2014 at 05:150 Comments

Due to the planned architecture, i have to be able to communicate in a reliable way between the Raspberry Pi and the Atmega chip. In the previous prototype, i was using simple GPIO commands to exchange information bewteen the two systems.

Indeed, i had a Arduino GPIO controlling the relay (for the lights), and this GPIO was also connected to an LED. I connected a wire after the resistor so that i had lower voltage, lower than 3.3V. This wire goes to the PI, as an input. The pi can thus read the lights status. In order to send commands, another GPIO of the pi is connected to an input of the Arduino. I thus write low - high - low to this GPIO, and the arduino must detect the high folowed by a low to accept the signal. This is also connected to a pushbutton, so in case of failure of the pi, i can manually turn on the lights. When this sequence is sent to the arduino, it inverts the light"s state : from off to on or on to off.

A python script runs on the pi to check the lights status, and turns it on and off when approriate (user defined).

Whereas this works, it is limited. I want to be able to send varied commands to the atmega without connecting tons of GPIO, but also to retrieve data. Indeed, the temperature is also handled by the atmega, and i want to log it on the pi. 

I tried both I2C and serial, and found serial to be easier, and more powerfull for what i want to do. I manage to send integer values with I2C, and it is probably possible to send real and text, but it was to much of a hassle. On the other hand, with serial communications, it is really simple : two wires have to be plugged (with a voltage divider on one, or a level shifter), and you send data with Serial.print(...).

I uploaded a simple test sketch for the Arduino and the corresponding python scripts for the pi to the project"s githgub. The Arduino sits there, and awaits a command. When a valid keyword is read, the corresponding command is executed. For now, it can respond to "lightstatus", telling weather the lights are on or off, it can turn lights on and off, and also respond to "waterTemperature" by providing the waterproof DS18B20 sensor reading.

For now those few commands will enable me to provide the same functionality that my previous prototype had, plus a few others easily.

I plan to add an air temperature sensor, maybe a second water temp sensor, and a second relay to control a second tank independantly.

The new prototype in developpement.

The LCD (4*20, RGB backlight) will print the most important information, and a few buttons will enable the user to control some parameters.

I plan to have the user setting some parameters, that will be saved inside the atmega memory. For now the parameters to be set are the cooling system shutown temperature, and the activation temperature for the same system. As of now, it is set in the Arduino sketch as 24.0 and 24.5.

The current iteration of the system is on a breadboard, i will use a "perma-protoboard" from adafruit later for a more reliable circuit.

See you soon for the next update!