body:
I have an arduino micro which I want to program from my Kubuntu 15.10 system. I installed the arduino software using apt-get, but when I try to upload the program (for test purpose I use the Basics\BareMinimum sketch) I get the following error:

    Found programmer: Id = "0.00 V1"; type =
        Software Version = 0..; Hardware Version = 0.0
    avrdude: error: buffered memory access not supported. Maybe it isn't
    a butterfly/AVR109 but a AVR910 device?

The proper device "Arduino Micro" is selected and also the proper port "/tty/ACM0". I found people on the internet which have the same error and could solve it by using another USB port or cable. But I tried it with two different cables and different ports and didn't manage to get it working. I even tried it on my Laptop running an older version of Kubuntu which produced the same error.

Therefore I tried the newest version of the Arduino software from the arduino homepage. With this I get a different error:

    avrdude: ser_open(): can't open device "/dev/ttyACM0": Device or resource busy
    avrdude: ser_send(): write error: Bad file descriptor

My user is added to the dialout group, so I should have access to the port. It is also the right port as the port disappears from the arduino menu when I unplug the board.

The arduino itself shouldn't be the problem, as I can upload the sketch from another windows laptop without problems.

EDIT: when I plug in the arduino, the following is added to the `dmesg` output:

    [ 8390.293960] usb 1-2: new full-speed USB device number 6 using xhci_hcd
    [ 8390.424861] usb 1-2: New USB device found, idVendor=2341, idProduct=8037
    [ 8390.424863] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    [ 8390.424864] usb 1-2: Product: Arduino Micro
    [ 8390.424865] usb 1-2: Manufacturer: Arduino LLC
    [ 8390.425283] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
    [ 8390.426815] input: Arduino LLC Arduino Micro as /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:2341:8037.0007/input/input21
    [ 8390.482163] hid-generic 0003:2341:8037.0007: input,hidraw4: USB HID v1.01 Mouse [Arduino LLC Arduino Micro] on usb-0000:00:14.0-2/input2

title: Error uploading Arduino Micro Sketch using Kubuntu

Answers: 5

