New Page 2

 

Welcome to SDR!

  • Amused
  • Angry
  • Annoyed
  • Awesome
  • Bemused
  • Cocky
  • Cool
  • Crazy
  • Crying
  • Down
  • Drunk
  • Embarraded
  • Enraged
  • Friendly
  • Geeky
  • Grumpy
  • Happy
  • Hungry
  • Piratey
  • Poorly
  • Sad
  • Shy
  • Sneaky
  • Tired
  • + Reply to Thread
    Results 1 to 15 of 15

    Thread: Raspberry Pi Tank Controller Thread

    1. #1
      sushi is offline Registered User
      My status is: pee in tank
       
      I am:
      Set you mood here...
       
      Join Date
      Jul 2015
      Location
      Mira Mesa
      Posts
      1,997

      Lightbulb Raspberry Pi Tank Controller Thread

      Hello everyone,

      I am using a Raspberry Pi to control my tanks lighting, ato and wavemakers. It could do much more including temperature control (hot and cold), feeding, water changes and water monitoring (with proper probes and calibration) or really whatever you can imagine.

      Occasionally people ask me about it and I thought it would be good to make a thread here where we can post code, designs and ideas and maybe all work on something that we can use and if others like it they can try it out on their tanks as well.

      Another benefit of this is that if more people with different equipment get involved we can make the pi more robust and compatible with more light fixtures etc.

    2. #2
      willp2 is offline Registered User
      Enter Status Here..
       
      I am:
      Set you mood here...
       
      Join Date
      Oct 2009
      Posts
      356
      I'll be following along and contribute however I can

    3. #3
      sushi is offline Registered User
      My status is: pee in tank
       
      I am:
      Set you mood here...
       
      Join Date
      Jul 2015
      Location
      Mira Mesa
      Posts
      1,997
      I pulled some pics out of an old post about this. You have to know a little about linux, python, sql etc. to work with this stuff. It is totally custom to my setup and not user-friendly at all, which is one reason why I am putting it here. If there is any interest, we can work to turn it into a more user-friendly and configurable product.

      I was looking through the code and there is a lot of messiness in there but I am just gonna post it with the caveat that it is jumbled up. I wrote part of it and added other features later, it could surely be reorganized and improved in many ways. Why haven't I done this? Because it works (I am lazy)!

      Here is a zip of the files http://www.filedropper.com/pi_2

      light_dimmer.py is the master file that runs through a loop every second and checks the current time, different timers and such to set lighting check the water levels and wave makers and whatever.

      temperature.py is just a little thing to read a w1 thermometer

      fishDatabase.py has a few things to read and write to config and log tables.

      fishtank.sql is to create those tables, first you need to make an empty database named fishtank

      I am also posting override.php this is the web config too

      The 8 outlet box is controlled by the Pi, I just found a tutorial here http://www.instructables.com/id/Web-...el-Powerstrip/ to build it, but I used a solid state relay instead of a mechanical relay.

      Float switches



      Power box and raspberry pi



      Hood with ground + PWM signal wires added



      Simple wiring diagram of ATO system
      Last edited by sushi; 02-12-2017 at 02:41 PM.

    4. #4
      willp2 is offline Registered User
      Enter Status Here..
       
      I am:
      Set you mood here...
       
      Join Date
      Oct 2009
      Posts
      356
      Very cool project. The attachments won't download for me unfortunatly.

      On PWM, I assume you are using the PWM pin, is that right? I'm looking at multiple PWM channels so I can ramp different colors at different rates. Perhaps with the addition of something like this https://www.adafruit.com/product/2327

    5. #5
      sushi is offline Registered User
      My status is: pee in tank
       
      I am:
      Set you mood here...
       
      Join Date
      Jul 2015
      Location
      Mira Mesa
      Posts
      1,997
      I tried moving the files here (and updated my original post) http://www.filedropper.com/pi_2

      You can use software PWM on, I think, any of the pins or at least most of them, and software pwm is sufficient for controlling the dimmer. I am controlling two sets of lights on mine (UV and 10k). Here is some info https://sourceforge.net/p/raspberry-...thon/wiki/PWM/

      Here is a code snippet from light_dimmer.py

      GPIO.setup(lightDimmerPin, GPIO.OUT)
      dimmer = GPIO.PWM(lightDimmerPin, 120) #GPIO.PWM(pin, frequency)
      dimmer.start(0)
      dimmer.ChangeDutyCycle(0.5)

      GPIO.setup(uvLightDimmerPin, GPIO.OUT)
      uvdimmer = GPIO.PWM(uvLightDimmerPin, 120)
      uvdimmer.start(0)
      uvdimmer.ChangeDutyCycle(0.5)
      Last edited by sushi; 02-12-2017 at 02:43 PM.

    6. #6
      pellikan is offline Registered User
      Enter Status Here..
       
      I am:
      Awesome
       
      Join Date
      Mar 2016
      Location
      Spring Valley
      Posts
      244
      You can also expand the PWM capability of the pi with the appropriate chipset such as this;
      https://www.adafruit.com/product/815

    7. #7
      sushi is offline Registered User
      My status is: pee in tank
       
      I am:
      Set you mood here...
       
      Join Date
      Jul 2015
      Location
      Mira Mesa
      Posts
      1,997
      Quote Originally Posted by pellikan View Post
      You can also expand the PWM capability of the pi with the appropriate chipset such as this;
      https://www.adafruit.com/product/815
      That is pretty neat, these little computers are amazing.

      Looking through my code and attempting to share it made me realize how much cleaner it could be. I think I will work on cleaning it up and making it easier to work with, otherwise it is not that useful.

    8. #8
      sushi is offline Registered User
      My status is: pee in tank
       
      I am:
      Set you mood here...
       
      Join Date
      Jul 2015
      Location
      Mira Mesa
      Posts
      1,997
      Here is a higher level overview of how I am controlling the lights with the pi. There are two things I am controlling with the pi: power to the light fixture, and dimming.

      To control the power, I am using an 8 channel relay board. The board uses 8 GPIO pins, 1 per channel. So I turn on the GPIO pin for the relay channel that is connected to the light fixtures 120v socket. Now it has power.

      [DISCLAIMER: I am a pre-novice at circuits and really need to read more, so please read https://reefledlights.com/driver-faqs/ ]

      For dimming, I am using dimmable LED drivers. I am using LDD-1000's which have a maximum current of 1000 mA each. LDD-700s have a max of 700 mA. Just google LDD-1000 or LDD-700 they are a few bucks each. The current and voltage of your LEDs, drivers and power supply are all related so please read more here https://reefledlights.com/driver-faqs/. This is one area where I need to learn more and it is not really pi-related, it is more of a DIY LED wiring topic.

      The pi has 2 hardware PWM pins, and you can use other pins for software PWM. I will cover using the 2 hardware PWM pins since that is the extent of my experience, but in the future we can work on controlling a hardware PWM board that can have way more than 2 PWM signals. PWM is pulse width modulation. What the PWM pins do [Another disclaimer: my knowledge is very basic, feel free to correct me] is send out a square wave (on, off, on, off) of power and the width of the on and off are the pulse widths. So if you set your duty cycle to 90% it will be ON for 90% of one cycle and off for 10% of one cycle. If you set it to 50% it will be on for 50% of a cycle and off for 50% of a cycle. You can easily change the duty cycle with the raspberry pi by the simple function ChangeDutyCycle([desired duty cycle]). If you want to set it to 50% you would use ChangeDutyCycle(0.5)

      Here is a picture of an LDD driver. It has 5 wires:



      On the top are the Vin. The DC power from your power supply goes here. The Vout wires go to the string of LEDs. The white DIM (dimmer) wire is where you send your PWM signal to, directly from the pi's PWM pin. The pi and LDD driver have to be grounded on the same circuit for the PWM signal to work.

      What the LDD does is set the output current to your LEDs to the duty cycle that is inputted. So if you set your PWM duty cycle to 50% the LDD will set the current to 50%, and your lights will be at 50% brightness.

      What I did was choose a ramp-up length of time, in my case 3 hours, and I change the duty cycle every 5 (for this example) seconds. I calculate the percent of brightness by dividing the current time since sunrise in seconds by the total length of sunrise in seconds. So if my sunrise is 10800 seconds long (3 hours) and the current time is 1 hour after sunrise (3600 seconds) I set the duty cycle to 3600/10800 or 0.33333

      This will set the brightness to 33.33333%

      Then 5 seconds later, the current time since sunrise in seconds will be 3605. The new duty cycle will be 3605/10800 or 0.33379629629

      I have a loop running continuously that updates the "seconds since midnight" every second, and it compares the current seconds since midnight to your "sunrise time in seconds" and "length of sunrise" to calculate these variables. If it determines that the current "seconds since midnight" is between the "sunrise time" and "length of sunrise" it will reclaculate the current percent of sunrise and adjust the duty cycle.

      The reverse happens for sunset.

      I thought this would be a short writeup but even at a high level it is pretty long. If you have any questions about specific code or the higher level logic I will be happy to answer.

      As I said I realize the need to refactor my code to make it much more universal and understandable. I will work on this.
      Last edited by sushi; 02-14-2017 at 11:31 PM.

    9. #9
      pellikan is offline Registered User
      Enter Status Here..
       
      I am:
      Awesome
       
      Join Date
      Mar 2016
      Location
      Spring Valley
      Posts
      244
      Sushi: a succinct and clear explanation of PWM and how to use it.

      Sent from my SM-N900P using Tapatalk

    10. #10
      willp2 is offline Registered User
      Enter Status Here..
       
      I am:
      Set you mood here...
       
      Join Date
      Oct 2009
      Posts
      356
      I'm finally getting around to trying to build at least the PWM functionality. What I am hoping to accomplish is having multiple set points throught day and ramp periods for each set point on at least 2 and ideally 3 channels. I had done something like this with Arduino years ago, but would like to have more direct control and flexibility. Ideally it would be nice to get some kind of interface to control everything from an easy to use

      Any chance you have that code available someplace? Looks like the link expired or something. I'll definetly share back whatever I come up with, but with the disclaimer that I am a complete noob with this kind of stuff.

      Thanks

    11. #11
      sushi is offline Registered User
      My status is: pee in tank
       
      I am:
      Set you mood here...
       
      Join Date
      Jul 2015
      Location
      Mira Mesa
      Posts
      1,997
      willp2 you can do exactly what you describe without much trouble at all. That is how I have mine set up. 2 channels ramping up and down, and also an override interface (web based) so I can turn the lights to whatever I want at any time.

      I am actually about to redo my LED's (got new bulbs) and rework the code and I can give you some pointers or code samples if that would be helpful. Are you familiar with GPIO and python? For controlling PWM you just choose one of your GPIO pins and tell the pi to make it a PWM pin. That takes two simple statements:

      GPIO.setup(lightDimmerPin, GPIO.OUT)
      dimmer = GPIO.PWM(lightDimmerPin, 120) #GPIO.PWM(pin, frequency)

      lightDimmerPin being the GPIO pin you choose for the first channel.

      Then you turn it on with this code, 0 is the initial duty cycle but you could make it anything:

      dimmer.start(0)

      And to change it you use the built in function ChangeDutyCycle. This will set it to 50%:

      dimmer.ChangeDutyCycle(0.5)


      I currently have a linear ramping from [sunrise time] to [sunrise time]+[length of sunrise]

      So it will start at 0% and ramp to my max % over a certain time period. As you can imagine, it is a simple calculation. You just get your current time and find out where it lies between your sunrise and length of sunrise time. So if your sunrise time is at 8:00 and the current time is 9:00 and you want a 3 hour ramp, your current duty cycle will be 33.33%

      How familiar are you with python and using GPIO? I don't want to patronize you with basic stuff if you already know it!

    12. #12
      willp2 is offline Registered User
      Enter Status Here..
       
      I am:
      Set you mood here...
       
      Join Date
      Oct 2009
      Posts
      356
      Not patronizing at all. I'm starting just above zero on this. Good with tech in general and persistant, but it's been a long time since I did any real programming at all. I think the concepts and timer stuff should be pretty similar to what I did in the past with Arduino, just with more set points. This is a project I did years ago and actually went on to have PC boards made and did a small run for other hobiests that wanted to tinker. http://www.sdreefs.com/forums/showth...er-version-.01. Getting my Pi built and and trying to get myself up to speed on some of the basics now.

    13. #13
      sushi is offline Registered User
      My status is: pee in tank
       
      I am:
      Set you mood here...
       
      Join Date
      Jul 2015
      Location
      Mira Mesa
      Posts
      1,997
      Quote Originally Posted by willp2 View Post
      Not patronizing at all. I'm starting just above zero on this. Good with tech in general and persistant, but it's been a long time since I did any real programming at all. I think the concepts and timer stuff should be pretty similar to what I did in the past with Arduino, just with more set points. This is a project I did years ago and actually went on to have PC boards made and did a small run for other hobiests that wanted to tinker. http://www.sdreefs.com/forums/showth...er-version-.01. Getting my Pi built and and trying to get myself up to speed on some of the basics now.
      Alright! I am planning to redo my lights tonight so I should have some updated python code and I am sure if you look through it you will be able to see what I am doing.

    14. #14
      newellio is offline Registered User
      Enter Status Here..
       
      I am:
      Set you mood here...
       
      Join Date
      Feb 2010
      Location
      north county
      Posts
      423
      Hey sushi, where did get that outlet box? I have a 16 outlet 3d printed box, but i'd much rather go with something metal like that?

      i have a pretty simple on/off electrical system right now controlled by a pi and some relays. About to dive in and add some probes and a pi controlled feeder.

    15. #15
      sushi is offline Registered User
      My status is: pee in tank
       
      I am:
      Set you mood here...
       
      Join Date
      Jul 2015
      Location
      Mira Mesa
      Posts
      1,997
      Quote Originally Posted by newellio View Post
      Hey sushi, where did get that outlet box? I have a 16 outlet 3d printed box, but i'd much rather go with something metal like that?

      i have a pretty simple on/off electrical system right now controlled by a pi and some relays. About to dive in and add some probes and a pi controlled feeder.
      Hello newellio DANG IT I AM AN IDIOT!!!! I meant to answer this a long time ago.

      My box isn't metal, it is actually plastic. I cannot seem to find the exact one I ordered but I just got a project box off amazon I think, one like this:

      https://www.amazon.com/uxcell-Dustpr...dp/B019OD62KU/

      Just search for one that is the correct size. I can measure mine if you want. Then I used a dremel with the roto bit to cut out the outlets. It isn't waterproof or anything and my cuts don't look very nice, but I am sure if you have an actual router attachment you could make it a lot better.

    + Reply to Thread

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts