text:
Arduino powering from 9V battery
Yesterday afternoon I have left my Arduino running on a fresh Alkaline 9V battery (+ connected to Vin, - connected to GND). Today morning (16 hours later) the LCD display was no longer visible, and when I measured the volatage, I saw the battery was depleted to my surprise - its idle voltage was only 7 V.
My device is Arduino Uno with LCD 2x16 with LCD backlight and 2 DS18B20 sensors. Is it normal for such device to deplete 9V battery this quick?
I have read an answer to What are (or how do I use) the power saving options of the Arduino to extend battery life? question and I think what I see might be related to this, however I am not sure. If it is, is there some common schematics how to connect Arduino to be powered by a battery efficiently?

I'd try attaching a multimeter and measuring the current from the battery with the whole thing and with the display and sensors disconnected.   Don't try to optimize the arduino if it's something else pulling most of the power.

@bowlofred "measuring the current from the battery" - Will do, hoever I need to buy a new 9V cell first. :)

9V batteries are tiny, only around 500mAh. The LCD backlight alone will kill it within hours.

More radical approach for powersaving: 1. Using TI MSP430 board instead of Arduino; 2. Using non-linear regulator; 3. Using LCD without backlight (like in a calculator).

@bowlofred Whole thing current is 61 mA. With no backlight it is 57 mA, with no LCD and no sensors it is 56 mA.

Power consumption
The Arduino boards use a fair bit of power compared to other embedded systems with similar functionality.
There are three main factors:

The NCP1117 (datasheet) 5V linear regulator in the Arduino UNO
R3 (schematic) has a quiescent current of around 6mA.
The ATMega328P (datasheet) draws around 5mA @ 8MHz and 5V, and probably more than double that at 16MHz.
user2973: The ATMega16U2 used for USB communications also draws approximately 13mA.

LEDs and other peripherals also draw some current. In your circuit, the LCD backlight is probably drawing 4mA as well.
When dropping 9V to 5V via a linear regulator, almost half of the power is lost by the regulator due to its 4V drop. Duncan comments that this nearly doubles the quiescent power draw from 9V as well as the power needed for every mA of 5V, since 4/9ths of the power gets wasted as heat by the voltage regulator. An efficient switching regulator would put out 5V with little wasted energy, effectively reducing the current draw seen by the battery by 4/9ths.
A duracell 9V battery (datasheet) drops from 9V to 7V in around 7.5 hours with a 50mA current draw. Therefore, a rough guess is that your circuit draws around 25mA, which sounds about right based on the description of your circuit.
Note, alkaline battery life is non-linear with respect to current. For very small currents (<1mA) the life of an Alkaline approaches that of a lithium battery.
Getting current down
Here are some tips to get the current consumption down:

Regulator: Replace the regulator with one with a low quiescent current, or better yet, a switching regulator (also with low quiescent current). A switching regulator uses 'pulses' of current and some external inductor and capacitors to give a reasonable steady voltage output. It doesn't waste energy like with the voltage drop of linear regulator and efficiency in the high 90% are possible.

There are buck (step down) converters that take the battery as input, then connect directly to 5V and GND, bypassing VIN and the regulator. This one from Pololu both steps up and down, and has 0.1mA quiescent current.
Alternatively, you could use some 1.5V alkaline batteries, and a boost (step up) converter to get the voltage up to 5V (e.g. this product from Sparkfun). It seems boost converters are more commonly stocked.
Finally, you could buy a rechargeable lithium battery with charging shield. This advantage of this is not having to buy new batteries, and for a tiny bit bigger than a 9V battery the lithium one has much greater capacity. A really cool product is the seeeduino stalker waterproof kit that includes a charging circuit, battery, solar panel and other goodies.

ATMega328P: Rather than using delay for timing and spinning in loop endlessly waiting for something to happen, re-write your code so that it goes to sleep in between sensor reads, etc. There are a few low power libraries out there that use the watchdog timer for periodic wakeup from sleep which are handy. You can get the current consumption of the ATMega328P below 0.1mA during sleep.
LCD: Turn off the backlight, or even the entire LCD. Add a button to the design that the user can push to activate the LCD and have it turn off after a set amount of inactivity.
Peripherals: Most peripheral chips also have a sleep mode that drastically reduces their power consumption. Remove power LEDs and other indicators that are not necessary.
ATMegu16U2: user2973 comments It seems this chip is quite power hungry (user2973). It could be removed to save power and just use the UART instead, but that seems like overkill. There are Arduino Pro boards that are just the bare bones Arduino without the USB interface that could be used instead of the UNO.
Batteries: Other alkaline cells have much greater capacity. For example, a 1.5V AA has over 2000mAh for low currents. Using AA cells plus a boost converter can increase the time before battery replacement. Use D cells (16000mAh) and it will run for quite a while. :D

Summary
With appropriate power supply and coding you can get a reasonable amount of life out of a battery. Using the above principles, I have made an Arduino derivative board that measures a few sensors and stores the readings to an SD card every half a second. It can last for about 4 months on 2 AA batteries, so it is definetly possible to have low power and remain in the Arduino ecosystem.
The chip I used for the low power in my board is the LTC3525-3.3V. It takes an input voltage as low as 0.8V and boosts up to 3.3V and a 5V version is also available. I designed a PCB for this chip as there was no ready-made breakout, and in the datasheet there are reference designs. The main critera for choosing this chip was it still had high efficiency at very low currents. Some other converters need a small minimum current draw.
The biggest consumer of power on the board ended up being the micro SD card. It can vary between 0.1mA and 1.5mA of idle current depending on the manufacturer. I have found Verbatim and Lexar cards to consume the least amount of power. I will this EE.SE question up to date with the results of my micro SD card power consumption tests.

Good thorough answer. Note: the power consumption of the usb to serial atmega16u2 which will be very significant after solving the other issues.

@user2973 do you have an idea of what it might be? I can get the typical characteristics off the data sheet, but I didn't put it in as I don't know if the firmware has any sleeping in it. If it is just running normally it is 12mA @ 5V which is a significant draw.

@geometrikal, how do you power an Arduino with 2 AA batteries? That's only 3 volts, which is below the minimum. Is the power supply you mentioned a buck/boost supply? (Outstanding answer by the way .)

@geometrikal There's no sleeping in the firmware for the atmega16u2. So the consumption should be the typical value - 13.5 mA (max 21 mA) according to my datasheet.

@geometrikal, would you mind posting a link to one of the buck power supplies you mention, like the one from SparkFun? I just did some searching and can't find it. For long life a buck style supply seems critical, since the idle current from a conventional voltage regulator is significant.

@DuncanC I couldn't find one either, I was thinking of the boost converters. I've edited the answer with a link to a pololu one that looks promising. They are also known as step down converters.

@DuncanC: Some AVRs can run on as little as 1.8V, and the ATtiny43U has a built-in boost converter that will let it run on a single AAA.

@geometrikal, you said "...Also when dropping 9V to 5V via a linear regulator, almost of the power is lost by the regulator due to its 4V drop" Doesn't that nearly double the quiescent POWER draw from 9V as well as the power needed for every mA of 5V? (Since 4/9ths of the power gets wasted as heat by the voltage regulator.) Seems like running it off a buck converter like a TSR 1-2450 would be better

@DuncanC yes true! I'll update with your comments.

@DuncanC I have updated with your comments. If you or anyone would like to expand or add on anything, please feel free to edit the answer.

I think an Arduino Uno is not suitable for such projects. Some components on the board draw too many amps, as @geometrikal correctly points out. If you're up to a challenge, I would advise you to take your project to another level and go barebones.
Sparkfun has a good article about how to increase battery life, using an ATmega328 that you also have on your Arduino Uno:
https://www.sparkfun.com/tutorials/309
Look for ways to create a circuit with only the components that you really need, and have your microcontroller sleep as much as possible.

Another option is to look for a hardware (Arduino Clone) that has been designed for that, like this board: https://bitbucket.org/talk2/whisper-node-avr/overview
Combining such hardware with power-saving code techniques you should be able to run projects for quite long time on batteries!


text:
'crash' when using pin change interrupts
I'm noticing a crash when testing out some interrupt code for a project I'm working on.
I've returned to the example provided with the library PciManager and I'm still experiencing the same issue. There doesn't appear to be any patten to when the crash appears, and on occasion I've been playing for several minutes and not seen a crash. NOTE I had to add a file (Task.h) from the developers other project (SoftTimer) to get it to compile.
here is the code:
#include <PciManager.h>
#include <PciListenerImp.h>

#define INPUT_PIN 3

PciListenerImp listener(INPUT_PIN, onPinChange);

int i = 0;

void setup() {
  Serial.begin(9600);
  PciManager.registerListener(INPUT_PIN, &listener);
  Serial.println("Ready.");

}

void onPinChange(byte changeKind) {
  i++;
  Serial.print("pci : ");
  Serial.print(i);
  Serial.print(" : ");
  Serial.println(changeKind);
}

void loop() { }

I have a wire connected to pin 3 and 3.3v which I'm pulling out and then connecting again. Some times when disconnected it continually interrupts, I was expecting this. Sometimes it doesn't which I found strange, the crash appears to happen more in the latter case.
Here is a trace from the serial monitor
Ready.
pci : 1 : 0
pci : 2 : 1
pci : 3 : 0
pci : 4 : 1
pci : 5 : 0
pci : 6 : 1
pci : 7 : 0
pci : 8 : 1
pci : 9 : 0
pci : 10 : 1
pci : 11 : 0
pci : 12 : 1
pci : 13 : 0
pci : 14 : 1
pci : 15 : 0
pci : 16 : 1
pci : 17 : 0
pci : 18 : 1
pci : 19 : 0
pci : 20 : 1
pci :

