text:
Powering Arduino Uno from 5V pin, what exactly is the voltage range/tolerance?
I want to bypass the onboard regulator and use the 5V pin to feed arduino with external, regulated source.
Everybody just keeps saying regulated 5V, but how precise does the regulation need to be exactly? Can you state a voltage range and what makes you think so?
10 ways to destroy arduino, Method #5: Apply >5V to the 5V Connector Pin mentions "applying more than 6V", can anyone elaborate how it can be calculated?
Is there a higher spike that arduino can handle for a short period of time?
My concern is that the current draw from arduino might be under 60mA (right after switching power on and before the program initilizes and starts running), which is the lowest draw at which my source guarantees the 5V regulation --- when unloaded it gives out 6.5V. How could I resolve this better than putting a 60mA dummy load between the regulator and arduino itself?

Ditto on https://www.rugged-circuits.com/10-ways-to-destroy-an-arduino/ - The one thing I don't see in your question is precisely why you would want to bypass the internal regulator?  That could help guide more-specific answers.

Unfortunately there is no one "clear cut" answer for all you ask.
There are some hard limits, though, which you can get from the main chip's datasheet:

Operating Voltage: 1.8 - 5.5V

But that's not the whole story. The minimum voltage depends on the clock speed of the chip, as shown in this graph:

But wait, there's more. The Arduino also contains a 3.3V regulator which is fed from the 5V supply. That will have a minimum voltage above 3.3V that it needs to maintain a 3.3V output. So if you want to use the 3.3V regulator then, according to the datasheet for the regulator (LP2985-33DVBR):

3 Description
  The LP2985-N low noise linear (LDO) regulator delivers up to 150mA output current and only requires 300mV dropout voltage of input to output.

So a minimum of 3.3 + 0.3V, or 3.6V.
That gives you a usable range, clock frequency permitting, of 3.6V to 5.5V.
As to how to protect the Arduino from a power-on spike like you describe - you could:

Add your own extra regulation in the form of a 5.1V zener diode.
Add a dummy load which the Arduino can switch out of the circuit once booted up
Change your source to something with better regulation
Ignore it - the regulation with even a light load will be considerably better than open circuit.  Add a resistor across your supply that would draw much less than 60mA and measure the voltage. See how bad the regulation at low load is.

I am more worried about the top limits rather than underpowering, but it's interesting thought, I didn't generally expect that low voltage could break stuff too.

According to the datasheet the absolute maximum is 6V - above that and you will kill it. The "safe" maximum though is 5.5V, above which they don't guarantee it will keep working reliably for any sustained period of time.

Can too low voltage damage components too? Or will they just stop working until the mimimal required voltage is supplied.

It depends on what else they are wired to. In general you just get stability problems. In some situations, though, such as when you have a 5V signal feeding into a chip that is being under-powered, you may get physical damage from over-voltage on the input.

Too low a voltage can make the micro controller brown-out and do funny things. It might jump to anywhere in the code. So it could theoretically set pins that are meant to be inputs, to output, and cause damage that way. Though the ATMega on the arduino has brown-out detection. So unless you specifically disable it, this isn't a problem.

Ad protection by zener diode: Do I need to carefully select a diode that would be able to conduct all arduino might need (~200mA?), while operating below the actual breakdown voltage (5V, maybe 4.9V, not exactly the 5.1V)? Do I need to care about characteristics of the "knee region", or can we simplify the situation by saying that most of the diodes would be fine for the purpose?

You want a zener reverse polarity across the supply with a small resistor in series between the supply and the zener (the Arduino is powered from the join between the two). The resistor is to limit the current through the zener and drop the voltage between the supply voltage and the zener voltage. http://www.electronics-tutorials.ws/diode/diode_7.html

Most decent 5V supplies (e.g. USB chargers) are within 5% of 5V. I use these all the time to power directly to the 5V pin. There has never been an issue with this. I don't use supplies outside 5% for this. Check with your multimeter first.

You don't say why you want this information, but there are others who are trying to do similar.  (Starting with NOT destroying their Arduino)
For instance, at the end of the article
10 Ways to Destroy An Arduino
is a reference (broken link in the article) to
The Ruggeduino
which might be more suitable to your requirements.
Here is an excerpt of its specs:

The 6.5V is too much. I have had an ATtiny chip which seems to run fine after applying 8V to it. But how can I be sure that it is okay ? There are so many parts in the chip die that can be damaged.
There has been a few broken voltage regulators reported, when applying 5V to the 5V pin of an Arduino Uno. The reverse diode inside the voltage regulator might not keep up with a large current peak. In some of my projects I power an Arduino via the 5V pin. I have added an extra diode 1N4007 from 5V to VIN, to save the voltage regulator, and my 5V power is not very strong.
I also don't apply that 5V while it is on. It is from a DC/DC converter that is part of the project. So when I turn on the power, the 5V raises not too fast, and there is no high current peak.
When applying 5V to the 5V pin, the current can flow into the computer via the usb cable. The polyfuse of 500mA on the Arduino board will prevent most troubles, but it could damage the computer. When I turn off my computer with that project connected, I do indeed see an increase of the current to my project. My computer is luckely not broken (yet).


text:
ILI9341 backlight flickers when using USB power from Laptop
I've developed a project using am ILI9341, ESP12F and Arduino. Everything works fine except a very annoying issue. The LCD flickers when I use the laptop's USB. But when I use a USB charger it's much better.
I use https://github.com/Bodmer/TFT_eSPI library for SPI driver and AMS1117 as regulator (with 1uf in the input, and 10uf in output).
I don't think the software has a problem because I don't refresh anything on the display (just draw something in the setup function, not in loop) and also it changes with different power sources. The problem is the backlight.
When I move the USB cable it goes crazier sometimes. I've checked it with many different cables and computers. Is this because of noise or something from the USB port? How can I fix this?
It's very important for me to be able to use the USB port as the power source.
Update
When I'm uploading the code to the ESP8266 (using TXD & RXI), the LCD doesn't flicker event a little bit! And immediately after finishing the upload, the LCD brightness decreases and starts flickering!
The circuit is pretty simple and LCD pins are connected directly as listed here

Is it the backlight that flickers, or the TFT display?

Just backlight, no problem with display

Try adding a capacitor between Vcc and gnd, near the display.

That happens because not all USB ports can supply more than 500mA of current.
When you use a charger's USB port, it is designed to provide more than 500mA of current(ex. 1-2amps in most chargers). Try using a USB port that can provide more than 500mA of current. Most PCs and Laptops will only supply 500mA at maximum unless specified so.
More information regarding USB power can be read here on Wikipedia.
Cheers!

I don't have anything except an ili9341 & ESP12. Is it normal to need this much power!

Maybe there is a fault with your board. try to measure its current from the USB input using a multimeter. Be sure to put your multimeter in >500mA Mode to not damage it(the multimeter ^_^ )
Adding also a capacitor between the supply and ground may solve the problem also

I solve the problem controlling the frecuency of refresh with the led pin. With a timer of 10ms disappears flickering

I'd vote this up if I understood it and it looked like it addressed the question, but it's not really clear that it does.  Did your controlling of the frequency of refresh solve a problem that had to do with how your project was powered like the poster had?