body:
I have been meaning to try the Arduino IDE on Ubuntu. (I'm on Ubuntu 14.10 LTS and using an original Arduino UNO).

From the top, I installed using:

    sudo apt-get update && sudo apt-get install arduino arduino-core

(from: http://playground.arduino.cc/Linux/Ubuntu)

It's the older version 1.0.5 and loaded up the basic sketch. It worked straight off the bat.

Just some quick thoughts:

#Keyboard and mouse emulation

I noticed the `hid-generic` and was reminded of the caution on:
[https://www.arduino.cc/ re codig practices for keyboard and mouse emulation][1]

regarding coding practices for keyboard and mouse emulation. Does your old sketch utilise the keyboard/mouse libraries at all? It might come down to REALLY timing the reset perfectly.

#The `reset` problem

Given that you're getting a communication error based on the virtual USB device in the Leonardo/Micro (single chip as opposed to the previous versions), and you're seeing it in the IDE but not via the `avrdude` software, have you followed the `reset` instructions from [the above link][2]? So back to timing the reset (emphasis mine):

>In general, you upload code to the Leonardo or Micro as you would with the Uno or other Arduino boards. Click the upload button in the Arduino IDE and your sketch will be automatically uploaded onto the board and then started. This works more or less the same way as with the Uno: the Arduino software initiates a reset of the board, launching the bootloader - which is responsible for receiving, storing, and starting the new sketch.

>However, because the serial port is virtual, it disappears when the board resets, the Arduino software uses a different strategy for timing the upload than with the Uno and other boards. In particular, after initiating the auto-reset of the Leonardo or Micro (using the serial port selected in the Tools > Serial Port menu), the Arduino software waits for a new virtual (CDC) serial / COM port to appear - one that it assumes represents the bootloader. It then performs the upload on this newly-appeared port.

>These differences affect the way you use the physical reset button to perform an upload if the auto-reset isn't working. **Press and hold the reset button on the Leonardo or Micro, then hit the upload button in the Arduino software. Only release the reset button *AFTER* you see the message "Uploading..." appear in the software's status bar.** When you do so, the bootloader will start, creating a new virtual (CDC) serial port on the computer. The software will see that port appear and perform the upload using it. Again, this is only necessary if the normal upload process (i.e. just pressing the uploading button) doesn't work. (Note that the auto-reset is initiated when the computer opens the serial port at 1200 baud and then closes it; this won't work if something interferes with the board's USB communication - e.g. disabling interrupts.)

#`avrdude` command line
Next, share your `avrdude` command line and we can see if something is odd there. As an example with my UNO I see this:

    /usr/share/arduino/hardware/tools/avrdude -C/usr/share/arduino/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/build1362089533882735765.tmp/Blink.cpp.hex:i

    avrdude: Version 6.0.1, compiled on Oct 21 2013 at 15:55:32
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "/usr/share/arduino/hardware/tools/avrdude.conf"
             User configuration file is "/home/madivad/.avrduderc"
             User configuration file does not exist or is not a regular file, skipping

             Using Port                    : /dev/ttyACM0
             Using Programmer              : arduino
             Overriding Baud Rate          : 115200
    avrdude: Send: 0 [30]   [20]
    .... and so on ....

#USB 3 vs USB 2
I probably could have put this closer to the top, but are you using a USB 2 or USB 3 port? If USB 3 are the correct drivers loaded? Have you tried a USB 2 port (if available)

#Good luck

  [1]: https://www.arduino.cc/en/Guide/ArduinoLeonardoMicro#toc13
  [2]: https://www.arduino.cc/en/Guide/ArduinoLeonardoMicro#toc12

body:
You may find that there is a process on Ubuntu that is grabbing the newly created CDC/ACM port as soon as it enters programming mode.

With the Leonardo and Micro you have a CDC/ACM port while it's running, and when the board resets to enter programming mode that CDC/ACM port is destroyed and an entirely new one (hopefully under the same name) is created.  The process `modem-manager` can grab that newly created CDC/ACM device thinking it's a modem and try to configure it as such, thus locking you out of the port.  A similar process in Debian is `brltty` which tries to configure the CDC/ACM port as a braille TTY interface.

You can check to see what process has the CDC/ACM device node open if any with the `lsof` command:

    sudo lsof /dev/ttyACM0

If you find that you do have `modem-manager` running on your system (I'm not sure if it's still default or not, it's been a while since I used Ubuntu, preferring the purity of Debian) it's best to completely remove it:

    sudo apt-get remove modemmanager

body:
> Therefore I tried the newest version of the Arduino software from the arduino homepage.

> The package version I am using is 1:1.0.5+dfsg2-2, the other I tried was 2:1.0.5+dfsg2-4.

That is not the newest version.

I think the more recent versions of the IDE are more robust - after all they have fixed reported bugs. Try 1.6.5 or 1.6.7. The version 1.0.5 is pretty old.

---

I too have had "upload completed" on my Leonardo (virtually the same as the Micro) when it did no such thing.

I am using Ubuntu 14.04 and don't have any problems programming my Micro with IDE 1.6.7.

---

When programming you should see the Tx/Rx and yellow LEDs flicker. If not, press Reset when it starts to upload and try again.

---

Have you followed the instructions here? [Arduino Troubleshooting](https://www.arduino.cc/en/Guide/Troubleshooting).

---

> I installed the arduino software using apt-get ...

Personally I download the IDE from this page: <https://www.arduino.cc/en/Main/Software>

---

## Update

I just compiled and uploaded "Blink" with IDE 1.6.7 to my Micro on Ubuntu 14.04. This is what I saw:

    Forcing reset using 1200bps open/close on port /dev/ttyACM1
    PORTS {/dev/ttyACM0, /dev/ttyACM1, } / {/dev/ttyACM0, } => {}
    PORTS {/dev/ttyACM0, } / {/dev/ttyACM0, /dev/ttyACM1, } => {/dev/ttyACM1, }
    Found upload port: /dev/ttyACM1
    /home/nick/Development/arduino-1.6.7/hardware/tools/avr/bin/avrdude -C/home/nick/Development/arduino-1.6.7/hardware/tools/avr/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM1 -b57600 -D -Uflash:w:/tmp/build8f287ac41038dd4edf2d64ea95be7b6f.tmp/Blink.ino.hex:i

    avrdude: Version 6.0.1, compiled on Apr 14 2015 at 19:04:16
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "/home/nick/Development/arduino-1.6.7/hardware/tools/avr/etc/avrdude.conf"
             User configuration file is "/home/nick/.avrduderc"
             User configuration file does not exist or is not a regular file, skipping

             Using Port                    : /dev/ttyACM1
             Using Programmer              : avr109
             Overriding Baud Rate          : 57600
             AVR Part                      : ATmega32U4
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PA0
             RESET disposition             : dedicated
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
               flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
               lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

             Programmer Type : butterfly
             Description     : Atmel AppNote AVR109 Boot Loader

    Connecting to programmer: .
    Found programmer: Id = "CATERIN"; type = S
        Software Version = 1.0; No Hardware Version given.
    Programmer supports auto addr increment.
    Programmer supports buffered memory access with buffersize=128 bytes.

    Programmer supports the following devices:
        Device code: 0x44

    avrdude: devcode selected: 0x44
    avrdude: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.00s

    avrdude: Device signature = 0x1e9587
    avrdude: reading input file "/tmp/build8f287ac41038dd4edf2d64ea95be7b6f.tmp/Blink.ino.hex"
    avrdude: writing flash (4456 bytes):

    Writing | ################################################## | 100% 0.33s

    avrdude: 4456 bytes of flash written
    avrdude: verifying flash memory against /tmp/build8f287ac41038dd4edf2d64ea95be7b6f.tmp/Blink.ino.hex:
    avrdude: load data flash data from input file /tmp/build8f287ac41038dd4edf2d64ea95be7b6f.tmp/Blink.ino.hex:
    avrdude: input file /tmp/build8f287ac41038dd4edf2d64ea95be7b6f.tmp/Blink.ino.hex contains 4456 bytes
    avrdude: reading on-chip flash data:

    Reading | ################################################## | 100% 0.03s

    avrdude: verifying ...
    avrdude: 4456 bytes of flash verified

    avrdude done.  Thank you.

Can you please compare to what you get? Or post exactly what you see?

---

What do you see in your Port menu? This is what I see:

[![Port menu][1]][1]

---

# Installing Arduino on a fresh Ubuntu system

I did the following steps to get Arduino up on Ubuntu 14.04, on a PC where it was not previously installed.

## Download and install

* Downloaded Linux IDE 1.6.7 (64 bit) from <https://www.arduino.cc/en/Main/Software>

* Un-archive downloaded file into `~/development` folder

* Executed from terminal:  `./arduino`

## Compile "blink"

* Selected Uno device type
* Loaded "Blink" from examples
* Uploaded (checked Uno showed in menu as shown above)
* Got error:

        Sketch uses 1,030 bytes (3%) of program storage space. Maximum is 32,256 bytes.
        Global variables use 9 bytes (0%) of dynamic memory, leaving 2,039 bytes for local variables. Maximum is 2,048 bytes.
        avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
        ioctl("TIOCMGET"): Inappropriate ioctl for device

## Check permissions, join dialout and tty groups

See owner of `/dev/ttyACM*`

    $ ls -l /dev/ttyACM*
    crw-rw---- 1 root dialout 166, 0 Feb  1 07:32 /dev/ttyACM0

Am I in that group? (No)

    getent group dialout
    dialout:x:20:

Add to group `dialout`:

    $ sudo usermod -a -G dialout nick

Am I in that group? (Yes)

    $ getent group dialout
    dialout:x:20:nick

Try again:

    avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
    ioctl("TIOCMGET"): Inappropriate ioctl for device
    Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Add to group `tty`:

    $ sudo usermod -a -G tty nick

Check groups I am in:

    $ groups nick
    nick : nick adm tty dialout cdrom sudo dip plugdev lpadmin sambashare

Try again (same error).

## Log out and log back in

After logging out and back in, it uploaded OK! Changed to Micro board (very similar to Leonardo) - still uploaded OK (after changing board type in IDE).

## Check USB for Micro

After reset:

    $ lsusb | grep Arduino
    Bus 002 Device 014: ID 2341:0036 Arduino SA

After about 3 seconds:

    $ lsusb | grep Arduino
    Bus 002 Device 015: ID 2341:8037 Arduino SA

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

body:
This is all the symptoms of not having the correct board selected in the IDE.
The fact that the LEDs are flashing during uploading means it's probably not a comms issue.

I understand you wrote that you have selected the correct board already, but please double/triple-check.

I work with both UNOs and Nanos, this is a classic mistake I make all the time.

body:
sudo chmod 666 /dev/ttyACM{for your arduino board}

mine happens to be "/dev/ttyACM1" so i did

sudo chmod 666 /dev/ttyACM1


body:
for my rc robot I want to use ir to send/receive the value from a jostick.

Is it possible ? I can't use any other radio chip like nrf24l01.

title: Send analog value over IR?

Answers: 1

body:
Yes, it is possible. That is already supported by the IR library. Please see this [tutorial][1] for further details. The outline of the sender is:

     uint16_t sample = analogRead(A0);
     irsend.sendSony(sample, 16);

And the receiver:

     if (irrecv.decode(&decodedSignal)) {
        uint16_t sample = decodedSignal.value;
        ...
     }

Cheers!

  [1]: http://garagelab.com/profiles/blogs/tutorial-arduino-ir-sender-and-receiver


body:
I've just installed the last version of Arduino 1.6.7 plug my Arduino SmartEverything (http://www.smarteverything.it/) to OS X 10.11.2, try to compile this project: https://github.com/nicolsc/sigfox-weather-station/blob/master/sigfox_smart_weather.ino But i got this error

    /Applications/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware "/Applications/Arduino.app/Contents/Java/hardware" -hardware "/Users/nunito/Library/Arduino15/packages" -tools "/Applications/Arduino.app/Contents/Java/tools-builder" -tools "/Applications/Arduino.app/Contents/Java/hardware/tools/avr" -tools "/Users/nunito/Library/Arduino15/packages" -built-in-libraries "/Applications/Arduino.app/Contents/Java/libraries" -libraries "/Users/nunito/Documents/Arduino/libraries" -fqbn=AMEL:samd:AMEL_SmartEverything_native -vid-pid=0X2341_0XE002 -ide-version=10607 -build-path "/var/folders/52/_nghc_ms7p52tqr5zdbwvj240000gn/T/build50d3a89dbbfb2b67c903ba23d4913431.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "/var/folders/52/_nghc_ms7p52tqr5zdbwvj240000gn/T/arduino_50d3a89dbbfb2b67c903ba23d4913431/sketch_jan21c.ino"
    /Applications/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware "/Applications/Arduino.app/Contents/Java/hardware" -hardware "/Users/nunito/Library/Arduino15/packages" -tools "/Applications/Arduino.app/Contents/Java/tools-builder" -tools "/Applications/Arduino.app/Contents/Java/hardware/tools/avr" -tools "/Users/nunito/Library/Arduino15/packages" -built-in-libraries "/Applications/Arduino.app/Contents/Java/libraries" -libraries "/Users/nunito/Documents/Arduino/libraries" -fqbn=AMEL:samd:AMEL_SmartEverything_native -vid-pid=0X2341_0XE002 -ide-version=10607 -build-path "/var/folders/52/_nghc_ms7p52tqr5zdbwvj240000gn/T/build50d3a89dbbfb2b67c903ba23d4913431.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "/var/folders/52/_nghc_ms7p52tqr5zdbwvj240000gn/T/arduino_50d3a89dbbfb2b67c903ba23d4913431/sketch_jan21c.ino"
    Build options changed, rebuilding all
    ""   -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_SMARTEVERYTHING -DARDUINO_ARCH_SAMD  -D__SAMD21J18A__        "-I/Users/nunito/Library/Arduino15/packages/AMEL/hardware/samd/1.1.0/cores/arduino" "-I/Users/nunito/Library/Arduino15/packages/AMEL/hardware/samd/1.1.0/variants/AMEL_SmartEverything" "/var/folders/52/_nghc_ms7p52tqr5zdbwvj240000gn/T/build50d3a89dbbfb2b67c903ba23d4913431.tmp/sketch/sketch_jan21c.ino.cpp" -o "/dev/null"
    ""   -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_SMARTEVERYTHING -DARDUINO_ARCH_SAMD  -D__SAMD21J18A__        "-I/Users/nunito/Library/Arduino15/packages/AMEL/hardware/samd/1.1.0/cores/arduino" "-I/Users/nunito/Library/Arduino15/packages/AMEL/hardware/samd/1.1.0/variants/AMEL_SmartEverything" "/var/folders/52/_nghc_ms7p52tqr5zdbwvj240000gn/T/build50d3a89dbbfb2b67c903ba23d4913431.tmp/sketch/sketch_jan21c.ino.cpp" -o "/dev/null"
    ""   -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_SMARTEVERYTHING -DARDUINO_ARCH_SAMD  -D__SAMD21J18A__        "-I/Users/nunito/Library/Arduino15/packages/AMEL/hardware/samd/1.1.0/cores/arduino" "-I/Users/nunito/Library/Arduino15/packages/AMEL/hardware/samd/1.1.0/variants/AMEL_SmartEverything" "/var/folders/52/_nghc_ms7p52tqr5zdbwvj240000gn/T/build50d3a89dbbfb2b67c903ba23d4913431.tmp/sketch/sketch_jan21c.ino.cpp" -o "/var/folders/52/_nghc_ms7p52tqr5zdbwvj240000gn/T/build50d3a89dbbfb2b67c903ba23d4913431.tmp/preproc/ctags_target_for_gcc_minus_e.cpp"
    exec: "-w": executable file not found in $PATH
    Error compiling.

[![enter image description here][1]][1]

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

title: Error compiling Arduino

Answers: 1

body:
Install Arduino SAMD Boards (32-bits ARM Cortex-M0+) board (using "Tools" -> "Board" -> "Boards Manager" menu).

Just search for "SAMD" in the search bar, choose the latest version and install.


body:
I have a PM10 sensor that I'd like to get the values from.

Here's the official documentation from the sensor:
[![ Sensor documentation ][1]][1]

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

I've looked as serial communication, but how do i process byte by byte of information if it's coming in byte at a time?

I'm looking at this example:

    void setup() {
      Serial.begin(9600);
      Serial.println("<Arduino is ready>");
    }

    void loop() {
      recvOneChar();
      showNewData();
    }

    void recvOneChar() {
      if (Serial.available() > 0) {
        receivedChar = Serial.read();
        newData = true;
      }
    }

    void showNewData() {
      if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChar);
        newData = false;
      }
    }

Ideally, i'd like to get the PM2 and PM10 values and print them out.

title: Processing Serial data

Answers: 1

body:
The proper method of receiving this kind of data is to use a *sliding window*. That is you visualise the stream of bytes as just that - a stream of bytes (think letters on paper tape).  You then have a conceptual "window" on that data which is the width of the packet (10 bytes in this case).  As the data passes behind the window you see just 10 bytes of it. When that 10 bytes is in the "right" format (that is, it starts with 0xAA, ends with 0xAB and the checksum is valid) then you have a valid packet and can read the values from it.

The simplest method of implementing that is with a 10-byte array. As a byte arrives on the serial port you shuffle all the bytes down the array to make room for the new byte at the top of the array.  Once 10 bytes have arrived that first byte should now have made its way to the bottom of the array.

For instance:

    uint8_t window[10];

    void setup() {
        Serial.begin(9600);
    }

    void loop() {
        if (Serial.available()) {
            // Slide the window
            for (uint8_t i = 0; i < 9; i++) {
                window[i] = window[i + 1];
            }
            // Add the new character
            window[9] = Serial.read();

            // Output the current window data for debugging
            dumpWin();

            // Check the framing characters
            if ((window[0] == 0xAA) && (window[9] == 0xAC)) {
                // Calculate the checksum
                uint8_t cs = 0;
                for (uint8_t i = 2; i < 8; i++) {
                    cs += window[i];
                }
                // If the checksum matches...
                if (cs == window[8]) {
                    // ...we have a valid packet!
                }
            }
        }
    }

    void dumpWin() {
        for (int i = 0; i < 10; i++) {
            Serial.print(window[i], HEX);
            Serial.print(" ");
        }
        Serial.println();
    }
Getting the data out of the valid packet is now a case of combining bytes into 16-bit integers then dividing them into floats.  For instance the PM2.5 would be:

    uint16_t pm25i = (window[3] << 8) | window[2];
    float pm25 = (float)pm25i / 10.0;

The PM10 would be the same but with window[5] and window[4] of course.

----

Since you can't really use the hardware UART for both communication with your sensor and communication with the PC you may want to investigate the use of [SoftwareSerial](https://www.arduino.cc/en/Reference/SoftwareSerial) instead of the hardware UART pins for communicating with the sensor.


body: I'm trying to program my Arduino Uno with my Windows PC. I followed all the instructions on the site. I mistakenly downloaded the .zip file and didn't unzip it, before plugging in my Arduino Uno. So naturally, no message came up. I then followed the correct procedure, but Windows driver installer does not detect the Arduino Uno. What can I do to fix this?

title: Windows driver installer not detecting arduino

Answers: 1

body:
Per my comment above, the drivers are not installed when using the Arduino editor from an extracted zip file. If you are feeling adventurous, they are located in the /drivers folder and you can install them manually, there are plenty of instructions elsewhere on the internet on how to do that.

My recommendation would be to just download and run the installer version of Arduino, as that will take care of registering the drivers for you. The installer can be found on the [download page][1] indicated with the text "Windows Installer".

  [1]: https://www.arduino.cc/en/Main/Software


body:
Except hardware UART. Main requirements are reliability and simplicity of use. Speed isn't as important.

Details:

I have an Arduino Pro Mini (ATmega328P 5V) controlled via UART.

I wish to connect an ESP8266 with stripped-down NodeMCU to offer a web interface for the same functionalities, sending <=122 character strings to Arduino and possibly getting a short response.

I do not want to use Arduino for processing the interface (too little memory) or use the ESP only (need a stable clock and multiple analog inputs).

My research shows that:

 - ESP8266 has obvious timing issues, having been designed for a different purpose.
 - [Controlling the ESP8266 from Arduino via hardware serial][1] works fine, but I need it the other way around, too. Also, NodeMCU is rather chatty and I don't know how to suppress it, and I'd rather keep the hardware serial ports for programming.
 - The same via [SoftwareSerial][2] is [unreliable][3]
 - Personal experience shows OneWire works poorly on ESP8266 (though it may have been fixed)

I have no experience with I2C and SPI beyond polling a slave, and don't know about reliability on ESP8266.

The Arduino already works as an I2C master.

I'm assuming I2C is the way to go, but wanted to ask for opinions first.

**[EDIT]**
Seems I have once again neglected to set up the proper context. The reason I'm asking is that ESP8266 *can't do very precise timing*, leading to communication problems. Hardware UART to hardware UART is shown to be reliable. For most other protocols, at least one side does bit-banging. I have not done or found extensive reliability tests for those options, and hope instead that the community can offer some insights. Can you?

  [1]: https://github.com/IRNAS/SimpleArduinoESP-Lua
  [2]: https://arduino.stackexchange.com/q/17184
  [3]: https://primalcortex.wordpress.com/2014/12/30/esp8266-nodemcu-and-lua-language-and-some-arduino-issues/

title: What is the best serial protocol for bidirectional communication with NodeMCU?

Answers: 2

body:
While possibly not "the best", I have found I2C to be sufficient for [my needs][1].

Simple to use, if a bit different conceptually (master-slave).

My tests have shown it to be reliable thus far, zero errors over 20 minutes (sending & receiving 20 bytes each time), as long as there were sufficient pauses between calls.

I am going to make the Arduino switch its i2c master/slave role based on the state of other pins. Master most of the time (to use a DS1307 RTC, etc), switching to slave whenever NodeMCU (which can only work as master) has something to say. Thanks to Zeph for the idea.

  [1]: https://github.com/mamert/iot-a

body:
So you are asking how to use an Arduino Pro Mini as a smart peripheral connected to a NodeMCU master, without making use of the hardware serial port on the latter.

In general, this is either going to operate slowly enough that you can guarantee reception, or you will need to use some kind of flow control or acknowledgement.

One question is whether the APM can always receive at any time, or whether it has to do things which would cause it to not respond for some while and possibly lose data.

Hardware I2c or SPI, with a software flow control protocol using additional pins, are probably your best bets if you cannot use async serial.  For example the APM sets OK2SEND high when it's ready to receive (this is an APM output pin connected to a NodeMCU input pin).  When NodeMCU detects this high, it writes to I2C and then sets HAVESENT high.  When the APM detects & processes incoming data as I2C slave, it sets OK2SEND low.  NodeMCU sees OK2SEND low (ack'ing the byte) and sets HAVESENT low.  APM detects HAVESENT low which completes the handshake.  When APM is ready for another byte, it sets OK2SEND high again.  etc.  Variants could send more than one byte per handshake, if performance needs that; APM asserting OK2SEND would be contracting to handle that number of bytes.

If you can guarantee that the APM will respond quickly enough to interrupts, you could use an interrupt driven I2C slave system on it, and simplify the above.  The APM could be like a dedicated I2C peripheral, albeit a slow one.


body:
I'm a newbie so forgive my ignorance.

I'am using the Morse code translator to light up the LED which is fine but after it has processed the sentence it turns off. How can I get it to loop the sentence continuously.

Thanks

title: Morse code translator Loop the same sentence

Answers: 1

body:
I guess this is the [sketch][1] you are using. It reads characters from Serial and translates them to Morse code.

What you need to do to make it loop a sentence is, 1) read a sentence into a buffer, 2) loop though the buffer and translate to Morse code.

  [1]: http://www.instructables.com/id/Morse-Code-Translator/step5/Program/