I've run this on a shrimp and on a freeduino diecimila compatible board both resulting in the same effect.
Anyway down to question; is the issue the way I'm interrupting? i.e. not stopping the floating pin? or is it a problem with the library, or is it a fundamental problem with pin change interrupts.

Your onPinChange() function is called with interrupts disabled.
For you what it means is this function should:

last as short as possible (because NO interrupts are handled during its execution, that includes timers that are used by several Arduino core libraries)
not use Serial functions as these functions are slow and sometimes wait on interrupts (that could thus mean wait forever)

You can read further advice about these so-called Interrupt Service Routines (ISR) here and there.
If you want to trace all calls to onPinChange() then you will have to use some kind of circular buffer as a global volatile variable, which will be written into by onPinChange() and read from by loop().
Accessing that buffer from loop() should be protected against concurrent write by ISR.
Here is sample code I have just written (disclaimer, I have not checked that it compiles but I think it should work correctly) that uses such a circular buffer as described above, and ensures all shared variables accesses are protected against concurrent write by ISR:
#include <PciManager.h>
#include <PciListenerImp.h>

// Structures and function to manage circular buffer of changes
struct Change {
    int i;
    byte kind;
};

// We allow max SIZE changes in the buffer; if onPinChange() is called more often
// than loop(), then at one time the buffer will be overwritten.
const int SIZE = 100;
volatile Change changes[SIZE];
volatile int start = 0;
volatile int end = 0;

// Get the next change recorded by onPinChange()
Change* nextChange() {
    static Change change;
    Change* result = 0;
    // Disable interrupts as we are accessing variables modified by onPinChange
    cli();
    if (start != end) {
        change = changes[start];
        start = (start + 1) % SIZE;
        result = &change;
    }
    // Re-enable interrupts before leaving the function
    sei();
    return result;
}

#define INPUT_PIN 3

PciListenerImp listener(INPUT_PIN, onPinChange);

// No change necessary in setup()
void setup() {
    Serial.begin(9600);
    PciManager.registerListener(INPUT_PIN, &listener);
    Serial.println(Ready.);
}

void loop() {
    // Get the next change recorded by onPinChange (if any)
    Change* change = nextChange();
    if (change != 0) {
        // One change occurred since last time, trace it to Serial
        Serial.print("pci : ");
        Serial.print(change->i);
        Serial.print(" : ");
        Serial.println(change->kind);
    }
}

void onPinChange(byte changeKind) {
    // i does not have to be visible outside this function
    static int i = 0;
    i++;
    // Write information to the end of the circular buffer
    Change& change = changes[end];
    change.i = i;
    change.kind = changeKind;
    // Prepare for the next call (write to the next item of the buffer)
    end = (end + 1) % SIZE;
}

Using Serial.print inside the ISR did cause crashes on my latest project too. By setting the baudrate to a higher value (Serial.begin(115200)), the number of crashes was reduced to almost zero.

@Gerben, yes increasing baud rate will make crashes appear less often, but they still can appear, as 115200 bps means that one character will need ~0.1ms to be transmitted, that's 1600 clock cycles on an UNO, just for one character! Really, I always stay away from Serial in ISR, whatever baud rate I use!

Just so o understand properly it's calling onPinChange while it's executing the code in onpinchange

I'm going to include this answer even though I think there's a very little chance that it is the problem because I just wasted ten hours on a project before finding it and it's an easy check so it won't take much time either way.
On AVR chips, if you have enabled interrupts and one occurs and you don't have an ISR for it, it will call the default ISR which resets the board. You can test if this is happening by redefining the default ISR by creating a function ISR(BADISR_vect){};  I would put a serial print in there and run it again and see if it's happening. If you don't want to do serial (for obvious reasons) just toggle an LED.
I also agree it's probably a bad idea to be doing this on a floating pin. I'd use the internal pull-up resister to keep it high then connect a wire between that pin and ground to simulate a button.

I just spent the last 8 hours trying to figure this out.  Thanks for preventing me from turning that into 16 hours.

Note that disconnecting a wire on an input pin is also not going to give you the results you expect. A disconnected input pin's value will float, and you'll get a semi-random mixture of 1s and 0s. You should either connect an external pull-up/pull-down resistor, or activate the internal pull-up resistor when you configure the pin (by setting the pin to INPUT_PULLUP).
I prefer using INPUT_PULLUP, since that saves wiring an external resistor. Use INPUT_PULLUP, then wire the pin through a pushbutton switch to ground.
Then look for a high-to-low transition on the pin to signify a button press.

Right, floating inputs have undeterministic values that can change all the time; in addition, they draw more energy due to these fast changes.

As I said in the question when it bounced round all over the place it didn't crash as much; recording thousands of interrupts when it didn't bounce it was more likely to crash like after 20 in the listing provided. I know I need pull it up or down I'm just confused by the crash.

Just realised I added extra debugging in after a crash so probably made my problem worse

Don't use Serial commands in an interrupt service routine, even for debugging. It will hang your device.

source: Stack Exchange

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

authors: Филипп Цветков

sort: votes


text:
Rename device name (ch340 usb to serial) Mac OS
Can't upload sketches to Arduino Nano clone with USB to serial chip ch340.
After installing drivers and plugging in, device has the name cu/tty.wch ch341 USB=>RS232 fa130 (with spaces), but Arduino can't recognize the full name (only tty.wch).
Is it possible to rename device in Mac OS or change device identifier?
UPDATE: ch340 new driver http://www.wch.cn/downloads.php?name=pro&proid=178

Found driver that works and after installing gives proper name for device. If you have WCH ch34x chip on arduino and get error "can't open device "/dev/tty.wch" or "/dev/cu.wch" in Arduino IDE, this should help http://goo.gl/EmN4IH (Dropbox)