I fixed this issue finally. The USB could supply both ESP and ILI9341, but the regulator could not. AMS1117 is not able to handle both EPS and ILI9341, we could connect ILI9341 directly to v5 (which it's not good and it would be hot!) or we can use another cheap regulator like XC6206P332MR just for the LCD.

source: Stack Exchange

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

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

sort: votes


text:
Arduino + IMU vs ArduIMU
I am working on a UAV and we are currently exploring inertial measurement units or IMUs. The two options that we have come across are:

Using an Arduino Uno and a 9 DOF IMU like this one
Using an ArduIMU chip like this one

Ignoring the cost aspect and assuming the same microprocessor on board, what would be the pros and cons of either of these approaches?
Keep in mind that performance is very important for a UAV controller as ESCs require 60 Hz or higher refresh rates for stable flight.

Weight: marginal as the difference between one board (with everything on it) and two boards (Uno plus DOF) may be - for model airplanes every bit counts.
Size: the traditional "Uno" is much larger than the ArduIMU integrated boards.
Power: the integrated board PROBABLY will use less and thus get away with a smaller (lighter) battery.

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


text:
MCU to MCU communication over UART
What would be the best way to send the following information from one MCU to another?
Now I'm just sending the sentence over as is eg. Serial.print(sentence in here)
Example sentence: 1306,60.123456,50.123456,23.765382,40.897558,245,85,20.3,5,65,1500,0.9
Many thanks.

It depends actually on your requirements what is 'best'.
If (transmission) speed is an issue, there are mainly some things you can do to improve this:

Increase the transmission speed (this depends on the distance of the wires and the noise).
Decrease the start/stop bits (this reduces the certainty the values will arrive ok)
Pack your data (takes more processing time possibly, and more programming work, but can be faster).

About the third option: since you are mostly sending values, you can make some improvements. So you can send them as float (by sending the float data, with the length of sizeof(float)). However, note there could be inaccuracies in the last digit.

Well I'm now at 9600baud and what I want to achive is less air time. How would one pack the values?

For example like I said, instead of serial.print, send it as floats

using Serial.print(floatVariable);

And boost the serial speed to 115200, will be 12x faster.

@CrossRoads if the noise/distance allows it, that's an easy improvement

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


text:
Cannot read modbus data repetitively
I try to communicate with 2 RS485 sensors (pH and EC), but I have some troubles with my code. First, I tried to get data from just one:
The function in charge of request sending:
String GET_probe(String probe){

if(probe == "pH"){
Serial.println("Sending request pH...");
digitalWrite(modbusModuleRE, RS485Transmit);  // Init Transceiver
digitalWrite(modbusModuleDE, RS485Transmit);  // Init Transceiver
byte  RTUrequest[] = {0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x85, 0xDB};
RS485Serial.write(RTUrequest, sizeof(RTUrequest));
}

if(probe == "EC"){
Serial.println("Sending request EC...");

digitalWrite(modbusModuleRE, RS485Transmit);  // Init Transceiver
digitalWrite(modbusModuleDE, RS485Transmit);  // Init Transceiver
byte  RTUrequest[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B};
RS485Serial.write(RTUrequest, sizeof(RTUrequest));
}

RS485Serial.flush();
RS485Serial.listen();
}

The function in charge of reading sensor's answer:
void ReadRx() {
     digitalWrite(modbusModuleRE, RS485Receive);
     digitalWrite(modbusModuleDE, RS485Receive);
     if(RS485Serial.available()) {
     Serial.print("Answer: ");
      for(int i=0; i<7; i++){
          String myByte = String(RS485Serial.read(), HEX);// Read the byte

          if (myByte.length() == 1)
          {
            myByte = "0"+myByte;
          }
          modbusHexBuffer[i] = myByte;

          Serial.print(myByte);
          Serial.print(" ");
      }
      Serial.println();
    }
   }

And the loop, sending the request each 5s:
void loop(){

  static uint32_t ts = millis();

  if (millis() - ts >= 5000) {
      ts = millis();
      GET_probe("pH");
  }

ReadRx();
}

The loop runs fine once and fails the second time, as shown in terminal. Can you tell me why and help me to fix it?
Sending request pH...
Answer: 00 03 02 05 78 86 f6
Sending request pH...

comments: wire DE and RE to one pin; you don't need to call listen if you have only one SoftwareSerial instance; don't use String; if  at least 1 byte is available you read 7

Are you talking about this line?:
String myByte = String(RS485Serial.read(), HEX);

regarding String and reading blindly, yes. use RS485Serial.readBytes(RTUresponse, 7);. readBytes will wait for the next byte

I have found why !!!
1st: buf[8] instead buf[7] in declaration
2nd: reinit byte buf[8] before EC request part.
So the code who works fine is:
byte buf[8];
void loop(){

      Serial.print("pH: ");
      digitalWrite(modbusModuleRE, RS485Transmit);  // Init Transceiver
      digitalWrite(modbusModuleDE, RS485Transmit);  // Init Transceiver
      byte  pHrequest[] = {0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x85, 0xDB};
      RS485Serial.write(pHrequest, sizeof(pHrequest));
      RS485Serial.flush();
      digitalWrite(modbusModuleRE, RS485Receive);
      digitalWrite(modbusModuleDE, RS485Receive);
      RS485Serial.readBytes(buf, 8);
     Serial.print(buf[3], HEX);Serial.println(buf[4], HEX);

byte buf[8];

      Serial.print("EC: ");
      digitalWrite(modbusModuleRE, RS485Transmit);  // Init Transceiver
      digitalWrite(modbusModuleDE, RS485Transmit);  // Init Transceiver
      byte  ECrequest[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B};
      RS485Serial.write(ECrequest, sizeof(ECrequest));
      RS485Serial.flush();
      digitalWrite(modbusModuleRE, RS485Receive);
      digitalWrite(modbusModuleDE, RS485Receive);
      RS485Serial.readBytes(buf, 8);
      Serial.print(buf[3], HEX);Serial.print(buf[4], HEX);Serial.print(buf[5], HEX);Serial.println(buf[6], HEX);

Serial.println();

}

rewrite it please as standalone answer


text:
Uploading code to Arduino wirelessly
I have been working on a project watch which would work best if it is entirely sealed (to waterproof it). The watch may need future updates, but I will be unable to send code to it using a usb connector or isp programmer without opening the case. What is the best way to connect my PC with this watch wirelessly?
I gather that the serial ports are usually used to send code via the usb, and that most Bluetooth modules use serial coms to communicate with the Arduino.
The Arduino that I am using is an Arduino Pro Mini clone.
Any help will be greatly appreciated.

Go simple, and use light. IR-receiver or photo-transistor.

There actually exists an Arduino BT board. (https://www.arduino.cc/en/Main/ArduinoBoardBT) which should be extremely easy (virtual bt COM-port as if it was connected to a cable). I'm not sure how up to date or available the board is though.

Alternatively, you could push a pin header through the box/casing, connect it, and cover it in hot glue. Which may be waterproof to some point.

You could use ESP8266 and ESP-LINK firmware to update the arduino firmware over the wire. Its also enables you to debug it wirelessly. What it does is provide a serial link but over wifi. Just like connecting it via cable.


text:
OLED not updating display
I'm trying to connect a GPS unit (GY-GPS6MV2) and an OLED screen as in the diagram below (green connector is GPS; VCC, RX, TX, GND left to right):

Here's the code I've come up with:
#include <Wire.h>
#include <Adafruit_SH1106.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
static const int RXPin = 5, TXPin = 3;
static const uint32_t GPSBaud = 9600;
float vkph;
float vmps;

TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);

void setup(){
  Serial.begin(9600);
  ss.begin(GPSBaud);
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(2000);
  display.clearDisplay();
}

void loop(){
  while (ss.available() > 0){
    gps.encode(ss.read());
    vkph = gps.speed.kmph();
    vmps = gps.speed.mps();
    if (gps.location.isUpdated()){
      Serial.print("Position: ");
      Serial.print(gps.location.lat(), 6);
      Serial.print(" : ");
      Serial.println(gps.location.lng(), 6);
      Serial.print("Speed: ");
      Serial.print(vmps);
      Serial.print(" m/s");
      Serial.print(", ");
      Serial.print(vkph);
      Serial.println( " km/hr");

      display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.println("Hello"); // Changing this to display.println(vmps);
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.println("World"); // Changing this to display.println(vkph);
      display.display();
      delay(1000);

    }
  }
}

The GPS outputs to the serial monitor fine, and the screen displays "Hello \n World" as expected. But when I make the changes indicated in the comments to the display part of the code, the display just shows its splash screen, flashing when the GPS updates.
How can I get the display to show the speeds in m/s and km/hr?

Maybe you need to add delay() in your code,I am not sure.

display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.println("Hello"); // Changing this to display.println(vmps);
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.println("World"); // Changing this to display.println(vkph);
      display.display();
      delay(1000);

Why, and where?

Because OLED doesn't have a time to keep showing.

Is this an answer or a question? Also please elaborate more, so that the answer is really helpful

I tried this, even before you posted the edit. Same problem, only now it takes 1000 milliseconds to flash the splash screen.

Have you also added the delay after the GPS display code?


text:
Array, hexadecimal and serial write
I am trying to write a pice of code which send to a receiver the frequency to listen.
As per its documentation, it should receive the following sequence:

Example with 123.456 MHz
Command to send (frequency converted in 4 bytes, followed by 2 instruction bytes
0x12 0x23 0x56 0x00 0x01

To be able to memorize six frequencies, I fill an array:
uint32_t mem_freq[6] = {
   0x121050,
   0x126500,
   0x120500,
   0x121700,
   0x121825,
   0x118700,
};

My concern is that when I do :
Serial.write(mem_freq[mem_index]);
//Serial.write(0x00);
//Serial.write(0x01);

Only 1 byte is sent, and it's hard to debug as the serial console displays only ascii characters.
When I use Serial.print instead, mem_freq[2] shows correctly 0x120500
After Majenko's answer, I tried this:
Serial.print(0x123456 >> 16,HEX);
Serial.print(0x123456 >> 8,HEX);
Serial.print(0x123456,HEX);
Serial.print(0x00,HEX);
Serial.print(0x01,HEX);

And it outputs:

12123412345601

Is this normal ?

use Serial.print(value, HEX) to print on Serial Monitor in hex form https://www.arduino.cc/reference/en/language/functions/communication/serial/print/

encoding 123.456 as 0x12 0x23 0x56 is very exotic. how do you use the frequency? I would send it as decimal number 123456. It fits into uint32_t

@Juraj, i think that the receiver hardware uses BCD and requires the above mentioned byte stream for correct operation

You need to manually split your values into bytes. You can either do that by storing them as individual bytes (as shown by Ignacio), or by using bit shifting:
Serial.write(mem_freq[mem_index] >> 16);
Serial.write(mem_freq[mem_index] >> 8);
Serial.write(mem_freq[mem_index]);

That sends the bits 16-23 (0x12) then bits 8-15 (0x10) followed by bits 0-7 (0x50).

Thanks Majenko. I have edited my post to show the result in ascii, and it is strange...

Since you have switched from write to print it can now print the entire number every time. If you want to print it you should also mask the value with & 0xFF.

Serial.print((0x123456 >> 16) & 0xFF,HEX);

That's because you need to use an array of arrays, and send three bytes.
uint32_t mem_freq[6][3] = {
  {0x12, 0x10, 0x50},
   ...
};

 ...
  Serial.write(mem_freq[mem_index], 3);
 ...


text:
avrdude: stk500_recv(): programmer is not responding - OSX10.11
I'm getting the following error with a genuine Arduino Uno on Mac OSX10.11 El Capitan when uploading to it (the green light is on, the orange light flashes intermittently while attempting to upload). Here's the error:
avrdude: stk500_recv(): programmer is not responding

I've tried all the solutions I can find. I've selected the correct port and board. I've tried pressing the reset button before uploading. I've tried different USB cables. I've tried unplugging and replugging everything. I've read this: http://arduino.cc/en/Guide/Howto .
I tried all these solutions here: https://stackoverflow.com/questions/23993111/mac-uno-avrdude-stk500-recv-programmer-is-not-responding
I tried the FTDI fix, (but not sure if was actually able to disable the mac drivers, or which drivers are now running, the example I tried is for for OSX 10.10 Here). I ran into the following issue in the Terminal:
Mac-Pro:~ m$ cd /System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns
Mac-Pro:PlugIns m$ sudo mv AppleUSBFTDI.kext AppleUSBFTDI.disabled
mv: rename AppleUSBFTDI.kext to AppleUSBFTDI.disabled: No such file or directory

I don't get why it says No such file or directory because AppleUSBFTDI.kext definitely exists as a package in the Extensions folder, but I guess it's talking about another file named that in the plugins folder? Confusing ... Was this moved in OSX 10.11 and should I rename this package in the Extensions folder?
I did download and install the old FTDI drivers, but I don't know if they're actually the ones working right now? How do I clarify that?
Any ideas how to get this working?
I also tried on an old Mac Laptop 10.6.8 - Snow Leopard, and had the same issue :(

Has this ever worked?
Can you use avrdude and hit the target?
There is a terminal mode in avrdude you can also use.  At least this would help you determine what is working.
Sounds like a configuration issue.  If you have the ability to 'follow the tail' (tail -f ) I'm assuming that you have 'like' tools we have in Linux like lsusb to assist?
You can ensure yourself that if it says it isn't found, it's not finding it, so it's not wherever it's looking. :)

It had never worked.  I think it was just a bad one, I got a new one, works perfectly :D

I had this problem for some time and what I did was I deleted the Arduino IDE and reinstalled it again and it worked. Thanks!

Nothing I tried could get it to work. I took it back on the hunch it was a bad one, that something was just not working right on it. And got a new one directly from the Arduino people. The new one works just fine! Problem solved :D

authors: Роман Андреев


text:
What is the Arduino compiler's version of `__unused` for function parameters?
When I first started with the Arduino environment I noticed that it had File | Preferences | Compiler Warnings set to None, so I set it to All - and there were many, many warnings in the supplied libraries! So I quickly set it to None again - until later.
Well, "later" is now, and I started going through the warnings to fix the code to quiet the compiler.
Note that I don't want to disable any warnings - I want to placate the compiler at each spot so that it says to itself "No problem here!"

If the compiler complains of an unused variable, I comment out the variable;
If it complains of a signed/unsigned comparison, I change the type;
If it complains of an unused parameter in a function, I...

...hmmm. If this was C++, I'd simply comment out the parameter name, leaving the type naked:
void Fn(int /*param*/) {
} // Fn(param)

Arduino reports:
error: parameter name omitted

But that isn't legal in C. With some compilers you can use the __unused attribute:
void Fn(int __unused param) {
} // Fn(param)

Arduino reports:
error: expected ';', ',' or ')' before 'param'
    It's interpreting __unused as the actual parameter name

or if they're fussy:
void Fn(int __attribute__((unused)) param) {
} // Fn(param)

Arduino reports:
warning: unused parameter 'param' [-Wunused-parameter]
    That's not the correct __attribute__, obviously

So none of the above work in the Arduino environment. Suggestions?

I've been programming in C and C++ for over twenty years, and I know that the #1 thing you should always do is ask the compiler to tell you about everything it notices. You need a warning-free compile at all times! Otherwise, you spend hours or days trying to find a bug - only to discover that the compiler has been warning you about it all along...

The Arduino core is a mixture of C and C++. The void f(int) {...} idiom should work in the C++ files. I agree it's a shame the core generates so many warnings.

Well, I typed all that question up for posting, then tried one last thing. It worked!
void Fn(__attribute__((unused)) int param) {
} // Fn(param)

So, rather than let a good question go to waste: here's the answer!
Now all we need to do is get the maintainers of all the libraries to put these in... and fix the other warnings...

Another idiom often used in C is void f(int param) { (void) param; ... }.

Within the body of a function you can do this to suppress a warning:
void do_something(int value) {
  (void) (value);
  . . .
}

You can use a macro to do the same thing, for better clarity:
#define UNUSED(v) (void) (v)

void do_something(int value) {
  UNUSED(value);
  . . .
}

This can be helpful in situations where you have conditional compilation:
void do_something(int value) {
  #ifndef USES_PARAM
    UNUSED(value);
  #else
    other_stuff(value);
  #endif
  . . .
}

I know most compilers will do the "right thing" with that, but I've seen some that emit the "load" - and then do nothing with it. The nice thing about "decorating" a variable declaration is that it does two things: it signals the compiler, not the code generation part; and it merely flags a possibility, not a guarantee. If you actually use a variable that is flagged as unused, then the compler doesn't complain. So in your final example, you decorate value and don't need both sides of the #if[n]def


text:
More missed messages with longer cables with nRF24L01+?
I am using nRF24L01+ 2.4 GHz transceiver.
When I connect them directly (with SPI pins 10..13 from Arduino) to the adapter board for the nRF24L01 I get occasionally errors (meaning the receiver does not get the sent message).
However, I want to use one nRF24L01 purely for transmitting, and one for receiving. So each Arduino will have 2 nRFs, one for receiving, one for transmitting.
Since they both use SPI, I need to take the pins 10..13 to a breadboard and forward them from there to both nRFs. However, I did a test with only the transmitter, and found out I get more errors than direct wiring.
The only difference is that I now use extra jumper wires (4" / 10 cm). Can the extra cable length cause problems?
Would it help if I use less long M/F dupont cables? (so the total length still is 8"/20cm)? ... I don't have such short ones, so I cannot try.
I use for the breadboard to the nRFs 8"/20cm M/F dupont cables.
See picture below. The white/grey/red/blue 20cm/8" dupont cable directly wired to pins 10..13 Arduino gives less errors than the situation on the photo where the white/orange/red/blue 4"/10cm cables are added.

More likely to be the breadboard itself. Try rotating the module 180 degrees so the antenna trace is outside the footprint of the breadboard.

@Majenko see the comment in the answer of Code Gorilla ... it cannot be the rotation or breadboard. Unless the connection of the wires to the breadboard might cause it.

@Downvoter, can you instead of downvoting all my posts, explain WHY you downvoted, so I may improve the post.

the Antenna is interfering with the signals because of its proximity to the point on the bread board where you are connecting the wires, as Majenko said.
If you rotate the nRF24L01 board 180 degrees you will increase the distance between the wires and the antenna and this will reduce the interference, but because of the way radio waves propagate there is also a chance that it may make it worse.  The radio wave propagate from the antenna in a share particular to the antenna.  I don't know what shape this antenna puts out, I'd expect it to be omnidirectional (all ways) because of its purpose.  However all directions are not equal because of reflections, the shape of the antenna, defects in the shape of the antenna, etc and if the pattern of the propagation can be mapped you can identify the make of board and if the mapping is accurate enough even the instance of the board itself.
So, to cure interference:

Increase the distance this reduces the power of the interference by the square of the distance.
Change the orientation, usually by something other than 90 or 180 degrees.
Shield the wires.

In short move the antenna further away from the wires, can you use MF DuPont wires to remove the radio from the breadboard all together.  The fact it won't sit still and is sliding all over you desk will probably help with reflections.

Maybe it was not fully clear from my question, however the 2 radios you see do not communicate with each other. One is only for transmitting, one only for sending. In my case only the upper one is used (the other is not even connected).
The only change between better and worse communication is that in the better case pins 10-13 for SPI are directly connected from the Uno to the (upper) RF and in the worse case wires are first lead through the breadboard and than to the RF.
In both cases the upper (and lower unused) radio were on the breadboard

Also in interesting comment about the breadboard, I had them sliding over my desk, that's why I add them to the breadboard (not connected, just not to have them move around). But even that, without the longer wire through the breadboard and the RF still on the breadboard I had better communication.

The junction of your wires is directly under the antenna. That is what you need to move the module away from.

Ah ok ... so it's mostly the routing instead of the breadboard ... I will check into it this evening. Thanks for the remarks/tips (Code Gorilla and Majenko)

The large chunks of metal under the antenna (breadboard strips) won't be helping your signal quality much. In general it's best to not have any metal around the antenna area - hence the suggestion to rotate 180 degrees and have the antenna sticking out of the breadboard footprint.

Sticking the board vertically may be the best solution, because that antenna design is going to output least of its signal out the thin edge of the PCB.  Therefore least signal goes to the metal in the breadboard.

@Majenko ... indeed I found out that ... I removed one and it's getting better. I now put them opposite of each other (thus closer) and get less errors. Not sure how I will do it later if/when I'm going to build it in a box but so far it helped, thanks.

@CodeGorilla I will do that when I wil put it in a box (can take some time, the hobby project has just started). . But it helped when it was off. Also I could even send upto about 10 meters around corners (getting still some errors though).

@MichelKeijzers - You probably need to devise a very tolerant protocol then, packet serial numbers and stuff.

@CodeGorilla ... my intention is indeed to put a 1 byte serial number (sequence) ... if more is needed than the communication is a mess anyway :-)


text:
Multiple SPIs on one Arduino [SOLVED]
Setup

I have 2 Arduinos... each has two 2.4 GHz nRF24L01+ transceivers (so in total 4).
Per Arduino, one is only for transmitting, while the other is for receiving (to prevent the need for switching between transmitting and receiving).
The receiver and transmitter are on different channels (per Arduino, so channel 109 for receiver on arduino 1 and transmitter on arduino 2 and 112 for the other pair).

SPI / Chip Select
Because the nRF24L01+ are SPI devices, I need to use Chip Select, since there is only one SPI bus on an Arduino.
Setup settings
Since I can both receive and send (successfully) I did not add the Setup code (I used slowest speed 250 kbps, 16 bytes payload, no auto ack, no retries, highest power).
Problem
I can transmit/receive from both Arduinos, so all 4 transceivers work correctly.
However, what I see in the output (see directly after the logging), is when I send, a lot of messages which should be received are missed. See the log at the end
Also, when I remove the write and replace it by a delay(1) than I miss just occasionally a message, so I think the write is the problem.
Assumption
Is it possible that during the write so many message from the other Arduino are colliding? I would expect a very fast on-air time, and even than, using two different channels should not make messages collide.
So it seems, while calling the Transmit for one RF, the other does not receive somehow. I know the CS pin of the receiver is HIGH (inactive) during transmitting (transmitter CS pin is LOW), but I would assume messages would be received by the RF, and when I set the CS pin of the receiver to LOW (active), that I can read the messages.
Code (of one of the Arduinos)
The code for the other Arduino is almost similar (only opposite port names as transmitter/receiver)
/*
*/
#include <SPI.h>
#include "RF24.h"

static const uint8_t RECEIVER_CE    = 5; // Chip Enable
static const uint8_t RECEIVER_CS    = 6; // Chip Select
static const uint8_t TRANSMITTER_CE = 7; // Chip Enable
static const uint8_t TRANSMITTER_CS = 8; // Chip Select

RF24 radioReceiver(RECEIVER_CE, RECEIVER_CS);
RF24 radioTransmitter(TRANSMITTER_CE, TRANSMITTER_CS);

uint32_t counter = 0;

static const int PAYLOAD_SIZE = 16;

static const int NR_OF_LOG_ITEMS = 10;
static const int LOG_LENGTH = 25;
uint32_t logData[LOG_LENGTH][NR_OF_LOG_ITEMS];
uint8_t currentLogLine = 0;

void setup()
{
  for (int m = 0; m < LOG_LENGTH; m++)
  {
    for (int n = 0; n < NR_OF_LOG_ITEMS; n++)
    {
      logData[m][n] = -1;
    }
  }

  pinMode(RECEIVER_CE   , OUTPUT);
  pinMode(RECEIVER_CS   , OUTPUT);
  pinMode(TRANSMITTER_CE, OUTPUT);
  pinMode(TRANSMITTER_CS, OUTPUT);

  digitalWrite(RECEIVER_CE   , HIGH);
  digitalWrite(TRANSMITTER_CE, HIGH);

  Serial.begin(250000);
  Serial.println(F("CONTROLLER"));

  digitalWrite(RECEIVER_CS   , LOW); // Select
  digitalWrite(TRANSMITTER_CS, HIGH); // Deselect

  radioReceiver.begin();
  radioReceiver.setPALevel(RF24_PA_MAX);
  radioReceiver.setChannel(109);
  radioReceiver.setDataRate(RF24_250KBPS);
  radioReceiver.setRetries(0, 0);
  radioReceiver.setAutoAck(false);
  //radioReceiver.enableAckPayload();
  radioReceiver.setPayloadSize(PAYLOAD_SIZE);
  //radioReceiver.enableDynamicPayloads();
  //radioReceiver.disableCRC();
  radioReceiver.setCRCLength(RF24_CRC_8);

  digitalWrite(RECEIVER_CS   , HIGH); // Deselect
  digitalWrite(TRANSMITTER_CS, LOW);  // Select

  radioTransmitter.begin();
  radioTransmitter.setPALevel(RF24_PA_MAX);
  radioTransmitter.setChannel(112);
  radioTransmitter.setDataRate(RF24_250KBPS);
  radioTransmitter.setRetries(0, 0);
  radioTransmitter.setAutoAck(false);
  //radioTransmitter.enableAckPayload();
  radioTransmitter.setPayloadSize(PAYLOAD_SIZE);
  //radioTransmitter.enableDynamicPayloads();
  radioTransmitter.disableCRC();
  radioTransmitter.setCRCLength(RF24_CRC_8);

  byte addresses[][6] = {"Read ", "Write"}; // TODO: Change name to slave/contr?
  radioReceiver.openReadingPipe(0, addresses[1]);
  radioTransmitter.openWritingPipe(addresses[0]);

  radioReceiver.startListening();
  radioTransmitter.stopListening();

  //radio.writeAckPayload(1, &counter, PAYLOAD_SIZE);
  //radio.printDetails();
}

uint8_t receiverBuffer   [PAYLOAD_SIZE];
uint8_t transmitterBuffer[PAYLOAD_SIZE];

uint32_t prevResponse = -1;
uint32_t response;

void loop(void)
{
  // Transmit.
  //Serial.print("Sending: ");
  //Serial.println(counter);

  transmitterBuffer[0] = counter >> 24;
  transmitterBuffer[1] = (counter & 0x00FFFFFF) >> 16;
  transmitterBuffer[2] = (counter & 0x0000FF00) >> 8;
  transmitterBuffer[3] = (counter & 0x000000FF);

  digitalWrite(TRANSMITTER_CS, LOW);  // Select
  digitalWrite(RECEIVER_CS   , HIGH); // Deselect
  //if (!radioTransmitter.write(transmitterBuffer, PAYLOAD_SIZE))
  {
    //Serial.println(F("Sending failed."));
  }
  delay(10); // Fake write

  // Receive.
  byte pipeNo = 0;

  digitalWrite(TRANSMITTER_CS, HIGH);  // Deselect
  digitalWrite(RECEIVER_CS   , LOW); // Select

  while ( radioReceiver.available(&pipeNo))
  {
    radioReceiver.read(receiverBuffer, PAYLOAD_SIZE);

    response = (receiverBuffer[0] << 24) +
               (receiverBuffer[1] << 16) +
               (receiverBuffer[2] << 8) +
               (receiverBuffer[3]);
    Serial.print("Received: ");
    Serial.print(response);

    if (prevResponse == -1)
    {
      prevResponse = response - 1;
    }
    else
    {
      if (prevResponse + 1 != response)
      {
        Serial.print(" MISSED ");
        Serial.print(response - prevResponse - 1);
      }
      prevResponse = response;
    }
    Serial.println("");
  }

  // Logging
  currentLogLine++;
  counter++;
  delay(10);  // Try again later
}

Log
Received: 10261 MISSED 15
Received: 10262
Received: 10263
Sending: 245
Received: 10278 MISSED 14
Received: 10279
Received: 10280
Sending: 246
Received: 10296 MISSED 15
Received: 10298 MISSED 1
Received: 10299
Sending: 247

"A complete minimal verifiable example" :)  Am I right in assuming response and prevresponse are longs?  Am not quite sure if you are doing what I think is this one Arduino talking to itself or two Arduinos talking to each other?  If its the latter how do you know that the when you are transmitting from Ard.A the Ard.B is receiving?  (Not familiar with these radios, so it might be a stupid question)

@CodeGorilla I added the full code (for the slave, which is similar to the controller), and yes two Arduinos (slave/controller) talk to each other, both arduinos have 2 RFs, one transmitting only and one receiving only. THey have different frequencies and different SPI SlaveSelect pins.

Brilliant.  So how do you synchronise the transmissions on A with the receive on B?  I think what might be happening is A is transmitting before B is receiving and that is why you are loosing packets.  Does that sound reasonable?

@CodeGorilla Thanks (I guess) ... I don't synchronize to be honest. Since sending is only done by two RFs (on two different Arduino's) and two different frequency ranges, I don't expect any collisions. It's like a two lane highway (or street), bidirectional. I am planning to implement my own acknowledgement system (since I want to send data along with the ack signal with data that might not readily be available).

(later it will be more complicated when there will be multiple Arduinos transmitting, but I try to solve this problem first for making it more complicated.

You mark the question as answered by accepting an answer not adding [SOLVED] to the title.

[solved] ... I found out I HAVE to put one of the CS (chip select) pins to pin 10.
I thought it would not needed since the CS pin is different per SPI device, but it seems one needs to be on pin 10. Or at least, now I don't get problems sending/receiving (except some errors now and than, but that's normal with RF devices).
Thanks for everybody giving comments to my question.

You don't have to actually use it as a CS pin, but pin 10 MUST be an output according to the documentation for the SPI library.

@Delta_G I did not do that when I posted the question... but I can better use pin 10 anyway as CS as output pin in this case to make sure I don't use it for anything else (and forget making it an output pin again)... thanks for the valid comment.

Quite right, it just has to be an output. I suggest accepting your answer.


text:
Counting loops or if..else
What I would like to do is,
 step 1:
led1 fades from black(off) to green (max-on 255)
led2 fades from black(off) to red (max-on 255)

this happens at the same time.
If the max value is reached, then both leds fade out (to black, off)
so step 2:
led1 fades from green to black
led2 fades from red to black

Then step 3, almost same as step 1 but opposite colours:
led1 fades from black(off) to red(max-on 255)
led2 fades from black(off) to green(max-on 255)

And step 4, both fade to black
led1 fades from green to black
led2 fades from red to black

This is the code that fades led 1/3/5 from red to black and back to red
and led 2/4/6 from green to black, and back.
#include <FastLED.h>
    #define NUM_LEDS 6
    #define DATA_PIN 3

        CRGB leds[NUM_LEDS];

           void setup() {
               Serial.begin(9600);
       FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
   }

       void loop()
{

  int x = 1;
   for (int i = 1; i > -1; i = i + x){

     leds[0] = CRGB(i,0,0);
     leds[1] = CRGB(0,i,0);
     leds[2] = CRGB(i,0,0);
     leds[3] = CRGB(0,i,0);
      Serial.println(i);
      FastLED.show();
      if (i == 55) x = -1;             // switch direction at peak
      delay(100);

   }
}

****Original question****

I am trying to fade a led (WS2812B) from black to green or red, and
  back to black. (that is working)  But now I want the same led fading
  to blue.
How could I do that? I was trying a if..else but can't figure it out
  Or should I count the for loops?
This is the starting code I am using
maybe something like
    if (i==0)
{
             leds[0] = CRGB(i,0,0);
             leds[1] = CRGB(0,i,0);
             leds[2] = CRGB(i,0,0);
             leds[3] = CRGB(0,i,0);
}
    else
{
             leds[0] = CRGB(0,0,i);
             leds[1] = CRGB(0,0,i);
             leds[2] = CRGB(0,0,i);
             leds[3] = CRGB(0,0,i);
}
              FastLED.show();
              if (i == 100) x = -1;
              delay(100);

But that is not working. Any suggestions?

Please provide your entire code, which doesn't work. Please tell us what it does, and what you expect/want it to do.

the same led fading to blue. Please elaborate.

added some new info

The maximum value is 255 for each RGB value, you are stopping it at 100.

I would do that based on the clock. This lets you run each one independently.
On the off-chance that your project runs that long, the clock rolls over (resets) every 50 days.
I'm going to assume the 55 in your code should read 255.
I would do something like this (this is a code snippet, but should get you started):
const int phase_milliseconds=2500; // each phase lasts 2.5 seconds.
const phase_progress_length=256;   // each phase goes from 0 to 255
const phases=4;                    // numbered from 0 to 3, will repeat forever.

// This is the time since your Arduino turned on
unsigned long time=millis();
// how far we are through the current phase?
int progress= time%phase_milliseconds)*phase_progress_length/phase_milliseconds;

