text:
Arduino Uno not able to handle 2-dimensional array

Now the code I'm writing in Arduino (Using Arduino) uses multiple 2-dimensional arrays. Now when I print some thing using the Serial Monitor it prints it correctly but when I declare and initialize the 2-dimentional array it won't print it.
Code:
void setup()
{
  Serial.begin(9600);
  int image_width = 56;
  int image_height = 96;

  int image_result[image_width][image_height];
  for (int i=0; i<image_height; i++) {
    for (int j=0; j<image_width; j++) {
      image_result[j][i] = 5;
    }
  }

  Serial.print("code works");
}

Now in this case "code works" does not print but when I remove the array declaration and initialization code works is printed. What is the problem?
Do 2 dimensional arrays work differently in Arduino or is it a space issue?

Even a one-dimensional array of 5376 bytes, on a processor with 2048 bytes, will fail.

I meant, 10752 bytes. I overlooked that each array item is 2 bytes. Bear in mind you don't even have all of those 2048 bytes available. The Serial transmit and receive buffers alone use up 128 bytes.

Well if I connect a micro-SD car is there some method to declare array in that memory?

You can connect a SD card and write data to your heart's content. However you can't "declare the array in memory" on it. What is your application here? An Arduino with 2 KB of RAM isn't the best thing for image processing.

I need to read a small BMP file in an array of ints in Arduino and need to do some processing on it. And the file size is 56 by 96 pixels.

You are going to have to re-think this. You can't read and "do processing" on 10752 bytes of pixels on an Arduino with 2048 bytes of RAM. Maybe on a Due you could do it. Do 2 dimensional arrays work differently in Arduino or is it a space issue? - it is most definitely a space issue.

What is different on Due? Plus can Mega 2560 work for this?

What if I save the image data on flash memory and if I do some processing save the results to flash memory too. Will this approach work?

Plus can Mega 2560 work for this? - the Mega has 8 KB of RAM, if that answers your question. You want 10.5 KB.

The Due has 96 KB of RAM. That looks more appropriate.

2D arrays work fine on arduino, but you run out of space very quickly.
An uno has 2 kilobytes of ram; your array has 56*96 = 5376 2-byte elements.
I would guess that you are writing over some critical memory value with a 5 at some point causing the program to fail.

Not only over memory, but probably also over all the I/O registers.

16 bit addressing, with SRAM starting from 256. So that's 65279 bytes of address space. So you won't reach that. Also, I'm pretty sure there is some kind of protection preventing this from happening.

There is no protection. The CPU registers are memory-mapped starting at address 0, then the I/O registers from address 32, then the statically-allocated RAM starts at address 256.

You are trying to use more memory than you have available: 96 * 56 * 2 = 10.752KBytes. Not much that the MCU can do when this happens.
If you look into the datasheet, you'll see that your microcontroller (ATmega328p) only has 2KBytes of RAM.
I guess the question then, is to ask yourself if you really need that large an array. You may consider getting an external flash chip or an SDcard shield. If you only need it for read-only purposes (such as a lookup table), you can use some of your flash program memory (you have 32KBytes).

I'm using a SDcard sheild but I'm reading the data into an array declared like this. How would I be able to use the SD Card memory.

You don't usually need to deal with all 5376 elements of your array at one instant. Consider dividing up your image into smaller chunks for processing. Depending on the kind of processing that you do, you may require different smarts to optimize the process. ;-)

Can one write data on the flash memory again and again. What do you mean by read-only? How does one write the data once on it. For example I want to write the image data on the flash memory one. How will I be able to do it?

I am referring to your program flash memory. AFAIK, you can only write to the program flash during programming. One you boot your MCU, the program flash is used as read-only memory (so that we don't mess up the program when it's running.) Since you want to write your data, the program flash is not suitable.

Do you really need to process the whole image in one go? As I've mentioned before, you can divide your image to smaller blocks, say chunk[8][8] would be a comfortable size for Arduino to swallow, and it works well even if you use convolution filters. (Having said that, I must stress that the Arduino Uno is ill-suited for any serious image processing application.)

This is what I fed my Uno:
#define IMAGEWIDTH 56
#define IMAGEHEIGHT 96

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

  int i, j;
  int image_result[IMAGEWIDTH][IMAGEHEIGHT];

  for (i = 0; i < IMAGEWIDTH; i++) {
    Serial.print("\nIMAGEWIDTH ");
    Serial.print(i + 1);
    Serial.println(":");
    for (j = 0; j < IMAGEHEIGHT; j++) {
      image_result[i][j] = i + j;
      Serial.print("image_result[");
      Serial.print(i + 1);
      Serial.print("][");
      Serial.print(j + 1);
      Serial.print("]: ");
      Serial.println(image_result[i][j]);
    }
  }
  Serial.println(F("\nDone!"));
}

void loop() {
}

This will run over the whole array, while printing progress over Serial, which then print "Done!" once it is. I suggest changing:
#define IMAGEWIDTH 56
#define IMAGEHEIGHT 96

To lesser values, unless you have a few good minutes at hand.

This is not at all going to solve his problem. It isn't time, it is the size of the array. 56 * 96 * 2 (an int is two bytes) uses 10752 bytes. Your Uno has 2048 bytes. The issue is not time, it is storage.

Nick was right, this hasn't solved my problem. Anyway, thanks for trying.

Indeed, this is an issue of RAM available. If you do not need 8 bits per piece of data (if you are perhaps willing to reduce image quality, for example), consider compacting your data such that you have multiple piece of data per bit. For example, hex values or BCD (binary coded decimals) could work, depending on the size of each piece of data.

The OP wants to read a BMP file into memory, so I doubt it can be turned into BCD very usefully.

That's a good point. Perhaps he's willing to significantly decrease his image quality? Either way, additional storage would be wise.

As others have noted, your array is larger than the available RAM in your Arduino. Others mentioned Flash memory which could be a solution for you. Your Arduino has 32 KB of memory which could hold your array. See the following reference for more info about Flash memory. Keep in mind that Flash and EEPROM have a limited number of write cycles before becoming unreliable.
Hidden Powers - storing data in Flash and EEPROM

In case the matrix is mostly empty or anyway has values that can be calculated programmatically, sparse arrays might come to the rescue. It requires memory allocation and hopping, so the access time to individual elements is not deterministic, but you can calculate the worst-case scenario.


text:
What's the benefits between different interrupts on Arduino
On an Arduino you can have several different interrupt types, two of them being RISING and FALLING. Looking past that RISING is from LOW to HIGH, and FALLING is the opposite, what are the benefits of using one or the other?
To clarify; why would you use a RISING interrupt or a FALLING interrupt?

These are the ways an external IO pin can generate an interrupt. You use rising when you wnat an interrupt when the level on a pin rises from low to high. It is that simple.

Imagine that you have the circuit below:

simulate this circuit – Schematic created using CircuitLab
Let's say that you wanted to catch the user pressing the button. The input signal will go from high to low, which is a falling edge. So you would use a FALLING interrupt to catch this event. Easy, right?
Now let's say you wanted to catch a user releasing the button instead. This time the inverse is true, so you want to use a RISING interrupt.
You should note that since these interrupts are edge triggered, the simple circuit below would not be ideal. Without any debouncing, there may be several edges to trigger from, resulting in repeated interrupts. Also, given the analogue nature of the design, we can't be sure that the rise / fall times will be fast enough to trigger the edge interrupt. We can get around this by adding a 100nF capacitor across the switch and following by a Schmitt trigger (which I can't find a symbol for in the circuit editor!).
So to answer your question, you use the interrupt that is correct for the event you are trying to catch. The Arduino MCU implements both edges for completeness and flexibility in your design, so if this interrupt was coming from an external IC you have no control over the design of, you can easily match the interrupt to its behaviour without having to add in an inverter.

Very good answer. And of course if you want to detect the switch press and release, you can use a CHANGE interrupt.

Suppose you have a pushbutton that connects Arduino pin to the ground. The pin is also pulled up  to VCC (may be internally in Atmega chip, or through external resistor). Now, when the switch is open, Arduino sees HIGH, and when you press the button it sees LOW. If you would like to perform an action when the button is pressed, you would use FALLING interrupt. If you would like to know when the button is released, you would use RISING. There are no general benefits of using one over another.

The interrupt will be generated by an external circuit.  In many cases, you have the control over the design of the external circuit, and you can choose whether it will be generating low-to-high edges or high-to-low edges.  But in some cases you don't have the control over the design of the external circuit which generates the interrupt.  Then you have to adapt your firmware code to the interrupt source.

source: Stack Exchange

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

sort: votes


text:
Using C# Program to Interpret Keystrokes
I am in the process of developing an Arduino application that can read keystrokes from a PS/2 keyboard. I was wondering if it would be possible to upload a C# program onto the Arduino to interpret the keystrokes from the keyboard and write an Arduino program to perform operations based on the keystrokes.

No, the Arduino doesn't run C#

Is there a specific feature of C# you need help working around in C++?

C# is just my go to language. I haven't dabbled in C++ at all, but I guess this would be a good time to pick it up.

The answer is actually, surprisingly, yes! C# requires .NET CLR for execution, I had assumed that .NET exists only in microsoft desktop land, but it has in fact been ported to microcontrollers and released open source as .NET micro, it can even run baremetal with no OS.
However this is not possible on an 8 bit regular arduino, it requires one of the larger 32 bit models. There is a prebuilt clone that has the .NET micro CLR framework ported to it on an STM32F4 cpu called the netduino
Unfortunately the footprint for .Net Micro is too large to run on a regular 8bit arduino and probably hasn't been built for 8bit systems. It is possible with the arduino Due (in theory) and on other micrcontroller platforms that support .NET micro to run C# code outside of the windows platform.

This is interesting... will this work on something like Arduino Due or another 32 bit Arduino board?

@AnnonomusPenguin it requires reasonable resources (256K Flash + 64K ram), but otherwise the devil will be in configuring/building it for the Arduino Due platform, I'm not sure how easy Microsoft makes it on you, I couldn't find anyone working on it after a cursory search for .net micro on arduino due

