Anyone doing an arduino controller?

I know there's a library on the Arduino Playground, at least. When the Hydra project gets to the software stage, we'll be developing something, since that's the chip we're using for our LCD.
 
Hi guys,

I need a little help! I finished building the controller using ICL7667CPAZ chip to control the dimming. It's working with the buckpuck (dimming). However, when I try with ELN 60-48P. It's only turn on/off the LEDs (50% power only). I use 10v wall quart and connect the Vcc in on the arduino to pin 6 of ICL7667CPAZ. When I measure the output V from ICL7667CPAZ, the V change from 0v to 10V according to the sketch that I use, but the LEDs are not dimming. I really need help to solve this problem since I'm not too sure about the ELN driver.
Thanks!
 
some of us are having some problems doing multiple things at the same time using arduino. We're trying to control our pumps and control dimmable LED drivers at the same time but the problem is that when the led's are dimming down, the pump is stuck at whatever state its at, which is a problem if you want to make a standing wave in the tank.

Here is an idea I had:

const int bluePin = 10; //blue LEDs
const int whitePin = 9; //white LEDs
const int pumpPin = 4; //tunze 6100

void pump() // this function creates a standing wave, like a wavebox would, in my 75
{
int a = 357; // you may need a different number here depending on your tank, pumps, etc..

analogWrite(pumpPin, 20); // pump is ON
delay(a);
analogWrite(pumpPin, 255); // pump is OFF
delay((a * 3) - 10); //i know this seems weird but its working to make a nice wave in my tank right now.
}

void blue(int val) /// these functions are just a wrapper for analogWrite
{
analogWrite(bluePin, val)
}

void white(int val)
{
analogWrite(whitePin, val)
}

byte getTime()
{
//whatever we need to put here to interface with the RTC I cant remember what goes here off hand
//just know that this function grabs the time for us.
}

void setup() {}

