Time for additional Ethernet add-on with PWM output
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
From the PWM expansion code. Wire () commands
Re: Time for additional Ethernet add-on with PWM output
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.
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.
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
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
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
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
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
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
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;
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
I have no clue how I missed that. Thanks
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
deleted
Last edited by DrewPalmer04 on Wed Feb 20, 2013 10:16 am, edited 1 time in total.
Re: Time for additional Ethernet add-on with PWM output
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?
If you are not using the RTC anymore, why do you want to communicate with it using the getDateDs1307() function?
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
old RTC. deleted
Last edited by DrewPalmer04 on Wed Feb 20, 2013 10:16 am, edited 1 time in total.
Re: Time for additional Ethernet add-on with PWM output
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:
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
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);
epoch should contain the epoch time.
I use this:
http://www.onlineconversion.com/unix_time.htm
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
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
So I need to define what second, minute, hour, dayOfWeek, dayOfMonth, month, year is...
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

Re: Time for additional Ethernet add-on with PWM output
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.
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.
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
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
Thanks for the education...I'll mess with this
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
Removed old code to minimize confusion. See new code.
Last edited by DrewPalmer04 on Thu Jan 31, 2013 6:31 am, edited 4 times in total.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
I need to clean it up. But it works!
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
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
Can you confirm that your time is correct?
Use Serial.print every minute and let it run, watching for the time
Use Serial.print every minute and let it run, watching for the time
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
Yep. Time is correct. I have it syncing only once a day now too.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
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
millis() is a unsigned long variable size, which means it only consumes 4 bytes.
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
Hmm. Any other thoughts?
Re: Time for additional Ethernet add-on with PWM output
Serial.print is your friend....
Debugging is part of coding
Debugging is part of coding

Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
Haha ok. I'll work on it more.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
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
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.
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.
Roberto.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
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.

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.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Time for additional Ethernet add-on with PWM output
Moonrise confirmed working. Must be in other part of code.
Fade in confirmed working.
Fade in confirmed working.