Time for additional Ethernet add-on with PWM output

Expansion modules and attachments
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Time for additional Ethernet add-on with PWM output

Post by rimai »

Exactly...
Read that post.

Sent from my Galaxy S3 using Tapatalk 2
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Lol tricky. Ok thanks. I won't bother anyone as much. Sorry all
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Ok I've got my code almost done. Bought an arduino book and it's making way more sense. One last question. Your opinion on how to get to the RTC. If I use the head unit jumps to get SDA SCL will this not mess with my single hub for my RF expansion or will the RTC pass through my Ethernet module back to the expansion. I've got all my Wire.read() in place but I wanted to ensure that it will through put to my expansion before I get to modifying the jumper. Thanks!!!
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Time for additional Ethernet add-on with PWM output

Post by rimai »

I think the easiest is to just solder some wires straight into the jumper that you can then connect to your arduino.
The jumpers still need to be there and you need a parallel connection
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Thanks for that. I was thinking the same. Reassuring to get it confirmed. Thanks!
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Will this work for pulling the RA RTC? :)

Code: Select all

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

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f); 
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());

}
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Time for additional Ethernet add-on with PWM output

Post by rimai »

Think so...
Try it.
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Well..epic fail...I did the soilder on the jumpers and every time I connect SDA the display goes out...I can connect SCL with no issues..

Any ideas as to why this is happening?

I figured something was going on so I went ahead and did a serial print through the Ethernet module but it still shows 00:00:00 00/00/0000

So the RA head unit is failing and not outputing a RTC either when I try the wire idea on the SCL SDA jumpers?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Tried new jumpers and even a new jumper (without the wire) hooked up to SDA the display goes blink and once removed the system works normally...I hope I didn't short something out? My RF expansion relies on the SCL SDA :( and isn't functioning now
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Time for additional Ethernet add-on with PWM output

Post by rimai »

What if you remove the RF?
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Good troubleshooting...I'll try that now and report back.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

YOU'RE THE MAN!!! unplugged RF...hooked up SCL SDA...instant RTC to the ethernet
PWM kicked in (with test LED)...it's following my slope.
Hooked up RF and the vortechs kicked on following my internal memory as they should...

BUT OOPS...once Delay.On() kicks in the system freaks out again...Work around or should I just remove that from the RA code?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Time for additional Ethernet add-on with PWM output

Post by rimai »

What Delay.On() ?
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

For my RA:
ReefAngel.Relay.DelayedOn( Port4,5);
ReefAngel.Relay.DelayedOn( Port8,5);

Once they engage the system resets for unknown reasons.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Time for additional Ethernet add-on with PWM output

Post by rimai »

What do you have in those ports?
Did you try without the equipment?
Curious to know if the problem is the equipment turning on or the relay being activated
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

It has to do with the RTC I think..

I only used Wire.read() but somehow the RTC date and time has reset on the RA? How can I get this back?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Got the RTC back...trying again now with the Wire.read() stuff...it just messed up my time...fixed on RA...going to try again with the ethernet module
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Odd...just odd
Got RTC set on the RA...but I get a status light if the ethernet module isn't plugged in...
once the ethernet is plugged in the display resumes with correct time.
I plug in my RF all is good..but now no PWM output from the ethernet module.

I had a Serial.print() on the ethernet but because it is powered by the RA I have no way of seeing the time. Any idea how to see if the time is being Wire.read()?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

It just wrote the time again to the RA. I'll post my code...not sure how it is doing this...this is probably the problem. :(
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Here it is...pieced together and some original

Code: Select all

#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68 //set Real Time Clock Location
#include <SPI.h>
#include <Ethernet.h>

