text:
Is EEPROM persisted across program flashes?
If I use EEPROM.write(someAddr, someValue) to write a value to an address, how long will that value "stick" to that address before being lost?
If I were to power down the Arduino, flash a whole new program to it, and power it on, could I still retrieve that old/cached value written from the previous program?

I am also interested in a technical answer to your first paragraph. Do you not have an Arduino to perform the test in the second paragraph yourself?

Only if the EESAVE fuse is programmed (it is unprogrammed by default). If not then the EEPROM will be erased when a chip erase command is performed.

Do you know how the Arduino IDE handles this? There are zero user options there.

@JorisGroosman: It doesn't. You'll need to use avrdude and ISP in order to read or manipulate the fuses.

So the IDE erases the EEPROM? I would say this explicitly in your answer, it seems important.

@JorisGroosman: It erases the EEPROM if the EESAVE fuse isn't programmed.

Yes, that's what you said. But I understand the EESAVE fuse is not set by default(?), and many users will just use the IDE, not avrdude.

@JorisGroosman You have to use avrdude to program the fuse.  Once you have done that, the IDE won't erase EEPROM.

I have couple of Unos, all of them keep eeprom content betweem flashing and I did not do anything with fuses.

It has been a while but I believe one of my Arduino projects that reads/writes EEPROM behaved as Michal Foksa explains.

how long will that value "stick" to that address before being lost?

The Atmega328 data retention is guaranteed by Atmel (the manufacturer) for 20 years at 85 degrees Celsius, 100 years at 25 degrees Celsius. Beware cheap Chinese clones usually use counterfeits chips, meaning those values are not going to be guaranteed any more

If I were to power down the Arduino, flash a whole new program to it, and power it on, could I still retrieve that old/cached value written from the previous program?

While @ignacio answer is more detailed I believe you are interested in plain Arduino IDE programming along with standard Arduino boards, in which case the answer is yes, the data is not going to be erased.


text:
Reading/writing to Arduino GPIO pins from raw C code
I'm interested in writing a C program without the Arduino IDE and related libraries and am trying to figure out how I can access the GPIO pins for read and write.
My assumption is that the GPIO pins are - at the hardware layer - just memory addresses, and so if I know what their address is I can send/receive data to and from them.

For writing to the digital pins, do I just send an int with a value of 0 or 1 to the pin's address? If so, what might that code look like? Can I then assume I could poll that address for a value, which would be either 0 or 1?
Can I assume the same for analog pins, but instead of binary values, I'd get an integral value between 0 and 1023?

And if I'm way off here, and pins are not accessed via memory addresses, then how?
Again, the solution I'm looking for wouldn't involve Arduino software, just the Arduino hardware (an AVR or ARM MCU). Bonus points for C pseudo-code examples! Thanks in advance!

I know the AVR stuff is easy, but I couldn't tell you how the ARM stuff works; I have an ARM board but I haven't had a chance to look at it.

Thanks @IgnacioVazquez-Abrams (+1) - I only mentioned ARM because that is what the Arduino Due is using, and I am interested in the Due for its beefier computing power. In any event, am I on track or way off in dodo bird land? Any chance I could see a few lines of C code for reading/writing pins (digital or analog)? Thanks again!

For the AVR-based Arduinos, a good reading: Port Registers.

Thanks @EdgarBonet (+1) - good find! Any ideas what the Arduino Due (ARM) might be using? Thanks again!

Also @EdgarBonet, I'm just realizing now, in that article it appears that the  DDRD register (controls data direction for pins 0 - 7) is a variable defined in the Arduino language. Since I am looking to bypass Arduino libs, what what the variable's value be in C?

No, DDRD does not come from the Arduino "language", it's defined by avr-libc. Just #include <avr/io.h> and you get all the I/O registers you see in the MCU datasheet.

In theses cases you are right, using register address is the way to read/write data from/to digital pins.
In the case you use analog input, the process is similar but you have to follow some procedures before getting the value of the data.
GPIO REGISTERS
For AVR micro-controllers these registers are:
DDRn – Data Direction Register
PORTn – Port Output data Register
PINn – Port Input Register
n- Indicates the port name i.e. A, B, C & D
If you have arduino board and want to use these pins, look for mapping pictures about arduino and avr pins.
The following is an example from the Arduino website.
DDRD is the direction register for Port D (Arduino digital pins 0-7). The bits in this register control whether the pins in PORTD are configured as inputs or outputs so, for example:
DDRD = B11111110; // sets Arduino pins 1 to 7 as outputs, pin 0 as input
DDRD = DDRD | B11111100; // this is safer as it sets pins 2 to 7 as outputs
                         // without changing the value of pins 0 & 1, which are RX & TX

See the bitwise operators reference pages and The Bitmath Tutorial in the Playground
PORTD is the register for the state of the outputs. For example;
PORTD = B10101000; // sets digital pins 7,5,3 HIGH

You will only see 5 volts on these pins however if the pins have been set as outputs either by using the DDRD register directly or by using the  pinMode() function.
For analog read
You just need to include the headers and start using the registers. They hold the equivalent hexadecimal values for your microcontroller. And the procedure is described in the datasheet. All you have to do is to translate it to code.
// this code scans ADC1 for an analog signal upon request, using 8Mhz processor clock

#include <avr/io.h>
#include <stdint.h>       // needed for uint8_t

int ADCsingleREAD(uint8_t adctouse)
{
    int ADCval;

    ADMUX = adctouse;        // use #1 ADC
    ADMUX |= (1 << REFS0);   // use AVcc as the reference
    ADMUX &= ~(1 << ADLAR);  // clear for 10 bit resolution

    // 128 prescale for 8Mhz
    ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

    ADCSRA |= (1 << ADEN);    // Enable the ADC
    ADCSRA |= (1 << ADSC);    // Start the ADC conversion

    while(ADCSRA & (1 << ADSC)); // waits for the ADC to finish

    ADCval = ADCL;
    ADCval = (ADCH << 8) + ADCval; // ADCH is read so ADC can be updated again

    return ADCval;
}

int main(void)
{
    int ADCvalue;

    while (1)
    {
        ADCvalue = ADCsingleREAD(1);
        // ADCvalue now contains an 10bit ADC read
    }
}

For more information about analog read, see this.

Thank you so much @bpinhosilva (+1) - however, I'm not 100% sure you understand my exact question. Take DDRD for instance. In your code example above you have: DDRD = B11111110. You state that this sets Arduino pins 1 - 7 as OUTPUT. But DDRD is a variable... but what library is it define inside of? In other words, what #include statement do I need to add to my source code to gain access to DDRD? If the answer is one of the Arduino libraries, then this doesn't help me! I need non-Arduino access to the AVR/ARM pins! Thanks again!

I just noticed your 2nd code sample above includes avr/io.h - if you can confirm that DDRD (and other similar port/register vars) are defined in this file, I think I'm all set!

You use #include <avr/io.h>. This is a standard library for avr units. Inside that you find definitions for these registers. Other point is that I am assuming you use Arduino but want to develop with a different IDE. So you need to find the equivalent avr pin to your board's labels. That's why the code says Arduino pinx and so on.

These names are not variables, they are mnemonics for addresses so you can easily remember them. You are welcome!

Thanks again @bpinhosilva (+1 again) - last followup question: I am wondering what the equivalent is for ARM registers. I found this EE.SE question but no one has answered it. Any idea what I would use for an ARM MCU? Thanks again!

I have never used ARM before, but I think it is similar. Just take a look at the datasheet and then you will see the gpio pins. And probably there is a lib similar to avr/io for your usage.

source: Stack Exchange

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

sort: votes


text:
Problems uploading sketch to Arduino Due
Windows 7 here. I just bought an Arduino Due and downloaded the Arduino IDE. I wrote a simple "blink LED" program (see below) and am trying to flash it to the Due.
When I connected the Due to my laptop (via micro USB cable), I got a warning on my laptop that it could not find the correct device driver. So I followed the instructions discussed on this excellent video tutorial and went into Control Panel >> System >> Device Manager >> Arduino and pointed it to load the appropriate device driver from C:\Program Files (x86)\Arduino\drivers. This got rid of the warning. Hooray!
I then Verified & Compiled my program:
int led = 13;

void setup() {
    pinMode(led, OUTPUT);
}

void loop() {
    digitalWrite(led, HIGH);
    delay(5000);
    digitalWrite(led, LOW);
    delay(5000);
}

Great success! Now it was time for me to upload the program to my Due. The first time I tried to upload it, I got the following error:
Arduino: 1.6.4 (Windows 7), Board: "Arduino Uno"
Sketch uses 1,068 bytes (3%) of program storage space. Maximum is 32,256 bytes.
Global variables use 11 bytes (0%) of dynamic memory, leaving 2,037 bytes for local variables. Maximum is 2,048 bytes.
avrdude: ser_open(): can't open device "\\.\COM1": The system cannot find the file specified.

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

    This report would have more information with
    "Show verbose output during compilation"
    enabled in File > Preferences.

So then in the IDE I went to Tools >> Port and changed the selection from Serial to COM3 (again, sort of explained in that video tutorial). I tried to upload again:
Arduino: 1.6.4 (Windows 7), Board: "Arduino Uno"
Sketch uses 1,068 bytes (3%) of program storage space. Maximum is 32,256 bytes.
Global variables use 11 bytes (0%) of dynamic memory, leaving 2,037 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x09

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

    This report would have more information with
    "Show verbose output during compilation"
    enabled in File > Preferences.

I thought it was interesting that the IDE thinks this is an Arduino Uno. So then I went to Tools >> Board and changed the selection from Uno to Duemilanove, hoping that Due and Duemilanove are compatible for the programmer/flasher tool. This time the error was the same as last, except the first line reads:
Arduino: 1.6.4 (Windows 7), Board: "Arduino Duemilanove or Diecimila, ATmega328"

So at least the IDE is switching board correctly. :-) I should note that my Tools >> Board menu does not have an "Arduino Due" option. And when I go to Tools >> Board >> Board Manager, searching for Due does not turn up anything either.
I also tried running the upload with verbose output, but that really didn't tell me anything more. I'm happy to post the exact verbose output but figured I could omit it here for brevity. I also did peruse the troubleshooting link that the error output recommends, but it looks like I've already exhausted all of those recommendations as well.
I'm stuck and frustrated, any suggestions?
What do I need to do to get the IDE programming my Due?

... hoping that Due and Duemilanove are compatible for the programmer/flasher tool.