// which phase are we in?
int phase=(time/phase_milliseconds)%phases;

if (phase==0) { // first step
         leds[0] = CRGB(progress,0,0);
         leds[1] = CRGB(0,progress,0);
} else if (phase==1) { // second step
         leds[0] = CRGB(255-progress,0,0);
         leds[1] = CRGB(0,255-progress,0);
} else if (phase==2) { // third step step
         leds[0] = CRGB(0,progress,0);
         leds[1] = CRGB(progress,0,0);
} else if (phase==3) { // fourth step
         leds[0] = CRGB(0,255-progress,0);
         leds[1] = CRGB(255-progress,0,0);
}

Since this is time based, it doesn't matter much how often it runs, you don't need a delay (you can still put one in if you like). You can extend this to more steps.
Also note that I rattled this off, off the top of my head, so there may be errors.


text:
How do I use I2C from an Arduino Uno when I have a GSM shield mounted?
This may be an extremely obvious question but I don't seem able to find a definitive answer.
I have an Arduino Uno and a Sim900 GPRS/GSM shield fitted on top of it. I had I2C working on the Arduino to communicate with a Raspberry Pi, but now that I have put the shield on top I can't get the Pi to detect the Arduino. As far as I can tell the SDA and SCL pins on the Arduino aren't being used by the shield so does anyone have any idea how I go about this?
Thanks