int ontime = 420 ;         // Time of day (in minutes from midnite eg. 450=7:30 AM) to begin photoperiod fade in 420 = 7 AM
int photoperiod = 420  ;   // Amount of time array is on at full power in minutes 510 = 8.5 hours              * Light ramps up beginning at 
int blueramptime = 60 ;    // Time for blue LEDs to dim on and off in minutes                                  * 10 AM and full pwer at 11:30 AM
int whiteramptime = 30 ;   // Time for white LEDs to dim on (after blues)  and off (before blues) in minutes   * Ramp down at 8 PM and off at 9:30 PM
int moonontime = 1290 ;    // Time in Minutes that moonlight comes on 1290=9:30 PM
int moontime = 120 ;       // Amount of time array is on at moon power in minutes
int moonpower = 3 ;        // Moon Intensity 0-255
int bluemin = 0 ;          // Minimum dimming value of blue LEDs, range of 0-255
int bluemax = 255 ;        // Maximum dimming value of blue LEDs, range of 0-255
int whitemin = 0 ;         // Minimum dimming value of white LEDs, range of 0-255
int whitemax = 255 ;       // Maximum dimming value of white LEDs, range of 0-255

int fan1 = 14;             // Fanspeed digital pin 12
int fan2 = 15;             // Fanspeed digital pin 13
int blue1 = 9;             // blue LEDs connected to digital pin 9 (pwm)
int white1 = 6;            // white LEDs connected to digital pin 6 (pwm)
int blue2 = 5;            // blue LEDs connected to digital pin 5 (pwm)
int white2 = 3;           // white LEDs connected to digital pin 3 (pwm)
int percentbright = 0 ;    // Percentage of brightness holder
int x = 1 ;                // Number holder for countdowns
int relmoontime = 0 ;      // Relative (to current time if turned on during moon time) moon on time
const int buttonPin = 41;  // The number of the pushbutton Digital pin
int buttonState = 0;       // Variable for reading the pushbutton status
int analogPinb = 0;        // Potentiometer connected to analog pin 0 for blue
int analogPinw = 2;        // Potentiometer connected to analog pin 2 for white
int bval = 0;              // Variable to store the blue read value
int wval = 0;              // Variable to store the white read value
int daybyminute = 1;       // Current timeof day in minutes


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0D, 0x28, 0x0E };
IPAddress ip(192,168,1, 114);
IPAddress remoteserver(198,171,134,6); // forum.reefangel.com
EthernetClient clientout;
unsigned long lastmillisout=millis();
unsigned long lastmillisin=millis();
boolean sending=false;
char strout[400];

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);







/* R T C   C L O C K   D S 1 3 0 7 */
byte decToBcd(byte val)    // Convert normal decimal numbers to binary coded decimal
{
  return ( (val/10*16) + (val%10) );
}


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

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.write(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

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

}

void ethernetmodule()//allows the ethernet module to run in loop without failure
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      while (client.available()) {
        char c = client.read();
        if (sending==false) Serial.write(c);
        lastmillisin=millis();        
      }
      while (Serial.available()){
        memset(strout,0,sizeof(strout));
        int b=Serial.readBytesUntil('>',strout,sizeof(strout));
        client.print(strout);
        client.print(">");
        if (millis()-lastmillisin>2000)
        {
         // Serial.flush();
          lastmillisin=millis();
          client.stop();
        }
      }
      if (millis()-lastmillisin>2000)
      {
        //Serial.flush();
        lastmillisin=millis();
        client.stop();
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
   
  }
  else
  {
    if (Serial.available())
    {
      memset(strout,0,sizeof(strout));
      int b=Serial.readBytesUntil('\n',strout,sizeof(strout));

      if (b>10)
      {
        sending=true;
        Serial.print(strout);
        Serial.println(" HTTP/1.0");
        Serial.println();
        if (clientout.connect(remoteserver, 80)) 
        {
          
          clientout.print(strout);
          clientout.println(" HTTP/1.0");
          clientout.println();
          lastmillisout=millis();
        }
      }
    }
    while (clientout.available()) {
      char c = clientout.read();
      Serial.print(c);
      if (millis()-lastmillisout>8000)
      {
        lastmillisout=millis();
        clientout.stop();
        sending=false;
      }
    }
    if (!clientout.connected())
    {
      clientout.stop();
      sending=false;
    }
  }
  if (millis()-lastmillisout>8000)
  {
    lastmillisout=millis();
    clientout.stop();
    sending=false;
  }



  //GET /status/submitp.aspx?t1=806&t2=0&t3=0&ph=441&id=test&em=0&rem=0&key=&atohigh=0&atolow=0&r=0&ron=0&roff=255 HTTP/1.0

  //GET /status/submitp.asp?t1=806&t2=0&t3=0&ph=441&id=test&em=0&rem=0&key=&atohigh=0&atolow=0&r=0&ron=0&roff=255 HTTP/1.0
  //Host: forum.reefangel.com
  //
  //GET /status/submitp.aspx?t1=806&t2=0&t3=0&ph=441&id=test&em=0&rem=0&key=&atohigh=0&atolow=0&r=0&ron=0&roff=255 HTTP/1.0
  //Host: forum.reefangel.com
  //Connection: Keep-Alive



}
void onesecond() //function that runs once per second while program is running
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
}

