Show Posts
Pages: [1] 2 3 ... 19
1  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet client connect can return negative number on: August 22, 2014, 08:52:34 am
thanks. I just entered a new report.

https://github.com/arduino/Arduino/issues/2252
2  Using Arduino / Networking, Protocols, and Devices / Ethernet client connect can return negative number on: August 22, 2014, 01:36:25 am
I spent a good half a day today trying to figure out why my ethernet client code suddenly does not work anymore.

It turns out if you are using "hostname" to connect, ethernet client will do a dns lookup, and if dns lookup fails, connect returns a negative value, which tests to TRUE if you do this code

Code:
if (client.connect("www.google.com",80)) {
  //apparently connected, NOT if there was a dns error.
}

The correct code is to explicity test for 1

Code:
if (client.connect("www.google.com",80)==1) {
}

I think someone should change the WebClient example that comes with Arduino Ethernet library and update the documentation as well.
3  Using Arduino / Programming Questions / Re: Incorrect calculation for micros() for CPUs running at 20 MHz, 24 MHz etc. on: November 14, 2013, 02:11:27 pm
sorry, but you are looking at this incorrectly.

start from 0, how many times do you increment to get to 255?
you say 256?
I say 255.
at 0, time is 0, after 255 increments, time is 1020 us.

If you really think it is 256, you need to have arduino correct their pwm frequency to 488 instead of saying it is 490.

I  can guarantee you without any doubt that I am right on this one.
and since this thread is about accuracy, I thought I should point out your mistake.
4  Using Arduino / Programming Questions / Re: Incorrect calculation for micros() for CPUs running at 20 MHz, 24 MHz etc. on: November 14, 2013, 01:47:36 pm
But aren't you still out by a small amount?

Running at 16 MHz, the interrupt service routine is called every...
(1/(16000000/(64*256)))*1000 = 1.024 ms


the above is not quite right.
16000000/64 = 250,000
1/250,000=4us per timer count.
but timer counts from 0 to 255 is only 255 increments, not 256, so the time is 1020us to be exact.
The overflow interrupt is called once every 510 count, not 512, since 0 and 255 only occurs once (check the datasheet)
hence one cycle is 2040us, or 490.19608 which is the PWM frequency (otherwise if it is really 2.048, arduino documentation should say the pwm frequency is 488hz).

It took me a while to figure out why I am getting 2.04ms cycle on the oscilloscope when I initially thought it should be 2.048.
5  Using Arduino / Programming Questions / Re: Arduino HTML timer on: November 14, 2013, 01:15:55 pm
I have an implementation that's similar to what you are looking for.

what I do is I run a javascript countdown on the html page, and periodically (like every 5 seconds I think, I can't remember),  the javascript will make a call back to the arduino to get the actual time in order to synchronize the local countdown.

I implement json service on the arduino to provide the countdown value, and it is an ajax call from the html file.

I initially tried to update the countdown in real time, but the network latency is very unpredictable, so I just do a local countdown and just synchronize.

this is a screenshot of the page doing the countdown
6  Using Arduino / Programming Questions / Re: Port manipulation Arduino Uno on: November 14, 2013, 12:28:32 pm
this
Code:
PORTD &= ~(_BV(PD4)|_BV(PD7));
instead of this
Code:
PORTD = PORTD & ~B00000000;// set pins 4&7 LOW
7  Using Arduino / Programming Questions / Re: creating an averaging function correctly on: November 12, 2013, 11:37:06 am
from performance point of view
Code:
average = ((9 * average) + newValue + 5) / 10;
the divider better be a multiple of 2  (even if average and newvalue are floats)
Code:
average = ((7 * average) + newValue + 5) / 8;



indeed better for integer values. However, if the value is a float, I think the method using sum and avg variable is more efficient, as it only involves one addition, one subtraction and one division.
8  Using Arduino / General Electronics / Re: Arduino monitoring Amp flow from a Car 12V Battery to some drvice on: November 11, 2013, 05:00:47 pm
I think there might be a confusion between amps and ampere-hour.
If all you want is to cut power at 10a, just replace the inverter fuse with a 10a fuse. (brings lots of 10a fuse)
9  Using Arduino / Programming Questions / Re: Anyone have a sketch to calculate the day of week based on the date? on: November 09, 2013, 04:21:35 pm
ok, I missed the part where OP said he cannot use time library.

I'd be more curious as to why and address that.

Just the same, the time library code is better, as Paul said, OP can adapt that. Just takes a little creativity. smiley-razz

At first I could not use Time library because I need to call time function now() from that ISR, so I modified the Time library with a few lines change so I have an interrupt friendly now() function. No need to reinvent the wheel.
10  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?
11  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.
12  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.
13  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)



 

14  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.
15  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...
Pages: [1] 2 3 ... 19