body:
Added at top:

**Your code runs correctly on a $US3 Arduino Nano** :-)

It seems extremely likely that you have a hardware problem of some sort.

If you have a voltmeter you can try these easy checks.
I carried these out to be sure that I got what was expected and the results are as you would expect them to me. Use a meter set to DC Volts - typical common meter circuitry averages the PWM well.

1. Remove LED etc connection to pin 9.
Measure the voltage from the 5V pin to ground. If powered from USB this will usually be slightly below 5V.

2. Run your code with the analogWrite set to 128 ie

   analogWrite(pinNine, 128);

3. Measure the voltage on pin 9 relative to ground. It should be close tohalf the voltage on the 5V pin in 1. above. This is because the analogWrite value is controlled by PWM with values from 0 to 255. 128/255 ~= 50% so output is 50% of Vref = 5V by default. in a 5V system.

4. Set analogWrite to

        analogWrite(pinNine, 25);

5. The voltage on pin9 should be about 10% of the voltage on the 5V pin.

IF you get approximately the voltages shown in 3. and 5. your code is working OK and your hardware is OK.  If not then 'summat aglae'.

Try another analog pin.

Check that the red wire to the LED goes to UNO ground.

The voltmeter is a surer way of checking that the LED is as you can see actual numeric values that result.

____________________

**OLDER:**

It always helps greatly if you show PIN IDs on photos so people can be confident re what you have done.

If you view the whole UNO-R2-R3 connector with numbering it is obvious that the important pinouts are the same.
If however you view part of the connector with no numbering/ pin names shown,  then on the R3 there are additional pins on the ARef end of the connector which make comparisons'more difficult).

You APPEAR to have an Arduino UNO R3
It would help if you gave actual model and weblink in future "just in case it matters". .

You appear to have connected to pin 9  (as you intended to)
Pin 9 has PWM capability, as required.
It seems that your code should work.

Thusly

![enter image description here][1]

IF the red wire connects to ground the circuit seems electrically correct.
Does it?

Code LOOKS OK.

Try digital write on / off on pin 9 to see if LED changes and that the port behaves as expected. A bad port pin is possible.

What pin is serial on?

Try another pin with PWM capability to see if it changes.

____________________

ARDUINO UNO R3 from [UNO home page](http://arduino.cc/en/Main/arduinoBoardUno)

The connector pinouts vary widely between models of UNO.

![enter image description here][2]

  [1]: https://i.stack.imgur.com/lC2XS.jpg
  [2]: https://i.stack.imgur.com/ErT8E.jpg


sender: user

message:
Issue with PWM output pin

I'm just starting off with using the Arduino and was learning about PWM
(http://arduino.cc/en/Tutorial/PWM).
Below is what my circuit looks like.

![enter image description here][1]

  [1]: https://i.stack.imgur.com/MDY9x.jpg

Below is the very simple code.

    const int pinNine = 9;    // LED connected to digital pin 9

    void setup() {
      // initialize serial communications at 9600 bps:
      Serial.begin(9600);
      // set the digital pins as outputs
      pinMode(pinNine,OUTPUT);
    }

    void loop() {
      analogWrite(pinNine, 0);
    }

I was expecting my LED to not be lighted as its a 0% duty cycle. I even change the pinNine outputValue to (64, 127, etc) but for some reason the LED is always lighted. Any ideas?

_____________________________________________

sender: assistant

body:
Flat side of LED is `-`. This means that your white wire is on `-` side and your red wire on `+` side. Therefore your power rail connection is reversed... and therefore your LED is ON when you send `0` on PWM. By the way, you will set the LED OFF by writing `255` on PWM.

Solution: connect power rails correctly and everything will be back to normal.


body:
Ok, it seems my understanding of the PWM was wrong. I tried the circuit and code from here (http://arduino.cc/en/Tutorial/Fade) and it worked as expected (fade in and out).

Actually when i wrote my original code i was expecting the LED to blink. So, as i got closer to 255 i was expecting it to spend more time being 'lit', as compared to 0 where it should spend less time being 'lit'.

> I even change the pinNine outputValue to (64, 127, etc) but for some
> reason the LED is always lighted.

It being lighted makes sense. What i missed out was it being dimmer when the value was lower.

Thanks for all your help..


message:
Tile NeoPixel NeoMatrix 8x8

As a programmer I am new and lack some knowledge in electronic and I will appreciate the help.

I wish to connect 3 Adafruit NeoPixel NeoMatrix 8x8 - 64 RGB LED Pixel Matrix (https://www.adafruit.com/products/1487) can some one please provide me a scheme how to connect/tile 3 these NeoMatrix 8x8 to one Arduino Uno.

Thanks a lot

body:
On [**the page that you cite**](https://www.adafruit.com/products/1487) they say

If, say, you need MORE blinky, **you can chain these together.**

 - For the second shield, connect the DIN connection to the first panel's DOUT.

 - Also connect a ground pin together

 - and power with 5V.

 - There you go!

You can chain as many as you'd like although after 4 or more panels you may run low on RAM if you're using an UNO. Watch your power usage too, you may need a 5V 10A power supply for so many of these!

________________

Related:

They also say:

 - There is a single data line with a very timing-specific protocol. Since the protocol is very sensitive to timing, it requires a real-time microconroller such as an AVR, Arduino, PIC, mbed, etc. It cannot be used with a Linux-based microcomputer or interpreted microcontroller such as the netduino or Basic Stamp.

 Our wonderfully-written Neopixel library for Arduino supports these pixels! As it requires hand-tuned assembly it is only for AVR cores but others may have ported this chip driver code so please google around.

 An 8MHz or faster processor is required.


body:
On the products page, they link to the [Neopixel Uberguide][1], which should really contain what you need :-)

The good thing about the NeoPixels is that they can be chained, since each pixel is supplied with VCC, GND, Data in and Data out. Data out of LED1 will be data in for LED2, and afaik you can make infinitely long chains this way

  [1]: https://learn.adafruit.com/adafruit-neopixel-uberguide


body:
I found the http://fastled.io/ libary to be a useful and well documented (https://github.com/FastLED/FastLED/wiki/Overview) alternative to Adafruit's NeoPixel library.

FastLED has some clever compression of palettes, and many other nice features that might save you valuable memory when using many neopixels.


message:
Getting sensor data wirelessly from arduino to PC

I am working on a project that involves sending motion sensing data wirelessly from an arduino to computer. Sensor readings have to be transmitted continuously (say every mili second). I am not sure if Xbee is my bet. I came across [this link][1]
which suggest s that there should be atleast 10 ms delay between packets if you're using xbees.

What are your experiences with xbees? I don't want to waste money.

  [1]: http://www.faludi.com/projects/common-xbee-mistakes/p://

body:
Xbee costs about 1000INR. They are really expensive. You should buy HC-05 module, which costs about 320INR.
You can easily interface them with Bluetooth of your Laptop using Processing Application.

You can even use ESP8266 ESP-01 Wireless Module. They Cost about 3$.
Wireless module gets connected with your router. [this][2] tutorial will help you to start. You can by this module from [here][4].

nRF24l01+ modules can not be interfaced with Laptop...

  [2]: http://www.instructables.com/id/ESP8266-Wifi-Temperature-Logger/
  [4]: http://www.banggood.com/ESP8266-Remote-Serial-Port-WIFI-Transceiver-Wireless-Module-p-947259.html?p=IY04239401772014128X


message:
Unable to read the IC Card UID

I have a RFID module using NXP RC522 chipset.
![Chipset][1]

I have no idea that is it correct the module using 27.120 mHz
![27.120 mHz][2]

And I have 4 IC card,

A) 0005302176, (Blue color tag, come with the RFID module)
B) 0008846830 134,65006 (White card, come with the RFID module)
C) 0004189112 063,60344 (White card)
D) White card, no number print on the card. Only this card UID can be read.

![4 IC Cards][3]

Here is the pinout
![Pinout][4]
Which I connected to Arduino UNO R3

     RFID         UNO R3
(Pin Name, Pin)    (Pin)
SDA        1        10
SCK        2        13
MOSI       3        11
MISO       4        12
IRQ        5        -No Connect-
GND        6        Ground
RST        7        9
3.3V       8        3.3V

PS: I am using this library, and this example.

PS: The serial return this information `MFRC522 Software Version: 0x91 = v1.0`

  [1]: https://i.stack.imgur.com/nnf3b.jpg
  [2]: https://i.stack.imgur.com/qSZxU.jpg
  [3]: https://i.stack.imgur.com/cRJ2j.jpg
  [4]: https://i.stack.imgur.com/SkJaH.jpg

body:
Check your power source, if you are powering the module from arduino/USB=>part or something like that, there can be not much power for the module.
Also you can try powering it 5v (not 3,3 as they should be powered by reference).

In my case I have had problems reading some types of cards, and I have solved that problems by giving better power supply, also higher power supply than in reference for some of the cards.

"By magic" the cards that were not working started working as a charm.

Also you should check if the cards you are using are all  ISO14443 A