void loop() {

hour = getTime(); //gets the time or some function to get the hour of the day

switch (hour) { //changes the state of the pumps and LED's based on the hour of the day

case 1:
pump(); // does the pump sequence 1x
blue(5); //tells the LED's how bright they should be. when hour is 1 its 1AM, so white is off and blue is dim.
white(0); //doing it this way will have
break;

case 2:
//etcetera.. there will be 24 of these .. one for each hour of the day
break;

}

the blue() and white() functions will just be a wrapper for analogWrite and the pump function will just be a wrapper for the wavemaker program. In a finished program, there will be more blue, white and pump functions and variables and of course a much larger switch case.

Each time the loop happens it will check the time, go through the cases to figure out what it should do, (which it can do almost instantly i think) run through the pump program 1x and set LED brightnesses before starting over again.

So this is nice, and i think it would work, BUT the LED's will not be gradually dimming. there will be a somewhat sharp change each hour in the amount of light output. Before we were using for loops to incrementally dim the LED's but the delays inside the for loops mess up the pump functionality big time and really makes the code a mess (not like a giant switch case is any better but i can't think of any other way to do this).

What we really need is some kind of basic multi-tasking, which I don't know if this thing can do for sure, but if it can sit there and write to the serial console constantly while my pumps are working, I def think we can do this in a better way (ie with more gradual dimming), I just don't know if we can use nice easy functions like delay for the wavemaker anymore. I think we're going to have to use interrupts to do this properly. thoughts?
 
Check the code I just put in the other Arduino thread:

Code:
/*
 Arduino controller for reef aquariums

//** Current Functionality
// paramterized LED lighting control for reef aquariums
// use a DS1307 RTC to kick off lighting schedules
// trigger a master pin "on" when the preset start time is reached
//   then, fade up on a given slope
//         delay a set amount
//         fade back down
//   such that the photoperiod lasts the correct amount of time


//**  Circuit
// 
//  PWM pins described below connected to dimming circuits on drivers
// ledMaster pin below connected to a 120V AC relay to turn the LED drivers on and off
// grounds from drivers connected to arduino ground
// DS1307 RTC connected via I2C
//
//
//

 */

// Pins to control LEDs
int firstLed = 9;     // LED PWM channel for east end
int secondLed = 10;  // LED PWM channel for center

// Set up RTC
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68

// RTC variables
byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;

// Other variables. These control the behavior of lighting.
int minCounter = 0;         // counter that resets at midnight
int ledStartMins = 480;    // minute to start lights
int photoPeriod = 510;     // photoperiod in minutes
int photoStagger = 60;      // minutes to stagger photoperiods for each bank

void setup()  { 
  
// init I2C and One Wire  
  Wire.begin();
} 

/****** LED Functions ******/
/***************************/
//function to set LED brightness according to time of day
//function has three equal phases - ramp up, hold, and ramp down
void setLed(int mins, int ledPin, int start, int period)  {
  if (mins > start && mins <= start + (period / 3) )  {
    analogWrite(ledPin, map(mins - start, 0, period/3, 0, 255));
  }
    if (mins > start + (period / 3) && mins <= start + 2*(period / 3))  {
    analogWrite(ledPin, 255);
  }
    if (mins > start + 2*(period / 3) && mins <= start + period)  {
    analogWrite(ledPin, map(mins - (start + 2*(period/3)), 0, (period/3), 255, 0));
  }
}

/***** RTC Functions *******/
/***************************/
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second,        // 0-59
                   byte minute,        // 0-59
                   byte hour,          // 1-23
                   byte dayOfWeek,     // 1-7
                   byte dayOfMonth,    // 1-28/29/30/31
                   byte month,         // 1-12
                   byte year)          // 0-99
{
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.send(0);
   Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
   Wire.send(decToBcd(minute));
   Wire.send(decToBcd(hour));      // If you want 12 hour am/pm you need to set
                                   // bit 6 (also need to change readDateDs1307)
   Wire.send(decToBcd(dayOfWeek));
   Wire.send(decToBcd(dayOfMonth));
   Wire.send(decToBcd(month));
   Wire.send(decToBcd(year));
   Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
          byte *minute,
          byte *hour,
          byte *dayOfWeek,
          byte *dayOfMonth,
          byte *month,
          byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.receive() & 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}

/***** Main Loop ***********/
/***************************/
void loop()  { 
  // get time from RTC and put in hrs and mins variables
  getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  minCounter = rtcHrs * 60 + rtcMins;

  // determine if it is day or night, and act accordingly
  if (minCounter > ledStartMins && minCounter < ledStartMins + photoPeriod + 2*photoStagger)  {   //day
    // set LED states
    //digitalWrite(ledMaster, HIGH);
    setLed(minCounter, firstLed, ledStartMins, photoPeriod);
    setLed(minCounter, secondLed, ledStartMins + photoStagger, photoPeriod);
  }
  else  {   //night
    analogWrite(firstLed, 0);
    analogWrite(secondLed, 0);
  }
    
  // Get ready for next iteration of loop
  oldMins = rtcMins;
  oldHrs = rtcHrs;
  delay(1000);
}

My basic approach is to store the current "states" of anything I want to be gradually changing, then check the state and adjust by one step each time through the loop.

So, instead of saying:

"Spend the next 2 minutes slowly ramping the Tunze to this value"

Then saying:

"Spend the next half an hour slowly ramping the LEDs to full on"

then starting the loop over, you do this:

1) start the loop
2) get the current time
3) Check the current state of the LEDs against the current time, adjust by one step if necessary
4) Repeat for pumps
5) Update the new state of the LEDs and pumps, etc.
6) Restart the loop

The Arduino can fly through that in milliseconds, so while it's not literally "multitasking" it IS able to appear like it's doing several things at once. The trick is to never give it something that takes a long time unless you NEED to (i.e. holding a data line high for 3/4 second to get a reading from a one-wire temp sensor is pretty unavoidable). In other words, you shouldn't ever have a function made for dimming that has a delay call in it! Instead, you just determine how often you want it to "step" up or down, then each time through the loop, check to see if at least that much time has passed since the last time it stepped up or down. This accomplishes the same end result, but lets you do other things while the Arduino would have been "delaying."
 
I feel like I just found a pot of gold :dance:. Lot of good info here. Now I just need to try it out when I get home... Jeff
 
So I spent the last 4 hours trying to just be able to display time on my LCD with no luck. I have followed thread after thread and I say uncle. Can anybody point me in the right direction or post some code that will allow this to work? Maybe an arduino for dummies book? :lmao:....... Jeff
 