I hope this answer doesn't get voted down just because it addresses the generic need (do something upon input from a PS/2 keyboard), rather than the (too) specific question that was asked (use c# on Arduino), but here it comes ...
If you use a PS/2 to USB adapter for the keyboard, you can select a much easier solution, based, for example, on raspberry PI (or anything that runs linux and has a USB master port) and use any simple scripting language - even shell. The overall cost would not be much higher and the ease of implementation would be definitely more likely to succeed. And in a short time.

authors: Иван Кондраль

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


text:
Wirelessly communicate between two Arduinos without router
I want to "connect" two Arduinos, without using wires. The range is ~0.2 miles (300 meters). Using Google, I saw too many options.
The idea is to build something like a beacon, so the bandwidth can be small. I want to send 32 or 64 bits/second of data (32 bits for the application + 32 bits for checksum if the module does not guarantee consistency of data).
The communication between Arduinos is bi-directional, and I'm looking for something cheaper than 50 US dollars per module.
Can I use a serial WiFi module for this, without using a router? Do you recommend a 2.4GHz module? Or a RF module?

They are all good possibilities, In order to identify a good choice you have to first define what you want to do. You've answered no useful questions that would narrow the choices besides distance. What  bandwidth? what is your acceptable error rate? what price? bi directional or not? uniquely addressable or not? etc. etc. First define what you want to do then find the right solution

Might want to look into zigbee, they are expensive but tends have a decent range.

I can highly recommend these cheap little 433Mhz radios.  You can get them on amazon, ebay, etc. and they work pretty well for me. Your distances are a bit longer than my situation but I have to go through several walls.

From the picture I see that one (the transmitter ?) seems to have an adjustable coil.
But even if it does, the other (the receiver?) doesn't seem to be adjustable.
Is there some other way to avoid interference from colocated pairs?

However, from the reviews, the max distance for reliable transmission seems to be much less, about 100m.

The type of antenna will have a big impact on range. I've managed 50' with a simple length of wire using the 433 MHz radios. A directional antenna should be able to provide a gain of 5 at least. I considered implementing a CSMA/CD protocol but lost interest at some point. I did implement a Master with multiple Slaves solution. The idea was for a thermostat that could poll slaves with a temp sensor. Each slave had a unique 'address' the master sends a message with the slave's address and a command ('send temp') and waits for a response.

It's a bit unorthodox solution, but have you considered toy walkie-talkies?
They cover the distance you reported, even if some obstacles are in the path and they are relatively cheap, if you go for some sales.
It requires a bit of hacking to connect the arduino to the mic/speaker and the push button, but it shouldn't be too difficult.

My idea isn't use a microphone. Instead, I want to send "digital" data, created by an application, and parse it from the reciever device. ¿There is any way to use the walkie talkies chipset for that?

@Nullpo: there is no such a thing as a digital signal, it's all analog.
It's up to the consumer of the signal to treat it as analog or digital.
In other words: the walkie talkie doesn't care if you transmit voice or a sequence of 1 and 0, as long as the input voltage in within the same range as the voltage provided by the microphone.
And the same goes on the receiving end: the arduino that receives doesn't care that the Walkie talkie thinks it's transmitting voice, as long as the voltage levels are compatible.

To clarify further, what I'm proposing is to remove the microphone and interface directly the Arduino with the board in the walkie talkie.


text:
What makes a board "Arduino Compatible"?
There are all sorts of Arduino and Arduino-compatible boards out there. They come in all form factors and they come with all sorts of different I/O. They even come with memory specs and different kinds of microcontrollers, from the ATmega328P to Intel-based.
So what is it that imbues a board to become "Arduino Compatible" ? Must it be pin-compatible? Must it be possible to compile Arduino source code for the board? Or must the board be binary-compatible? Must it emulate some specific processor instruction set?
Very curious. Please reference specifications if possible. Thank you.

Related: What does “Arduino compatible” mean?

The problem here is that "compatible" can mean so many things in different contexts and to different people.  For instance, it may mean any of the following:

Can be used with the Arduino IDE without any need for additional board installation of other modifications
Can be used with the Arduino IDE after modification (boards installed)
Uses the same (or very similar) API to the Arduino system
Has the same footprint as an existing official Arduino board
Is a device which will work with an Arduino board and has software available to operate it