There seems to be a number of different Sim900 shields from different suppliers? I suggest you check/post the datasheet of the one you're using. If I2C works without the shield, and does not work with the shield connected , then it seems logical that there is a pin clash.
There is a good Random Nerd Tutorial on getting started with the shield on a Uno. Maybe test it out completely before connecting to the Raspberry Pi?
The Raspberry Pi is 3.3v and the Uno is 5v. You didn't mention level shifting in your question, but it may be worthwhile.

I mean thanks for the reply, but this question is nearly 6 years old lol. At this point I haven't got the faintest recollection of how I actually fixed it

@Brae :-) No problem, I’m new to the forum and had to find some entries to contribute to to build up some points. Glad to hear your project worked out.


text:
Uploading/Flashing different programs to two different Arduino uCs, using one USB
I'm designing a custom dual-uC board, where I want there to be two Arduinos both running different programs - kind of dual core arduino. In order to load new programs onto the uCs, yes, I could have two USB ports each connected to one of the uCs (say a ATmega32u4). But I'm trying to work out strategies with just one USB port (and no usb-hub).
Also, I don't need the USB functionality for general use, only for program updates.
Option 1:
Switch access to each USB capable Arduino (e.g. ATmega32U). Program one uC, toggle switch, program other uC
EDIT: this is fine, however I ideally want to use zero additional end-user buttons - I want the end-user to do as little as possible.
Option 2:
The arduino UNO has two devices, ATmega16U2 and a ATmega328. During normal operation the 16U operates as a usb-to-serial. However, I'm aware that there are custom firmwares that allow different functionality (such as USB-Joystick etc) - it is possible to switch firmawares between a custom-firmware and default firmware, to allow the ATmega328 to be programmed normally but also to run the custom program. But it seems that Arduino.h doesn't support the ATmega16U2, so I would have to program this device using the AVR or another framework.
Alternatively, the ATmega32U4 is supported by Arduino.h but there doesn't seem to be Arduino usb-serial 'firmware' for the 32U (only the 8U & 16U)
Option 3:
Can I use a ATmega32u4 with Arduino-ISP programming an ATmega328p?
EDIT: above seems valid:
https://petervanhoyweghen.wordpress.com/2012/09/16/arduinoisp-on-the-leonardo/
Other simple recommended approaches?
EDIT: the firmware update should be physically as hands off as possible, as to be used by end-user, and preference for solutions that require zero additional buttons/etc
UPDATE:
I tried the Arduino as ISP method (option 3), and it works

