Show Posts
Pages: 1 2 3 [4] 5 6 ... 248
46  Using Arduino / Programming Questions / Re: Timer2 is slighly less accurate on: April 11, 2014, 02:05:25 pm
It is! Just saw this recently in another thread.

If it isn't using the Arduino runtime then I don't see how you could consider it an Arduino sketch - it is just a bit of firmware running on the Arduino hardware.

Guess I'd have to look up the definition of an Arduino sketch. IMHO, if the Arduino IDE compiles it, and the Arduino hardware runs it, then I don't have any issue with calling it a sketch. Funny because I hate the word sketch anyways. Whatever. YMMV, a rose by any other name ... smiley-grin
47  Using Arduino / Programming Questions / Re: Timer2 is slighly less accurate on: April 11, 2014, 11:34:35 am
That isn't an Arduino sketch, is it?

It is! Just saw this recently in another thread.

You've provided your own main() and don't initialise or make any calls to the Arduino runtime.

Maybe that's the point smiley-wink
48  Using Arduino / Programming Questions / Re: Timer2 is slightly less accurate on: April 11, 2014, 08:28:20 am
Consider the differences between the two sketches.

The first sets Timer1 to interrupt at a 5000Hz rate. The second sets Timer2 to interrupt at a 1000Hz rate.

The ISR in the second sketch simply toggles the pin. But in the first sketch it only toggles the pin if x<10. This would seem to give the same frequency on the output pin, but the variable x is never zeroed. So the output is probably five cycles, but then x continues to be incremented and will overflow and go negative after about 32K interrupts. At that point the toggle will happen at every interrupt until x counts back to zero, then the whole cycle repeats.

If the goal is for the two sketches to output the same frequency, then it seems like there would be more than a slight difference between the two.
49  Using Arduino / Programming Questions / Re: Timer2 is slightly less accurate on: April 11, 2014, 07:43:44 am
I think it is time to describe your overall project.

It must be something very interesting if the variability you are talking about matters.

Agree. Specifically, in what way is it inaccurate, and by how much? What exactly are you seeing on the scope?
50  Using Arduino / Microcontrollers / Re: How to choose cheapest AVR for a task on: April 10, 2014, 10:05:07 pm
Right now I'm testing this out with an ATTiny84, but these seem to be relatively expensive, the cheapest I see them is for ~$2.50 on Ebay vs $3 for a full ATMega328.

Mouser's prices for ATtiny84A-PU:

1:      $1.41   
10:     $1.28   
25:     $0.896 
50:     $0.832 
100:    $0.80
51  Community / Exhibition / Gallery / Re: Vote for my data logger on Atmel's design contest on: April 08, 2014, 10:16:09 am
I voted five times!
Good luck Jack

LOL, thanks very much, Lefty.  I'm not sure what to make of a contest that allows stuffing of the ballot box! An idea for an Arduino Ethernet client sketch did cross my mind. I could submit a second entry to the contest, "An AVR Contest Entry that Votes for Itself" smiley-grin
52  Community / Exhibition / Gallery / Re: Vote for my data logger on Atmel's design contest on: April 08, 2014, 06:40:45 am
Thanks, Robert!
53  Using Arduino / Sensors / Re: Using DS1820 data as integers on: April 07, 2014, 10:10:36 pm
I just use the OneWire library, it only takes a few lines of code to read the sensor. I also like to work in the integer domain to avoid the code size and run time overhead of floating point.

#include <OneWire.h>          //
#include <Streaming.h>        //

const int DS_PIN = 5;         //DS18B20 temperature sensor
OneWire ds(DS_PIN);

void setup(void)

void loop(void)
    delay(1000);                //wait for temperature conversion to complete

    int C = dsReadC16();
    int F = dsReadF10();
    Serial << (C + 8) / 16 << "C " << (F + 5) / 10 << "F\n";

//    float C = dsReadC16() / 16.0;
//    float F = dsReadF10() / 10.0;
//    Serial << C << "C " << F << "F\n";

//start temperature conversion
void dsStart(void)