All very different meanings.
Point 1 could be a board that is based on the design of an existing Arduino board (say the Uno) but built into a new form factor, maybe with additional hardware and peripherals added.  It is still treated as if it was the board the design was based on though.
Point 2 would be a board that is similar, though not the same, as an existing board.  A different board definition may be required to map the IO pins properly, for instance.  It could use a slightly different chip in the same supported family. You still use it as an Arduino, but it's not the same as an existing Arduino board.
Point 3 may mean it's based on a completely different chip.  The programming environment may be almost the same, but it's hard to get 100% API compatibility.  Arduino sketches and libraries may work out of the box, or may not.
Point 4 could be a board that, internally, is completely different to the Arduino, uses a different programming language, IDE, etc, yet the layout of the board is the same as, say, an Arduino Uno.  A good example is the Mecanique Firewing - an Uno footprint, but a PIC32 chip instead of an Atmel, and Basic instead of C++.  Most Arduino shields would just plug in and work though, software permitting.
Point 5 is from the completely opposite direction.  This is a device which "is compatible with" in that "it will work with" and Arduino.  That could be on an electrical level (it's a 5V device and will connect to the Arduino) or that it has full software support ("Download our Arduino library...").  It has nothing to do with how the device works or what it is though.
I prefer to use specific terms, respectively:

Based on the Ardino UNO
Programmable with the Arduino IDE
Compatible with the Arduino API
Footprint compatible with the Arduino UNO
Suitable for use with Arduino boards

That way it states exactly in what way this device relates to the official Arduino boards.

I think the practical answer is: it is not defined.
In practice:
For peripherals, it seems to mean that it can interact with an Arduino compatible board.
For boards, as far as I can tell, it has to be: instruction-set compatible, OR pin (layout) compatible with another board which was previously defined as Arduino compatible.

I think you could say it is Arduino-compatible if it contains a processor found on an Arduino board. For example:

The Atmega328P (found on the Uno, Duemilanove, Pro Mini, amongst others)
The Atmega32U4 (found on the Leonardo, Micro, amongst others)
The Atmega2560 (found on the Mega2560)
Other processors used by Arduinos such as the Atmel SAM3X8E ARM Cortex-M3 CPU used on the Arduino Due.

With a processor used on an Arduino, you will find that you can almost certainly compile code using the Arduino IDE, and the Arduino libraries, that will work on such chips.

You could say it is Arduino-Uno-compatible if the board physically was compatible with the Arduino Uno (ditto for other boards). In other words, if it was possible to plug a shield, designed for the Uno, onto such a board. That could be called "plug compatible" I suppose.

As for other boards, like sensors, relay boards, etc., I have seen a lot of those on eBay advertised as "Arduino compatible", but of course they would also be compatible with other micro-controllers as well. I'm waiting for the day someone advertises "Arduino compatible" resistors.


text:
Arduino Serial.write sending more than 64 bytes

I am using an Arduino Due to collect a large amount of data from an encoder (about 1kb). Afterwards I need to send the collected data to a C# application I wrote over the serial port. I serialized my tx data into a byte buffer and simply used this code to transmit:
void sendEncoderData()
{
  byte buffer[1024];

  /*** some code that populates buffer ***/

  int bytesToSend = 1024;
  Serial.write(buffer, bytesToSend);
}

When I run the code, nothing seems to get received by the C# application. In fact, I never see the Tx LED light up. However, if I change bytesToSend to a value smaller than 64 bytes everything works. Is this a limitation of Serial.write() or is it something else? What are ways I can work around this limitation?
More information： sendEncoderData() is called by an interrupt service routine. However prior to the call, I made sure to 'detachInterrupt()` on all pins including the pin associated with said ISR.

Have you tried sending in 64-byte chunks?

That's a snippet, isn't it? http://snippets-r-us.com/

@NickGammon, I would be a snippet if Serial.write() is supposed to be capable of sending more than 64 bytes at a time. If that's the case:

My assumption was wrong and perhaps you could have pointed it out. 2. I will post more code and details.

This only seems to work - define "work". It hangs? Only 64 bytes are transmitted? If so, which? The first 64? The last 64?

I(t) would be a snippet if  ... - OK, let's say you turned interrupts off. You may have, you may not have. With them off things would be different than if they were on. It may not seem important to you, but to us, it is. You are the one asking the question. It is up to you to supply as much information as you can to get a good answer.

More information： sendEncoderData() is called by an interrupt service routine. - this is absolutely crucial information, which is why I linked you to http://snippets-r-us.com/. If you had said "In an ISR I am calling this line of code ..." I would have been able to answer you straight away.

Here's the problem:

sendEncoderData() is called by an interrupt service routine.

There is an internal 64 byte serial transmit buffer that is filled by Serial.write().  That buffer is empted by sending the data a byte at a time using an interrupt.
If you are in an interrupt (at a higher priority than the serial interrupt) then the interrupt that sends the data can never happen, so the buffer just fills up and stops when it gets to 64 bytes.  It will hang until there is room for more bytes in the buffer, and that will never happen because you're not allowing the data to be sent.
The answer (as I and others have said many times in the past): Never use Serial in an interrupt.


text:
Use all pins As digital I/O
Increase the number of digital pins
There are many post that explain how to use more than just the standard pins on the various arduinos but none of them explain the limitations and the proplems properly.

Arduino Uno:
1.You can use the analog pins
Pin 14 = Analog in 0
Pin 15 = Analog in 1
Pin 16 = Analog in 2
Pin 17 = Analog in 3
Pin 18 = Analog in 4
Pin 19 = Analog in 5

digitalWrite(14,HIGH);
or
digitalWrite(A0,HIGH);

2.You can't use both SDA , SCL & A4 , A5 as they are basically the same (18,19).
3.You can also use the TX/RX.

"Don't do it, you break the serial communication..."
"Never use pins 0 and 1"
"you can't use the TX/Rx Pins"

You can... but you need to take precautions. Which ones?
It should have software serial over USB, right?
Or do i break the USB serial?
Are there internal Chip problems if i use TX/RX?
As i use those TX/RX pins in the code i probably should not use Serial.print()?
What happens if i forget to remove Serial.print() after uploading the code that use pins 0,1?
How to hardware reset the arduino/bootloader if something goes wrong?
As there are various other Arduino's that use different chips, is the above valid for all Atmel chips?
So, what shuold i know before using those TX/RX or also maybe the other analog pins?

There are cheap shiftregisters, pwm drivers, led drivers, spi, i2c and
  more ic's to expand your I/O

But if there are not to big problems it means that the arduino has 20 I/O pins...
You could theoretically control:
17x3 = 51 = 17 RGB leds (multiplexing, pwm sourcing&sinking);
14x6 = 84 leds (multiplexing, pwm on 6 rows/colums );
10x10 = 100 leds (multiplexing, high low);
20x(20-1) = 380 leds (charlieplexing, high low);
// yes it would flicker

Correct me if i'm wrong. That means you are able to control 380 "Whatever" using diodes and one arduino.

The main issue is with pins 0 and 1.
Many pins have multiple functions assigned to them, such as A4 and A5 are also the I2C pins, pins 10/11/12/13 are also the SPI pins, etc.  But pins 0 and 1 are the only multi-function pins that actually have something attached to them on the board.
All the other pins, while being multi-function, have their function defined basically by what you attach to them.  Since the pins 0 and 1 are already attached on the board to the USB interface chip their usage possibilities are somewhat more limited.

As soon as you enable Serial in your sketch (Serial.begin()) those two pins can no longer be reliably used for digital IO.

That means that you can either use the hardware serial port or you can use the pins for digital IO, but not both.

Devices connected to pins 0 and 1 can interfere with the serial connection

That includes uploading of sketches.  You have serial data coming in from the PC while the same pins are being affected by other things connected to them.  The most common one is things like GPS modules which connect to those pins and constantly send serial data.  That serial data will conflict with the PC's serial data and neither will arrive right.

How do you upload sketches if the serial is being interfered with by your sketch? How do you "reset" the board?

You don't.  It's not your sketch that's interfering with the serial, it's what is physically connected to those two IO pins that are interfering.  Just disconnect those two pins from whatever is connected and you will be able to upload sketches again.  Many shields now are starting to add a small switch on them to disconnect those pins so you can upload sketches without unplugging the shield.  You can also use the same trick with other devices you wire up to those pins - add a double-pole-single-throw or double-pole-double-throw (and not use one position) to easily isolate both pins from the rest of your hardware when you need to.

Does this affect all Arduino boards?

No, only those that use a USB to Serial bridge chip - that's things like the Uno, Due, Mega, etc.  Boards that have a direct USB connection don't use the TX and RX pins for uploading sketches - they use the dedicated USB D+ and D- pins.  That's boards like the Leonardo, some of the smaller (mini? micro? I forget which) boards, etc.

"Many shields now are starting to add a small switch" cool. Micro has "USB to Serial bridge chip" ?  Does that mean i can use pins 0,1 on uno but not on micro?

You can use them on any that do not have a USB to Serial bridge. The Uno has one, the Mega has one, the Mini doesn't have one, however you do need to connect one externally to the TX/RX pins to program it.  All of those are out.  The Micro, and the Leonardo do not have one, so you can use those.

Thats what @Nick Gammon is talking about ? Uno and the others you wrote down have pullup resistors that don't allow you to properly use pin 0 and 1 but the Micro has no pullup resistor and so pins 0 and 1 work properlky and also the usb to upload new sketches?

For once Nick is mistaken on that point. There aren't any pullup resistors. What is there is a pair small inline resistors to prevent problems if the main MCU and the USB chip both try driving the same line to opposite levels at the same time.  You can see them on the Uno schematic as RN4A and RN4B.

If the USB chip happens to try driving the RX pin (you have the USB port plugged in and you open the serial connection [or maybe it's just plugged in, not sure]) then it can affect the voltage on the RX pin independent of whatever you're doing in your sketch, so it may not be safe to use that pin for things like charlieplexing.

so i can charlieplex 380leds or switches with an Uno if i don't use serial,i2c,spi. if the usb is not used as serial. then if i want to add a new sketch i just need to unplug stuff from pin 0 & 1.At the other side with micro i don't even need to unplug pins 0,1 as they are not connected to the usb?

That is almost correct.  You may be able to use 0 and 1 for charlieplexing, but the USB chip may still interfere despite your best efforts.  Different USB chips work in different ways, and it depends on what firmware is loaded on the USB chip on those that use an MCU instead of a dedicated chip like FT232 etc.

Even if the usb is not connected but i use only vin or the dedicated power supply? Once programmed i use a external powersupply usb is not connected. to change sketches remove pin0,1stuff

That is not a question that can be answered with a simple "yes" or "no".  It completely depends on what the USB chip does and that depends on what the USB chip is, which depends on what the board is, where you bought it from, who designed and built it, etc.  It's best to assume the worst and not use those pins for that kind of operation.

It's unclear ... or they work or they don't ... if it's something like yes it works with charlieplexing as the interferences are to low to have a visual impact on the leds , while using switches its not suitable a could get to many bad readings. btw i'm talking about original Arduinos.. Uno rev 3 and microalso latest... the "real" arduinos. Maybe it implies that the chip firmware also changes and so it could write some random data on those pins? like i said usb is not connected after programming. has the chip some sort of loop on those pin to check if it's connected or whatever?

what happens if i put 2 leds inverted(with resistors) on pin 0 and 1, set pin 0 high pin 1 low delay 1 second and set pin 0 low and pin 1 high delay 1sec? same question i asked Nick.

Let us continue this discussion in chat.

Have you tried it?  You won't do any damage by having a go. Yes, firmware can (and probably will) change over time.

i try, post updates later.. i hope my arduinos don't explode.AAAAAnd that i'm able to program it later with other sketches...

Tested on Arduino Uno, 2 inverted leds on pin 0,1 blink correctly , no visible interferences even if powered with usb from pc. sketches load normallly also with the leds plugged in.actually the tx rx are probabliy wired exactly as the test as you can see in and out tx rx comunication... so if it works on uno... the arduino micro should have totally no problem.

I can't comment due to insufficient reputation but I want to point out that the OP pinout has at least one pin wrong!
PB6 should be PB5
I spent quite a lot of time trying to figure out why I couldn't see SCK on scope (SPI bus). I was working low level, not with the IDE.
As this is the first picture that comes up when googling I wanted to avoid the same trouble to others...

20x(20-1) = 380 leds (charlieplexing, high low);
  Correct me if i'm wrong. That means you are able to control 380 "Whatever" using diodes and one Arduino.

First, the figure of 380 is correct for 20 pins (202 - 20) however pins 0 and 1 are connected to pull-up resistors on the Atmega16U2, so they are never really at 0V. If you load a blank sketch, you will measure 5 V on pins 0 and 1.
Second, you can't drive 380 "whatevers" you can drive 380 LEDs via Charlieplexing. The property of the LED, that current only flows one way through it, is important to the way it works.
Related question Is there a way to have more than 14 Output pins on arduino?

First: what happens if i put 2 leds inverted(with resistors) on pin 0 and 1, set pin 0 high pin 1 low delay 1 second and set pin 0 low and pin 1 high delay 1sec?

Second: By "whatevers" i mean switches... click switches, reed switches, sensors or every type of combination of inputs outputs that support high low.http://electronicdesign.com/site-files/electronicdesign.com/files/archive/electronicdesign.com/files/29/18652/fig_02.jpg done with diodes.

Well, not really. Charlieplexing is a form of multiplexing, so unless you want your switches clicking like mad, it won't really work for them. And it is an output situation, so you won't be doing inputs, like you seem to think. I suggest you read the other links. Shift registers, or port expanders, are more practical than Charlieplexing here.


text:
Increasing the numbers of I/O pins on Arduino Uno
I want to make a game of Tic-tac-toe using an Arduino, LEDs and bouncy buttons. Hence I need nine inputs and nine outputs. But you see that an Arduino only has 13 I/O pins. So is there a way I can use the analog pins or a way to reduce the number of I/O pins using an ingenious way?

possible duplicate of Is there a way to have more than 14 Output pins on arduino?

See Is there a way to have more than 14 Output pins on arduino? - there is a lengthy discussion there, with references.

I added an answer to the question Nick mentioned, with a note about accessing 7 I/O lines from the Atmega16U2 on the Uno.

Have a look at charlieplexing

This question is similar to Creating an Arduino Tic Tac Toe game.

Yes, just use the analog pins. The analog pins are both analog inputs and digital I/O pins. The functions happen to be shared on the pins, in the same way that the interrupt pins are shared with digital I/O, the TX and RX pins are shared with digital I/O and the SPI pins are shared with digital I/O.
Every I/O pin (analog or digital, etc.) can be used as digital I/O.
You can also reduce your required number of I/O pins by using a technique known as multiplexing.
For instance, to read nine buttons you could have them arranged (as in Tic-tac-toe) in three rows of three buttons. You then have three I/O pins for the columns and three I/O pins for the rows - that's just six I/O pins for nine buttons.
The technique is widely used for keypads, but they are just buttons, so the same technique can be applied to any buttons.

The Matrix Keypad how-to

The same can go for LEDs. There are various specialist LED multiplexing techniques that allow for many LEDs to be driven from just a handful of I/O pins.

How to Multiplex an LED Grid... (YouTube)
Charlieplex Library for Arduino

You can also multiplex buttons with LEDs, this way you just need 3 pins for commons + 3 pins for LEDs + 3 pins for inputs.

If multiplexing is too complicated for you, you can wire all buttons to one analog pin using resistors. This way you only need 9 pins for LEDs and 1 analog pin for buttons.

What I am planning to do is that use rgb leds, So if user 1 presses some button then red color and then next one green. So I guess that this method would not be able to work that way, because they require different voltages. And all this process have to be dynamic. I don't know which button will the user be pressing.


text:
Low Power library messing up serial text
I noticed something unusual using the Low Power library today.
When printing text in the loop and using LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); to sleep for one second, all the text in the loop gets messed up in the Serial Monitor as if you chose the wrong baud rate.
Example code:
#include "LowPower.h"

void setup() {
  Serial.begin(9600);
  Serial.println(F("HELLO"));
  Serial.println(F("HELLO"));
}

void loop() {
  Serial.println(F("HELLO"));
  LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
}

This code just prints
����11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=

even when using different baud rates. (I used the same baud rate on both the arduino and the monitor).
Replacing the low power command with delay(1000); works fine

The problem is most likely that the system is going to sleep while it's still sending the serial data.
Forcing all the serial data to be sent before you go to sleep should fix the problem (serial data is sent in the background using an interrupt so as to keep sketch slowdown to a minimum):
Serial.flush();
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);

Thank you very much for this fast answer. Would this affect the power saving of the library? I assume not but better be sure :)