Only that kind of cards is compatible with that reader.
So if you got type B, or other type of ISO cards, that will not be working.
Some of them may use different frequency, there is a bunch of standards around.

Also as said before the cards can be damaged, or could be corrupted if you tried reading UID while writing to the card, the problem is known , and in that case you can damage the UID.

I hope it helps you.
cheers


body: The MFRC522 reader is for 13.56 Mhz tags; these tags normally dont have the UID printed on them, in my experience. 125khz cards, however, usually have their SNs printed on them; as you can see all the cards that didnt work, have a 10 digit SN that seems to follow the same pattern. These card SNs can't be read by the MFRC522, as they follow a different protocol. When you buy a tag/card, make sure that its a 13.56 Mhz tag (look for Mifare tags), if you want the MFRC522 to be able to read it.


message:
Good way to get automatically generated code into a sketch

Situation:

Mac OS, Arduino IDE 1.5.6r2

I've got a sketch with several files, all classic .cpp and .h source and header files except the main sketch file. As the project goes more complex I started to generate code automatically by another program. Now I have hard times integrating the generated code it into my sketch. The arduino IDE seems to load the code on opening the sketch. After that, the source files aren't beeing checked for external changes by the IDE (as I would expect it from a real editor like *vim*). On top of that, when I verify my code the IDE seems to save the files from RAM into a temporary build directory ignoring the contents of the sketch directory further. So if I let my code generator change a source file while the sketch is opened in the IDE, the changes won't reach the build. I had to close the IDE and reopen it. The next thing I tried is to include my autogenerated file from an existing and opened code file inside the IDE. But the IDE ignores files, which aren't opened completely. Hence, the file is missing in the build directory.

Is there a trick to let the IDE take the code unknown to itself along into the build directory? Or how else can I deal with this situation? I don't want to close and open the IDE a hundred times a day.

body:
According to the release notes starting with V1.5.2 of the IDE you can verify and upload from the command line.

You could use your favorite editor and then use the command line to do the arduino build/upload instead of the IDE.

See: https://github.com/arduino/Arduino/blob/ide-1.5.x/build/shared/manpage.adoc

I have not used it so I can't say if it work well or not.


message:
RTClib library dependency on Wire library

I downloaded the RTClib library from <https://github.com/adafruit/RTClib>.  In every provided example, `#include <Wire.h>` is written immediately above `#include "RTClib.h"` at the top of the sketch.

Why is this necessary?  I know the RTClib library requires the functionality of the Wire library but, if this is the case, why can't I just `#include <Wire.h>` at the top of RTClib.h?  I have tried the latter, even using just the following sketch, but my sketch failed to compile.

RTClib.h:

    // Code by JeeLabs http://news.jeelabs.org/code/
    // Released to the public domain! Enjoy!

    #ifndef _RTCLIB_H_
    #define _RTCLIB_H_

    #include <Wire.h>
    ...

    #endif // _RTCLIB_H_

Sketch:

    #include "RTClib.h"
    void setup() {}
    void loop() {}

body:
Not getting too formal here, The arduino IDE looks at which libraries are included in the top level sketch when deciding what libraries to include in the compilation.

It would make sense for only RTClib.h to include Wire.h yes, but the IDE does not get the information to add Wire to the compilation list that way. It is a quirk of the IDE that makes implementing libraries that use other libraries a bit more painful.


message:
Home-made Arduino not receiving data

Me and my friend recently built a Breadboard Arduino. It switches on fine, and the LED changes a bit. I have added a 5V FTDI cable, but it wouldn't upload, trying to fix this, I used my friends 5V FTDI Basic USB-To-Serial converter chip, thinking this would upload fine, as it was new, but it still wouldn't upload, giving the very long error:

    Arduino: 1.5.8 (Windows XP), Board: "Arduino Duemilanove or Diecimila, ATmega328"

    Build options changed, rebuilding all

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\sketch_jan31a.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\sketch_jan31a.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\hooks.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\hooks.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\WInterrupts.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WInterrupts.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_analog.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_analog.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_digital.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_digital.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_pulse.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_pulse.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_shift.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_shift.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\abi.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\abi.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\CDC.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\CDC.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial0.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial0.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial1.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial1.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial2.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial2.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial3.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial3.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HID.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HID.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\IPAddress.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\IPAddress.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\main.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\main.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\new.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\new.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\Print.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Print.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\Stream.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Stream.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\Tone.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Tone.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\USBCore.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\USBCore.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\WMath.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WMath.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\WString.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WString.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\hooks.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WInterrupts.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_analog.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_digital.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_pulse.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_shift.c.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\abi.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\CDC.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial0.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial1.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial2.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial3.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HID.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\IPAddress.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\main.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\new.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Print.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Stream.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Tone.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\USBCore.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WMath.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WString.cpp.o

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega328p -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.elf C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\sketch_jan31a.cpp.o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a -LC:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp -lm

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.elf C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.eep

    C:\Program Files\Arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.elf C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.hex

    Sketch uses 450 bytes (1%) of program storage space. Maximum is 30,720 bytes.

    Global variables use 9 bytes (0%) of dynamic memory, leaving 2,039 bytes for local variables. Maximum is 2,048 bytes.

    C:\Program Files\Arduino/hardware/tools/avr/bin/avrdude -CC:\Program Files\Arduino/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -PCOM8 -b57600 -D -Uflash:w:C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.hex:i

    avrdude: Version 6.0.1, compiled on Apr  3 2014 at 23:12:16
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "C:\Program Files\Arduino/hardware/tools/avr/etc/avrdude.conf"

             Using Port                    : COM8
             Using Programmer              : arduino
             Overriding Baud Rate          : 57600
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x01
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x01
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x01
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x01
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x01
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x01
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x01
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x01
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x01
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x01

    avrdude done.  Thank you.

    Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

The light on the USB-To-Serial board lights once for each failed upload, but the sketch won't upload. I am trying to upload the blink sketch. The chip I am using is an Atmel AtMega328P-PU. All answers greatly appreciated.

body: I solved this by using an empty Uno-Board as a 'bridge' between the PC and the Bareduino (empty means with no controller chip). Just connect this guy via USB to the PC and then connect RX/TX, Ground, and Reset to your Bareduino. Just works fine for me.


body: I would upload a blink sketch using the method Stephan suggested then plug it back into your breadboard.  If it runs the blink sketch then the problem is in your programming method, but  it is more likely there is something wrong in the setup.  Problems could be using the wrong crystal for your setup, mis-wired or loose connection, or having your chip turned around (happens more often than you think).  If it does run I would make sure that you are using all USB-to-Serial converter with all the wires used and having a resister on the reset pin.


body:
The likely causes of failure are

 - Wrong baud rate: you're already using 57600, the most common one.
 - Rx and Tx cross connected: try connecting them the other way round.
 - Wrong clock clock frequency in the chip: The tools usually assume an AtMega328 runs at 16MHz.
 - Chip is not in bootloader/programming state, in the very first seconds after releasing the reset button or powering the arduino, the bootloader is listening for instructions to start reprogramming the chip via serial communication, if there is none it will continue running the program on it. Hold reset -> Hold upload -> Release upload -> Release reset.

The above assumes, of course, that you have a working board. If that isn't certain, follow @Nathan's advice to plug in a chip pre-programmed with a Blinky sketch to confirm it. I use a combined Blinky and HelloWorld sketch to prove both the basic functioning and the serial I/O in one test.

A couple of these are handy to keep around, too, for proving there is power or a logic HIGH where you expect it:

![LED with resistor][1]

           LED with current-limiting resistor on the cathode

  [1]: https://i.stack.imgur.com/Ztoil.jpg


message:
arduino resets or hangs after providing power to DHT22