Not even close. You will need to go into the Boards Manager and download and install the SAM support files, select the Due from the list, and then upload the sketch.

Thanks @Ignacio Vazquez-Abrams (+1) - you got me half-way there. After installiing the Arduino SAM Boards, the Tools >> Board menu gives me two Arduino Due options: Arduino Due (Programming Port) and Arduino Due (Native USB Port). What are these, what's the difference between them, and which one do I want? Thanks again!

I'm not entirely certain, except that they use different physical ports on the board itself.

Programming Port it is! Thanks again!

Yes, I just had this problem myself..
Unless you use the Boards Manager Menu and install the Arduino SAM Boards (32Bits ARM cortex M3) board info you will not be able to upload your sketch.
After installing in the Boards Manager you will see the Arduio Due programming port and Arduino Native port as an extra options at the bottom or the TOOLS>BOARD menu.
That should fix the problem.(Check which you are connected to and which COM port)
If you still have trouble, disconnect and reconnect the DUE and restart the IDE and if required restart you computer.
This seems to be a common problem when people switch from the Uno or MEGA to the Due. I'm surprised this is not installed as standard in the IDE. I am using 1.6.5r2.
Thanks also to Ignacio Vazquez-Abrams.

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


text:
Writing C Program outside of Arduino IDE?
I like the idea of using the Arduino IDE for simple projects and for getting started with Arduino, but the consensus I've gotten so far is that it is for those who are new to Arduino and/or programming in general.
My understanding is that it is possible to write a C program from scratch, completely outside of the Arduino IDE, and then use a tool like AVRDUDE to upload it to an Arduino MCU. This option, albeit appealing and interesting, leaves me with a few concerns:

What Arduino libraries would need to be imported/linked by such a "raw C" program? I assume that when an Arduino IDE-based program executes a digitalWrite(...) it is really calling a C lib, probably provided by Arduino, under the hood. I am concerned about making sure all these "underlying libs" get included with my C program. Thoughts?
Is anything else "lost" by flying solo and venturing outside the Arduino IDE? Any capabilities/features that I would now have to "roll my own"?

http://arduino.stackexchange.com/questions/9538/using-an-arduino-board-to-program-an-avr
The answers on my question helped me to set it up.
You can replace/leave out anything from arduino.
You can: -Make your own board. -Use your own IDE. -Use your own libraries.

Here you are two nice articles how Arduino actually works in background. How it removed friction from microcontroller  programming.

A Tour of the Arduino Internals: How does Hello World actually work?
Arduino and GCC, compiling and uploading programs using only makefiles

It was also discussed here Is there a way or tutorial for converting Arduino code to C code?

Thanks @Michal Foksa (+1) - I guess I'm just shocked that the answer to this isn't much more well known! I would have thought that the Arduino IDE had, say, a lib/ directory somewhere under its installation root that had things like arduino-core.dll, arduino-io.dll, etc.

@smeeb: You're correct, the Arduino IDE installation does - has to - include libraries of the basic run-time functions plus user supplied ones. Halfway down the page of link 2, in the makefile, the symbol LIBS points to them. They aren't .dlls (which in Windows, are called at run-time); they are object files (.o under unix-like systems, probably the same under Windows) that are statically linked with your compiled object files into (ultimately) a .hex load file, which is the complete loader image. ...

... It is well known to people who write programs for a living, but the Arduino (brand) tool designers have deliberately hidden as many of the messy details as possible to make applying digital electronics available to people without them having to become professional level programmers and engineers to do it. To the extent you're finding this information hard to find in the Arduino community, they've been successful!

You're absolutely right about needing to link against other libraries. However, you don't necessarily need to worry about all of the details yourself, unless you want/need to do something unusual. Several alternative IDEs already support Arduino, typically via plugins which handle a lot of the details automatically.
I normally recommend Eclipse as it's a very widely used IDE for various purposes. However, there are several other possibilities. See this question for more information:

What are the other IDEs for Arduino?

Thanks @Peter R. Bloomfield (+1) - however I'm really looking for a non-IDE centric answer. Not that I have anything against IDEs, it's just that in order to understand the "library landscape" of Arduino, I feel like IDEs are just an unnecessary middle man. Having said that, I would assume that there are 1+ "core libs" that ALL Arduino apps must link with, and that there are then optional libs that you may or may not need, depending on what your app actually does.  Can you point me to a list of these "core libs", as well as any other optional ones? Thanks again!

And to qualify what I was saying above about IDEs being "unnecessary middlemen", what I really mean is: I should be able to write a C app outside of any IDE (Arduino, Eclipse, or otherwise), link to the Arduino libs that my app needs, and still compile/deploy the app to Arduino hardware. I'm wondering what those libraries are, and where I can find documentation on them.

@smeeb Given that Arduino is aimed at beginners, I don't think there's much (if any) official documentation along those lines. I expect the best way to research it would be to search online for examples of Arduino makefiles. There are some old examples near the bottom of this page.

@smeeb: Like you, I am not fan of IDEs. There are a few generic Arduino makefiles floating on the Web. You basically have to compile the Arduino core library into libore.a, then compile your .ino file with -x c++ -include Arduino.h for your compiler to understand it (plus a bunch of -D, -I, etc) and link with libcore.a.

Yes, you can write a program outside Arduino IDE.
For example I tried Eclipse IDE with AVR plug-in and now I stick with AVR Studio. Of course,you won't have some functions that you maybe usually use when you write in Arduino IDE and also some libraries. But, why not to try implementing stuff. Why to limit yourself to functions and libraries made by others when you can learn and write your owns, maybe better than the existing ones.


text:
Arduino SoftwareServo by example
I am interested in writing a simple Arduino program that will turn a servo back and forth (180 degrees each time) continuously.
I am looking at these servos and am planning on following this example.
Being so new to Arduino, I first wanted to confirm that the SoftwareServo library in that example will drive those particular servos. If it will not, then can someone begin by explaining to me why these servos are incompatible with the lib?
Assuming they are compatible, I am looking at the main example on that page (comments stripped out for brevity):
#include <SoftwareServo.h>

SoftwareServo myservo;

int potpin = 0;
int val;

void setup() {
    myservo.attach(2);
}

void loop() {
    val = analogRead(potpin);
    val = map(val, 0, 1023, 0, 179);
    myservo.write(val);
    delay(15);

    SoftwareServo::refresh();
}

My concerns:

There seem to be 3 pins involved here: a potentiometer pin (0), an analog pin (val) and a servo pin (2). What is the purpose of each of these pins, and is this 3-pin wiring common across all/most servos?
Is there anything "wrong" with defining myservo.attach(2); up above the setup function, and leave the setup function an empty no-op function?
Where does the map(...) function come from? If it was defined inside SoftwareServo I would have expected its usage to be something like SoftwareServo::map(...), etc.
Why do we need the delay after calling myservo.write(val);? What would happen if this delay wasn't in there?
According to that link, calling SoftwareServo::refresh() once every 50ms is necessary in order to: "keep your servos updating." But what does this mean, really? Updating to what?!?

There seem to be 3 pins involved here: a potentiometer pin (0), an analog pin (val) and a servo pin (2). What is the purpose of each of these pins, and is this 3-pin wiring common across all/most servos?

No, there is only 2 pins.  The value of the potentiometer attached to pin 0 is read and stored in the variable val.  That is then used to set the angle of the servo motor on pin 2.

Is there anything "wrong" with defining myservo.attach(2); up above the setup function, and leave the setup function an empty no-op function?

Yes.  It'll never get called.  setup() is the first function to be called and its purpose is to perform any initialization routines, such as attaching the servo code to the pin the servo is connected to.  So you have to call that either from setup() or from a function which setup() itself calls.

Where does the map(...) function come from? If it was defined inside SoftwareServo I would have expected its usage to be something like SoftwareServo::map(...), etc.

map() is part of the standard Arduino API.  http://www.arduino.cc/en/Reference/Map

Why do we need the delay after calling myservo.write(val);? What would happen if this delay wasn't in there?

You don't need the delay() call, but you don't want to set the value of the servo too rapidly.  You really want to allow at least one PWM cycle between each call to ensure the values have been set properly.

According to that link, calling SoftwareServo::refresh() once every 50ms is necessary in order to: "keep your servos updating." But what does this mean, really? Updating to what?!?

SoftwareServo is just what it says - a piece of software.  You have to run that software for it to work, and the refresh() function is that bit that you run.  If you don't call that then the PWM signal for the servo will never get generated and nothing will happen.
Oh, and yes those little servos should be fine.

1- there is only two pins a servo pin which is D2 and an analog pin which is A0. D2 pin for writing analog value to servo. D2 pin is used for getting analog pin value.
2- map function is a default function like sin, cos or digitalRead so library inport not necesary.
3- delay function and waiting 50ms is used to wait servo response time. if you change servo angle too quickly servo will not respond accurately


text:
Connecting battery and LED to Arduino Due
I am brand new to Arduino/robotics and am trying to take baby steps. First I'd like to just power an Arduino and an LED from a 9V battery like so:

No programming, just simple circuitry. The battery powers the Due, and the Due in turn powers the LED.
A few concerns here:

Will the 9V battery fry the Due, which I believe is expecting 3.3V? If so, what can I do to reduce the voltage/amps?
Will the 9V battery fry the resistor and/or LED?
As you can see by my question marks, I'm not real sure where to connect the battery to the Due (both positive & negative terminals) as well as the where to connect the breadboard to the Due (again, both terminals).

Any ideas?

You can connect the battery to VIN. That way the onboard regulators will bring it down to 5v and 3.3v. If you want to connect the led to the 9v battery directly, you might have to use a bigger resistor value.

What you want is something like this (ignore the fact that my mini breadboard is stuck to a shield):

My starter Arduino kit came with the connector for the 9 volt battery into the power socket on the Arduino, you may need to make one.  You cannot connect the 9V battery to any other part of the Due that I am aware of (without damaging it!).
It is perfectly safe to power your Arduino with 9V this way, there is circuitry to step the voltage down to the 5V and 3.3V that the board requires.
In the connector strip nearest this power socket (labelled Power on my board) there are a couple of Gnd connections and 5V and 3.3V connectors perfect for what you want to do.  I have used the 3.3V connector in my photo, but the 5V one should also be fine with the right resistor.
In your picture you don't appear to have anything connecting the LED to ground, but other than that, if you were to connect the battery up as I have shown and the red and black LED connectors to 3.3V and Gnd respectively, it should work as desired.
As a next step, you could load the sample sketch Examples->01Basic->Blink, write it to your Due, move the red LED connecting wire to pin 13 on the opposite side and your LED would flash (along with one of the LEDs on the Due board itself).
Edit (to specifically address your concerns):

