Show Posts
Pages: 1 [2] 3 4 ... 19
16  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.
17  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.
18  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.
19  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;
20  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);
}
21  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.
22  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.
23  Using Arduino / Programming Questions / Re: How to change the PWM frequency on ATmega 328p to 16Khz. on: November 07, 2013, 12:48:46 pm
you will need to use timer registers directly and not use analogWrite.
use the code from this post
http://forum.arduino.cc/index.php?topic=196815.msg1454187#msg1454187
set ICR1=500 to get a period of 62.5us (16khz)
set OCR1A to any value from 0 to 500 (you got a 500 resolution pwm).

the code is for mega, I think it should work on 328, but check if pwm pin for timer 1 is same PB5 for 328.


24  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 06, 2013, 03:17:35 pm
(which mostly goes to show that if you NEED this level of optimization, you probably NEED to look at the actual code generated, ......
If you need this level of optimization you might look at a faster/heavier processor and just keep the code as maintainable/readable as possible. Optimized code seldom is (from experience).

I know, its harder and harder to fight that, even arduino is jumping on the 32-bit bandwagon. just code unoptimized and use a faster processor. I see that all the time now.

gone are the days when you are challenged to write a program on an IBM punch card to print a 10 digit number in reverse order, and the punch card can only take 8 instructions.

programming skill goes down each generation.
times change.
25  Using Arduino / Programming Questions / Re: output format question - XML? on: November 06, 2013, 02:40:17 pm
\r\n is ok after the closing tag. likewise \t or spaces to indent before opening tag to make it readable.
like
Code:
<a>a</a>\r\n

but \r is not ok between the tags. (with exceptions, but that is getting too technical)

BTW, \r is not just ignored by xml parsers,  it must not be present inside the tags, xml parsers are required to normalize presence of line endings in the infoset (to use the proper w3c spec terminology),
26  Using Arduino / General Electronics / Re: Stranded Wire + Breadboards on: November 06, 2013, 02:30:25 pm
I do see the novelty and coolness to be able to show your buddy you can crimp your own jumper wires. smiley
creativity is still the key, like the suggestion above to just solder a resistor leg to the stranded wire. and do not take that literally, you can be creative and use something in place of the resistor leg. 
27  Using Arduino / General Electronics / Re: Stranded Wire + Breadboards on: November 06, 2013, 01:14:34 pm
seems like an awful lot of trouble (not to mention the cost of the crimper) just to connect servo motor wire to the breadboard.

I have a bunch of these (and alligator clip jumpers)  for use on stranded wires, pcbs, or anything that cannot be connected directly by the standard jumper wire. Or just be creative and use what you got.
28  Using Arduino / Programming Questions / Re: output format question - XML? on: November 06, 2013, 01:04:30 pm
do you know if println generates \r\n ?
if so, you must not use it inside xml tags, as only \n is valid between xml tags.
strictly speaking, all white spaces can be trimmed between the opening xml tag and the first character of the element text, and between the last character of the element text and the closing xml tag.  a white space is defined as  space, \r, \n, \t.
29  Using Arduino / Motors, Mechanics, and Power / Re: Timing problems with short 2...12 us pulses generation with PWM out on: November 05, 2013, 04:34:39 pm
I think for what you need, the simplest solution is to just use mode 0 (normal mode) and just control the pin output high low in the compare match ISR. You have total control of pulse width and frequency.. I don't think the suggestion to use the wave generation mode and setting com1a1 to 0 is not quite right, hence. might as well use normal mode.

if you div clock by 8, one count is 0.5us. to get a 2us pulse at 10hz,
set pin high at count=0
set pin low at count=4 (4*0.5=2us)
set pin high at count =200,000 (since this is higher than 8 or 16 bit, you have to count the overflows)
for 2000hz pulse
set pin high at count = 1000 (again if you are using 8bit timer, you need to count the overflows)
30  Community / Bar Sport / Re: I just got the fastest delivery from China :) on: November 05, 2013, 03:01:52 pm
got another fast delivery. just 3 business days. This item costs 99cents total!

Pages: 1 [2] 3 4 ... 19