It will cause a slight delay before it goes to sleep while the serial data is sent out.  It won't affect the actual sleeping though, no.  It just means the "on" time will be slightly longer - long enough to finish what it's doing.

I didn't know of that method. Thanks. @qwertz using a higher baudrate than 9600 will decrease the transmit time, so reduce power usage.

@Gerben In pre-1.0.0 Serial.flush wiped the transmit buffer.  In 1.0.0 and onwards it blocks until the transmit buffer is empty and the UART hardware has transmitted the last bit.

Let us know if this doesn't totally solve it. There may be other issues as well like the serial line stopping being driven high.


text:
Use AS3935 with I2C?
Has someone experience with interfacing the AS3935 lightning sensor using I2C? I found a library but it only works with SPI as far as I can tell. I really don't want to give up 4 pins for SPI as I need those for other things. I2C would be great as I use a couple more sensors with I2C so no extra pins only for AS3935.

Please post a link to this library. And preferably to the AS3935. That way your question can be answered more readily.

Datasheet http://www1.futureelectronics.com/doc/AUSTRIAMICROSYSTEMS/AS3935.pdf

I've used other I2C devices with Arduino UNO (version 1.6 IDE); a word of advice: since AS3935 wants I2C repeated-start condition (Sr) to read device registers, you may need to patch the Wire library... see http://forum.arduino.cc/index.php?topic=137607.0 and https://github.com/helenarobotics/Arduino/commit/8aff39a229362e0167e5f48f6c15d02b39b0fbca -- Modification to file C:\Program Files (x86)\Arduino-1.6.0\hardware\arduino\avr\libraries\Wire\utility/twi.c  --- line 468      twi_stop();  // <---- comment out this line

Just use these functions to read/write AS3935 registers, replacing the SPI ones (_devAddr is the device address, usually 0x03) :
// read/write functions for I2C mode
uint8_t AS3935::_i2cRead(uint8_t addr)
{
    // send register number
    Wire.beginTransmission(_devAddr);
    Wire.write(addr);
    Wire.endTransmission(false); // <<<--- THE 'false' here is mandatory!

    // request register data
    Wire.requestFrom(_devAddr, (uint8_t)1);

    // read data
    return Wire.read();
}

void AS3935::_i2cWrite(uint8_t addr, uint8_t data)
{
    Wire.beginTransmission(_devAddr);
    Wire.write(addr);
    Wire.write(data);
    Wire.endTransmission();
}

The "trick" is to use Wire.endTransmission(false) inside the read routine; this avoid to send the stop bit, which is mandatory for AS3935 read operation.


text:
Controlling a sliding tray - beginners project
I have a small light metal platform about 30 cm square mounted on horizontal rails. It is well lubricated and slides easily from side to side. I would like to build a device to connect to the underside of the platform that will allow me to programatically move the platform left or right by a defined distance at the touch of a button.
While I've never used an Arduino, I've been aware of its existence for a while and felt this might be a good project to begin experimenting with it. For context, I'm a computer programmer by trade, but have limited exposure to electronics in general.
Where would be a good place to start?  Are there books that are considered the "bible" of Arduino development? Are there existing projects that  basically do what I'm hoping to achieve? Am I barking up the wrong tree and shouldn't be attempting to find a solution for this with an Arduino? Any input would be greatly appreciated.

A stepper motor, with either a timing belt or lead screw would work for this. Arduino would be the most appropriate way to control those in this case.

You may find  robotics.stackexchange useful too.

A stepper motor moves a precise number of steps per revolution. This is a gross over simplification but with a stepper motor controller and an Arduino Stepper Motor Library (there are several) you can rotate the motor forward and backwards by precise amounts. My YouTube video covers controlling stepper motors with an Arduino. https://youtu.be/yV30DO6NO2Y

Thanks guys, this has all given me some excellent starting points. I now have a starter kit and a couple of books to get me going. Many thanks!

Am I barking up the wrong tree and shouldn't be attempting to find a solution for this with an Arduino?

Not at all. For example see Reprap - a 3D printer using an Atmega1280 as the controller. As it says here:

Arduino is an open source project that has created an easy and powerful microcontroller board based on the Atmel ATmega168. It is the brain of the RepRap electronics.

If you can make a 3D printer with an Arduino, then you can make your sliding platform gadget, which sounds simpler if anything.

Are there existing projects that basically do what I'm hoping to achieve?

Reprap, for one.

Are there books that are considered the "bible" of Arduino development?

This is a broad question, and your original question already has a couple of "flags" that it is too broad. I suggest you narrow it down a bit.
There are a number of books about learning Arduino. My advice is to start doing some simple projects (simpler than the platform initially) to get the hang of compiling, uploading, and generally working with microcontrollers.

Also try Google and YouTube. There are a lot of Arduino projects out there.


text:
Serial communication with two devices
I have two devices connected to my Arduino using the SoftwareSerial library. However, it seems that they cannot communicate at the same time. I can only communiate with both by switching between which one I am listening to every 1000ms (they poll for 1500ms), but this slows down overall communication significantly. Is there anyway to communiate with both at the same time? Could this be achieved by using SoftwareSerial with one and the hardware serial port with the other?

See SoftwareSerial Write to return Read in Serial Monitor? - SoftwareSerial cannot both read and write at the same time.
However HardwareSerial can.

Could this be achieved by using SoftwareSerial with one and the hardware serial port with the other?

Yes.

So, likewise, there is no way to read from both devices using only SoftwareSerial?

That is correct. Not at the same time. SoftwareSerial uses an interrupt to detect the start bit of incoming data. So far so good. But once it gets it, it leaves interrupts disabled while it goes into a timed loop to read all the bits.
Thus, it is impossible for it to react to another incoming byte on another pin at the same time.
Still, you could receive on SoftwareSerial on one pin, and HardwareSerial on another. With HardwareSerial the hardware will run in the background, receiving the byte.

So, likewise, there is no way to read from both devices using only SoftwareSerial?

See amended answer.


text:
Using UART to Set RTC
I'm using an Adafruit NRF8001 Low Energy Bluetooth module and a Real Time Clock module with my Arduino board. I want to connect to the BLE module using UART to set the clock. I'll also be using UART to set alarms.
I'm not sure which is the best way to take a string from the UART receiver and pull it apart into the hours, minutes, second, etc.
Any ideas? I did look at the Arduino JSON library but it seems a little buggy, and possibly overkill.
Any help would be very much appreciated :)

The simplest method is to keep it as a fixed format string with line termination.
Read one line in from serial into a character array (aka C string) and then chop it up.  As long as the string is in the correct format you can easily chop it around.
For instance, assume you chose the format YYYY-MM-DD HH:MM:SS\n which is quite common and easy to use, you may have data like this:
char *indata = "2015-08-22 17:23:48\n";

(\n is the new-line character)
Using simple char pointers you can get each substring quite easily:
First slice the string up into the component parts by replacing the separator tokens with character 0:
indata[4] = 0;
indata[7] = 0;
indata[10] = 0;
indata[13] = 0;
indata[16] = 0;

Then you can assign pointers to each segment:
char *year = indata;
char *month = indata + 5;
char *day = indata + 8;
char *hour = indata + 11;
char *minute = indata + 14;
char *second = indata + 17;

Or if you want it as integers, you can pass it straight to atoi:
int year = atoi(indata);
int month = atoi(indata + 5);
int day = atoi(indata + 8);
int hour = atoi(indata + 11);
int minute = atoi(indata + 14);
int second = atoi(indata + 17);

In fact, if passing it direct to atoi() you shouldn't need to even do the first stage, since it will stop parsing at the first non-numeric character.
There are more flexible ways of parsing the string too, using strtok(), but that is somewhat more advanced.
Note that this method is highly intolerant to invalid strings being passed, so you may want to first ensure that a) the string is the right length, and that b) there are the right separator tokens in the right placed, to validate that the string is properly formatted before proceeding.

Thank you @Majenjo. This might infact be the easiest way to do it. I can prepend the string with the item I want to update too. E.g. ST to set the clock, A1 to set alarm 1, A2 to set alarm to and so on.


text:
How to wire up 4-digit 7-segment display?
I have an Arduino Mega and the CL5642BH, a 4-digit 7-segment display. I found very helpful code here, but I don't understand how to wire it up on the breadboard.
The display has 12 pins: 6 on the top and 6 on the bottom. First I guess I need to find out which one is GND.
Then (see the link) there is this code:
int digit1 = 11; //PWM Display pin 1
int digit2 = 10; //PWM Display pin 2
int digit3 = 9; //PWM Display pin 6
int digit4 = 6; //PWM Display pin 8

int segA = A1; //Display pin 14
int segB = 3; //Display pin 16
int segC = 4; //Display pin 13
int segD = 5; //Display pin 3
int segE = A0; //Display pin 5
int segF = 7; //Display pin 11
int segG = 8; //Display pin 15

It's 11 pins, that's the correct amount so far. But how do I wire it up? The pins on the display are in no way labeled.
Note: I'm a software developer, but as far as electronics go, I'm still a beginner.

Datasheet where?

Here: http://www.robotshop.com/media/files/pdf/datasheet-com-09483.pdf, but I don't know how to read it. Also the datasheet shows 8 pins in a row, meaning 16 total pins instead of 12, for whatever reason...