Since you don't need USB cable for general use, I strongly recommend 1) as it is very simple. But if you do need it after code has been uploaded, then things get complicated........

You should be able to get the ATMega16u2 to work with the IDE relatively simple. I'd suggest option 1, but I'd add some headers for an external  USB-to-Serial adapter. That way you don't require chips with usb support (cheaper). Either add two headers, one for each chip. Or add a triple pole, double throw switch (TX,RX,DTR). Or DPDT if you don't mind both chips resetting (which would actually be a nice feature).

Provided that you are okay with producing a customized PC side tool (which you would probably want anyway for user convenience) automated target selection should be far superior to manual.
You should be able to use one ATmega16u2 with a  minimally customized firmware as a front end to program two distinct ATmega328p's.  This could be as simple as selecting the target based on the baud rate, having it hold the de-selected one in reset the whole time, and using some resistors on the shared TX lines for safety.  Last I checked the stock firmware used a soft serial at some rates, and that can be put on different pins, so it could be another way to de-conflict and select targets.
Your idea of using a 32u4 both as a functional part and as a buddy-programmer for another part is perfectly valid too - you can do that programming to a serial bootloader (it should be a simple matter to port the 16u2 firmware, or find another example), or via the ISP pins.
Now that I think about it, there's been a version of this question here before, as I remember writing about an idea for using two ATmega328p's permanently wired to a stock USB-serial, but with their bootloaders customized to use unique baud rates, and a little logic added so that on reset each would leave its serial TX pin tristated if it didn't detect bootloader traffic at its individually unique baudrate, thus allowing the other to be programmed without interference.

Option 1 using three header pins and a jumper wouldn't take up much board space, is simple to implement, and easy to use. Even easier if the jumper has a handle.

You'd need two set of these. One for D+ and one for D-. I'd suggest a DPDT switch.

Header pins and jumper for what ?

Rx & Tx from the USB->Serail converter, for which two sets will be needed as @Gerben points out, to Rx & Tx of one or the other of the '328s.

this is fine, however I want this to be idiot proof


text:
Two nRF24L01 radios per Arduino
Due to the results of my previous post (Slower nRF24L01 round trip delay than expected) I found out that it will be quite difficult to reach my latency requirements.
I am thinking about using my own protocol (instead of the 6-1 Multiceiver protocol), but that would involve getting some kind of 'clocked' receive and send times for devices, which will not make it simple probably. The time to change from reading to writing is less than expected (startListening takes max 350 us and stopListening 450 us). However, if I need to do this ever 5 ms and making sure no devices are reading/sending to others, that's quite a bit of downtime.
So I was thinking, would it be a good (or stupid) idea to use TWO nRF24L01's per Arduino, one by default in reading mode, the other on writing mode (thus having bidirectional communication) and using two different channels. This means I never have to switch between reading and writing and can read/write simultaneously without message colliding.
(note: later I want to use multiple Arduinos and one STM32 device).
Does anyone see problems in this idea?
Requirement goals:

Latency: less than 10 ms to send it from device A to B, process it (excluded, takes a few ms) and send back from B to A (or in some cases B to C). Less than 10 ms is better.
Amount of messages: can be theoretically hundreds per second, in practice max 100 (from various devices, but all go through a processor-device).
Payload per message: 16 bytes probably, most are shorter, some are longer but I can split or combine them if needed.
Range: about 10 meters max, but in a music/band stage environments
Channels: I will not use the WIFI channels, but a range of others, also (professional) wireless mics do not work on 2.4 GHz, so I don't expect too many problems.

About channels: I don't expect any problems. I should have enough channels between 2.484 and 2.525 GHz. This gives me about 40 channels for 1 mbps or 20channels for 2 mbps to chose from.

sources:

2.484 GHz: WIFI Channels, first table with red/green items
2.525 GHz: Datasheet, paragraph 6.3.

What is your overall wireless communications goal? Bandwidth, latency, etc? NRF24L01 might be 2 Mbps (bitrate) but my guess is that 1-2 KBps is somewhat the limit. They are fine/designed for short and less frequent messages such as from a wireless mouse, e.g. 20 ms update frequency, 16-32 byte payload. Also you might want to try changing channel to avoid noise (message drops) due to WiFi.

@MikaelPatel I improved my answer, I think 1-2 KBps would be sufficient, 20 ms is way too long for my needs, payload can vary.
I thought I wouldn't have problems with WIFI, I could do an occasional channel check though.

@MikaelPatel from 2.484  to 2.525GHz. I should have enough channels (sources: https://en.wikipedia.org/wiki/List_of_WLAN_channels#Most_countries, first table with red/green items,  2.525: https://www.nordicsemi.com/chi/content/download/2730/34105/file/nRF24L01_Product_Specification_v2_0.pdf paragraph 6.3. This gives me about 40 channels for 1 mbps or 20channels for 2 mbps to chose from.

I can see no reason not to use two nRFs concurrently. You may want to turn off auto-ACK and use Enhanced ShockBurst mode though to get better throughput.

@Majenko ... that sounds good ... I was already planning to switch off auto-Ack (actually all ACK) and implement the 'ACK' myself. I have to check into Enhanced ShockBurst (if that is the 6-1 Multiceiver idea I will use it).

@Majenko ... I checked into it and I thought that was the only way (using Enhanced Shockburst). Actually I'm using http://tmrh20.github.io/RF24/index.html which highlikely makes use of that. I will disable ACKs/retries and handle those myself.

@Downvoter, can you instead of downvoting all my posts, explain WHY you downvoted, so I may improve the post.

At 2 Mbps, a 32-byte packet (40 bytes with preamble, addresses, CRC) will be approx 160 microseconds long.  The round-trip time is likely to be much longer, since the microcontroller or radio will need additional time delays for auto-retry, sending and receiving the response packet, PLL lock, reading the data registers, etc.  In my experience a 2 ms round trip is possible, and the best way to do that is make use of the nRF built-in features:
-- IRQ interrupt: interrupts = fast
-- Enhanced Shockburst: this automatically handles lost packets and failed transmissions.  You can't get that capability any faster via the microcontroller coding.
On top of this, there is scope to use fast SPI libraries (or use SPDR/SPCR registers directly) to transfer data to and from the radio module.  If speed is your goal, don't rely on plug-and-play libraries that others have written.  Read the data sheets carefully and minimize unnecessary delays within the Arduino code.

I deviated my project slightly, so I will not use nRF's for the time being, and if so, probably on STM32, not Arduino, but good to know it's better to use the builtin way.


text:
Need help on HC05 and Nano
I am new to Arduino programming and currently working on this instructable
http://www.instructables.com/id/Control-Led-RGB/ (following this diagram http://cdn.instructables.com/F6Q/IMHF/I0LCDK6B/F6QIMHFI0LCDK6B.LARGE.jpg)
I have ordered these parts as well.

Arduino Nano: www.ebay.in/itm/Arduino-Nano-SOLDERED-PINS-V3-0-ATmega328-CH340G-BUY-2-GET-1-USB-CABLE-FREE-/172117729247?
HC-05: www.amazon.in/Bluetooth-Transceiver-Module-TTL-Outputs-HC05/dp/B00R95Y0AK?ie=UTF8&psc=1&redirect=true&ref_=ox_sc_act_title_2&smid=A1NDZY44BCNIQJ

My questions are:

Is there need to add voltage divider? If yes can you please provide link?
Can I connect two 5050 RGB modules?
Will 12 V, 1 A will be enough to power this board.

1A will be enough to power you arduino but the total powerconsumtion will depend on the amount of leds that you want to drive. If you follow the instuctable, it should be enoug but it's never a good idea to use your power source at max capacity all the time.
It allows you to connect 2 modules indeed.
Why would you need a voltage divider?

hc05  logic works on 3.3v please check the ebay link  thats why l want know about divider

Your arduino can give you 3.3V for powering it. If your board doesn't accept 5V logic, then you'll need a voltage level shifter.

do you have any link or example which I can use?

https://www.sparkfun.com/products/12009


text:
Yet another "Mac cannot find USB serial port" post
I have read about every post about people having issues with their Arduinos on Macs. I have a 100% authentic Arduino UNO, that I cannot by any circumstance manage to connect to my late 2009 iMac with macOS Sierra 10.12.2.
I tried just about anything from disabling Apple FTDI drivers, installing FTDIUSBSerialDriver, D2XX drivers and even the CH34X drivers (for knockoffs). NOTHING works.
Not even setting boot arguments, not disabling default extensions/drivers, not removing extensions/drivers.
I am completely stuck, and no guide has ever worked. I've tried rebooting numerous times, but still no luck. The only port available in the Port menu is the Bluetooth Incoming port.
Does anyone have any tips or hints? I am on the verge of doing a complete reinstallation of my computer just to have all drivers back to default.

What does dmesg tell you while you plug it in?

Alot of "AMFI: allowing exception handler for 'polard' (3658) because the process is unsigned." (I guess polard is my Polar heart rate monitor). Other messages: IO80211Interface::updateReport _peerManager is missing. That is basically it.

A little research and I'm not so sure polard is the heard rate monitor at all. For every time I connect the Arduino, a new line with this message shows up.

Does the same USB port work for other USB devices? Try another port? Can you test whether another computer sees your Arduino? Substitute a different USB cable?

An actual Uno does not require drivers on OSX as support for CDC/ACM is built in.  Fair warning: answers which ignore this and propose installing FTDI, CH340, CP210x, etc drivers will be severely down-voted.  This question is about an Arduino Uno; it is not about random other boards with different details.

@JRobert I've tried all ports on my iMac (4) plus the 2 on the keyboard. Not one of them is working with the Arduino. All of them are working with other devices. The Arduino does not work with my girlfriends MacBook Pro (OS X El Capitan 10.11.5), but it did work on my dads MacBook Pro (macOS Sierra 10.12.2). My dad only had to install the FTDI drivers to get it to work.

It sounds a lot like the Arduino or the cable, just by the fact that it fails on at least two machine. I'm surprised, though, that you needed install any drivers. Macs have understodd FTDI out of the box since at least OS 10.6.8; It's just the alternative USB <-> serial chips that have needed any additional drivers.

Thanks @JRobert. Are there some way to reset the whole Arduino to factory settings?

Just by powering it off. There aren't any arduino settings relevant to how it appears to a computer. That's built in to the auxilliary 8u2 or 16u2 processors' firmware and not configurable any way that I've ever heard of.


text:
Increase Serial Rx buffer
I am working with an Arduino Due and I am having some issue with the serial Rx buffers size. I am using a GSM module and some of the replies to the Arduino exceed the number of bytes I can store in the buffer at once.
I have read about ways to increase the buffer size by modifying the Arduino default install files but I cannot take this route as my code may then be compiled on a machine with standard buffer sizes in the default install files and the module would not work correctly.
I am not sure if it is possible but I was hoping that someone might know how to increase the serial buffer size using the source code. If I can do it this way the buffer would always be the size I have specified.

Here are some good suggestions on this topic; https://groups.google.com/a/arduino.cc/forum/#!topic/developers/AEA8LniThTA

Just read from the serial port faster. Don't rely on the buffer for storing your data, read it from the buffer and store it yourself.

@Mikael, thank you for the link I am reading through them now.

@Majenko My issue isn't with the speed that I read the serial at but more so with how often I can perform the reads. I am working on code written by someone else so I have limitations on how often I can read the data on the serial. One work around I am looking into is actually reducing my baud rate so that I will read that data slower and thus have more attempts to read and clear the bytes from the rx buffer before it has a change to fill.

Maybe hook into yield() to pull data into your own buffer then?

good suggestion, I will have a look into that, again the code runs various threads that already each use yield() so it might be tricky but definitely worth a look. I am also working on trying to get the headers stripped from the response which is sent to me so that I do not need to process unwanted data. thanks again

Use timer interrupts to read and store the data from serial. Lets assume you are receiving data at baud rate of 115200 in default configuration (8data bits, 1 stop bit), 115200/9=12800 bytes per second, approximately 80 micro seconds for every byte, create a timer interrupt that is called once every 2 millisecond(Choose best time for your application making sure that receiver buffer does not overflow), In 2milli seconds 25bytes of data will be available in the buffer. So you can read data in batches of 25 each. From the interrupt read and store the available data from the buffer.


text:
Generating digital positive (+5 V) and negative (-5 V) signal?
Problem in getting -5 V with Arduino.
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(20);
  digitalWrite(13, LOW);
  delay(20);
}

