Show Posts
Pages: 1 [2] 3 4 ... 19
16  Using Arduino / Programming Questions / Re: Anyone have a sketch to calculate the day of week based on the date? on: November 09, 2013, 03:55:01 pm
+1 on using the macro that comes with Time library.

the macro is defined as (and way simpler than the two examples above)
Code:
#define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday

just call
dayOfWeek(now()) to get the day of week for the current day.

why reinvent the wheel?
17  Using Arduino / Networking, Protocols, and Devices / Re: NTP Time Server on: November 09, 2013, 03:48:43 pm
well, there's that, and there is the practicality side of a solution.
time library does not sync itself, you must call the now() function for it to check if it is time to synchronize.
plus like I said, it does not matter if your time source is accurate to 1 billionth of a second if arduino is only accurate to 62 billionth. plus gps is not as accurate as you think, in theory it may be, but not from practical point of view. There is latency for the signal to get from satellite to the gps (ntp introduces network latency as well) , not to mention you are using a serial connection, which itself introduces timing error. Anyone who has ever used a gps for navigation knows how much error there is on location data.  Gps signal can disappear or be blocked, hence it is not 100% reliable as well.  Just understand its limitations so as not to fall into a false sense of security you are synchronized with atomic clock in fort collins.
the fastest sync is still via rtc. Connecting to ntp server on the internet adds a lag of several seconds (I've see it hang up to 10 seconds). That's why it is not practical to use it (and gps) as a main sync source. Hence you cannot sync to ntp or gps as often as you like. You will find all these out when you actually build your project.
18  Using Arduino / Networking, Protocols, and Devices / Re: Arduino as Web Server: visibility to outside world? on: November 09, 2013, 03:30:15 pm
the webcam video feed is from a foscam ip camera, but integrated into the web page.
if you buy a foscam, you get a dns service from foscam that works similar to dyndns, so thats what I use. I do not have a static ip per se, but my dynamic ip has been the same for the last 10 years. As long as you do not disconnect your modem (cable or dsl) too long, you will most likely get the same dynamic ip address from your isp.
19  Using Arduino / Networking, Protocols, and Devices / Re: Arduino as Web Server: visibility to outside world? on: November 09, 2013, 03:07:24 pm
you need to configure port forwarding on your router. Just google it, there are tons of instructions for it, there might even be one specifically for your router model.

Here is my webserver.
I use (modified) TinyWebserver library and wrote an html5/javascript program using jquery heavily for a mobile web interface to my arduino based aquarium controller. I access it via my smart phone. This is how it looks (everything is served out of the arduino, no external service used)



 

20  Using Arduino / Networking, Protocols, and Devices / Re: NTP Time Server on: November 09, 2013, 02:54:02 pm
this
https://www.sparkfun.com/products/10160
or half price on ebay
http://www.ebay.com/itm/DeadOn-RTC-DS3234-Breakout-Real-Time-Clock-DS3234-/280892418658?pt=LH_DefaultDomain_0&hash=item41667e2a62

 if accuracy is your concern, then syncing time every 8 hours is defeating the whole objective. A better solution perhaps is a combination gps + rtc. you can actually sync the rtc to gps once every 8 hours, and rtc to sync the arduino time every 5 minutes.
21  Using Arduino / Networking, Protocols, and Devices / Re: NTP Time Server on: November 09, 2013, 01:53:13 pm
And the gps needs to be outside for it to lock to the satellites.

GPS always gives accurate UTC time.  RTCs will always drift.

The ublox and MT3329 chipset GPS receivers are very sensitive and work very well inside a house. 

you can get more accurate RTC chips. It is still a  way simpler (and faster) solution to using GPS if all you need is time.  If you want accuracy, the time sync of 8 hours is not sufficient, that is why the default is 5 minutes. I would not count on the gps working on all indoor location. I know when I first setup my neo6 gps while indoors (for a quadcopter I am working on), it took several hours before it got a 3D lock (I actually was not expecting it to),. even outdoors it takes up to 10 minutes on a cold boot. so yes, it will work indoors, but...
22  Using Arduino / Programming Questions / Re: How to change the PWM frequency on ATmega 328p to 16Khz. on: November 09, 2013, 01:18:39 pm
Hi, thanks for the info.  It is honestly more than I can comprehend.  For me to try and understand any part of the datasheet, would be equivalent to opening a book written in a foreign language and expect to be able to read it.  I say this because I have looked at it before.  I am not afraid or unwilling to learn something, quite the contrary.  I am just realistic about my background level regarding these things.  I cannot ask the datasheet to explain itself!

So any chance this can be "dumbed" down even more, I know it is asking a lot?  Otherwise, I do indeed appreciate your efforts nonetheless!

cheers,

don't sell yourself short, it's really easier than it looks. I started in the same situation you are.

just think of it this way.

you start with a 16mhz clock.

you have a timer (8 or 16 bit). which will increment once per clock cycle.

so say you want 16000 hz, that is 1/16= 0.0625ms or 62.5us.

one cycle of the pwm is when counter starts from 0, counts to top (255 for 8 bit, 65536 for 16 bit, or can be user specified), then back down to 0.

so you need to divide 62.5us by either 512 (256*2 due to upcount then downcount), 65536*2, or a custom value.

62.5/512=0.122us. per timer increment using 8 bit.

now the arduino clock of 16mhz can be divided by 1,8,64,256,1024.
if we use divided by 1, 1/16 = 0.0625us, which is too fast to get 16khz
if divided by 8. 16mhz/8=2mhz, 1/2 = 0.5us per timer increment.
we cannot get the exact 16khz freq using the standard 8bit or 16bit top, so we must use a custom counter top (top is the number where the timer switch direction and counts downwards)

lets use the divided by 1 value of 0.0625us per count.
so we divide 62.5/0.0625 =1000
this means if timer increments once every 0.0625us, after 1000 increments/decrements, 62.5us has elapsed, exactly the time period for 16khz!  Since we need 1000 count, 8 bit timers are out.

since the counter counts up then down, divided 1000 by2 to get the 500 for TOP.

Now you got all the values, just figure where in the timer registers to set these.
TCCR1A, TCCR1B for setting the clock divider, wave generation mode
ICR1 for the TOP
OCR1A for the duty cycle.

wave generation mode 10 is whats needed here. it clears the pin low on  match to OCR1A value on counting up, and sets the pin high on OCR1A match on the way down.

say you set OCR1A to 125.
counter start from 0, count to 500, back down to 0.
lets start from the top, from 500, the pin is low. when it decrements down to 125, it will set the pin high, once it hits 0, it start incrementing, and when it reaches 125, it set the pin low.

so the pin is high from 125 to 0 to 125 for a total of 250 clock cycles out of 1000 or exactly 25% duty cycle.

all these info can be found in atmega328 datasheet chapter 15. study section 15.11 carefully for the register description. and you can see in my code how I arrived at the values to set the registers to.

you can use that pwm library, but it won't hurt to understand how this works.
23  Using Arduino / Storage / Re: Using Lots of Data From SD Card on: November 08, 2013, 12:44:36 pm
unless you are mass producing, you will not save anything using atmega328 chip and building your circuit. you can get an arduino pro mini now for $3.45 and can use the full 32kb program space if you program via icsp.

anyway, if you are doing animation, is that at 15 frames per second? or probably slower right? at 15 frames, that gives you 66ms to setup the data and send it out.did you try this at all yet? sd read should take a shorter time that sd write. worse case you can use timer interrupt code to control your led line, reading from a circular buffer containing the frame data, and the sd card read will be in the main loop just continuously filling up the buffer.
24  Using Arduino / Networking, Protocols, and Devices / Re: i2c circuit on: November 08, 2013, 12:27:30 pm
you can just disable internal pullup on arduino i2c, and have pullup on the 3.3v circuit and you can connect arduino to 3.3v i2c device directly without any level conversion. I've never seen a single i2c error using this method.
25  Using Arduino / Networking, Protocols, and Devices / Re: NTP Time Server on: November 08, 2013, 12:22:16 pm
I think if you need time on a stand alone device (or no internet connection),  another option is to just get an RTC for cheap, set the time and be done. This is useful though if you are already using the gps for other purpose, like navigation. And the gps needs to be outside for it to lock to the satellites.
26  Using Arduino / Programming Questions / Re: How to change the PWM frequency on ATmega 328p to 16Khz. on: November 08, 2013, 11:57:58 am
To get the most out of this, you must read the atmega328 datasheet timer chapter.

The code I gave is for mega, and is not intended for you to cut and paste. you need to read up so you can figure out how to modify it to suit your requirements.

for the frequency you need, you can only use timer1 (16 bit). Hence only pins PB1 and PB2 (digital pin 9 and 10) can be used on the atmega328.

you will need to change PB5 in the code to PB1 in the code and use digital pin 9 for the output.

pin11 is connected to timer2 which is an 8 bit timer.

once you setup the registers, all you need to do to change the duty cycle is assign a value between 0 and 500 to OCR1A.
OCR1A=250 will give you 50% duty cycle PWM @16khz on digital pin 9

BTW, since the code altered the clock divider for timer1, you cannot use analogWrite on pin10 anymore. You can however setup timer1 register B to do PWM similar to what was done to register A in my code example.
27  Using Arduino / Programming Questions / Re: output format question - XML? on: November 07, 2013, 08:56:30 pm
there is a problem here
Code:
<faultDescription>Bit D6 is Set. It's Possible your RTD+ and RTD- is shorted. Please verify your connection and your Low Fault Threshold Value.</faultDescription>

single quote (or apostrophe) is not allowed. you must escape it. The following characters must be escaped
"   &quot;
'   &apos;
<   &lt;
>   &gt;
&   &amp;
28  Using Arduino / Networking, Protocols, and Devices / Re: Daylight Saving Time adjust with Ethernet NTP on: November 07, 2013, 07:24:22 pm
the key is to call the function only at 2am. (well, actually I call it once on reboot also)
since on reboot, I use ntp time (which is not dst adjusted), I have to use 1am for dstEnd instead of 2am, since the ntp of end time is really 1am.
The boolean isDst I use to format the time string with  PDT or PST for pacific daylight time or pacific standard time which is my local time zone.
this is my autoDST function that calls the isDST function. I call it everyday at 2am.
Code:
void autoDST(time_t t) {
  if (IsDST(t)==isDst) return;
  isDst = !isDst;
  if (isDst)
    RTC.set(t+SECS_PER_HOUR);
  else
    RTC.set(t-SECS_PER_HOUR);
  setTime(RTC.get());
  logMessage(F("Auto adjusted DST time."));
  char buf[20];
  logMessage(F("Current time is "),getdatestring(now(),buf));
}

boolean IsDST(time_t t)
{
  tmElements_t te;
  te.Year = year(t)-1970;
  te.Month =3;
  te.Day =1;
  te.Hour = 0;
  te.Minute = 0;
  te.Second = 0;
  time_t dstStart,dstEnd, current;
  dstStart = makeTime(te);
  dstStart = nextSunday(dstStart);
  dstStart = nextSunday(dstStart); //second sunday in march
  dstStart += 2*SECS_PER_HOUR;//2AM
  te.Month=11;
  dstEnd = makeTime(te);
  dstEnd = nextSunday(dstEnd); //first sunday in november
  dstEnd += SECS_PER_HOUR; //1AM
  return (t>=dstStart && t<dstEnd);
}
29  Using Arduino / Networking, Protocols, and Devices / Re: Daylight Saving Time adjust with Ethernet NTP on: November 07, 2013, 07:06:10 pm
deleted.
see my updated post.
30  Development / Other Software Development / Re: simple XMLwriter library for Arduino on: November 07, 2013, 02:26:47 pm
How about adding check to escape the following characters

"   &quot;
'   &apos;
<   &lt;
>   &gt;
&   &amp;

or if not, to warn not to use those characters.
Pages: 1 [2] 3 4 ... 19