body: I used 6 rechargable AA batteries (total 7.2V) to power my Arduino (UNO R3) Car's two DC Motors (using L293D IC as motor driver). I used separate 9V battery to power arduino itself. But I want to share same 6 battery pack to power my arduino via barrel jack. Please suggest me how can I do this? What precautions Should I take? Like decoupling capacitors or any other?

title: Share battery pack with Arduino and DC motors

Answers: 1

body:
You may have read that the UNO can accept 7-12 volts as input power. Your AA battery pack (7.2 volts) is very near the low limit of 7 volts. After just a little discharge of the battery (and also voltage drop from motors running), your batteries are likely to deliver less than 7 volts.

As your AA battery goes below 7 volts, then the 5 volts (regulated) will also begin to go lower.  A reasonable scenario would be if AA battery was 6.5 volts (1/2 volt low), then the 5 volts regulated would be about 4.5 volts. The UNO is likely to operate ok at this voltage, but as voltage goes lower operation could become a problem depending upon your program used.

Since you are experimenting with a toy car, I would say to go ahead and run both the motors and UNO from the same battery pack.  Not a lot to lose on trying.

The UNO already has decoupling capacitors in it's 5 volt regulator circuit.

Just for fun,  you could use an Analog input to measure your 5 volts and if the voltage drops to 4.5 volts, you could dis-allow motor operation and flash an LED (or other action). Just a low battery indicator.

If you decide to measure the 5 volts with an analog input,  read up on using resistor dividers and the Analog reference (A-ref). Because 5 volts dropping to 4.5 volts could effect your analog reading, depending upon what you use for Analog reference.


body:
I have 64 hall effect sensors (magnetic field sensors) ([DRV5023AJQLPG][1]) connected to an Arduino MEGA 2560. For that, I use 48 digital pins and 16 analog pins as digital input pins. The program in the Arduino continuously reads out those 64 digital input pins (in a for-loop) and sends out a serial byte, to a laptop via a usb cable, whenever one of those input pins changes between LOW and HIGH. I also use the ATmega2560’s internal pullup resistors to prevent irregular readouts of the input pins when the sensor is not giving a 0v output (i.e. when it isn’t measuring a strong enough magnetic field).

Everything is working fine when I only physically connect up to 16 of the sensors. The laptop then only receives bytes that correctly tell when a sensor measures a state-change.

However, when I start connecting more of those 64 sensors, then the laptop starts receiving irregular streams of bytes, erroneously suggesting that all the connected sensors measure changing magnetic fields (HIGH and LOW readouts).

I can think of two reasons why these irregular readouts occur:
1. Either, the ATmeag2560’s internal pullup resistors arent working as I think they should.
2. Or, the arduino board and >16 hall effect sensors combined are pulling to much current.

1. **Pullup resistors not working?**
When testing with only 16 sensors connected, it is a stable, properly working setup. When I explicitly *don’t* use the pullup resistors in the program then the setup *does* start behaving irregular, also with just 16 sensors. So the internal pullup resistors seem to be properly activated by the program.

2. **Arduino + 64 sensors draw to much current?**
Besides powering the Arduino board and sensors via the usb cable (providing 500mA), I’ve also tried external power sources that provide 1 or 2A. I’ve also powered the Arduino board via an external 5v, +1A voltage regulator, bypassing the Arduino’s onboard voltage regulator. This all doesn’t seem to make a difference in the system’s irregular behaviour. When measuring those setup’s current usage (with amperage meter) it didn’t go above **250mA**.

Calculating the combined current usage (using datasheet info), I came to this:

 - sensor operating current:    2,7 mA
 - sensor output current when in ‘active’ state:  0,25 mA
 - TOTAL current of 64 sensors (3mA*64=)  192 mA
 - Arduino MEGA current (approx)    150 mA
 - TOTAL current of 64 sensors + Arduino MEGA:  **342 mA**

So, both the calculated and measured current usage seem within the range of what can be handled by mentioned power sources.

I’m kinda stuck now. Can anyone suggest anything that might cause this problem? Or point to incorrect thinking of me? Thanks for any responses.

----------

'Schematic' (only showing first 8 sensors connected. The ArduinoMEGA is connected to a computer via a usb cable with disabled power line):

[!['schematic' (only showing first 8 sensors connected. The ArduinoMEGA is connected to a computer via a usb cable with disabled power line)][2]][2]

Top-side: the hall effect sensors and Vcc an GND rails:
[![Top: the hall effect sensors and Vcc an GND rails][3]][3]

Bottom-side: ArduinoMEGA + the 64 red sensor output lines to the input pins:
[![Bottom: ArduinoMEGA + the 64 red sensor output lines to the input pins][4]][4]

Below is the Arduino code:

<!-- language: c -->

    /*
    Arduino to Pd protocol

     Placing or removing a chess piece sends only one byte.
     There’s no other serial data being communicated.

     event:      byte value:
     placing a chess piece on a square:  0-63
     removing a chess piece from a square:         64-127

     ArduinoMEGA pin to byte value mapping:
      byte  pin
      0  6
      1  7
      2  8
      3  9
      …
      46  52
      47  53

      48  A0 (analog 0)
      49  A1
      50  A2
      …
      62  A14
      63  A15

    */

    byte prevSquares[64];  // array that holds previous readouts
    byte i;                // variable used in for-loops
    byte sensorValue;      // variable temp storing of digitalread

    void setup() {
      Serial.begin(9600);
      for (i = 0; i < 64 ; i++) {
        pinMode(i+6, INPUT_PULLUP);  // activate pullup resistor
      }
      for (i = 0; i < 64 ; i++) {
        prevSquares[i] = digitalRead(i+6);
      }
    }

    void loop() {
      for (i = 0; i < 64 ; i++) {
        sensorValue = digitalRead(i+6);
        if (sensorValue != prevSquares[i]) {
          // chess piece was placed or removed from square
          if (sensorValue == 0) {
            // chess piece was placed
            // send serial byte (0-63):
            Serial.write(i);
          }
          else {
            // chess piece was removed
            // send serial byte (64-127):
            Serial.write(i + 64);
          }
          //update prevSquares array:
          prevSquares[i] = sensorValue;
        }
      }
    }

  [1]: http://nl.farnell.com/webapp/wcs/stores/servlet/ProductDisplay?partNumber=2455494
  [2]: https://i.stack.imgur.com/E57Se.jpg
  [3]: https://i.stack.imgur.com/cuwYF.jpg
  [4]: https://i.stack.imgur.com/0eqiP.jpg

title: ArduinoMEGA: 64 digital inputs cause random digitalRead values

Answers: 1

