text:
Analog Reference and Power Voltage
On the Arduino website it states that the analog pins read voltages from 0 to 5 volts (default) and return a value from 0 to 1023. One can also set the range with analogReference(). However, this is probably assuming the Arduino is running at 5 volts. If one powers the board with, say 4 volts, will the analog reference still be 5 volts default, or changed to the input voltage of 4 volts?

A reading of 1023 will mean 4V if the board is powered using 4V. 1023 means supply voltage, which is not necessarily 5V.

Your suspicions are correct. Calling analogReference() with a value of DEFAULT sets the ADC reference to the voltage at AVCC which at least on the Uno R3 is tied directly to VCC and hence has the same voltage as whatever you're supplying there.

There is code published that shows how to read the internal voltage, I use that to correct my A/D readings. It is not perfect but close. You can of course select a lower reference voltage by changing the appropriate registers and use a different reference. This is much safer then supplying an external reference.


text:
Finding arduino bootloader version?
I have problem with WDT reset. After reset the device goes on for a boot loop. from the following link https://code.google.com/p/arduino/issues/detail?id=181
It has been mentioned that there is problem with Bootloader because some of them does not support wdt properly.How can i find which version of bootloader is running in my arduino mega 2560 . Which version of bootloader support wdt properly? where these bootloaders can be found?

In all practicality; put a known boot loader on it. Because if it is a problem version you will need to replace it anyways.
The Mega uses STK500 protocol. Which only shows a command to read its type (or signature) and not its version of firmware.
It is a good exercise, but not really worth the time to go deeper into it, as programmers are cheap and or you can use another Arduino as the programmer.

The watchdog timer will reset the Arduino in case of a timeout. The way to prevent this from happening is to catch the WDT interrupt.
ISR(WDT_vect)
{
  // do nothing
}

This has nothing to do with the bootloader. The fix suggested in the link above only makes the bootloader detect a reset triggered by a WDT event, and have it not add any delay. This delay is normally needed to see if the usb-host is trying to upload a new program.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Using an Arduino for learning embedded C programming
I'm a computer systems engineering student and was planning to buy an Arduino to learn embedded C programming. After researching I found mention that an Arduino may not be a good choice for a beginner that wants to learn about programming embedded systems using C.
I'm not sure if that is true, can an Arduino be programmed in C without using C++ and the other included class libraries? I'd prefer to learn how to program things at a fairly low level and not rely on libraries that hide details of the underlying hardware. Can the Arduino be used as a general AVR / microcontroller development platform to learn embedded C programming?

