Reef Central Online Community

Reef Central Online Community (http://www.reefcentral.com/forums/index.php)
-   Do It Yourself (http://www.reefcentral.com/forums/forumdisplay.php?f=3)
-   -   My Neptune Apex web interface compatible DIY reef controller (http://www.reefcentral.com/forums/showthread.php?t=2332822)

d0ughb0y 09/16/2013 10:13 PM

My Neptune Apex web interface compatible DIY reef controller
 
I'm starting this thread to document and share the progress of my controller build. I have been working on this for 1.5 years now and is still a work in progress. I have been using this on my tank since April 2013. I initially planned on getting an Apex controller, but it does not contain some features I need. Apex feed mode cannot be run on a schedule, it only has input lines (no output), no water level sensor, and no built it support for auto feeder (I think they are coming out with one for $99).

Objective:
To build a reliable, compact, simple, low cost, web based interface aquarium controller.

Description/Features:
Base Features:
8 outlet aquarium controller using Chauvet SR-08 relay packs.
Web based user interface optimized for mobile browser (Neptune Apex compatible).
Water level sensor using SR04 ultrasonic sensor (for top off water).
http://reefcentral.com/forums/showthread.php?t=2328819
Auto Feeder using hacked Aqua Chef feeder.
http://reefcentral.com/forums/showthread.php?t=2327962
Can run a Feed cycle on schedule.
Time is synchronized with NTP server and DS1307 RTC module.
Automatic daylight savings time adjustment of time.
ph sensor.
Temp sensor.
Two ATO switches.
Sound and Email alert.
Outlets, Sensors and Web access logging.

Mobile Client app features:
View and control outlets.
View chart of sensor data for last 24 hours.
View logs for any day since logging started.
Modify controller program schedule.
Calibrate ph probe.
Manage SD card files (currently supports file delete only).

Optional Features:
Can be expanded with another unmodified Chauvet SR-08 to add another 8 outlets.
Two channel PWM 0-10v variable output. (hardware implemented, no software yet).
LCD display. (implemented)

The original design includes an X10 interface so I can use my old AC jr DC-8, but had since dropped that feature. The PWM I originally intended for controlling LED lights, but I have since bought a Maxspect Razor so PWM is currently unused. I may use it someday when I get a controllable pump.


Main Parts Needed:
Chauvet SR-08 Relay pack.
8 channel 5v relay module.
Arduino Mega2560.
Ethernet Shield.
Atlas ph stamp.
DS1307 RTC module.
DS18B20 Temp sensor.
ph probe.
BNC connector.
Aqua Chef feeder.
BC327 PNP transistor and 4.7k, and 47K resistors and 1N914 diode.
12v 1A power adapter.
5v 1A power adapter (USB charger).
5mm LED and 220ohm resistor.
Piezo buzzer.
micro SD card. (4GB will store your logs forever).
assorted jumper wires, pin connectors male and female , stereo and 4 pole plugs and jacks, prototype board, soldering equipment, switches, etc.

Optional Additional Parts:
For 8 outlet expansion
Another Chauvet SR-08.
DB-9 breakout module (Sparkfun 8552)
ULN2803 Transistor Array.
DB9 cable (male to female).

For PWM output
LM358 and 4 10k resistors. For 0-10v variable DC output.

For LCD Display
1602 LCD with I2C backpack. You can display a lot of stuff on 16x2 if you get creative. :)

Depending on where you source your parts, the base unit will cost around $150 and definitely under $250 with the optional parts. I got all my parts from Ebay, Tayda Eletronics, and Sparkfun.


Software Features:
The software consists of the arduino code, and an html5/javascript code that runs on mobile web browser. The outlet schedule processing is done via timer interrupts. Each outlet is updated once per second, guaranteed. I use a very simple, efficient and compact algorithm to define the outlet schedule programming.

The main loop executes less time critical tasks at 60 hz (60x per second or once every 16ms) like logging outlet switch events to SD file, updates LCD, update ph, temp and sonar readings. The ph, temp and sonar readings use an 8 reading rolling average to smooth out the values.

Input lines use pin change interrupts. Ultrasonic sensor echo pulse, Feeder home position indicator (to stop feeder rotation), generic IO open and close all use pin change interrupt. ATO uses timer interrupt to poll once per second.

I also have a timer interrupt based audio beep code for the controller to provide an audio confirmation when commands are received by the controller from the mobile app.

The web server code is based on TinyWebserver. I modified it to use SdFat library and to read and write faster (using buffered reads and writes). I also added basic web authentication code to prompt web connections for a username and password. TinyWebserver is nice that it has code for uploading your files to the SD card.

The mobile web interface is compatible with Neptune's Apex controller. This means, my htm file will work with Neptune Apex controllers. See http://reefcentral.com/forums/showthread.php?t=2306409. Someday when I get an Apex, I will have a nice mobile html app to use. The web page also displays live video stream from a Foscam compatible camera. It is a single htm file written in html5 and javascript using jquery mobile library.

Files for this project are available on github at
https://github.com/d0ughb0y/Chauvet16

d0ughb0y 09/16/2013 10:14 PM

Hardware:

The controller
http://i.imgur.com/8w6uF95.jpg

main board with Atlas ph stamp, RTC, PWM circuit, ULN2803 driver, connectors, etc.
http://i.imgur.com/bWRMcoD.jpg

inside view. the main board is under the relay board
http://i.imgur.com/7rylf7d.jpg

lcd display
http://i.imgur.com/RBAN6kF.jpg

http://i.imgur.com/5NwNwpa.jpg

d0ughb0y 09/16/2013 10:15 PM

mobile web interface
http://i.imgur.com/NabU2f5.jpg---- http://i.imgur.com/5phudlw.png

http://imgur.com/Iw8FkpG.png---- http://imgur.com/eYkf75V.png

http://i.imgur.com/Z7QNe8U.png---- http://i.imgur.com/Jw1KJAU.png

http://i.imgur.com/d4JoLEm.png---- http://i.imgur.com/melUwfn.png

http://i.imgur.com/vFhgIuc.png---- http://i.imgur.com/X6wMZmP.png

d0ughb0y 09/16/2013 11:23 PM

Connection diagram

http://i.imgur.com/qsEIxJK.jpg

ghellin 09/17/2013 12:32 AM

Very nice!

cmantis 09/17/2013 12:54 AM

Omg I love it. Was about to build a jarduino but need web interface. Now what to do w my touch screen lcd. Want one to test w? Maybe u can make it work?

nemosworld 09/17/2013 10:21 AM

one word: Genius!

Rafael Compassi 09/17/2013 04:43 PM

Following!

Amazing job!

Rafael Compassi 09/17/2013 05:40 PM

Well, did everything you said, tried to compile with the v1.0.3 and got the following errors:

Apex.ino: In function 'boolean apex_status_handler(TinyWebServer&)':
Apex:139: error: 'now2' was not declared in this scope
Apex.ino: In function 'void prelog(TinyWebServer&, tmElements_t&, time_t&, int&)':
Apex:170: error: 'now2' was not declared in this scope
Apex.ino: In function 'boolean apex_outlog_handler(TinyWebServer&)':
Apex:227: error: 'now2' was not declared in this scope
Apex.ino: In function 'boolean apex_datalog_handler(TinyWebServer&)':
Apex:264: error: 'now2' was not declared in this scope
Apex.ino: In function 'boolean apex_command_handler(TinyWebServer&)':
Apex:345: error: 'now2' was not declared in this scope
Apex.ino: In function 'boolean apex_status_json_handler(TinyWebServer&)':
Apex:363: error: 'now2' was not declared in this scope
Outlets.ino: In function 'void outletHandlerA()':
Outlets:24: error: 'now2' was not declared in this scope
Outlets:35: error: 'now2' was not declared in this scope
Outlets:85: error: 'now2' was not declared in this scope
Outlets.ino: In function 'void outletHandlerB()':
Outlets:119: error: 'now2' was not declared in this scope
Outlets.ino: In function 'void _outlogentry(uint8_t, boolean)':
Outlets:172: error: 'now2' was not declared in this scope
Utils.ino: In function 'void logOutlet()':
Utils:233: error: 'now2' was not declared in this scope
Utils.ino: In function 'void logSensors()':
Utils:267: error: 'now2' was not declared in this scope
Utils.ino: In function 'void logMessage(const __FlashStringHelper*, char*)':
Utils:280: error: 'now2' was not declared in this scope
Utils.ino: In function 'void logMessage(uint8_t*, char*)':
Utils:301: error: 'now2' was not declared in this scope
Utils.ino: In function 'void logAlarm()':
Utils:310: error: 'now2' was not declared in this scope
Utils.ino: In function 'void dateTime(uint16_t*, uint16_t*)':
Utils:342: error: 'now2' was not declared in this scope


Care to shed some light?

djmx2002 09/17/2013 05:50 PM

very nice work, how do you have ethernet? do you use the ethernet shield?

nvm i didn't read the whole post

d0ughb0y 09/17/2013 05:52 PM

yes I use the standard ethernet+sd shield.

Rafael, I have to fix that. I added a now2 function to Time library that it can be called from interrupt handler. I'll add the instructions later.

Rafael Compassi 09/17/2013 05:53 PM

Allright, post here when you update then!

Very nice job, btw!

djmx2002 09/17/2013 06:56 PM

I wonder if it's possible to connect several PH probes.

d0ughb0y 09/17/2013 07:05 PM

Quote:

Originally Posted by Rafael Compassi (Post 21911504)
Allright, post here when you update then!

Very nice job, btw!

I just updated the readme on github. sorry about that.

d0ughb0y 09/17/2013 07:10 PM

Quote:

Originally Posted by djmx2002 (Post 21911692)
I wonder if it's possible to connect several PH probes.

you can, there are 2 more Serial lines available on the mega, so you can add two more. You just need to extend (or more like duplicate) the code for Serial1 to Serial2 and Serial3. And adjust to corresponding code for the display to display the additional probes.

Rafael Compassi 09/17/2013 07:22 PM

Awww yes! Compiled like a charm!

Thank you very much!

Tickyty 09/20/2013 08:34 AM

This looks great. Thanks for posting. I will definitely be using a lot of this once I get started.

Tickyty 09/20/2013 10:44 AM

Quote:

Originally Posted by d0ughb0y (Post 21909255)

Looking at the relay outlets, why did you use the darlington pair for the second SR8? Since I will not be gutting the SR8 like you and using the two units whole how would I control the linking of the two?

d0ughb0y 09/20/2013 10:57 AM

you will just need to wire the first 8 just like outlet9-16 using the ULN2803A since chauvet relays are 12v. Then in the code, you will see the logic is inverted for outlets 0-7 and 8-15. So you will need to modify the code to just use the code for outlets 8-15 for all outlets 0-15 since they are all inverted logic now.

Likewise, I got a question from someone who is not using chauvet at all, and will just use 2 8 channel 5v relays. In this case wiring outlets 9-16 will just be the same as 1-8 (no ULN2803), and the corresponding change in the arduino code to use the code for outlets 0-7 for all outlets 0-15. BTW for 8 channel relay connection, you only connect Vcc from Arduino to Vcc on the relay board, no ground connection. Then you use another 5 v power supply to JDvcc and Gnd to power the relay coils. I would not use the same 5v from arduino to power the relay coils, because if all coils are on, it will take at least 500ma at 5v. I just gutted one of those USB charger wall warts (everyone has a few of those laying around) and use that to power the relay board.

the code is in outlets.ino

Tickyty 09/20/2013 11:25 AM

So I will need an 16 array chip or two of the 8. I will definitely need to do another board then. Did you use an external 12v supply for the SR8? This brings me to another question concerning the pin out of the SR8. I came across another pinout that stated pin 9 was the 12V pin. Did you have to trial and error to determine the pinout?

Can you point me to a line in the code so that I can see the inverted logic. I am really rusty with my programming skills.

d0ughb0y 09/20/2013 11:54 AM

I am using a gutted 12v 1a power supply inside the chauvet to power the arduino and the PWM circuit and to pin 5 of the DB9 to power the second chauvet.

No trial and error, I opened up the chauvet and test using a multitester continuity test to figure out the DB9 pin connections. You should do the same.

https://github.com/d0ughb0y/Chauvet1...er/Outlets.ino
lines 178-207

actually, first 8 uses PORTA and next 8 uses PORTC, so in your case, you would use the same code as PORTC on PORTA.
like this

Code:


void _outletOn(uint8_t p){
  if (p<8) {
    if (!(PORTA & _BV(p))) {//is off
      PORTA |= _BV(p); 
      _outlogentry(p,true);
    }
  } else if (p==Feeder) {
    feed();
  } else {
    if (!(PORTC & _BV(p-8))) {
      PORTC |= _BV(p-8);
      _outlogentry(p,true);
    }
  }
}

make sure to do the corresponding change in _outletOff

wgraham 09/20/2013 11:55 AM

having a problem compiling get the same as Rafael, now2 was declared and i followed the direction on github. Added the lines to Time. Do I delete anything

d0ughb0y 09/20/2013 12:05 PM

Quote:

Originally Posted by wgraham (Post 21919783)
having a problem compiling get the same as Rafael, now2 was declared and i followed the direction on github. Added the lines to Time. Do I delete anything

do you only have one copy of Time library? It should be in libraries folder in your sketch folder, not in the libraries folder of Arduino program. You only add exactly as described in the readme, nothing to delete.

you need to edit BOTH Time.h and Time.cpp

Tickyty 09/20/2013 01:48 PM

It would most likely be simpler if I used two DB9 outlets instead of trying to link the two units together using the integrated connectors.

So when I initialize my port A the value should be "0" not "0xFF"?

In the utils.ino file line 179 should I remove the ~from "~PortA" as well?

d0ughb0y 09/20/2013 01:59 PM

Quote:

Originally Posted by Tickyty (Post 21920087)
It would most likely be simpler if I used two DB9 outlets instead of trying to link the two units together using the integrated connectors.

So when I initialize my port A the value should be "0" not "0xFF"?

In the utils.ino file line 179 should I remove the ~from "~PortA" as well?

You must use two DB9, one going to each chauvet. You cannot daisy chain the chauvet because the DB9 connection is straight through.

Yes in the initialization (initOutlets), you want it 0. Basically driving port pin low will turn off the outlet, driving it high will turn it on. So yes in Utils.ino routine that prints the status of the ports, it will be a direct read (no need to invert) to show if the port is on or off. and same for isOutletOn function.


All times are GMT -6. The time now is 04:12 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
User Alert System provided by Advanced User Tagging v3.3.0 (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.