body:
After seeing your schematic, I think the general problem here is that you need to more closely read and follow the datasheet for this part. A lot of times, when you are hobbling a project together at a small scale there are a lot of things you can ignore and get away with, but as you scale up, all the rounded corners start to add up. In this case, you can get away with 16, but once you start adding too more, it becomes too much. Let's go over a few:

**Pull up resistors**

Like I mentioned in the comments, relying on the internal pull ups is probably not a good idea. In my personal experience, they are only really good for adding a quick button input for debugging purposes. I'm not sure specifically what would cause issues only after 16 sensors. It could be that collectively internal pullups are subject to a different and lower current limit, but I'm not familiar enough with the internal architecture of the ATMega2560 to do more than just speculate.

Whatever the case, the best practice here would be to use separate external pull up resistors, within the specifications of the datasheet. (See equation 1 on page 13 of the datasheet.)

**Decoupling Capacitor**

Per the datasheet, page 17:

> A 0.01-µF (minimum) ceramic capacitor rated for VCC must be placed as close to the DRV5023 device as possible.

This capacitor is referred to as C1 in the datasheet figures and is required. This type of capacitor is called a decoupling capacitor, and one of the things it does is provide a local energy storage, so that when the sensor starts pulling a little extra current, it doesn't have to wait for the regulator to respond, it has some local energy already.

Your schematic indicates a single 1uF capacitor on the output of the voltage regulator, however, there are no capacitors for the sensors. The one capacitor is only for output filtering for the regulator, and will not satisfy any decoupling needs of the sensor.

**Filtering Capacitor**

Referred to as C2 in the datasheet, this an optional capacitor to filter out high frequency noise. This isn't needed in most cases, in fact, per the datasheet, page 13:

> Most applications do no require this C2 filtering capacitor.

However, your project might not fall into "most applications" and there are a few things specifically that worry me.

 1. You have long wires that are basically acting as antennas that will capture any nearby noise.
 2. You have long power lines running parallel to your signal lines which can cause stray inductance which leads to other interesting things. (With the thickness of the plywood separating them, this might not be an issue, but it is something to be aware of).

I would definitely try the first two ideas above to begin with, and only pursue this as a last resort. The  only way to know for sure if this is something you need is to stick an oscilloscope on the line and see how noisy it is, but that is not something you probably have handy.

**Other Concerns**

I'm just a little bit worried about voltage drop. Depending on the gauge of wire used, with all the sensors connected, at the end of a strand you might have a non-negligible voltage drop.

With that many wires running together into the Mega, there might be cross talk problems.

Another common problem with scaling up is that there is a higher probability of having faulty components. This is especially with this part which per the datasheet indicates that is particularly sensitive to ESD. It could be that there is a dead sensor that has failed in such a way that it is causing problems for the other sensors. Maybe go through and test all 64 sensors, 8~16 at a time to make sure that separately they all work, and that the issue only occurs when all of them are connected.

**Other Ideas**

Many other comments on the question have suggested a multiplexer and/or multiplexing and I will just briefly echo that here. Multiplexers are typically used in situations where you don't have enough pins and you want to split a single pin to multiple other pins. While that isn't an issue here with the Mega (it appears you have enough pins to do what you are wanting to do), there are other benefits that can be derived from multiplexing this.

For example, one thing you could do is split up the board into 8 - 2 x 4 chunks and then have a multiplexer (such as a 4051 or a 74151) local to each chunk. Then you would have just 8 short wires going into the multiplexer, as opposed to having long antenna-like wires heading to the Mega. This could improve overall signal integrity.


body:
I'm trying to dim a 10w LED via Arduino PWM.

This is the LED that I have: http://www.banggood.com/10W-Warm-Pure-White-High-Brightest-Save-Power-LED-Light-Lamp-p-88169.html

Without knowing much about this stuff, I bought this (namely because it had LED, DIM, and PWM in its name): http://www.ebay.com.au/itm/121437119430?_trksid=p2057872.m2749.l2649&ssPageName=STRK:MEBIDX:IT

I can't get the eBay dimmer to work for love or money.  When I connect it to ground directly on the battery terminal, it goes off, which means the dimmer circuit is working.  I don't even know where to start with MOSFET dimming solution, but I think that the IRFZ44N MOSFETs are the wrong ones because they won't turn on with 5v power (they need 10v or something, but those are the ones I have on hand).

I can't seem to find any good guides on how to do this after stacks of googling, and to be honest, I don't even know if those LED's can be dimmed in the first place.

What do I need to make this happen?

title: How can I dim a 10w LED?

Answers: 2

body:
I would suggest the CAT4101 PWM controllable constant current sink LED driver.  You might want 2 in parallel for the higher current.

They can deal with up to 1A each (theoretically) though they may get a bit hot at that current level - so it would be better to parallel them so they deal with roughly 500mA each.

body:
Well, it appears that your driver should do that for you. Since you already have the MBI6651 driver, read [its datasheet][1] and so you can get a guess on how it should work:

 1. attach a 9-35V supply to the Vin-GND terminals. I suggest to use at least 12V
 2. attach the LED to the terminals LED+ and LED- (remember the polarity!)
 3. attach a transistor to pull down the pin DIM
 4. send a PWM signal (frequency between 100Hz and 1000Hz) to the transistor and you should see the LED light up and then dim

If it works then you can try to send to DIM directly th PWM signal, but personally I don't recommend so (unless the board already have the transistor)

EDIT:

How to attach an nMOS to the DIM pin. Since the pin is internally pulled up, you don't need any pullup. So you just need an nMOS. I suggest you to use a SOT-23 logic level nMOS connected this way:

[![nMOS connection][2]][2]