void setup() {

  // initialize the manual pushbutton pin as an input:
  pinMode(buttonPin, INPUT);    



  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  Wire.begin();

  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  // Ethernet connection ok and server started

  Serial.print(hour, DEC);
  Serial.print(":");
  Serial.print(minute, DEC);
  Serial.print(":");
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.println(year, DEC);
// print end
  analogWrite(blue1, bluemin);
  analogWrite(white1, whitemin);
  analogWrite(blue2, bluemin);
  analogWrite(white2, whitemin);
  analogWrite(fan1, 0);
  analogWrite(fan2, 0);
}

void loop()
{
  ethernetmodule();//loop the ethernet code


  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes




  int bluerampup;
  if (daybyminute >= ontime) {
    bluerampup = (blueramptime - (daybyminute - ontime));
    if (bluerampup <= 0)
      bluerampup = 1;
  }
  else {
    bluerampup = blueramptime;
  }

  int whiterampup;
  if (daybyminute >= (ontime + blueramptime)) {
    whiterampup = (((whiteramptime + blueramptime) - (daybyminute - ontime - bluerampup)));
    if (whiterampup <= 0)
      whiterampup = 1;
  }
  else {
    whiterampup = whiteramptime;
  }

  int whiterampdown;
  if ((ontime + photoperiod + blueramptime + whiteramptime) <= daybyminute){
    whiterampdown = ((ontime + photoperiod + blueramptime + (2*whiteramptime)) - daybyminute);
    if (whiterampdown < 0)
      whiterampdown = 1;
  }
  else {
    whiterampdown = whiteramptime;
  }

  int bluerampdown;
  if ((ontime + photoperiod + blueramptime + (2*whiteramptime)) <= daybyminute) {
    bluerampdown = ((ontime + photoperiod + (2*blueramptime) + (2*whiteramptime)) - daybyminute);
    if (bluerampdown < 0)
      bluerampdown = 1;
  }
  else{
    bluerampdown = blueramptime;
  }

  int relmoontime;
  if (moonontime + moontime - 1440 > 0) // If moontime goes beyond midnite
    if (daybyminute < 1440)  //  If current time less than midnite
      relmoontime = (moonontime + moontime - daybyminute);  //rel moon time minus midnite
    else
      relmoontime = (moonontime +moontime - (1440 - daybyminute) ); //re moon time minus midnite minus time after midnite
  else
    if (daybyminute>=moonontime)
      relmoontime= moontime + moonontime - daybyminute;
    else
      relmoontime = 1;

 getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
  if (daybyminute >= ontime && daybyminute <= (ontime + blueramptime + whiteramptime)) //if time is in range of fade in, start fading in 
  {
    if (bluerampup >= blueramptime)
      bluerampup = blueramptime;
   
    // fade blue LEDs in from min to max.
    for (int i = bluemin ; i <= bluemax; i++) // setting blues in smooth rampup 
    { 
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH Then go manual
      if (buttonState == HIGH) {  
        i = 255;
      }
      percentbright = int(i/2.55);  // Convert the 0-255 to a percentage
      analogWrite(blue1, i); 
      analogWrite(blue2, i); 
      if (i <=75) {
        analogWrite(fan1, 70);
      }
      else {
        analogWrite(fan1, i);
      }
     
      int countdown = ((bluerampup*60)/bluemax); // calculates seconds to next step based on ramp time
      if (countdown < 1)
        countdown = 1;
      while (countdown>0)
      {
        onesecond(); // updates clock once per second
        countdown--;
      }
    }      
    getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
    daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
    int countdown = 61; // wait one minute after rampup to account for rounding difference
    while (countdown>0)
    {
      onesecond(); // updates clock once per second
      countdown--;
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH Then go manual
      if (buttonState == HIGH)   
        countdown = 0; 
    }

    // fade white LEDs in from min to max.
    if (whiterampup >= whiteramptime)
      whiterampup = whiteramptime;
    analogWrite(blue1, bluemax); 
    analogWrite(blue2, bluemax); 
    analogWrite(fan1, 255);
    for (int i = whitemin; i <= whitemax; i++) // setting white in smooth rampup 
    { 
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH Then go manual
      if (buttonState == HIGH) {  
        i = whitemax; 
      }
      percentbright = int(i/2.55);
      analogWrite(white1, i); 
      analogWrite(white2, i); 
      if (i <=75) {
        analogWrite(fan2, 70);
      }
      else {
        analogWrite(fan2, i);
      }
      
      int countdown = ((whiterampup*60)/whitemax); // calculates seconds to next step
      if (countdown < 1)
        countdown = 1;
      while (countdown>0)
      {
        onesecond(); // updates clock once per second
        countdown--;
      }
    } 

    countdown = 61; // wait one minute after rampup to account for rounding difference
    while (countdown>0)
    {
      onesecond(); // updates clock once per second
      countdown--;
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH Then go manual
      if (buttonState == HIGH)   
        countdown = 0; 

    }
  }
  
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
  if (daybyminute >= (ontime + blueramptime + whiteramptime) && daybyminute <= (ontime + blueramptime + whiteramptime + photoperiod)) // if time is in range of photoperiod, turn lights on
    //to maximum fade value
  {

    analogWrite(blue1, bluemax);
    analogWrite(blue2, bluemax);
    analogWrite(fan1, 255);
  
    analogWrite(white1, whitemax); 
    analogWrite(white2, whitemax); 
    analogWrite(fan2, 255);
  
    int countdown = 61; // wait one minute toaccount for rounding difference
    while (countdown>0)
    {
      onesecond(); // updates clock once per second
      countdown--;
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH Then go manual
      if (buttonState == HIGH) {  
        countdown = 0; 
      }
    } 
  }
  
   getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
  if (daybyminute >= (ontime + photoperiod + blueramptime + whiteramptime) && (ontime + photoperiod + whiteramptime + 2*blueramptime) >= daybyminute)
  {
   
    // fade white LEDs out from max to min in increments of 1 point:
    if (whiterampdown >= whiteramptime)
      whiterampdown = whiteramptime;
    for (int i = whitemax; i >= whitemin; i--) // setting i value 255 to 1
    { 
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH Then go manual
      if (buttonState == HIGH) {  
        i = 0;
      }
      analogWrite(blue1, bluemax);
      analogWrite(blue2, bluemax);
      analogWrite(fan1, 255);
    
      percentbright = (float)(i/(whitemax/100.0));
      analogWrite(white1, i); 
      analogWrite(white2, i); 
      if (i <=75) {
        analogWrite(fan2, 70);
      }
      else {
        analogWrite(fan2, i);
      }
      
      int countdown = ((whiterampdown*60)/whitemax); // calculates seconds to next step
      if (countdown < 1)
        countdown = 1;
      while (countdown>0)
      {
        onesecond(); // updates clock once per second
        countdown--;
      }
    } 
    // fade blue LEDs out from max to min in increments of 1 point:
    if (bluerampdown >= blueramptime)
      bluerampdown = blueramptime;
    for (int i = bluemax ; i >= bluemin; i--) // decrease from 255 to 1
    { 
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH Then go manual
      if (buttonState == HIGH) {  
        i = 0;
      }
      percentbright = (float)(i/(bluemax/100.0));
      analogWrite(blue1, i);
      analogWrite(blue2, i);
      if (i <=75) {
        analogWrite(fan1, 70);
      }
      else {
        analogWrite(fan1, i);
      }
     
      int countdown = ((bluerampdown*60)/bluemax); // calculates seconds to next step
      if (countdown < 1)
        countdown = 1;
      while (countdown>0)
      {
        onesecond(); // updates clock once per second
        countdown--;
      }
    }
    int countdown = 61; // wait one minute to account for rounding difference
    while (countdown>0)
    {
      onesecond(); // updates clock once per second
      countdown--;
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH Then go manual
      if (buttonState == HIGH) {  
        countdown = 0; 
      }
    }
  }

getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
  if (daybyminute >= moonontime) //|| If it is time to turn on the moonlights
  { 
   
    for (int i = (relmoontime * 60)-65 ; i >= 0; i--) // relative moon time countdown
    { // if time is in range of photoperiod, turn lights on to maximum fade value
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH Then go manual
      if (buttonState == HIGH) {  
        i = 0;
      }
      analogWrite(blue1, moonpower);
      analogWrite(blue2, moonpower);
      if (moonpower <=75) {
        analogWrite(fan1, 0);
      }
      else {
        analogWrite(fan1, moonpower);
      }
     
      analogWrite(white1, 0); 
      analogWrite(white2, 0); 
      analogWrite(fan2, 0);
   
      onesecond(); // updates clock once per second
    }   
    analogWrite(blue1, 0);
    analogWrite(blue2, 0);
    analogWrite(fan1, 0);
   
    analogWrite(white1, 0);
    analogWrite(white2, 0);
    analogWrite(fan2, 0);
   
    relmoontime=0;
  }
}  // END LOOP
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

