Page 3 of 7

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

Posted: Sun Jan 20, 2013 7:21 pm
by DrewPalmer04
From the PWM expansion code. Wire () commands

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

Posted: Sun Jan 20, 2013 7:37 pm
by rimai
You will need to start your slave with Wire.begin(15), where 15 is the I2C address.
Make sure to attach interrupt with Wire.onReceive(receiveEvent);
Everytime your master send byte data, your slave will execute void receiveEvent() function.
You don't need $$$. I just had in there, but you really don't need it.
Then on master, you can the byte variable to slave.

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

Posted: Mon Jan 21, 2013 2:31 pm
by DrewPalmer04
Where to I define "tm" I'm going to try and use RA RTC code but I cannot find tm defined anywhere in the libs

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

Posted: Mon Jan 21, 2013 3:12 pm
by rimai
What's tm?

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

Posted: Mon Jan 21, 2013 3:22 pm
by DrewPalmer04
It's used in the time functions of DS1307RTC. It must be a variable, buffer or? It's involved in creating the time but I can't find where it is defined. Ive looked in the #include references too of the RTC RA code. Ive searched high and low for it in the RA libs

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

Posted: Mon Jan 21, 2013 3:46 pm
by DrewPalmer04
One Part of the code states read(tm); but I don't know what it is :)

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

Posted: Mon Jan 21, 2013 3:51 pm
by rimai
Inside Time.h

Code: Select all

typedef struct  { 
  uint8_t Second; 
  uint8_t Minute; 
  uint8_t Hour; 
  uint8_t Wday;   // day of week, sunday is day 1
  uint8_t Day;
  uint8_t Month; 
  uint8_t Year;   // offset from 1970; 
} 	tmElements_t, TimeElements, *tmElementsPtr_t;

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

Posted: Mon Jan 21, 2013 3:55 pm
by DrewPalmer04
I have no clue how I missed that. Thanks

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

Posted: Wed Jan 23, 2013 9:07 am
by DrewPalmer04
deleted

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

Posted: Wed Jan 23, 2013 9:31 am
by rimai
I'm not sure what you mean...
If you are not using the RTC anymore, why do you want to communicate with it using the getDateDs1307() function?

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

Posted: Wed Jan 23, 2013 9:37 am
by DrewPalmer04
old RTC. deleted

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

Posted: Wed Jan 23, 2013 9:41 am
by rimai
Humm... Still not sure I understand...
Or maybe you are missing something.
The Time library does all that for you.
The minute you call this function:

Code: Select all

setTime(epoch);
The Time library is synced in time and you can call any of its functions... now(), hour(), minute() etc...
epoch should contain the epoch time.
I use this:
http://www.onlineconversion.com/unix_time.htm

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

Posted: Wed Jan 23, 2013 9:52 am
by DrewPalmer04
OK that helps...I'm just having an issue of defining
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{

*second =
*minute =
*hour =
*dayOfWeek =
*dayOfMonth =
*month =
*year =


}

If I can figure that out my code will just work as it did with RTC.
The problem is if I try:
*second = second()

I get "error: 'second' cannot be used as a function"

I need these to = something that will tell my code what the second,minute, hour, dayOfWeek, etc is.


The reason behind this is that every time I start a loop in the custom code I'm calling for

Code: Select all

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
So I need to define what second, minute, hour, dayOfWeek, dayOfMonth, month, year is...:)

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

Posted: Wed Jan 23, 2013 10:01 am
by rimai
Why?
The Time library already does all that already.
I thought you were trying to move away from DS1307 and going to NTP.
The NTP is already syncing the time and you already have the Time library synced to your local time.
Just use the functions of the Time library just like the way RA does.
if you call hour(), you will get the hour of the day.... There are plenty of function calls already pre-defined inside the Time library.

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

Posted: Wed Jan 23, 2013 10:03 am
by DrewPalmer04
AH-HA moment. I was thinking I had to make this happen..but it's already done in the Time.h

Thanks for the education...I'll mess with this

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

Posted: Wed Jan 23, 2013 1:55 pm
by DrewPalmer04
Removed old code to minimize confusion. See new code.

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

Posted: Wed Jan 23, 2013 2:29 pm
by rimai
Cool!!! :)

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

Posted: Wed Jan 23, 2013 2:40 pm
by DrewPalmer04
I need to clean it up. But it works!

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

Posted: Wed Jan 23, 2013 3:33 pm
by DrewPalmer04
My output pins for the PWM spaz after about 10 min. What could be causing this? :(

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

Posted: Wed Jan 23, 2013 3:39 pm
by rimai
Can you confirm that your time is correct?
Use Serial.print every minute and let it run, watching for the time

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

Posted: Wed Jan 23, 2013 3:41 pm
by DrewPalmer04
Yep. Time is correct. I have it syncing only once a day now too.

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

Posted: Wed Jan 23, 2013 3:43 pm
by DrewPalmer04
Could the milli() in the Ethernet side of the code you provided me be using up all of my RAM?

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

Posted: Wed Jan 23, 2013 3:44 pm
by rimai
millis() is a unsigned long variable size, which means it only consumes 4 bytes.

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

Posted: Wed Jan 23, 2013 3:47 pm
by DrewPalmer04
Hmm. Any other thoughts?

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

Posted: Wed Jan 23, 2013 3:51 pm
by rimai
Serial.print is your friend....
Debugging is part of coding :)

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

Posted: Wed Jan 23, 2013 3:55 pm
by DrewPalmer04
Haha ok. I'll work on it more.

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

Posted: Wed Jan 23, 2013 4:13 pm
by DrewPalmer04
Maybe you can help me talk through this. The PWM is sapzing but I have full control from the iPhone app. This would mean the issue is in the PWM part of the code?

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

Posted: Wed Jan 23, 2013 4:33 pm
by rimai
Yeah, I think it is in your PWM section of your code.
Here is what I would suggest:
No more than 1 analogWrite() per channel. I see you have several instances of it.
Change the global variable (blue1,white1,blue2,white2) and apply it at the end of the loop by calling the analogWrite().
This way, you can Serial.print what you are sending and know exactly what is going on.

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

Posted: Wed Jan 23, 2013 5:01 pm
by DrewPalmer04
Thanks very much for that help :)

Before I had byte sec min etc. then getDS1307RTC for every section of fade in. Then fade out etc. I had it all sectioned off. But now the code is all connected by dayMinute (hour() * 60 + minute()). I think this is getting confused because its not sectioned like it was before.

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

Posted: Wed Jan 23, 2013 5:17 pm
by DrewPalmer04
Moonrise confirmed working. Must be in other part of code.
Fade in confirmed working.