//get temperature as °C times 16
int dsReadC16(void)
    uint8_t dsData[9];

    ds.write(0xBE);                //read scratchpad

    for ( int i=0; i<9; i++) {     //read 9 bytes
        dsData[i] =;

    if (OneWire::crc8(dsData, 8) == dsData[8]) {
        return (dsData[1] << 8) + dsData[0];
    else {
        return -9999; //CRC error

//get temperature as °F * 10
int dsReadF10(void)
    long tC16 = dsReadC16();        //°C * 16
    if (tC16 == -9999) return tC16;
    long tF160 = tC16 * 18;         //°F * 160 but without the 32 degree offset
    int tF10 = tF160 / 16;          //°F * 10
    if (tF160 & 15 >= 8) tF10++;    //round up to the next tenth if needed (x & 15 is more efficient than x % 16)
    tF10 = tF10 + 320;              //add in the offset (*10)
    return tF10;
54  Using Arduino / Sensors / Re: Counting Multiple FSR Presses on: April 07, 2014, 09:38:09 pm
jmarx34, something to try, just connect an FSR from any pin to ground. Enable the internal pullup resistor and treat it as you would a push button, i.e. a digital input, not analog. Debounce like any other switch.

I have a project that has several tactile button switches and this FSR:

My first impulse was also to read it with the ADC, but I only needed to know whether there was pressure on it or not. So on a lark I tried using a digital input and to my amazement it worked perfectly. Your project is a bit different so YMMV but definitely worth a try.

I use a debounce library that I wrote. The only thing I do differently is to use 100ms debounce time for the FSR; I usually use 20-25ms for tact buttons. If you don't have favorite debounce code, give it a try:

You could use one of the example sketches to see if it will work with your FSR, just change the debounce time from 20 to 100:
55  Community / Exhibition / Gallery / Vote for my data logger on Atmel's design contest on: April 07, 2014, 01:28:33 pm
I submitted my "Double-A Data Logger" to Atmel's "Simply AVR" design contest. Check it out; if you like it, I will certainly appreciate a vote.

I can't seem to figure out a direct URL, so go to, then click VOTE in the upper right.  My entry is first on the page right now, but I think it will move as new ones come in.

I'm glad to have any feedback on the project too, whether or not you vote. Thanks!
56  Using Arduino / Project Guidance / Re: Should I be Worried about Random Noise Triggering Outputs on: April 06, 2014, 10:07:57 pm
For all unused pins, make them inputs with the internal pullup resistors enabled, e.g.

pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
57  Using Arduino / Programming Questions / Re: Why == works in an if statement? on: April 06, 2014, 09:23:15 pm
Don, you're welcome. The answer to your next question is in the Arduino Reference or any C++ reference (for example, this one). Let us know if you don't find it smiley
58  Using Arduino / Programming Questions / Re: Write anything to EEPROM on: April 06, 2014, 09:13:37 pm
When using ATmel AVR programmers and programming software (and presumably others), it is possible to program EEProm directly using the programmer. That way the strings never reside in flash. I do not know how to define the hex file that would contain the strings, but that information is presumably available.

The Arduino IDE in fact produces the .eep file which is an Intel hex file that AVRDUDE can upload to EEPROM. I'm not aware that can be done from the IDE, or that the bootloader would handle it, but it could be done outside the IDE as a separate step with an ICSP.
59  Using Arduino / Programming Questions / Re: Why == works in an if statement? on: April 06, 2014, 08:41:48 pm
They are two different operators. = is the assignment operator. == is a comparison operator.

In the first sketch,
  if ((Switch7 == LOW)  && (cycleCounter = 0)) {
causes an assignment to happen in the if statement. cycleCounter is set to zero.

In C and C++, assignment statements also return a value, that being the value that the variable on the left side of the statement was set to. This is why the statement above is acceptable syntax but obviously not what is wanted. The value of the assignment statement is zero, which in the context of the if statement is taken as a logical false value. Since this is part of an AND (&&) construct, the overall if statement will never be true because the second argument is always false.
60  Using Arduino / Microcontrollers / Re: Attiny84 & Arduino Serial Monitor on: April 06, 2014, 06:41:57 pm
The frequency of the internal RC oscillator is only guaranteed to be calibrated from the factory within 10%, which is not generally close enough for reliable asynchronous serial communication. I haven't tried serial comm with an ATtiny84 myself, but I've found that many or even most of the ATmega328Ps I've tried are close enough. So it may just be bad luck but there are two options. (1) Change the clock source to an external crystal or resonator, or(2) Calibrate the internal RC oscillator (the datasheet says it can be calibrated within 1%).
Pages: 1 2 3 [4] 5 6 ... 248