Time for additional Ethernet add-on with PWM output

Expansion modules and attachments
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 »

From the PWM expansion code. Wire () commands
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 »

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.
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 »

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
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's tm?
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'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
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 »

One Part of the code states read(tm); but I don't know what it is :)
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 »

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.
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 have no clue how I missed that. 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 »

deleted
Last edited by DrewPalmer04 on Wed Feb 20, 2013 10:16 am, edited 1 time in total.
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'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?
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 »

old RTC. deleted
Last edited by DrewPalmer04 on Wed Feb 20, 2013 10:16 am, edited 1 time in total.
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 »

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
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 »

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...:)
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 »

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.
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 »

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
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 »

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.
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 »

Cool!!! :)
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 »

I need to clean it up. But it works!
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 »

My output pins for the PWM spaz after about 10 min. What could be causing this? :(
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 »

Can you confirm that your time is correct?
Use Serial.print every minute and let it run, watching for the time
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 »

Yep. Time is correct. I have it syncing only once a day now too.
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 »

Could the milli() in the Ethernet side of the code you provided me be using up all of my RAM?
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 »

millis() is a unsigned long variable size, which means it only consumes 4 bytes.
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 »

Hmm. Any other thoughts?
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 »

Serial.print is your friend....
Debugging is part of coding :)
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 »

Haha ok. I'll work on it more.
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 »

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?
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 »

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.
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 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.
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 »

Moonrise confirmed working. Must be in other part of code.
Fade in confirmed working.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
Post Reply