I'm developing a low power project based on Atmega328p which among other things uses a DHT22 to measure air humidity. DHT22 spec says that it consumes 50uA when idle. This is too high for me (I'm aiming at sub 10uA consumption for the whole device when in sleep mode) so I've figured out that I'll just power it from one of Atmega328p pins. This will give me the ability to turn it off or on at software level. DHT22 consumes only 1.5mA during measurement so I should be fine (a single Atmega's pin can safely provide up to 20mA). I've set up a following test circuit:

![schematic](https://i.stack.imgur.com/3AcJY.png)

The red wire powers DHT22, the blue one is for data transfer, the black one is GND and the 4.7k is a pull-up resistor.

My problem is that after I turn on the DHT22 using just:

    digitalWrite(4, HIGH);

the Atmega either resets or hangs or... successfully turns on the DHT22 and keeps working, but that happens about 10% of the time. My suspicion is that there is some current spike in the moment of supplying power to the DHT22. Unfortunately I don't have an oscilloscope to confirm this.

I've added a 220 ohm resistor between VCC pin of DHT22 and the pin 4 on the Arduino and it solved the problem. My question is: will it work like this reliably? Are humidity readings reliable when voltage is not stabilized (but stays within 3.3-5.5V range as required by the datasheet)? I could of course use a transistor to turn it on/off, but I'd like to keep it as simple as possible.

Why DHT22's datasheet doesn't mention this current spike? Here it is for reference: http://www.adafruit.com/datasheets/Digital humidity and temperature sensor AM2302.pdf

body:
The sensor is a large capacitive load. You need to improve decoupling of the CPU power supply.

A 10 uF between 5V and GND will help for the current spike and the resistor in series with the sensor will not be an issue (50 uA on 250 Ohm makes only 12.5 mV voltage drop once the sensor is started).


body:
The previous answers regarding adding decoupling capacitors are good.
You don't have to be concerned about the voltage drop across your 220 ohm resistor. MAC's answer states that only 12.5mv drop at 50uA (when not measuring).
**During measurement**, 1.5mA will result in 0.33v drop across the 220 ohm resistor. This should be noted, but is not a problem. The DHT22 data sheet shows that it will accept any supply voltage between 3.3v and 6v.
  Looks like you have a good design.


body:
Decoupling capacitors do help, as mentioned in the other answers.

Also, to get a good reading, after powering up your digital pin 4, a delay of maybe 100-500ms may be required to allow the DHT22 to stabilize. For better results, you can also perform multiple readings (call delay(dht.getMinimumSamplingPeriod()) between the readings) and average them.

It looks like you are using an Arduino Uno. For further power savings, you might consider using a Pro Mini and performing [some hardware modifications][1]. For software power saving techniques, there is no better resource than Nick Gammon's [Power saving techniques for microprocessors][2].

  [1]: http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/
  [2]: http://www.gammon.com.au/forum/?id=11497


message:
Has anyone used an Arduino to transfer software to an Apple IIe?

Yes, you read that right.  An `Apple IIe`.

I have many retro computers and I was thinking that since the `Apple II` line of computers (especially the `IIe`) have pretty speedy serial ports that it should be somewhat simple to use an Arduino to send data to/from the Apple.

My issue is that all of my every-day computers are USB based with no RS232 serial.  I guess I could boot up an old Linux laptop that has a serial port but that seems too cumbersome given my limited desk space.  :-)

Anyway, I've Googled but I'm not finding anything.

Since most `Apple IIe` disk images are pretty small (<144k or so) they should fit pretty easily into, say, an Arduino DUE that I have.  Or better yet, using the DUE to mount as a USB device that could send over to the IIe would be great.

So, my question is, does anyone know of any site that explains how this could be done?

Thanks!

**EDIT**

OK, turns out it WAS pretty easy getting the Arduino DUE to send to the Apple IIe.  I simply connected 3 wires from TX1/TR1/GND to the Apple IIe serial port (SSC).

Now, when I launch ADT Pro and start sending, the IIe is receiving garbage.  Bunch of "9d9d9d9d" all over the place.

Here's my code:

    // ADT.ino

 int incomingByte = 0;

 void setup() {

  Serial.begin(9600);
  Serial1.begin(9600);

 }

 void loop() {

  if(Serial.available() > 0) {

   while(Serial.available() > 0) {

    incomingByte = Serial.read();

   }

   Serial1.write(incomingByte);
   delay(100);
  }

 }

The ADT Pro software is set to send the data over the USB port and it's obviously sending data to the IIe.  I'm just wondering if the formatting is wrong or something.

body: You need to adapt the levels. Arduino Due operates on 0 - 3.3 V. Apple IIe is either on 0 - 5 V or +/- 12 V (depends which port you are using). There are standard ICs to do the level adaptation.


message:
In system programming for avr?

I generally use sockets for AVRs in standalone circuits, but sometimes I sell my items and therefore I soldier the chip on the circuit. As you guess I can upgrade the code inside the chip with socket simply putting the chip out and putting it into the programmer board, but It doesn't work the same way with the ones which are soldiered on the circuit.

I know there are some ISP devices like USBtinyISP etc., but I want to be more professional and know exactly how an in system programmer work.

Do I have to use Avrdude If I design my own In system programmer? Isn't there any way that is more universal?

 I searched the internet for a long time and I found only hobbyist stuff. Can anyone explain or simply direct me to a good source that explains this topic? Thank you in advance.

body:
ISP works by using a serial connection (usually via the SPI and nRESET pins) to the MCU. The programmer talks to the device using the low-level protocol that the device expects, and connects to the host using a different, high-level protocol. The host then directs the programmer to perform the various programming actions on the device, and in turn the programmer reports to the host about its current status.

There are a number of programming protocols that already exist, such as the one described in AVR910. As long as both the connection type and the protocol itself are supported by AVRDUDE it will work transparently once the hardware is assembled.

Further details about ISP are available in both AVR910 as well as the "Serial Programming" section of the datasheet for the device in question.


body:
You can use an ISP using the Arduino UI - simply select your programmer (tools->programmer) then "upload using programmer" (under the file menu).

Alternatively, you could use a pre-programmed AVR to do the programming - see http://www.atmel.com/images/doc0943.pdf for the spec. I think an AtTiny would be enough, depending on how big your program is, you might need some external storage. You could set it up with a "read" and a "write" option, so you program your dev AVR normally, then use an AtTiny to suck the data off, then push it up to one of the others. This is left as an exercise to the reader.

In any case, you would just need access to the 6 pins - VCC(power), GND(ground), RST(reset), SCK(clock), MISO(master->slave) and MOSI (slave->master). Note that the RST pin has to go high/low at specific times during the programming, so if programming from another AVR, it will need to be a data pin.


message:
Can stackable Arduino headers be automatically soldered?

I want to design an Arduino shield with stackable headers, so it will allow other shields to be mounted on top of it.

![enter image description here][1]

I was wondering if these could be soldered automatically. Neither wave nor reflow soldering seems to be an option. Wave soldering would leave solder on the pins so they won't fit in sockets, and for reflow (pin-in-paste) the long pins will completely pull the paste from the holes.
Is hand-soldering the only way (making the board more expensive), or is there still another way? Would it be a good idea to supply the shield with the headers not mounted to save cost?
Or shouldn't I assume the average Arduino user has a soldering iron?

  [1]: https://i.stack.imgur.com/u7HYX.jpg

body:
I would suggest using SMD headers on one side and through hole on the other side. One side with this: http://www.tracepartsonline.net/(S(30y0dp21y1rd0u3erv1mrrbw))/partdetails.aspx?Class=ASSMANN&ClsID=/F_ASSMANN/ASSMANN.010/ASSMANN.010.170/&PartID=10-18062010-079808
and one side with this: http://www.tracepartsonline.net/(S(30y0dp21y1rd0u3erv1mrrbw))/PartDetails.aspx?Class=ASSMANN&clsid=/F_ASSMANN/ASSMANN.010/ASSMANN.010.170/&ManID=ASSMANN&PartFamilyID=10-23062010-067691&PartID=10-23062010-067691&SrchRsltId=1&SrchRsltType=0

You will shift upper side a few mm from bottom side, and use glue to have upper side set in place and then reflow for soldering on both sides.


body: You might look at getting a solder stencil.  It is still hand soldering, but significantly faster than doing it completely by hand.  Another option would be a pick and place machine; there would be a significant upfront cost but it would be more automatic.


message:
Why does a Piezo Buzzer not require a PWM digital pin (Gallileo Gen2)?

According to my current (poor) understanding, only the PWM pins (with the ~) among the digital pins (ignoring Analog pins) can be passed to `analogWrite()`.  I understand the servo therefore - since interfaced by a variable voltage signal - must be connected to such a PWM pin.

 - Why is the humble Piezo Buzzer not bound to this condition?
 - Why can I connect the buzzer to a digital pin that is not PWM (and so should only be able to output binary LOW, HIGH voltage at some consistent frequency) and still achieve a varying sound by calls to the `tone()` function?
 - Surely under the limitations of being digital and non-PWM, the pin could only cause some consistent buzzer frequency?

I'm reading online that the Piezeo Buzzer does indeed require a PWM digital pin, but I can connect it to any digital pin on my Galileo gen2 and have it function seemingly correctly (differing tones produced).

Also, since slightly relevant; what exactly is the difference between a PWM digital pin and an analog pin, in terms of output? They both use PWM, right? Why can't even a PWM digital pin read analog input?

body:
> Why does a Piezo Buzzer not require a PWM digital pin?

Tone() uses the microcontroller's hardware timers to control the related code function but do not use the hardware PWM features. The timer can be assigned to any pin that has a digital output capability.
Tone() sends a "rail to rail" square wave (50% duty cycle) to the selected pin

Slightly more lower level information here under [**Ugly details**](https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation#Ugly_Details)
They say:

 - The library uses the hardware timers on the microcontroller to generate square-wave tones in the audible range.

 You can output the tones on any pin (arbitrary). The number of tones that can be played simultaneously depends on the number of hardware timers (with CTC capability) available on the microcontroller.

 ATmega8: 2 (timers 2, and 1)
 ATmega168/328: 3 (timers 2, 1, and 0)
 ATmega1280: 6 (timers 2, 3, 4, 5, 1, 0)

 The timer order given above is the order in which the timers are allocated. Timer 0 is a sensitive timer on the Arduino since it provides millis() and PWM functionality.

_____________

> ... what exactly is the difference between a PWM digital pin and an analog pin, in terms of output? They both use PWM, right? Why can't even a PWM digital pin read analog input?

There is a misconception there.
Analog pins are capable of Analog INPUT functionality .
"PWM" output is known as "analogWrite" but is actually a purely digital function and is not related to whether a pin has analog read functionality.
PWM out = analogWrite is available on pins which have associated PWM hardware.
The actual signal is a "rail to rail" square wave with a mark:space (on:off)that varies.   Filtering the PWM produces DC at the average DC level. PWM range is 0 to 255 (8 bits)


body:
The signals that you mention are of different nature.

1) The PWM signal is a digital signal (output voltage is either ground or supply) that is modulated in time. It has a fixed period and its duty cycle varies from 0% (always ground) for value 0, to 100% (always supply) for value 255, the middle value being a signal that switches between ground and supply with 50% of its period at ground and 50% of its period at supply.

2) A servo is controlled by a signal that has a fixed period of 20 ms and a pulse of varying duration (between 0.5 to 2.5 ms).