Well my programming and electronics skills are quite good (i'm third year student Computer system engineering) got good knowledge in computer architecture, but no experience in embedded systems.So i want to do projects which would teach me about them and how to code for them.

The format of ee.se is more like a wiki than a forum. The aim is to develop a set of good, specific, questions, which can have fact or evidence based answers. So the usual approach is to update the question with extra information in response to comments. Unfortunately, your question still seems vague, and hence answers would be based on opinion, which is a poor fit to ee.se. Questions of the form, "I want to make an XYZ, my experience is ..., I plan to use an Arduino and an ABC, I have researched the web, found http... and http... however, I still need help with ..." is a better fit.

I had a bit of a problem following the title at first, but by "Type-C" do you mean something that can run C code for learning embedded systems? If so let me know and I might be able to edit the question into something more answerable.

yeah , it's for c language

Yes, an Arduino can be programmed in ordinary C - use of the IDE and the quasi-C++ libraries is entirely optional, one is free to treat the hardware as an ATmega development board and use avr-gcc (or similar) directly, using either the arduino style (optiboot or whatever) bootloader or some other method (ISP, etc) to load the results into the chip.

Seconding Chris Stratton's comment, noting also that the avr-gcc compiler allows you to specify the input-language.

The Arduino is a great place to start embedded C programming. You can use both C and CPP. There are tons of tutorials online and there are a bunch of books available. In addition there are lots of libraries available on GIT HUB for interfacing with all types of hardware like RF24 Wireless Transceivers.
If you want to go into more low level programming, you can. For example, you can set all Port B pins to Output:
// the setup routine runs once when you press reset:
void setup() {

  // initialize the digital pins as an output.
  DDRB = 0xff;
}

[Not sure who's listening, as this is a 4 year old question posted by someone who no longer seems to have an account here, but... ]

... can an Arduino be programmed in C
  without using C++ and the other included class libraries?

You absolutely can use either C or C++, and make use of class libraries or write your own functions for either or both of computing tasks and managing your external hardware.

Can the
  Arduino be used as a general AVR / microcontroller development
  platform to learn embedded C programming?

Yes, for the reasons above, and more. Embedded systems differ from other computing systems by having deadlines the must meet. These can be soft deadlines (try to keep visible delays to a minimum so you don't annoy the user/operator) or hard deadlines (if you miss one, something could fail or someone might die). They come in different scales: my home thermostat could be capably run by an Attiny "with one pin tied behind its back". :) Other systems might contain many large-scale chips or a mix of both, networked internally to one another. A mid-scale example of this is an automobile engine controller. It runs your signals, entertainment system, ABS brakes and traction control, and more, all while opening and closing injector valves and firing spark plugs with precise timings, at up to 125 times per second. And that is for a pretty normal, family-car, "street" engine.
The Atmega328p (Uno's MCU) is sufficiently over-engineered to tolerate occasional misuse, being over-clocked or supplied a lower than spec'd voltage, has several ways to update/replace its program, is easy to hand-build into a custom micro-controller board, and after all that abuse, is cheap enough to replace if you do manage to damage one.
Documentation is readily available as are online communities like this one, to help with beginners questions, unusual questions, esoteric uses that maybe only a handful of people have tried or know about.
So, tl;dr: yes, I'd call it an ideal platform for everything you asked about.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Newbie has difficulty compiling unedited svn Arduino code that should work
I'm having some trouble getting this arduino code to compile. It's not my project, but it should compile totally fine. Having never worked with the Arduino before, these errors are a bit intimidating, but I'll try to be specific enough for someone to get a guess. So...
I have this directory with these files:  .
I found that the ArduCAM_OSD.ino has the loop and setup functions. When I try to compile the ino and solution I get these errors:
In file included from ArduCam_Max7456.cpp:4:

ArduCam_Max7456.h:78: error: expected class-name before '{' token

ArduCam_Max7456.h:84: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:84: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:87: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:91: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:91: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:98: error: 'size_t' does not name a type

ArduCam_Max7456.h:99: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:100: error: 'BetterStream' has not been declared

ArduCam_Max7456.h:102: error: 'uint8_t' does not name a type

ArduCam_Max7456.cpp: In member function 'void OSD::init()':

ArduCam_Max7456.cpp:38: error: 'video_mode' was not declared in this scope

ArduCam_Max7456.cpp: In member function 'void OSD::setMode(int)':

ArduCam_Max7456.cpp:109: error: 'video_mode' was not declared in this scope

ArduCam_Max7456.cpp:110: error: 'video_center' was not declared in this scope

ArduCam_Max7456.cpp: In member function 'int OSD::getMode()':

ArduCam_Max7456.cpp:123: error: 'video_mode' was not declared in this scope

ArduCam_Max7456.cpp: In member function 'int OSD::getCenter()':

ArduCam_Max7456.cpp:138: error: 'video_center' was not declared in this scope

ArduCam_Max7456.cpp: At global scope:

ArduCam_Max7456.cpp:162: error: prototype for 'void OSD::setPanel(uint8_t, uint8_t)' does
not match any in class 'OSD'

ArduCam_Max7456.h:84: error: candidate is: void OSD::setPanel(int, int)

ArduCam_Max7456.cpp: In member function 'void OSD::openPanel()':

ArduCam_Max7456.cpp:177: error: 'row' was not declared in this scope

ArduCam_Max7456.cpp:177: error: 'col' was not declared in this scope

ArduCam_Max7456.cpp: In member function 'void OSD::closePanel()':

ArduCam_Max7456.cpp:206: error: 'row' was not declared in this scope

ArduCam_Max7456.cpp: At global scope:

ArduCam_Max7456.cpp:212: error: prototype for 'void OSD::openSingle(uint8_t, uint8_t)' does
not match any in class 'OSD'

ArduCam_Max7456.h:91: error: candidate is: void OSD::openSingle(int, int)

ArduCam_Max7456.cpp:236: error: no 'size_t OSD::write(uint8_t)' member function declared in
class 'OSD'

ArduCam_Max7456.cpp:251: error: prototype for 'void OSD::control(uint8_t)' does not match
any in class 'OSD'

ArduCam_Max7456.h:87: error: candidate is: void OSD::control(int)

ArduCam_Max7456.cpp:268: error: prototype for 'void OSD::write_NVM(int, uint8_t*)' does not
match any in class 'OSD'

ArduCam_Max7456.h:99: error: candidate is: void OSD::write_NVM(int, int*)

The most notable of these is the first error. Here's the class, in a header file, throwing the error:
class OSD: public BetterStream
{
  public:
    OSD(void);
    void init(void);
    void clear(void);
    void plug(void);
    void setPanel(uint8_t start_col, uint8_t start_row);
    void openPanel(void);
    void closePanel(void);
    void control(uint8_t ctrl);
    void detectMode(void);
    void setMode(int mode);
    void setBrightness();
    void openSingle(uint8_t x, uint8_t y);
    int getMode(void);
    int getCenter(void);
    virtual int     available(void);
    virtual int     read(void);
    virtual int     peek(void);
    virtual void    flush(void);
    virtual size_t write(uint8_t c);
    void write_NVM(int font_count, uint8_t *character_bitmap);
    using BetterStream::write;
  private:
    uint8_t start_col, start_row, col, row, video_mode, video_center;
};

Now, since I know confidently that this should compile, I'm convinced that I've made some
small syntactical error that can be fixed easily. In case anyone needs to see more of the files, you can access them all on the google code page here. Alternatively, please feel free to ask any questions.

Is it your own code? I guess you have not properly imported the complete project. This is just a class. where are other files? the main? Or may be you have not properly installed the compiler of this IDE. Which IDE is this?

is it your complete class? you have not included  ´BetterStream` and you are inheriting it.

add #include before the class definition

@Mahmood I'm using Arduino IDE 1.0.5-r2 . It's not my own code. All of the code is at the link at the bottom,  though I'll look for a main. I believe I was told to look for setup and loop to determine the ino to compile, which is in ArduCAM_OSD.ino .

add #include"BetterStream" if it works. tell me

@Mahmood adding "#include "BetterStream.h" did work to get rid of all those errors after I went and found a copy of BetterStream.h. Thanks!

@Mahmood I only have one more error. One of my include statements is failing, even though the file is indeed in the same directory. Another file is referenced the same exact way, yet it can't see this one particular file.

which file? name the file I will see

#include "menu.h"
#include "c++.h"
In file included from AP_Common.cpp:16:
/AP_Common.h:38:35: error: c++.h: No such file or directory
What's weird is that menu.h and c++.h exist in the same location, yet menu is included fine.

I guess you are missing some files in the library of your installation of IDE. Because these files seems to be libraries. Does you ide works perfectly? Is it your first program you are testing? try something other working one.

@Mahmood I found that the issue was that I wasn't using the IDE to include all the libraries so it wasn't seeing any of the references. After including all of the relevant libraries I finally got it to compile. Thanks so much!

This is really ambitious for a first project. Do yourself a favor and go through the basic tutorials before you start frying components. Learning how to include libraries properly is something you will pick up if you go through the basics. Arduino isn't "safe" - it's easy to fry the Arduino and easy to melt components too.

It sounds like you are missing the libraries that the project was build for. BetterStream was part of the library system of the Ardu projects at diydrones.com
Normally for Ardu projects they use a modified version (their own) of the Arduino IDE but I don't know if the Arducam project works the same way.
I think you will find a better answer over in the support forum as http://www.diydrones.com which is where Arducam comes from.
Some of the source files look like they replace libraries so it might be that you just need a different core from diyd


text:
What is the use of ISP and ICSP in Arduino?
I am trying to connect gsm module with my arduino uno. confused about the use of isp and icsp

What GSM module are you using?  And what is the cause of the confusion?

i hav a module of sim900a and someone advised me to connect it to ard uno using isp or spi. now i m having queries like can we program using isp? why cant i use spi or i2c? how are they different? xcept i2c which uses uart, right?

ISP/ICSP has no role when utilizing a typical, properly functioning Arduino, as the program code compiled from sketches is instead downloaded via a bootloader (either serial, often behind an on-board USB-serial converter, or else directly USB).
The role of ISP in the Arduino ecosystem is mostly limited to:

Loading a bootloader into new chips which do not have one, or have somehow lost theirs (note however that you can buy pre-loaded ATmega328's from many sources at a small premium)
As an alternative program loading scheme when the tiny amount of program memory used by the bootloader must be re-claimed for a particularly large sketch
Programing alternate targets to which the Arduino libraries have been partially ported, especially resource-constrained ones where the bootloader takes up a larger fraction of the total memory, such as the the ATtiny25/45/85
Replacing or modifying the firmware of an on-board USB-serial micro such as the 16u2 on an Uno to perform a different function, such as emulate a keyboard or mouse.  However, this chip can also be programmed over its USB interface in DFU mode.
Programming other non-Arduino devices used in a project (though these often have a different ISP scheme than the ATmega series).

But a typical project using purchased board(s) will involve none of these.

SPI vs. ISP
As jfpoilpret points out, a very popular way of interfacing chips to a microcontroller is the Serial Peripheral Inteface, or SPI.  Like ISP, this is a synchronous (has a distinct clock line) serial interface with a master and a slave, a mode or enable pin, and a distinct data line in each direction.  Some Arduinos use MCUs like the ATmega328p which re-use their SPI pins for ISP (with the reset functioning as the mode pin).
In effect, ISP is a sort of special "SPI-like" interface mode for programming an ATmega - often using the master-mode SPI engine of the programer to do the actual transfers.  But "ISP" applies only when programming an ATmega - the more generic case of communicating with a peripheral would be "SPI".
It's my impression that most GSM modules use asynchronous serial interfaces (ie, utilizing a UART engine), but there may be some which use SPI or other synchronous schemes, at least as an option.

Don't you forget the thousands of devices using the ISP bus as the only way to communicate with them (just like I2C). That makes a common use for ISP in Arduino projects! Although I admit that you don't have to use the 2x3 header for it as you can find MOSI, MISO... on other pins as well, but you could.

@jfpoilpret - no, that is SPI, not ISP.  The ATmega328p happens to use the same pins for both, and they are indeed quite similar - we might consider ISP to almost be a special case of SPI.  But SPI is not a case of ISP.

Damn! How could I make this mistake? Of course you are right! Sorry for the confusion.

point 5 of roles, using that can i program at89c51 or other mcu?

That would depend on the scheme used by the MCU in question.  The at89c51 uses a parallel programming scheme, rather than a serial one.  You probably could build a programmer with an arduino, but would have to look into details such as if you would need an I/O multiplexer to drive all the lines, and if you need a transistor to enable a 12v programming supply, or if you have the version of the chip which programs at 5v.


text:
Problem uploading to Arduino Yun
I have an Arduino Yun. I am trying to upload the code in Arduino but after I click on Upload, I get the error message shown in the image.
At first it showed the Arduino Yun under the port tab, after this message no Arduino is showing in port tab.

The portion of the error visible in the image:

Couldn't find a Board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload.

It's very hard to read that error, perhaps you could crop it a bit? It's also useful to include the message as text so that it's searchable for anyone else with the same problem in the future.

In the Arduino IDE, click on Tools (on the menu bar). Then, open the submenu Board and make sure "YUN" is selected.

Seems like you havent chose the appropriate serial port.
Under tools, you'll also find serial port - make sure the appropiate one is selected.


text:
What does the line "while (! Serial);" do in an Arduino program?
I'm new to Arduino, and I am trying a couple of tutorials. What does this line do in a program?
while (! Serial);

On boards with an FT232 chip or other USB->Serial bridge chip (Uno, Mega, etc) it does absolutely nothing.
On boards with a direct USB connection, such as the Leonardo or the Yùn it waits for an active serial connection to be established by the PC (i.e., for the serial port to be opened by a piece of software).
When you open the serial port of a board like the Uno or Mega the whole board usually resets*, so opening the serial port allows you to see the first bits of the serial data.  On the Leonardo etc it doesn't reset when you open the serial, so any serial output during the setup() function would be missed.  Adding that line makes the board pause until you open the serial port, so you get to see that initial bit of data.
*) Unless you specifically write some software that doesn't assert DTR when you open the port

Strictly "When you open the serial port of a board like the Uno or Mega the whole board resets," is not correct. The Arduino's IDE does that by default. However, simply opening the serial port from the USB host PC does not reset the ATmega. I've written code that opens a serial connection over USB from the host, and it doesn't reset the ATmega.

Actually, it is both OS and driver dependant, not just down to the software that does the port opening.

The arduino resets when it gets the DTR signal. It is transmitted by default whenever I open a connection from anywhere, not just arduino's IDE.

In some OSses it's possible to open the serial without asserting DTR. In others it's possible to configure a port to not assert DTR when opened, but only after it's been opened once. By default, as mentioned, the IDE always explicitly asserts DTR.

I believe it is possible to open an FTDI SUB/Serial without asserting DTR on Windows, OS X, and Linux, because I've done it. It is optional. So please update the answer, either say that when the IDE opens the serial port the board is reset, or that opening the serial monitor resets it, or that opening the serial port usually resets the board. I don't mind which is chosen. However the current answer is not accurate.

@BrettM - which OS?

On Linux you have to open the port first in order to set the port to not assert DTR. That first opening will always reset the board regardless.

Note that if that line is in your sketch, you are using a 32u4 or M0 or similar chip with built-in USB support, and you are trying to run without being connected to a host via USB, your sketch will hang forever waiting for Serial to be ready. This is a common problem: "Sketch runs when connected to PC, but not when unconnected".


text:
Using timers on an Arduino Mega 2560
I'm an amateur and I wish to use timers in my project. I'm using an Arduino Mega 2560 with a touch-sensitive screen with six  DS18B20 temperature sensors and a DS1307 RTC (real time clock). I would like to query my sensors every 1 or 2 minutes to refresh the screen for temperature acquisition. I do not how to program timers to schedule the readings and which timers to use?

You can use the function millis(), that returns the number of milliseconds since the Arduino board began running the current program (unsigned long). This number will overflow (go back to zero), after approximately 50 days.
The code below uses the millis() function, a command that returns the number of milliseconds since the Arduino board started running its current program, to blink an LED.
/* Blink without Delay

 Turns on and off a light emitting diode(LED) connected to a digital
 pin, without using the delay() function.  This means that other code
 can run at the same time without being interrupted by the LED code.

 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.

 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
 */

// constants won't change. Used here to
// set pin numbers:
const int ledPin =  13;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

Source: http://arduino.cc/en/Tutorial/BlinkWithoutDelay

This solution is the way to go. Timers aren't really useful in this case. Also don't worry about the 50 day overflow. Since you are calculating the time difference, this will never become a problem (unless you want to check the temperature every 60days or so).

You can use the watchdog timer for that. Below is part of the code that I use to make temperature readings every 8 seconds using the watchdog timer. It compiles on Arduino IDE 1.0.5 for Arduino Uno R3 board, but be warned that I didn't run it as it is below (so it's untested). You can change variables COUNTER_TRIGGER and WATCHDOG_PARAM to adjust its timing it to your liking. Note also that I'm using ATmega328P, so map it accordingly to your MCU.
#include <avr/sleep.h>
#include <avr/power.h>

#define WDTCR_REG WDTCSR
#define SERIAL_DEBUG

int COUNTER_TRIGGER = 1; // 1 * 8 sec = 8 seconds
int WATCHDOG_PARAM = 9; // 9 = 8 sec
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms, 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec

volatile long watchdog_counter = 0;
int counter_trigger = COUNTER_TRIGGER;

const byte TEMP_PIN = A5;

void setup() {
  #ifdef SERIAL_DEBUG
  Serial.begin(9600);
  #endif

  pinMode(TEMP_PIN, INPUT);

  //Power down various bits of hardware to lower power usage
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();

  // ADCSRA &= ~(1<<ADEN); //Disable ADC
  ACSR = (1<<ACD); //Disable the analog comparator
  DIDR0 = 0x3F; //Disable digital input buffers on all ADC0-ADC5 pins

  sei();
  setup_watchdog(WATCHDOG_PARAM);
}

void loop() {
  #ifdef SERIAL_DEBUG
  Serial.print("Sleeping...");
  Serial.flush();
  delay(20);
  #endif

  sleep_mode();

  #ifdef SERIAL_DEBUG
  Serial.println("awake");
  #endif
  // Zzzz...

  #ifdef SERIAL_DEBUG
  Serial.print("watchdog_counter = ");
  Serial.println(watchdog_counter);
  Serial.print("counter_trigger = ");
  Serial.println(counter_trigger);
  #endif

  if (watchdog_counter >= counter_trigger) {
    watchdog_counter = 0;
    doSomething();
  }
}

void doSomething() {
  // do your thing here
}

// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms, 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii) {
  byte bb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<WDCE);
  ww=bb;

  MCUSR &= ~(1<<WDRF);
  // start timed sequence
  WDTCR_REG |= (1<<WDCE) | (1<<WDE);
  // set new watchdog timeout value
  WDTCR_REG = bb;
  WDTCR_REG |= _BV(WDIE);
}

// executed when watchdog timer expires
ISR(WDT_vect) {
  watchdog_counter++; // increment volatile
}

I don't remember where I got it. I'll add proper attribution when I find out who provided the code... soon.
I hope this helps.

Thank you for sharing your knowledge. I am going to make tries.


text:
Arduino if else code
I have made this If-Then-Else code, but it doesn't work.
First I tough only the analog code is wrong, but if I take a digital port, the code doesn't work either.
What did I do wrong?
int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0.00001;  // variable to

void setup() {
  pinMode(13, OUTPUT);  //LED BORD UIT
  pinMode(12, OUTPUT);  //LED4
  pinMode(11, OUTPUT);  //LED3
  pinMode(10, OUTPUT);  //LED2
  pinMode(9, OUTPUT);   //LED1
  pinMode(8, OUTPUT);   //Elektro Magneet
  pinMode(A0, INPUT);
}

void loop() {
  if (A0 == HIGH) {
     digitalWrite(13, LOW);
     digitalWrite(12, HIGH);   //LED on, magnet off
     digitalWrite(11, HIGH);
     digitalWrite(10, HIGH);
     digitalWrite(9, HIGH);
     digitalWrite(8, LOW);

  } else {
     digitalWrite(13, LOW);
     digitalWrite(12, LOW);   // LED Off, magnet on
     digitalWrite(11, LOW);
     digitalWrite(10, LOW);
     digitalWrite(9, LOW);
     digitalWrite(8, HIGH);
  }
}

Sidenote: Be careful with that electro magnet. Those tend to use quite a bit of current, while the digital pins of the arduino can only source a maximum of 40mA. You don't want to "blow up" you Arduino.

To add to what @Gerben said, you'll want to keep current around and under 20mA on any I/O pin and under 100mA on the MCU. Beyond lighting a few LEDs, you'll have to use transistors, darlingtons and relays.

Replace the line:
  if (A0 == HIGH) {

by this one:
  if (digitalRead(A0) == HIGH) {

If you plan on using the pin back as an analog input, use something like this:
  if (analogRead(A0) > 512) {

The explanation is what Ignacio said: you were comparing the pin "name" A0 directly to HIGH instead of reading from the input named A0. To make it clearer, the two lines are equivalent:
if (A0 == HIGH)
if (0 == HIGH)

Get it?
There's more about what pin names to use with digitalRead() and analogRead() here:

analogRead(0) or analogRead(A0) at EE.SE.

You're comparing the pin variable value with HIGH. If you want to get the value at a digital input then you need to use digitalRead().

You have defined your pin as
int sensorPin = A0;

Which should be replaced with
#define sensorPin = A0

And then in your code, you need to read the value from  the pin in your if statement:
 if (digitalRead(sensorPin) == HIGH) {


text:
Sainsmart LCD 2004 - LiquidCrytal_I2C library issue unable to compile
I bought a Sainsmart LCD2004 from Amazon to use with my Arduino Uno.
I understand that since this LCD uses I2C a new library needs to be downloaded.
From the sainsmart website I dowloaded the LCD 2004 rar
http://www.sainsmart.com/arduino/arduino-shields/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html
When I try to compile the example titled helloworld I get the following error:
In file included from HelloWorld.pde:3:
C:\Users\r_yob_000\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:81: error: conflicting return type specified for 'virtual void LiquidCrystal_I2C::write(uint8_t)'
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'
There seems to be a conflict between two functions returning different types.
I've tried searching the issue and found a lot of posts with similar errors.
The solution suggested is usually that a new version of the LiquidCrytal_I2C needs to downloaded. Or that one should use Arduino IDE version 1.0
I have downloaded tons of LiquidCrytal_I2C libraries and tried them all on IDE version 1.0 and 1.0.6 and I still get the same error message. I've even tried changing the LiquidCrytal_I2C.h file so that it returns the correct type and still have no luck.
Could I please get some help with this issue.
Thank you very much.

I just bought 3 of these that work well with this library
 LiquidCrystal_I2C2004V1.zip
(License: CC BY-NC 2012 http://www.wikispaces.com/user/view/TerryKing).
When installing this library in Arduino IDE (version 1.6 or later), use menu item Sketch | Include Library | Add .ZIP Library..., navigate to the folder where LiquidCrystal_I2C2004V1.zip was downloaded, and then open the zip file.
Use the I2C address in the example "HelloWorld" supplied with LiquidCrystal_I2C2004V1:
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Hello, world!");
  lcd.setCursor(2,1);
  lcd.print("Ywrobot Arduino!");
   lcd.setCursor(0,2);
  lcd.print("Arduino LCM IIC 2004");
   lcd.setCursor(2,3);
  lcd.print("Power By Ec-yuan!");
}

void loop()
{
}

Do not change the other library directory name; this one is compatible with the existing library. Just add it as a contributed library.

should have been "Import library" menu extract the zipfile with.

Welcome to "Arduino Stackexchange" you can actually edit your answer using the "edit" button under your answer.

Extra paragraph consolidated into answer as suggested by MarkU. Thanks!

I had problems with this library too, until I realized the default library name "LiquidCrystal" conflicts with that of another library, which makes that the files get mixed up. Simply place the files in a different folder (I named mine) "LiquidCrystal_4x20". Solved it for me.

You must to upgrade your I2C library.
Here you can find it the last version:
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/
And move the old one in another folder so you can  use this one
or after you install this one do like this:

Go in the Arduino\libraries\Newliquidcrystal_1.3.5\
Rename the LiquidCrystal_I2C.h  like LiquidCrystal_I2Ca.h
When you use it in the sketch use include LiquidCrystal_I2Ca.h


text:
Arduino Leonardo is not recognized by usb cable in Windows 8
My Arduino Leonardo was working properly but for the last two hours when I connect it to a PC via a USB cable, it is reporting something like USB is not recognized and even in device manager it is not showing. However, when I press the restart button on the Arduino, the PC will detect it as an Arduino Leonardo bootloader(com 7) but after few seconds it disappears. What do I have to do? I tried to restart the PC, changed USB cable but the same issue occurs. I checked the USB by connecting another device - it works fine but the Arduino is not recognised.
I tried other PCs also but the same problem continued. What do I have to do?

It is highly likely that the sketch you loaded is causing this.

However, when I press the restart button on the Arduino, the PC will detect it as an Arduino Leonardo bootloader(com 7) but after few seconds it disappears.

For a few seconds after reset the bootloader will configure the board as a USB serial device, awaiting upload of a new sketch. Once that times out it runs the existing code. If the existing code does not configure the USB port (eg. by doing Serial.begin) then it will cease to enumerate as a USB device. This is perfectly normal.
The "fix" is to upload a sketch that uses the USB interface. For example, open a serial port, open the keyboard (Keyboard.begin()) or similar.

Nick Gammon's solution worked for me. I am adding the arduino code I used below.
While Arduino Leonardo is connected to your computer, press its reset button. A COM for Arduino Leonardo appears under the Arduino IDE: Tools > Port:
You should upload the code within a few seconds just after you press the reset button while the Leonardo COM is appearing.
The following is the code I used:
// Start of Code

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  digitalWrite(13,HIGH);
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if(digitalRead(2)==LOW){
    //Send the message
    Keyboard.print("Hello!");
  }
  delay(1000);
  digitalWrite(13,HIGH);
  delay(1000);
  digitalWrite(13,LOW);
}

// End of Code

It is more reliable the other way around: Start the upload process and wait for the "PORTS ..." lines to appear (in the Arduino log window at the bottom of the screen). Only then press the "RESET" button.

It could be the settings of the serial port (you mentioned com 7). Try going on your Arduino Integrated Development Environment.
Go to Tools > Serial Port > (and try putting this setting on different serial ports)
If the Serial Port is grayed out and you cant press it, try restarting the Arduino with the restart button, and hopefully you will have an opportunity to change the Serial Port in those few seconds that the Arduino is recognized. Try all the different Serial Ports your computer has.


text:
Arduino Uno PWM
My scheme is very basic: I use RGB LED with Arduino Uno. 5v is connected to anode, and pins 9-11 are connected to cathodes.
When using following sketch, my LED is producing white colour, which red, green and blue components are on:
int redPin = 9;
int greenPin = 10;
int bluePin = 11;

void setup(){}

void loop(){
  analogWrite(redPin, 0);
  analogWrite(greenPin, 0);
  analogWrite(bluePin, 0);
}

But when I refer to docs for PWM:
A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on)

When I write 0 to all pins, I expect led to be off. What am I missing?

With your LEDs connected to +5V (AKA "Common Anode"), the PWM signal is reversed.

When the output is "on", the voltage on the pin is 5v.
When the output is "off", the voltage on the pin is 0V.

The difference in voltage between +5V and the pin for those two different states is:

"On" = 5V - 5V = 0V
"Off" = 5V - 0V = 5V

So you can see than when the output is off the LED will on because it causes a difference in voltage from one side of the LED to the other, so current can flow.  When the output is on the voltages either side of the LED are the same, so no current will flow.

Since you've connected to the cathodes the pins are sinking current. As such the LEDS are active low with 0 being almost fully on and 255 being fully off.

Your LEDs are connected to the supply voltage. The output must be low to allow the LED to shine.
Output 0 ==> LED on

I guess this is very basic, but I don't get why.

When you set the pin value to 0 you are making that pin act as ground. Since the LED had a single anode that receives 5V. When the difference between the anode and cathode is high (Anode - 5V & Cathode - 0V) the LED turns on. When the difference between the anode and cathode is low (Anode - 5V & Cathode - 5V) the LED is off. The larger the difference between the two the brighter the LED. In your code use analogWrite(redPin, ~0); then everything should work. Change 0 above to whatever value you want, less than 255, and it should work. Also do the same for the green and plus pins too.

Note that PWM doesn't influence voltage, it just creates pulses.


text:
Is my TFT screen defective?
I bought the standard 1.77" TFT screen months ago and It has never worked. I follow the wiring diagram shown for Uno on the guide on the Arduino website and the best result I have ever got is it seeming like the screen itself is broken. I must have rewired the whole thing many times now and quadruple checked each time.
As I have never used this screen before I do not know what is correct any further than the tutorial.

I say that because it seems to understand instructions but does not display them correctly.
I have tried multiple examples and tests on it that all yield weird results.
The tests I have tried are:

The SD demo that loads the Arduino icon off SD and fills the screen
with it. The serial connection says that it has successfully read the
image but just displays black lines
Setting the background colour with random colours which seems to work fine apart from the black bars
Drawing random colour, positioned and sized rectangles. Result is image below. Colours seems to prefer pink, purple and white.

As you can see it looks like the image is 1D, no rectangles stop across the x axis so I did a test for that, it just draws a 1x1 pixel red dot going down the screen's left side, if it drew a red line moving down then my thought that it was stretching the first column would be correct, it didn't, just white and black bars still, so I modified it to test every column in case it wasn't column 0, same result...weirdly only when I made the 1x1px rectangle 5x5 my idea was correct.

As you can see on both the images, the black bars are a persistent factor, their colour cannot be changed and they appear once TFT.begin has been called.
After looking around the only help I could find is someone mentioned that Arduino the company updated the TFT library but not the software but he/she didn't provide a download link. In the time I've had this I'm sure I'm redownloaded/updated the Arduino software a few times too.
Are the glitches normal for wrong pin connections? Is there some pin wrong on the website?

A wrong library is not likely to cause that, it sure looks broken to me.

Maybe post a photo of your wiring... the screen output isn't real helpful.

@Jasmine TLDR? That's the last thing I thought I'd hear with how how much information I put in. I did say I'm sure the wiring is correct but I'll upload a picture anyway.

It's good information, but the screen shots don't give any clue to the problem other than "it's not right" and the wiring for these isn't super simple, and I have seen similar displays with wrong wiring, but it also seems your data is getting through. So, I want to check the wiring before stating the screen is broken with any real certainty.

@Jasmine Added wiring.

It's pretty hard to see the wiring for sure in the photo, but you have an extra red wire looped from one side to the other, what is that for? It's not in the tutorial. Other than that, your wiring looks ok to me, as far as I can see from the photo. So probably it's broken, I hope you can return it.

The extra red wire is for the backlight. Unfortunately I was so determined to test it in so many way by so many people it took too long so I highly doubt anyone would allow a return after months.

OH! You have a simple solution then. Buy another one and use it right away. If the same thing happens, your wiring is wrong and you have two good boards. If the new one works, you know this one is bad.

I am having the exact same problem as you! I am using an Arduino Mega 2560 instead but having exactly the same results as you on the screen.

@AkashPednekar Ooh! That makes things interesting, Either this screen is delicate or theres something wrong in the tutorial. How long have you had yours? Are you sure you haven't applied current to a pin when its not powered?

There are multiple versions of this display, requiring different commands.

I ran into the same problem, looked around the net a bit.
Someone found a solution from the Italian forums translated + posted how to help this.
In short there was something wrong with the TFT library
https://forums.adafruit.com/viewtopic.php?f=25&t=45289#p228908
I installed the nightly build, currently 1.6.0 and the screen is working now.

Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.


text:
arduino nano V3 updated schematics
Does anybody know where to find an updated scematics of Arduino Nano V3? All the Nano drawings I found (even in the Arduino official site) are based on ATMEGA 168 , no one including ATMEGA 328!!!
Thanks
Mike

http://arduino.cc/en/uploads/Main/ArduinoNano30Schematic.pdf

@RogerRowland - The OP is trying to find schematic that shows with an ATMEGA 328 as opposed to the ATMEGA 168 which he stated right in his question.

@MichaelKaras Ahh, sorry, misunderstood and just looked at the V3 bit.

Use the Nano schematic as a reference, and replace the 168 with the 328 from the UNO schematic. The only thing that would change is which pins you're connected to. If you're building this yourself, I'd also steal the hardware reset functionality from the UNO

I think the developers just were lazy, and didn't bother changing the 168 with a 328 in the schematic. Since the pinouts are identical, it doesn't really matter.

the nanov3 zip file is corrupt

this link work:  http://www.electronics-lab.com/make-your-own-arduino-nano-diy-arduino-nano/fswsje2iz6bvkj2/

Go for the manufacturer of this board website i.e. www.gravitech.us. You can get the eagle files and all the data you need. Alternatively, you can download the eagle file of nanov3 directly using this link: http://site.gravitech.us/Arduino/NANO30/ArduinoNano30_Eagle.zip

Also IIRC there's a ground connection that was inadvertently left off the FTDI chip in the published schematics that should be reconnected.

The real issue is that the question is based on an insignificant distinction - no board changes are involved in using a 328p in place of a 168.


text:
Why does Arduino use USB A-B plug, instead of A to micro USB plug?
I understand that A-B plug used to be common but they could have switched to micro without issues.
My questions:

Why does Arduino use USB A-B plug, instead of A to micro USB plug?
What are the challenged Arduino would be facing if they switched to micro USB?

Note:
By "Arduino" I'm referring to Arduino models that do not come with a micro USB port such as the most common Uno & Mega.

Are you talking about any particular Arduino?

Arduino leonardo has a micro USB. What is your question?

Just a legacy thing. Micro usb didn't even exist until april 2007.

UNO was first released in 2010 I think.

Obviously I'm referring to Arduino models that do NOT come with a micro USB here. But I will edit nonetheless. Thanks.

Please note that this answer is based on speculation and some common sense rather than on insider information:
If you take look at the hardware index, you'll notice that significant parts of the layout (drill holes, pin spacing, and position and type of the USB jack) haven't changed between the Arduino Extreme and the current Arduino UNO R3), while other improvements have been made. For changes between the UNO R2 and R3, please see Arduino UNO FAQ at adafruit (link provided by jfpoilpret).
It is thus reasonable to me that keeping the USB jack was a deliberate design decision: Improve if possible, but keep the layout changes to a minimum and allow for maximum backwards compaptibility.
But again, this is just the guess of a user!

I am not sure, even including your comment, that it would consitute a serious answer to the question, it looks more like a lead to follow and check.

Then you should improve your answer by changing the question into something like "It is probably for backward compatibility between UNO revisions". You could even refer to https://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduino-uno-faq#uno-r2-and-r3 which mentions backward comaptibility albeit it does not explicitly mention USB socket compatibility. Merry Christmas to you too!

That makes absolute sense @KlausWarzecha, thanks! And thank you as well jfpoilpret !

Durability is also a factor. The big standard USB-B is a lot more durable than Micro-USB. Though in practice it probably doesn't make such a huge difference, you don't connect/disconnect your Arduino THAT often.
But I guess its one of the components that could die first, if you don't built a bad circuit with your UNO, the connector could indeed die first after years and years of usage.


text:
arduino wifi shield not present error
I'm using an HLK-RM04 WIFI shield and arduino uno R3 board. whenever I mount my shield on the uno board and connect it to the pc using a usb only the power led(red) of my wifi shield glows. I tried to upload the example code on wifi(provided by arduino)but whenever I run the code it shows "wifi shield not present". Looking into the previous discussions on this website I even tried to connect my arduino with usb+9v supply. In that case my trackpad of the laptop ceases to work. whenever I power my system(arduino+shield) using a 9v external supply all the 3 leds(power,link,wan led) on my wifi shield glow but still the same error of "wifi shield not present" persists.
What is going wrong?
Has anyone configured an HLK-rm04 wifi shield with uno r3 before?
Thanks

unfortunately i gave up using hlk-rm04 wifi module for my application.
it was too power hungry and there was very little online help available.

I DON'T have experience with the shield you are mentioning, but it sounds to me that no data is being sent from the WiFi shield to the Arduino.  I suggest you do a bit of debugging with:
1) Print Statements
2) A multimeter (better yet, an oscilloscope)
3) Check that the pins you are connecting the shield to are not blown

Welcome to Arduino SE! Can you expand your post a bit to explain how to use these to debug the problem of the OP? To me, it doesn't seem like these would fix a computer error, but feel free to elaborate on how this would help. Thanks!

Might be because of a non-compatible version of the Arduino IDE? (latest version isn't always the fittest, apparently).
I found evidence for this weird behavior in various forums around the web - even when using the Uno R3 board with its official WiFi shield, I had to go back to version 1.0.3 of the Arduino IDE (and to flush its compatible firmware version for the WiFi shield) in order to get the sample code to work. Later versions just didn't work!

Welcome to Arduino SE! Do you have any evidence that this works for wifi shields? If so, can you please edit your post? Thanks!

Yes I do have, but I couldn't comment in the original post :(

Ok, if you have evidence, can you please edit your post? Thanks.

Is it ok now? :)


text:
Powering Arduino from a shield
I'm designing a shield for Arduino which drives two stepper motors. They are small and require 5V but their max combined current is around 1A, way too much for the USB supply. Therefore I will have external 5V power supply connected to my shield.
The entire device will usually operate being connected to a PC through USB, but still I'd like to have a possibility to run it separately.
The question is: how to power Arduino itself?

From my external PSU through the pins: Sounds as the simplest solution but I'm bit worried about the onboard regulator of Arduino while reverse powered.
Separate power circuits for electronics and motor: My L293D chips allow for separate power and even different voltage for the motors. It could even be an advantage for my shield, as I could use other motors and different power for them in the future. I will, however, lose the possibility of running the device without USB connection.
Same as above with additional barrel jack power connection to supply Arduino when USB is disconnected. This, however, could fail with 5V supply, because of the voltage drop of the regulator which handles power coming from barrel jack.

Option 1 is by far the simplest. Just have one 5V power supply for everything.  Make sure you have enough capacitance on there to absorb the noise of the motors - maybe separate the digital side from the drive side with an inductor.
You can add a diode connected backwards between the 5V and VIN pins to bypass the regulator when reverse powered.  That is, anode to 5V and cathode to VIN.

What I am doing for similar is powering 7.2v to motorshield EXT_PWR and same to RAW pin of Arduino mini pro, where taking 5v out from vcc and input to motor shield 5v. It works for my car well.


text:
Serial Connection to Phone Line
I was hoping to create a cheap security system by connecting an Arduino to the phone line output of a base station.
Since the base station should call a phone number if the alarm is tripped I wouldn't have to do much hardware hacking so long as I can read/parse the output from the base station.
My question is can I read serial output from a phone line like this?

Serial connection over a phone line is done using a "modem" - you can probably still find an RS232 external one on a surplus site for which you will need a serial level shifter (with implicit inversion).  You may also be able to find a new module for embedded use, perhaps even one with logic level serial. Most sophisticated enough to use the AT command set can dial.

These days you can find TTL modems, removing the need to deal with RS-232.

Phone lines run off of the RS-232 telecommunications protocol which can run off -25v to 25v, which would completely destroy your Arduino. Luckily there is an IC made to help you with that. You can use the MAX3232 IC to convert RS-232 to TTL 5v or 3.3v (Same chip can do either). Look at providers like Digikey for just the chip or you can get a breakout from providers like SparkFun.
TL;DR Yes, but you need a special IC to not fry your Arduino.


text:
Arduino power consumption issues
I'm working on an Arduino project involving an UNO.
I'm powering a 20x4 LCD screen and I am using all the ports on the Arduino, to the last.
All but four of them are pulled high at any given time, so by the time I'm done with pulling them all up the screen is going dim when powering via USB.
So I tried powering via an external 9V 600mA adapter, but that makes the Arduino overheat and eventually shut down.
I then tried another, 12V 500mA adapter, and that one doesn't even get my UNO to the end of the setup function, and it reboots repeatedly.
Anyone got good advice? Ideas?

Stop trying to burn out the MCU.

It's worth adding a schematic / daigram of what's connected. It sounds like you're trying to draw too much current from the outputs, normally an LCD shouldn't draw much current unless you're also using the backlight?

Use a 5V usb power supply, which allows you to bypass the voltage regulator, which is overheating.

Maybe an inadvertent short path somewhere - this should not happen. Schematic and/or photos helpful.

Is it a 0.6 mA or A? That's a huge difference! If it's 0.6 mA that's not nearly enough to power an Arduino with a LCD. I assume that's a typo.

The official arduino uno schematic uses a NPC1117 voltage regulator. This is a linear one. This means that if you put 12V on it, and if your system requises 0.5A, you Will leak 0.5A on the 12V, and, if there is 5V on the output, 12V on the input, there is a 7V drop on the regulator, 7V * 0.5A = 3.5W that turns into heat.
To avoid overheating, the solution isn't to increase the input voltage, but to decrease it. If you have a 6.2V power supply, this will minimize overheating. At least 6.2V are required for the NPC1117 to provide a stable 5V.
An other option is to use a USB 5V power supply with an output current greater than 0.5A. This is often used with smartphones. This allows to bypass the NPC1117, but the power supply shall be exactly 5V (where exactly stands for less than 10% of over or undervoltage).
Also, please note:

Arduino does not recommend bypass[ing the] Vin supply to directly supply 5V rail on the board as it will damage the NPC1117. See the first two line on page # 3 from the document link below. http://media.digikey.com/pdf/Data%20Sheets/Arduino%20PDFs/ArduinoEthernet.pdf
  You can either do the soldering and remove NPC1117 chip before you apply 5V directly onto the board or find a higher current capability power supply with the output voltage between 7v-12V.

Go with Jacen's second option. If you need any decent power, it's much better to skip the regulator on the arduino and just send it 5 volts directly, and since there are tons of USB power supplies out there, it's easy to find one.


text:
Arduino RBBB - Device not accepting address
I recently purchases and make a Arduino RBBB with a BUB II from Modern Device. I ordered the package found HERE. I built everything according to the instructions, but when I connect it to my laptop (running Ubuntu 14.10), I get the following in dmesg
[63415.213391] usb 3-1: new full-speed USB device number 63 using xhci_hcd
[63415.381403] usb 3-1: device descriptor read/64, error -71
[63415.485225] xhci_hcd 0000:00:14.0: Setup ERROR: setup context command for slot 26.
[63415.485240] usb 3-1: hub failed to enable device, error -22
[63415.597236] usb 3-1: new full-speed USB device number 64 using xhci_hcd
[63415.709154] usb 3-1: device descriptor read/64, error -71
[63415.813102] xhci_hcd 0000:00:14.0: Setup ERROR: setup context command for slot 27.
[63415.813116] usb 3-1: hub failed to enable device, error -22
[63415.925108] usb 3-1: new full-speed USB device number 65 using xhci_hcd
[63415.925270] usb 3-1: Device not responding to setup address.
[63416.129120] usb 3-1: Device not responding to setup address.
[63416.332902] usb 3-1: device not accepting address 65, error -71
[63416.444973] usb 3-1: new full-speed USB device number 66 using xhci_hcd
[63416.445174] usb 3-1: Device not responding to setup address.
[63416.649008] usb 3-1: Device not responding to setup address.
[63416.852734] usb 3-1: device not accepting address 66, error -71
[63416.852813] usb usb3-port1: unable to enumerate USB device

It is repeatable every time I insert. lsusb does not register it. I have read that I should switch out the cable, but it is brand new (and I don't have another to test with. I was wondering if there is something evidently wrong with my circuitry. I posted pictures

Have you tried another port? Another computer? Another serial adapter?

I tried another computer and switching USB ports on my laptop, same error. I don't have another BUB II, but tomorrow, I am going to go to a lab on campus to use the oscilloscope to check the BUB II I/O. I will also try another cable.

I fixed it. Here is how I did it.
First, I tried connecting just the BUB II to via the USB. Same error, thus I ruled out the Arduino RBBB as the source. I then decided that perhaps it was the voltage jumpers (black things on the pins sticking out in the first picture). After removing them, it works under dmesg, yielding the below.
[  214.044563] ftdi_sio 3-1:1.0: FTDI USB Serial Device converter detected
[  214.044687] usb 3-1: Detected FT232RL
[  214.044696] usb 3-1: Number of endpoints 2
[  214.044704] usb 3-1: Endpoint 1 MaxPacketSize 64
[  214.044712] usb 3-1: Endpoint 2 MaxPacketSize 64
[  214.044718] usb 3-1: Setting MaxPacketSize 64
[  214.045209] usb 3-1: FTDI USB Serial Device converter now attached to ttyUSB0

Thus I wanted to put them back on so I wouldn't lose them. I proceeded to try various combinations till it worked. Ultimately, I ended with 5V for VOUT and VL for LGLV. If that is a bad idea, someone please comment, but it works.
May this help someone else.

Since you fixed it, I upvoted it. It would be good to accept your own answer too, so this becomes the "accepted" answer to your issue.


text:
"void does not name a type"
Hi I'm new at this and can't figure out why I get this error "void does not name a type" on lines 3,5,8,26
// _2-5 set Debounce Button
const int BUTTON=2;
const int LED=9;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;

Void setup()
{
  pinMode (LED, OUTPUT);
  pinMode (BUTTON, INPUT);
}

boolean debounce(boolean last)

{
  boolean current = digitalRead(BUTTON);
  if (last != current)
  {
    delay(5);
    current = digitalRead(BUTTON);
  }
  return current;
}

Void loop()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledOn = !ledOn;
  }

  lastButton = currentButton;
  digitalWrite(LED, ledOn);

}

I thing the problem is not "void does not name a type", but "Void does not name a type".  Subtle difference:
Void setup()

should read:
void setup()

The same on
Void loop()

should be
void loop()

Watch those caps - C is case sensitive.


text:
74HC595N in series error
I want have 2 74HC595N shift registers in series.
I built this schematic

When I send a value to the first register, it is sent to the second one. I have same value on both. I change them (master/slave) but the result is the same.
I connected pin 9 on the first SR first with pin 14 on the second. I am using Johnny Five on Galileo Gen 1 with shiftRegister.send(25) to send the data.
What am I doing wrong because several days ago I made it and it worked?

I am very curious about the 3 leds on the right - the clock, overflow, and data/digital pin 2 should go at much too high a rate to be able to see anything. I have a very similar circuit (Arduino Uno, connected to 2x7 segment displays), so it should work.

If you had it working and it has changed, I would suggest trying a few changes to track down the issue. The schematic seems OK so assuming that all connections are sound, I would look towards proving the code. Maybe try a simple pure Arduino sketch designed for the 74HC595N and see if the results are the same. If not, the culprit is almost certainly Johnny Five.
Perhaps try this sketch which should work with your schematic (remap the I/O though to your 2,3,4 configuration). If the problem persists, throughly examine your connections because there is very little else which would prevent it from working - especially given that it did work a few days ago. Also, have you got another Leonardo to test with?
Finally, the schematic for the Arduino-only example shows a cap on the latch line - presumably for debouncing - which is missing from your schematic. I don't think you've damaged your registers but I wouldn't rule it out.


text:
Program/Read 93LC46B with an Arduino with bit-banging
I'm Tom. I'm pretty new to electronics and programming but I've been getting better. So, recently I bought a 93lC46B EEPROM from Element 14 (It was $0.28! Why not!). I've been doing some research and reading the datasheet VERY carefully. But I still can't get the EEPROM to work right. I'm using an Arduino Uno to program the chip by using the Bit-Banging method. So what I've understood is that I need to cycle the clock, then pull the CS (Chip select) to high and then cycle the clock after each bit like this:
digitalWrite(CLK, LOW);
digitalWrite(DATAIN, VALUE);
digitalWrite(CLK, High);

But so far, that method hasn't been working right. I can't seem to read or write to the device properly. I'm using this set of bits to write 1 and 2 to the first address of the ROM: 1 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 0.
Here's my code so far (Sorry in advance on how bad it is):
#define DATAOUT 11//Comes from DO on chip MISO
#define DATAIN 13 //Goes to DI on chip    MOSI
#define CLK 10
#define CS 9

int data[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int inst1[] = {1,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1,0};
int inst2[] = {1,1,0,0,0,0,0,0,0};

void setup(){
  Serial.begin(9600); //Start serial coms

  pinMode(CS, OUTPUT);
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(CLK, OUTPUT);
  digitalWrite(CS, LOW);

  //Write 12 to address 1
  digitalWrite(CS, HIGH); //Enable device
  //Write to memory
  for(int i=0;i<25;i++){
    Write(inst1[i]);
  }
  digitalWrite(CS, LOW); //Disable device
  delay(250); //TCSL Delay
  Serial.print("Memory sucessfully written\n");

  //Read memory
  digitalWrite(CS,HIGH); //Enable device
  for(int i=0;i<9;i++){
    Write(inst2[i]);
  }
  Serial.print("Read instruction written\n");
  for(int i=0;i<16;i++){
    saveBit(i);
  }
  for(int i=0;i<16;i++){
    Serial.print(data[i]+"\n");
  }
  digitalWrite(CS,LOW);
  delay(250);
  Serial.print("Read successful!\n");
}

void Write(int Bit){
  digitalWrite(CLK, LOW);
  if(Bit==0){
    digitalWrite(DATAIN, LOW);
  }
  if(Bit==1){
    digitalWrite(DATAIN, HIGH);
  }
  digitalWrite(CLK, HIGH);
  delay(1);
}

void saveBit(int outbit){
  digitalWrite(CLK, LOW);
  if(digitalRead(DATAOUT) == HIGH){
    data[outbit] = 1;
  }
  if(digitalRead(DATAOUT) == LOW){
    data[outbit] = 0;
  }
  digitalWrite(CLK, HIGH);
  delay(1);
}

void loop(){

}

Where have you connected your 93LC46's ORG pin?

@brhans This chip does not have an ORG pin. Read the data sheet before asking please.

Try access it with hardware SPI first. Mybe that can help.

I wanted the experience of running it with big-banging but I could try the SPI. I've found lots of posts for SPI.

Yet another improper migration from EESE.  The problem here is not with Arduino, but rather with lacking understanding of the peripheral's interface.  Send it back!


text:
USB BUB II - Misconnection and no longer uploads
I accidentally misconnected a USB BUB II to a Arduino RBBB (atmega 328), and it no longer uploads code. Here are the symptoms, I think the BUB II is fried. I am using Ubuntu 14.10.

Code won't upload with error ser_recv(): programmer is not responding
The RBBB board will reset is I hit the button. Evidenced by the LED flashing in port 13
Prior code runs as expected
dmesg behaves normally upon USB connection
When I short the Rx and Tx terminals of the BUB II, I can send instant reply messages via the Serial Monitor

Does this sound like the USB BUB II is broken? Or is is possible that some component on the RBBB board is fried?

Well, I asked too soon. I tend to do this.
I had to switch the board configuration to Arduino Uno and it worked


text:
Struggling with SD card read on Arduino
I'm attempting to read data from my SD card, but I have strange behavior and can't figure out why this is happening.
I'm using CardInfo from the Arduino example and am trying to read the data from my SD card.
I'm faced with two different problems, but maybe they can be related:
1:  If I format my SD card from my Mac (FAT32), if my card is still empty, the program can read my card and output the right information. But if I add data from my Mac to the SD Card, card.init never initialise, and my data are never read (because of the hidden files). If I remove those hidden files, but let only the expected files be, the program never find them, like if my card was still empty. I don't know how to handle this.
2: From my Arduino, if I feed the card from the 3.3 V output, I get the

Card type: SD2 Could not find FAT16/FAT32 partition. Make sure you've
  formatted the card

It only works on 5 V (but the card type becomes SDHC). So I've tried to feed my card with another 3.3 V/5 V supply (my Arduino is grounded to this supply as well), but this is only working on 5 V. On 3.3 V my card isn't detected. My wires to the SD card are about 15 inch. I don't know if it can affect it drastically, but this is the only 'weird' thing about this circuit. By the way I naively think my 3.3 V supply should handle that.
Here are my materials:
- Arduino Duemilanove

For the SPI wiring I'm using pin 10 for SS.
Using the Cardinfo from the Arduino library.

And SD cars is powered by 3.3v, but also the I/O is 3.3v. You'd need a logic level converter to talk to it. Giving it 5v signals might screw up the SD card and result in wrong behavior. Not sure if that's the case here though. I haven't worked with SD cards.

I recommend you get a MicroSD card breakout board from that link, or something similar. That's around $US 15.

That includes the logic level converters. That particular board is for the **micro* SD card, but similar converters could no doubt be found for an SD card. Or use that one with a micro-SD card and just get an SD converter for when you plug it into the Mac.
I personally have used the SDfat library without any problems. However since he started rewriting it, I did have some issues. I have a backup of an earlier version which might be useful if the live library doesn't work for you.
You might be best off not formatting the card, but leave it as factory formatted. That will probably be compatible with the Mac, and also the SDfat library.

First of all, use 3.3 V. You need a logic-level converter.
Then you have to understand SPI is not the main protocol used by SD cards, and that Arduino should use SDSC to be sure, as some libraries are SDSC only.
Then you may have a hardware problem (from FAT32/SDHC library for Wave and other shields):

SDHC cards have a 3.3 V bus so most Adruino shields, like the Wave Shield, use a resistor voltage divider to shift bus levels from 5 V to 3.3 V. These voltage dividers can not meet the 10 ns rise time for most SDHC cards."

Also using an external power source may solve your trouble.

Mac OS X will default to using the GPT partition table to format the card, even in FAT32. This does not work with the standard Arduino library for SD cards I've found. You must use MBR.


text:
i2c of Atmega 328 on arduino uno not working
I am using Arduino uno board with Atmega 328 for i2c.
The ic is not showing any clock signal on its SCL line on oscilloscope, The same code when used with different new atmega 328, and same code. It is showing a good clock signal on oscilloscope.
The ic whose i2c is not working can be still programmed and can be used for other purposes like serial communication , adc etc.
So, is there any way by which i can confirm and surely say that i2c of my atmega 328 is fried up. And what can be the possible methods by which it can be fried up.

I think you just did it. I mean, if you tested the new '328 in the very same board and with the same code you had the faulty one, then I think your scope shots just confirmed that the I2C is fried.

Do you have a pull-up resistor attached the I2C lines?

Are you saying you swapped the processor chip on the Uno? Or your working test is a different board altogether? What pin on the Uno are you testing with your scope? Please post your test code.

I2C (SDA-SCL) line needs to be pull up (place resistor on both to 5v input from master- the uno), it works with the arduino code for master-slave I2C (uno on master-severino on slave) using the code from arduino website (just be sure you set the address for the slave on the slave sketch (any number 1-126), it works for me that way, my pull up resistor is 10kohm, the same goes for my breadboard, if this is not doing the trick, maybe there's something wrong (I wouldn't know the answer to, just tried the i2c yesterday) update : on august5th (today) I just finished reading i2c's on atmel site, it is a complex one, there are several factors on why something is doing something on your twi comm, post your code, and maybe I have an answer


text:
How to remove Adafruit Pro Trinket bootloader flashing startup sequence
From what I understand, the Pro Trinket has "Optiboot" which allows it to detect which boot loader you are trying to use, one for USB and one for FTDI. When it's in this "bootloader state" the red LED on pin 13 buses for 10 seconds before it starts to run the program I've programmed.
Can I remove this Optiboot functionality? Would that entail permanently choosing a single boot loader/interface?
One problem I have with this is that along with the LED on 13, it causes the LED strip I have attached to pins 9, 10, 11 to blink. I would also really like to not have to wait 10 seconds to start running code.
Here's the page on Adafruit's site that talks about the bootloader[s] on the Pro Trinket.
Thanks!

If you have the source code and a programmer and the drive to dive into detail, then yes, you can presumably do that.

Have you asked on the Adafruit forums? They probably can answer better than anyone.

Only pin 13 will blink. Pins 9-11 will be floating. Maybe you should add some pull-down resistors to the FETs connected to the led strip (which is a good idea even if you do change the bootloader).

You could take the Pro Trinket bootloader source code and tweak it to your needs, burn it, and make sure you have patience and debugging skills.
From the author's (Frank Zhao) source code, it seems that this is the 10 seconds loop you are referring to, located in main.c, line #456:
if ( ((usbHasRxed != 0) && (timeout > USBBOOTLOADER_TIMEOUT)

The USBBOOTLOADER_TIMEOUT variable which is defined to 10 at the top of that file, line #70:
#define USBBOOTLOADER_TIMEOUT 10

and is progressed after 'roughly' 1 second, at line #496:
// roughly 1 second
#if (F_CPU == 12000000)
    if (t1ovf > 183) {
    #elif (F_CPU == 16000000)
    if (t1ovf > 244) {
    #endif
        t1ovf = 0;
        timeout++;
    }

Not the regular trinket. PRO trinket bootloader source code.

Just program the pro trinket using ISP. (not using the USB connector). For example by using an Arduino as a ISP-programmer.
If you are brave, you could change the bootloader to only run when the reset button was pressed, and not at power-up. I've done exactly that for the regular trinket (see my github)

I'd be careful to remove that section because these ten seconds are not only where the board detects which bootloader to use but also when it is accepting a new sketch at all. So if you'd get rid of that, you wouldn't be able to upload new sketches anymore i guess.

That's more of a comment than an actual answer. You could tweak the timing so it fits better, woulnd't be a problem. IF you can change the bootloader you should also be able to undo it (same tools/same changes). I'm not sure if the bootloader does the blinking, you could also easily disable that in the bootloader. But yeah, I would test it before shipping it to customers ;D

It is actually much simpler than the other answers suggest. There is no need to remove/overwrite the bootloader. You can just disable the bootloader by setting the appropriate fuse bit.
In order to do so, you need an ISP programmer. As you might know, you'll loose the ability to upload code though USB/FTDI. But you can restore that ability at any time, just by resetting the appropriate fuse bit to its original value.
Step 1: Connect your trinket through an ISP programmer
There is no ISP header on the trinket, but you can easily build one or just use jumper wires to connect the individual pins directly to the programmer. Pinout can be found at learn.adafruit.com. You need to connect MISO, MOSI, SCK, RST, VCC and GND.
Step 2: Determine current fuse configuration
avrdude -c usbtiny -p m328p

If you're using a different programmer than the USBTinyISP, replace usbtiny with the appropriate identifier. List possible values by specifying a bogus identifier, eg. avrdude -c foo.
Among some other things, avrdude should return a line containing the current fuse values. It should look similar to the following:

avrdude: safemode: Fuses OK (E:FD, H:D0, L:FF)

We're interested in the high fuse (H:D0). D0 indicates that the bootloader is enabled. Actually, any even number means the bootloader is enabled.
Step 3: Calculate new fuse value
We want to set the BOOTRST bit of the high fuse. It is the least significant bit of the fuse, which equals the number 1. So all we need to do is increment the value by 1.
In the example, the new fuse value is D1.
If you are unsure how to calculate the fuse value, you can use the Fuse Calculator. Choose ATMega328P as your device, enter the fuse values as reported by avrdude at the very bottom under "Current settings", then click apply. Uncheck BOOTRST in the "Manual fuse bits configuration" section, then you will see the new fuse value in the bottom section, where you entered the original value.
Step 4: Program new fuse value
avrdude -c usbtiny -p m328p -U hfuse:w:0xd1:m

Again, replace usbtiny with the identifier of your programmer. If you calculated a different value than D1, replace 0xd1 with your approriate value. However, if your original value for the high fuse was D0, then your new value is D1.
Done!