I was going to suggest a symbolic link (e.g. in terminal ln -s /dev/tty.arduino "/dev/tty.wch ch341 USB=>RS232 fa130" but I tried it and it didn't work. Good you found a solution.

I expect a symbolic link would work, but creating it may require admin permissions, and that complicated a name could require escaped characters.

Does this work on El Capitan? The device disappeared after upgrade.

Which version of OSX was this for?

I used a terminal command:
sudo ln -s /dev/tty.wch\ ch341\ USB\=\>RS232\ 1450 /dev/tty.USB0

where /dev/tty.wch\ ch341\ USB\=\>RS232\ 1450 is the original name not recognized by Arduino; and /dev/tty.USB0 is the new port name.

You don't have to escape the spaces, rather, put everything in double quotes.

The drawback is that after disconnecting the drive it also removes the symlink :-?

I am Antonis from codebender and we recently released drivers for the Mac.
If you want to overcome this problem, without disabling your computer's security settings, maybe I can help you with this! Codebender just released their Mac drivers package, which includes a new driver that supports the CH340G chip, on Yosemite and all other versions of OS X for Mac.
This will help you to install these drivers securely, and
all you have to do is to download and install them.
You can find more information about the drivers in the codebender blog.

Can your driver be used by the regular Arduino IDE, or does it only work with Codebender?

Loading  codebender and its drivers (ch341 driver in particular)  fixed my strange problem where only my old Arduino 1.05 IDE would work with my ch340 UNO and the the 2.0  (1.6.7) would not.  Thanks.  And it works in the browser as advertised.

Worked very well for an unrecognized clone board ! Thanks

I send email about this issue to WCH, and they change drivers to the latest version on their website, this is direct link http://www.wch.cn/downloads.php?name=pro&proid=178 (driver works and device has proper name in dev/)

Nice try. But actually the driver still creates that rotten name /dev/tty.wch ch341 USB=>RS232 fd130

Have to take back that comment. The new driver seemed to need some restart (log off/on) to activate and now creates /dev/tty.wchusbserialfd130. Cheers!

For Yosemite you seem to need to run this command in the Terminal and then restart the computer to get it to work.
sudo nvram boot-args="kext-dev-mode=1"

Can you explain what this does so us less smart people are not as scared running it.

@ChristianJuth With this command, you enable non-approved drivers to work on newer OSX versions such as Yosemite.

I was having the same problem. installed the latest drivers, I'm using yosemite, installed the Arduino IDE, and tried the board in windows 7 and it worked in windows, so board and cable are working.
In mac OS 10.10 in system report now they show as USB 2.0 Serial in arduino IDE it appears the port now (only after I used the SUDO command that sjunnesson posted) /dev/cu.wchusbserialalpha1310
so, use the sudo command if you are in yosemite

once you have installed the driver, you should be able to use it with any IDE or program
but I doubt anyone would prefer the Arduino IDE to codebender

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


text:
MAX72XX with 8 digit 7 segment display library
A while ago, I found a library for the MAX72XX that had functions for writing text to the display, but unfortunately cannot find such library now.
Which would be the best library to use for a text and number display? I'm using LedControl but it is very awkward to use.

Are you aware that it is not possible to represent all alphabetic characters with just 7 segments? That means that some characters cannot be printed or would be printed in a strange way.

Cosa library for Arduino has this text support for MAX72XX but this is not compatible with standard Arduino libraries as Cosa is a whole "framework" for Arduino: https://github.com/mikaelpatel/Cosa

You might be able to just extract the library files from Cosa  https://github.com/mikaelpatel/Cosa/tree/master/cores/cosa/Cosa/LCD/Driver
and modify them.

Try this one: http://playground.arduino.cc/Main/LedControl#CharSeg7Control

I have a library for driving the MAX7219 chip connected to a 7-segment display. It is at: https://github.com/nickgammon/MAX7219
Example of use:
#include <SPI.h>
#include <bitBangedSPI.h>
#include <MAX7219.h>

const byte chips = 1;

// 1 chip, bit banged SPI on pins 6, 7, 8
MAX7219 display (chips, 6, 7, 8);  // Chips / LOAD / DIN / CLK

void setup ()
  {
  display.begin ();
  display.sendString ("HELLO");
  }  // end of setup

void loop () { }

In operation displaying a number:

More details at: Interfacing LED displays with the MAX7219 driver

Another reply of mine with no acceptance, no upvotes, and now it has been bumped by "Community" in the hope that someone will give a better answer. Good luck with that one.

Sedition! We'll be watching you.


text:
Controlling Floppy Disk Drive with Arduino
I am having problems controlling a 3.5" Floppy Disk Drive with an Arduino Uno.
I have the floppy disk drive powered with a computer power supply that is switched on, and the Arduino powered by my computer's USB.  I have cut apart the ribbon of a 34-pin IDC connector to be able to route the pins to my Arduino.  I am able to turn the floppy disk motor on and move the read/write head back and forth, but I am never able to read any pulses from the Track-0 or Index pins.
I have pins 7, 15, 17, 19, and 25 from the floppy all grounded to my Arduino, and I have pins 8, 16, 18, 20, and 26 from the floppy connected to my arduino as output pins so I can control the drive.
I am expecting the Index to pulse when the disk motor makes a rotation, and for Track 0 to change when I am at the outside of the disk, but they are both always LOW.  Am I missing something?
Here is the spec I found for the back of the floppy disk unit
    2   /REDWC  Input Density Select
    4   n/c N/A Reserved
    6   n/c N/A Reserved
    8   /INDEX  Output Index
    10  /MOTEA  Input Motor Enable A
    12  /DRVSB  Input Drive Sel B
    14  /DRVSA  Input Drive Sel A
    16  /MOTEB  Input Motor Enable B
    18  /DIR    Input Direction
    20  /STEP   Input Step
    22  /WDATE  Input Write Data
    24  /WGATE  Input Floppy Write Enable
    26  /TRK00  Output Track 0
    28  /WPT    Output Write Protect
    30  /RDATA  Output Read Data
    32  /SIDE1  Input  Head Select
    34  /DSKCHG Output Disk Change/Ready

Here a schematic of what I have hooked up
(The breadboard in this circuit diagram represents the IDC connector that is plugged into the 3.5" floppy drive.)

Here is a photo of the IDC Connector and I labelled which wires are connected to the Arduino.

Here's the code I am running.
//constants
static const int IN = LOW;
static const int OUT = HIGH;
static const int pulseDelayTime = 6;

//pins
int indexPin = 2; //8 on the drive INDEX
int track0Pin = 3; //26 on the drive. TRACK 0
int dirPin = 6; //18 on the drive. DIRECTION
int stepPin = 7; //20 on the drive. STEP
int motorEnableBPin = 9; //16 on the drive. MOTOR ENABLE B

unsigned long motorSpinTime = 1000UL; //in ms

void setup() {

  //initial delay
  delay(3000);

  //setup serial monitor
  Serial.begin(9600);

  //setup pins.
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(motorEnableBPin, OUTPUT);
  pinMode(indexPin, INPUT);
  pinMode(track0Pin, INPUT);

  //turn the motor off initially
  digitalWrite(motorEnableBPin, HIGH);

  //print state here.
  printState("Setup done.");

  //spin the disk some.
  printState("Begin to spin motor");
  spinMotorForThisManyMs(motorSpinTime);
  spinMotorForThisManyMs(motorSpinTime);
  printState("Done spinning motor");

  //step read/write head all the way in.
  stepAllTheWayIn();

  //spin the disk some more.
  printState("Begin to spin motor");
  spinMotorForThisManyMs(motorSpinTime);
  spinMotorForThisManyMs(motorSpinTime);
  printState("Done spinning motor");

  //step read/write head all the way out.
  stepAllTheWayOut();

  //spin the disk even more.
  printState("Begin to spin motor");
  spinMotorForThisManyMs(motorSpinTime);
  spinMotorForThisManyMs(motorSpinTime);
  printState("Done spinning motor");

  //never completes.
  waitForIndex();
}

void loop() {
}

//spins the disk motor for a number of ms and prints the state
void spinMotorForThisManyMs(unsigned long msToSpin) {

  //start spinning
  digitalWrite(motorEnableBPin,LOW);

  //delay.. keep printing the state
  unsigned long maxTimeMs = millis() + msToSpin;
  while(millis() < maxTimeMs ) {
    printState("Spinning");
  }

  //stop spinning
  digitalWrite(motorEnableBPin,HIGH);
}

//step the read/write head all the way to the center
void stepAllTheWayIn() {
  for(int i=0;i<100;i++) {
    printState("Stepping In");
    stepInALittle();
  }
}

//step the read/write head all the way to the outside
void stepAllTheWayOut() {
  for(int i=0;i<100;i++) {
    printState("Stepping Out");
    stepOutALittle();
  }
}

//print the state of the index and track
void printState(const char* charPrint) {
  Serial.print(" Index:");
  Serial.print(digitalRead(indexPin));
  Serial.print(" Track:");
  Serial.print(digitalRead(track0Pin));
  Serial.print(" ");
  Serial.println(charPrint);
}

//move the head towards the outside a little
void stepOutALittle() {
  digitalWrite(dirPin,HIGH);
  stepPulse();
}

//move the head towards the center a little
void stepInALittle() {
  digitalWrite(dirPin,LOW);
  stepPulse();
}

//pulse the step pin
void stepPulse() {
  digitalWrite(stepPin,LOW);
  delay(pulseDelayTime);
  digitalWrite(stepPin,HIGH);
}

//waits for the index to trigger. this never gets completed.
void waitForIndex() {

  printState("beginning to wait for index pin to pulse");

  //start spinning
  digitalWrite(motorEnableBPin,LOW);

  //wait for pulse
  while(digitalRead(indexPin));
  //wait for end of pulse 0
  while(!digitalRead(indexPin));

  printState("end of waiting for index pin to pulse");

  //stop spinning
  digitalWrite(motorEnableBPin,HIGH);
}

Here is the output I am getting.
 Index:0 Track:0 Setup done.
 Index:0 Track:0 Begin to spin motor
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Done spinning motor
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Begin to spin motor
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Done spinning motor
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Begin to spin motor
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Done spinning motor
 Index:0 Track:0 beginning to wait for index pin to pulse

UPDATE:
I am now receiving my expected results due to geometrikal's answer.   While researching this problem I found a few code examples of Arduino to Floppy Drive. I noticed that they were setting their input pins to HIGH, but I never realized why they were doing this.  After fixing my problem, I found this in some Arduino documentation (which made me realize the code examples I had were using an older version of the Arduino IDE):
"Prior to Arduino 1.0.1, it was possible to configure the internal pull-ups      in the following manner:"
pinMode(pin, INPUT);           // set pin to input
digitalWrite(pin, HIGH);       // turn on pullup resistors`

In Arduino 1.0.1+ you can do it this way.
pinMode(pin, INPUT_PULLUP);

Both methods of enabling the pull-up work. The second method, using the INPUT_PULLUP pinMode, is better both because it uses 1 less line and because it's a lot easier to read.

According to this (dead link):
http://bitsavers.trailing-edge.com/pdf/nec/FD1035_Product_Description_Jul84.pdf

This is an archived copy of the FD1035 3.5" Floppy disk drive: Product Description July 1984 - PDF:
https://archive.org/details/bitsavers_necFD1035Pl84_876629

The outputs are open-collector, so a pull-up resistor is required. You can instead enable the Arduino internal pull-ups on those pins by
pinMode(indexPin, INPUT_PULLUP);
pinMode(track0Pin, INPUT_PULLUP);

I can't thank you enough.  This is exactly what I needed.

You should replace int with unsigned long in all locations where you deal with time in milliseconds.
The point is that millis() returns an unsigned long, thus using int to store millis() value, you have a loss of information due to automatic cast performed by the compiler.
The changes you have to perform are:
unsigned long motorSpinTime = 1000UL; //in ms

and:
//spins the disk motor for a number of ms and prints the state
void spinMotorForThisManyMs(unsigned long msToSpin) {

  //start spinning
  digitalWrite(motorEnableBPin,LOW);

  //delay.. keep printing the state
  unsigned long maxTimeMs = millis() + msToSpin;
  while(millis() < maxTimeMs ) {
    printState("Spinning");
  }

  //stop spinning
  digitalWrite(motorEnableBPin,HIGH);
}

Note that I have also performed some optimization in the waiting loop by calculating the maximum time once and then compare millis() directly to that value. This is not mandatory but I just find it a bit more clean.

Great catch! Unfortunately, changing this code does not fix the unexpected output I am receiving. I am still receiving all 0's for the index and track 0 pins. I'm still stumped. I would say that perhaps the drive is bad but I bought 2 3.5" floppy drives for this project, and I get the same output with both of them (I guess they could both be bad, but what are the chances of that?).

This is potentially important, but does not in any way answer the question asked, so is the type of point which should be made as a comment.

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


text:
How to process this XBee analog pins signal?
I'm new to XBee and a colleague setup a sender/receiver pair. I'm using an usb breakout and reading the values using this java XBee API in Processing/Java.
The issue I'm having is two of the pins(analog 3 and 4) seem to have a strange alternating pattern and this makes it harder to read the values. Here's what I mean:
a recording of the plot I'm drawing of the values:

and here are some values. I noticed there were duplicate entries, so I removed those:
654,28
65,28
65,366
52,366
52,263
607,263
607,23
45,23
45,554
164,554
164,138
393,138
393,14
33,14
33,677
432,677
432,64
77,64
24,237
24,345
659,345
659,29
61,29
74,378
74,226
455,226
455,16
42,16
42,592
225,592
225,107
348,107
348,13
27,13
27,700
515,700
515,56
60,56
60,392
372,392
372,70
98,70
98,141
12,141
12,456
663,456
663,30
64,30
74,349
74,224
554,224
554,20
41,20
41,600
256,600
256,96
127,96
127,87
13,87
13,502
659,502
659,37
75,37
75,251
20,251
20,364
631,364
631,25
55,25
55,436
128,436
128,165
447,165
447,16
38,16
38,618
224,618
224,107
251,14
25,14
25,700
535,700
535,54
67,54
69,323
69,235
568,235
568,21
49,21
49,503
182,503
330,128
330,12
13,12
13,498
665,498
665,35
76,35
76,247
47,247
47,277
313,277
313,12
22,12
22,691
513,691
513,56
157,56
157,53
18,53
18,640
169,640
103,48
103,105
12,105
12,389
209,389
209,30
65,30
65,353
19,353
19,282
200,282
200,18
21,18
21,681
152,681
152,54
123,54
123,47
14,47
14,526
654,526
654,37
74,37
74,260
17,260
17,387
655,387
655,29
61,29
61,375
74,375
74,249
512,249
512,18
32,18
32,678
255,678
255,92
270,92
270,11
25,11
25,319
557,319
557,53
61,53
61,165
115,165
115,133
195,133
195,18
20,18
20,317
594,317
594,48
126,48
126,41
14,41
14,281
653,281
653,40
80,40
80,96
35,96
35,189
623,189
623,25
55,25
55,191
139,191
139,123
468,123
468,16
31,16
31,306
622,306
622,45
82,45
82,90
24,90
24,345
207,345
207,32
66,32
66,347
22,347
22,247
201,247
201,18
41,18
41,616
82,616
82,82
93,82
93,147
12,147
12,472
206,472
206,33
73,33
73,287
18,287
18,274
204,274
204,19
49,19
49,526
64,526
64,103
182,103
182,14
27,14
27,701
457,701
457,61
225,61
225,19
19,19
19,654
592,654
592,48
105,48
105,125

Looking at the pattern I noticed the higher values occur every 3rd value but also the values seem to oscillate like on a sine wave. If I read only the 3rd value of each sensor that seems remove the 'gaps', but the sine wave pattern is still visible. When I physically get the two pots connected to analog pins 3 and 4 (index 2 and 3 in my plot) I can notice the maximum value either increases or decreases, but the sine pattern is still there.
I've also started going though the XBee manual and found this:

Analog samples are returned as 10-bit values. The analog reading is
  scaled such that 0x0000 represents 0V, and 0x3FF = 1.2V. (The analog
  inputs on the module cannot read more than 1.2V.) Analog samples are
  returned in order starting with AIN0 and finishing with AIN3, and the
  supply voltage. Only enabled analog input channels return data as
  shown in the figure below. To convert the A/D reading to mV, do the
  following: AD(mV) = (A/D reading * 1200mV) / 1023

Unfortunately I'm not very experienced with electronics, but it looks like a linear mapping to me and I haven't found anything else pointing to this oscillation.
My naive approach would be to work out the period or this sine wave and see how much the amplitude changes when I physically turn the pots versus the 'default' position.
I've also started looking at signal processing and thought that potentially I could use a 'wavelet' to detect a pattern and then see difference between the expected one and the current signal, but that sounds a bit overkill.
Is my naive approach decent ? What's the simplest way to read values from a signal like this ?

Sounds like your pots are not connected correctly and you pick up noise. The waveform you are seeing could be from the mains, or another source. Stray magnetic fields from transformers etc. can couple and be picked up by your circuit and you will notice them if your input is of high impedance. The atmosphere is also full of electromagnetic radiation from human sources and from space, that you can also pick up. The longer wires that are connected to your high impedance input, the more noise you will pick up.
Your pots should be wired 1.2V-AIN-GND, with the 1.2V source being low impedance, coming from a power supply/regulator and not eg. a voltage divider. If your potentiometer is high impedance (say 100 kOhm), and it is connected with wires from eg. a breadboard, you might want to add a decoupling capacitor between AIN and GND. 0.1 uF would be a typical value. It will short out AC waveforms(noise) to ground.

Thank you for the tip(+1)My colleague hooked up the circuit to an oscilloscope and the signal looks like an oscillation. The pots are L/R triggers on a joypad and it looks like that's how the joypad deals with these.I did a quick test using pygame and the joystick class and I see 5 axis weridly: 4 are for the horizontal/vertical for the two thumb sticks, but the 5th axis changes values based on these L/R triggers: L goes from 0 to ~-900, R goes from 0 to ~900 and when either L/R are released or fully pressed the value is 0 (the 900 and -900 add to 0). Any hints on reading oscillating signals ?

At what frequency does the signal oscillate? What's the amplitude? How does the waveform change when you press a button / move a joystik? A circuit diagram and/or product name would be helpful. I doubt that it's really supposed to oscillate though. How are the two circuits(xbee, joypad) grounded?

The product is an Xbox One controller and it's the LT/RT I'm trying to get. One problems is the wave frequency is faster than what the XBee can send so what I'm receiving doesn't have a peak at the same distance (it's 3 samples away, then 4 depending on what samples I might be missing). However, I've managed to get something off the ground in two steps: 1st I'm detecting the peaks (by checking the signs of the difference between the current and the previous and the current and the next: if they're both positive I'm looking at a peak), then seeing the maximum value. Then I threshold the maximum

Where in the circuit are you sampling from?

Sounds familiar .
First i will test whether i am reading something or just picking up random noise due to poor connection or error in coding (data conversion arithmetic etc).
Connect 1 pin to ground and another to 1.2V.
You should read 1024 and 0 on e 2 pins . If not check circuit and code.
Anyway
Vadc = (ADC/1024) * Vref

Did you connect Vref ?


text:
Can I use the SVG headers on the SainSmart Uno to drive servos?
I am working with a Sainsmart Uno with SVG header pins.  This header is really convenient for hooking a servo to directly, so I have two servos connected to it on D9 and D10 and a 9v battery supplying power via the power jack.
Everything seems to work fine at first, but eventually (sometimes quickly), the board becomes unresponsive.  If, instead, I wire my servos to use the 5v pin on the Arduino (not from this SVG header), I don't run into this trouble.
Does anyone know if I am running into a limitation of this header Voltage pin?  Has anyone had any success using this mechanism to drive servos?  Certainly, I don't NEED to do it this way, but it sure is convenient.

Do you have a multimeter? Can you check where the voltage on that pin comes from? Looking online it seems there is a 5V and a 3.3V regulator. The 5V can supply 500mA, but the 3.3V only 50mA. Therefore it is the 3.3V going to the servos it is not enough. There is a switch on the front of the board that looks like it may change the voltage over.

Yes.  Good question @geometrikal.  I have the board switched into 5v mode, and the "V" pin on the header is reading as 5v.  But this pin switches based on the board voltage setting, which is different from the specific 5v and 3.3v pins on the other side of the board. Perhaps, because the SVG pins can switch between 3.3v and 5v dynamically, they could have limited it to 50mA.  That is my working hypotheses right now :)

It's probably best not to power your servos from the Arduino's regulator anyway, as servos are both power hungry and notoriously noisy.  Give them there own 5v regulator, and connect the grounds in common.

@ChrisStratton Yeah, that makes sense.  I just wonder what the utility of these SVG-style headers are if you can't plug a servo into them... but what you say makes sense.  That is how I have it wired right now anyways.  I was just hoping to use these headers.  They are sooooo convenient.


text:
Connecting a Arduino to FT232
I found this wonderful breakout board based on FT232. I wonder if I can use this board for connecting my arduino to a USB dongle for 3g/GPRS connection ?
From what I understand this board can be connected to the serial data pins of the arduino board. And if I connect the USB dongle to the FT232 board, I should be able to run AT commands from the arduino board.

How exactly do you imagine connecting two USB devices to work?

Many don't realize that USB has distinct host and device roles; it's a common confusion, but yes, the answer is that it doesn't work.

Unfortunately, no, as the FT232 would have to act as a USB host device. A USB host shield might work if someone has written driver code to support 3G modems.


text:
Nested For Loop
I'm not sure if I'm being really really stupid, but why doesn't this work?
void setup() {
  Serial.begin(9600);
}

void loop() {
  for (int x; x < 8; x++) {
    for (int y; y < 8; y++) {
      Serial.print(x);
      Serial.println(y);
      delay(100);
    }
  }
}

When this does:
void setup() {
  Serial.begin(9600);
}

void loop() {
  for (int x; x < 8; x++) {
    Serial.println(x);
    delay(100);
  }
}

The first produces no output over Serial, whereas the second one prints out the numbers 0 to 7 as expected. I'm using a Teensy 3.1.

Very odd... doesn't work for me on Mega 2560. I must be missing something obvious :-)

yes, obvious: int x = 0; inside for() statements (same for y by the way)...

How we can solve question 18 ?

You are not initializing x and y.
When a local variable isn't initialized, it will "inherit" the value contained in the register assigned to the variable by the compiler. The fact that your single loop example worked is pure luck - the assigned register happened to contain 0 at that point in execution.
Change your nested loop like this:
for (int x = 0; x < 8; x++) {
  for (int y = 0; y < 8; y++) {
    Serial.print(x);
    Serial.println(y);
    delay(100);
  }
}

And it will work.
Note: Global variables, on the other hand, are guaranteed by the c++ standard to be initialized to zero. The compiler will make sure to write zeros to those memory addresses before the main program code executes.

I've spent too long writing Ruby...


text:
Using Arduino RS232 to a modem (only RS232)
I am a newbie to the arduino world. And am trying to work out a configuration that does not involve USB.
I wonder if this configuration will work.
Are there any 3g modems that work on Rs232 interface. That should get rid of the USB compatibility that costs 3 times a arduino.

I'd suggest buying a 3g/gprs shield, or the adafruit fona. That way you already have some sample code, and don't have to figure out everything yourself.

I am ruling out usb completely since a usb compliant host device increases the cost of the solution 3 fold. I need a rs232 interface, speed is not my requirement. I need to send 150 bytes every 60 seconds. Cost is the only factor for me at this time.

Just corrected the subject line.

There are more TTL/UART 3G modems than RS-232 3G modems.

In Aus: http://www.maxon.com.au   Arduino doesn't have RS232 however, so like for a TTL/UART interface as Ignacio suggests.

You might want to consider something with native USB support like a raspberry pi instead of the Arduino.


text:
Arduino: Hardware SPI hangs, bit-bang does not
I'm using FastLED with a custom board built around the ATMega32u4. When I set it to use Software SPI, everything works fine, but when I use hardware SPI it just hangs whenever it tries to write out the data (FastLED.show()).
I originally mocked this up on an Arduino Pro Micro and it worked fine there. That makes me think that it's a hardware issue but, as I mentioned, SPI output does work, but only when bit-banged. Which really doesn't make much sense.
I tested this by also just using the built in SPI classes and I get the same thing. No luck with hardware SPI.
Anyone else ever see something like this?
The schematic of my circuit is below.

Have you checked SCK/MOSI with an oscilloscope to verify if some signal was sent?

According to ATmega32u4 datasheet, section 17.2.1 (SPI / SS Pin Functionality / Master Mode:

If SS is configured as an input, it must be held high to ensure Master SPI operation.

In your circuit, SS pin (#8 on package), also labeled as "(SS/PCINT0) PB0", is left unconnected.
Is it possible that PB0 is also configured as input somewhere in your program or libraries? In this case, it should be connected to Vcc.

YOU ARE MY FAVORITE PERSON RIGHT NOW!! I was testing on a Pro Micro and it just happened to have that pin connected to VCC through an LED and resistor. So, it made it work. pinMode(0, OUTPUT) made it all work again :) THANKS!

Just to add. Instead of connecting to vcc you can also just enable the internal pull-up resistor.

Or just configure the pin is OUTPUT which is the easiest way, and it enables you to use that pin for something else. That's probably the best option.


text:
Do Arduinos meet military standards?
Do Arduinos meet military standards?
If not, where does it fall short? Is it something internal to the chip which might be corrected via external circuit? How could I evaluate the potential of a device I'm building?

There are many countries and many militaries, and not everyone of them is a USA puppy.

It depends on the application. For something like a rechargeable torch, Arduino might exceed the specifications. For a weapons system, NEVER (and this is one of the specific prohibitions in the license agreement - see section 1.5 note: link currently broken). You also have to consider that there's literally thousands of armies in the world and they all have different standards. What might be acceptable to one might not be acceptable to another. Hamas uses rockets I wouldn't consider safe for anything, and they use them effectively - the Qassam rocket would never meet US military standards but it works great for Hamas.
US military standards are so complicated, nobody can answer this question for you. You're gonna need an army of lawyers to do that... here's a link to some documents to get started though...
Please note there are multiple standards which may apply to a given device. For example, you will see common off the shelf desktop computers (running Windows) used for some things in a military installation, but they could never be used to control a vehicle. Bottom line - you're gonna need a lawyer to navigate this. (You are better off selling your devices directly to soldiers, if you can live with that if it fails.)
http://www.dsp.dla.mil/ - Terrible site - get used to that if you want to deal with govs.
OH BTW... if you want to use Arduino to prototype something, and you plan to remove "Arduino" later, running straight from the ATMega - that's the whole point of Arduino! It is a prototyping system, not intended to be used wholly in products. Arduino is very little more than a break-out board for the ATMega processor, a robust (kinda) power supply, and a runtime environment in C++.

"... an army of lawyers ..." BADUM-TSH!

@Jasmine, that link didn't get me to any license agreement.  Can you please update the link to something that shows the section you are talking about.

Ugh, it seems they have updated the site, and the hardware license agreement is something I can't find any more. I've made as much effort as I want to make, but if anyone finds it, just reply here and I'll update the answer. Sorry about that.

Defiantly not. If you wanted to use it for very early prototyping then I think it would be fine. However, it really depends on the use because lets admit it Adriuno boards don't have huge amounts of processing power and are somewhat limited to capabilities.

Not every application requires a quad-core 1.8GHz CPU.

@IgnacioVazquez-Abrams, performance isn't the issue. The main issue is ruggedness and hardening against things like EMP. Stuff that is rated for the military needs to be able to survive being dragged behind a humvee through a swamp for 5 miles. (Ok, I exaggerate, but that's the general idea.)

@DuncanC: Sure, but that's completely independent of what this answer mentioned.

Your question is broad. My first reaction is to say No.  But in order to be very accurate (or fair), your should find the application standard. Military has an extensive library of standards ranging from manufacturing and testing.  Therefore, take a look at the standard regulating your application. Only after this assessment, the question of whether Arduino will suffice a military application will be accurately answered.

It is not mil spec. Making something comply with milspec is a big, complex subject. (A subject I know very little about.)

In Military.. everything has to do with standard military specifications.

Do Arduinos meet military standards?

it meets some military standards but fails the others.


text:
Can I change VCC pin to 3.3V on a 5V Arduino Pro Micro?
I'm using a 5V Arduino Pro Micro (schematic).
For my project, I'm using the VCC pin to output power to an external device.  I need VCC to output 3.3V to the external device.  Can I open jumper SJ1 to reduce the voltage of the VCC pin without affecting the operation of the other parts of the unit?

No. If you change the voltage to 3,3 Volt you also have to change the crystal to 8MHz and reprogram the ATmega32u4 to meet the new frequency.

How other Arduinos handle that were one can switch between running at 3.3 and 5V (e.g. Olimexina 32u4)?

Running the atmega32u4 at 3.3V @16Mhz is outside the "Safe Operating Area" is indicated in the datasheet on page 381. Maximum freq. is around 12Mhz at 3.3V. I myself would just try it and see if it works reliable enough. The chip makes are usually quit conservative about their ratings.

I'm pretty sure that, despite the schematic provided, you will find that the 5V Pro Micro actually has a 5V regulator onboard. So even if you open the jumper, it will still be powering the Atmega32u4 at 5V (technically 5V minus diode voltage drop and regulator dropout voltage).
You could change the regulator for a 3.3V one using a hot air station and solder paste and open the jumper, but as other posters have commented, you would still be running the Atmega beyond spec at 16MHz and 3.3V.

You can, actually albeit 32u4 at 16MHz at 3.3V is outside of the safe operating area, it worked for me perfectly. Also for others :) google for it.

I had the same issue on my cheap 5V @ 16Mhz Pro Micro from ebay. I have the 16Mhz crystal and a voltage regulator marked S2PC.
The J1 was not bridged and I was only getting 3.3V on the digital pins... wait a sec that should be 5V!!
I Went ahead and bridged the J1 jumper and now I am getting 5V on my digital pins! Not sure what is going on behind the scenes with the J1 jumper open with this hardware but I'm thinking it may have been overclocking the chip while running at the lower voltage.
Going to let it run over night and see if something doesn't blow but it looks like they may have just forgot to bridge that J1 whilst mass producing both the 3.3V and 5V versions of this board.


text:
LM386 module not working
I have arduino UNO hooked up with wtv020-sd-16p and it works fine, playing audio files - speaker is connected right to the WTV020's pin #4 and #5. However, volume is rather low. So I have ordered LM386 amplifier module. I have wired it's IN pin with WTV020's pin #2 AUDIO-L. But no sound comes out of speaker. I can hear only some scratches from the speaker while arduino is running.
LM386 is pretty easy, only VCC, IN and GND pins, so there is nothing much to screw up. I am wondering, what could be the problem ?
Thanks for any help or hints in advance.
EDIT: Only to note, when WTV020 is playing sound, speaker goes completely mute. When it doesn't play sound, little scratchy sounds can be heard from speaker. Maybe it could help with analysis ?

Where does the Vcc plugged into the lm386 come from? This one should be at least 1A I think.

Oh, I am powering LM386 from Arduino 5V. So it might be the problem ?

@jfpoilpret But here is shown LM386 taking power directly from Arduino's VCC as I am using, so it should be fine then ? http://arduino.cc/en/Tutorial/SimpleAudioPlayer

Try feeding your input to the module via a series capacitor to remove any DC offset.

@ChrisStratton You've nailed it. Please add your comment as answer, I will accept it. Thank you.

when WTV020 is playing sound, speaker goes completely mute. When it doesn't play sound, little scratchy sounds can be heard from speaker. Maybe it could help with analysis

Indeed - what you are describing sounds like the DC component of the Arduino's output is outside the workable range of the amplifier, effectively cutting it off.  When there is no output, the voltage is within range and little bits of noise are able to be amplified.
You should be able to fix the cutoff problem with a series capacitor to block the DC component of the input, allowing only the AC signal through - a common technique for coupling between stages in Audio and RF systems.
The value of the capacitor will depend on the impedance of the circuit it is driving.  A bare input to many chips could use a quite small value, while a circuit with feedback or a voltage-divider volume control might require a larger or carefully chosen one.


text:
Reading a 10 pin 7 segment (2 digits) sing Arduino 1. Please Help!
thanks for taking the time to read this, I really appreciate it.
I am very new to Arduino and the Micro controller world so please forgive my ignorance.
So I have an old 7 segment display that displays outside temperature, what i want to do is read the temp into the Arduino and light up an LED if the temperature gets high, and a different color if the temp gets low.
I know i can use a thermometer and plug it into the Arduino and go from there, but that would be cheating. So my question is, can i read each pin of the 7 segment display and translate that into a number into the Arduino?

Task: Read a dual  10 pin 7 segment by jumping wires into the Arduino.
Setup: I am using the code and setup found here: "http://blog.rastating.com/using-a-7-segment-led-display-w-arduino-uno/" to display a number (21) for testing purposes. I want to jump the pins into another Arduino and read "21"

please see pictures.
Any help would be very very appreciated!!
Thanks again for reading.

This last picture shows "21" using the code and set up on the above link.
I want to jump another Arduino into the breadboard and read "21" or any other temperature (depends on outside thermometer) into the serial monitor. Now the challenging part is the code, Im not really good at coding but i understand if this had 1 pin for each LED i would just read each one and translate it into the serial monitor. However this only has 10 pins therefore represents a challenge.
Any input is greatly appreciated, I dont even know how to start.

Have you checked (eg with a DMM or an oscilloscope) the voltage between the anode and cathode for one lit segment of the display? This will tell you if this can be directly used as a digital input of Arduino or it it requires additional circuitry.

In order to get the value from any display pin, you will also need a ground that you can plug to Arduino GND, do you have such a pin onn the display board, or you just have 8+2 pins, 8 for the 7 segments + DP, 2 for each common anode?

This post helped me to develop an Arduino circuit to read multiplexed display.
The solution can be found https://github.com/bunhoel/FT107m good luck

Your display is multiplexed, so you will need to monitor not only the segment lines but also the digit lines.
First figure out if your display is "common anode" or "common cathode" as the logic in one case will be inverted from that of the other.
For your test case, you can write the driving and reading arduinos to the display in the same way, but configure all the connected pins on the reading one as inputs.
The tricky part is going to be detecting when the segment select has changed, but you could do it by storing the current value of each select pin, and then reading the new value.  If you see that the old value was inactive and the new value active, then wait a tiny amount of time and read all of the segment lines.  You want to wait long enough to make sure that the data lines have been driven to match, but no so long that you get the data for the next digit instead.  If you have access to a scope, you can find the best value, but you could also experiment by making the delay short until you get wrong data, making it long until you get wrong data, and then picking an intermediate value.
You may find it easiest to read all 7 or 8 segment lines into a single byte value, and then compare it to each element in the lookup table you used in the driver code until you find a match.
If you don't know the exact wiring of the segments on the unknown target board, consider printing the bytes to the serial monitor as you cause the displayed values to change (cup of ice water, cup of hot water...) and taking notes of the segment values vs. the digits you see display.  It will be a puzzle, but one you should be able to figure out.

I have a common anode setting. I am really new to code, is there an example anywhere that i could go over?

First of all, make sure that the voltage is below 5V (but above 2.5V so it can register as HIGH on a digital pin). If not, it will either fry your Arduino or won't work.
As for the code, you can do one of the two following things:

Use a library like PinChangeInt to help you detect when and what changed.
Store the data and check every so often.

Chris Stratton had a good idea with the byte and compare it. To do this, you would do something like this:
byte data = 0;
if(digitalRead(10) == HIGH) {
  data |= B00000001;
}
if(digitalRead(11) == HIGH) {
  data |= B00000010;
}
if(digitalRead(12) == HIGH) {
  data |= B00000100;
}
//...

Basically, this is bit-wise math that sets one bit of your byte to a 1. If it is a 0, then you leave it alone (all bits default to 0 because of how I declared data).
If pins 10 and 12 were HIGH, the byte would look like this in binary:
00000101

Hi! so I realized that the 2 pins that are driving this toggle at 4kHz, when one is on the other is off, but there is a 6usec time when both pins are on. So what im trying to do now is adding "if right bit is == 1, if A=1 b=0 c=1 d=1... and so on" then number 'code'

@user3537 Do you need help with that? If so, what I can I help you with?

It would be so much more efficient to read an entire AVR port register, even if a few bits spill into the next.  Does Arduino support that cleanly, or only by ignoring it and doing a raw read?

so I realized that the 2 pins that are driving this toggle at 4kHz, when one is on the other is off, but there is a 6usec time when both pins are on. So what im trying to do now is adding "if right bit is == 1, if A=1 b=0 c=1 d=1... and so on" then number = 6 then scan for it. Im not sure how to use that library.
void loop() {
// read the input pin:
//int buttonState = digitalRead(pushButton);
int State_A = digitalRead(A);
int State_B = digitalRead(B);
int State_C = digitalRead(c);
int State_D = digitalRead(D);
int State_E = digitalRead(E);
int State_F = digitalRead(F);
int State_G = digitalRead(G);
int State_DP = digitalRead(DP);
int State_RIGHT = digitalRead(RIGHT);
int State_LEFT = digitalRead(LEFT);

if (State_LEFT==1)
{
 if(State_A==0 & State_B==1 & State_C==0 & State_D==0 & State_E==0 & State_F==0 & State_G==0)
{
number=6;
Serial.println(number);
// Serial.print(State_LEFT);
}

i plan to add that for every digit. is there any easier way to do that?

This should be edited into your question, as it is not an answer.

I would personally tie the two select pins to an level changing interrupt input on Arduino. Then when you receive an interrupt from one of the digits you have 'all the' time to read the segments. When you don't do the interrupt thing, you may read segments from different digits. A further optimization would be to replace all digitalRead's with a single segments = PINB which would read 8 input lines in a single go.

Using port registers would be cleaner, but much less portable. The port assignments are different between Arduino models.

"segments = PINB" how does this work? if i have all 7 pins a-g

What you are trying to do is tricky and awkward, and probably not worth the trouble.
It's also above your current skill level, both in hardware and software.
As the other poster has said, the display is likely multiplexed. If so, it sends a value to 1 digit, then to the next, and alternates them quickly. Only one digit at a time is actually lit.
It's also possible that the digits are latched. The processor sends a value to one digit at a time and that digit's circuitry remembers the value until it changes again. However that's  less likely because it's more complex and expensive to do
To decode a multiplexed display you'll need to figure out how the multiplexing is done. There are lots of different ways it could be done.
You say it's common anode. It might have the anodes of a digit wired together, and have them both connected to the controller. The anode that's currently being displayed would be connected to +5, and the cathodes of like segments from each digit would be wired together in parallel. To drive a digit, the control circuitry would connect the anode of that digit to the positive supply, and connect the segments to be displayed to ground. All other connections would be left floating. Then it would disconnect the anode of the first digit and connect the anode of the other digit to the positive supply.
The display may also have a logic level that determines which segment is being driven. For a 2 digit display all you'd need is one line, and a HIGH would drive 1 digit and a LOW would drive the other digit.
A logic analyzer would help you sort this out, but you need to know how to use it.
You might also try researching the thermometer you're using and see if you can find a schematic for it, in the documentation, the manufacturer website, or in a patent
Once you figure out how to read the segment values from each digit, you will need a truth table that maps segment values to numbers, and will need to do a lookup. That is intermediate level C programming.


text:
Sensors and leds. This need resistors? and how?
I have a project with leds and sensors, this is my first project in Arduino and I want to know if it need resistors and how and where?
I use 16-Bit I/O Expander MCP23017 for leds and multiplexer CD4051 for sensors LM35

I'm downvoting this because it never should be asked. By the time you're ready to do the project you've outlined, you would know the answer to this. You aren't ready to build this project yet. Why do people think they can do this? It's like trying to copy the Mona Lisa without knowing how to mix paint.

You will definitely need resistors for each LED connected to MCP23017 circuits.
This is necessary because without resistor the following is likely to happen:

burn each LED that is lit on as it would be fed too much current
burn the MCP23017 because it is rated for 125mA maximum (20mA per output pin)

The resistor to use normally depends on the color of each LED as those LEDs have different electrical charasteristics.
Typically one LED (3 or 5mm) needs no more than 20mA to be lit (lower current such as 10mA is generally provides enough light).
One other important LED characteristic is its forward voltage, which depends on the color.
This link will help you calculate the "ideal" resistor for each LED.
For the sensors part, I see no reason to use any resistor to connect them to 4051 circuits.
One last important point is related to the use of I2C bus by the MCP23017 circuits. I2C bus is "open drain" and thus requires pullup resistors for both SCL and SDA lines.

Doesn't the I2C library (Wire.h) use the internal pull-up resistors?

@Gerben: You want external pull-ups.

@IgnacioVazquez-Abrams thank you. Much appreciated.


text:
Is TM4C123 similar to Arduino?
I'm currently studying embedded systems on eDx.
https://courses.edx.org/courses/UTAustinX/UT.6.01x/1T2014/info (must login to see)
http://users.ece.utexas.edu/~valvano/edX/index.html (don't need to login)
and I found out that TM4C123 is quite similar to Arduino.
but I haven't worked TM4C123 yet.(I ordered it and I'm waiting for it)
 I don't know much about it.
and it's not that popular as Arduino I guess.
so If anyone has used Tm4C123, please give me some information compared to Arduino.

This link does not show anything about this course or requires registration, this is not acceptable. Rather try to copy part of the course description to your question so that we know what it is about.

@jfpoilpret I'm sorry. I've just added the link. thanks :)

It's a micro controller, just like an Arduino. But it's more powerful than an Arduino. 32-bit instead of 8-bit architecture, faster clock-speed, more flash memory, more s-ram, usb-support. You just don't get the ton's of libraries and tutorials that are available for arduino.

@Gerben: Seen the Due yet?

Arduino'like IDE for Launchpad http://energia.nu/

The Tiva C LaunchPad is comparable to the Arduino Due in power and capabilities, but is incompatible with the stock Arduino ecosystem. It uses "BoosterPacks" rather than Shields, and Code Composer Studio (or other [some non-gratis] tools) instead of the Arduino IDE and libraries.
The Energia IDE is a port of the Arduino IDE and significantly simplifies configuration and programming Tiva C launchpads.
Beware of odd quirks with the Tiva C Launchpad board, such as the 0-ohm shunts that must be removed if you want all pins to be completely independent.

But if you're looking to jump from an AVR-based Arduino then I recommend the MSP430-based LaunchPads instead.

Actually, as the Tiva C has an ARM Cortex-M4 CPU it is likely that free toolchains can be used and an Arduino port seems possible.  But yes, it is quite different hardware and from the manufacturer a quite different environment.

@ChrisStratton: Corrected.

I have completed the edX course, and the TM4C123 is significantly different to the Arduino from a programming perspective. Each family of microcontrollers have (on the surface) a fair amount in common - GPIO pins, an ADC or two, timers etc. However the way these work internally are very different - different registers, different process for using them, different gotchas to look out for, etc. If you're looking at tackling a new MCU family, be prepared to effectively learn a new "language".
Incidentally, the Launchpads from Texas Instruments have a processing-based language similar to the Arduino - called Energia - which should work on your TM4C123.
Enjoy the course, I did.

Thank you for the information.
I have a question.
Do you think TM4C123 will be more popular or it's just for embedded students or hobbyists??

@StarbuckSb: With all due respect to TI, I honestly don't think they can make something that can displace the Arduino any time soon. Which is fine, they don't have to; their products are excellent regardless.


text:
Serial.write displaying repeating output from Xbee communication
I want to use xbee's to communicate between two different arduinos.  I'm using this tutorial as a guide to setup my xbee's. I've already used XCTU to setup one xbee as a router and another as a coordinator (both in ZIGBEE AT mode).  I used XCTU's terminal feature to verify that info was being sent and received properly.
Basically, I have both arduinos connected to the same PC via USB cables, but the communication is taking place through the Xbee's.  I also made sure to disconnect the TX & RX wires when uploading the sketches to avoid an AVRDUDE error.
I wanted to test the communication by sending a "hello world" message once every five seconds, from the router to the coordinator.  To do this, I wrote the following code:
//Code for Arduino attached to Xbee in Router AT mode
void setup(){
 Serial.begin(9600);
}

void loop(){
  Serial.println("Hello World!");
  delay(5000);
}

and
//Code for Arduino attached to Xbee in Coordinator AT mode
void setup(){
  Serial.begin(9600);
}

void loop(){
  if (Serial.available()>0){
    Serial.write(Serial.read());
  }
}

I checked the serial monitor for the arduino connected to the router, and it does exactly what I expected to see:  a new Hello World message once every 5 seconds.  However, the serial monitor on the arduino connected to the coordinator does not produce the desired effect:  the "hello world" message instantly displays the message over a hundred times per second and repeats without end, each time on a separate, new line.  Sometimes, when I turn the serial monitor on, the message instantly appears with a few repetitions before displaying some strange characters and stopping altogether.
I'm not sure if the problem is with the serial monitor or with the xbee.  Any help with this problem would be greatly appreciated.

The same issue was reported on the Arduino forum and the user was able to solve it by setting the DL parameter to be 1 on the coordinator Xbee and 0 on the router Xbee.

Code is correct and it does what it is asked to. The receiver code reads the RX pin of arduino which is connected to the Xbee. The same pin is used by the FT232 interface IC to send data to your computer through USB.
The "hello world" you send is received by the Xbee and is send to microcontroller and FT232 at same time as that pin is shared between them. Thus the "hello world" will be seen in serial monitor, first time from Xbee and second time, from Serial.write(Serial.read()) of the program.
Also check whether the settings are correct from this tutorial, as Xbee will not be configured as P2P.

But why would the message repeat infinitely and fill up the serial monitor at a rate faster than one message every 5 seconds?

The problem is that the message repeats over a hundred times a second, much faster than the "once per 5 seconds" that the message is being sent from the other xbee.  Why would this happen?

Did you check the baud rate configured for xbee and serial monitor is same as in the code (9600)?

I checked, and it was, in fact, set to 9600 baud rate.

Is there any way to work around this problem?  I just want to be sure that the data that was sent is received and displayed at the proper speed in which it was sent.


text:
Externally Powering a 3.3V device (nRL24L01+) with a 5V Arduino Pro Mini?
I have seen several references where the solution to interfacing a 5V Arduino with a 3.3V nRF24L01+ was to power the nRF24L01+ externally.
How do I do this?  The ground of the nRF24L01+ is connected to the Arduino; can I simply attach 3.3V power between the power and ground pins of the nRF24L01+?

"... power the nRF24L01+ externally." Not really sure what this has to do with interfacing with it...

If you have a 3.3v supply or regulator, yes.  Preferably the 3.3v and 5v would be available/absent at the same times.

To connect the nRF24L01+ to a 5V Pro Mini you will need external 3.3V power supply to power the nRF24L01+.  The ground for the Pro Mini and the ground for the nRF24L01+ should be tied together to ensure a common ground reference.
The inputs to the nRF24L01+ are 5V tolerant so you will not need a level shifter to convert the 5V Digital IO on the Pro Mini to 3.3V. Be aware the not all 3.3V devices have 5V tolerant inputs like nRF24L01+.
You might want to look into using a 3.3V Pro Mini with that you should be able to use the regulated 3.3V power on the Pro Mini to power the nRF24L01+. Be aware that the 3.3V Pro Mini only runs at 8MHz instead of 16MHz.

The second part is incorrect, in this case. The nRF24L01+ has 5v tolerant inputs. So, for this specific device, an level shifter isn't needed.

Yes, You can.
In any communication system, each module should have the same reference point of operation, or else the line is said to float. Here it is GND of arduino mini and GND of nRF24L01+.

you can download the references from this link: https://s3-ap-northeast-1.amazonaws.com/sain-amzn/20/20-019-102/NRF24L01.rar
Hope the information may be helpful. Cheers!

As far as I can tell, the file you're linking to only contains some source code. Can you explain how it's relevant to the power supply issue in this question? Thanks.


text:
Strange values from LSM303 Magnetometer
I am having problems with values i get from Pololu MinIMU-9 boards's magnetometer. I am using Arduino-micro and the arduino library from Pololu. The sensor on the board is 3 axis accelero- and magnetometer LSM303.
The problem is - the highest value always seems to be in vertical axis, not horisontal, as i would expect.
For example, here is the data i got when i put sensor flat on the table and made 360 clockwise turn in horizontal plane:
(values are X Y Z)
-6 102 -516
-11 103 -515
-11 103 -515
-21 102 -514
-31 109 -515
-40 114 -512
-57 116 -509
-57 116 -509
-77 111 -507
-93 109 -506
-104 106 -507
-104 106 -507
-114 99 -508
-126 88 -504
-131 74 -507
-142 52 -507
-142 52 -507
-151 31 -506
-150 4 -509
-147 -27 -513
-147 -27 -513
-133 -60 -513
-119 -80 -519
-112 -87 -517
-102 -97 -521
-102 -97 -521
-89 -101 -522
-77 -101 -524
-50 -104 -527
-50 -104 -527
-43 -105 -529
-14 -98 -532
2 -92 -535
23 -92 -535
23 -92 -535
36 -81 -534
66 -54 -534
76 -32 -531
76 -32 -531
76 -21 -532
78 -7 -531
85 10 -528
91 39 -524
91 39 -524
94 50 -524
91 63 -524
76 75 -525
76 75 -525
63 82 -526
47 93 -525
44 98 -522
44 98 -522
38 104 -521
26 110 -521
26 112 -518
21 116 -519
21 116 -519
18 116 -518
12 120 -517
11 120 -515
11 120 -515
8 120 -517
5 122 -515
-5 123 -514

Turning the sensor "upside down" and then rotating it in horisontal plane again gives similar results, only Z axis has positive 500+ value.
Shouldn't the magnetometer always point in the direction of the magnetic field - in X or Y direction?
I have tried this in different rooms and buildings and got the same results.
Rotating the sensor on other axes yields the same results - vertical axis has the largest (and constant) value.
For reference, here is the code i used to get the values.
#include <Wire.h>
#include <LSM303.h>
LSM303 compass;

void setup()
{
  Serial.begin(115200);
  Wire.begin();
  compass.init();
  compass.enableDefault();
}

void loop(){
  compass.readMag();
  Serial.print(compass.m.x);
  Serial.print(" ");
  Serial.print(compass.m.y);
  Serial.print(" ");
  Serial.print(compass.m.z);
  Serial.print("\n");
  delay(100);
}

The earth's magnetic field is not parallel with the ground. In some locations it can be pointing more down than across.
NOAA has a magnetic field calculator where you can enter you latitude and longitude. For example, I am located at approx  19deg S 147degE and the field is
North Comp    East Comp    Vertical Comp    Total magnitude
32,434.4 nT   4,280.6 nT   -36,035.1 nT     48,670.7 nT

So the downwards strength is more than the other two combined for my location. I'm guessing the calculator will also show a very strong down component for your location.
Some other things to be aware of are that the LSM303DLHC magnetometer can have quite large offsets, up to the equivalent of 2 earth magnetic fields, and therefore requires calibration. Also hard and soft iron distortions can affect the readings.
Edit: Please see my answer here for methods to calibrate the sensor.

Thenk you, this really seems to be the case here.
`Horisontal intesity: 15,210.5 nT
Vertical component: 49,455.8 nT`


text:
Arduino LED backlight - should PWM be used with transistor or capacitor?
I have implemented a PWM controlled LED backlight for the LCD in my Arduino Uno design. One LCD backlight pin is connected to +5V, the second to the ground via 220 Ohm resistor and MOSFET controlled from a PWM capable D9 pin.
Everything seems to work fine, I do not see any oscillation, but after some reading about PWM I am not sure if I perhaps should connect a 100 uF capacitor to smooth the voltage?
Is the MOSFET even necessary? It seems backlight is drawing about 5 mA - can I perhaps drive it directly from the D9 pin, using the resistor? (It seems another user in Do I need to use a resistor if I am using a potentiometer to control an LED's brightness? is controlling brightness without any of those.)

You don't need the MOSFET, you don't need the capacitor, you do need the resistor.
The pins on your Arduino can deliver up to 20mA comfortably, so in this case there is no need for the MOSFET. However, if you were to replace your backlight with a high power LED, your current setup will work just fine.
Without a capacitor, your PWM is a nice square wave. The cap will, depending on its capacity and the resistor in your circuit, turn that into a more rounded waveform, or very ripply DC. Whichever is the case, it will not benefit the (dimming of) your LED. With some bad luck it will even introduce flickering instead of preventing it!
The reason why you should still use the resistor is to prevent the LED from drawing too much current. Without it, it's simply a game between the LED and the Arduino pin to see who will burn first. Whoever wins, you'll end up with a destroyed backlight or fried Arduino. Adding a component costing a few cents can prevent that.


text:
How to send numbers to Arduino UNO via Python 3 and the module serial
I am new to Arduino (and computer programming in general), so I apologize if this question  looks silly.
Once I set up a basic arduino-LED connection, I have problems sending INTEGERS to arduino through the serial port. I can easily send characters such as 'm', 'o' and so on.. However if I send a number it looks like it simply does not get it.
Here is the Arduino code, ideally it should get a value from the usb port through python or the serial monitor and then adjust the brightness of the LED according to the value. (value must be in range [0,255]).
NOTE: I am using ARDUINO UNO and PYTHON 3
//--------------------------
int LED = 10;
int number;

void setup(){

pinMode(LED,OUTPUT);
Serial.begin(9600);
}

void loop(){

number = Serial.read();
Serial.print(number);
Serial.print('\n');
if(number == -1){
number = 0;
}

else if(number > 255){

number = 255;

}

else if(number < 0){

number = 0;
}

analogWrite(LED,number);
delay(1000);
}

However, when I input a value into the Serial port or through Python, for instance 0, it gives me 48 as answer (which, interestingly, is the ASCII code for 0!) and lights up the LED which is not what should happen since at 0 the LED should be off!!
I am missing something but I cannot find what... Could you please tell me what is wrong?
Here is the code I use in Python:
import serial
import time
try:
    arduino = serial.Serial(port,speed)
    time.sleep(2)
    print("Connection to " + port + " established succesfully!\n")
except Exception as e:
    print(e)

#Note: for characters such as 'a' I set data = b'a' to convert the data in bytes
#However the same thing does not work with numbers...
data = 0
data = arduino.write(valueToWrite)
time.sleep(2)
arduino.close()

what am I doing wrong or misunderstanding? Thank you.

Try arduino.write(chr(valueToWrite))

This solution does not work even for characters.. Furthermore, as far as characters are concerned, it works fine just sending them as bytes such as: b'm'. Anyway, thanks for the answer.

Parsing on the Arduino can be slow and time-consuming (which is bad if you use clock prescaling or have time-critical tasks), so let's do it in Python.
The problem is that you're sending the numbers as ASCII whereas you need to be sending them as raw binary. This is where struct comes in.
3>> import struct
3>> print(struct.pack('>B', 0))
b'\x00'
3>> print(struct.pack('>B', 255))
b'\xff'
3>> print(struct.pack('>2B', 255, 0))
b'\xff\x00'
3>> print(struct.pack('>H', 9000))
b'#('

So what you really want is:
data = arduino.write(struct.pack('>B', valueToWrite))

or something to that effect.

Thank you very much! This is exactly what I was looking for!

Despite what the empty comment box greyed text says, I'm going to say thanks! Was trying to write a bit-stream (FPGA .bin program file) to a SPI flash chip using a Teensy 3.2 with Arduino as the PC -> flash interface, and this was the key to making it work on the PC end.

Serial.read() reads only ONE character from the serial port and returns its ASCII value, which explains the 48 you got.
To read a complete number, you have 2 options:

Use Serial.parseInt() that reads as many characters as needed and performs the conversion before returning the read number as an int. Please further check the reference here.
You read eachn character in a loop (with Serial.read()) until the last one, put each read charcater into a buffer (char array) then convert the resulting string to a number with the standard C function atoi.

Of course, the first option is the easiest one but it will return 0 if nothing is read after a 1s timeout (configurable with Serial.setTimeout()).

This answer was not exactly what I was asking for, however it has been very useful and I'll be using it! Thank you very much for the help!


text:
How to use readLine from JSSC
When I use JSSC and call serialPort.readLine(event.getEventValue()) from public void serialEvent(SerialPortEvent event) I've got fragments, not all string. What I must do to get all string from begin to "\r\n"? What I must do to get all string from my start marker (like "[start]") to my stop marker (like "[stop]")? What to modify in this code:
private static class PortReader implements SerialPortEventListener {
    public void serialEvent(SerialPortEvent event) {
        if(event.isRXCHAR() && event.getEventValue() > 0){
            try {
                String data = serialPort.readString(event.getEventValue());
                serialPort.writeByte((byte) 1);
            }
            catch (SerialPortException ex) {
                System.out.println(ex);
            }
        }
    }
}

What is the relationship to Arduino. Your question is about Java!

Anyone who uses jSSC (the most common Java serial library) to interface with the Arduino will have to implement this, so I'll answer it.

Indeed, this is a problem that will be faced by those trying to use Arduino (or similar) with a larger system.  It should either be open as an appropriate question here, or sent to stackoverflow.  Probably it is more useful here - there it may simply get lost (though if it had not been answered here, sending it there in search of more eyeballs could have made sense)

@ChrisStratton since this is more of a Java question, this doesn't belong here. I'll see if SO will take it.

The event gets fired when a single character is received, not the whole string. You have to build the string up until you get to \r\n and then process it. This is my code for a similar project. It uses a protocol where > signifies the start of a message and \r signifies the end. processMessage is a function to process the entire message and update GUI elements etc. It is invoked using runLater because the serialEvent function will be on a different thread to the GUI thread.
StringBuilder message = new StringBuilder();
Boolean receivingMessage = false;
public void serialEvent(SerialPortEvent event) {
    if(event.isRXCHAR() && event.getEventValue() > 0){
        try {
            byte buffer[] = serialPort.readBytes();
            for (byte b: buffer) {
                if (b == '>') {
                    receivingMessage = true;
                    message.setLength(0);
                }
                else if (receivingMessage == true) {
                    if (b == '\r') {
                        receivingMessage = false;
                        String toProcess = message.toString();
                        Platform.runLater(new Runnable() {
                            @Override public void run() {
                                processMessage(toProcess);
                           }
                        });
                    }
                    else {
                        message.append((char)b);
                    }
                }
            }
        }
        catch (SerialPortException ex) {
            System.out.println(ex);
            System.out.println("serialEvent");
        }
    }
}

A simpler version for you might be the following. processMessage is called whenever a \r or \n is received and there are some bytes in the message.
StringBuilder message = new StringBuilder();
public void serialEvent(SerialPortEvent event) {
    if(event.isRXCHAR() && event.getEventValue() > 0){
        try {
            byte buffer[] = serialPort.readBytes();
            for (byte b: buffer) {
                    if ( (b == '\r' || b == '\n') && message.length() > 0) {
                        String toProcess = message.toString();
                        Platform.runLater(new Runnable() {
                            @Override public void run() {
                                processMessage(toProcess);
                           }
                        });
                        message.setLength(0);
                    }
                    else {
                        message.append((char)b);
                    }
            }
        }
        catch (SerialPortException ex) {
            System.out.println(ex);
            System.out.println("serialEvent");
        }
    }
}

Edit:
Two things fixed:  1. Using StringBuilder instead of String to save making a lot objects every time the message is incremented. 2. Make a copy of the message string before passing to runLater otherwise when it does run it will use the up to date version of the string, which could have new characters, and thus cause problems.
Edt 2:
On Windows I found it needed if(event.isRXCHAR() && event.getEventValue() > 0) as the event would sometimes be fired with 0 bytes causing a null point exception in for (byte b: buffer)

Thak you very much. Maybe it will be better to add your answer to FAQ or something else.

@oventarb I hope you get this message - please see the updated code, there was a big error in the initial one. I had been using the erroneous code for a while myself and only just fixed it.