3) A tone for a buzzer has a variable period (or variable frequency - both being linked by the equation frequency * period = 1). The period is audible if is is between 0.06 ms (15 kHz) and 60 ms (15 Hz) (the exact value change from person to person. If the frequency is higher than 15 kHz, you are entering ultra-sonic.

All three signals are digital in their voltage and modulated in time. But the modulation is very different as indicated above and the Arduino driver is therefore different for each one.


message:
Is it possible to use FrSky D8R-II Plus 8ch 2.4Ghz ACCST Receiver with an arduino Uno?

I'm in the process of buying a receiver and transmitter for my quad copter project. Would it be possible to use this receiver or a similar one to control the quad. I'm trying to read the signals using Pulse in. I'm inexperienced in RC and I only found one tutorial on how to do this.

I know that the receiver will have to be wired up to the analog pins on the arduino however, the receiver has an operating voltage of 3.5V-10V and an operating current of 100mA which exceeds the 40mA of the arduino board. I have seen videos of people using silar 2.4Ghz receivers on arduino Nanos without problems. Has anyone on this board done something similar and if so, can thou guide me?

body:
I've used plenty of receivers like this with arduino.

The operating current is not really an issue; It is drawing power off of the 5v line, not the digital pins, which is capable of 100mA. In any case they usually have an extra "bat" line that you could plug in to a BEC from one of your speed controllers, and then just connect signal and ground lines to the arduino.

pulseIn works, but not ideally (especially for quadcopters). reading with pulseIn tends to have quite a bit of noise, and runs slow. Those receivers pulse around 50-60Hz, so reading those signals with pulseIn (which has to wait for the signal to finish) will take too long. I say "too long" because in all the open source quad copter programs I've looked at the sensor-read/stabilize update loop needs to run at 100 Hz or more.

What you need to use is the interrupt functionality of the AVR. That way you can detect the time between changes in state of the input pulse without causing the rest of the program to stop. This can get somewhat complicated so I'm not going to write a tutorial here. I recommend you research it yourself and ask new, specific questions here if you have any.

It doesn't magically fix everything for you though; the Uno only has 2 external interrupts. I think most arduino based quads use arduino megas or Leonardos, which have more. I know the APM 2 board has a separate chip converting those 8 single channel PPM signals into a single 8 channel PPM signal that goes into the main controller, despite the fact that it is a mega.

You can look into Aeroquad and Multiwii for inspiration. ArduPilot is open source as well but their code is messier, which makes reading it much more difficult. I don't think it is impossible to use an Uno, but it will be difficult.


message:
Imbedded loops based on inputs

I'm working on a project with 4 inputs and 7 possible outputs on an Arduino Uno.  Based on any combination of those inputs, I need to run a specific "loop" that will repeat until there is a change in ANY of the 4 inputs.  Specifically:

 - Input 1 = loop 1
 - Input 2 = loop 2
 - Input 3 = loop 3
 - Input 4 = loop 4
 - Input 2 and 3 = loop 5
 - Input 2 and 4 = loop 6
 - No input = do nothing

So I need to constantly read the 4 inputs and change output loops accordingly.  I have basic Arduino knowledge but am stumped.

This is what I've tried - I have 4 input pins and 8 output pins

    int outPin = 0;
    int inPin = 0;
    int CAR = 0;
    int pinRead = 0;

    void setup()
    {
     for (int outPin = 3; outPin < 11; outPin++);  {  //set pins 3 thru 10 as OUTPUT
       pinMode(outPin, OUTPUT);
      }

     for (int inPin = 9; inPin < 13; inPin++);  {    //set pins 9 thru 12 as INPUT
       pinMode(inPin, INPUT);
      }

    }

    void loop()
    {
      for (int CAR = 3; CAR <11; CAR++); {  //set all pins to LOW
       digitalWrite(CAR, LOW);
      }

      // BRAKE

        {while (digitalRead(9 == HIGH) && digitalRead(10 == LOW) && digitalRead (11 == LOW) && digitalRead(12 == LOW)) {
        digitalWrite(3, HIGH);
        digitalWrite(4, HIGH);
        digitalWrite(5, HIGH);
        digitalWrite(6, HIGH);
        digitalWrite(7, HIGH);
        digitalWrite(8, HIGH);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);

      }}

      // LEFT

        {while (digitalRead(9 == LOW) && digitalRead(10 == HIGH) && digitalRead(11 == LOW) && digitalRead(12 == LOW)) {
        digitalWrite(0, HIGH);
        delay (200);
        digitalWrite(1, HIGH);
        digitalWrite(3, HIGH);
        delay (200);
        digitalWrite(2, HIGH);
        delay (200);
        digitalWrite(0, LOW);
        digitalWrite(1, LOW);
        digitalWrite(2, LOW);
        digitalWrite(3, LOW);
        delay (200);

      // RIGHT

      }}

        {while (digitalRead(9 == LOW) && digitalRead(10 == LOW) && digitalRead(11 == HIGH) && digitalRead(12 == LOW)) {
        digitalWrite(5, HIGH);
        delay (200);
        digitalWrite(4, HIGH);
        digitalWrite(6, HIGH);
        delay (200);
        digitalWrite(7, HIGH);
        delay (200);
        digitalWrite(4, LOW);
        digitalWrite(5, LOW);
        digitalWrite(6, LOW);
        digitalWrite(7, LOW);
        delay (200);

      // HAZARD

      }}

        {while (digitalRead(9 == LOW) && digitalRead(10 == LOW) && digitalRead(11 == LOW) && digitalRead(12 == HIGH)) {
        digitalWrite(0, HIGH);
        digitalWrite(5, HIGH);
        delay (200);
        digitalWrite(1, HIGH);
        digitalWrite(4, HIGH);
        digitalWrite(5, HIGH);
        digitalWrite(6, HIGH);
        delay (200);
        digitalWrite(2, HIGH);
        digitalWrite(7, HIGH);
        delay (200);

          for (int CAR = 0; CAR < 8; CAR++); {  //set all pins to LOW
           digitalWrite(CAR, LOW);
        delay (200);}}

      // BRAKELEFT

      }

        {while ( digitalRead(9 == HIGH) && digitalRead(10 == HIGH) && digitalRead(11 == LOW) && digitalRead(12 == LOW)) {
        digitalWrite(0, HIGH);
        digitalWrite(5, HIGH);
        digitalWrite(6, HIGH);
        digitalWrite(7, HIGH);
        delay (200);
        digitalWrite(1, HIGH);
        digitalWrite(3, HIGH);
        delay (200);
        digitalWrite(2, HIGH);
        delay (200);
        digitalWrite(0, LOW);
        digitalWrite(1, LOW);
        digitalWrite(2, LOW);
        digitalWrite(3, LOW);
        delay (200);
        }
      }

      // BRAKERIGHT

        {while (digitalRead(9 == HIGH) && digitalRead(10 == LOW) && digitalRead(11 == HIGH) && digitalRead(12 == LOW)) {
        digitalWrite(0, HIGH);
        digitalWrite(1, HIGH);
        digitalWrite(2, HIGH);
        digitalWrite(5, HIGH);
        delay (200);
        digitalWrite(4, HIGH);
        digitalWrite(6, HIGH);
        delay (200);
        digitalWrite(7, HIGH);
        delay (200);
        digitalWrite(4, LOW);
        digitalWrite(5, LOW);
        digitalWrite(6, LOW);
        digitalWrite(7, LOW);
        delay (200);
        }
      }

      // NOTHING

        {while (digitalRead(9 == LOW) && digitalRead(10 == LOW) && digitalRead(11 == LOW) && digitalRead(12 == LOW)) {

           for (int CAR = 0; CAR < 8; CAR++); {  //set all pins to LOW
             digitalWrite(CAR, LOW); }}
        }
    }

body:
When you need repeating behaviour in an Arduino program, putting loops within the `loop()` function often isn't the best approach. It leads to a lot of confusing logic which is quite hard to get right, and becomes quite unwieldy to maintain.