The first thing you do is ask Google for a datasheet.  It tells you: http://www.robotshop.com/media/files/pdf/datasheet-com-09483.pdf
Then you can read the datasheet and find the pin diagram:

That tells you that it is a Common Anode LED display - which means that for each digit all the Anodes (positive pins) of the LEDs are wired together.
Further, all the cathode (negative) pins of the LEDs for the same segments across the digits are connected (that is the cathode for segment A on digit 1 is connected to the cathode for segment A on digit 2, digit 3 and digit 4, etc).
From that you can then infer that you need to provide current for each digit in turn through its common anode pin, and sink current from the segments you want to have lit for the digit that is currently having its current sourced.
The diagram also shows you which pin on the display is for what function - the common anodes are pins 9, 10, 12 and 13, with pin 11 the common anode for the extra dots.
The datasheet also tells you which pin is pin 1 - in this case the one in the bottom left when you have the display facing you and the numbers the right way up.  The pins count anti-clockwise from there, so 2 is to its right and 13 is above it.

By the sounds of it though you may not have the same display as in that datasheet.  If your display lacks the extra dots then it may not have the LEDs on pin 11, and pin 12-13 may be moved down one, so you have 4 commons on 9, 10, 11 and 12 with no pin 13.
So the four digit select pins in your program are wired to pins 9, 10, 12 and 13, and the segment select pins connect to pins 1, 2, 3, 4, 5, 6, and 7.  Don't forget the resistors on all the segment pins to limit the LED current or you will damage the Arduino.
You can do some manual testing of the display by using two wires and a resistor (say 1KΩ).  Connect the resistor to +5V, and one wire to the other end of the resistor.  The other wire you connect to ground.
You then take the loose ends of the wires and try probing pins.  Start with the 5V wire touching pin 9 and connect the other one in turn to pins 1-8 to see if the first digit's segments light up.  Repeat with the 5V wire on pins 10-12.
Edit:
If this (http://mklec.com/displays/7-segment-4-digit-12-pin-common-anode-display) is indeed the same display as yours you can ignore the numbers I mention above and work from the pin numbers on that page.  The same principle applies though, just the pin numberings are different.

This clears things up a lot. And I also found a wiring description. Unfortunately it's in German, but here it is anyway: http://ecotronics.ch.honorius.sui-inter.net/wordpress/2013/multiplexed-4-digit-7-segment-led-display-mit-arduino-ansteuern/

@bytecode77 Don't follow his wiring instructions, they are wrong.  He has 4 resistors, one on each anode.  You need 8 resistors (7 without DP), one on each cathode.

Oh... Well, I'm very confused by now. Do you have some sort of idiot's guide to wiring this display?

@bytecode77 Wires from IO pins to anodes.  Resistor on each cathode. Each resistor to IO pin.

What? Look, I'm really a beginner in electronics. I have trouble with the simplest things. Do you have some sort of guide?

@bytecode77 A guide for connecting a wire between an IO pin and your LED display?

For instance, I don't know which pins are cathode and which are annode.

@bytecode77 Then read my answer. It tells you which pins are which, and how to work that out from the diagrams in the datasheet.

As page 2 of the datasheet shows, there are 5 anode pins (4 digit and 1 aux) and 8 cathode pins (7 segments and 1 DP). Connect the digit lines to the digit anodes and the segment lines to resistors connected to the segment cathodes. The location of pin 1 is shown on the top right of page 2, and as always they go counter clockwise from there. Segments are lit by putting the anode high and the cathode low.

But why does the data sheet show 16 pins when I only have 12?

Probably because that's not the correct datasheet.

@bytecode77: This would appear to be more accurate. The same principles apply, just the numbers differ.

From the datasheet found by Ignacio Vazquez-Abrams:

Now one segment will light up if there is a positive (eg. 5 V) on the anode, and a negative (eg. ground) on the cathode. You need a resistor (eg. 330 ohm) to protect the LED and the output pin.

Hopefully it is clear from the original question which Arduino pins go to which LED pins.

Then the code which I presume you found will have to multiplex the display. That is, it will ground (send LOW) to the appropriate cathode pins for the number of segments it needs to light up (all of them, for example, for the number 8, except the decimal point). And then it will raise to 5 V (send HIGH) to DIG 1. That will make some segments on digit 1 light up. Then it repeats that for digits 2 to 4, fast enough that they will all appear to be on at once.

Apply the pin 1, 2, 3 with 5v from Audrino passing through the resistors. Apply low voltage to pin-a to light up the led, so on so forth.
You can use the multi-meter to confirm the common pins and led pin.
For example touch the pin1 with (+) and pin-a with (-) of the multimeter.
If the pins are correct, led pin-a will light up.
Picture Reference:http://www.circuitstoday.com/voltmeter-using-arduino


text:
433MHz transmitter and receiver pair doesnt work
I have a pair of 433 MHz transmitter and receiver:

Transmitter is connected to Arduino pro mini, receiver to Arduino Uno R3.
Output of receiver on serial looks like that (it doesn't change much):
Basicly I am getting either 75x or zero regardless of transmitter is on or off.
in > upper
756
in > upper
758
0
0
 0
in > upper
758
0
in > upper
757
in > upper

Transmitter code:
#define rfTransmitPin 4
#define ledPin 6

void setup()
{
    pinMode(rfTransmitPin, OUTPUT);
    pinMode(ledPin, OUTPUT);
}

void loop()
{
    for(;;)
    {
         digitalWrite(rfTransmitPin, HIGH);     //Transmit a HIGH signal
         analogWrite(ledPin, 255);              //Turn the LED on
         delay(500);                            //Wait for 1 second

         digitalWrite(rfTransmitPin,LOW);       //Transmit a LOW signal
         analogWrite(ledPin, 0);                //Turn the LED off
         delay(500);                            //Variable delay
    }
}

Receiver code:
const unsigned int upperThreshold = 70;  //upper threshold value
const unsigned int lowerThreshold = 0;  //lower threshold value
const int ledPin = 13;

#define ReceiverPin  A0

void setup()
{
    Serial.begin(19200);

    pinMode(ledPin, OUTPUT);

    DiodeTest();
}

void loop()
{
   int data = analogRead(ReceiverPin);
   delay(50);

   if(data>upperThreshold)
   {
       digitalWrite(ledPin, LOW);   //If a LOW signal is received, turn LED OFF
       Serial.println("in > upper");
   }

   if(data<lowerThreshold)
   {
       digitalWrite(ledPin, HIGH);   //If a HIGH signal is received, turn LED ON
       Serial.println("in < lower" );
   }

   Serial.println(data);
}

The receiver simply sends random data to the output pin when it is not receiving a valid signal.  It is up to you to encode your transmit signal in a fashion that you can recognise.

Basically what dwayne is saying is this: if you connected a standard logic chip to your phone wires you wouldn't expect it to be internet ready. These are basic devices and the receiver will produce garbage when not poked by a transmission.

Those receivers don't give an analog value. They give a HIGH if a signal is detected, and a LOW when no signal is detected. (Though the HIGH seems to only be 3.7v). So just use digitalRead instead of analogRead.

These types of receivers are AC coupled so you will not be able to do what you are doing as you need to have regular transitions in the signal and not stay in one state for too long.
They are also limited in the speed at which they will work, I expect 19200 bps is too fast.
You need to use a modulation technique such as Manchester Encoding or other technique that guarantees a suitable density of transitions, can synchronize the data and perform error checking.
One popular software library that does this is VirtualWire Arduino Library that is designed for Arduino and the type of transmitters and receivers you are using.

See this post about a radio-controlled car.
I found when using what looks like a similar receiver to yours, that the received data looked like this:

The cyan line was the receiver, the yellow line is what is being transmitted.
The trouble turned out to be the pull-up resistor on the Arduino Rx pin (from the USB chip).
Even with SoftwareSerial it wasn't too great:

I found that using an op-amp as a buffer helped a lot:

I also agree with the comments about adding an aerial wire, just a short length of hookup wire should do it.

You also need to attach a piece of insulated wire as a 1/4 wave length antenna to each of the receiver and transmitter boards. For the 433 MHz type antenna's this would be a piece of wire ~6.8" (17.3cm) long.
For reference if you were using the other popular type of low cost RF link pair at 315 MHz the antennas would be ~9.37" (23.8cm) long.


text:
Connecting MicroSd Reader with arduino uno
I am working on a Project with
(a) Arduino Uno Clone (6 PWM Pins i.e, 3,5,6,9,10,11)
(b) 6 Servos
(c) MicroSD Reader Module
(d) Speaker
As We Know that MicroSD reader modules uses pins 10, 11, 12 of an Arduino board, but my pin 11 is already being used by a servo motor.
1. Then how can I connect the MicroSD reader in my project ?
2. Which pin can I use for the speaker in this case ?
Please help me plus Provide me some additional information if needed.

The best answer is: don't use pin 11 for your servo motor - move it to another pin.
The SD card needs SPI.  SPI is pins 10/11/12/13.  You can't change that.  You can much more easily move the servo to a different pin, since there are multiple PWM pins that can support the servo in hardware. If they are all taken then software PWM is easy and there are libraries available to do it for you, so you can use any IO pin you like for that.  Much simpler than re-writing the SD card software to use bit-banged SPI on other pins (which would also be incredibly slow).

Please Give me Link to that Soft PWM. And what about the speaker? Does it also needs PWM pins ?

Tone works on any pin. I don't have a link off hand, ask Google.

The Servo library he is using is most likely already using software PWM. You can't use pins 5 and 6 as servo pwm pin without messing up the delay and millis functions.

Pin 10 is not mandatory for SPI. Slave select can be performed with nearly any other pin without complicating matters.

@Ariser Pin 10 is special.  It's the SS pin, and has to be in the right mode for SPI to work right.  If pin 10 is set to output then SPI is in master mode.  If pin 10 is set to input then SPI is in slave mode.  It's part of the SPI module and can't be changed.  Yes, you can also use any other pin as your slave select, but you still have to take care that you don't break SPI by using pin 10 wrong.

@Majenko: You are right, you have to use pin 10 as an output, or your controller will halt on a signal on this pin.


text:
Arduino nano getting powered through analog input?
I noticed something today. I am powering the Arduino Nano from a battery and a 5v step up converter. That works just fine and I'm getting a stable 5v output. I have a second cable coming out from the battery which plugs right into analog input A0 set as input so I can measure the battery voltage. However when I disconnect the battery from the usb plug and leave the voltage sensing cable connected to the analog input the power led stays on. I want it to shut down and be disconnected from the power source and have the voltage sensing cable still connected.
How can I fix this?

Power is flowing from the analog pin, through the internal clamping diodes, to the Vcc line. Those diodes are however not designed to handle that much current, so don't continue doing this.
Either also disconnect the ground wire from the battery, or simply add a resistor between the battery and the analog pin. Something like 10k. That way less than a mA of current will be clamped, and the arduino will stay off.

But how high of a voltage drop will I have then? I can't have any if I'm measuring battery voltage which needs to be precise

Negligible. The analog pins are high impedance inputs. The ADC is optimized for analog signals with an output impedance of approximately 10k or less.

Thank you. Another question: Do you know any transistors/FETs with a very low voltage drop which I need for switching off a sensor?

@qwertz That is a completely different topic. Don't ask it in a comment.  Instead that question is best asked in http://electronics.stackexchange.com since it has nothing to do with Arduino.

Ok so I'll create a new topic for that, thanks

Any (MOS)FET will do. They don't have a voltage drop, like regular transistors do. They only have a very low resistance. Like e.g. 50mΩ. Which would create a voltage drop of 50mV if 1A of current is passed.

This addresses a subset of your question which was covered in your added comment-question. I've addressed use of a 20V full scale input range to make the answer more general. The results would be "even better" for your 5V input case. Note that is Vin ~= 5V you would want a measurenet range somewhat above 5V max so that you can handle typical voltage variations.

Do you know any transistors/FETs with a very low voltage drop which I need for switching off a sensor?

If you used a say 10k resistor in the upper leg of a voltage divider and added a MOSFET switch with an on resistance (Rdson) of 2 Ohms (a terrible spec) between Vin and the divider then the error introduced would be about 2/10k = 1:5000. If measuring a say 12V  battery and using a Vinmax voltage of 20V the error in voltage measurement would be in the order of 20V/5000 = 4 mV. If using an Arduino Nano with a 10 but ADC the resolution (not accuracy) is 1 in 2^10 = 1:1024 or 20V/1024  = about 19 mV for a 20V input range. ie the resistor introduces an error of about 1/5th of a bit of available measuring accuracy.
Worse (or better) - if you use 1% resistors they will swamp errors caused by ADC resolution. Even use of say 0.1% resistors or calibration is liable to produce a result where ADC resolution is not the main limiting factor.
Even with no resistive divider, getting accuracies that are doinated by the 1:1024 ADC resolution and not other factors takes care and effort. At 5V in ax ADC resolution of 1:1024 means that a variation of 1 part in 2048 could cause an erroneous reading. Input offset voltages, thermal effects, board and connector resistances and ground voltage dropsm and offsets can easily provide greater error magnitufes.
Test: Take a working design. Set meter to lowest voltage range such that 1 mV can easily be seen. (Ideally 200 mV range. 2V range marginally OK). Measure ground voltages between various "ground" points at various locations in the system. Differences ofm mV to 10's of mV can often be found. Differences are poptentially higher if power current are present - say 10's of mA or more.


text:
Hi-speed external ADC
I would like to detect signals in nanosecond scale. For that, an ADC with at least 500 MSPS is required.
My question is if its possible to use an external ADC with 500 MSPS with a 16MHz Arduino Mega? If not, is there any additional hardware like FIFO buffer to overcome this problem?
Please help, thanks!

Not sure what it is you want to achieve, but you might be able the use the comparator inside the ATMega328. E.g. to detect when a voltage goes above a certain threshold. PS 16mHz will mean one clock-cycle every 62.5ns, so you're already in the tens of nanoseconds scale.

Why do you want to do this? Even if you could do 500 million samples per second, where would they go? You only have 2048 bytes of RAM on a Uno.

From the Arduino reference on AnalogRead:
"It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second."
500msps is an awfully high rate - my first instinct is, perhaps you need to revisit what you are after, and why.
There are indeed chips that will do this for you. It is still not possible with an Arduino, since the Arduino can't even receive the data this fast, let alone process it. Assuming 8-bit sampling, this would generate a stream of data at 4gigabits/second - I doubt any disk drive could write that fast (SATA3 is 4.8gbit/sec, which is 20% more, I suspect that the 20% would be eaten up by overhead - you can't just send raw data to a drive, you also have to tell it where to put it. That just accounts for getting the data to the drive circuitry, not actually storing it).
Perhaps what you're looking for is an oscilloscope. An oscilloscope takes high speed readings and displays them. Oscilloscopes are often used for testing circuits (e.g. looking at what an Arduino puts out/reads in when it's being programmed). Looking on National Instruments' websites, their cheapest one I could find that does > 500msps is worth about US$8,000 (ballpark). You will still not be able to store this to disk, or process it in any meaningful way, in realtime - a board like this will typically capture data (based on a trigger, sample until the memory is full, then slowly move the data to the PC to process.