Above code is generating below digital signal:

I want this type of digital signal output:

I read this for generating negative -5 V signal:
https://electronics.stackexchange.com/questions/10322/what-is-negative-voltage
but not able to understand very well WRT Arduino.
Also read this:
Negative voltage: How do I scale a 0 to 5 V signal to -10 V to +10 V?
seems to much complicated circuit diagram with TL802.
My questions:

How do I get above digital signal?
I was wondering if we can use some 1 microF capacitor or transistor to generate negative signal? (simplest way)

You need to define (specify) what you will be connecting your +5/-5 signal to. That will determine how much current the negative 5 volts will need to supply.  Then we can answer how to make a -5 volt supply for you. Also, a level converter will be necessary to change 0-5 into  -5 and +5.

You can also easily make a -5 supply using a Wall wart 5 volt supply.  The +5 of the Wall wart would go to board ground,  and then the negative lead is your -5 volts.  If this is satisfactory, I will provide an answer on how to do the level changer.

@Marla This is no good if the 0V rail from the supply is tied to Earth; you'll just end up shorting the supply. It will work in some cases, but cannot be relied on as a solution.

@CharlieHanson   I will specify in my answer that the wall wart shall be isolated.  Thank you

Also see  Push-Pull tone code,  Digital pins on Arduino function as both positive and negative terminals?, and perhaps other piezo questions

It is not so easy to create a -5v power supply using a capacitor or transistor.
A very easy way is to use an additional Wall wart power supply to create -5 volts (while still using your original +5 volt power supply).
For the additional (new -5 volts power supply), use the two wires (positive and negative to create your -5 volts).   The positive lead goes to your board ground, and the negative lead becomes your -5 volts.
EDIT 1  :   Make certain that the Wall wart that you use is isolated from the mains voltage (line voltage you plug it into).  Most Wall warts are isolated,  but check to be sure.
Then you need level translation, which can be done with an op-amp and a couple of resistors  :

You have not mentioned what frequency (data rate) you need.  This circuit is not fast, so for high frequency or high data rates, the circuit could be improved.

Just to clarify, you are talking about a 10V wall-wart, right?

Talking about OP's existing 5 volt, and an additional 5 volt wall wart to create the new -5 volts.

Oh, OK. So use +5V in the usual way. Then use a 5V wall-wart, connecting the + side to ground, and the - side to the op-amp "negative" power supply. That's what you are suggesting, right?

@nickgammon.  Yes , correct

@NickGammon  I edited the answer with more description about the power supplies (which is what I think you were encouraging me to do)


text:
Arduino car parking program help

Here is a program and circuit diagram of an Arduino-based car parking (copy pasted from http://www.arduining.com/2012/10/13/arduino-parking-lot-filled/ ) I want to replace the Exit and End switch with IR sensor or ultrasonic sensor.
/*ParkingL02.pde
  Arduining.com 08 JUL 2012
  Code used in the production of the Youtube material.
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
#define ServoM 12 //Connected to the servo motor.
#define Bright 11 //servo library disable PWM on pins 9 and 10.
#define Exit 9 //Pin connected to the EXIT button.
#define In 8 //Pin connected to the IN button.
#define BarLow 177 //Low position of the barrier.
#define BarUp 95 //Up position of the barrier.
#define CAPACITY 8 //Capacity of the parking lot.
#define INTEN 80 //Display intensity %
//Pins conections to segments (cathodes).
#define segA 0
#define segB 1
#define segC 2
#define segD 3
#define segE 4
#define segF 5
#define segG 6

int SensorIn(void);     // declare the sensor function for entering autos

//Array with the segments to represent the decimal numbers (0-9).
byte segments[10] = {
  // pgfedcba <--- segments
  B00111111, // number 0
  B00000110, // number 1
  B01011011, // number 2
  B01001111, // number 3
  B01100110, // number 4
  B01101101, // number 5
  B01111101, // number 6
  B00000111, // number 7
  B01111111, // number 8
  B01101111 // number 9
};

void setup() {
  myservo.attach(ServoM); // attaches the servo.

  pinMode(Exit, INPUT); // set "EXIT" button pin to input
  pinMode(In, INPUT); // set "IN" button pin to input

  digitalWrite(Exit, HIGH); // Connect Pull-Up resistor.
  digitalWrite(In, HIGH); // Connect Pull-Up resistor.

  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(Bright, OUTPUT);

  analogWrite(Bright, 255 * INTEN / 100);
  myservo.write(BarLow); //Barrier in the low position
  // delay(1000);
}

int Available = 9; // Number of places available.

void loop() {
  Display(Available);
  if ( SensorIn() == 0 )
  {
    if (Available != 0) {
      Available--;
      myservo.write(BarUp);
      delay(3000);
      myservo.write(BarLow);
    }
  }
  if (digitalRead(Exit) == 0)
  {
    if (Available != CAPACITY) {
      Available++;
      myservo.write(BarUp);
      delay(3000);
      myservo.write(BarLow);
    }
  }
}

/*-------------------------------------------------------------------
  Put the segments according to the number.
  --------------------------------------------------------------------*/
void Display(int number) {
  byte segs = ~segments[number]; //"~" is used for commom anode.
  digitalWrite(segA, bitRead(segs, 0) );
  digitalWrite(segB, bitRead(segs, 1) );
  digitalWrite(segC, bitRead(segs, 2) );
  digitalWrite(segD, bitRead(segs, 3) );
  digitalWrite(segE, bitRead(segs, 4) );
  digitalWrite(segF, bitRead(segs, 5) );
  digitalWrite(segG, bitRead(segs, 6) );
}

// We've moved the "sensor code" for entering autos to this function
// For now, the "In-sensor" is just a push-button.
int SensorIn(void) {
  return ( digitalRead(In) );
}

It might help if you format your code.

Theoretically, an IR sensor could/would work exactly the same as an button (code wise).

I want circuit with connection of IR Sensor

i need this code but i have and lcd i'm doing the same project with two IR sensors so please if anyone have done it with lcd i will be thankfull i have to show it next week please help

If it were me, I'd approach it this way:

Move each button read (digitalRead(xxx)) into its own routine.
Get everything to work, still using the buttons.
Write a separate sketch for whatever sensor or sensors you're going to use. All it needs to do is light an LED so you can be sure when it is detecting and when it isn't.
Now replace the contents of each of the new button routines (from step 1) with the sensor code you just wrote. Your routines should return the same values for sensor detection that they returned for button detection. You shouldn't need to change any other part of your original code.
Fix any bugs you made in the step above, and you're done.

Update:
I've just indented your code (above) and made one of the changes I suggested. You'll see that I made a new function called SensorIn() and put the code to read the "In" button there. Do the same thing for the "Exit" button.
Then, using a new sketch, learn to write code for whatever kind of sensor you want to use for entering autos. When that works, copy it into this sketches 'SensorIn()' function, replacing the line that reads the push button. Get this much working.
Then do the same thing, write a new sketch for the exit sensor until you can make that work reliably, too. Of course, if you choose to use the same kind of sensor for Exit as you used for In, you can just re-use the same code. Get this sketch working again.
Now you should have a sketch, just like your pushbutton sketch, but one that uses two real sensors instead of buttons.

Can u rewrite the code for me ..  and paste for me plzz... I'm kinda nooob..N  I'm getting confused... Writing separate code for ultrasonic sensor.. and calling in place of button .  Causing more error

The coding and project is completed ..its an old question :) thank you anyway