After more testing. Any timer once it reaches 0 OR delay.on the system panics. And I have to correct the issue my syncing time with the iPhone app. Then everything is good again? Odd?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

rimai wrote:What do you have in those ports?
Did you try without the equipment?
Curious to know if the problem is the equipment turning on or the relay being activated

Removed equipment and it still panics. Sorry just saw that post.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Time for additional Ethernet add-on with PWM output

Post by rimai »

Does it mean that if you remove the DelayedOn(), everything works?
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Removed delayed.on() but then used feeding mode to feed the fish and once it reached "0" on the count down it panicked again.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

rimai wrote:Does it mean that if you remove the DelayedOn(), everything works?

On top of the timer reaching "0" the RTC resets on the RA. I have to sync the RA with the iPhone app. Then it's all good again until I use any timer mode (water change, feeding etc) is there something in my code writing to the RTC to make it reset?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Time for additional Ethernet add-on with PWM output

Post by rimai »

IDK...
I know it is something in the now() function that is causing your issue.
Take a look at the Time library.
Are you constantly reading the RTC in your code?
You should only read every hour or so and sync with it.
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

rimai wrote:IDK...
I know it is something in the now() function that is causing your issue.
Take a look at the Time library.
Are you constantly reading the RTC in your code?
You should only read every hour or so and sync with it.
Ok I need to sync every hour right now i do every minute and try that. I'll also look at the now()
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

I'll be trying alligator clips in place of the jumpers I believe too. I'm suspicious of the status light when the arduino Ethernet isn't even hooked up to it. I believe a jumper was compromised when adding the wires. This way I'll have a parallel connection plus wires for the expansion. Sorry I sort of use the forum as reminders/progress notes as well. Lol
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Time for additional Ethernet add-on with PWM output

Post by DrewPalmer04 »

Roberto. Can you explain how to send the RTC specifically on the RA side with the $$$? This way I can read that output specifically from the RA? That may help my RTC issue. Thanks!
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Time for additional Ethernet add-on with PWM output

Post by rimai »

What $$$?
Roberto.
Post Reply