Raspberry Pi/Reef Angel Aquarium Controller

Discussion in 'DIY' started by pixelpixi, Aug 3, 2013.

  1. pixelpixi

    pixelpixi Guest

    Hey guys. I thought I'd share a project I've been working on. This is going to be super nerdy. Consider yourself warned. :)

    For a long time now I've thought it would be fun to build my own aquarium controller. I'm pretty sure I can get the software end working, and I have some experience with electronics, but building everything from scratch (especially analog stuff like pH probe inputs) and packaging it nicely was daunting enough that I never did it. Recently I took a look at the Reef Angel stuff and the openness of it seemed really awesome. All the source code is there, and even the schematics are published on the website.

    I've also been wanting to do something with the Raspberry Pi. If you aren't familiar with it, the Raspberry Pi is a credit card sized single board compter. It has a 300Mhz CPU, 512MB of RAM, USB, Ethernet, a GPU, HDMI, and audio ... all for just $35. So, you probably see where I'm going here. I thought it would be fun to try hooking up the Pi to reef angel hardware. I spent some time studying the schematics and found that most of the reef angel hardware connects using an i2c bus. i2c is a very common standard in electronics for connecting all sorts of components. In fact, that raspberry pi has i2c built in and comes with linux drivers for it!
    The reef angel hardware uses USB cables (mini connectors upstream and USB-A connectors downstream) but it's actually i2c rather than USB.

    The second interesting feature of the reef angel is the connection between the relay box and the head unit. This is a DB-25 connector like you would use for an SVGA monitor. This cable caries i2c, but also includes wires to control each relay. I can drive the relays either using output pins on the pi, or by using i2c and the reef angel relay box expansion module.

    Next up I'll post some photos showing where I'm at with it and what I'm doing on the software side. Big shout out to Roberto for making such awesome hardware and making it an open platform so nerds like me can tinker with it.
  2. pixelpixi

    pixelpixi Guest

    Okay here's the basic hardware I started with. The ReefAngel relay box, IO module, relay expansion module, and hub. And of coure, the Raspberry Pi. [​IMG]

    It wasn't long before I had a mess on my hands: [​IMG]
    But here it is basically all hooked up. I also got an i2c LCD display kit from adafruit. It's able to connect to the ReefAngel expansion hub just like everything else!
  3. pixelpixi

    pixelpixi Guest

    In terms of software, I wanted to start with a web app so I could do everything on either my laptop, tablet, or phone. I decided to do the server software in python (PHP... never again!). I'm using tornado, which is python web framework that makes it super easy to set up a server that can reply to requests from a browser. In the frontend I'm using jquery and jquery UI along with WebSockets, which allows the browser to keep a live connection open to the server so it can update when new data comes in from the controller. So far I have it working enough that I can set up a basic timer, click buttons to turn relays on and off, etc. but nothing very pretty or worth showing off just yet. That's about it for now! I'll try to update this thread as the project progresses.
  4. Kensington Reefer

    Kensington Reefer Supporting Member

    Reading this makes my head explode!
    You could have written it in Sanskrit!
  5. tr1gger

    tr1gger Keyboard Cowboy

    very very VERY cool! Raspberry pi's are quite powerful for such a small package. They will only be getting smaller too. Can't wait to see more on this.
  6. rygh

    rygh Supporting Member

    Sweet! I wish the picture links worked. Warning: RasberryPi I/O are NOT 5V tolerant. A lot of the I2C peripherals will use a 5V pullup. Not sure about ReefAngel. Look into using "Xively." It is a great way for a microcontroller to "push" data to the cloud. So you can see it remotely without port forwarding your firewall.
  7. rygh

    rygh Supporting Member

  8. pixelpixi

    pixelpixi Guest

    Thanks, guys! Good point about the 5v thing, Mark. Maybe that's a good reason to stick with the other setup the pi only talks to the relay expansion module. I think I fixed the picture links. Are they working now?
  9. Kensington Reefer

    Kensington Reefer Supporting Member

    I hope you will be able to do some really cool stuff with that.
  10. rygh

    rygh Supporting Member

    Pictures are working now.
    I2C should be fine, even if 5V pullups. Not enough current to do real damage. Something like 2mA in. Just be careful of SPI or others that really drive in.
    I can tell it will work - you have a real soldering iron
    Silly thought : You could get a Gertboard (Raspi interface board), which is atmel based, then port the reef angel code to it..... :)
    Curious though: Why a small LCD display, instead of a full on VGA? Raspi has the capability, and it would be impressive graphics
  11. pixelpixi

    pixelpixi Guest

    The LCD is a quick and easy way to provide some status information and requires very little work to get up and running. I don't plan to make it the interface through which you use the controller, though. I could write a full linux GUI app, but that would be a lot of work (and is what I do for a day job). I'm also not sure I could get a touch interface working well and I don't want a button or joystick based interface. It seems like a better way to get a great interface is to push it off to a separate device. An LCD on the Raspi would be cool, but it's not going to be able to compete with, say, a Retina iPad. So, I decided to focus on the client/server architecture and web frontend first. Next, if I still feel motivated, I might write a native iOS frontend. Later on I could upgrade to vga and write an OpenGL app if I want to make the status display slicker.
  12. rygh

    rygh Supporting Member

    Hmm, what you really need to do is take advantage of the H.264 encode capability on the Raspi. Meaning, HD video streaming of your tank!!
    Heck, you are doing an iOS app anyway, what is a little bit of extra tweaking.
    Actually, your plan makes a lot of sense. I just look at my little screen for temp and error messages, but then look online for detailed data logging. Very handy for reducing worry when on vacation as well.
  13. newhobby

    newhobby Guest

    Very cool :) Bondolo was also looking into doing something like this. Not sure how far he went though. Will you share python and front end code too :) I linked this to the one we have in the reefangel forum: http://forum.reefangel.com/viewtopic.php?f=4&t=1885 I hope it is ok.
  14. bondolo

    bondolo Supporting Member

    This is really cool! I have been meaning to work on a project with similar goals but work has kept me busy such that I have had little time other than for basic maintenance of my tanks.

    I will definitely follow this thread with interest!
  15. denzil

    denzil Webmaster

    Hey Erin, I have a spare Gertboard (IIRC) if you're interested. There was an ordering mixup and I somehow got two (paid for both of them) and I've been meaning to offload it if someone needed it on BAR. I've been meaning to go further on my RPi than just setting the OS up and toying with it but have been recently preoccupied with the forum. :)
  16. rygh

    rygh Supporting Member

    My kid says I have to switch my aquarium controller to RasPi.
    Why? Because they have ported Minecraft to it of course.
    denzil likes this.
  17. pixelpixi

    pixelpixi Guest

    I've made some progress on this project. I switched to using i2c to drive the relay module, rather than the 15 pin connector. That allowed to really streamline the hardware. I cut a hole in the enclosure and attached a USB jack for connecting to the reef angel. I also wired in the temperature sensor and used some ICGel to secure it.

    Denzil, thanks for the gertboard offer but I think I'm good for now. I'm going to try and keep the hardware simple and really focus on the software.

    [​IMG] [​IMG]
    denzil likes this.
  18. pixelpixi

    pixelpixi Guest

    On the software front I've made some progress, too. The basic architecture is that there are "devices", which talk to physical hardware. Devices can have "variables" which are either inputs (read from the hardware), outputs (write to the hardware), or options (configure the behavior of the hardware).

    Then there are also rules, which have connections to variables. The rules run periodically to read from the connected inputs and write to the connected outputs.

    Anyway, here's the device page, where you can configure device options and switch outlets on and off. It keeps in sync with the pi so when something changes you instantly see it reflected there.


    I also have a status page kind of working where you can drag widgets around on a grid. I'm thinking of having various types of widgets, from a simple temperature readouts to full interactive graphs.

    I have rules working on the server side, but there's no UI for them yet. Still lots to do!
    denzil likes this.
  19. rygh

    rygh Supporting Member

    In fact a bit too clean. I bet a bunch of nice duct tape would cover that bit of temp sensor wire that is sticking out,
    and just give it that better look. :p
    Advice though: You might want to stress test the I2C for reliability. It is not uncommon
    to have issues, especially with all the wiring and questionable grounding.
    Are there registers in the I/O expander? You could read/write those non stop for a day, and see if there are
    any errors.
  20. denzil

    denzil Webmaster

    Looking pretty good there, Erin!

Share This Page