authors: Феликс Сагателян


text:
Can I use Visual Studio instead of Arduino IDE?
I think that Visual Studio is a great product! I find the Arduino IDE is limited in its features. For example the Arduino IDE does not have:

Code prediction
Error highlighting
Previews of #define values
Peek at code definition
Jump to code definition
and many more...

Since the Arduino ino & pde file types are basically C++, Can I use the Visual Studio IDE instead of Arduino IDE?
To be considered as a replacement, Visual Studio must be able to:

Save & open ino & pde files.
Compile my code.
Download my code.
Use existing/custom libraries from the Arduino IDE.
Detect and display an Arduino project.

I would consider these features as a bonus:

Arduino board selection.
Debugging

Variable watch window
Breakpoints
Step through code

Simulation
Open the Arduino Examples
Automatic board detection
Serial Monitor

This question is similar but different to http://arduino.stackexchange.com/questions/4354
I am after all options available, using any method.

Atmel Studio deserves mention here.  It's based on the Visual Studio shell, has top debugging support if using something like ATMEL-ICE and is the official way to program Atmel chips.
Downside?  It's clunky with Arduino API.

I use Eclipse and Sublime Text for editing Arduino code, and I build in the Arduino IDE with it set to "external editor" mode, or using the Arduino Command Line tools. Eclipse has a fantastic indexer and makes understanding the Arduino core much easier. I've written a detailed PDF about using and setting up Eclipse for professional software development here: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/blob/master/eclipse/Eclipse%20setup%20instructions%20on%20a%20new%20Linux%20(or%20other%20OS)%20computer.pdf.

I only use Visual Studio for Arduino programming.
Arduino Plugin for Visual Studio

This really ought to be the accepted answer.  VisualGDB would be your go-to for "real" debugging, but unlikely it works with base Arduino Uno.

If it wasn't when before, the linked plugin is a paid product.

Note, this answer is not technically for the full edition of Visual Studio, rather Visual Studio Code.
Microsoft has released an Arduino extension for VS Code that can do most (all?) of the required items in the OP's list.
Added this answer as a free alternative to the accepted answer.

Atmel Studio 7 which is built with Visual Studio. Google "Atmel Studio 7" or click here. It has everything you want and it's released by the company that makes the atmega328 your Arduino is built on.

The link location has changed to: https://www.microchip.com/mplab/avr-support/atmel-studio-7.

It's not exactly what you are asking, but maybe you would be willing to consider a solution based on Eclipse?
Eclipse has the advantage of being cross platform, so you can have the same experience no matter what your OS might be.
Although, for the sake of completeness, almost all you mentioned can be done even with vim, if adequately configured. But I wouldn't recommend it as first choice, if you have never used it before.

I use Eclipse and Visual Studio on an almost daily basis for my job. Although there are a few nice things I like about Eclipse, and even CodeBlocks, Visual Studio is by far a more polished product.

Different strokes ... I'm happy with vim :-)
About debugging, you will need something more than an IDE.
You need an ICE or equivalent. I have the AVR dragon (http://www.atmel.com/tools/AVRDRAGON.aspx) and it works nicely with ddd + gdb, but it can be made to work also with eclipse, iirc. If you want a windows based solution, I suggest you to check the Atmel site. Most likely they do support primarily windows and you can start from there, to pick the debugger, based on what is available/recommended.


text:
One shift delay in receiving the response messages when using two nRF24L01 to communicate with each other
When I send "a" from the Serial Monitor of the slave, on the master slave window it will show "car1_place_2_go = a" then it should show on the slave Serial Monitor "a" but it doesn't show up in the slave serial window until I send another new characters. So there is a 1 delay shift in the messages showed on the slave Serial Monitor.
Master:
#include <SPI.h>
#include <SoftwareSerial.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

char car1_place_2_go;
char car2_place_2_go;
char temp_place = 0 ;

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(addresses[1]); // mastr
  radio.openReadingPipe(1, addresses[0]); // carwl

  radio.setPALevel(RF24_PA_MIN);
}

void loop()
{
  delay(5);
  radio.startListening();

  if (radio.available())
  {
    radio.read(&car1_place_2_go, sizeof(car1_place_2_go));
    Serial.print("car1_place_2_go = ");
    Serial.println(car1_place_2_go);

    delay(5);
    radio.stopListening();

    radio.write(&car1_place_2_go, sizeof(car1_place_2_go));
  }
}

Slave:
#include <SPI.h>
#include <SoftwareSerial.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

char car1_place_2_go;
char car2_place_2_go;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(addresses[0]); // 00003
  radio.openReadingPipe(1, addresses[1]); // 00002

  radio.setPALevel(RF24_PA_MIN);
}

void loop()
{
  if (Serial.available() > 0)
  {
    car2_place_2_go = Serial.read();

    delay(5);
    radio.stopListening();

    radio.write(&car2_place_2_go, sizeof(car2_place_2_go));

    radio.startListening();

    if ( radio.available())
    {
      char text[32] = "";
      radio.read(&text, sizeof(text));
      Serial.println(text);
    }
  }
}

Library I use: https://github.com/nRF24/RF24

Probably you are waiting too long between sending the message and listening for data, so you're only getting the data on the next radio transmission.  See my answer to your other nRF24 question.  It looks like you can use ACK payload to send and receive data in the same radio transaction.  Please remember to upvote or accept the answer if correct.

From the code it looks like the slave keeps repeatedly sending the serial data. Shouldn’t it only sent it once?

i found the problem is that the receiver in the slave doesn't see what send to it until the next loop and that mean it need a delay so it can see what transmit to it so i add this while loop in the slave so the slave doesn't exit the "void loop" function until it get the message from the master
slave
 radio.startListening();

    while(! radio.available())
    {

    }
    if ( radio.available())
    {
        char text[32] = "";
        radio.read(&text, sizeof(text));
        Serial.println(text);
     }

you should accept your own answer.


text:
Where can I find a central repository of all available Arduino libraries?
Currently; when I start a new Arduino project with some new hardware, the first thing I do is to look for 3rd-party libraries that bring Arduino support for this hardware.
The first places I look are:

The Arduino Playground
GitHub
Google