A more effective approach would be something like a simple state machine. At the start of `loop()` you would check the input values and figure out which behaviour (or state) you want to execute: BRAKE, LEFT, RIGHT etc.. You might want to store this information in a variable somewhere, e.g. state `0` could be BRAKE, state `1` could be LEFT, and so on.

Next, you simply check what the state value is, and execute the appropriate instructions **once**. For example:

    switch (state)
    {
        case 0:
            // BRAKE instructions here...
            break;

        case 1:
            // LEFT instructions here...
            break;

        // etc...
    }

There's no need for any `while` loops because `loop()` is going to get called all the time anyway. There are two big advantages of this approach. First, you only need all the input conditions in one place, which makes the code easier to manage. And second, it means you can easily have your program doing other things later in `loop()` because it's no longer stuck in nested loops all the time.

----
As a side note, it's very important to mention that lines like this are incorrect:

    digitalRead(9 == HIGH)

What you're doing here is comparing the number `9` to `HIGH`, and then passing the result (which is 0) to the `digitalRead()` function. That means you're effectively only ever checking pin 0. What you actually want to do is pass `9` to the function, and then compare the overall result to `HIGH`, like this:

    digitalRead(9) == HIGH


message:
Bluetooth shield/module for file transfer?

I'm currently working on a project that requires to display images on a touchscreen on my arduino. These images are neither stored in arduino nor any memory card. I want to be able to send the images via Bluetooth from an app and display it on the touchscreen. The problem is I couldn't find a good and solid Bluetooth shield or module that provide file transfer via bluetooth from an iOS app to arduino. If you can name a few bluetooh shields or modules that'd be great. In the thread below, someone claimed hc-05 works. Can anyone support that claim? Thanks.
http://forum.arduino.cc/index.php?topic=208306.0

body:
I would use an HC-05 (or HC-06 - there seems to be little difference) - You will need to do your own file transfer protocol - for small images, zmodem or xmodem (usual file-over-serial) are probably completely overly complex. You would also need your own app for the phone.

Alternatively, you could use a network (ethernet or wifi) addon on your arduino - I think I read the Arduino Yun has built in ethernet and wifi.http://arduino.cc/en/Tutorial/WebServer has a webserver, this could be adapted to accept uploaded files. You can then use a webbrowser on your phone (or indeed anywhere else!) to send the files. If you want to send from outside your local network, you may need to set up port forwarding on your router (google: port forward) - the port you want to forwards is 80.


message:
analogWrite never outputs a non-zero voltage

With a very simple connection of an LED (which can withstand 5V) to ground and to a pin on my Galileo gen2, I can never output a non-zero voltage from the pin via `analogWrite`, regardless of whether the pin is digital or analog (although PWM digital works)

The LED is in the correct bias and I'm calling `pinMode(pin, OUTPUT)` before attempting to call `analogWrite(pin, 255)` (or any 2nd parameter in-between), even though it's not even necessary.
The LED glows if I call `digitalWrite(pin, HIGH)` on both analog and digital pins, but does not glow at all for `analogWrite(pin, 255)` with the same configuration and pins, nor does it for any 2nd param in [0, 255]. This holds for whether the call is attempted in `loop()` or `setup()`.

The only possible way I can get the LED to receive any power from `analogWrite` is through a digital PWM pin, but I know the other digital pins can still produce square-waves with timers and the analog pins should certainly be able to use PWM.

(So far, I've been to scared of short-circuits to connect the analogWrite output straight into an analog input to read the voltage)

Is there something I don't understand about the underlying board, or am I experiencing some strange malfunction?

Thanks,
Tyson

body: I don't believe Galileo has a D/A converter, which is what it sounds like you're expecting. In the Arduino 'eco-system', analogWrite() sets a PWM duty cycle - that's kinda-sorta somewhat like an analog output, but not really. You could add external circuitry to low-pass filter the PWM and produce some sort of proportional DC but it might be a good trick get it clean enough for whatever you plan to put downstream.


body:
On most boards, the standard implementation of Arduino's `analogWrite()` will only ever produce PWM, and only on a specific set of (digital) pins. These are usually pins 3, 5, 6, 9, 10, and 11, although it's slightly different on some boards.

The only official board which has 'true' analog output is the Due (pins DAC0 and DAC1).

If you want any other behaviour (such as outputting PWM on non-standard pins), you'll either need to modify the Arduino implementation, or directly manipulate the microcontroller's special registers. Note though that modifying the chip's configuration could cause other standard Arduino functions not to work as expected.


body: I am not sure where you are getting your LEDs but the ones I purchase do not survive 5 volts. You need to put a resistor in series with then, something in the 220 to 510 ohm range.  When you get some resistors test your LEDs you may have damaged them as well. A good indication of this if there color if obviously off and or dim. If the timers are set up correctly the digitalwrite will set the PWM value, somewhere from 8 to 16 bits depending on the Arduino and timer used. This PWM output will appear to control the brightness of the LED. It does this by simply turning it on and off at a speed the eyes cannot follow. the longer it is on the brighter it is. Hopefully this will help you get your arms around the circuit.


message:
How can I analyse large packets on an Arduino?

I'm trying to send a large packet to an Arduino with an ethernet shield on it. I'm using the built-in RX buffer of the W5100 controller to store the data, but I need more memory (at least 16K of buffer space, the W5100 only has 8K of RX buffer space). I have control over the server side of things as I'm writing the server process myself, so I can take solutions on that side.

Is there some hack I can use in the TCP protocol to have the packet broken up?

**Edit:** I'm using the SFML 2.1 network API on the server side.

body:
All you need to do is analyse the packet on-the-fly using a state machine.

<http://www.gammon.com.au/statemachine>

You certainly don't need to hold the entire packet at once, however you **do** need room for the information the packet contains.

Say, for example, that the packet, although wordy, contains 4 x 32-bit numbers of interest. All you need memory for is those 4 numbers, plus a minor extra amount for the current data you are processing (eg. the current state, and the current number being assembled).

Conceptually it is like streaming a movie to your PC. The PC doesn't need to hold the whole movie, it just needs to hold the current frame, and a few seconds in advance, just to keep things running smoothly.


message:
Why are pin 18 and 19 always HIGH?

I wired my switch just like in the default button program. I know it works because it works fine on other pins, just not pin 18 or 19. What am I doing wrong?

    const int buttonPin = 18;     // the number of the pushbutton pin
    const int ledPin =  13;      // the number of the LED pin

    // variables will change:
    int buttonState = 0;         // variable for reading the pushbutton status

    void setup() {
      // initialize the LED pin as an output:
      pinMode(ledPin, OUTPUT);
      // initialize the pushbutton pin as an input:
      pinMode(buttonPin, INPUT);
    }

    void loop(){
      // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);

      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH:
      if (buttonState == HIGH) {
        // turn LED on:
        digitalWrite(ledPin, HIGH);
      }
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW);
      }
    }

body:
The analog pins function as digital pins number 14 - 19, with 14 being A0 and 19 being A5. I had hooked it up backwards.

    This time we're gonna get funky
    Everybody check your pins
    Check check check check your pins
    Check check check check your pins
![enter image description here][1]

  [1]: https://i.stack.imgur.com/zeUmI.png


message:
Arduino UNO does not get recognized by PC(no USB connecting sound), also TX and RX not blinking, neither are lit

I am trying to build a robot, which needs motors to roll around. So I was trying to control two DC motors with H-Bridge that comes with Arduino StarterKit(H-bridge motor driver [L293D]). I used Sketch that looks something like that ![enter image description here][1]

  [1]: https://i.stack.imgur.com/Jh66v.jpg

I did read that Arduino needs separate powering, but i did not use any only USB connection. I connected 5V that comes from arduino to where + pin from battery should have been connected and motors were controlled and working.
However when i tried using 9V battery and connecting it as seen on above picture ,H-bridge did not control mototrs and nothing was working.
There is also another aspect - when robot was touching the surface then wheels did not move aka motors did not rotate and when you picked it up motors accelerated to quite some speed. Also when robot was on the surface and connected via USB, the PC made these USB connecting sounds repeatedly.
I am not sure when RX and TX stopped working. Power LED and L13 LED do work correctly.

Any ideas? Is it Fixable?

body: You should definitely avoid connecting anything else than 5v to these 5v(!) PINs. The Uno has regulators, but these only work when powered through the power-dc-connector (or USB). You can easily buy a 9v-block to dc-jack cable to connect power to the right point easily.


body:
The "5V" pin takes only regulated 5V input.  Your schematic shows the the board powered here, and you mention 9V battery.  That's not a good idea.

If you have 7V-12V, then you can supply the board via the "Vin" pin.  It passes through the same regulation circuits that the DC jack does.

http://arduino.cc/en/Main/ArduinoBoardUno

> VIN. The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.


body: May be your ATmega328 IC would have been damaged or ATmega16u or ATmega8u chip was damaged. I also got same few days ago.


message:
What is the most accurate sensor for detecting ping pong ball?