I need to measure the round trip time of certain EM wave that travels in speed of light. But I have replaced the Arduino, and is using a high speed oscilloscope (with 5GS/s) for my application. Anyway, thank you for the suggestion!

No, it's certainly not possible to directly sample at 500Msps on an Arduino using an external ADC.  Simple maths:

The Arduino can perform 16 million instructions (best case) per second
The ADC performs 500 million samples per second.
500 / 16 = 31.25

Therefore the ADC would be generating 31.25 samples for every clock of the Arduino, so unless you can build in a time compressor (maybe with a flux capacitor too), it just ain't gonna do it.
So you will have to think creatively instead.  A possible solution would involve:

A high speed flash or pipelined ADC, ideally with parallel output.
A large chunk of memory to act as a buffer.
A high speed clock source to set the timing (500MHz?).
Glue logic and counters to take one sample, store it in the buffer, and increment the buffer address.
More glue logic and interfacing to allow the Arduino access to the buffer memory and to control the operation of the sampling system.

This, to me, sounds like a job for an FPGA, and at 500MHz, quite a fast FPGA.  You should investigate some of the FPGA development boards from Xilinx and Altera.

Sorry for the late reply, but I realized that Arduino is not suitable for my application. I need to measure the round trip time of certain EM wave that travels in speed of light. So I have already replaced the Arduino, and is using a high speed oscilloscope (with 5GS/s) for my application. Thank you for the suggestion!


text:
Updating a sketch to work with IDE 1.6.6
I've got a MAX7456 chip and I am using this (this is the unmodified one) library with it.
There's a sketch inside the examples folder (Max7456WriteTable) that I need to get to work to update the character table.
I modified three lines and then I got really stuck as I do not know how to continue. This is the modified one.
In file included from Max7456Write.ino:2:0:
/tmp/build4608284042510222737.tmp/sketch/Max7456WriteTable.h:29:69153: warning: narrowing conversion of '243' from 'int' to 'const char' inside { } is ill-formed in C++11 [-Wnarrowing]