The 9V battery will not fry the Due if it is connected through the power socket, which has circuitry to drop the voltage to safe levels.
The 9V battery will not damage the LED or resistor as they are connected to 5V or 3.3V that the Due outputs, not the 9V from the battery.
Only connect the battery through the power socket.  If you have a good quality steady 5V power supply, you can power the board through a 5V pin (at least I have been able to), but you bypass the voltage regulation circuitry that way and it is not recommended.  Connect the black wire from your LED to any Gnd pin, connect the red wire from the LED to 3.3V or 5V.

Additional edit:
You can connect the battery directly to the Arduino Due board without needing a plug to connect to the power socket.  Connect the red battery wire to the Vin pin and the black battery wire to a Gnd pin.

The only thing I'd add to this thorough answer is, if you connect a barrel plug to your 9v battery (b/c I don't see one in your - OP's - photo) make sure to connect 9v + to the center-pin and 9v - to the outer shell.

Thanks @Mick Waites (+1) - one quick followup question: please see Gerben's comment under my question. Gerben alludes that there is something called Vin which handles non-5V external power supplies. Sure enough, on the Due's website (under Power) they define Vin as: "The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source)." Can you confirm that I could use Vin to power my board directly from the 9V battery? Thanks again!

@smeeb - Gerben is completely right.  I have never used the Vin pin as I use a stable 5V supply for my board in my projects.  The voltage limits for the Vin pin are 6-16V, but 7-12V is recommended.  This saves you having to get a connector for your battery to fit the power socket.  You would connect the + pole of the battery to Vin, and the - pole to Gnd.  You would then connect your black LED/resistor wire to another Gnd pin (it would be difficult to plug 2 wires into the same pin socket, but it would work if you could manage it) and the red LED/resistor wire to a 3.3V or 5V pin.


text:
Arduino Due and Vin, 3.3V and 5V power inputs
I just want to confirm something before I wire up my first ever Arduino project and fry all the stuff I just spent money on.
It is my understanding that the Vin power input will tolerate a 9V battery and use voltage regulators to pare it down to either 3.3V or 5V (as different parts of the board require). So it is then my assumption that if I have a 9V battery running to Vin, that I could then connect a power wire to the 3.3V connector, and reliably get a 3.3V signal (and ditto for 5V), yes?
Or, is it that they are input jacks expecting either 3.3V or 5V signals? I guess I'm confused over this:

Will Vin then power the 3.3V and 5V inputs, giving me access to voltage at that level; or
Do I have to choose between 3.3V, 5V or Vin, and only use one of those to power my board (with the appropriate voltage level)

Have you checked the schematic yet?

If you can provide a schematic I'll check it out and maybe it answers my question, but I'm so new to electronics, I may not even be able to make sense of it.

All Arduino product pages link to a schematic for the board.

Then I would assume this is what you mean, in which case, I cannot at this exact moment make sense of it. And although I think I can guess your next argument, which is probably "Well then you need to learn how to read schematics, otherwise get out of electronics", I would counter-argue that Arduino is from the ground-up aimed at complete electronics newbies like myself. And that this is a basic usage question that should be answer-able without a moderate understanding of EE/ECE.

And yes, in time, I will learn this stuff, but I shouldn't have to be able to read that diagram and fully comprehend it to understand how to connect my board to a battery.

The power subsections are on the bottom right of the page. Unmarked, of course, because that's how Arduino rolls.

DC Jack is connected, through a diode, to Vin.
Vin is stepped down to 5V on-board.
5V is stepped down to 3V3 on board.
Thus you can do any one of the following numbered items.

Connect a 7-12V supply to the DC Jack; thus:

use Vin as a supply @ DC - 0.7V for off-board peripherals, and
use 5V as a supply for off-board peripherals, and
use 3V3 as a supply for off-board peripherals.

Connect a 6-12V supply to Vin; thus:

use 5V as a supply for off-board peripherals, and
use 3V3 as a supply for off-board peripherals.

Connect 5V supply to the 5V; thus:

use 3V3 as a supply for off-board peripherals.

The above is only guaranteed for boards that follow the reference schematic, as plenty of clone/compatible boards do. If you buy a cheap Chinarduino and something doesn't work, or the thing breaks, after following anything above then that's your tough luck.

Yes your assumption is correct you can power 3.3v and 5v items from those pins as long as you don't take more current than the onboard regulator(s) can supply


text:
Blinking LEDs as fast as possible at different rates.
I'm trying to use the Arduino Uno to make a strip of LEDs blink as fast as they can while still blinking at different rates. I am able to get them blinking at different rates but the blinking is very slow:
#include <Adafruit_DotStar.h>
#include <SPI.h>         // COMMENT OUT THIS LINE FOR GEMMA OR TRINKET

#define NUMPIXELS 144 // Number of LEDs in strip

// Here's how to control the LEDs from any two pins:
#define DATAPIN    11
#define CLOCKPIN   13
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN);

void setup() {
strip.begin(); // Initialize pins for output
strip.show();  // Turn all LEDs off ASAP
}

  int brightness = 1; //Setting brightness of all LEDs

   void loop() {

  for(int i=1; i<6; i++)
//This loop is here so the number i can be used below to get different blink     //rates for the 3 LEDs blink at the same time
  {
    if(i%2==0){

    strip.setPixelColor(0, brightness, brightness, brightness);
    }
    else
    {strip.setPixelColor(0, 0);
    }
    //Sets blink rate of first LED, will be the fastest

    if(i%3==0){

    strip.setPixelColor(1, brightness, brightness, brightness);
    }
    else
    {strip.setPixelColor(1, 0);
    }
     //Sets blink rate of second LED

    if(i%4==0){

    strip.setPixelColor(2, brightness, brightness, brightness);
    }
    else
    {strip.setPixelColor(2, 0);
    }
     //Sets blink rate of third LED

   strip.show();
  }
  }

I thought I would be able to make them blink as fast as possible by using the micro() function as my counter instead of the i in the for loop, but this led to strange behavior:
#include <Adafruit_DotStar.h>
#include <SPI.h>

#define NUMPIXELS 144 // Number of LEDs in strip

// Here's how to control the LEDs from any two pins:
#define DATAPIN    11
#define CLOCKPIN   13
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN);

void setup() {

  strip.begin(); // Initialize pins for output
  strip.show();  // Turn all LEDs off ASAP

  Serial.begin(9600);
}

int brightness = 1;

void loop() {

    int time = micros();

    if(time%2==0){

    strip.setPixelColor(0, brightness, brightness, brightness);
    }
    else
    {strip.setPixelColor(0, 0);
    }

  if(time%3==0){
    strip.setPixelColor(1, brightness, brightness, brightness);
    }
    else
    {strip.setPixelColor(1, 0);
    }

   if(time%4==0){
    strip.setPixelColor(1, brightness, brightness, brightness);
    }
    else
    {strip.setPixelColor(2, 0);
    }

   strip.show();
}

This led to the first LED appearing on (good, presumably I wouldn't be able to see it blinking) and the second blinking at a rate I could see (I shouldn't be able to see this) and the third LED is not on at all.
Can anyone see the mistake I'm making? Am I using the micro() function right?
Thank you!

1 microsecond is only 16 clock-cycles. Your loop function will take a lot more that 1 microsecond to complete. Instead just declare int time=0; outside the loop and increment this variable at the end of the loop function (time=time+1). That way you don't skip any values for time.

Thank you. So basically I can't make my fastest blinking LED blink at half the frequency of the clock in the Arduino? I'm limited by how fast the loop can execute. Thanks a lot :)

Blinking an led at 8Mhz is useless (human eye can see anything faster than 150hz), and probably impossible (due to gate capacitance of the output pins)


text:
Do multiple ultrasonic sensors need an external power source?
So maybe it's a very low class form of question, but please bear with me. I'm working on a project with 7 HC-SR04 ultrasonic sensors connected to one Arduino. I tried to unify the trigger and echo pin, but the sensing isn't good enough, so I dropped the Uno and convert it to Mega. My question is, do I need external power source for those 7 Sensors? And how do I connect all of them? Thanks

Well, according to the datasheet the "working current" is 15mA.  Even if you had all 7 working at once, which I doubt you will - you'll be working through them in sequence I guess - that would be just 105mA - way below the 800mA the Arduino's on-board regulator can supply, and only a fifth of what a USB port can provide.
The datasheet doesn't mention the quiescent (idle) current, but it will be a tiny fraction of that 15mA and so can mostly be ignored.  Running the sensors in sequence, which is the most likely scenario, would use about the same amount of current as if you had 1 sensor - or 20 sensors.  Most of the current consumption would be while you are actively producing an ultrasonic chirp.
So no, you don't need an external power supply to run them all - just take them all from the Arduino's 5V pin.

Well, I'm working on an Obstacle avoidance, but yeah, I can only make a sequential code for all of them. Is it possible to make them work all at once?
But, either way, I still didn't need the external power supply, right?
Thanks for your answer though :D

Either way it's still way below what the Arduino can supply, so no need for an extra supply, no.

You will probably not have any kind of problem with the Arduino power source, while in the test bench. When using it for the Drone/Bot you seem to be working, make sure to have a stable power source to the Arduino, and, if possible, let your sensors have their own energy input.
I had previous experiences with the sensors not working properly because the Arduino was not getting enough energy through the Arduino's pins when mounted.


text:
7 Segment display dimming
I've got project that needed to have some (4) digits display, and had plenty of 7 seg. displays lying around. I didn't have any multiplexers left but have instead wired it up as per this diagram:

I've the wired my duemilanove with the a-dp pins on the 13-6, and the transistors on 5-2.
Getting the right segments on has been a breeze, but I'm finding that if I have any kind of counting logic, the displays dim to about 20%.
What I mean by this is that I can have my sketch run with all digits full brightness displaying 8s no problem, but if anywhere in the loop I have a variable that I increment up (say by incrementing up 1 per loop), and change nothing else, the display will go from 100% brightness, to 20% (at best).
Below is the demo code I'm using (there are tons of weird things in it at the moment as I've been desperately trying to track this dimming issue down), and all I have to change to see the effect take place is to uncomment the line at the end of the loop: "//count = count + 1;"
const int sub_delay = 1000;

const int middle_middle = 13;
const int middle_top = 11;
const int middle_bottom = 8;

