(DIY) Arduino Controller

Noahs Home Zoo

Active Member
View Badges
Joined
Nov 19, 2017
Messages
183
Reaction score
108
Location
moses lake
Rating - 0%
0   0   0
The Why:
After much searching I have seen a lot of the raspberry Pi builds that have been shared around and are kept updated. But I haven't seen any up to date threads for arduino controllers. So I figure I would track my project as it goes and try to build something that is fairly modular. I'll start tracking all of the hardware that I'm using and will post up code as I go.

My Background:
I am an IT Specialist within a large corporation but my degree is in Software Engineering. I started courses in 2003 and learned un-managed C++ 6.0 well before I touched any C# managed code. My position within the company I work for has left me many a opportunity to write software to perform and track things that they didn't want to put additional funds into. I have also done a bit of moon lighting including building a web applications server side for a smaller PC game.

Current Goals:
  • Temperature Probe sensor (already Have)
    • Tracks the tank temperature for trending temp/time curve.
  • 2x Relay controlled Tank Heater (ordered)
    • alternate between heaters and trend temps to bring keep the temperature as stable as possible.
  • Room Heat/humidity Sensor (already Have)
    • Used to track the trending temp/time curve based on room temp and humidity
  • Relay control for blue/white channels (already Have)
    • Allow for controlling the on and off time based on a weekly schedule.
    • Alternate Mode setup for introducing new corals.
  • 2x Relay controlled powerheads (ordered)
    • Used for alternating the powerheads on a set schedule. Simulates more of a tide event without a constant off on which would burn it out.
  • ATO pump (need to order)
    • normal water top off
  • Buoyancy meter (need to order)
    • Used for determining when the water salinity needs to adjusted by additional water from the ATO reservoir.
  • Relay for pump (need to order)
    • To be used for shutting off the pump if the water level gets to low.
    • As well as a turning it off for water changes if needed.
  • Screen output (already Have)
    • To scroll the time and sensor levels.
  • Webserver (already Have)
    • Allows for monitoring and changing settings
  • WiFi (already Have)
    • Remote Access
  • SD Card (already Have)
    • Allows for keeping track of the data from the sensors
    • Allows for loading of preset conditions
    • (TBD) To hold the webpage information so it doesn't have to use up valuable space.
  • Timer Module (already Have)
    • Just for making sure that the time is accurate.
  • Dosing Pumps (need to order)
    • Dosing. Because that is what we do. We Dose and we know things.
  • Time lapse camera (already Have)
    • To allow for visual tracking of the corals.
    • Later I may employ a second arduino board to do image recognition to see if I can determine coral health. This is a long term project of mine. If I can train the system to tell the difference between healthy and unhealthy I can know way ahead of time if there are things wrong in the tank. A canary in the mine so to say.
Code:
As I am using OOP for this I will post up the cpp and header files as I go. I imagine due to limited memory on the Arduino Pro Mini I'm using there may be a diminishing return on making a class for everything. But I guess that will need to be a bit of a learning curve. Later on I may have to upgrade to a better controller, but for now I'm using what I have on hand.
 
OP
OP
Noahs Home Zoo

Noahs Home Zoo

Active Member
View Badges
Joined
Nov 19, 2017
Messages
183
Reaction score
108
Location
moses lake
Rating - 0%
0   0   0
***Disclaimer....A lot of this was spit balling as I typed it up. And had to rewrite things over as I realized there were better ways to accomplish it. So it is a bit of rambling but it certainly helped me to improve my code.***

Update:
I have been tinkering with this for the last week trying to get it to properly work. The first issue I ran into was the space limitations of the Arduino Mini Pro. For the code that I'm writing I ended up with only enough space for managing the lights and the SD card. As I got to > 75% of the dynamic memory space used I ran into memory issues. The code currently goes through and polls the SD card files to get the start and end date-time for each light. I created classes to contain the light, and the SD card. I then use those as variables that contain information specific to the control of each relay as well as logging information. I kept having issues with knocking my cables free from the two analog ports for the time controller so I decided it was time to go through and solder everything together. Should have that done tonight. Once finished it will be ready for the Mega 2560 I ordered. Just the act of writing this out is helping to get my mind thinking of better memory management practices for the program. I have a feeling there may be a whole other program by the time I'm done.

Looking at changing my approach for programming the light timers to:
  • Only having a single start Time for the Blue Lights. Then a lapse time in minutes till the White lights come on. Followed by a lapse time in minutes before the white turns off. Ending with a lapse in minutes before the blues turn off.
Currently storing start and end time as a DateTime variable. When programming windows applications theres so much memory its easy to lose sight of small bits of data. A DateTime variable is stored as an 8 byte variable, meaning I'm using 32 bytes for saving four time variables. But if you use a start time, with 3 events you only use up (8+2+2+2) 14 bytes. The reason this is important is with a controller like the Mini Pro it only has 2048 bytes total that can be used to run everything. So trimming out and slim down is key. We call this "reFactoring". So I will be doing a bit more of that to try and be smarter in how I streamline the code and reduce overhead.

For setting up an acclimation period I'll use two bytes to store a days to run, and percentage complete. And possibly one more byte to define the percentage of reduction to start at. These variables can be stored on the SD card so we track the time even if something failed.