What is the most accurate proximity sensor for a ping pong ball? I will be using this to calculate 3D positioning of a ping pong ball in flight. I only need to detect the ball within 0-5 feet (basically on one side of ping pong table).

body:
In the meantime a student has made a really impressive implementation, that might answer your question: [interactive tennis table][1]

  [1]: http://thenextweb.com/gadgets/2016/04/28/interactive-tennis-table-help-step-ping-pong-game/


body:
I've had some good luck with using the Pixy camera system.

http://www.cmucam.org/projects/cmucam5/wiki

You get a maximum of 50 FPS and can detect and locate different objects based on hue. The library function getBlocks() returns the X and Y center location of each of the objects the camera detects. You teach the camera what hues to recognize as blocks, and adjust the detection thresholds. I use mine in monochrome infrared light by adding a visible filter and lens kit from http://irlock.com/


message:
Waking Raspberry Pi on time schedule using Sleepy Pi

I'm have a [Sleepy Pi][1] and am having extreme difficulties trying to program a wake/sleep cycle. Sleepy Pi is an Arduino board with a RTC. My ultimate goal is for a time-lapse project.

I have the Raspberry Pi programmed and operational to take a picture on boot, my trouble is coming from trying to program the Arduino board to actually do it's job.

I would like the Sleepy Pi to wake at 8am, 9am, 10am, ..., 3pm, 4pm, and 5pm, each for 5 minutes, then go back to sleep. I've been working with the [SleepyPi][2], [Time][3], [TimeAlarms][4], [LowPower][5], and [DS1374RTC][6] libraries in the Arduino IDE. However, I cannot find any examples on how to put everything to sleep until a specific time comes around. Also, in several of my tests, it seems that the clock actually stops when the Sleepy Pi is asleep!

Here is what I've been working with (and this is non-working). It's probably completely wrong.

    #include "SleepyPi.h"
    #include <Time.h>
    #include <TimeAlarms.h>
    #include <LowPower.h>
    #include <DS1374RTC.h>
    #include <Wire.h>

    // Set the status LED pin constant
    const int LED_PIN = 13;

    void setup()
    {
      // Configure "Standard" LED pin
      pinMode(LED_PIN, OUTPUT);
      digitalWrite(LED_PIN,LOW); // Switch off LED

      // Start with the Pi off
      SleepyPi.enablePiPower(false);

      // Set our communication rate
      Serial.begin(9600);

      // Set up our boot times
      Alarm.alarmRepeat(8,0,0, startPiUp);
      Alarm.alarmRepeat(9,0,0, startPiUp);
      Alarm.alarmRepeat(10,0,0, startPiUp);
      Alarm.alarmRepeat(11,0,0, startPiUp);
      Alarm.alarmRepeat(12,0,0, startPiUp);
      Alarm.alarmRepeat(13,0,0, startPiUp);
      Alarm.alarmRepeat(14,0,0, startPiUp);
      Alarm.alarmRepeat(15,0,0, startPiUp);
      Alarm.alarmRepeat(16,0,0, startPiUp);
      Alarm.alarmRepeat(17,0,0, startPiUp);
    }

    void loop()
    {
      // Tick the alarm clock every second
      SleepyPi.enableWakeupAlarm();
      Alarm.delay(1000);

      // Cut Power if we detect Pi not running
      bool pi_running;
      pi_running = SleepyPi.checkPiStatus(true);
      if(pi_running == false){
        SleepyPi.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
      }

      // Flash the LED
      digitalWrite(LED_PIN,HIGH);
      delay(1000);
      digitalWrite(LED_PIN,LOW);
    }

    // Function to tell the Pi to boot up
    void startPiUp()
    {
      // Turn the Pi on
      SleepyPi.enablePiPower(true);

      // Turn on the LED to signal we're here
      digitalWrite(LED_PIN,HIGH);

      // Keep the Pi on for 5 minutes
      delay(300000);

      // Start a shutdown
      digitalWrite(LED_PIN,LOW);
      SleepyPi.piShutdown(true);
    }

I also cannot find a good way to "debug" things. I've been trying to use the LED flashes as a "I'm here" echo, but have been unsuccessful with this as well.

**NOTE:** I do not have enough reputation on this site yet to create new tags. Someone with over 150, please tag this with [tag:raspberry-pi] and [tag:sleepy-pi]. Thank you.

  [1]: http://spellfoundry.com/products/sleepy-pi/
  [2]: https://github.com/SpellFoundry/SleepyPi
  [3]: http://www.pjrc.com/teensy/td_libs_Time.html
  [4]: http://www.pjrc.com/teensy/td_libs_TimeAlarms.html
  [5]: https://github.com/rocketscream/Low-Power
  [6]: https://github.com/SpellFoundry/DS1374RTC

body:
Same probem. Kludgy solution ... but it works

Get the startstopsimple skectch from GitHub.

Set the period to 60 minutes
Set the timeout to whatever makes sense for you

Modify the setup function to loop until the clock says the minute is 59.
something like

    do
    {
       delay (100);
    } while !(minute() == 59);

Then it will go into the loop function. It will be asleep. So it will then do a whole "empty" loop and sync after that, dunno how one gets rid of first the empty loop. But it works .... :-)


body:
I have the same problem and  I just saw that they fixed a bug in a library used by SleepyPi

More specific, the RTC library file [`DS1374RTC.cpp`][1] reads since March: '2015
(which is after the question was asked)

>   Releases
  ========
  V1_0 - 10 Aug 2013 - Initial release
  V1_1 - 11 Mar 2015 - Mod:    Added "ackAlarm" and "ackRTCOSF" functions to aid Alarm use
- Bugfix: **Changed the way the "SetAlarm(tmElements_t   &tm)" was updating the Alarm time.** It wasn't mapping correctly

They also added a new example to wake up the Pi: [`WakePeriodicallySimple.ino`][2]

  [1]: https://github.com/SpellFoundry/DS1374RTC/blob/master/DS1374RTC.cpp
  [2]: https://github.com/SpellFoundry/SleepyPi/blob/master/examples/WakePeriodicallySimple/WakePeriodicallySimple.ino


message:
How do I use this sound sensor?

I bought one of [these][1]:

![1Pcs New Sound Detection Sensor Module Voice Sensor for Arduino Best][2]

There are 3 pins on it:

 - 5V
 - GND
 - OUT

My guess is that OUT is an analogue signal that I can measure with my Arduino, am I right?

I am using the "Analogue Output" example code but I just get 5V all the time, it does not seems to change with the sound levels.

Am I doing something wrong? What am I adjusting with the blue square on the board? Should I maybe do that?

  [1]: http://www.ebay.com/itm/171505106187?_trksid=p2059210.m2749.l2649&ssPageName=STRK:MEBIDX:IT
  [2]: https://i.stack.imgur.com/04v2jm.jpg

body:
The wording on this particular eBay item is pretty poor but there are plenty of similar products with better descriptions that are photographically identical... [example][1] that make a little bit more sense.

Anyway, I don't think this gives an analog value output, the LM393 is a comparator, so I think the blue dial sets the 'threshold level' and any sounds over that level cause a logic low. i.e. it compares the audio level and the dial and when one exceeds the other it gives a signal.

The features also say "The output effective signal is low level" which is probably Chinglish for the signal is a logic low, i.e. when the sound is heard it goes to 0V rather than 5V which is what I think you were expecting.

In summary: This device is is more like a Clapper, it detects a loud noise and sends a digital low signal.

Try making a loud noise with the same setup you already have, and if not try adjusting the potentiometer by turning it, but not too far! It probably only turns 180-270º.

  [1]: http://www.ebay.co.uk/itm/1x-Sound-Sensor-Detection-Module-LM393-Electret-Microphone-for-Arduino-/231034416834


message:
what is the use of "<<=" operator?