const int top_left = 12;
const int top_right = 10;
const int bottom_left = 9;
const int bottom_right = 7;
//Build the digit quick table

int digits_all[] = {top_left, top_right, middle_top, middle_bottom, bottom_right, bottom_left, middle_middle};
int digits0[] = {top_left, middle_top, top_right, middle_bottom, bottom_right, bottom_left};
int digits1[] = {top_right, bottom_right};
int digits2[] = {middle_top, middle_middle, middle_bottom, top_right, bottom_left};
int digits3[] = {middle_top, middle_middle, middle_bottom, top_right, bottom_right};
int digits4[] = {};
int digits5[] = {};
int digit_selector0 = 2;
int digit_selector1 = 3;
int digit_selector2 = 4;
int digit_selector3 = 5;
int digit_selectors[] = {digit_selector0, digit_selector1, digit_selector2, digit_selector3};

int last = digits_all;
int last_size = sizeof(digits_all);
int last_selector = digit_selector0;

String test = "12, 13, 10, 8, 7, 9";

int count = 0;

// the setup function runs once when you press reset or power the board
void setup() {
  //Initialize the digit segments
  for (int c = 0; c < sizeof(digits0); c++) {
    //digitalWrite(digits0[c], HIGH);
    pinMode(digits0[c], OUTPUT);
  }

//demo
  //digitalWrite(middle_middle, HIGH);
  //digitalWrite(top_left, HIGH);
  //digitalWrite(middle_top, HIGH);
  //digitalWrite(top_right, HIGH);
  //digitalWrite(bottom_left, HIGH);
  //digitalWrite(middle_bottom, HIGH);
  //digitalWrite(bottom_right, HIGH);

    Serial.begin(9600);

}