So I spent the last 4 hours trying to just be able to display time on my LCD with no luck. I have followed thread after thread and I say uncle. Can anybody point me in the right direction or post some code that will allow this to work? Maybe an arduino for dummies book? :lmao:....... Jeff

I tried for a several hours to get this working on my own. Eventually, I found everything I needed on the arduino website. I think they call it the playground or something. Just look for your "chip" in the time/RTC category and start from there.

Here's my "core" code. I can't really tear it down for you, so you'll have to pick the pieces out that do the time and display stuff.

You may need to go get some of the libraries included in order to get everything to work. I don't remember exactly, but the DS1307RTC was one of them, as was (I think) Time. Once those two pieces are there, you should be up and running. From your avatar pic, it appears that you've managed to display text on your LCD, but that stuff's included here, too.

Ignore all of the buttonState junk -- I was playing around with tutorial code for getting input from buttons and making LEDs light up in response -- you can cut out that whole if statement in the main loop.

EDIT -- the
Code:
 thing doesn't want to post the include statements correctly, so here they are without the greaterthan/lessthan sign thingies:

#include Time.h  
#include Wire.h  
#include DS1307RTC.h  // a basic DS1307 library that returns time as a time_t
#include LiquidCrystal.h


[code]
#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte res;
byte msb;
byte lsb;
int val;
int switchPin = 2;// switch is connected to pin 2
int ledPin = 13;
int val1;
int val2;      // variable for reading the pin status
int lightMode;
int buttonState;

void setup()  {
  
  pinMode(switchPin, INPUT);
  buttonState = digitalRead(switchPin);
  lcd.begin(20, 4);
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  Wire.begin();
 
}

void loop()
{
   displayTime();
   getTemp();
   //watchButton();
   //delay(1000);
    val = digitalRead(switchPin);      // read input value and store it in val
  lcd.setCursor(0,3);
  if (val != buttonState) {          // the button state has changed!
    if (val == LOW) {                // check if the button is pressed
      if (lightMode == 0){
        lightMode = 1;
         digitalWrite(ledPin, HIGH);
         lcd.print(".");
      }
      else {
        lightMode = 0;
        digitalWrite(ledPin, LOW);
        lcd.print(" ");
      }
      
    } else {                         // the button is -not- pressed...
      //Serial.println("Button just released");
    }
  }
  buttonState = val;      // save the new state in our variable
  }



void displayTime(){
  lcd.setCursor(15, 0);
  lcd.print(hour());
  printDigits(minute());
  //printDigits(second());
  lcd.print(" ");  
}

void displayDate(){
  //lcd.print(month());
  //lcd.print("/");
  //lcd.print(day());
  //lcd.print("/");
  //lcd.print(year());
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  lcd.print(":");
  if(digits < 10)
    lcd.print('0');
  lcd.print(digits);
}

void getTemp(){
  res = Wire.requestFrom(72,2); 
  if (res == 2) {
    msb = Wire.receive(); /* Whole degrees */ 
    lsb = Wire.receive(); /* Fractional degrees */ 
    val = ((msb) << 4);   /* MSB */
    val |= (lsb >> 4);    /* LSB */
    //Serial.println(val*0.0625);
    lcd.setCursor(0, 0);
    lcd.print((((val*0.0625)*9)/5)+32);
    //delay(500);
  }
}
 
Thanks for the code funkmuffin....

OK, so I just found out that I had to download the time library :hmm3: and put it into my Arduino hardware folder. I must have done it right because it no longer gives me a error when I try to upload. However, now I have two rows of blocks on my LCD. Tomorrows a new day i guess... Jeff
 
Thanks for the code funkmuffin....

OK, so I just found out that I had to download the time library :hmm3: and put it into my Arduino hardware folder. I must have done it right because it no longer gives me a error when I try to upload. However, now I have two rows of blocks on my LCD. Tomorrows a new day i guess... Jeff

That sounds like an un-initialized LCD. Make sure that this line:

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

References that actual pins that you have connected your LCD to.
 
Post your sketch or go to the Arduino forums over at Arduino.com.


There are plenty of posts on the Arduino forum involving the RTC. Search for RTC chip you are using.

Can you get anything to display on the LCD?

Make sure your telling the pin you assigned the clock to look for input from the RTC and send that input to the LCD. Some times it is as simple as that.
 