I recently read this piece of code and I dont know what is the use of "<<=" in the for loop:

    for (mask = 0x01; mask>0; mask <<= 1) {
        if (data & mask){ // choose bit

This is the entire code:

    //Created August 23 2006
    //Heather Dewey-Hagborg
    //http://www.arduino.cc

    #include <ctype.h>

    #define bit9600Delay 100
    #define halfBit9600Delay 500
    #define bit4800Delay 188
    #define halfBit4800Delay 94

    byte rx = 6;
    byte tx = 7;
    byte SWval;

    void setup() {
      pinMode(rx,INPUT);
      pinMode(tx,OUTPUT);
      digitalWrite(tx,HIGH);
      delay(2);
      digitalWrite(13,HIGH); //turn on debugging LED
      SWprint('h');  //debugging hello
      SWprint('i');
      SWprint(10); //carriage return
    }

    void SWprint(int data)
    {
      byte mask;
      //startbit
      digitalWrite(tx,LOW);
      delayMicroseconds(bit9600Delay);
      for (mask = 0x01; mask>0; mask <<= 1) {
        if (data & mask){ // choose bit
         digitalWrite(tx,HIGH); // send 1
        }
        else{
         digitalWrite(tx,LOW); // send 0
        }
        delayMicroseconds(bit9600Delay);
      }
      //stop bit
      digitalWrite(tx, HIGH);
      delayMicroseconds(bit9600Delay);
    }

    int SWread()
    {
      byte val = 0;
      while (digitalRead(rx));
      //wait for start bit
      if (digitalRead(rx) == LOW) {
        delayMicroseconds(halfBit9600Delay);
        for (int offset = 0; offset < 8; offset++) {
         delayMicroseconds(bit9600Delay);
         val |= digitalRead(rx) << offset;
        }
        //wait for stop bit + extra
        delayMicroseconds(bit9600Delay);
        delayMicroseconds(bit9600Delay);
        return val;
      }
    }

    void loop()
    {
        SWval = SWread();
        SWprint(toupper(SWval));
    }

body:
`<<` is the left bit-shift operator. That means it takes the binary contents of a number and moves everything left by a certain number of binary places (1 place in this case). `<<=` simply combines the left bit-shift with an assignment, so it takes the current value of `mask`, shifts it left, and then stores the result back in `mask`.

In this situation, the `mask` variable starts with a value of `1`. The second time round the loop, it will be `10` (binary). Next time, it will be `100`, and so on. Since `mask` is a byte (which is 8 bits), it will go all the way up to `10000000` and then stop. After that, the 1 effectively falls-off the left and `mask` ends up with a value of 0.

The purpose of this in the code you provided is to test each individual bit within the `data` parameter. It basically goes through from least- to most-significant and checks if each bit is 1 or 0. It will then pull an output pin HIGH or LOW (respectively) to match. This allows it to send the contents of the variable digitally to some other device.

Doing low-level binary (aka bit-wise) operations like this is very common in microcontroller programming. If you're not familiar with it then I'd definitely recommend looking up some tutorials online. It opens up a huge range of new possibilities for your projects.


body:
In simpler terms `mask <<= 1` is shorthand for `mask = mask << 1`

In general

    variable operator= operand

is the augmented assignment operator which means

    variable = variable operator operand


body:
As stated in the other answers, the `<<=` operator shifts the byte to the left; however, the number '1'  after it specifies how far to shift it - so, `2 <<= 2` == 8.
Possibly clearer in binary:

`00000001 <<= 1` == `00000010`

`00000010 <<= 1` == `00000100`

`00000001 <<= 2` == `00000100`


message:
Xbee power issue

I want to power xbee s2 module through atmel 328p digital output pin. And I am powering atmel 328p IC using 3.7 li-ion cell 5500 mAh. In sleep mode atmel consume current in micro Amp but xbee consuming around 40 mA. I want to reduce it. I tried xbee in power down mode but its not working for me. Is der any way to switch xbee automatically with as atmel sleep & wake-up. Circuit works properly when I power xbee through 3.7 v li-ion cell but consume power continuously.

body:
The best solution would be to determine why your Xbee is not being switched into power down mode.

But, if you wish to turn the Xbee power off using the Arduino then there are many ways of doing this. One method is shown on the diagram below {[**from here**](http://www.microchip.com/forums/m697820.aspx)}. This requires two transistors and three resistors. Almost any small transistors would work. Good choices if buying new components would be BC337 / BC817 for T1 and BC327 / BC807 for T2. The first part number in each pair is a through hole part and the second number is the equivalent surface mount part. If buying these try to get the -40 suffix versions, although in this case any version would work OK.

This circuit was drawn for use with a PIC processor controlling a 12V supply, but the Arduino works equally well controlling a 3.7V LiIon supply. The load is shown as a light bulb - that's where you'd connect the XBee.

![enter image description here][1]

Input low turns 1 off which turns T2 off. To enable/disable the XBee you have to raise / lower the input pin.

  [1]: https://i.stack.imgur.com/Ll7ah.gif


body: I would use a sleep mode, e.g. PIN sleep, in order to reduce the power consumption of the Xbee. At the hardware level, the XBee uses pin 9 as a control pin. This pin can be used to sleep the radio: setting it to 3,3V (“high” or “asserted”) causes the radio to sleep; setting it to 0V (“low” or “deasserted”) wakes the radio up. You can find some useful hints on the following websites http://citizen-sensing.org/2013/08/xbee-sleeping/ or https://www.digi.com/wiki/developer/index.php/Designing_a_Sleeping_XBee_Sensor  or here http://www.johnhenryshammer.com/WOW2/pagesHowTo/xbeeSeries1.php#index.


message:
Time based scheduling, NTP vs delay()

Without asking an open-ended question, i wish to find the best way (resourcefulness) to execute methods from an arduino based on time.

in a nutshell, every 10 minutes i want functionA() to be called & every 30 minutes, functionB(). At this point i'm unable to specifiy whether a method would need to be called at a less frequent rate, however i wish to assume that one may.

My 2 ideas so far:

 - encapsulate the functions a & b inside the NTP client, and execute based on the minutes in an hour

<b>or</b>

 - use delay() or even the milli() counter with functions a & b below inside the loop.

My main worry of the 2nd option is that the arduino handles time keeping itself, in a long run (lets say 1 year), the arduino will end up with no memory left. Whats is the consensus with this?

Board wise, to be run on Uno & Mega.

body:
memory used by delay() and milli() (if any) will be recycled every time you call it, so it does not add up. You should be aware that milli rolls over (resets back to 0) after approximately 50 days - see http://arduino.cc/en/Reference/Millis - you will need to keep track of how many times it has overflowed, and include that in your calculations.

delay will only be useful if you do NOTHING AT ALL during that time - if you want to do other stuff in that space, you should use milli(). Also, if you delay (without using milli()), your events will drift by the time it takes to run the code. delay() and milli() will also only be as accurate as the crystal on your arduino - it should be no more than 20 parts per million; this comes to 10 minutes per year. This may or may not be a problem.

NTP will use a lot more resources, and has to be polled. It is also potentially less reliable (i.e. NTP may be down for short periods).

If you need accurate timing, the best solution would be to use delay() to pass the time (approximately), milli() to keep the time, and adjust for drift with NTP.


body:
Connect a battery backed up Real-Time clock to your arduino and use that to keep track of the time.

Basically the same idea as NTP but minimal hardware is required and you can get an RTC with the long term accuracy you need.


body:
Both NTP and milli() waste a lot of processing as it keeps the Arduino busy checking if the time is right.

Your best bet is to use the Arduino timer. Set the timer to interrupt every 10 minutes. If you don't need to do anything aside from functions A and B, you can let your Arduino sleep and keep power draw to a minimum.

    // Example code
    void funcA(){
        // do stuff
    }
    void funcB(){
        // do stuff
    }

    void setup() {

        // initialize Timer1
        cli();          // disable global interrupts
        TCCR1A = 0;     // clear TCCR1A
        TCCR1B = 0;     // same for TCCR1B

        // set compare match register to desired timer count:
        // 15624*1024/16000000 = 1sec at 16MHz
        OCR1A = 15624;
        // turn on CTC mode:
        TCCR1B |= (1 << WGM12);
        // use 1/1024 the speed of the clock:
        TCCR1B |= (1 << CS10);
        TCCR1B |= (1 << CS12);
        // enable timer compare interrupt:
        TIMSK1 |= (1 << OCIE1A);
        // enable global interrupts:
        sei();
    }

    ISR(TIM1_COMPA_vect)
    // Your task manager here
    // This function decides when to execute the functions A and B
    {
        static t1= 0;
        static t2= 0;

        // increment your counter flags
        t1++;
        t2++;

        if (t1==10) {//runs function every 10 sec
            funcA();
            t1=0;
        }
        if (t2==30) {//runs function every 30 sec
            funcB();
            t2=0;
        }
    }

    void loop(){

        // do stuff or sleep for even more power saving
    }

Hope this helps.


message:
How can I run multiple programs on an Arduino?

I'm trying to get students to experiment with Arduino. However, due to a lack of boards, two teams of students will collaborate on each board. They will push their own code (independent from each other) and use half the pins.

The "hardware" part isn't really a concern: students will push their sketches on a server that uploads them on the board, or something like that.

What I'm worried about is the software part. **How can I allow two sketches to run on the same board**, and **allow the user to upload sketches without resetting the board**?

----

As of my understanding, using the flash memory isn't an option, because the board must be reset before it can be written.

My first idea was to compile the students' C code into custom-made "assembly", and then push the assembly code to the board, which stores it into RAM and interprets it. However, my biggest problem would be implementing functions, I don't really have a clue of how I could do that. While common C functions could just be encoded in a fashion like `FUNC printf STRING %s VAR a` for `printf("%s", a)`, I don't know how to encode user-defined functions. Besides, I don't even think the RAM is sufficient for running the client, storing two small programs, and running them.

Then, I thought about running the C code on the computer, but replacing `digitalWrite` with appropriate signals to the board. However, I'm worried about the performance of this, mostly when dealing with "high" speeds - say, using a custom-made library to print text on a LCD driver.

body:
There is a solution. It requires some programming discipline from your students, but it is feasible.

1) Make sure each group uses different variable and function naming conventions (one starts all variable and functions with `a_` and the other group with `b_`). These functions will be written in separate include files.

2) In the `setup()` and in the `loop()` functions, you will call either `a_setup()` or `b_setup()`, and either `a_loop()` or `b_loop()`. Each of the group setup and loop functions will call their functions and use their variables as the groups want to, but they are not allowed to call variables/functions from the other group. Other resources can also be allocated by you in advance for each team.

3) During the `setup()` function, start by reading a specific input that you will either connect to GND or to 5V. Use the result of this reading to execute either one version of the software, or the other.

This is not elegant, but it gets two program into each Arduino.


body:
> How can I allow two sketches to run on the same board, and allow the user to upload sketches without resetting the board?

This is "easily" dealt with as long as you can enforce certain minimum disciplines.

Students must only use assigned pins.

Identifiers (functions, variables ...) defined by a group must always be unique to that group. This can be as simple as eg always starting with a group specific symbol or eg one group NEVER using a z in names and the other ALWAYS using Z etc. Annoying but easy.

Loop() contains calls to two non-terminating functions eg Group1() and Group2()
All code for Group1 is in Group1() and ....

One digital pin is assigned for Giulio's use.
When GiuliosPin is low the system executes Group1() - and never exits it until restarted.
When GiuliosPin is high the system executes Group2() - and never exits it until restarted.

I uses a system very close to the Group1() / Group2() selection for my own purposes to allow multiple sketches to be compiled at once - but I use a constant which is set  as I compile to choose which to run. My concern is the ability to test multiple code fragments.

____________________

Added:

After reading Mac's similar answer I see I missed mentioning Setup().
Code from both users can be merged into the same Setup() as the identifiers are unique.
Or the Setup() function for each Group can be carried out inside their unique Groupx() function with a "run once" function at the start of their code. This is a matter of programming discipline and not in any way hard per se.


body:
In addition to the other answers, I have a few ideas:

1.) Instead of doing variable prefixes, have them wrap all of their code inside a namespace! Please note that you can't wrap "setup" or "loop" in that namespace. Example

    setup() {
      if(conditionIsTrue) {
        aGroup::setup();
      } else {
        bGroup::setup();
      }
    }

    loop() {
      if(conditionIsTrue) {
        aGroup::loop();
      } else {
        bGroup::loop();
      }
    }

    namespace aGroup {
    setup() {
      // Code
    }

    loop() {
      // Code
    }
    }

    namespace bGroup {
    setup() {
      // Code
    }

    loop() {
      // Code
    }
    }