Generally I find either no support library or several different libraries (it's quite rare to find only one) in different locations with different levels of documentation, different levels of testing...
Once I have found the library I need (sometimes I need to try several), I download it to my Arduino libraries folder, I use it and I forget it.
I find this process cumbersome:

manual search with different possible options, not always well documented
manual download and install to Arduino libraries
no version control in the process (all versions of a library have the same name and thus cannot coexist in the Arduino library folder).

I wish there was a central repository with all available libraries for arduino, with:

description (supported hardware, supported boards)
source code
documentation
versions

And a tool (Arduino IDE or external) to access this repository at project build time.
A kind of maven for Arduino in fact.
I have seen several discussions once took place on Arduino forum, but it seems they led nowhere:

Arduino Libraries Census and Repository
Arduino Library downloader
Arduino Library downloader (2)

Are there other options, that are made it to something usable (from the community or individuals, why not)?

This would be similar to PyPi https://pypi.python.org/pypi and virtualenv in Python, if anyone needs an analogue in another language.

Another good source is PJRC https://www.pjrc.com/teensy/td_libs.html

Something tells me the [tag:library] tag wiki would be a good place to create such a database. ~35,000 characters should provide ample space to develop a very comprehensive list.

@AsheeshR why not? But first, a clear description of what's required (and what is optional) for each library entry is to be defined, so that this 3template3 could be followed for each added entry.

@jfpoilpret Thats a topic for a [meta] discussion.

@AsheeshR only if we decide to go this way; for the time being, I'd like to hear what others have to say, in particular if there are already some tools that can help in this direction.

Three words about keeping a 'database' in a tag wiki: "main" "ten" "ance". I don't believe a handful Arduino.SE users can keep such a list current and complete. Notice that a library that is not being maintained any longer must be considered to be removed too. But by all means prove me that I'm wrong, that happened before.

@jippie an unmaintained library may be in use by projects, hence it should not be removed, but just marked as "unmaintained since ..."

@jfpoilpret Good argument. I'd say you'll have to include version v.vv.vv and release date yyyy-mm-dd then.

This question assumes that there is some connection between all the different entities that might write a library.  I guarantee I have written libraries that you won't find in any repository other than my own github site.  It's not that you're not welcome to use them.  Just that I see no advantage in actively promoting them.

Since this question was first asked, there is now the Arduino Library Manager, built into the Arduino IDE. There you can search for and install libraries.
There is information about how the library manager works here:
https://github.com/arduino/Arduino/wiki/Library-Manager-FAQ
There isn't however an official website listing the libraries, so I recently created this unofficial site, based on the same data in the Arduino Library Manager:
http://www.arduinolibraries.info/

The Arduino Playground LibraryList and the standard library list appear to be the official pages for that.

Yes but they are just a mix of short doc with links to libraries, and seem to follow a "best effort" maintenance, leading to something that looks like a mess if we would want to use it from some kind of package manager.

There is none. Unfortunately, you will have to manually search for each library you are interested in.
If you are interested in creating such a central repository, while it would be awesome, this is not the correct forum in which to do it.

Then what would you advise if we were to create such a repository?

Uh.... get started? What do you mean advise? It's basically a website. Maybe add a package-manager thing to the arduino text editor if you were really into it? The major issue, as always, is going to be getting people to actually use it.

Frankly, even if you add a fancypants package manager to the arduino text editor, I don't know what kind of adoption you're going to get, because the arduino editor is horrible, and people tend to stop using it in fairly short order. As such, you'd almost need a separate package manager, so I'd almost just say a basic web-site with a index of libraries, a short blurb, and links to where they're actually hosted is the best bet.

That was my idea too, the purpose would not be to host libraries but rather keep references to them, along with useful metadata. Regarding Arduino IDE, I agree, I don't use it very often, but an external tool should be easy to integrate with it later on.

@jfpoilpret - The issue with an external tool is, as with package managers, dependency resolution and version requirement management. The arduino people don't seem too bothered by maintaining backwards compatibility, and lots of libraries require "arduino verson {blah}". I really think just a list of references is the best bet. Any more complex stuff can come later.

If you want to create such a registry yourself, you may want to take a
look at npm, the package manager of Node.js, which is
open-source and very similar in scope to want you describe. Npm is both:

a central registry with metadata about each library:

name, description, keywords, homepage, author, contributors
version number, in principle complying with semantic versioning
URL of source repository (svn, git, github, gitlab, bitbucket...)
compatibility information (in this case it's about the versions of Node)
license
dependencies

a command-line tool for:

searching the registry
downloading and installing packages, recursively following their
dependencies
publishing and updating your own packages on the registry.

See for example the page of a popular library, and the JSON
file holding its metadata.

Arduino IDE and associated libraries are included as installable software in most OS repositories.  Unfortunately the versions in these repositories is usually several months or even years out-of-date.  This would seem that the real problem is in getting OS repository managers to incorporate new releases as they become available.
This problem is compounded when your OS version has not been updated to the latest release, because this forces you to use an outdated software repository.
While not a perfect answer, you should probably insure that you are using the latest release of your OS, and then encourage the repository managers for that OS to incorporate the latest version of Arduino IDE.
An alternative would be to go to the Arduino.org homepage and follow instructions to download and install the latest IDE and associated libraries.  This will probably be in the form of a .tar.gz file so you  will need to know how to unzip, untar, and build the necessary software.

http://downloads.arduino.cc/libraries/library_index.json provides a list of all libraries available in Arduino Library Manager.
I used this file to create https://github.com/scls19fr/arduino_libraries_search It's a Python Pandas script to search for Arduino libraries matching some keywords and to output to Excel file
You can also find Arduino libraries using:

https://platformio.org/lib/search?query=keyword%253A%2522arduino%2522
or https://www.arduinolibraries.info/

I think, that your wish will not come true. I hope for it, because having only one place for all Arduino libriaries, with no libraries allowed not be there and all those libraries would be forced to stand all commercial standards of quality, testing and documentation (+code quality, effectivity and readability) would mean, that only professionals and similary qualified teams would be allowed to publish some Arduino library and it all would be governed by one single entity, which would enforce removing functionally duplicate or similar libraries. And such entity would soner or later became evil.
I like the Arduino for being free and that also means, that I am free to write library for support of some features (which I want to use) of some hardware (which I have, plan to buy or want to make myself - even highly experimental and maybe unstable, but fun for me).
With your Big Central Authority being effective, I would just choose another free platform, rather then be sued for lesser than perfect and commercially certified outcome of my hobby playing with electronics and forced to work for their, NOT my goals on MY free time.
And if your Big Central Athority would not force me to forced free labor work for them, then what would you do about my library enabling one special use of some common hardware, and about me sharing it to anyone want it, even if it does not solve all the HW functionality fully in proffesional matter and documented only so much as I would be comfortabe to spend my own free time with documentation. And what if there would arise another library for the same HW, which would enable another part of functionality or would use another API and another approach to the whole problematic?
Namely I bought some multi 7-segment module and there was "official library" for it from its manufacturer. I made another library for the same module. What now? Should be my library be in the Central Repository as "the only one library for this HW" or should be there the "official one from manufacturer"?
Note, that if there were both of them, than it would break your requested "one and only one" library point.
If you disallow the manufacturer one, then "the only one" would be missing a lot of features, as integrated buffer for numbers, simple object interface, simple example, how to use it and there would be hard dependency on one specific timer and generic non-object, just functional API, which would require user to break integers to single digits somehow - does not sound too good.
If you disallow my library, then user would have the above, but his display would refresh only 10x per second with blinking and leaving ghosts of other digits all over place, while fully utilise processor and the documentation would be mainly in chinese. And the user would miss refresh rate 100x per second with nearly no usage of processor, nice clean digits AND characters (potetially also user defined). - Also not good.
In current state of chaos user (maybe you or anyone else) can use the library, that is better fit for his needs (be it simplicity and native integer support, or be it clean fast refresh and low CPU usage) or combine both together, making third with fast refresh AND simple integer manipulation AND user defined charset, WITH nice object API and rich documentation. It only needs one person with some time and dedication make it easy for beginers and some english skills and basic knowledge of objects and how are "official Arduino libraries" packed, so the IDE can easily import them. (And such person should do it and contribute it to Arduino library packager).
I would not do it - for my needs is functional API far better and simpler to use, take less bytes from memory and less CPU cycles and I have no urge to improve the library in ways I would not use. Also I do not use Arduino IDE, I use simple Makefile to build and upload the programs, so I can easily use good text editor (vim in my case) and have not to fight with IDE-Notepad-parody.
Under Big Central Authority enforsing your model I would not care about using Arduino at all and you will be stuck with the chinese version, if any at all (as it would not make it there for lack of good english documentation and proper package format too).


text:
Why can't I declare a class in another tab in Arduino IDE?
I wanted to move some of my code out into a second tab in the Arduino IDE, to keep things better organised. At first, I only tried moving a function, and it seemed to work fine. I could call the function from the setup() function in my main tab, and there were no problems compiling or uploading.
However, I tried putting a whole class into the second tab, and suddenly it didn't work any more. For example:
Tab 1:

TestClass obj;

void setup()
{
    obj.init();
}

void loop()
{
    //...
}

Tab 2:
class TestClass
{
public:
    void init()
    {
        //...
    }
};

When I tried to compile this, it gave me the following errors:
tab1:1: error: 'TestClass' does not name a type
tab1.ino: In function 'void setup()':
tab1:5: error: 'obj' was not declared in this scope

Why does it recognise a function in another tab, but not a class? Is there a way to make it work in the Arduino IDE, or do I need to use an alternative like Eclipse?

Is this the entirety of the code? What are the file names? Are there no preprocessor directives like #include?

Yes, that's the entirety of the code. The tabs are named tab1 and tab2 respectively. The names were set using the IDE, so the underlying files are both .ino.

I am starting to hate the jiggery pokery the Arduino IDE does. What it adds in ease of use over AVR it takes away in breaking things like this.

It is not possible to declare and use classes declared in one .pde file in another .pde file from within the Arduino IDE.
One workaround is to make the second file into a C++ source file (.cpp) and then add a #include "<filename>" directive in the beginning of the first file.

This code compiles correctly:
Tab 1:
#include "test.cpp"

TestClass obj;

void setup()
{
    obj.init();
}

void loop()
{
    //...
}

test.cpp :
class TestClass
{
public:
    void init()
    {
        //...
    }
};

Thanks for the workaround. It works for the basic example, but unfortunately it doesn't work if I add any Arduino-specific calls in the .cpp file. For example, if TestClass::init() tries to call pinMode(), the compiler complains that pinMode was not declared in this scope. Is there a way to access the Arduino functions in my class?

@PeterR.Bloomfield Add a #include <Arduino.h> to the top of the .cpp file.

I think it's not good to teach others to include source files (#include "test.cpp"). It works, but may brake the understanding of the linking process. Only header files should be included.

I agree with @Mars - a better solution is to put the class declaration in a .h file, and the definition (implementation) in a .cpp file. So you have two extra files in the project. This is actually the normal way of handling classes.

The way the Arduino IDE works is that it compiles your code (the code you write in the IDE) as the "main" code. Then it pulls code from all of the libraries you have imported and compiles that along with the main code. To do what you are suggesting would require you to create a library for Arduino.
Here is some more information on Arduino libraries:
http://arduino.cc/en/Guide/Libraries
And here is some on how to create a library:
http://arduino.cc/en/Hacking/LibraryTutorial //this one is the easiest to understand imo
http://playground.arduino.cc/Code/Library
http://www.divilabs.com/2013/03/write-your-own-arduino-library.html#
Here is an example library I wrote https://github.com/jamolnng/Arduino/tree/master/libraries/ShiftRegister as you can see there is no problem with calling Arduino functions from the .cpp file (I know, I've tested the library)

It’s also possible to just create .h and .cpp files in your main project, without having to create a separate library.


text:
Arduino with 8 LEDs and a switch
I have an assignment wherein we have 8 LEDs connected to an Arduino Uno which has a switch. These LEDs light up according to the johnson counter but every time I turn the switch off it should reset back to the start. An example is if I turned the switch off while the pin is at 8 going back to 1 , then when i turn it on it should be back to 1 again. I got the 1 to 8 reset part right but the 8 to 1, I'm having trouble solving.
Here is my code:
int pin;
int sw3 = 10;

void setup() {
  // put your setup code here, to run once:
  for (pin = 2; pin <= 9; pin++) {
    pinMode(pin, OUTPUT);
  }
  pinMode(sw3, INPUT);
}

void loop() {
  pin == 2;
  if (digitalRead(sw3) == HIGH) {
    for (pin = 2; pin <= 9; pin++) {
      digitalWrite(pin, HIGH);
      delay(200);
    }
  }
  else {
    digitalWrite(pin, LOW);
  }

  delay(200);

  for (pin = 2; pin <= 9; pin++)
  {
    digitalWrite(pin, LOW);
  }
  delay(200);

  if (digitalRead(sw3) == HIGH) {
    for (pin = 9; pin >= 2; pin--) {
      digitalWrite(pin, HIGH);
      delay(200);
    }
  }
  else {

    digitalWrite(pin, LOW);
  }

  delay(200);

  for (pin = 9; pin >= 2; pin--) {
    digitalWrite(pin, LOW);
  }
  delay(200);
  {
    if (digitalRead(sw3) == LOW) {
      digitalWrite(pin, LOW);
    }
    else {
      digitalWrite(pin, LOW);
    }
  }
}

I'm not able to comprehend what your problem is. The code also doesn't seem to do a johnson counter. Could you rephase your question, and maybe mark in your code where your problem is?

Some fixes:
pin==2;  should only be 1 = here. == is a comparison.
pinMode(sw3,INPUT);  make this INPUT_PULLUP, to turn on the internal pullup resistor
if(digitalRead(sw3)==HIGH){  change this to LOW, and wire your switch/button to connect the pin to GND when pressed. The internal pullup will unsure the pin is HIGH when not pressed, and the button/switch makes it LOW when pressed. The pin is thus not allowed to 'float' and return a random HIGH or LOW.

I think they are using an external pull-down.

the pin == 2 is probably the problem.