This happens for every item in the array. But that is not the only problem. (I'll skip a few hundred lines)
/tmp/build8855411239666100148.tmp/sketch/Max7456Write.cpp.o: In function `setup':
/home/t/Max7456Write.ino:13: undefined reference to `Max7456::Max7456(unsigned char)'
/home/t/Max7456Write.ino:19: undefined reference to `Max7456::activateOSD(bool)'
/home/t/Max7456Write.ino:44: undefined reference to `Max7456::getCARACFromProgMem(char const*, unsigned char, unsigned char*)'
/home/t/Max7456Write.ino:46: undefined reference to `Max7456::sendCharacter(unsigned char const*, unsigned char, unsigned char)'
collect2: error: ld returned 1 exit status
Error compiling.

It takes a huge amount of time for it to abort the compilation.

https://github.com/arduino/Arduino/wiki/1.6-Frequently-Asked-Questions#q-the-compiler-complains-about-prog_char-or-anything-that-begins-with-prog_-the-exact-error-is-iso-c-forbids-declaration-of-type-name-with-no-type-what-can-i-do

@Gerben I tried everything I could, it does not compile. I tried changing what is mentioned in the wiki page, it still does not work. The array no matter what I try either complains "duplicate const" or "not constant" or "invalid conversion from int to const char". As a newbie this is way too complex for me.

Yeah, it now works when I nuked my install.

If I change prog_uchar to unsigned char in both max7456.h and max7456.cpp the hello world example sketch compiles.
In Max7456WriteTable change
Max7456::getCARACFromProgMem(i,currentChar); //Because the table is too big for ram memory

osd->sendCharacter(currentChar,i); //We send currentChar at address i.

to
Max7456::getCARACFromProgMem(tableOfAllCharacters, i,currentChar); //Because the table is too big for ram memory

osd->sendCharacter(currentChar,i, 0); //We send currentChar at address i.

0 is probably the wrong value, but at least it compiles.

Did that already. Check my second download link for my current progress.

Just move the contents of Max7456WriteTable.h to Max7456WriteTable.ino, and adding #include <SPI.h> makes the second download compile.

Are you using IDE 1.6.6?

1.6.3. I updated to 1.6.6 and still compiles. https://www.dropbox.com/s/d3d0mkasvqrea8k/max7456.zip?dl=0

I updated my Arduino IDE version, wiped all libraries, redownloaded them, nuked all configurations and dynamic links I've created to keep consistency in my projects. It now finally works.

authors: بشير عبد الوهاب


text:
ESP8266 problem as Web server
I asked a previous question about esp8266 that made a lot of things clear for me that esp8266 is very powerful and can be independently used as the webserver now, I have used the following library(https://github.com/sandeepmistry/esp8266-Arduino) to achieve this thing as I found a tutorial(https://learn.adafruit.com/esp8266-temperature-slash-humidity-webserver/code) to help me out.
Now this is the code that was in the tutorial and is working fine
/* DHTServer - ESP8266 Webserver with a DHT sensor as an input

   Based on ESP8266Webserver, DHTexample, and BlinkWithoutDelay (thank you)

   Version 1.0  5/3/2014  Version 1.0   Mike Barela for Adafruit Industries
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DHT.h>
#define DHTTYPE DHT22
#define DHTPIN  2

const char* ssid     = "--MYRouterID";
const char* password = "--MYRouterPassword";

ESP8266WebServer server(80);

// Initialize DHT sensor
// NOTE: For working with a faster than ATmega328p 16 MHz Arduino chip, like an ESP8266,
// you need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold.  It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value.  The default for a 16mhz AVR is a value of 6.  For an
// Arduino Due that runs at 84mhz a value of 30 works.
// This is for the ESP8266 processor on ESP-01
DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266

float humidity, temp_f;  // Values read from sensor
String webString="";     // String to display
// Generally, you should use "unsigned long" for variables that hold time
unsigned long previousMillis = 0;        // will store last temp was read
const long interval = 2000;              // interval at which to read sensor

void handle_root() {
  server.send(200, "text/plain", "Hello from the weather esp8266, read from /temp or /humidity");
  delay(100);
}

void setup(void)
{
  // You can open the Arduino IDE Serial Monitor window to see what the code is doing
  Serial.begin(115200);  // Serial connection from ESP-01 via 3.3v console cable
  dht.begin();           // initialize temperature sensor

  // Connect to WiFi network
  WiFi.begin(ssid, password);
  Serial.print("\n\r \n\rWorking to connect");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("DHT Weather Reading Server");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/", handle_root);

  server.on("/temp", [](){  // if you add this subdirectory to your webserver call, you get text below :)
    gettemperature();       // read sensor
    webString="Temperature: "+String((int)temp_f)+" F";   // Arduino has a hard time with float to string
    server.send(200, "text/plain", webString);            // send to someones browser when asked
  });

  server.on("/humidity", [](){  // if you add this subdirectory to your webserver call, you get text below :)
    gettemperature();           // read sensor
    webString="Humidity: "+String((int)humidity)+"%";
    server.send(200, "text/plain", webString);               // send to someones browser when asked
  });

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void)
{
  server.handleClient();
}

void gettemperature() {
  // Wait at least 2 seconds seconds between measurements.
  // if the difference between the current time and last time you read
  // the sensor is bigger than the interval you set, read the sensor
  // Works better than delay for things happening elsewhere also
  unsigned long currentMillis = millis();

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

    // Reading temperature for humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
    humidity = dht.readHumidity();          // Read humidity (percent)
    temp_f = dht.readTemperature(true);     // Read temperature as Fahrenheit
    // Check if any reads failed and exit early (to try again).
    if (isnan(humidity) || isnan(temp_f)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }
  }
}

Now this is my modification of code(of esp8266) as I am willing to communicate it over serial with my arduino which will further send data to the esp8266 when it requests using the attached sensor to the batteries(I am making a solar related project).
Its only a basic code but the problem is that it compiles and runs ok but I am only able to access the web page once and that is also only the root. The other links do not open up or when I try to even reload the web page root it stuck and browser says error timed out
Here is code
void handle_root() {
  //server.send(208, "text/plain", "
Hello from the weather esp8266, read from /temp or /humidity
");
  String sendx = "
This Page Shows the Basic Info
";
//  Serial.write("MP");
//  delay(20);

//  while(Serial.available()>0)
 // {
  //  rec = Serial.readString();
  //}
  rec = "TESt";
  if(rec[0] == AllMain)
  {
     sendx += "
Running on Main Power Now
";
     sendx += "
" + rec + "
";
  }
  else if(rec[0] == HouseMain)
  {
    sendx += "
Home on Main Power
";
    sendx += "
" + rec + "
";
    sendx += "Turn on Hospital Main";
  }
  else if(rec[0]==HospitalMain)
  {
    sendx += "
Hospital on Main Power
";
    sendx += "
" + rec + "
";
    sendx += "Turn on House Main";
  }
  else
  {
    sendx += "
" + rec + "
";
    sendx += "
Turn on House Main
";
    sendx += "
Turn on Hospital Main
";
  }
// sendx +=  "Temp";

    server.send(200,"text/html",sendx);
  delay(100);
}
void thm()
{
 // if(Serial.available())
  {
//    Serial.println("thm");
    String sendx = "signal sent... go back to previous page to verify";
  //  sendx += "Go Back";
    server.send(200,"text/html",sendx);
    delay(100);
  }
}
void thos()
{
 // if(Serial.available())
  {
//    Serial.println("thos");
    String sendx = "signal sent... go back to previous page to verify";
 //   sendx += "Go Back";
    server.send(200,"text/html",sendx);
    delay(100);
  }
}
void setup(void)
{
  // You can open the Arduino IDE Serial Monitor window to see what the code is doing
  Serial.begin(115200);  // Serial connection from ESP-01 via 3.3v console cable

  // Connect to WiFi network
  WiFi.begin(ssid, password);
  if(debug)
    Serial.print("\n\r \n\rWorking to connect");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    if(debug)
      Serial.print(".");
  }
  if(debug)
  {
    Serial.println("");
    Serial.println("DHT Weather Reading Server");
    Serial.print("Connected to ");
    Serial.println(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
  }
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handle_root);

 server.on("/thm", thm);
 /*server.on("/thm", [](){  ===== I have tried this inline as well no luck ====
   Serial.println("thos");
    String sendx = "signal sent... go back to previous page to verify";
    server.sendContent(sendx);
 });*/
  server.on("/thos",thos);

  server.begin();
  if(debug)
    Serial.println("HTTP server started");
}

void loop(void)
{

  server.handleClient();
}

Now please I would also appreciate your help for the commented portion of my code dealing with serial communication in function handle_root but it would be more than enough if you can point out my misconception or error or point me in right direction


text:
Better method for PROGMEM data access with multiple indirection?
-edit-
This is a simplified recreation of personal learning project I have ongoing.  My issue is in accessing data in flash, the path to which includes multiple layers of indirection.  When the data was in RAM I found accessing it easy and all worked as expected.
In flash I have created a struct mylist, aa in the example, containing a pointer to an char* array (item_list[ ])(in flash) pointing to char[ ] (in flash).
Problem: (refer to example) Given a pointer to struct aa (pml) and an index into item_list[] (ndx), how to correctly retrieve the string from flash.  My example illustrates the only method I can find that works. It seems kludgy at best, in particular needing to twice read pointers from flash as well as calculating the array item offset.  Have I missed a proper cast or perhaps become confused about 32 vs 16 bit pointers? Or, as strange as it seems, is this the correct and/or best approach?
All help and constructive criticism will be appreciated.
Code:
#include "Arduino.h"
#include <avr/pgmspace.h>

const char x[] PROGMEM = {"Item x"};
const char y[] PROGMEM = {"Item y"};
const char* const item_list[] PROGMEM = {x, y};

struct mylist {
  uint8_t nitems;
  const char** const list;
};
const mylist aa PROGMEM = {2,(const char** const)item_list};

const mylist* pml = &aa;

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

  char cbuf[11] = {"__________"};

  // two line with declared intermediate pointer
  uint8_t ndx = 0;
  const char* pitem = (const char*)pgm_read_ptr_near(&pml->list) + (ndx * sizeof(const char*));
  strcpy_P(cbuf, (const char*)pgm_read_ptr_near(pitem));
  Serial.print("item[0]: /");
  Serial.print(cbuf);
  Serial.println("/");

  // one line without declared intermediate pointer
  ndx++;
  strcpy_P(cbuf, (const char*)pgm_read_ptr_near(pgm_read_ptr_near(&pml->list)
                                                + (ndx * sizeof(const char*))));
  Serial.print("item[1]: /");
  Serial.print(cbuf);
  Serial.println("/");
}

void loop() {
  // put your main code here, to run repeatedly:

}

Output:
item[0]: /Item x/
item[1]: /Item y/

-edit-
After many more hours trying many more variations, I feel the approach shown in the following example is workable for me. I have chosen to keep the extra level of indirection to maintain all the flash data for a particular Field in one struct ‘package’. @NickGammon and his excellent examples greatly helped my understanding and comfort level with pointers in and to flash.
The listing is meant to give context to my point in question and is summarized in the method _copyitem( ) (hope the underscore is ok):
void Field::_copyitem(uint8_t ndx){
  PGM_VOID_P plist = pgm_read_ptr(&_fp->list);
  PGM_P pitem = (PGM_P)pgm_read_ptr(plist + ndx * sizeof(char*));
  strlcpy_P(_value, pitem, getLength());
}

This listing recreates a very small subset of the overall codebase, but the one part that has stopped my progress.
#include "Arduino.h"
#include <avr/pgmspace.h>

struct FieldDefinition {
  uint8_t nitems;
  const char** list;
  uint8_t row;
  uint8_t column;
  uint8_t length;
  // etc, etc
};

class Field {
public:
  Field(const FieldDefinition*  /* other parameters */);
  ~Field();  // -edit-
  char * selectItem(uint8_t);
  uint8_t getLength();
  char * selectItem(uint8_t);
  uint8_t getLength();
private:
  const FieldDefinition * _fp;
  char * _value;
  uint8_t _ndx;
  void _copyitem(uint8_t);
};

Field::Field(const FieldDefinition* fp ) : _fp(fp) {
  _ndx = 0;
  char * _value = new char[getLength()];
 _copyitem(_ndx);
};
Field::~Field(){  // -edit-
  delete _value;
};
char * Field::selectItem(uint8_t ndx){
  _ndx = ndx;
  _copyitem(_ndx);
  // display item
  // do more here . . .
 return _value;
}
uint8_t Field::getLength(){
  return pgm_read_byte(&_fp->length);
}
void Field::_copyitem(uint8_t ndx){
  PGM_VOID_P plist = pgm_read_ptr(&_fp->list);
  PGM_P pitem = (PGM_P)pgm_read_ptr(plist + ndx * sizeof(char*));
  strlcpy_P(_value, pitem, getLength());
}

// Setup flash data
// selection list
const char f1_0[] PROGMEM = {"Item 0"};
const char f1_1[] PROGMEM = {"Item 1"};
const char f1_2[] PROGMEM = {"Item 2"};
const char* const f1_list[] PROGMEM = {f1_0, f1_1, f1_2};
// create in-flash struct
const FieldDefinition f1 PROGMEM = {4,(const char**)f1_list,1,1,10};
// global instance and pointer to Field
Field * s1f1 = new Field(&f1);

void setup() {
  Serial.begin(115200);
  Serial.println();

  Serial.println();
  Serial.print("Field Length: ");
  Serial.println(s1f1->getLength());
  Serial.println();
  for (uint8_t i = 0 ; i < 3; i++) {
    Serial.print("Selection at index ");
    Serial.print(i); Serial.print(" : ");
    Serial.println(s1f1->selectItem(i));
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

Output
Field Length: 10

Selection at index 0 : Item 0
Selection at index 1 : Item 1
Selection at index 2 : Item 2

I could very wrong (as previously demonstrated) so comments please.
-edit-
Point taken and completely understood.  Destructor added for completeness.  In my actual application, multiple fields are constructed by a screen class when a screen is displayed, user interaction accepted, configuration data stored in EEPROM (my next endeavor), then destroyed on screen exit. Selecting from a list is one method available to populate the field value. The whole interface consists of multiple fields, for multiple screens, driven by an underlying state engine, stepped during each ‘loop’ to minimize impact. It functions as expected in an Xcode simulation, and has been a wonderful learning experience moving it to Arduino.  I thought all this was non sequitur to my question and regret any confusion I may have caused.
To restate my issue: how to get from
// ram based
strcpy(value, _fp->list[ndx]);

to
// flash based
PGM_VOID_P plist = pgm_read_ptr(&_fp->list);
PGM_P pitem = (PGM_P)pgm_read_ptr(plist + ndx * sizeof(char*));
strcpy_P(value, pitem);

using best/correct form with multiple layers of indirection as posted. Is it possible I have missed a proper cast or other mechanism that would allow the compiler to handle the ‘pointer magic’? It appears I have not. @NickGammon I greatly appreciate your input.

Is there some reason you're named your macros so that they specifically conflict with reserved identifiers (underscore followed by a capital letter)? Is there a reason for those macros in the first place?

@Matti  Certainly not intended to conflict, just stand out, and being the case I will stop. Suggestions for form of personal macros, or is there a standard?  The reason is purely personal, I am not good at with keyboards and after typing “Serial.print” the first hundred times I wanted to abbreviate.  Thanks for the observation.

I don't mean this unkindly, but I'm having a lot of trouble reading your code. Can you explain what it is doing? Whatever it is, I think there must be an easier way. Take a look at my page about PROGMEM - see if that helps. And @MattiVirkkunen is quite correct, variables starting with an underscore and followed by a capital letter are reserved for the compiler.

@Nick Gammon  Just the opposite, I take your comment as quite kind. I freely display my ignorance in hope of learning and improving.  Trust I shall never use _Cap again, or perhaps macros at all.  I have read your posted work with respect to PROGMEM several times and in fact have it bookmarked.  It has greatly help my transition to flash. Thank you!  I have edited my submission and reduced to my main point of question as the rest seems to be a distraction and not the insight into my thought process as I had hoped.

What is wrong here precisely? Is the output not what you expect?

See my amended answer to your amended question. :P

const char x[] PROGMEM = {"Item x"};
const char y[] PROGMEM = {"Item y"};
const char* const item_list[] PROGMEM = {x, y};

struct mylist {
  uint8_t nitems;
  const char** const list;
};
const mylist aa PROGMEM = {2,(const char** const)item_list};

It seems to me this is way too wordy for what appears to be trying to store a list of a couple of strings.

First:
const char* const item_list[] PROGMEM = {x, y};

You have a array of pointers to strings. OK.

Now:
struct mylist {
  uint8_t nitems;
  const char** const list;
};
const mylist aa PROGMEM = {2,(const char** const)item_list};

Now you have a list of an array? This is where I am confused.

Compare to an adaptation of the code on Putting constant data into program memory (PROGMEM):
const int NUMBER_OF_ELEMENTS = 2;

const char Message0000 [] PROGMEM = "Item X";
const char Message0001 [] PROGMEM = "Item Y";

const char * const messages[NUMBER_OF_ELEMENTS] PROGMEM =
   {
   Message0000,
   Message0001,
   };

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
    {
    char * ptr = (char *) pgm_read_word (&messages [i]);
    char buffer [80]; // must be large enough!
    strcpy_P (buffer, ptr);
    Serial.println (buffer);
    }   // end of for loop

  }  // end of setup

void loop () { }

Edited to comment on new code
You have a major problem here:
Field::Field(const FieldDefinition* fp ) : _fp(fp) {
  _ndx = 0;
  char * _value = new char[getLength()];
 _copyitem(_ndx);
};
char * Field::selectItem(uint8_t ndx){
  _ndx = ndx;
  _copyitem(_ndx);
  // display item
  // do more here . . .
 return _value;
}
uint8_t Field::getLength(){
  return pgm_read_byte(&_fp->length);
}
void Field::_copyitem(uint8_t ndx){
  PGM_VOID_P plist = pgm_read_ptr(&_fp->list);
  PGM_P pitem = (PGM_P)pgm_read_ptr(plist + ndx * sizeof(char*));
  strlcpy_P(_value, pitem, getLength());
}

What I gather you are doing here is, to get the string for an item (for printing) doing a new (which allocates memory), copying from PROGMEM into that memory, displaying that item, and then ignoring the allocated memory. Well, you can't do that. You will run out of RAM very quickly.
The code doesn't even have the word delete in it. Every new should have a corresponding delete. It's a fundamental principle.
It looks too complex still. Make a function that just displays the item (menu or whatever it is) without actually making a copy of it. Certainly don't allocate memory and not free it.


text:
LininoIO running "partially"
I installed LininoIO (OS dated 02 06 2015).
Everything seems to work fine - but nothing works as expected.
I have a running Linux - but when I try to use GPIO, as described on Lilino.org -GPIO on lininoIO, I run into the first problems.
D13 doesn't exist (this should be the little red LED on board of the Yún).
Next I tested reading the analog inputs.
I can for example use cat /sys/bus/iio/devices/iio:device0/in_voltage_A0_raw. There are no errors, but I always get the value 0.
Checking with /etc/linino/test_avrdude.sh shows:
Testing AVRDUDE on ATMEL 32U4 ...

avrdude: Version 6.1-20140519, compiled on Jun  2 2015 at 12:34:59
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : unknown
         Using Programmer              : linuxgpio
Can't export GPIO 11, already exported/busy?: Device or resource busy
avrdude done.  Thank you.

Maybe this is "by design" or another sign of an error.
By the way - when I start a serial console I get the message:
avr-uart: switched to uart mode: mcuio

Further in kernel log I found:
[   42.480000] fuse init (API version 7.18)
[   42.620000] spi_tty_plain spi1.0: spi_tty_probe
[   45.380000] No need to change console settings
[   49.550000] mcuio-hc 0:0.0: unexpected reply
[   49.600000] gpiochip_add: registered GPIOs 100 to 139 on device: generic
[   49.630000] mcuio adc is 0:1:1
[   49.750000] mcuio-adc 0:1.1: 6 input channels detected
[   49.910000] mcuio-hc 0:0.0: unexpected reply
[   49.970000] mcuio pwm is 0:1:2
[   49.970000] mcuio-pwm 0:1.2: 6 pwm outputs detected
[   55.790000] busybox: sending ioctl 5310 to a partition!
[   55.800000] busybox: sending ioctl 5310 to a partition!
[   55.820000] busybox: sending ioctl 5310 to a partition!
[   55.830000] busybox: sending ioctl 5310 to a partition!
[   56.290000] EXT4-fs (sda2): couldn't mount as ext3 due to feature incompatibilities
[   56.310000] EXT4-fs (sda2): couldn't mount as ext2 due to feature incompatibilities
[   56.360000] EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null)
[   58.520000] cfg80211: Calling CRDA for country: AT

It seems as if there are problems with mcuio-hc.
Last thing - when I ran run-avrdude /etc/linino/bathos-one.hex
I get an error when comparing the written data (I found information that this can be ignored).
How can I fix this / find out what to fix / what's going wrong?

finally I got it (somehow) working.
After a reset and another run of run-avrdude /etc/linino/bathos-yun.hex (the first was a mistake by copy and past - not bathos-one I already ran bathos-yun before) and a reboot again I was able to read analog IO.
But still the digitals were missing.
Than I found the command gpioexport an ran it.
After that the correct entries (D13, D14...) were present in sys/class...
But an echo out > D13/direction resulted in a timeout error message.
Again reboot - again the Dxxx entries were gone.
Another gpioexport made them appear again.
And this time not timeouts - instead I could turn on / of D13 (for test).
I guess all I have to do to make the things better is include gpioexport in "startup code" so that it runs after a reboot.

Have a look at the schematics of the YUN https://www.arduino.cc/en/uploads/Main/arduino-Yun-schematic.pdf
You will notice that most of the GPIO pins on the Atheros is not available to you. You only have access to the GPIO pins of the atmega.

I know this fact. In my example I'm talking about the D13 which is as pin from the 32U4. And the bathos-yun.hex makes those pins available in linux. Something like using the bridge.

And as I wrote in my second post it finally works - with some little problems. That wouldn't be if I couldn't somehoe reach the pins from linux

LininoIO has a part which runs on the microcontroller and make the Atheros enable to use the mcu pinout as linux gpios. So you are right, you need to flash the bathos to the mcu.
In general to enable/disable lininoIO run:
> lininoio start
> lininoio stop

those commands do everything for you.
have also a look here
Anyway your Linino version seems old, try to upgrade it: http://www.arduino.org/learning/tutorials/advanced-guides/how-to-upgrade-the-linino-distribution-for-arduino-yun-and-yun-mini