2.)

Please note you'll have issues with a student tries to access an analog pin and doesn't prefix it with `A`. For example, if I wanted analog pin 5, I should do `analogRead(A5);`, ***not*** `analogRead(5);`. That could cause some major issues.


body:
There is no native multitasking on an Arduino. A few solutions have been suggested above, all of which depend on cooperative multitasking - each half has to play fair.

An alternative may be this:

Buy some AtTiny chips - e.g. AtTiny 24a; they are about $2-3 each. Buy some VeroBoard. Solder the AtTiny on to the board, so each verboard strip has 2 pins on it (not the other way, where each veroboard strip has half of the pins on it). Solder on some pins, cut the track between the pairs of pins, and cut the board to size. You should be able to get a working board, with 12 usable pins per board, and you'll be paying less than $5 per board in your local currency. Buy a USBISP, and hook up the pins, whenever you need to program them - I suggest using the FreeTronics programmer, like this one here: http://www.jaycar.com.au/productView.asp?ID=XC4237 - you can solder 2 pins for the "slow clock" option - you'll need this. Optionally, you could make an adapter board which plugs into all of the relevant pins in one go, to program it. You should only need one of these. To figure out which wires to connect where, compare the top diagram on http://www.dz863.com/datasheet-8310956563-ATTINY24A-SSU_8-bit-Microcontroller-With-2k-4k-Bytes-In-system-Programmable-Flash/ with https://www.olimex.com/Products/AVR/Programmers/AVR-ICSP/resources/AVR-ICSP.gif

You can power them with AA batteries or an external power supply - you could easily make one power supply that runs many boards. Check out the spec sheet for the voltage required - it varies, depending on the clock speed (default clock speed as described is 1 MHz, google "avr fuses" for how to set them to e.g. 8 MHz at no extra cost).


body:
A little late, but I used a potentiometer as a switch to determine which "sketch" to run; in this case swapping LEDs on/off. I assume it can be applied to this instance, the students just have to share/divide pins and declare variables together at the top with comments. (I'm new at this, but I think a shift register (75HC595) could be used if you run out of pins). Thoughts?

EDIT: Potentiometers give a value of 0-1023. I split that up into 2, 3, and 4 separate sketches with no problems. You just have to change the IF/ELSEIFs to reflect how many sketches you want to run (512 for 2, 341 for 3, ~256 for 4, etc).

    int sensorPin = 0;
    int sensorValue = 0;
    int ledPin1 = 4;
    int ledPin2 = 8;

    void setup() {

      pinMode(ledPin1, OUTPUT);
      pinMode(ledPin2, OUTPUT);
    }

    void loop() {

      sensorValue = analogRead(sensorPin);

      if (sensorValue < 512)
    {
        digitalWrite(ledPin1,HIGH);
        digitalWrite(ledPin2,LOW);
    }

      else
    {
        digitalWrite(ledPin2,HIGH);
        digitalWrite(ledPin1,LOW);
    }
    }


message:
Cannot find Arduino under /dev Directory

I have the Arduino board connected to a USB port of my machine. But I cannot find it under /dev/ directory in my Ubuntu. Does anyone know how to deal with this issue? By the way, "lsusb"'s output proves that it has been recognized. Here is the output of this command:

    Bus 002 Device 002: ID 8087:8000 Intel Corp.
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 002: ID 8087:8008 Intel Corp.
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 003 Device 007: ID 413c:2105 Dell Computer Corp. Model L100 Keyboard
    Bus 003 Device 013: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Here is the output of ls -l /dev/ttyACM*

    ls: cannot access /dev/ttyACM*: No such file or directory

and the dmesg output when disconnect and reconnect the device:

    [1653809.002715] usb 3-11: USB disconnect, device number 13
    [1653832.188835] usb 3-11: new full-speed USB device number 14 using xhci_hcd
    [1653832.211392] usb 3-11: New USB device found, idVendor=2341, idProduct=0043
    [1653832.218400] usb 3-11: New USB device strings: Mfr=1, Product=2, SerialNumber=220
    [1653832.226003] usb 3-11: Manufacturer: Arduino (www.arduino.cc)
    [1653832.231859] usb 3-11: SerialNumber: 85235353137351708191
    [1653832.237468] usb 3-11: ep 0x82 - rounding interval to 1024 microframes, ep desc says 2040 microframes

body:
Note that lsusb does not guarantee the drives are loaded (See https://superuser.com/questions/165733/will-lsusb-and-lspci-list-devices-for-which-the-system-has-no-drivers)

Per the https://stackoverflow.com/a/14586884/1653571 answer, try an 'lsmod' and see whether you have a 'cdc_acm' module loaded.


message:
verification error, first mismatch at byte 0x3895 0xdf != 0x44?

I bought a SainSmart Arduino Mega 2560. I uploaded a small sketch to it, and it uploaded fine. When I upload a larger sketch though, I get this error:

    verification error, first mismatch at byte 0x3895
             0xdf != 0x44
So obviously there's nothing wrong with my bootloader because I can upload smaller files. Why is this happening?

body:
If your sketch contains !!! in it, that can cause some versions of the bootloader to drop into interactive mode, eg.

    Serial.println ("Rocket firing!!!");

Also there can be problems with 0xFF bytes in your code causing the bootloader to incorrectly assume that that page of memory was erased, when it was not.

I have a bootloader-uploader sketch at: [Atmega bootloader programmer](http://www.gammon.com.au/bootloader)

You need a second board to use it (eg. a Uno) - the bootloader for the Mega2560 is a reasonably up-to-date one. I haven't actually tested it with the Sainsmart version of the Mega, but I presume that internally that part is the same.


body:
I believe I have finally understood this error today, and would like someone to verify or refute.

In "avrdude.conf" there is defined for each processor and for each memory type a minimum duration and a maximum duration that the programmer will repeat trying to write each byte. These have values of "min_write_delay = 4500" and "max_write_delay = 4500" (no idea what the units are).

After increasing the max_write_delay to "max_write_delay = 16000" (arbitrary increase but keeping it less than a 16 bit signed integer to avoid buffer overflow risks), for all memory types (but I would presume that only "flash" memory needs the parameter to be altered) my Arduino takes an extra 30 seconds to program, but no more verification errors.


message:
Set Arduino digitalRead reference voltage

I wanted to know if the reference voltage for the `digitalRead()` function could be set to a particular voltage, either with an external reference or internally.

In the Arduino reference under the constants heading they have mentioned that they use 3V as reference for the boards I'm using (an Arduino Uno R3). But I want to change it to be a little lower.

Is it possible and if so how?

body: for a 5 volt Arduino anything over 2.7V will be considered as a digital HIGH whereas anything below 0.4V will be a digital LOW.