Post your sketch or go to the Arduino forums over at Arduino.com.


There are plenty of posts on the Arduino forum involving the RTC. Search for RTC chip you are using.

Can you get anything to display on the LCD?

Make sure your telling the pin you assigned the clock to look for input from the RTC and send that input to the LCD. Some times it is as simple as that.

Thanks, I will give that a shot tonight when I get home. I am getting blocks when I run the code above. Leaving everything hooked up I can upload the "hello world" program and it displays fine. I did verify that everything is initialized correctly and the pins are addressed the same in both programs. I also managed to upload a program where one of the Arduino on board leds flashed every second. I was hoping that was a sign the RTC is working.... Jeff
 
Well I tried about 50 different examples with no luck until I stumbled across a post that used a DS1307.h library instead of the DS1307RTC.h library and got it to work.

The code
Code:
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> // written by  mattt on the Arduino forum and modified by D. Sjunnesson
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  lcd.begin(20, 4); //20x4 LCD Display
  lcd.setCursor(3, 0); //Starts on column 3 row 0 
  lcd.print("LED Controller"); //Line above centers statement
  Serial.begin(9600);

  RTC.stop();
  RTC.set(DS1307_SEC,1);        //set the seconds
  RTC.set(DS1307_MIN,33);     //set the minutes
  RTC.set(DS1307_HR,11);       //set the hours
  RTC.set(DS1307_DOW,1);       //set the day of the week
  RTC.set(DS1307_DATE,13);       //set the date
  RTC.set(DS1307_MTH,6);        //set the month
  RTC.set(DS1307_YR,10);         //set the year
  RTC.start();

}

void loop()
{

  lcd.setCursor(0, 2); //Starts on column 0 row 2 
  lcd.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  lcd.print(":");
  lcd.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  lcd.print(":");
  lcd.print(RTC.get(DS1307_SEC,false));//read seconds
  lcd.setCursor(10, 2);
  lcd.print(RTC.get(DS1307_MTH,false));//read month
  lcd.print("/");
  lcd.print(RTC.get(DS1307_DATE,false));//read date
  lcd.print("/");
  lcd.print(RTC.get(DS1307_YR,false)); //read year 

  delay(1000);

}

What it looks like.
rtc1.jpg


Post on the Arduino forum

For those of you that were like me a week ago and have no clue. You have to install specific libraries into you Arduino folder. Without doing this it will never work. You will know that you have it installed right if you can click sketch > import libraries > DS1307. Once you installed the files into you folders you should be able to cut and paste the code, upload and have the time working. I can put up a step by step if need be. Thanks to all that help get me through this... Jeff
 
I went back and integrated some of my new found knowledge to the DS1307RTC.h library and was able to get it working adn I actually like this one better :spin3:. I found on the previous example that the seconds would not display properly and time was not being saved?

Code:
#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()  
{
  lcd.begin(20, 4); //20x4 LCD Display
  lcd.setCursor(0, 0); //Starts on column 0 row 0 
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet) 
     lcd.print("Somethings wrong!");
  else
     lcd.setCursor(3, 0); //Starts on column 3 row 0
     lcd.print("LED Controller");      
}

void loop()
{
   digitalClockDisplay();  
   delay(1000);
}

void digitalClockDisplay()
{ 
  lcd.setCursor(0, 2); //Starts on column 0 row 2 
  lcd.print(hour());
  printDigits(minute());
  printDigits(second());
  lcd.setCursor(10, 2); //Starts on column 0 row 2 
  lcd.print(month());
  lcd.print("/");
  lcd.print(day());
  lcd.print("/");
  lcd.print(year()); 
  //lcd.print(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  lcd.print(":");
  if(digits < 10)
    lcd.print('0');
  lcd.print(digits);
}
 
I have no programming knowledge or experience so even after reading a tonne of posts on sketches, I just can't combine those sketches that I copied into one sketch for my reef controller...

So, can anyone be kind enough to put together a sketch that fades LEDs on 2 channels for Sunrise/Sunset and display the time on a 16x2 LCD display.

Thank you very much :)
 
I'm in the same boat but trying to figure it out as I go. Two months ago I didn't even know what a Arduino was.. Jeff
 
Back
Top