void turn_off_all (int digit, int digits[], int digits_size, int num) {

  last = digits;
  last_size = digits_size;

  digitalWrite(last_selector, LOW);
  last_selector = digit;

  digitalWrite(digit, HIGH);
int temp = 1;
  if (num == 0) {
    digitalWrite(top_left, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(bottom_left, HIGH);
    digitalWrite(middle_top, HIGH);

    digitalWrite(middle_middle, LOW);
  }

  if (num == 1) {
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);

    digitalWrite(top_left, LOW);
    digitalWrite(middle_bottom, LOW);
    digitalWrite(bottom_left, LOW);
    digitalWrite(middle_top, LOW);
    digitalWrite(middle_middle, LOW);
  }

  if (num == 2) {
    digitalWrite(middle_top, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_left, HIGH);

    digitalWrite(top_left, LOW);
    digitalWrite(bottom_right, LOW);
  }

  if (num == 3) {
    digitalWrite(middle_top, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);

    digitalWrite(top_left, LOW);
    digitalWrite(bottom_left, LOW);
  }

  if (num == 4) {
    digitalWrite(top_right, HIGH);
    digitalWrite(top_left, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(middle_middle, HIGH);

    digitalWrite(middle_bottom, LOW);
    digitalWrite(middle_top, LOW);
    digitalWrite(bottom_left, LOW);
  }

  if (num == 5) {
    digitalWrite(top_left, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_top, HIGH);

    digitalWrite(top_right, LOW);
    digitalWrite(bottom_left, LOW);
  }

  if (num == 6) {
    digitalWrite(top_left, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(bottom_left, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_top, HIGH);

    digitalWrite(top_right, LOW);
  }

  if (num == 7) {
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(middle_top, HIGH);

    digitalWrite(bottom_left, LOW);
    digitalWrite(middle_bottom, LOW);
    digitalWrite(middle_middle, LOW);
    digitalWrite(top_left, LOW);
  }

  if (num == 8) {
    digitalWrite(top_left, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(bottom_left, HIGH);
    digitalWrite(middle_bottom, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_top, HIGH);
  }

  if (num == 9) {
    digitalWrite(top_left, HIGH);
    digitalWrite(top_right, HIGH);
    digitalWrite(bottom_right, HIGH);
    digitalWrite(middle_middle, HIGH);
    digitalWrite(middle_top, HIGH);
    digitalWrite(middle_bottom, HIGH);

    digitalWrite(bottom_left, LOW);
  }

}

// the loop function runs over and over again forever
void loop() {

    turn_off_all(digit_selector0, digits0, sizeof(digits0), 1);
  delay(1000);

  //count = count + 1;

}

Any suggestions welcome!
Extra notes: I haven't yet tried another arduino board, but I've never had issues with this particular board before (Though I am hoping to switch to an ESP8622, but that is irrelevant to this issue).

You can try to change "digitalWrite" into directly assign to the PORT. It will be a lot more efficient

It is often because of a lack of current. Use an external 5V supply some good enough current.

I'm definitely open to it being a current issue, but that doesn't explain why it would only occur if I start counting (or seemingly any other math op)

@dpw: I'll look into that and see if the increased efficiency helps at all

I don't see how count is relevant to the function. Is this also the same code you used to turn on all the segments?

Have you tried  adding a few capacitors (plus other sundry components) to give it extra power?

@TisteAndii, it certainly is, minus the extra 3    turn_off_all(digit_selectorX, digitsX, sizeof(digitsX), 8); .
And I completely agree, the two things have nothing to do with each other, except when I uncomment the count increment-er the displays dim...

@DatHanBag: I'll give it a go and see if that helps!

@ShaneGadsby Tell us how much it helps-if you need more help with capacitor idea after trying it- ask here-we'll find the solution

The caps didn't seem change anything, thanks for the suggestion

You seem to be trying to do this from scratch. I haven't analysed the code, but you would be better off using one of the established libraries.
The code is unclear - I am not sure what much of it is trying to do (a few comments would help). There are obvious errors - in particular the incorrect use of sizeof() which is a common error.
I use the following http://playground.arduino.cc/Main/SevenSegmentLibrary
This just requires a single call to set the digits to be displayed and includes a Brightness call.

I did start with this, and seemed to have the same results, so I went the manual route to see if that pinpointed the issue; I'll try it again just to be extra sure however!

If you posted your original code using the library it would be easier to debug. Also add some comments.

Further to the wrong use of sizeof: if I change it from that I get the dimming issues again, haha, which is even more puzzling...
I'll re-write it with the 7-seg lib and post it (assuming it still fails), and yeah, more comments == more better

I assume you are trying to get the number of elements. The correct use would be (sizeof(digits0)/sizeof(int))

I didn't get it working how I wanted it to with this library, but it certainly is the better option over all - thanks again for showing me the correct usage of sizeof!

If, as comments suggest, the problem also occurs when you are using a library, it's possible the problem is hardware related.  The 10KΩ base resistors are inordinately large, and are so large the transistors probably are limiting the total current per display to under 50 mA.
When you turn on one of d2 ... d5 (your digit-select drives), at most half a milliamp (5V/10KΩ) will enter the base.  If transistor beta is 100, that will allow 50 mA to flow.  (Not knowing the transistor type you used, I don't know its range of betas.)
Consider replacing the 10KΩ base resistors with 500-700 Ω resistors.
I see no place in the circuit where capacitors would make any positive difference.


text:
Arduino analog joystick
I'm planning to make a handbrake for my racing simulator (Assetto Corsa) and I wanted to know how can I transform arduino into a joystick so the game can read the analog input?
Thanks in advance, and sorry for my bad english.

You would need some sort of Human Interface working on your computer. A Leonardo should work but you would have to reprogram the HID interface so that it gets recognised by the PC as a Joystick. See this page for some info on how to use the potentiometer joystick.

I made this video and github just for this about a year ago.

And here is the code:
/*
2-axis joystick connected to an Arduino Micro
to output 4 pins, up, down, left & right

If you are using pull down resistors, change all the HIGHs to LOWs and LOWs to HIGH.
This skectch is using pull up resistors.

*/

int UD = 0;
int LR = 0;
/* Arduino Micro output pins*/
int DWN = 13;
int UP = 12;
int LEFT = 11;
int RT = 10;
/* Arduino Micro Input Pins */
int IUP=A0;
int ILR=A1;

int MID = 10; // 10 mid point delta arduino, use 4 for attiny
int LRMID = 0;
int UPMID = 0;
void setup(){

  pinMode(DWN, OUTPUT);
  pinMode(UP, OUTPUT);
  pinMode(LEFT, OUTPUT);
  pinMode(RT, OUTPUT);

  digitalWrite(DWN, HIGH);
  digitalWrite(UP, HIGH);
  digitalWrite(LEFT, HIGH);
  digitalWrite(RT, HIGH);

  //calabrate center
  LRMID = analogRead(ILR);
  UPMID = analogRead(IUP);
}

void loop(){

  UD = analogRead(IUP);
  LR = analogRead(ILR);
  // UP-DOWN
  if(UD < UPMID - MID){
   digitalWrite(DWN, LOW);
  }else{
   digitalWrite(DWN, HIGH);
  }

  if(UD > UPMID + MID){
   digitalWrite(UP, LOW);
  }else{
   digitalWrite(UP, HIGH);
  }
  // LEFT-RIGHT
  if(LR < LRMID - MID){
   digitalWrite(LEFT, LOW);
  }else{
   digitalWrite(LEFT, HIGH);
  }

  if(LR > LRMID + MID){
   digitalWrite(RT, LOW);
  }else{
   digitalWrite(RT, HIGH);
  }

  delay(400);

}

This is not what I meant. I want to connect the arduino to my computer and use it to control the handbrake in my game. I want to make my computer recognize the arduino as a controller. But thanks for replying =D

You can use my example as a starting point. However  I would assume you will need to create a customer driver for "Assetto Corsa".

Everything was just handed to you except for the PC side. Now you need to ask yourself: What does the game need for input: text? a logic signal? How can it receive input - through a serial port? The kbd only? Bluetooth? How can I provide that from what the Arduino and @PhillyNJ's code and diagram already make available - text messages to the serial port? Logic signals to RTS and DTR of 2 serial ports? Patch into the keyboard cable? (If your difficulty is on the PC side, this is probably not the right place to get help).

Never tried it with the Arduino, but it's quite easy to do with Teensy (which is mostly compatible with Arduino).
Teensyduino actually includes several examples.


text:
Data Logging GPS with Arduino
I am working on a project for my final in a first year programming course at my high school. I would like to make an Arduino based data logging device that I can bring with my on the mountain biking trails around where I live to create a map. I have found a lot of great sources online but I do not have a small budget. I have an Arduino Uno and a breadboard. My first question is whether it is easy to interface between an Uno and my phone for data logging, or if it would just be easier to buy a microSD card shield? And I need help finding a GPS unit. I have no preference and size is not really a problem. I just need to know how to interface with the Uno. Also if you have any links to other sources I can use that would be greatly appreciated!

I've been looking at the same problem, and there is a lot of new stuff now that may still count as a DIY project, but cut out a lot of the leg-work.
On kickstarter there are a lot of new boards that can make it easy:
Here is a ready to go GPS tracking band:
https://www.kickstarter.com/projects/blipperbands/blipper-bands-safety-wherever-you-go?ref=nav_search
Spark-IO has a board that gives you 20,000 messages per month, so you could use it instead of a cellphone to send out the data.
https://store.particle.io/?product=particle-electron
U-Blox makes gps higher-end consumer GPS units that are used in autonomous drones.
There are also a lot of instructables that show how to do the GPS datalogging with while building a drone. These would be small enough and light enough to use while cycling.


text:
Why the bootloader burn on ATmega328 rather than Atmega16U2 in Arduino Uno
I have been researching about the reason why we have a second MCU in arduino UNO for a while now. finally i understood that its been use as  USB to serial converter. the question that really bug me now, why is the boot-loader is burn on the main ATmega328 not Atmega16U2 ?

The purpose of the bootloader is to get the firmware through the serial
port and burn it into the flash. The 16U2 has no access to the 328's
flash. The job has to be done in the 328 itself.

The normal AVRProgrammer dose not require a bootloader  to burn the code to any  ATmega, why then the Atmega16U2 need the help of the bootloader ?. cant just do the job as any other AVRprogrammer ?

It probably could, but it would need to be connected to more lines of the 328, it would also need more complex firmware, doing double duty of USB to serial interface and ISP programmer.

@Akkilah: It is also worth noting that the 16U2 replaces an FTDI that was used in previous versions of the Arduino board.

so the more complex firmware that  need to be used, it will be used in the 16U2 not  the 328 , did I understood u correctly ?

worth nothing ( the replacement of FTDI with 16U2 )  in sense that we will still need the use of boot loader and there is no advantages that happen because of the replacement  ?

You understood correctly. The only advantage of the 16U2 is that you can reprogram it via ISP if you want to emulate, say, a mouse or a keyboard. A Leonardo would probably be more convenient for that, though.


text:
Not able to make my NrF24L01 work
I have been trying to make my two Nrf24L01 wireless model work for few days now, to do so I follow the tutorial in the following link.
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
I followed the link exactly, i changed nothing, expect i didn't add the bypass capacitor , as they said it will improve the performance and reduce heat, however mine is not working at all.
here is a pictures of my hardware setup ,

for the code i didnt change any this from the tutorial but i will past it to make it easy to follow Transmitting code
 /* YourDuinoStarter Example: nRF24L01 Transmit Joystick values
 - WHAT IT DOES: Reads Analog values on A0, A1 and transmits
 them over a nRF24L01 Radio Link to another transceiver.
 - SEE the comments after "//" on each line below
 - CONNECTIONS: nRF24L01 Modules See:
 http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
 1 - GND
 2 - VCC 3.3V !!! NOT 5V
 3 - CE to Arduino pin 9
 4 - CSN to Arduino pin 10
 5 - SCK to Arduino pin 13
 6 - MOSI to Arduino pin 11
 7 - MISO to Arduino pin 12
 8 - UNUSED
 -
 Analog Joystick or two 10K potentiometers:
 GND to Arduino GND
 VCC to Arduino +5V
 X Pot to Arduino A0
 Y Pot to Arduino A1

 - V1.00 11/26/13
 Based on examples at http://www.bajdi.com/
 Questions: terry@yourduino.com */

 /*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10
#define JOYSTICK_X A0
#define JOYSTICK_Y A1

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe

/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int joystick[2];  // 2 element array holding Joystick readings

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
 }//--(end setup )---

 void loop()   /****** LOOP: RUNS CONSTANTLY ******/
 {
  joystick[0] = analogRead(JOYSTICK_X);
  joystick[1] = analogRead(JOYSTICK_Y);

   radio.write( joystick, sizeof(joystick) );

   }//--(end main loop )---

  /*-----( Declare User-written Functions )-----*/

  //NONE
  //*********( THE END )***********

Receiving code :
/* YourDuinoStarter Example: nRF24L01 Receive Joystick values

 - WHAT IT DOES: Receives data from another transceiver with
   2 Analog values from a Joystick or 2 Potentiometers
   Displays received values on Serial Monitor
 - SEE the comments after "//" on each line below
 - CONNECTIONS: nRF24L01 Modules See:
 http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
   1 - GND
   2 - VCC 3.3V !!! NOT 5V
   3 - CE to Arduino pin 9
   4 - CSN to Arduino pin 10
   5 - SCK to Arduino pin 13
   6 - MOSI to Arduino pin 11
   7 - MISO to Arduino pin 12
   8 - UNUSED

 - V1.00 11/26/13
   Based on examples at http://www.bajdi.com/
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe

/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int joystick[2];  // 2 element array holding Joystick readings

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  delay(1000);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();;
}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  if ( radio.available() )
  {
    // Read the data payload until we've received everything
    bool done = false;
    while (!done)
    {
      // Fetch the data payload
      done = radio.read( joystick, sizeof(joystick) );
      Serial.print("X = ");
      Serial.print(joystick[0]);
      Serial.print(" Y = ");
      Serial.println(joystick[1]);
    }
  }
  else
  {
      Serial.println("No radio available");
  }

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/

//NONE
//*********( THE END )***********

The output result on the serial is No radio available
dose anyone know where i can go from here ?
or how i can debuge such a problem ?
i dont even know if the problem is with the sender or receiver or both of them

If you can get rid of that lump of ribbon cable it might help - ribbon cable is really not conducive to SPI.  You could also try reducing the SPI clock speed to compensate for the ribbon cable.

"No radio available" means there is a wiring issue.

@Majenko : I tried to slow down SPI  as you see in the code below
void setup()    /****** SETUP: RUNS ONCE ******/     {        Serial.begin(9600);        Serial.println("Nrf24L01 Transmiting  Starting");        radio.begin();        SPI.setClockDivider(SPI_CLOCK_DIV8) ;        radio.openWritingPipe(pipe);      }//--(end setup )---
however taking out ribbon cable i will need few days to do that as i need need to go and buy some cable   :(

@Gerben : then what if there is no transmitter , what should the receiver output  look like in the serial monitor ?

My bad. That's the wrong function for checking connection. Try this if( !radio.isPVariant() ) Serial.println("No SPI connection");

@Gerben : I check my SPI connection by the function u give me and no hope . :(

@Majenko : i have change the wire to normal one but still same result

@Majenko it worked , it was the capacitor , after i aadded it it just worked .im crying right now

@Gerben :) it work after i added the capacitor :)

Just added a 47uf capacitor to the pin 1 and 2 in  NF24L01 ,then every thing worked fine
this is the new setup .

Ideally the capacitor should be soldered on pins 1 and 2 or as close to them as possible. Long jumper wires, in a sense, defeats the purpose of it. You might wan to try that and eliminate the breadboards.

If adding a 47uF capacitor between the 3.3V and GND is not enough to solve your problem, try to:

power the NRF24 through a 3.3V voltage regulator (like a LM1117T-3.3) and power the voltage regulator (NOT the NRF24) through the Arduino's 5V pin. Indeed, the Arduino 3.3V pin is limited to 150mA output, while the the 5V pin can provide you about 400mA.
don't use a breadboard: the NRF24 chip is very sensitive, so try to connect it directly to the board through jumpers or PCB / perf-board.
Add to your code the line:
radio.setPALevel(RF24_PA_MIN);

and check if it works in that way; if it does, the issue is probably about the chip's current consumption.
Hope this helped

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


text:
How can I control neopixels attached to a Digispark?
I want to use a string of Neopixels attached to a Digispark hanging off of a RasPi3 as indicators for various situations.  For example: a motor (connected to a driver hat on the I2C bus of the RasPi) turns on or reverses direction.  Can I use Firmata, or is there something like it for the Digispark that I can use with Python?

It's a ATTiny85, right? The NeoPixel library seems to support it. But it might not be able to control a lot off them. Check the RAM usage and current draw

What is a Digispark? It is a company, no? :)

Digispark is a tiny Arduino compatible (sort of) ATiny85 dev board first released by the company Digistump.  I should have mentioned that I HAVE managed to get Adafruit's strandtest example loaded and working.

Damn edit limitations caught me--The Digispark plugs into a USB port like a dongle, and uses pins 3 and 4 for USB communication, but apparently it's "wierd" in ways I don't quite understand.  There is a deprecated sketch "digiUSB" and a newer one "digiCDC" but they're a little beyond what I grok at this point.  I guess I should take a closer look at them.

You can drive APA102 bases strips from the raspberry pi (though they might need 3.3v to 5v logic level converteren).

Also, I've found a source explaining on how to use the NeoPixels with an Raspberry Pi direclty: http://popoklopsi.github.io/RaspberryPi-LedStrip/#!/ws2812

You need a dedicated microcontroller since you need very precise timing for controlling the neopixels. It works well on an ATTiny85, we are using Adafruit Trinket boards to control Neopixels and work well. So far up to 12 pixels :)
You can download a Trinket Neopixel library, which is modded for an internal osc ATTiny85 from Adafruit.
Then your Raspi can talk to the microcontroller. It is a little problematic, though, since the software serial port handling consumes too much memory on ATTiny, and the ATTiny will ignore all serial input while refreshing the neopixels. Therefore you may get it easier by using an Arduino UNO, or Leonardo or Micro which is powerful enough for many pixels, and have a built-in hardware serial port.
As a matter of fact, you can talk to these Arduino boards as if it would be a serial port, so just plug in a Leonardo over USB and you'll get a new serial port in Rpi to talk to.

I'm using a max of 8 pixels, and I've already gotten strandtest to work.  I need to wrap my head around how to get it to talk to the Raspi using Python, the way Firmata does.  The fact that it plugs in like a dongle is a very attractive feature for me.  Tho, if I can't get the Neopixels to turn on and off under the Raspi's control, I guess that's a moot point.

Send the RGB value through the USB/serial/COM port. And read them at the Arduino side. Then set your strand accordingly.

Afaik, Firmata is for low-level bit-banging of the ports of the Arduino side. You can nicely turn them on and off, however the speed and timing is not good enough to simulate the Neopixel communication.
I am afraid you need to make your hands "dirty", and extend the strandtest app with handling of serial commands, instead of fiddling with Firmata.


text:
What is wrong with my 32u4 breakout board from adafruit?
I recently bought the atmega 32u4 breakout board from adafruit. I uploaded a sketch, then it says that there isn't a timer 2 on it and it won't do as I programmed my sketch. how can I fix this?

Please include some more information - especially the code you're trying to run.

You will need to port any libraries and code that depend on timer 2 to the '32U4 architecture. There is no way to add timer 2 to the chip, and it is likely that trying to force it to use a different timer won't help since it may configure things the other timer doesn't have.


text:
Change range of IR programatically
I am building a IR-based laser tag system. The basics are working fine. One feature, that I want to have, is different weapon modes with different ranges.
How can I change the range of an IR transmitter with as little hardware as possible, or at best, completely in software?

Just guessing, but if you are using IR LEDs as transmitters, the only way I see to alter range is by altering the amount of current applied to the IR LEDs, and PWM would not be a solution in this particular case. However I wouldn't say this is an accurate way to get different ranges, if (again) as I guess you would like to get differences in range of tenths of meters, or even meters. more or less the same accuracy you get when your TV remote's batteries are getting discharged and you must get up from your sofa a given distance...

Roberto's suggestion can only work if the beam diverges significantly. A laser beam is practically cylindrical at close distances, and you will not get enough attenuation for this idea to work. You should instead use lightsaber technology to make the beam stop at a fixed distance.

It's not a laser, sorry for the confusion. That's only the name of the game. All it is is an IR LED behind a lens.

The problem with altering the current is that I have the IR LED behind a transistor that allows for the full current to go through, so I can't even use two pins with different resistors. From what I gather from the datasheet of an infrared receiver, it looses a lot of responsivity if the frequency of the signal does not match the frequency of the receiver exactly. Would that work? So e.g. if I want full range, I use 38 khz, while if I want half range, I use 36khz.

@Dakkaron You should be able to easily test that. Using an led without a resistor isn't advisable, unless the voltage of the batteries is lower than the forward voltage of the diode (or a bit above, since you are only pulsing the led). I think you could use PWM, but you'd have to use a frequency that's way above 38khz.

I am using a resistor, I just meant, I cannot use two different ports with different resistors, because there is the transistor behind that. Off course I have a resistor between transistor, LED and VCC. Using PWM on a much higher frequency also makes sense, thank you. I will try that.

@EdgarBonet Please describe this lightsaber technology to us.

@Dakkaron - you could simply use two transistors, each with its own current limit resistor.  Chose the values correctly and you can actually get three modes - one, the other, or both.

Let us assume you are using an ordinary inferred LED and a type of inferred detector used in remote control entertainment equipment.
Inferred LED modulation is simple and is well documented on the web.
The inferred receiver is a complex device.  It contains, among other features, an Automated Gain Control (AGC) circuit and a Phase Locked Loop (PLL) circuit.  The AGC adjusts the gain and makes it impossible to gauge the power of one IR source relative to another. The PLL "locks onto" the signal.
Consider using and adjusting the power of a secondary inferred LED transmitter transmitting at the same time as the primary LED transmitter is being received. The secondary inferred LED transmitter is local to the inferred LED receiver and transmits a unique code.  The primary inferred LED transmitter is part of the opponent's equipment and transmits a unique code.  Slowly reduce the power of the secondary inferred LED source until the code switches from the secondary source to the primary source.  The power used by the secondary inferred LED when the switch occurs should be proportional to the distance to the primary inferred LED.
In the above scenario we have used the AGC to "hide" the primary source until we reduced the power of the secondary source to just below that of the primary source.  And we used the PLL to "lock onto" the strongest signal.

Instead of modifying the TX power, why not make the receiver read the light level. You just need to transmit some data, like the weapon ID.
If it works you could send more information, including how stable the weapon that hit the target was, during the shoot, using an accelerometer.

My devices have to be compatible to the guns I already have. Those are a proprietary system, so I have no control over them. Also the receivers I use on my devices are integrated IR receiver circuits (something like this: http://www.vishay.com/docs/82491/tsop382.pdf) and they only report the demodulated data, not the light level.

@Dakkaron, note the AGC block in the specification sheet you linked to above.  There is no way to determine the AGC setting from the outside world.  No way to tell how strong the source is.  No way to tell how far away it is. So you need to either supplement your setup with the Sharp Distance measurement device (my 1st answer) or utilize a power varying secondary signal source  as a reference (my 2nd answer).

Consider using a Sharp Distance Sensor in addition to your shoot / confirm-hit inferred LED & receiver.
This Sharp distance sensor is specified to detect objects that reflect IR light from 100 cm-500 cm.

How can I change the range of an IR transmitter with as little
  hardware as possible, or at best, completely in software?

I believe the sensors produce an analog output that can feed into an Arduino's ADC.  So software (by itself) can be used to adjust the threshold distance.
Similar devices I have used have a narrow sensing field.  They only reported the distance to objects directly in front of them.  Also, I found they were effected by defective (burning out?) florescent light sources.  We assumed failing florescent light sources produced IR radiation similar in frequency as used by the sensor's IR emitter.  Also, the analog output is slightly stair stepped in the unit we tested.  I say this in case you were expecting to use increase relative accuracy of several readings if not precision of any given reading.

No, the receivers are digital which product an all-or-nothing output.  Also the entire receive systems apparently already exist and are not being modified by the asker.

Perhaps there are several different types of Sharp Distance Sensors.  The Sharp Distance Sensors we used produced a voltage that was proportional to the distance.  However, we could not use them as they actually change the voltage in small desecrate steps.


text:
Is it possible to remove the bootloader while flashing using the bootloader?
The question is meant as in, can I lock myself out of the Arduino using the bootloader, if I flash a hex file that doesn't contain the bootloader?
Or does the bootloader automatically add the flashed file after itself, so that it's never overwritten?
The device in question is an Arduino Pro Micro (ATMega32u4). Asking, because I don't have an ISP available right now, and I have to flash pre-compiled hex files.

If you don't play around ISP programming and have not already been playing around with ISP programming, your bootloader is fine and will remain fine no matter what you try to upload. The bootloader has its own protected section, so it's not necessary to tack it onto your sketch code on every upload. The Pro Micro bootloader can't be updated via itself anyway.
Worst case what you try to upload your precompiled binaries and they simply don't work.
You can upload code that fails to respond to the 1200 baud touch request that is used to reset the board into the bootloader, which may make you think you've screwed up the board, but you haven't. The Pro Micro version of Caterina bootloader supports a double-tap reset for an 8-second upload window no matter what you've put (or tried putting) on the chip.
Practically speaking, the existing bootloader is immutable and will always work for you until ISP becomes involved at some point.

Nice, that was the answer I was looking for, thanks!

as the question title doesn't mention the MCU, I just want to add a note that this answer doesn't apply to all MCU. even on the new AVR MCUs the bootloader is not protected by default

@Juraj: I had the ATMega32u4 both in the question and in the tag. Which new AVR MCUs do you refer to? I guess, you mean anything beyond the ATMega line? Your input is definitely valid.

@Dakkaron for example ATmega4809 used on Nano Every and Uno WiFi

The ATmega4809 doesn't support the protocol that Atmel/Microchip refer to as "ISP".

@Dakkaron I guess the idea is that you're asking about a specific board and anyone reading the answer will need to have read the question to understand the the answer only was intended to answer for the board in the question. I'm not sure what the likelihood is of anyone in that situation being inclined to read comments on the answer, but sure, I guess. If you want though you can just put "Pro Micro" in your question title: "Is it possible to remove the Pro Micro bootloader while flashing using the bootloader?"

@timemage From my understanding, that's what tags are there for. At least on Stackoverflow they tend to edit info like that away from the title. The device is prominently featured in the question, so no need for digging into the comments. Interesting fact about the ATMega4809. Haven't used that chip at all so far.

@Dakkaron I figured if their concern was going to be addressed it made sense to do it in the question title. I also think it's probably fine the way it is.

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


text:
What happens if I draw too much current from ATMEGA IO pin?
I revisited an older device that I made and discovered, that I had an 8 Ohm speaker connected directly to ground and an IO pin of an Atmega328P. According to my calculation that means that the pin would have to source 625 mA, which is way above the 40 mA that any single port should be able to source and even above the 200 mA that the Vcc and GND support. Yet it somehow worked and the chip seems to be working just fine. The application uses a duty cycle of 50%, so in the best case it would use maybe 312.5 mA, which is a little better but still way above the ratings.
So my question is, what happens if the output pin is asked to source more than it's rating?
I've seen chips that just release their magic smoke while others just can't keep up with supplying that kind of voltage, so only the voltage drops without any other problems. How does the Atmega328P handle this?
The Atmega clearly didn't burn through, but what other kind of damage should I expect?

It is not good, but the effective internal impedance means that when facing such a load the voltage of the pin will not be at the supply rail and so the current will be less than you calculated.

Your math is off. You would only draw 150mA.

@IgnacioVazquez-Abrams: How so? According to Ohm's Law 5V / 8Ohm = 625 mA. Where is my calculation off?

@ChrisStratton: Sounds interesting. Do you have more details on that?

You forgot to account for the 25ohm output impedance of the chip.

@IgnacioVazquez-Abrams Thanks, that is a good point!

There's a few crude calculations you can do using some numbers from the datasheet.
This graph is in the datasheet:

It shows the voltage dropped by the high-side MOSFET driver in the IO pin for different amounts of current draw. From that we can get its resistance R(DSON).
For instance at 10mA, at 25C, the output voltage would be 4.75V. That's a 0.25V drop from the 5V supply voltage. So we can calculate the resistance as:

R=V/I = 0.25V / 0.01A = 25Ω

Now we have that resistance we can use it to calculate the actual current from the IO pin with an 8Ω load.  Simply add the two together:

25Ω + 8Ω = 33Ω

Now we can calculate the current through that circuit:

I=V/R = 5V / 33Ω = 0.152A

That is, of course, way above what the IO pin can actually supply (or so the datasheet says).
So what happens? Well, two things, basically:

The voltage on the IO pin will be below the 4.2V specification for the minimum of an output pin when HIGH, and
It will get hot.

The actual voltage will be, of course, V=I×R = 0.152A × 25Ω = 3.8V droped, so 5 - 3.8 = 1.2V
What is more critical, though, is the heat.  152mA through a 25Ω resistance generates P=I²R = 0.152 × 0.152 × 25 = 0.5776W. That's quite a lot. Enough to melt the internal circuits in the chip and release the Magic Smoke™.
Running at 50% duty cycle, though, makes a difference. That's 50% of the power, which makes a big difference to the heat.
What would the actual allowable heat be? Well, at 40mA, with 25Ω, that is 0.04 × 0.04 × 25 = 0.04W.
So you're generating more than 14 times the amount of heat you are allowed to. Even at 50% duty cycle, that's over 7x the limit.
Will it kill the chip? Well, possibly, possibly not. It depends how rugged the chip is and how well it can withstand the heat. Short bursts may be OK since the heat doesn't build up enough to melt things. Extended use, though, will make it get too hot, and things will go pop.

Your duty cycle analysis is incorrect.  At moderate PWM rates, when it is on it is still running at full power, however it is running at full power only half the time.  Hence half the heat, not a quarter.

@ChrisStratton It's actually not as simple as either situation - you have to take thermal conductivity, dissipation, etc into account. Instantaneous power (which would be half) is not the same as dissipated heat power, since that is subject to time and the aforementioned parameters. Either way, though, it's still exceeding the limits by a considerable margin.

Wow! Thanks for that amazing answer! That was much more than I expected! So basically, I am just really lucky that this is still working. I will add some resistance before using it the next time.

It is indeed not simple, but your posting and also followup are both substantially wrong on the basic points.  It is time average power, not instantaneous power which would be half.  Instantaneous power is full once the coil inductance is overcome.

@Dakkaron - while far outside the specs, the reality is that shorting a pin to ground does not usually damage a device such as this, at least in the short term.  Of course when you go outside the specs, there are no guarantees, and even apparent functionality no longer implies complete reliability.

That is very true. I am getting my terminology mixed up somewhat. Feel free to edit the answer and improve it.

@ChrisStratton I have worked out where I was going wrong - for some reason I was confusing output power with mosfet dissipated power. Yes, 50% current = 50% power dissipation from the mosfet because the voltage drop across the mosfet is determined by the peak current not the average current, so the peak voltage drop and the average current give the same result as the average power.


text:
How do I enable CONFIG_SPIRAM_SUPPORT for ESP32 S3 on Arduino?
I'm trying to use PSRAM with the TFT_eSPI library, but it fails because CONFIG_SPIRAM_SUPPORT isn't defined.
In Arduino -> Tools -> PSRAM I selected OPI PSRAM as the board manufacturer (the board is a Lilygo T-HMI with ESP32 S3) recommends, but that seems to not do anything in this respect.
How can I fix this?

One example from the library built fine. But then, I'm not using your code, your library version, your esp32 core version, and probably have not configured the board in exactly the way you have.

Which example did you check?

The  TFT_eSPI library should be configured correctly to use PSRAM.

@liaifat85 It is setup to use PSRAM if CONFIG_SPIRAM_SUPPORT is defined, which it isn't in my setup for some reason. If I comment out the check for this in TFT_eSPI and thus force it to use PSRAM, then it works flawlessly and uses PSRAM without issues. But I'd like to have PSRAM working the "proper" way without hacking around and manually modifying the library, which breaks when I update the library at any time. So I'm looking for a way to enable the CONFIG_SPIRAM_SUPPORT preprocessor define.


text:
Atmega32u4: Reduce power consumption while keeping USB active
I have a USB powered board, that should consume as little power when idle as possible, while keeping the USB connection alive.
The device only sends data to the host, doesn't receive any, so the connection itself doesn't necessarily have to be working while idle, but the host needs to be able to see the device as connected. So the device should never disconnect.
I can set the Atmega32u4 to idle mode while keeping the USB connection up, but the power consumption is really high (hardly lower than when active). I disabled all the peripherals I can disable in idle mode, but it didn't change much.
As soon as I enter any other sleep mode (power down, stand-by or ADC noise reduction) the connection is lost and the host can't see the device any more, even though the documentation says, that in ADC noise reduction mode, the USB clock stays active, and in power down/stand by, asynchronous USB interrupts should keep working.
Is there anything else I can do to reduce power consumption?
Is there anything I need to do to use power down, stand-by or ADC noise reduction modes while keeping the USB connection alive?

How do you put the MCU into sleep mode? Isn't it waked after a millisecond or so by the timer interrupt?

I am currently using this library: https://github.com/LowPowerLab/LowPower . I figured out, that I made a mistake, and now I can use ADC noise reduction mode. But the change isn't very high. If I drop it down using power-down/standby, the power consumption is reduced to next-to-nothing, but the USB connection is lost. It is woken by the WDT, afaik, and I let it wake up after 256ms. It is than awake for <1ms before sleeping again.

Is there a way to put it into power-down/standby without loosing the USB connection? That would be perfect.

Are you calling idle() with ADC_OFF, TIMER4_OFF... and everything else OFF? Try measuring the current draw with both USB_OFF and USB_ON: this will tell you whether it's the USB peripheral itself that is drawing too much current. You can also check the datasheet to see if there are other peripherals not taken care of by the library, which you could disable with the power_*_disable() function from the avr-libc.

@EdgarBonet Very interesting: USB_OFF reduces the power consumption significantly (even lower than ADC noise reduction mode), while keeping USB alive. I am still well above the current usage that I get in powerdown mode, but that's a significant improvement already. This leads me to think that powerdown should be possible, but that I need to somehow need to add interrupts or something for USB to correctly react to SUSPI/WAKEUPI while in powerdown mode.

Thanks a lot for the list of peripherals, I will cross-check than!


text:
Can I supply the board's 3.3V directly to the AREF pin?
Short dumb question: can I connect the 3.3V pin and the analog reference pin (AREF) directly?
I've heard mentions of a 32K internal resistor but I'm not willing to risk a short circuit without confirmation. Should I add an external resistor? Won't that create a voltage divider?

In Atmel's doc8271 pdf (with specification details for ATmega48A; ATmega48PA; ATmega88A; ATmega88PA; ATmega168A; ATmega168PA; ATmega328; and ATmega328P), table 29-20 on page 117 shows R_REF (the AREF input resistance) as 32KΩ (typical).  Section 24.5.2 on page 248 suggests that AREF is to be treated as a high-impedance input or output:

... the reference voltage can be made more immune to noise by connecting a capacitor between the
  AREF pin and ground. VREF can also be measured at the AREF pin with a high impedance voltmeter. Note that
  VREF is a high impedance source, and only a capacitive load should be connected in a system.

Also note that there is no reason to connect anything to AREF (pin 21), because on a standard Uno, AVCC (pin 20) is connected to VCC (pin 7), and one can select AVCC as the reference voltage during analog converter setup [as explained below].  Quoting again from section 24.5.2:

VREF can be selected as either AVCC, internal 1.1V reference, or external AREF pin.  AVCC is connected to the ADC through a passive switch. The internal 1.1V reference is generated from the internal bandgap reference (VBG) through an internal amplifier. In either case, the external AREF pin is directly connected to the ADC...

Summary: you can connect the 3.3V pin and the analog reference pin (AREF) directly, but on a 3.3V system  there is no reason to do so.
Selecting AVCC as the reference voltage:  Say analogReference(DEFAULT) to select AVCC as the reference voltage.  According to arduino.cc, this will choose “the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)”.

I disagree that "there is no good reason to do so". If you are sampling a signal that is 0-3.3V (or below) then connecting AREF to 3.3V gives you the full resolution over the signal range you are sampling instead of only a portion of the resolution.

That's why I wanted to change the reference. I wish there was a way to do it internally. Since I'm using an UNO, the default is 5V.

@Majenko, I edited that section slightly :)

I don't see any big objection to connecting the 3.3 V pin to AREF, providing you take precautions in your code.
The default for AREF is so-called DEFAULT (heh) as here:
uint8_t analog_reference = DEFAULT;

Once you do an analogRead the analogRead code connects up the desired analog reference:
ADMUX = (analog_reference << 6) | (pin & 0x07);

Then it starts the ADC conversion.
If you change the analog reference voltage then this needs to be done before doing the analogRead. eg.
  analogReference (EXTERNAL);
  analogRead (A0);  // use external reference

The reason they do it this way is so that it is safe to physically connect up the 3.3V pin to the AREF pin, because the initial state of the processor is to read the AREF pin.
Once you do your first analogRead, and with the DEFAULT reference voltage used, you will find 5V at the AREF pin. If you had then connected that to something else like the 3.3V pin, it will short out and damage the board.
Example code:
void setup ()
  {
  pinMode (13, OUTPUT);
  delay (5000);
  digitalWrite (13, HIGH);
  int foo = analogRead (0);
  }  // end of setup

void loop ()
  {
  }  // end of loop

Put your meter on AREF and you will see it jump to 5V after 5 seconds.


text:
Stop Arduino from powering LED strip when connected to USB
I have a WS2812B LED strip that is controlled by an Arduino. Normally, both the Arduino and LED strip are powered by the same 5V power supply. The 5V and GND pins of the Arduino and LED strip are connected together. If I want to reprogram the Arduino, I have to disconnect the LED strip or else it might want to try and draw power from my computer's USB.
I have a bunch of (assorted) transistors, (schottky, zener) diodes and resistors. Is there something I can build that will allow the power supply to power both the Arduino and LED strip, while the Arduino's USB can only power the Arduino itself?
I've thought about using a diode between the 5V of the Arduino and 5V of the power supply and using a resistor to pull the 5V terminal of the power supply pin low (when the power supply is not connected) but I'm not sure how stable that will be: once the diode starts conducting the resistor will have no chance to pull the pin low again and I'm not sure if the Arduino will like the voltage drop across the diode.
Obviously the external power would be disconnected before plugging the Arduino into USB. Since the LED strip runs on 5V I can't use the VIN pin.

I'd try powering the led strip for the power-supply directly, and the arduino board via a (schottky) diode.
That way the led strip will have no power when only usb is plugged in.
The Arduino won't mind that it receive a bit less that 5v because of the voltage drop of the diode.
The only thing to look out for it sending a 5v signal to a WS2812B chip that has no power. According to the datasheet this is not allowed.
So you either need to buffer the output of the arduino going to the input of the WS2812B (e.g. using some transistors, or a simple pull-up with diode). Or, since you are not hot-plugging the usb, have the 5v from the power supply go (via a resistor) to an input on the arduino, so you can detect this in your setup routine, and have it block the rest of the code, or something.


text:
Can a timer be used in both CTC and (fast) PWM mode simultaneously?
I would like to generate a sequence of pulses of varying lengths in the range of 0-100us, so that from the start of one pulse to the start of the next there is a delay of 100us. I have set up timer0 in CTC mode to trigger an interrupt every 100us.
In this interrupt, I would like to turn the appropriate pin high, read the length of the current pulse from an array, and then configure the timer in such a away that it turns the pin off as soon as the pulse length has elapsed (I am hoping that this is possible without using an interrupt for turning off the pin). It seems that the PWM functionality can do what I want, if I use the second output compare register.
In any case this seems possible using a secondary timer in PWM mode, but I'd like to know whether the same is possible using only a single timer. From what I've seen in the datasheets the answer seems no, but perhaps I am missing something.
Can a timer be used in both CTC (with output compare register A) and PWM modes (with output compare register B)?

Setting the COM0B1 bit in the TCCR0A register will Clear OC0B on Compare Match. Though as others described, CTC might not be the best mode for it.

As noted in previous answer, CTC and PWM are distinct modes, and only one mode can be selected at any given moment.
However, your problem description sounds like mode 14 on timer 1 will serve.  That's a Fast PWM mode that uses ICR1 as TOP.  OCR1A or OCR1B can be used for output compare, depending whether you want to output on OC1A or OC1B. OC1A is PB1, or digital pin 9 on ATmega328 systems, and OC1B is PB2, or digital pin 10.
On a 16 MHz system, you would put 1600 in ICR1, so there would be an  Overflow Interrupt every 100 μs.  At each Overflow Interrupt you would put the currently desired pulse-length into OCR1A or OCR1B.  This will work so long as your Overflow ISR takes fewer cycles than any desired pulse length.
You would set COM1A1/COM1B1 and COM1A0/COM1B0 to 1, 0, because Table 16-3 for this combination says, “Clear OC1A/OC1B on Compare Match, set OC1A/OC1B at BOTTOM (non-inverting mode).”  [Or see §16.9.3 (“Fast PWM Mode”) of the 2015 '328 spec, which says: “In non-inverting Compare Output mode, the Output Compare (OC1x) is cleared on the compare match between TCNT1 and OCR1x, and set at BOTTOM.”]

Technically no. CTC and PWM are distinct modes of operation.
However, more advanced PWM modes, specifically mode 7 for 8-bit timers and modes 14 and 15 for 16-bit timers, allow specifying an arbitrary timer duration in OCRxA or ICRx while still allowing PWM operation using the other output compares.


text:
Advanced Line Follower robot
I know about line follower mainly the grid solving robots i know the basics actually. Actually they have to trace the path of the grid in an arena and then reach back to starting point in a shortest distance. Here my doubt is regarding the line follower in this link I have attached.Advanced Line Follower Robot for maze solving
My doubt is what are the procedures to do it? They have mapped the path and used Dijkstra algorithm to solve the path. But how do they transfer the code(i.e) where it has to turn which direction it has to turn. how are they generating the what function should be passed? Please explain i need the procedure alone. am going to try it with python.

Any language will do, as long as it is supported by your HW platform.
If you want to use python, you need a board that can run python.
That could be an Arduino Yun, for example. Or an Intel Quark. Or an Intel Edison with an Arduino shield.
But these will be expensive.
You could, alternatively, use C/C++ and an Ardino UNO (or micro, nano, mini pro), which is far cheaper.
Googling for something as simple as "Arduino line following kit" gives as first answer this, which seems to be exactly what you are looking for.

Please read my question and see the link I have attached.

Why do you think I didn't do that? Try instead with a constructive comment, explaining what of my answer is not matching your question.

Did you see the link? They have just mapped the arena and did it. I want to know the procedures exactly how they did it. I didn't ask whether it will work with python. Arduino works with python-pySerial

I did watch the link, but you need to ask them exactly how they did it.
Other than that, pySerial is not sufficient. It will let you run python code to talk to the arduino, but you need something on the Arduino to listen to it and take the corresponding actions. And send to the PC where your python program is running all the information coming from the sensors.

Oh, wait, are you thinking to continuously poll the sensor over the connection? That might work, but it's kinda lame.

No sir, I just need to know how they did it? I searched many blogs. Actually what kind of implementation is this?


text:
Can one supply an Arduino Zero's VIN pin with 5v?
The title pretty much says it all. I know that most Arduinos can do this, but I couldn't find very much information for the Zero. Any help would be very much appreciated.

Yes you can. If you look at the schematics on the Arduino website you can see that the 3.3 volt regulator is connected to the 5 volt regulator. That means that if you feed 5 volts straight into the 5 volt pin it will go through the 3.3 volt regulator to supply the main chip.
Note that this is going into the 5 volt pin not the VIN pin which goes into the 5 volt regulator and would thus require a higher voltage than 5 volts.


text:
Can LilyPad Main Board interface with a sensor via UART?
Is the LilyPad Arduino Main Board physically capable of interfacing with, let's say, a LeddarTech LeddarOne Optical Rangefinder, which has a 3.3v UART interface? I understand that the LilyPad has a serial interface, but I wouldn't be sure if it was meant to handle more than just transferring code.

Yes you can.
Lilypad <> Other device using UART
Rx         <    Tx
Tx         >    Rx
Note that you cannot use 5V with the lilypad if you do this. If you do want to use 5V with the Arduino, then you'll have to put a voltage divider between the Tx and Rx (other wise you might fry the other UART device using 3.3V.
Also, when you upload the code FROM your computer TO your Lilypad, you have to connect all other UART device connected to the Lilypad. Connecting other devices to the Tx and Rx of the Lilypad while uploading a code to it might cause lag or bugs.
Hope I anwsered your question!


text:
Using Arduino to learn AVR programming
I want to learn AVR C programming instead of arduino programming. I have an arduino UNO board and few Atmega328 chips that I bought, and Atmel studio for programming. Can I use Arduino Uno board as programmer to flash the chips from Atmel Studio? Or any other alternatives?

Without a lot of knowledge on this subject, this post on the Arduino Forums and it looks related. For reference, what you want to do is use the Uno as an ISP.

Do your self a favor and buy a real programmer like the Atmel ICE, Dragon etc... You will thank me.

If your chips have a bootloader already installed in them, you can use any USB -> Serial cable (FTDI cable) to program them in-circuit on their Rx/Tx pins. If not, you can use the Uno to program a boot loader into them (one time) and program them with the cable from then on.
To use standard C, you can use the bare chips or the UNO. You'll want a different environment than the Arduino IDE, though. That can be anything from an editor, the the gnu compiler tools run from a command line, to almost any other IDE. A number of people, myself included, use the Eclipse IDE with an AVR plug-in and do almost everything from writing the code to programming the AVR from within it. (I say 'almost' only because I personally prefer a full-blown programming editor, run outside of the IDE, for initial creation of sizeable projects or major edits and rewrites. That isn't necessary, though).

If you're starting out then Atmel Studio is a good option - it's very easy to install and get up and running, and I use it.
To use an Arduino as an ISP you're going to need to use AVRDude.  You can configure Atmel Studio to flash chips using AVRDude - I struggled with this but eventually got it working, you can look here if it will help - not specifically for the Arduino as ISP, but should get you started.
Finally you should also double-check whether you have ATmega328-PU or ATmega328P-PU - AVRDude doesn't support the ATmega328-PU (without the P) so you'll need to do a workaround (again something that I've been caught out with in the past, [here's how I worked around it] (http://www.crash-bang.com/resource/bootload-atmega328/)
Good luck - programming the AVR directly is more challenging but gives you more control.

AVRDude does support the ATmega328 (no P) - however, the configuration file shipped when it is distributed by the Arduino folks may not include an entry for it.

Essentially, it is to use menu Tools -> External Tools to define a new menu command that calls AVRDUDE with the appropriate parameters, using $(TargetDir) and $(TargetName) to construct the full path to the hex file created by Atmel Studio.

I want to learn AVR C programming instead of arduino programming.

It's not really clear what you think the difference is. You can use the Arduino IDE to do "straight AVR" programming, for example:
int main ()
  {
  DDRB = bit (5);  // pin 13
  DDRB |= bit (4);  // pin 12

  while (true)
    {
    PINB = bit (5); // pin 13
    PINB = bit (4); // pin 12
    }
  }

The AVR register names (eg. DDRB, PINB, PORTB and so on) will be included by the IDE, however you don't have to use a single Arduino library or function if you don't want to.

Ah, cool you can actually "override" the main function and not use the setup & loop functions?
But to be honest I would let everyone drop the arduino IDE. I think code-completion and/or code hints are very usefull for beginners.

Certainly, and you can specify an editor of your choice for the IDE. I just don't think that "Arduino programming", "C Programming" and the supplied IDE are different things. The IDE basically implements C++ so there is really no "Arduino language".

You can use the Atmel Studio + Visual Micro plugin to easily get started with atmega328 + support for the uno board (easily program, use arduino libraries etc). Checkout here.  http://www.visualmicro.com/page/Arduino-for-Atmel-Studio.aspx

Just found in this forum that a similar answer exists for a similar question. http://arduino.stackexchange.com/questions/13225/what-changes-i-have-to-take-care-while-coding-from-atmel-studio-instead-of-ardui


text:
Suggest some ways to communicate (Rx and Tx) between Arduino and LabVIEW through Internet

Suggest Hardwares to use and also suggest some place to learn about
IoT, video tutorials, websites, blogs, books etc.
Currently I am using Xbees to communicate between LabVIEW and Arduino Mega.
Most of the websites that I checked are using ESP8266 but I am not
sure how to use them to receive and transmit simultaneously.

What type of protocols do you want to run? What is the required bandwidth (message per second, avg message size)? Response time? This could be control algorithm inner time, etc. These types of questions (requirements) need to be answered first before approaching an architecture, design and implementation. You are skipping directly to the implementation.

I am sending 54 bytes and receiving 18 bytes of data. I want response time to be as minimum as possible, which I think would depend on the internet speed. I am not sure about other things. How would you tackle this problem ? I am asking you to answer your own question :P sorry. I am a newbie.

Would it work if the round trip of messages is approx. 10-20 ms with a worst case delay of 250 ms? How would the application (LabView/Bot) react? I am assuming that you wish use a WiFi Router. The "Internet Speed" or bit-rate has very little to do with the actual bandwidth as using using WiFi/TCP/IP may require retransmission, etc. If you have requirements of lower than 1 ms it all becomes much more difficult (expensive :).