no external components (as long as the nMOS supports 5V on the gate, but every discrete mosfet should). As for the nMOS, I prefer the SMD case because it is easy to solder also on perfboards (just use three pads forming an L shape and you'll see that you can easily solder it). Just choose any n-channel mosfet with a maximum threshold voltage of 2V or less and you are done

  [1]: http://www.ledlabs.ru/pdf/macroblock/mbi6651.pdf
  [2]: https://i.stack.imgur.com/Myxdh.png


body:
Does anyone know of any Pelco D libraries available for Arduino?

I already have a PTZ joystick controlling 3 PTZ cameras, but I would like to add an Arduino 'intelligent' controller capable of sending automated sequences of Pelco D commands according to various PIR triggers etc.

title: Pelco D Library for Arduino

Answers: 1

body:
It looks like someone wrote a Pelco library. Check out:

https://github.com/Pixelbo/Pelco_And_Arduino


body:
Does anyone know the voltage situation regarding multi-drop nodes on an RS485 bus please?

Nick Gammons RS485 article shows 2 different hardware configurations, one using 5v devices, and another using 3.3v devices, and I am fairly sure my Pelco PTZ CCTV system uses 12v.

But I have never seen anything mentioned anywhere about needing to voltage-match nodes on an RS485 bus.

So I am unsure whether the MAX driver chips isolate the RS485 bus voltage from the mcu logic levels.

Or do any lower voltage devices (3.3v or 5v) need logic-level matching to their MAX driver chips, which all need powering from the higher bus level (perhaps 12v)?

Basically, I wish to add an 'intelligent' arduino controller to an existing ptz cctv system.

title: RS485 bus voltage?

Answers: 3

body: RS-485 is a differential bus. As long as the *difference* in voltage between the two lines reaches certain thresholds the signal can be interpreted unambiguously regardless of the system supply voltages. Isolation (from ground loops) is not provided by default by the driver, but can be implemented easily enough.

body:
According to my datasheet for the LTC1480:

* –7V to 12V Common Mode Range Permits ±7V Ground Difference Between Devices on the Data Line

**Absolute maximum ratings**

* Supply Voltage (V CC ) : 7V
* Driver Input Voltage  : – 0.3V to V CC + 0.3V
* Driver Output Voltage : ±14V
* Receiver Input Voltage : ±14V
* Receiver Output Voltage : – 0.3V to V CC + 0.3V

---

> I am fairly sure my Pelco PTZ CCTV system uses 12v.

Judging by the above you would need to drop Vcc on the part involving your 12V gadget and use level shifters for the logic levels (if you used this particular chip).

body:
I suspect that the line-driver Vcc may be using a commercial standard of 5v which we are not aware off.

The RS485 Vcc VMax is only 7v anyway, so presumably the thousands of different 12v RS485 CCTV devices on the market must use line-drivers chips with a Vcc of 5v because they were historically assumed to be interfacing to TTL logic levels, and therefore still will be for compatibility.

So for integration, I think any 3.3v logic nodes will require level-matching up to a line-driver chip which has its Vcc connected to 5v for RS485 bus compatibility.

Line-driver Vcc would not normally be a problem for any home-brew systems, but could offer a potentially serious gotcha if mixing 3.3v home-brew with existing commercial 5v equipment.

I had been expecting it to be an already known problem, but apparently not, so it would seem to be something worth being aware of.


body:
I have an arduino [flexbot](http://www.flexbot.cc/), I was making some test and accidentally I connected the battery in the opposite way. The drone turned on the six motors when I connected the battery, but any led turned on to see if the processor was working. I disconnected the battery and connected it in the wrong way again same thing happened the six motors turned on again. Then I realize that the battery was connected in a wrong way and connected it in the right way. The LED's turned on as always, and also the blue-tooth module was working I could detect the device using the control-application. I tried to fly the drone but the motors didn't turn on, I could hear little click and I saw a little movement of a motor.

I connected my drone to my PC using the micro USB connection, also I connected the battery. I tried to turn on the drone and in this way it looks to work fine.

But when I disconnect the USB port and I tried to fly it the same thing happens, the click and the little movement. Any idea of what can I do to fix this drone?

title: arduino flexbot drone connected in a wrong way

Answers: 1

body:
The motors turning on is expected because or the reverse diode in the mosfets driving the motor.

Looking at the schematic, it seems like the problem is on the 5v rail. If 5v isn't supplied by the USB port, it is provided by the LTC3200 (DC/DC converter)(U3 on the pcb). I think that's where the problem is, as that would explain why it only work when USB is connected.

To confirm this you'd have to measure the output voltage (pin1 (pin nearest to the ATMega) of U3, and see if it's 5 volt.

To fix it you should ideally replace this part. But it might also work without, if you simply connect the battery voltage directly to the 5v (i.e. jumper pins 1 and 5).


body:
I want to make a standalone programmer for Teensy-LC in **windows 8.1**.

So basically I have provided the board to a client of mine and now I want to change the program loaded into the Teensy-LC board.

But the solution available right now is to send the [Teensy Loader](https://www.pjrc.com/teensy/loader.html) and send the hex file. But the teensy LC board is packed inside a device. So reset button cannot be pressed.

Also it would be better if this code can be burned in an installer format instead of the [Teensy Loader](https://www.pjrc.com/teensy/loader.html).

Is there any way to make this work?

**EDIT**

My Teensy.exe does not have the option for program or reboot
The icons are not accessible

[![Teensy.exe][1]][1]

Does that mean my interrupts are disabled or there might be something else I am doing wrong?
My program loads on pressing the reset button but I cannot press the program button inside Teensy.exe

If I turn off the Auto Mode, all icons go grey.

[![AutoMode turned off][2]][2]

  [1]: https://i.stack.imgur.com/ZYGzx.png
  [2]: https://i.stack.imgur.com/d6vri.png

title: Use command line to upload program through hex file to Teensy-LC

Answers: 2

body:
Paul Stoffregen (Teensy creator) has released a command line version of the Teensy Loader which can be found on [his website][1]. However, this program appears to be Linux only, so unless your client has Linux, that may be a non-starter. The [source code][2] for the program is available, so you might be able to work out the logic and port it over to whatever platform you are wanting this to work on (just make sure you comply with the source code license).

All that being said, pressing the reset button is not necessary for programming. The Teensy loader should be able to trigger a reset over USB all on its own. So unless the current program on the device disables interrupts that are necessary for the USB port to function, or it was programmed with the USB port disabled (by selecting "No USB" in the USB Type menu), physically pressing the reset button isn't necessary for programming. For more details you can see this [forum post][3].

**Loading Firmware Without Pressing the Button**

When programming via Arduino, it does a lot of things for you automatically. To replicate that manually, follow these steps:

 1. Connect the Teensy to the computer via USB.
 2. Run `teensy.exe` (found in `C:\Program Files (x86)\Arduino\hardware\tools`)
 3. Click the button on the left to select the hex file to load.
 4. Go ahead and leave Auto enabled (this actually doesn't matter).
 5. Run `teensy_reboot.exe` (also found in `C:\Program Files (x86)\Arduino\hardware\tools`, this will restart the Teensy, as if you had pressed the button, and automatically start the programming process.)

  [1]: http://www.pjrc.com/teensy/loader_cli.html
  [2]: https://github.com/PaulStoffregen/teensy_loader_cli
  [3]: https://forum.pjrc.com/threads/30503-When-do-you-need-the-teensy-reset-button

body:
Sadly the accepted answer is incomplete and requires manual steps.

The reason why your "Auto" button is greyed out is that you did not execute the second executable that is required for that: "Teensy_Reboot.exe".
You find it on your disk if you have installed TeensyDuino.

First kill Teensy.exe if it is running (Important)

Then you write path and file of your Hex file into the registry:

    HKEY_CURRENT_USER\Software\PJRC\teensy\dir
    HKEY_CURRENT_USER\Software\PJRC\teensy\file

Then you start Teensy.exe

Then you start Teensy_Reboot.exe as a hidden process.

That is the solution of your problem!

It is a shame that Paul does not document his stuff.

NOTE: If you have previously loaded a sketch into the Teensy that was compiled with "USB Type: No USB" the reboot will not work and the button on the board must be pressed manually, but Teensy_Reboot.exe is still usefull because it enables the green "Auto" button in Teensy.exe.

NOTE: Teensy_Reboot.exe has a severe bug: If the Teensy.exe is not successfull because another program still had the Teensy CDC COM port open while you started Teensy.exe, the Teensy_Reboot.exe may run eternally consuming 100% CPU under some circumstances. I reported that bug in the forum of Paul but he never answered to my posting.

______________________________

**PLAN B:**

The disadvantage of using teensy_reboot.exe is that you don't know if the programming was successful or not because sadly teensy_reboot does not return any usefull exit code.

So the better option (which requires more code) is to instruct Teensy.exe directly from your program. Therefore you need a TCP connection to localhost.

You find more details in this thread:
https://forum.pjrc.com/threads/38684-How-does-Teensy-Reboot-exe-communicate?p=120443
where Paul (once again) did not answer my question.

___________________________

**PLAN C:**

You can even replace Teensy.exe with your own code.
Have a look at this project: https://github.com/Koromix/ty
Sadly this code depends on the huge QT library. Apart from that it may not work with future versions of Teensies.


body:
I'm writing some code for Arduino and I'm not sure if I'm checking the value of this character variable correctly. Can you please tell me if this is correct:

    const char* front = "front";
    const char* back = "back";

    eyeballs(front);
    eyeballs(back);

    void eyeballs(const char* frontOrBack){

    if (frontOrBack == "front") {
        digitalWrite(frontEyes, LOW);}//end if
      else if (frontOrBack == "back") {
        digitalWrite(backEyes, LOW);}//end else*/
    }

title: Check the value of character variable

Answers: 2

body:
Since you are using C strings (array of characters) instead of the C++ String class, you cannot use the == operator.

Instead, you can use the C style [strcmp][1] function, which is also part of the C++ library:

        #include <string.h>
           .
           .
           .

        if (!strcmp(frontOrBack,"front")) {
            digitalWrite(frontEyes, LOW);}//end if
        else if (!strcmp(frontOrBack,"back")) {
            digitalWrite(backEyes, LOW);}//end else*/
        }

  [1]: http://www.cplusplus.com/reference/cstring/strcmp/

body:
Another option would be an enum.

    enum
    {
       FRONT,
       BACK
    }
    .
    .
    .
       if (frontOrBack == FRONT)
       {
          // Stuff
       }
       else if (frontOrBack == BACK)
       {
          // Some other stuff
       }


body:
Hello i am trying to reverse a dc motor direction upon hitting either limit switch. but noting is working can some one point me in right direction. all example i find use stepper motors and step count.

    const int sw2 = 2;          //Up Limit switch
    const int sw3 = 3;          //Down Limit switch
    const int ic1_2 = 8;        //TA8409S IN2
    const int ic1_1 = 9;        //TA8409S IN1
    const int enable = 10;      //TA8409S Enable (motor)
    int sw2State = 0;
    int sw3State = 0;

    void setup() {
      pinMode(sw2, INPUT_PULLUP);
      pinMode(sw3, INPUT_PULLUP);
      pinMode(ic1_1, OUTPUT);
      pinMode(ic1_2, OUTPUT);
      pinMode(enable, OUTPUT);
      digitalWrite(enable, 1);
      Serial.begin(9600);
    }

    void loop() {
      tilt_up();
    }

    void tilt_up()
    {
    Serial.print("up Started\n");
      digitalWrite(ic1_1, LOW);
      digitalWrite(ic1_2, HIGH);
      sw2State = digitalRead(sw2);
      if (digitalRead(sw2State == LOW)) {
        tilt_down();
        Serial.print("sw2 pressde\n");
      }
    }

    void tilt_down()
    {
      Serial.print("down Started\n");
      digitalWrite(ic1_1, HIGH);
      digitalWrite(ic1_2, LOW);
      sw3State = digitalRead(sw3);
      if (digitalRead(sw3State == LOW)) {
        tilt_up();
        Serial.print("sw3 Pressed\n");
      }
     }

title: How to properly reverse DC motor direction with 2 limit switchws

Answers: 3

body:
    void loop() {
      tilt_up();
    }

    void tilt_up()
    {
    ...
      if (digitalRead(sw2State == LOW)) {
        tilt_down();
    ...
      }
    }

    ...

    void tilt_down()
    {
    ...
      if (digitalRead(sw3State == LOW)) {
        tilt_up();
    ...
      }
     }

You are recursing here. `loop` calls `tilt_up` which eventually calls `tilt_down` which calls `tilt_up` and so on until you - rather quickly - run out of RAM.

Rewrite so that you are not doing that.

---

Also see what @MikaelPatel told you in [your other question](https://arduino.stackexchange.com/questions/19852/). You have the brackets in the wrong place.

      if (digitalRead(sw2State == LOW)) {

should be:

      if (digitalRead(sw2State) == LOW) {

body:
If you want to reverse the movement you sould remember where you are going. This, along with the brackets correction suggested by @MikaelPatel and @NickGammon, leads to this code:

    boolean moving_up = true;

    void loop() {
     if (moving_up)
      tilt_up();
     else
      tilt_down();
    }

    void tilt_up()
    {
     digitalWrite(ic1_1, LOW);
     digitalWrite(ic1_2, HIGH);
     if (digitalRead(sw2State) == LOW) {
      moving_up = false;
      Serial.println("sw2 Pressed");
      Serial.println("down Started");
     }
    }

    void tilt_down()
    {
     digitalWrite(ic1_1, HIGH);
     digitalWrite(ic1_2, LOW);
     sw3State = digitalRead(sw3);
     if (digitalRead(sw3State) == LOW) {
      moving_up = true;
      Serial.println("sw3 Pressed");
      Serial.println("up Started");
     }
    }

body:
I got it to work!!!
do not know if it is the right way ... but it works. thank you all for your input/advice. here is the new working code:

    /*

     */

    // set pin numbers:
    const int sw2 = 2;           // Down limit
    const int sw3 = 3;           // Up Limit
    const int ledPin =  13;      // Pwr L.E.D
    const int ic1_2 = 8;         // TA8409S IN2
    const int ic1_1 = 9;         // TA8409S IN1
    const int enable = 10;       // TA8409S Enable (motor)

    int sw2State = 0;            // Down Limit State
    int sw3State = 0;            // Up   Limit State

    void setup() {
      // Setting L.E.D and Motor In, Enable pins as an output:
      pinMode(ic1_1, OUTPUT);
      pinMode(ic1_2, OUTPUT);
      pinMode(enable, OUTPUT);
      pinMode(ledPin, OUTPUT);
      // Setting limit switches pins as inputs
      pinMode(sw2, INPUT_PULLUP);
      pinMode(sw3, INPUT_PULLUP);
      // Enables motor
      digitalWrite(enable, 1);
      //Starts program down
      down();
    }

    void loop() {
      // reads the state of the limit switches
      sw2State = digitalRead(sw2);
      sw3State = digitalRead(sw3);

      if (sw3State == LOW) {
        down();
      }
      if (sw2State == LOW) {
        up();
      }
    }

    void up() {
      digitalWrite(ic1_1, LOW);
      digitalWrite(ic1_2, HIGH);
    }

    void down() {
      digitalWrite(ic1_1, HIGH);
      digitalWrite(ic1_2, LOW);
    }

    void err() {
      digitalWrite(enable, LOW);
      digitalWrite(ic1_1, LOW);
      digitalWrite(ic1_2, LOW);
    }


body:
I have 2 buttons and 2 voids (blink_slow) (blink_fast).
i need to be able to press button 1 and blink-slow void will run, then press button 2  and blink fast will run. none of my code works, any idea how i can do this?

    const int btn1 1;
    const int btn2 2;
    const int led  13;

    void setup(){
    pinMode(btn1,INPUT_PULLUP);
    pinMode(btn2,INPUT_PULLUP);
    pinMode(led,OUTPUT);
    digitalWrite(led,HIGH);
    }
    void loop(){
    if(digitalRead(btn2 =LOW)){
    blink_slow();
    }
    if(digitalRead(btn3 =LOW)){
    blink_fast();
    }

    void blink_slow(){
    digitalWrite(led,LOW);
    delay(1000)
    digitalWrite(led,HIGH);
    delay(1000)
    }

    void blink_fast(){
    digitalWrite(led,LOW);
    delay(500)
    digitalWrite(led,HIGH);
    delay(500)
    }

title: How to change Void with button press

Answers: 1

body:
Start by correcting the obvious:

    const int btn1 = 2;
    const int btn2 = 3;
    const int led = 13;

    void setup()
    {
      pinMode(btn1, INPUT_PULLUP);
      pinMode(btn2, INPUT_PULLUP);
      pinMode(led, OUTPUT);
      digitalWrite(led, HIGH);
    }

    void loop()
    {
      if (digitalRead(btn2) == LOW) {
        blink_slow();
      }
      else if (digitalRead(btn3) == LOW) {
        blink_fast();
      }

    void blink_slow()
    {
      digitalWrite(led, LOW);
      delay(1000)
      digitalWrite(led, HIGH);
      delay(1000)
    }

    void blink_fast()
    {
      digitalWrite(led, LOW);
      delay(500)
      digitalWrite(led, HIGH);
      delay(500)
    }

The mistakes where 1) const variable assignment, 2) using pin 1 (TX) is a potential risk if you later what to use Serial for debugging, etc, 3) condition expression, and a lot of formatting. Open your C/C++ book and check the syntax.

Now your turn to improve this!


body:
I have ESP8266, FTD232 UART, Linux mint 17.3 OS, Arduino IDE 1.6.7,

Following are the connections:

    External Power source  ESP8266
      3.3 V                  VCC
      GND                    GND
      3.3 V                  CHPD
      3.3 V                  GPIO0

    FTD232 UART  ESP8266
        RX         TX
        TX         RX

Plus FTD232 GND and Power Source GND are connected to make sure that there is a common reference.

I open the Arduino IDE and select Generic ESP 8266 board.

Open Serial Monitor:

AT command, no response..?

I have tried lots of different things found from web, even a new ESP8266, but no response.

Can anybody provide help...?

title: ESP8266 is not responding

Answers: 2

body:
The ESP8266-01 will boot and show some boot up messages at baud rate 76800 before switching to the default configured baud rate of 9600 or 115200.

Try setting the baud rate to 76800 and reset the ESP8266 to see if you can see the boot up messages first to determine if your circuit is working. You might see something like this:
> ets Jan 8 2013,rst cause:4, boot mode:(3,7)

body:
[![enter image description here][1]][1]
1.What firmware ? AT commands do not work in nodeMcu firmware.
Usually the AT firmware work to 115200 bps.

2.If your FTD232 works at 5V, you will need resistor between Arduino TX and ESP RX. ESP8266 only works at 3.3V.

3.Try esplorer - is a very nice tool to test ESP8266:
http://esp8266.ru/esplorer/

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


body:
I need four Fast PWM signals for four different transistors.

I want to use timers 1+2 (pins 3, 11, 9, 10) so it wouldn't interfere with `delay(...)`.

I tried setting the timers to Fast PWM mode, and applied different OCRnA/OCRnB values, but nothing really worked - at most, I managed to get two good PWM signals, *one from each timer*.

How should I deal with `TCCRnA/TCCRnB, OCRnA/OCRnB` to achieve 4 parallel PWM signals?

My latest attempt:

    // Timer 1 Fast PWM setup: TOP=0x00FF, Update of OCRx at BOTTOM (0), TOV Flag Set on TOP
    pinMode(9, OUTPUT); pinMode(10, OUTPUT);
    TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM10);
    TCCR1B = _BV(WGM12) | _BV(CS11) | _BV(CS10); // Divisor 64
    // Timer 2 Fast PWM setup: TOP=0xFF, Update of OCRx at BOTTOM (0), TOV Flag Set on MAX (0xFF)
    pinMode(3, OUTPUT); pinMode(11, OUTPUT);
    TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
    TCCR2B = _BV(CS22); // Divisor 64
    // ...
    int val = 200; // Desired PWM output
    OCR1A = val;
    OCR1B = val;
    OCR2A = val;
    OCR2B = val;

title: Four Fast PWM outputs, in parallel

Answers: 1

body:
Basically, your question comes down to this:

"How to generate two PWM signals with only one timer."

(Once you've got that figured out, you could set up 6 PWM channels)

Keep in mind that there also are PWM generator IC's, if you don't want to use up all your timers, which can be usefull for other things.

IF you really want to set all outputs to toggle at the same time (based on your code example) why won't you just use one PWM signal, and drive all the 4 devices with the same signal? (Given you're not going to change it)
IF you're going to drive motors, why would you need 4 different PWM signals? It's often enough to only use one PWM signal for the right tires/tracks and one PWM signal for the left tires/tracks.

----------
**Setting the max**

Since we want to generate different PWM signals from one timer, we can't just make the timer overrun (and generate a pulse or switch polarity at that point).
We want to let the timer run to completion over and over, and only change the signal when it reaches a set value.

The datasheet tells us this:

>  The TOP value can be assigned to be the fixed value 0xFF
(MAX) or the value stored in the OCR0A Register. (328P datasheet 15.2.1 Definitions)

**Setting a limit per pin**

We want to set 2 limits on one timer, each timer has an output compare register (OCR), the action will be generated when the timer hits this value.

> The Timer/Counter (TCNT0) and Output Compare Registers (OCR0A and OCR0B) are 8-bit registers. Interrupt
request (abbreviated to Int.Req. in the figure) signals are all visible in the Timer Interrupt Flag Register (TIFR0).
All interrupts are individually masked with the Timer Interrupt Mask Register (TIMSK0). (328P datasheet 15.2.2 Registers)

**Extra info on compare**

Below you can read some extra info on the signaling.
What actually will happen, depends on how the WGM

> 15.5 Output Compare Unit
The 8-bit comparator continuously compares TCNT0 with the Output Compare Registers (OCR0A and
OCR0B). Whenever TCNT0 equals OCR0A or OCR0B, the comparator signals a match. A match will set the
Output Compare Flag (OCF0A or OCF0B) at the next timer clock cycle. If the corresponding interrupt is
enabled, the Output Compare Flag generates an Output Compare interrupt. The Output Compare Flag is
automatically cleared when the interrupt is executed. Alternatively, the flag can be cleared by software by writing
a logical one to its I/O bit location. The Waveform Generator uses the match signal to generate an output
according to operating mode set by the WGM02:0 bits and Compare Output mode (COM0x1:0) bits. The max
and bottom signals are used by the Waveform Generator for handling the special cases of the extreme values in
some modes of operation (”Modes of Operation” on page 98).

**Fast PWM**
The actual settings are different per mode/modus, but for fast PWM we have:

    Table 15-3. Compare Output Mode, Fast PWM Mode(1)
    COM0A1 COM0A0 Description
    0      0      Normal port operation, OC0A disconnected.
    0      1      WGM02 = 0: Normal Port Operation, OC0A Disconnected.
                  WGM02 = 1: Toggle OC0A on Compare Match.
    1      0      Clear OC0A on Compare Match, set OC0A at BOTTOM, (non-inverting mode).
    1      1      Set OC0A on Compare Match, clear OC0A at BOTTOM, (inverting mode).

The table tells us we need to set COM0A1 and COM0A0 to 1.

    COM0B1 COM0B0 Description
    0      0      Normal port operation, OC0B disconnected.
    0      1      Reserved
    1      0      Clear OC0B on Compare Match, set OC0B at BOTTOM, (non-inverting mode)

This table tells us we need to set COM0B1 and COM0B0 to 1.

**WGM mode**

If it's all set up, we only need to put the PWM in the right mode.

    Mode WGM02 WGM01 WGM00 Timer/Counter TOP  Update-OCRx TOV-on
    0    0     0     0     Normal        0xFF Immediate   MAX
    1    0     0     1     PWM,P-Correct 0xFF TOP         BOTTOM
    2    0     1     0     CTC           OCRA Immediate   MAX
    3    0     1     1     Fast PWM      0xFF BOTTOM      MAX

So we'll need to set WGM02 to 0 and WGM01 and WGM00 to 1, to use fast PWM.F

**Succes?**

You should now be able to change the PWM's of these pins by setting the output compare registers of these.
Getting the double PWM of the other timer ready, shouldn't be much more different.
Be sure to set the right prescaler. Though it depends on a lot of external things.


body:
What is the cheapest and best method to convert 12v(14)<->5V(3.3)? Need to connect Arduino to a car.

I need logical shifter not buck converter to connect Arduino to car 12v circuit. I would like to control electrical equipment of car by Arduino. For example, I want to connect input pin to heater, when heater is on from 12v circuit I get HIGH 12v signal which processes by Arduino, but like everyone knows, Arduino can handle only 5/3.3V. Then Arduino going to change state of equipment by connecting optocoupler/relay/transistor to  button(of elect. equip.) and will act like physical press.
P.P.S I know that more clever to hack and control by CAN bus. But not all eq. are connected to CAN bus and it`s a little bit risky but I'm working on it as well.
I'm looking for best low cost solution. I have found it on [ebay][1] . Will it work like I want? Offer DIY solutions as well.

  [1]: http://www.ebay.com/itm/Level-Shifter-Logic-Level-Converter-12-Channel-5V-to-12V-or-12V-to-5V-/251604416861?hash=item3a94cab95d:g:DUYAAOSwxH1T2d~7

title: Logic level converter 12v to 5v

Answers: 5

body: Use LM7805 linear voltage regulator to regulate to 5 v , it's all about 2-4$, you need LM chip and 2 capacitors, that's all :) and if you need 3.3 just search for linear voltage regulator

body:
What are you trying to achieve?

It's simply unclear if you want to run the Arduino on 12v of the car battery. Or if you want to control the car-windows by hooking into them? Or if you want to read out your car using the arduino.

I'll go with the later since otherwise the question would be stated a little different.

Also, you're looking for something good/cheap.
You don't tell what type of car you want to connect to.

But I think this might help you out: https://www.sparkfun.com/products/13262

25€ isn't that pricey, compared to the car you're fiddling with... So you should go with a little quality (also, you don't need them in batch?).

While a bit subjective, sparkfun could be considered a better vendor than most e-bay suppliers. Both in documentation and support. And in this case, their price isn't that bad. (I'm not affiliated with sparkfun, I actually never bought stuff of them, since e-bay works well for me. There may be hundreds of other good/better suppliers, but this one popped up first on google)

Also, "hacking" your car can have serious safety risks.

body:
Your safest option is to use an opto-isolator. Connect the LED side in parallel with the load with a suitable resistor, then the transistor side becomes, effectively, a button connected to the Arduino.

As far as the car is concerned you have just connected an LED. As far as the Arduino is concerned you have a button connecting to ground.

It provides complete isolation of the car's electrics from your Arduino.

body:
This might be what you need — a multi-channel level shifter with input and output voltage ranging from 3.3V to 18V:
https://www.ezsbc.com/index.php/featured-products-list-home-page/ls2.html#.WqmSZ2aZNGU

It's no bi-directional: you'll need a couple of boards if you want inputs and outputs from an Arduino to 12V.

body:
Ok, so... I can see your question is a bit obscure, so I'll try to cover a generic approach.

1. **Power** If you need to power the arduino, you can get a cheap car USB adapter. If you want a "solderable" solution, I'd avoid linear regulators (such as a 7805)and go with a cheap switching module. For low power applications I usually buy some modules called mini360 (for instance [here][1] is a link from aliexpress) which are cheap and ok for even some hundreds of milliamps. You FIRST turn the potentiometer to set the output voltage (checking with a multimeter) and THEN connect the arduino to it.

2. **Get status** If you need to get the status of something (e.g. whether the lamp is on or off) you have to analyse the circuit. If you have to detect if either 12V or GND are applied, you can solve the problem with a voltage divider. But if the lamp is always connected to 12V and then the GND side is he controlled one then you will always force a (small) current inside it. If this is the case, maybe an optocoupler is the best solution. If the signal is a PWM maybe you need some filtering, if it is a digital wire maybe it is already at the correct voltage, .... You have to figure out what is the best solution for you

3. **Set status** If you need to control something (e.g. turn on a light) your best bet is to use a 5V relay. There are plenty of them, even modules with the transistor and diode necessary to control them with an arduino.

Here are some ideas and rough schematics for the three points
<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

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

<!-- End schematic -->

Just one **very big** WARNING: you have to carefully double check that the modification does not blow something up (for instance, you can make a short circuit if the body computer tryes to force a wire to 12V and you close the relay to ground). So... Be very careful, since what you do can break a lot of things, and if you are very lucky the bill can be *only* some couple of thousand dollars (I'll let you figure out what happens if you are not lucky enough)

  [1]: https://www.aliexpress.com/item/1pcs-Mini360-DC-DC-Buck-Converter-Step-Down-Module-4-75V-23V-to-1V-17V-17x11x3/32835208399.html?spm=2114.search0104.3.9.372623d0lCPKb6&ws_ab_test=searchweb0_0,searchweb201602_1_10152_10151_10065_10344_10068_10342_10343_10340_10341_10696_10084_10083_10618_10304_10307_10302_5711211_10313_10059_10184_10534_100031_10103_10627_10626_10624_10623_10622_5722411_10621_10620_5711311,searchweb201603_12,ppcSwitch_5&algo_expid=3bf6a53d-cc3c-479b-b30a-5a108f557776-1&algo_pvid=3bf6a53d-cc3c-479b-b30a-5a108f557776&priceBeautifyAB=0


body:
I am trying to build a WiFi humidity and temperature sensor. My board is a nodeMCU using the ESP8266 connected via USB. The board is working fine with various WiFi examples and various serial examples. Hence I guest my environment is OK.

Now I am trying to connect a DHT22 to read temperature and humidity. To reduce the error sources I boiled down my code to the standard DHT example:

    // Example testing sketch for various DHT humidity/temperature sensors
    // Written by ladyada, public domain
    #include "DHT.h"
    #define DHTPIN 2
    #define DHTTYPE DHT22   // DHT 22  (AM2302)
    DHT dht(DHTPIN, DHTTYPE);

    void setup() {
      Serial.begin(9600);
      Serial.println("DHTxx test!");
      dht.begin();
    }

    void loop() {
      delay(2000);

      float h = dht.readHumidity();
      float t = dht.readTemperature();
      float f = dht.readTemperature(true);
      if (isnan(h) || isnan(t) || isnan(f)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
      }

      Serial.print("Humidity: ");
      Serial.print(h);
      Serial.print(" %\t");
      Serial.print("Temperature: ");
      Serial.print(t);
      Serial.println(" *C ");
    }

Nevertheless I always get the message "Failed to read from DHT sensor!".

Regarding the hardware I tried connecting the sensor with or without the 10k resistor, tried different DHTs and different pins. To rule out the DHTs I connected them with an Arduino Nano where these are working fine (both with and without resistor and using the same code). The only difference I see is that the Arduino is using 5V while the ESP8266 is using 3.3V - which is nonetheless inside the rating of the DHT.

Any ideas?

title: ESP8266 cannot read DHT22

Answers: 2

body:
I found, that the pin mapping printed at the board of the nodeMCU does NOT match the pin mapping in the library/software.

Check out [this issue/solution][1]. It states the correct pin mapping (e.g. pin 2 is "D4" at the board) and provides also an according workaround. My DHT22s are working now... :-)

  [1]: https://github.com/esp8266/Arduino/issues/584

body: I had been racking my brain for over 16 hours trying to figure out why this library would not work. I tested the DHT on an Arduino and it worked fine but whenever I tried on the nodeMCU it failed to read or gave spurious data. That is untill I saw the above answer that is not mentioned anywhere. The pins for the nodeMCU are not the same as the Arduino. (I thought that by defining the pin it would be using the pin stated) This is false as the library is mapped the Arduino pins so this is something to look out for, for any nodeMCU/ESP8266 beginners.


body: Using Temperation through arduino to trip off an ac device?

title: Using Temperature sensor arduino to trip off an ac device

Answers: 1

body:
Yes, there are lots and lots of project descriptions similar to yours (if I guesstimate) on the web. Google is your friend.

Here is one [link][1] to an interesting project - if you are interested in brewing beer.

Cheers!

  [1]: http://makezine.com/2014/03/28/arduino-controlled-tec-coolingheating-system-for-beer-fermentation/


body:
I'm still fairly new to the Arduino world. I got myself a kit with a clone board  couple of months ago and have successfully prototyped the project and got it to the state I want it to be. I now want to create 5 - 10 working models of what I've done.

I'd seen on Amazon that I could get 5 Nano clones for about £10 and this seemed ideal to me. Until I saw that people were complaining that some Nano's aren't quite a direct replacement for the Uno that I have working. There's some kind of problem with loading the software from the IDE.

I really don't want to do anything more than just load my software onto the Nanos "As Is" using the IDE I already have.

Can anyone recommend what I need to look out for to ensure that the Nanos I buy will work this way please?

title: Porting my project to multiple Nanos

Answers: 2

body:
> ... people were complaining that some Nano's aren't quite a direct replacement for the Uno

First, I hope you have understood that the Nano and Uno have totally different board formats. The Uno is the classical Arduino format. And the Nano is for breadboards.

Second, (and this will have to be a guess in lack of info or reference in your question) the Nano USB hardware on clones may differ and require another device driver. There might be other component selections to reduce the cost such as alternative a crystal for the oscillator, protection fuse, etc.

Cheers!

body:
The Arduino Uno and Arduino Nano are fairly compatible.

**Problems:**

 - The board layout isn't the same, Nano's won't wield a classic "shield".
 - Nano's don't have a barrel jack.
 - Nano's (usually) have a micro USB connector. While the Uno has another one.

 - But, Nano's are smaller, withouth leaving out the USB connection.

**But wait!**

Microcontrollers of the same family are quite scaleable, Nano and Uno might even have the same micro on it! Be sure your Nano has the same Atmega328(P?) chip as your Uno.
Check if the pins you're using, are accessible on the Nano. Then you should be fine.

There is a little problem with cheap Arduino Nano's, I've bought 2, from 2 different vendors. They we're about 3$.

 - The first one featured a counterfeit FTDI chip. By installing the latest FTDI drivers, my FTDI actually got bricked. I had to undo this by using M_PROG or some EEPROM flashing tool to unbrick the chip, and install older drivers (which didn't corrupt it).
 - The second one featured an CH340G usb-serial chip. I had to download and install the drivers from a chinese website. But Windows wouldn't install unsinged drivers that easily. You have to go into advanced boot options mode and allow installing unsigned drivers.

Getting these Nano's working took me an reasonable amount of time. But they now are working quite well :)
It's something to take into account when buying cheap.

I wouldn't really bother for the alternative crystal, as long as they're 16Mhz. For time-critical behaviour, I wouldn't rely too much on your crystal.


body:
I have made a sumobot with an arduino, an afmotor shield and a 4-pin ping sensor when I upload my code it keeps giving me this error: "'Servo' does not name a type" here is my code.

```
#include <AFMotor.h>
#include <NewPing.h>
#include <Servo.h>

#define TRIGGER_PIN  A0  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     A2  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

 //speed variables for the left and right motor
int Lspeed = 180;
int Rspeed = 255;

//declaring the left and right motors and attaching them to
//their corresponding connector on the motor shield
Servo leftMotor;
Servo rightMotor;

void setup() {
  Serial.begin(115200);
  //sets initial speed
  leftMotor.setSpeed(Lspeed);
  rightMotor.setSpeed(Rspeed);
}

void loop() {
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  unsigned int CM = uS / US_ROUNDTRIP_CM;

  if (CM < 15 && CM > 0) {
    int iteration = 0;
    while( iteration == 0){
      leftMotor.run(FORWARD);
      rightMotor.run(BACKWARD);
      iteration = 1;
    }
    delay(600);
  }

  //starts motors going forward
  leftMotor.run(FORWARD);
  rightMotor.run(FORWARD);

  Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");
}
```

  [1]: http://codepen.io/jsmason/pen/EPQbyX

title: afmotor saying "servo does not name a type"

Answers: 1

body:
You are creating `Servo` objects instead of `AF_DCMotor` objects. Change this:

    Servo leftMotor;
    Servo rightMotor;

to this:

    AF_DCMotor leftMotor(1);   // Change these numbers to the correct motor numbers
    AF_DCMotor rightMotor(2);  // you are using on the shield


body:
I need a command line implementation for uploading code to Teensy-LC through Windows 8.1 operating system
I know Paul has not released support for command line for Teensy-LC yet but i would like to know if any work has been done by anybody else in this regard.

I asked [this](https://arduino.stackexchange.com/questions/19844/use-command-line-to-upload-program-through-hex-file-to-teensy-lc) and [this](https://arduino.stackexchange.com/questions/18679/is-it-possible-to-create-a-standalone-exe-which-can-burn-the-code-into-a-teensy). But all these solutions include
> sending the hex file to the user.
>
>Asking him to open Teensy.exe
>
> Asking him to upload the hex file into Teensy.ex
>
> Asking him to run teensy_reboot.exe

So is it possible to create an installer of a sort for this purpose which eliminates the user performing all these operations separately and a guided installer simply with Next->Next which does the entire job.

But I suppose that since Command Line installer is not available for windows I don't know if this is possible for impossible.

So if there is any way I can achieve an installer UI for Teensy-LC bootloader that would be perfect

**Other viable option**
If not that is it possible to make the entire process happen with the person not having direct access to the hex file.
Like sending a packaged installer or something
I am not sure how this would happen but if there is any possible way please help me out

title: Use command line to upload hex code to teensy.ex

Answers: 1

body:
This is starting to drift off topic for this site, but the best solution for making an automated programming utility for the Teensy on Windows, short of writing one yourself, would be to use some kind of UI automation framework to automate the process described in [my earlier answer][1]. My favorite one that I have used in the past is [AutoIt][2]. It has tools to inspect applications so that you can programmatically click buttons and fill out fields. There are even ways of having it run programs without them being visible to the user. There are plenty of tutorials on the web on how to use AutoIt so I would suggest googling for that. If you have further questions on how to do that, they would be more appropriate on a site other than Arduino.SE.

  [1]: https://arduino.stackexchange.com/a/19845/11086
  [2]: https://www.autoitscript.com/site/autoit/


body:
When one selects a board within Arduino IDE, a preprocessor definition is added to one of the behind-the-scenes files.

After a lot of hunting and some good fortune I found that the format of this definition is:

    #define ARDUINO_<PROCESSOR-DESCRIPTOR>_<BOARDNAME>

Some are easy to guess (`ARDUINO_AVR_UNO`, for example), but others are less so. The Pro Micro has '16' or '8' appended to the definition depending on the speed. I do not know if the definition is different for 5V or 3.3V. I haven't managed to guess the definition for the Mega2560, but it isn't anything obvious.

**Question 1**: Is there a list in existence of the possible definitions?

**Question 2**: Is there any distinction, as far as compilation and preprocessor involvement is concerned, between _BoardX_-5V and _BoardX_-3.3V, and how is this distinction defined?

title: List of Arduino board preprocessor #defines

Answers: 3

body:
The first blank is the *platform*. This is "AVR" for AVRs, "SAM" for SAM-based Arduinos, etc. This is derived from the platform directory containing the core.

The second blank is the *board*. This comes from the entry in `boards.txt` in the core itself, and is the identifier before the first period.

There is no difference between compilation processes with regards to voltages; any speed difference is given in `F_CPU` and the board itself should not be checked for this.

So there is no definitive list, since the list is of arbitrary size due to its source.

body:
The list of board symbols can be generated by this shell command:

    $ grep board= boards.txt | cut -f2 -d= | sort -u
    AVR_ADK
    AVR_BT
    AVR_DUEMILANOVE
    AVR_ESPLORA
    AVR_ETHERNET
    AVR_FIO
    AVR_GEMMA
    AVR_LEONARDO
    AVR_LILYPAD
    AVR_LILYPAD_USB
    AVR_MEGA
    AVR_MEGA2560
    AVR_MICRO
    AVR_MINI
    AVR_NANO
    AVR_NG
    AVR_PRO
    AVR_ROBOT_CONTROL
    AVR_ROBOT_MOTOR
    AVR_UNO
    AVR_YUN

The boards are defined by the "build.board" property in the [boards.txt][1] file.

    mini.build.board=AVR_MINI

This property is used by the build [recipe][2] together with ARDUINO_-prefix.

    -DARDUINO_{build.board}

Cheers!

  [1]: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/boards.txt
  [2]: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/platform.txt#L52

body:
Mikael has the right answer, but there are multiple boards.txt files depending on the installed boards with board manager,
modifying the command to:

    grep board= `find . -name boards.txt` | cut -f2 -d= | sort -u
and running it from your base Arduino directory collects the whole set.


body:
i'm trying to create a display that notifies me when someone goes live on twitch. I need to acess the API and check if the 'stream' object is null or not. Then, perform an action depending on this.

The address to the API is http://api.twitch.tv/kraken/streams/pedrinholuizf

What can I do? I'm using an Arduino Leonardo with the Ethernet Shield.

title: Read information from Twitch's API and execute actions depending on the output

Answers: 1

body:
Break your problem into small steps and try to identify the success criteria for each step. So you might:

1. Try to set up the Ethernet shield and get it to respond to a ping on your local network.
1. Try to connect to a site outside of your network.
1. See if you can find some examples of using the Twitch API.
1. Try to replicate one of the simple examples.
1. See if you can get the Stream object that you want.
1. See if you can read the value of the object.

If you have a plan and try to follow it you'll be able to tell us what you've been doing and where you got stuck / confused. That is likely to get you better answers – both because we can be more specific and also because we can see that you're "carrying your weight" as we work on the problem.


body:
Whenever I compile irrecvdemo of or remote library it gives error saying that fatal error saying

> no file or directory exists `#include <WProgram.h>`

    #include <IRremote.h>

    int RECV_PIN = 11;

    IRrecv irrecv(RECV_PIN);

    decode_results results;

    void setup()
    {
      Serial.begin(9600);
      irrecv.enableIRIn(); // Start the receiver
    }

    void loop() {
      if (irrecv.decode(&results)) {
        Serial.println(results.value, HEX);
        irrecv.resume(); // Receive the next value
      }
    }

title: Irrecvdemo program in or remote library gives fatal error #include<WProgram.h>

Answers: 1

body:
You are using a very old library on a modern IDE.  The file that was called `WProgram.h` in IDE version 0023 and below is now called `Arduino.h`.  You will need to change any references to `WProgram.h` to `Arduino.h` instead.

Well written libraries do this with a #ifdef block:

    #if (ARDUINO >= 100)
    # include <Arduino.h>
    #else
    # include <WProgram.h>
    #endif


body:
I have an Arduino and I am building a space satellite, just for fun. I'm not going to launch it obviously.

I have built all the sensors and everything works. I was looking into communication because if a satellite is in space it needs to send down the data.

Is it possible to have radio communication between two Arduino or an Arduino and something else that are 100km apart, it doesn't need to particle, I'm just wondering if it is possible and how it works. Is it possible without going out to buy shields?

title: Arduino radio communications

Answers: 2

body:
There are three basic factors that control long distance communication:

1. Transmitter Power
2. Receiver Sensitivity
3. Signal Directionality

The more transmission power you have the "louder" your signal is at the receiver.

The more sensitive your receiver the "quieter" the signals it can pick up.

The more directional (focussed) your signal is the more arrives at the receiver and the less gets sent off elsewhere.

So you would think get all three of those and you're laughing, but it's not that simple:

* High power transmission requires high-power power source
* Good focus requires heavy and bulky antennae.

Neither of those are very good on a satellite, since you want it to be as small and light as possible and use as little power as possible.

So in general you have a medium to low power transmitter on the satellite with *reasonable* directionality, and put all the bulk on earth.  That is why satellite dishes are so big.  They give good focus, and the large size captures a lot of the signal making them more sensitive. You can also use very precise electronics to amplify the signal more.

There is, of course, nothing like that in a shield format, so you would have to create your own. The transmitter isn't so hard, since you don't want to have anything too meaty - the hard part comes when you want to make the base station.  If you can afford enough power to transmit a strong enough signal and have it with enough directionality you can use a satellite TV dish (not a little Sky dish, one of the bigger solid round ones - Sky satellites actually have quite powerful transmitters and the massive solar panels to go with it; not really practical for a small home-built satellite).  Getting the receiver and LNB (Low Noise Booster) tuned properly as well is vital - unless you're transmitting at the same frequency as the satellite the dish is intended to receive (which you mustn't or there'll be a lot of annoyed people around - there are specific frequency ranges you are allowed to use) then you will need to ensure the antenna is exactly the right length and that the LNB amplifies and filters the right frequency range.

Once you have got over all those hurdles the receiver is just a simple receiver.

The actual transmitter and receiver circuits themselves can be something fairly off-the-shelf (the lower the frequency the better since that goes further than higher frequencies) - it's what goes between - the antenna and amplifier - that makes it much more special and long range.

body:
Majenko covered several aspects of radio communications between a satellite and a ground station.  An additional factor to consider is that the [azimuth or altitude](https://en.wikipedia.org/wiki/Horizontal_coordinate_system) of a low-altitude satellite changes rapidly as it passes over a ground station.  For example, a satellite 100 km up takes about 86 minutes per orbit and travels at about 7.84 Km/s, and probably would be in view for less than a minute per pass.  [See eg *[Orbit of a satellite Calculator](http://keisan.casio.com/exec/system/1224665242)* at casio.com.]  Unless a phased array is used, and assuming communication is highly directional, the big dish on the ground will need to swing at up to 4.5° per second (about 270° per minute) as it tracks the satellite passing over.  The much smaller antenna on the spacecraft should rotate at the same rate, the opposite direction.

Note, an alternative to radio communications is a tight-beam laser system.  Rather than using big, bulky microwave or UHF antennas to achieve directionality, you would use a small telescope (a few cm of aperture) on the satellite and a larger telescope (as much aperture as you can afford) at the ground station.  Infrared or visible light lasers at each end of the link would be modulated to transmit at a high data rate.  Accurate tracking and aiming might end up being important research projects for this approach.


body:
I have a Arduino Pro Mini 3.3V connected to a sim800l chip using a serial connection of 9600bps. When I connect the Arduino to the device, it seems I don't receive anything on the Arduino Rx pin.

I then connected a FTDI that listen the sim800l Tx pin:

[![enter image description here][3]][3]

The FTDI is able to receive data so this means the sim800l is working well by receiving data from the Arduino and responding accordingly.

So normal logic would say that the Arduino Rx pin is not working but when I connect the Arduino Rx and Tx pin together:

[![enter image description here][2]][2]

I'm able to receive what I send on Tx on the Rx pin.
Why would that be?

I tried with AltSoftSerial and SoftwareSerial. The Arduino is powered by a FTDI connected to my computer via USB. The sim800l is powered by a second FTDI that is also powered by my computer USB. So all component uses the same ground and I verified that with my multi-meter.

Here is the code I use:
<!-- language-all: lang-cpp -->

    AltSoftSerial sim800Serial(8,9); // RX, TX

    void setup()
    {
      Serial.begin(9600);
      sim800Serial.begin(9600);
      void loop()
    {

    while(1)
    {
      if(sim800Serial.available())
      {
        Serial.write(sim800Serial.read());
      }

      if(Serial.available())
      {
        sim800Serial.write(Serial.read());
      }
    }

  [1]: https://i.stack.imgur.com/pVXBm.png
  [2]: https://i.stack.imgur.com/XAWDk.png
  [3]: https://i.stack.imgur.com/yqzfn.png

title: Why the serial connection only work when Tx and Rx are shorted?

Answers: 0


body:
Over the years, I have acquired many TinkerKit modules for my Arduino Uno. My only issue is that I need to find a way to code using the native syntax, and not the less-powerful TinkerKit variation. To do this, I need to know if TinkerKit maps its 3-pin connector to the Arduino Board's pins (ex: 1, 3, 5). If it does, what are the mappings?

Thanks in advance!

title: Converting TinkerKit to native Arduino pins

Answers: 1

body:
The [TinkerKit Sensor Shield][1] helps understand the mapping. There is also the [TinkerKit Header File][2] with symbol mapping.

  [1]: https://store.arduino.cc/product/T020010
  [2]: https://github.com/TinkerKit/TinkerKit/blob/master/TinkerKit.h