The new hardware is not supposed to be here till next week so for now I'm just working on refactoring these classes to work better within the limitations of memory space. A slight learning curve to remember my C++ days from 15 years ago. But enjoying this thoroughly. Anyone moving from managed code to this code can appreciate how much more difficult it is to be on point and know every line of your code and how to spell it.

Once I have cleaned up the code again I will post it up so people can learn from my mistakes instead of repeating them. Cheers!
 

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,843
Reaction score
17,058
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
***Disclaimer....A lot of this was spit balling as I typed it up. And had to rewrite things over as I realized there were better ways to accomplish it. So it is a bit of rambling but it certainly helped me to improve my code.***

Update:
I have been tinkering with this for the last week trying to get it to properly work. The first issue I ran into was the space limitations of the Arduino Mini Pro. For the code that I'm writing I ended up with only enough space for managing the lights and the SD card. As I got to > 75% of the dynamic memory space used I ran into memory issues. The code currently goes through and polls the SD card files to get the start and end date-time for each light. I created classes to contain the light, and the SD card. I then use those as variables that contain information specific to the control of each relay as well as logging information. I kept having issues with knocking my cables free from the two analog ports for the time controller so I decided it was time to go through and solder everything together. Should have that done tonight. Once finished it will be ready for the Mega 2560 I ordered. Just the act of writing this out is helping to get my mind thinking of better memory management practices for the program. I have a feeling there may be a whole other program by the time I'm done.

Looking at changing my approach for programming the light timers to:
  • Only having a single start Time for the Blue Lights. Then a lapse time in minutes till the White lights come on. Followed by a lapse time in minutes before the white turns off. Ending with a lapse in minutes before the blues turn off.
Currently storing start and end time as a DateTime variable. When programming windows applications theres so much memory its easy to lose sight of small bits of data. A DateTime variable is stored as an 8 byte variable, meaning I'm using 32 bytes for saving four time variables. But if you use a start time, with 3 events you only use up (8+2+2+2) 14 bytes. The reason this is important is with a controller like the Mini Pro it only has 2048 bytes total that can be used to run everything. So trimming out and slim down is key. We call this "reFactoring". So I will be doing a bit more of that to try and be smarter in how I streamline the code and reduce overhead.

For setting up an acclimation period I'll use two bytes to store a days to run, and percentage complete. And possibly one more byte to define the percentage of reduction to start at. These variables can be stored on the SD card so we track the time even if something failed.

The new hardware is not supposed to be here till next week so for now I'm just working on refactoring these classes to work better within the limitations of memory space. A slight learning curve to remember my C++ days from 15 years ago. But enjoying this thoroughly. Anyone moving from managed code to this code can appreciate how much more difficult it is to be on point and know every line of your code and how to spell it.

Once I have cleaned up the code again I will post it up so people can learn from my mistakes instead of repeating them. Cheers!
Sounds like you are having fun with the code :)
It is a fascinating experience coding against such memory constrained system. I am curious to see how this goes, since you are keen on keeping things object oriented (classes etc). Each of those abstractions will cost you memory and some cpu (compared to purely imperative C code).
I bet the end result will be significantly different than your initial ideas, but thats standard software development, in my experience. But you'll also be a much better programmer (not in terms of OOPs designs, but in terms of efficient and performance oriented coding) .
I think there are memory ICs that you can hookup with most micro controllers, I am not sure if theres anything popular with arduino in particular. Another way to deal with this might be to use bitmap or some other datastructure that will consume less memory.
Keep us posted, and godspeed.
 

erk

Valuable Member
View Badges
Joined
Mar 19, 2014
Messages
1,382
Reaction score
2,049
Location
DFW
Rating - 0%
0   0   0
I was considering going the Arduino way for my controller, but decided against it due to the memory limitations. My first LED controller used an Uno. I realized I wouldn't be able to have a nice touch screen GUI and all the control I wanted, so I went with RPi. I still used an Arduino though. I communicate and power the Arduino via USB since I didn't want to buy digital sensors or ADCs nor want to deal with the issues of implementing PWM from the RPi. In a sense, I use the Arduino as a smart ADC/DAC.
 

CTM

New Member
View Badges
Joined
Jul 18, 2018
Messages
2
Reaction score
1
Rating - 0%
0   0   0
Might I suggest taking a look at the Teensy 3.6 from PJRC.com. Display interfacing, digital and analog ports, IC2, and PWM. It's all there. Take a look at Adafruit and Sparkfun for interface modules. Even Bluetooth, WiFi, and XBee.
 

CTM

New Member
View Badges
Joined
Jul 18, 2018
Messages
2
Reaction score
1
Rating - 0%
0   0   0
Might I suggest taking a look at the Teensy 3.6 from PJRC.com. Display interfacing, digital and analog ports, IC2, and PWM. It's all there. Take a look at Adafruit and Sparkfun for interface modules. Even Bluetooth, WiFi, and XBee.
 

Set it and forget it: Do you change your aquascape as your corals grow?

  • I regularly change something in my aquascape.

    Votes: 12 8.8%
  • I occasionally change something in my aquascape.

    Votes: 38 27.7%
  • I rarely change something in my aquascape.

    Votes: 66 48.2%
  • I never change something in my aquascape.

    Votes: 18 13.1%
  • Other.

    Votes: 3 2.2%
Back
Top