text:
Compile Problem with RFDuino RFD22301
I have the following setup:
- Arduino IDE for Mac 1.8.5
- RFDuino RFD220301
- CP2102 USB to UART connector
- Board set to "RFduino"
- port set correctly (but shouldn't matter as it is a compile error)
- Programmer: AVRISP mkII
When trying to compile an example script using BLE (Such as AdvertisementContinuous) I get the following error
arm-none-eabi-g++: error: /var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_188605/core/syscalls.c.o: No such file or directory
Any ideas?
Here's the -v log:
Arduino: 1.8.5 (Mac OS X), Board: "RFduino"

/Applications/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -hardware /Users/julian/Library/Arduino15/packages -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/julian/Library/Arduino15/packages -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/julian/Documents/Arduino/libraries -fqbn=RFduino:RFduino:RFduino -ide-version=10805 -build-path /var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200 -warnings=none -build-cache /var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_cache_722169 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arm-none-eabi-gcc.path=/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1 -verbose /Users/julian/Code/openSleep/embedded/sleepduino/sleepduino.ino
/Applications/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -hardware /Users/julian/Library/Arduino15/packages -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/julian/Library/Arduino15/packages -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/julian/Documents/Arduino/libraries -fqbn=RFduino:RFduino:RFduino -ide-version=10805 -build-path /var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200 -warnings=none -build-cache /var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_cache_722169 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arm-none-eabi-gcc.path=/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1 -verbose /Users/julian/Code/openSleep/embedded/sleepduino/sleepduino.ino
Using board 'RFduino' from platform in folder: /Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3
Using core 'arduino' from platform in folder: /Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3
Detecting libraries used...
"/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin  -w -x c++ -E -CC -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=10805 -mthumb -D__RFduino__ "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/cores/arduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino/include" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/CMSIS/CMSIS/Include" "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/sketch/sleepduino.ino.cpp" -o "/dev/null"
"/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin  -w -x c++ -E -CC -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=10805 -mthumb -D__RFduino__ "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/cores/arduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/libraries/RFduinoBLE" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino/include" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/CMSIS/CMSIS/Include" "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/sketch/sleepduino.ino.cpp" -o "/dev/null"
"/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin  -w -x c++ -E -CC -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=10805 -mthumb -D__RFduino__ "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/cores/arduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/libraries/RFduinoBLE" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino/include" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/CMSIS/CMSIS/Include" "/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/libraries/RFduinoBLE/RFduinoBLE.cpp" -o "/dev/null"
Generating function prototypes...
"/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin  -w -x c++ -E -CC -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=10805 -mthumb -D__RFduino__ "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/cores/arduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/libraries/RFduinoBLE" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino/include" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/CMSIS/CMSIS/Include" "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/sketch/sleepduino.ino.cpp" -o "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/preproc/ctags_target_for_gcc_minus_e.cpp"
"/Applications/Arduino.app/Contents/Java/tools-builder/ctags/5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/preproc/ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin -MMD -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=10805 -mthumb -D__RFduino__ "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/cores/arduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/libraries/RFduinoBLE" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino/include" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/CMSIS/CMSIS/Include" "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/sketch/sleepduino.ino.cpp" -o "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/sketch/sleepduino.ino.cpp.o"
Compiling libraries...
Compiling library "RFduinoBLE"
"/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin -MMD -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=10805 -mthumb -D__RFduino__ "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/cores/arduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/libraries/RFduinoBLE" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino/include" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/CMSIS/CMSIS/Include" "/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/libraries/RFduinoBLE/RFduinoBLE.cpp" -o "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/libraries/RFduinoBLE/RFduinoBLE.cpp.o"
Compiling core...
"/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin -MMD -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=10805 -mthumb -D__RFduino__ "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/cores/arduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/RFduino/include" "-I/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/system/CMSIS/CMSIS/Include" "/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino/variant.cpp" -o "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/core/variant.cpp.o"
Using precompiled core
Linking everything together...
"/Users/julian/Library/Arduino15/packages/RFduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -Wl,--gc-sections --specs=nano.specs -mcpu=cortex-m0 -mthumb -D__RFduino__ "-T/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino/linker_scripts/gcc/RFduino.ld" "-Wl,-Map,/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/sleepduino.ino.map" -Wl,--cref -o "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/sleepduino.ino.elf" "-L/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200" -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/core/syscalls.c.o" "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/sketch/sleepduino.ino.cpp.o" "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/libraries/RFduinoBLE/RFduinoBLE.cpp.o" "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/core/variant.cpp.o" "/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino/libRFduinoSystem.a" "/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino/libRFduino.a" "/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino/libRFduinoBLE.a" "/Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/variants/RFduino/libRFduinoGZLL.a" "/var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/../arduino_cache_722169/core/core_RFduino_RFduino_RFduino_96c93913732efe419124a59ff97a44c7.a" -Wl,--end-group
arm-none-eabi-g++: error: /var/folders/m6/mfwpb8b13wn4f9fvb4lhx_v40000gp/T/arduino_build_997200/core/syscalls.c.o: No such file or directory
Using library RFduinoBLE in folder: /Users/julian/Library/Arduino15/packages/RFduino/hardware/RFduino/2.3.3/libraries/RFduinoBLE (legacy)
exit status 1
Error compiling for board RFduino.

I cannot reproduce this using 1.8.3. I installed https://github.com/RFduino/RFduino in the board manager and used the https://github.com/RFduino/RFduino/blob/master/libraries/RFduinoBLE/examples/AdvertisementContinuous/AdvertisementContinuous.ino sketch. It compiles fine. Can you go into the Arduino IDE settings and activate verbose output on compiling and edit your question with that log?

So it appears solved: Using Arduino 1.6.13 I don't get the compile error. Must be an incompatibility with the RFduino Board libraries and the 1.8x IDE.


text:
GSM cannot read SMS when Arduino is not reset for the first time after it is powered
I'm using a GSM Module with Arduino along with Node MCU. I have a supply of 9V, 2A in the DC jack of the Arduino and the GSM Shield. The Node MCU is powered from the 3.3V of the Arduino. I can receive messages fine in the GSM when the USB port of the Arduino (including the power supply I mentioned earlier) is connected to the laptop through and monitored using the serial monitor. However if I remove the USB port, the GSM cannot receive the messages anymore but when I press the reset button of the Arduino, it will start receiving messages again. Why does it only works when I reset the Arduino first after powering it up?
#include <SoftwareSerial.h>
#include <Wire.h>

SoftwareSerial gsmSerial(2, 3);

char incomingByte;
String inputString;

// Pin configurations.

const int outlet1Pin = 4;
const int outlet2Pin = 5;
const int outlet3Pin = 6;

const int ping1Pin = 7;
const int ping2Pin = 8;
const int ping3Pin = 9;
const int ping4Pin = 10;
const int ping5Pin = 11;
const int ping6Pin = 12;
const int signalPin = 13;

const int pingWaitTime = 3000;

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

  pinMode(outlet1Pin, INPUT);
  pinMode(outlet2Pin, INPUT);
  pinMode(outlet3Pin, INPUT);

  pinMode(ping1Pin, OUTPUT);
  pinMode(ping2Pin, OUTPUT);
  pinMode(ping3Pin, OUTPUT);
  pinMode(ping4Pin, OUTPUT);
  pinMode(ping5Pin, OUTPUT);
  pinMode(ping6Pin, OUTPUT);
  pinMode(signalPin, OUTPUT);

  initGSM();
  //Serial.flush();
  //gsmSerial.flush();
  //sendSMS("Test send.");

}

void loop()
{
  if (gsmSerial.available())
  {
    digitalWrite(signalPin, HIGH);

    delay(500);

    //Serial.println("Serial available.");

    while (gsmSerial.available())
    {
      incomingByte = gsmSerial.read();
      inputString += incomingByte;
    }

    inputString.toUpperCase();

    checkCommandAction(inputString);

    if (inputString.indexOf("OK") == -1)
    {
      gsmSerial.println("AT+CMGDA=\"DEL ALL\"");
      delay(1000);
    }

    inputString = "";
    gsmSerial.flush();

  }
  digitalWrite(signalPin, LOW);

}

void sendSMS(String text)
{
  Serial.println("Sending Text...");

  gsmSerial.println("AT+CMGF=1");
  delay(1000);

  gsmSerial.print("AT+CMGS=\"+numberhere\"\r");

  delay(1000);

  gsmSerial.print(text);
  delay(1000);

  gsmSerial.print((char)26);
  delay(1000);

  gsmSerial.println();
  Serial.println("Message sent!");
  delay(1000);
}

void initGSM()
{
  gsmSerial.println("ATE0");
  while (!gsmSerial.available())
  {
    gsmSerial.println("AT");
    delay(500);
    Serial.println("Connecting...");
  }

  Serial.println("Connected!");

  gsmSerial.println("AT+CMGF=1");
  delay(500);
  gsmSerial.println("AT+CNMI=1,2,0,0,0");
  delay(500);
  gsmSerial.println("AT+CMGL=\"REC UNREAD\"");
  delay(500);
  gsmSerial.println("AT+CMGDA=\"DEL ALL\"");
  delay(500);

  Serial.println("All messages deleted!");

  Serial.println("Sending Text...");

  gsmSerial.println("AT+CMGF=1");
  delay(500);

  gsmSerial.print("AT+CMGS=\"+639776811077\"\r");

  delay(500);

  gsmSerial.print("Device Initialized!");
  delay(500);

  gsmSerial.print((char)26);
  delay(500);

  gsmSerial.println();

  Serial.println("Message sent!");
  delay(500);
}

void checkCommandAction(String command)
{

  //Serial.println("Check Command.");

  if (command.indexOf("O1ON") > -1)
  {

    digitalWrite(ping1Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping1Pin, !HIGH);
    Serial.println("O1ON Enter");
    sendSMS("Outlet 1 Turned ON by text.");

  }
  else if (command.indexOf("O1OFF") > -1)
  {
    digitalWrite(ping4Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping4Pin, !HIGH);
    Serial.println("O1OFF");
    sendSMS("Outlet 1 Turned OFF by text.");
  }
  else if (command.indexOf("O2ON") > -1)
  {
    digitalWrite(ping2Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping2Pin, !HIGH);
    Serial.println("O2ON");
    sendSMS("Outlet 2 Turned ON by text.");
  }
  else if (command.indexOf("O2OFF") > -1)
  {
    digitalWrite(ping5Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping5Pin, !HIGH);
    Serial.println("O2OFF");
    sendSMS("Outlet 2 Turned OFF by text.");
  }
  else if (command.indexOf("O3ON") > -1)
  {
    digitalWrite(ping3Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping3Pin, !HIGH);
    Serial.println("O3ON");
    sendSMS("Outlet 3 Turned ON by text.");

  }
  else if (command.indexOf("O3OFF") > -1)
  {
    digitalWrite(ping6Pin, !LOW);
    delay(pingWaitTime);
    digitalWrite(ping6Pin, !HIGH);
    Serial.println("O1OFF");
    sendSMS("Outlet 3 Turned OFF by text.");
  }
  else if (command.indexOf("CHECKSTATE") > -1)
  {
    int state1 = !digitalRead(outlet1Pin);
    int state2 = !digitalRead(outlet2Pin);
    int state3 = !digitalRead(outlet3Pin);

    String toSend = "";
    toSend += "Outlet 1: ";
    toSend += String((state1) ? ("ON") : ("OFF"));
    toSend += "Outlet 2: ";
    toSend += String((state2) ? ("ON") : ("OFF"));
    toSend += "Outlet 3: ";
    toSend += String((state3) ? ("ON") : ("OFF"));

    sendSMS(toSend);
  }
}

void turnPingsOn()
{
  // The pins where the pings are connected are
  // configures as INPUT_PULL up, so we need to high
  // it by default.

  digitalWrite(ping1Pin, HIGH);
  digitalWrite(ping2Pin, HIGH);
  digitalWrite(ping3Pin, HIGH);
  digitalWrite(ping4Pin, HIGH);
  digitalWrite(ping5Pin, HIGH);
  digitalWrite(ping6Pin, HIGH);
}

Please show us the sketch you are using.

Updated, I use AT commands for sending and receiving SMS. It works fine if I connect it to the computer and open the serial monitor. However when I just use the dc jack, it won't receive any message.

how do you know that messages are not being received?

A relay will open if a certain message is received.

In theory you shouldn't rely on the 3.3V supply of the Arduino to power the NodeMCU board, it doesn't have enough power particularly when WIFI data is being transmitted.
Are you removing the USB while the system is live?  If so you are probably spiking various bits that don't like being spiked and that's why it breaks.
If you are removing the USB and THEN powering up the system, what happened when you power down you system and power it back up again after 10 seconds?  My guess is that it won't receive messages.  So there is a difference between applying power and resetting the board, which implies that you are very marginal on your power supply.
If you are using the SIM800 (?) module they need 2Amps to transmit, so if you are only supplying 2A it might not have enough power to cold start, but when reset it does.  So if you can try more power that might help.
Another thought might be you haven't got a proper ground (wall warts aren't normally grounded) so your USB connection is acting as a ground.  If this is the case then it should work when you PC is turned off.
Sorry this is a bit vague, but your question needs model names and part number for people to be a bit more specific.

source: Stack Exchange

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

sort: votes


text:
Strange things happening with Arduino PROGMEM
I am currently working on a display library. The font should be stored in PROGMEM. The code looks something like this:
unsigned int i = 0;
Serial.println(pgm_read_byte(&font[1]),HEX);
unsigned char width = pgm_read_byte(&font[0]);
unsigned char height = pgm_read_byte(&font[1]);
unsigned char spacing = pgm_read_byte(&font[2]);

The strange thing is that the code breaks (Serial spits out random characters, OLED displays only noise or nothing) when I remove the
Serial.println(pgm_read_byte(&font[1]),HEX);

If I replace it with something like
Serial.println("Hello World!");

the code breaks as well, but in a different way. I think pgm_read_byte() returns different things with different Strings in the Serial.println() function.
Is there something going on with the compiler? Are there some optimization options that I should change? Or am I doing it completely wrong?
Here is the whole function:
/**
 *
 * Displays text using a predefined sprite in PROGMEM
 * Only fonts with a uniform letter spacing are supported
 * The font must have the following format
 * Byte   Description
 *  0.    X width of one letter in pixel
 *  1.    Y height of one letter in bytes (8 pixel)
 *  2.    letter spacing in pixels
 *  3.    data
 *  .      .
 *  .      .
 *  .      .
 *  N.    data
 *
 * The data is arranged like this
 *    | 0 | 1 | 2 | 3 | 4 | ... |126|127
 *     b0  b1  b2
 *     b3  b4  b5
 *    LSB D0
 * In each byte the data is displayed like this
 *    .
 *    .
 *    .
 *    MSB D7
 *
 * A font starts with the symbol "!" (ASCII 33) and ends with the symbol "~" (ASCII 126).
 * Each symbol in between has to be present. The letters have to be arranged like this
 * Letter     A       B       C
 * Bytes    b0 b1   b2 b3   b4 b5
 *          b6 b7   b8 b9  b10 b11
 *
 * @param unsigned char disp[]          the display buffer where the text should be shown
 * @param const unsigned char font[]    the font in PROGMEM
 * @param const char *string            the string to display
 * @param unsigned char X               x location
 * @param unsigned char Y               y location
 * @param int mode                      blend mode
 */
void gfx::text(unsigned char disp[], unsigned char *font, const char *string, unsigned char X, unsigned char Y, int mode){
  unsigned int i = 0;
  Serial.println(pgm_read_byte(&font[1]),HEX);
  unsigned char width = pgm_read_byte(&font[0]);
  unsigned char height = pgm_read_byte(&font[1]);
  unsigned char spacing = pgm_read_byte(&font[2]);
  while(string[i])
  {
    if(string[i] > 32 && string[i] < 127){  //only display valid characters, otherwise leave a blank spot
      unsigned char s[width*height];
      unsigned char c = string[i] - 33;
      //transfer pixel with and height to the sprite
      s[0] = width;
      s[1] = height;
      //copy the other bytes
      for(int y = 0; y < height; y++){
        for(int x = 0; x < width; x++){
          unsigned int sprite_pointer = 2 + width*y + x;
          unsigned int font_pointer = 3 + c*width + x + y*width*93;
          s[sprite_pointer] = pgm_read_byte(&font[font_pointer]);
        }
      }
      sprite(disp,s,X+i*(width + spacing),Y,mode);
    }
    i++;
  }
}

I am also having issues with PROGMEM. I can't use forloops to iterate through and print a PROGMEM'd array, it just spits out garbage. I have to go character by character using constants.

The problem is probably not in the code you show, but in some weird interaction with other parts of your program. Please, post a Minimal, Complete, and Verifiable example isolating the problem.

Why compute unsigned int sprite_pointer = 2 + width*y + x;? The array s only has width*height entries, when the for loop goes at the maximum values of x and y, this index will be out-of-bounds. You need 2 bytes more in the s array. What's the size of the font you're passing it?

If this is code from a 3rd party library I would find another library.  If its your code, you need to look at simplifying the function so you can see why it doesn't work.  If anything goes wrong in the code you program will splat stuff everywhere, If its internet connected you could start a world war :)  What does 93 mean?

Maximilian Gerhardt was right. The array had only (witdh*height) but I wrote
(width*height+2) in it. So something else got overwritten and nothing worked. Thanks a lot!

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


text:
How to create "Auto switch case"
I am new to programming. I want to modify this sketch and I really need help. I have a switch case in this sketch, and what I want is an auto change effect.
In this sketch 18 color effects for WS2812B led strip. To change effects you have to press ta button. How do I make it change effect automatically, for example 8-10 seconds. I don't know how to do this. So please help me, huge thanks!
#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
#define PIN 6

#define BUTTON 2
byte selectedEffect=0;

void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  digitalWrite (BUTTON, HIGH);  // internal pull-up resistor
  attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed
}

// *** REPLACE FROM HERE ***
void loop() {
  EEPROM.get(0,selectedEffect);
  if(selectedEffect>18) {
    selectedEffect=0;
    EEPROM.put(0,0);
  }

  switch(selectedEffect) {

    case 0  : {
                // RGBLoop - no parameters
                RGBLoop();
                break;
              }

    case 1  : {
                // FadeInOut - Color (red, green. blue)
                FadeInOut(0xff, 0x00, 0x00); // red
                FadeInOut(0xff, 0xff, 0xff); // white
                FadeInOut(0x00, 0x00, 0xff); // blue
                break;
              }

    case 2  : {
                // Strobe - Color (red, green, blue), number of flashes, flash speed, end pause
                Strobe(0xff, 0xff, 0xff, 10, 50, 1000);
                break;
              }

    case 3  : {
                // HalloweenEyes - Color (red, green, blue), Size of eye, space between eyes, fade (true/false), steps, fade delay, end pause
                HalloweenEyes(0xff, 0x00, 0x00,
                              1, 4,
                              true, random(5,50), random(50,150),
                              random(1000, 10000));
                HalloweenEyes(0xff, 0x00, 0x00,
                              1, 4,
                              true, random(5,50), random(50,150),
                              random(1000, 10000));
                break;
              }

    case 4  : {
                // CylonBounce - Color (red, green, blue), eye size, speed delay, end pause
                CylonBounce(0xff, 0x00, 0x00, 4, 10, 50);
                break;
              }

    case 5  : {
                // NewKITT - Color (red, green, blue), eye size, speed delay, end pause
                NewKITT(0xff, 0x00, 0x00, 8, 10, 50);
                break;
              }

    case 6  : {
                // Twinkle - Color (red, green, blue), count, speed delay, only one twinkle (true/false)
                Twinkle(0xff, 0x00, 0x00, 10, 100, false);
                break;
              }

    case 7  : {
                // TwinkleRandom - twinkle count, speed delay, only one (true/false)
                TwinkleRandom(20, 100, false);
                break;
              }

    case 8  : {
                // Sparkle - Color (red, green, blue), speed delay
                Sparkle(0xff, 0xff, 0xff, 0);
                break;
              }

    case 9  : {
                // SnowSparkle - Color (red, green, blue), sparkle delay, speed delay
                SnowSparkle(0x10, 0x10, 0x10, 20, random(100,1000));
                break;
              }

    case 10 : {
                // Running Lights - Color (red, green, blue), wave dealy
                RunningLights(0xff,0x00,0x00, 50);  // red
                RunningLights(0xff,0xff,0xff, 50);  // white
                RunningLights(0x00,0x00,0xff, 50);  // blue
                break;
              }

    case 11 : {
                // colorWipe - Color (red, green, blue), speed delay
                colorWipe(0x00,0xff,0x00, 50);
                colorWipe(0x00,0x00,0x00, 50);
                break;
              }

    case 12 : {
                // rainbowCycle - speed delay
                rainbowCycle(20);
                break;
              }

    case 13 : {
                // theatherChase - Color (red, green, blue), speed delay
                theaterChase(0xff,0,0,50);
                break;
              }

    case 14 : {
                // theaterChaseRainbow - Speed delay
                theaterChaseRainbow(50);
                break;
              }

    case 15 : {
                // Fire - Cooling rate, Sparking rate, speed delay
                Fire(55,120,15);
                break;
              }

              // simple bouncingBalls not included, since BouncingColoredBalls can perform this as well as shown below
              // BouncingColoredBalls - Number of balls, color (red, green, blue) array, continuous
              // CAUTION: If set to continuous then this effect will never stop!!!

    case 16 : {
                // mimic BouncingBalls
                byte onecolor[1][3] = { {0xff, 0x00, 0x00} };
                BouncingColoredBalls(1, onecolor, false);
                break;
              }

    case 17 : {
                // multiple colored balls
                byte colors[3][3] = { {0xff, 0x00, 0x00},
                                      {0xff, 0xff, 0xff},
                                      {0x00, 0x00, 0xff} };
                BouncingColoredBalls(3, colors, false);
                break;
              }

    case 18 : {
                // meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
                meteorRain(0xff,0xff,0xff,10, 64, true, 30);
                break;
              }
  }
}

void changeEffect() {
  if (digitalRead (BUTTON) == HIGH) {
    selectedEffect++;
    EEPROM.put(0, selectedEffect);
    asm volatile ("  jmp 0");
  }
}

// *************************
// ** LEDEffect Functions **
// *************************

void RGBLoop(){
  for(int j = 0; j < 3; j++ ) {
    // Fade IN
    for(int k = 0; k < 256; k++) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
    // Fade OUT
    for(int k = 255; k >= 0; k--) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
  }
}

void FadeInOut(byte red, byte green, byte blue){
  float r, g, b;

  for(int k = 0; k < 256; k=k+1) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
  }

  for(int k = 255; k >= 0; k=k-2) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
  }
}

void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip();
    delay(FlashDelay);
  }

 delay(EndPause);
}

void HalloweenEyes(byte red, byte green, byte blue,
                   int EyeWidth, int EyeSpace,
                   boolean Fade, int Steps, int FadeDelay,
                   int EndPause){
  randomSeed(analogRead(0));

  int i;
  int StartPoint  = random( 0, NUM_LEDS - (2*EyeWidth) - EyeSpace );
  int Start2ndEye = StartPoint + EyeWidth + EyeSpace;

  for(i = 0; i < EyeWidth; i++) {
    setPixel(StartPoint + i, red, green, blue);
    setPixel(Start2ndEye + i, red, green, blue);
  }

  showStrip();

  if(Fade==true) {
    float r, g, b;

    for(int j = Steps; j >= 0; j--) {
      r = j*(red/Steps);
      g = j*(green/Steps);
      b = j*(blue/Steps);

      for(i = 0; i < EyeWidth; i++) {
        setPixel(StartPoint + i, r, g, b);
        setPixel(Start2ndEye + i, r, g, b);
      }

      showStrip();
      delay(FadeDelay);
    }
  }

  setAll(0,0,0); // Set all black

  delay(EndPause);
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){

  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);
}

void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
}

// used by NewKITT
void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
    setAll(0,0,0);

    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);

    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);

    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
    setAll(0,0,0);

    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);

    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);

    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);

  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),red,green,blue);
     showStrip();
     delay(SpeedDelay);
     if(OnlyOne) {
       setAll(0,0,0);
     }
   }

  delay(SpeedDelay);
}

void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);

  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
     showStrip();
     delay(SpeedDelay);
     if(OnlyOne) {
       setAll(0,0,0);
     }
   }

  delay(SpeedDelay);
}

void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
  setAll(red,green,blue);

  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,0xff,0xff,0xff);
  showStrip();
  delay(SparkleDelay);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
}

void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
  int Position=0;

  for(int i=0; i<NUM_LEDS*2; i++)
  {
      Position++; // = 0; //Position + Rate;
      for(int i=0; i<NUM_LEDS; i++) {
        // sine wave, 3 offset waves make a rainbow!
        //float level = sin(i+Position) * 127 + 128;
        //setPixel(i,level,0,0);
        //float level = sin(i+Position) * 127 + 128;
        setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                   ((sin(i+Position) * 127 + 128)/255)*green,
                   ((sin(i+Position) * 127 + 128)/255)*blue);
      }

      showStrip();
      delay(WaveDelay);
  }
}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
  for(uint16_t i=0; i<NUM_LEDS; i++) {
      setPixel(i, red, green, blue);
      showStrip();
      delay(SpeedDelay);
  }
}

void rainbowCycle(int SpeedDelay) {
  byte *c;
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< NUM_LEDS; i++) {
      c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
      setPixel(i, *c, *(c+1), *(c+2));
    }
    showStrip();
    delay(SpeedDelay);
  }
}

// used by rainbowCycle and theaterChaseRainbow
byte * Wheel(byte WheelPos) {
  static byte c[3];

  if(WheelPos < 85) {
   c[0]=WheelPos * 3;
   c[1]=255 - WheelPos * 3;
   c[2]=0;
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   c[0]=255 - WheelPos * 3;
   c[1]=0;
   c[2]=WheelPos * 3;
  } else {
   WheelPos -= 170;
   c[0]=0;
   c[1]=WheelPos * 3;
   c[2]=255 - WheelPos * 3;
  }

  return c;
}

void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < NUM_LEDS; i=i+3) {
        setPixel(i+q, red, green, blue);    //turn every third pixel on
      }
      showStrip();

      delay(SpeedDelay);

      for (int i=0; i < NUM_LEDS; i=i+3) {
        setPixel(i+q, 0,0,0);        //turn every third pixel off
      }
    }
  }
}

void theaterChaseRainbow(int SpeedDelay) {
  byte *c;

  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < NUM_LEDS; i=i+3) {
          c = Wheel( (i+j) % 255);
          setPixel(i+q, *c, *(c+1), *(c+2));    //turn every third pixel on
        }
        showStrip();

        delay(SpeedDelay);

        for (int i=0; i < NUM_LEDS; i=i+3) {
          setPixel(i+q, 0,0,0);        //turn every third pixel off
        }
    }
  }
}

void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[NUM_LEDS];
  int cooldown;

  // Step 1.  Cool down every cell a little
  for( int i = 0; i < NUM_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);

    if(cooldown>heat[i]) {
      heat[i]=0;
    } else {
      heat[i]=heat[i]-cooldown;
    }
  }

  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for( int k= NUM_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
  }

  // Step 3.  Randomly ignite new 'sparks' near the bottom
  if( random(255) < Sparking ) {
    int y = random(7);
    heat[y] = heat[y] + random(160,255);
    //heat[y] = random(160,255);
  }

  // Step 4.  Convert heat to LED colors
  for( int j = 0; j < NUM_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
  }

  showStrip();
  delay(SpeedDelay);
}

void setPixelHeatColor (int Pixel, byte temperature) {
  // Scale 'heat' down from 0-255 to 0-191
  byte t192 = round((temperature/255.0)*191);

  // calculate ramp up from
  byte heatramp = t192 & 0x3F; // 0..63
  heatramp <<= 2; // scale up to 0..252

  // figure out which third of the spectrum we're in:
  if( t192 > 0x80) {                     // hottest
    setPixel(Pixel, 255, 255, heatramp);
  } else if( t192 > 0x40 ) {             // middle
    setPixel(Pixel, 255, heatramp, 0);
  } else {                               // coolest
    setPixel(Pixel, heatramp, 0, 0);
  }
}

void BouncingColoredBalls(int BallCount, byte colors[][3], boolean continuous) {
  float Gravity = -9.81;
  int StartHeight = 1;

  float Height[BallCount];
  float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
  float ImpactVelocity[BallCount];
  float TimeSinceLastBounce[BallCount];
  int   Position[BallCount];
  long  ClockTimeSinceLastBounce[BallCount];
  float Dampening[BallCount];
  boolean ballBouncing[BallCount];
  boolean ballsStillBouncing = true;

  for (int i = 0 ; i < BallCount ; i++) {
    ClockTimeSinceLastBounce[i] = millis();
    Height[i] = StartHeight;
    Position[i] = 0;
    ImpactVelocity[i] = ImpactVelocityStart;
    TimeSinceLastBounce[i] = 0;
    Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
    ballBouncing[i]=true;
  }

  while (ballsStillBouncing) {
    for (int i = 0 ; i < BallCount ; i++) {
      TimeSinceLastBounce[i] =  millis() - ClockTimeSinceLastBounce[i];
      Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;

      if ( Height[i] < 0 ) {
        Height[i] = 0;
        ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
        ClockTimeSinceLastBounce[i] = millis();

        if ( ImpactVelocity[i] < 0.01 ) {
          if (continuous) {
            ImpactVelocity[i] = ImpactVelocityStart;
          } else {
            ballBouncing[i]=false;
          }
        }
      }
      Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
    }

    ballsStillBouncing = false; // assume no balls bouncing
    for (int i = 0 ; i < BallCount ; i++) {
      setPixel(Position[i],colors[i][0],colors[i][1],colors[i][2]);
      if ( ballBouncing[i] ) {
        ballsStillBouncing = true;
      }
    }

    showStrip();
    setAll(0,0,0);
  }
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
  setAll(0,0,0);

  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {

    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );
      }
    }

    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }

    showStrip();
    delay(SpeedDelay);
  }
}

// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
    // NeoPixel
    uint32_t oldColor;
    uint8_t r, g, b;
    int value;

    oldColor = strip.getPixelColor(ledNo);
    r = (oldColor & 0x00ff0000UL) >> 16;
    g = (oldColor & 0x0000ff00UL) >> 8;
    b = (oldColor & 0x000000ffUL);

    r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
    g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
    b=(b<=10)? 0 : (int) b-(b*fadeValue/256);

    strip.setPixelColor(ledNo, r,g,b);
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[ledNo].fadeToBlackBy( fadeValue );
 #endif
}

// *** REPLACE TO HERE ***

// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************

// Apply LED color changes
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

use millis to check
static unsigned long lastChange = millis();
if(auto_changing && millis()-lastChange  > 10*1000){
    selectedEffect++;
    EEPROM.put(0,selectedEffect);
    lastChange = millis();
}

Put this before the if(selectedEffect>18) and it will cycle each effect for at least 10 seconds before going to the next effect.

BTW I suggest that you rejig your code like blinkWithoutDelay so you don't need to use interrupts the flash memory and jmp 0 and can instead avoid that.
It'll require quite a bit of refactoring though but will allow you to fade from one effect to the next smoothly.

I got error when put your part of code after if(selectedEffect>18), that says next : 'auto_changing' was not declared in this scope
That's screenshot ( https://dl.dropboxusercontent.com/s/1l1342opvq43n6x/javaw_2018-05-31_14-21-35.png )

@VanderAGSN forgot to add that auto_changing is the enable variable for the auto changing mode. When true it will cycle the states if false the current state will remain active. How you change that is up to you

Code successfully accepted in arduino, but effects not switched, have any ideas? Also thanks for help!

Please post the updated code in your question, so that we can see how you followed ratchet freaks instructions


text:
Can i use a range in a switchcase like in pascal?
in pascal's case statement i can use this:
Var i : integer;
...
Case i of
 1..5 : DoSomething;
end;

i was wondering if there is a way in can do this with c/c++ in the arduino compiler using:
switch (var) {
   case 1..5:
     // statements
     break;

or is this only possible using if/else?

In C/C++ you need to write the case explicit "case A: case B: ... break;" https://www.tutorialspoint.com/cprogramming/switch_statement_in_c.htm

Short answer: No
Longer answer: Each case in a switch statement must be a discrete value (which is why floats and doubles won't work either) but there are way around it.  In order of preference:
A) Utilise the "drop through" feature
switch (value)
{
  case 1: // Deliberate drop through
  case 2: // Deliberate drop through
  case 3: // Deliberate drop through
  case 4: // Deliberate drop through
  case 5:
    DoThingA();
    break;
  case 6:
    DoThingB();
    break;
}

B) Change the logic so the range is the default  (not nice, but if you have no other option):
switch (value)
{
  case 6:
    DoThingB();
    break;
  default:
    DoThingA();
    break;
}

C) Use a helper function (Really ugly, but...).  There would have to be a good reason not to call the DoThing() from the helper function.
enum DoOptions {EOptionA, EOptionB};
DoOptions DoWhat (int value)
{
  if (value < 6) return EOptionA;
  return EOptionB;
}
switch (DoWhat(value))
{
  case EOptionA:
    DoThingA();
    break;
  case EOptionB:
    DoThingB();
    break;
}

I guess ill be using if statements then. thx for the quick reply.

The above posted code results in two(2) compiler messages, 1 warning and 1 error

That doesn't surprise me, I wrote them to explain what I was trying to say in the text, not to provide a water tight solution to the problem.  If you are not able to clear the issues on your own, feel free to post details and I'll solve them for you.

There are some GNU extensions available in the avr-gcc/avr-g++ compilers (used in Arduino IDE for AVR based Arduino boards). One of them is suport of ... for the case:
  switch (i)
  {
    case  10 ... 100:  Serial.println(F("First"));           break;
    case 101 ... 1000: Serial.println(F("Second"));          break;
    default:           Serial.println(F("Everything else")); break;
  }

But, it's not the part of C/C++ standard, it's just compiler extension, so there is possibility it fails to compile on different platforms (mainly different compiler). So it's better to avoid it in portable code.

In the settings I have turned on extra warnings and I have added the pedantic flag, then the compiler issues a warning: range expressions in switch statements are non-standard. But I still use it anyway.


text:
IOT-GA6 gsm module Arduino +CME error 58
I've recently bought a IOT-GA6 gsm module . I want to use it to send an mms but doesn't work.
The SMS and call work.
When I execute the void function (mms) the monitor shows the error message +CME EYROR:58.
Does anybody know what this means and how to solve it?

this is my code
include SoftwareSerial.h
include SD.h

define  CS    4

SoftwareSerial A6Module(2, 3);

File dataFile;

int i;

unsigned char data=0;

void setup()
{
  pinMode(PWR,OUTPUT);
  pinMode(CS,OUTPUT);

  A6Module.begin(115200);
  Serial.begin(115200);

  digitalWrite(PWR,LOW);
  delay(10);

  digitalWrite(PWR,HIGH);
  delay(10);

  if (!SD.begin(CS)) Serial.println("initialization failed!");
  else Serial.println("initialization done.");
}

void loop()
{
  if(Serial.available())
  {
    while(Serial.available())
    {
      data=Serial.read();
      Serial.write(data);
      Serial.println("\n");
    }
    //data=0;
  }

  if(Serial.available())
  {
    data=Serial.read();
  }

  if(data=='1')
  {
    A6Module.println("AT+CGMI\r"); //Manufacturer identification
  }

  if(data=='2')
  {
    A6Module.println("AT+CGMM\r"); //Model identification
  }

  if(data=='3')
  {
    A6Module.println("AT+CGMR\r"); //Software version
  }

  if(data=='4')
  {
    A6Module.println("AT+CGSN\r"); //IMEI number
  }

  if(data=='5')
  {
    A6Module.println("ATD+21369682909;\r"); //Calling
  }

  if(data=='6')
  {
    A6Module.println("ATH\r"); //Hang Up
  }

  if(data=='7')
  {
    A6Module.println("AT+CMGF=1");
    delay(2000);
    A6Module.print("AT+CMGS=\"+213696829093");
    A6Module.print(char(34));  // "
    A6Module.print(char(13));  // CR
    A6Module.print('\r');  // hex equivalent of newline
    delay(2000);
    A6Module.print("A6 test message");
    delay(500);
    A6Module.println (char(26));  //ctrl_z
  }

  if(data=='8')
  {
    A6Module.println("AT+CMGR=1\r"); //Read message
  }

  if(data=='9')
  {
   A6Module.println("AT+CMGD=1,0\r"); //Delete message
  }

  if(data=='s') sendMMS();
  data=0;
}

void sendMMS()
{
  A6Module.print("AT+CMMSINIT");
  delay(100);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSCURL=\"http://mms.itelcel.com/servlets/mms\"");
  delay(100);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSCID=1\r");
  delay(100);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSPROTO=\"148.233.151.240\",8080");
  delay(100);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSSENDCFG=6,3,0,0,2,4\r");
  delay(100);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+SAPBR=3,1,\"CONTYPE\",\"MMS\"\r");
  delay(100);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+SAPBR=3,1,\"APN\",\"mms.itelcel.com\"");
  delay(100);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+SAPBR=1,1");
  delay(4000);
  if(A6Module.available())

  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+SAPBR=2,1");
  delay(4000);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSEDIT=1");
  delay(100);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSDOWN=\"PIC\",19293,2000000,\"test.jpg\"\r");
  delay(1000);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }

  dataFile=SD.open("test.jpg");
  i=0;
  if(dataFile)
  {
    while(dataFile.available())
    {
      data=dataFile.read();
      if(data<0x10) Serial.print("0");
      Serial.print(data,HEX);
      i++;
      if((i%40)==0) Serial.println();
      A6Module.write(data);
    }
    dataFile.close();
  }
  else
  {
    Serial.println("error opening test.jpg");
  }

  delay(1000);
  A6Module.print("AT+CMMSRECP=\"+213696829093");
  delay(100);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSVIEW\r");
  delay(2000);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSSEND\r");
  delay(2000);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSEDIT=0\r");
  delay(2000);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
  A6Module.print("AT+CMMSTERM\r");
  delay(2000);

  if(A6Module.available())
  {
    while(A6Module.available()) Serial.write(A6Module.read());
  }
}

which line causes the error? ... use print statements to debug the program flow

all commands beginning as 'AT+CMMS' to A6 receives +cme error 58 I dont' know why!

The Arduino Uno does not support the maximum current requested by GA6, try an external source for the gprs module of at least 6V using common ground between the gprs module and the arduino.


text:
Arduino Switching Between Loops IR Remote
I've been working on an LED strip project. However, I've come to a stand still at the moment. Within the program I am wanting to assign different lighting effects to each button on my IR remote. I am wanting the program to work on the basis that each lighting effect will run, until another button is pressed, to start another effect.
Currently with my code I have made it so each effect will run, once, when the corresponding button on the IR remote is pressed.
I am fairly new to C++ / Arduino but from my understanding I need to have a variable which would hold the current value of the IR remote. I am unsure on how to actually implement this. I will post my code below and if anyone could give me tips or even amendments to my code it would be to a great help.
Thank you in advanced.

#include "IRremote.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, PIN, NEO_GRB + NEO_KHZ800);

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'
int Remote = 0;

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received

// describing Remote IR codes

{
  switch(results.value)
  {
  case 0xFFA25D: Serial.println("POWER");
  ArrowRight(strip.Color(25, 0, 0), 100); //Red
  ArrowRight(strip.Color(0, 0, 25), 100); //Blue
  break;

  case 0xFFE21D: Serial.println("FUNC/STOP");
  ArrowLeft(strip.Color(25, 0, 0), 100); // Red
  ArrowLeft(strip.Color(0, 0, 25), 100); // Blue
  break;

  default:
  Serial.println(" other button   ");

  }// End Case

  delay(0); // Do not get immediate repeat

} //END translateIR
void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn(); // Start the receiver
  strip.begin();
  strip.show();
  Remote = 0;

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?

  {
    translateIR();
    irrecv.resume(); // receive the next value
  }
}/* --(end main loop )-- */

void ArrowRight(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 1; j++) { // The j<# determines how many cycles
    for (uint16_t i = strip.numPixels()/2; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(50);
    }
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(50);
  }
}

void ArrowLeft(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 1; j++) { // The j<# determines how many cycles
    for (uint16_t i = strip.numPixels()/2-1; i + 1 > 0 ; i--) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(50);
    }
    for (uint16_t i = strip.numPixels(); i + 1 > 0 ; i--) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(50);
  }
}

delay(0) apparently[*] acts like delay(2^32) or about 10^10 milliseconds. That may not be what you had in mind ... :)
Try reducing the delay to 1 or use delayMicroseconds() to get something shorter. That should at least get you some repeatable results.
(10^10 mSec is ~ 16.5 weeks, for those without a calculator handy).
[*]  I didn't read the code, nor wait for the call to expire. I tried it and saw that the Uno froze. I'm guessing a zero-argument to delay() isn't rejected but just gets decremented as usual, until it hits zero.

Hi, thanks for the reply. I'm not sure you've understood what I'm wanting to achieve. I am wanting each effect to continuously loop until another button is pressed, activating another effect. I've loaded the code I pasted onto my uno, it works fine for me. I did changed the delay like you said, this seems to just change the speed of which my effect happens, changing it to 1 makes the effect turn into a flash. Thanks.

I need to have a variable which would hold the current value of the
  IR remote.

You already have one.  It's called results and is of type decode_results.
decode_results results;

You read the IR results into that variable.  Then you clear it to look for another one.  What you need is a way to store the last good code that you got.  Your best bet is to just use an int and store a certain number for each code, store a 1 when you get 0xFFA25D and a 2 when you get 0xFFE21D or something like that.  Then use that int instead of the results variable to decide what to do in the rest of the code.


text:
Serial communication between GPS and Arduino Ethernet
I'm trying to read out GPS positions from a serial GPS module I have.
I'm using an Arduino Ethernet and a Haicom HI-204 III GPS (http://www.haicom.com.tw/driver/hi-204iii_usb.pdf).
If I connect the GPS directly to my computer (through a USB-serial converter) at 4800 baud, 8N1, I receive a nice stream of position and diagnostics messages:
$GPGGA,183652.000,5702.0870,N,00954.4732,E,1,06,2.0,20.5,M,42.5,M,,0000*62
$GPGSA,A,3,22,08,27,18,11,32,,,,,,,3.4,2.0,2.7*37
$GPRMC,183652.000,A,5702.0870,N,00954.4732,E,0.00,,310518,,,A*70
$GPGGA,183653.000,5702.0870,N,00954.4732,E,1,06,2.0,20.5,M,42.5,M,,0000*63
$GPGSA,A,3,22,08,27,18,11,32,,,,,,,3.4,2.0,2.7*37
$GPRMC,183653.000,A,5702.0870,N,00954.4732,E,0.00,,310518,,,A*71
$GPGGA,183654.000,5702.0870,N,00954.4732,E,1,06,2.0,20.5,M,42.5,M,,0000*64
$GPGSA,A,3,22,08,27,18,11,32,,,,,,,3.4,2.0,2.7*37
$GPGSV,3,1,12,08,67,204,28,18,59,267,23,10,47,067,26,11,46,279,32*72
$GPGSV,3,2,12,27,36,156,30,01,33,270,20,32,31,116,32,28,26,314,18*79
$GPGSV,3,3,12,22,21,217,33,14,15,140,24,20,09,055,,24,04,038,*7D
$GPRMC,183654.000,A,5702.0870,N,00954.4732,E,0.00,,310518,,,A*76
$GPGGA,183655.000,5702.0870,N,00954.4732,E,1,06,2.0,20.5,M,42.5,M,,0000*65
$GPGSA,A,3,22,08,27,18,11,32,,,,,,,3.4,2.0,2.7*37
$GPRMC,183655.000,A,5702.0870,N,00954.4732,E,0.00,,310518,,,A*77
$GPGGA,183656.000,5702.0870,N,00954.4732,E,1,06,2.0,20.5,M,42.5,M,,0000*66

Now I'm trying to read these messages from the Arduino. But when I connect the GPS to a SoftwareSerial port, I only get gibberish:

:⸮⸮J2⸮⸮>>⸮

(note that when I copy/paste the output to here, many of the charaters disappear, so they are probably completely invalid)
My code looks like this:
#include <SoftwareSerial.h>

#define rxPin 3
#define txPin 4

SoftwareSerial gpsSerial(rxPin, txPin); // RX, TX

void setup (){
  Serial.begin(4800);
  gpsSerial.begin(4800);
}

void loop (){
  while (gpsSerial.available()) {
    char c = gpsSerial.read();
    Serial.write(c);
  }
}

In think the output looks like wrong serial settings, but I have tested all speeds (and verified that 4800 baud works through the serial adapter), and as far as I can tell, SoftwareSerial is 8N1 by default.
What am I doing wrong?

What USB adaptor are you using?

The GPS unit you link to is a USB device, not a serial device. How can you be connecting that through a USB to serial converter?

Good question :-) The USB unit simply becomes USB because they have a serial to USB-converter on the cable between the GPS and the USB plug. So I cut the cable on the serial side of the converter and connected that to the Arduino.

So you don't actually have any information about the electrical signalling the unit uses? You need an oscilloscope to examine the signal - see if it's TTL or EIA-232 signalling.  If it's the latter you will need to feed it through a MAX232 first.

Further Googling leads me to the theory that I might need a RS232-to-TTL converter between the GPS and the Arduino. I'm not sure, though, as I supply the GPS with 5 V directly from the Arduino, so there should be no need for a step down from 12 V.

It's not just stepping down - it's inverting and removing the negative voltages.

Ah, you're too quick :-) No, I don't have any further information, and unfortunately also no scope available. So I guess I will test a MAX232 (somebody also suggests that here: http://forum.arduino.cc/index.php?topic=9798.0)

Awesome, thanks for that info. I'll try it and check back in when I get hold of the hardware. Thanks again!


text:
won't verify a simple code
When I tried to verify a simple “Hello world” program I get the following message:
class hardwareSerial has no member named printin.

What does it mean?

pretty simple fix here, but in the future, please post your code as well as any errors.

Try using println instead of printin.  It stands for print line.


text:
How do I get more than 64 characters of message from serial
I am trying to make a moving message board using an Arduino Uno, HC-05 Bluetooth module and DMD board.
Sending message to the DMD through the Bluetooth module can only give a not more than 62 character message.
I need help in what to do to get up to 200 or more. Thanks.

You need to read the serial data before the buffer fills up. Do not use the serial's buffer in place of your own.

What about reading the serial buffer into a ring buffer larger that 64 bytes?

I got to access the HardwareSerial through program files> arduino, till i got to it, but find it hard to implement a change, am a newbie in this stuff.

The point is, that you don't really have a good reason to modify the HardwareSerial library. You are a beginner, so start with using the library correctly by constantly reading the bytes from the internal buffer to your own big buffer in your code. You do not need to modify the library for this

First: There is no such concept of a message on the Serial bus, unless you implement it yourself. On hardware level only individual bytes are transmitted, and you don't even know, when each byte will be transmitted exactly. Since there are only individual bytes in the first place, there is no limitation on how many bytes can be transmitted.
Yes, the Serial library has a limited buffer of 64 bytes, but as Majenko wrote it is not intended for buffering all bytes for one of your messages. It should only buffer the bytes, until the main sketch can read them from the buffer. On reading the bytes will be removed from the buffer, leasing buffer space for new characters.
The buffer size of the Serial library can be increased by changing the numbers in HardwareSerial.h in the following lines
#define SERIAL_TX_BUFFER_SIZE 64

#define SERIAL_RX_BUFFER_SIZE 64

But this is not really the solution to your problem. When first filling the buffer and then read the whole message you just arbitrarly
constrain yourself to a insufficient solution.
Instead of waiting for all the messages bytes (and finally filling up the buffer) you should steadily check, if new bytes are available and then load them into your own buffer. You can use a delimiter byte to mark the end of a message, mostly "\n" (newline character) is used for this. Copy the bytes into your own buffer, until you read the delimiter byte. Then use the message as a whole for your application. Don't forget to clear your buffer afterwards.
The examples for the Serial library, especially the SerialEvent example show how to do this in your code.

It gets even worse.  There's no concept of a message in a serial line, but there often is in an application.  Further, a serial link proxied over Bluetooth will be bunched into packets and tend to arrive in bursts.  But those bursts often won't align with the boundaries between application messages!

The software from the transmitter can break the text you want to send into pieces of 62 characters in length and send them one by one. The receiver will save the most recent piece in a String and join it with a another String which will be storing the whole message. If you don't mind it being a little bit slower, then this is the solution for you


text:
Need Input: Wait for voltage input to begin script & when voltage maintains 0V for X amount of time Reset and wait for Voltage Input
So I'm currently working on an automotive set up.
I'm using a 555 timer to emulate a turn-signal alternating voltage pulse (12V to 0V and repeat) for debugging purposes which is output to turnPin/A1.
Here's the goal: When voltage is greater than 1V arduino is to supply constant power to output pin (pin 13) until input voltage is returned to constant 0 (or end of turn signal input) for x-time or as I'll refer to as Timeout.
It seems I've gotten the constant power to apply when input is applied and then turn off constant output when voltage is back to 0V. However I'm having difficulty getting the timeout function to work properly as the LED still remains HIGH.
EDIT: I've reworked the code to use millis(); rather than purely using sensor inputs. I've also added comments to help walk you through what I believe is happened/what I want to happen.
// Constants won't change
const int ledPin = LED_BUILTIN; //using built in led + pin13
const int turnPin = A1;         // the input pin (turn signal alternating 5V/0V/5V/0V & so-forth)

// Variables will change
int ledState = LOW;             // the current state of the output pin
int prevLed = ledState;
int lastVoltage = 1;            // the previous reading from voltage source
int state = 1;                      // the current "state" (see below)
                                // State = 1++: LED OFF -- State = 0: LED ON

// The following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.

long previousMillis = 0;    //the last time the voltage reached 0
long waitTime = 100;    // the wait time

void setup()
{
  pinMode(ledState, OUTPUT);        //set output pin
  pinMode(turnPin, INPUT);          //set input pin NOTE: SIGNAL ALTERNATES
5V/0V/5V/0V & so forth to emulate a turn signal for this application
  Serial.begin(9600);               //begin serial
}

void loop()
{
  int sensorValue = analogRead(turnPin);        // Read voltage at input pin
  float voltage = sensorValue * (5.0/1023.0);   // Convert
  unsigned long currentMillis = millis();    // set currentMillis as current
 time

  if (voltage > 1)      //if Voltage greater than 1V
  {
    ledState = HIGH;    //turn led on
    state = 0;          //set state to 0
  }

  if (voltage < 1)      //if voltage less than 1V
  {
    currentMillis;      //set currentMillis as current time

    if ((millis() - currentMillis) > waitTime) // if (current time minus time voltage was less than 1) is greater than wait time
    {
        ledState = LOW;     //set LED to off
        Serial.print("OFF - TIMED OUT - WAITING FOR INPUT: ");  //output message for debug
        Serial.println(state);//current state
        state++;              //increment state (time passed)
    }
        else if ((millis() - currentMillis) < waitTime) // if (current time minus time voltage was less than 1) is less than wait time
        {
            ledState = HIGH;    //set LED to on
        }
  }
  digitalWrite(ledPin, ledState);   //send LED status to output
}

When voltage > 1  .... larger than one what? potato? .... it is really unclear what you are asking, a few commas in some of your sentences would help

@jsotola "Voltage > 1 Volt" - My apologies thought it was assumed. And No. I didn't read it after I wrote it! My bad! Haha. Updated.

if (sensorValue < 1 > currentMillis + 500)  What the heck is this line supposed to mean?

@Delta_G if sensorValue greater than 1 for greater than current time + 500 then ->
Was a late-night I'm-done-for-the-night hoo-rah.

@jsotola Volts.

So you're saying that late at night you try to invent your own syntax?  That won't work.  Try coming back early in the morning and studying how the language works.  That will work a lot better.

@Delta_G code updated. Any input?

the question is looking better .... removed the downvote .... what is it that you are building?

you assign this variable float voltage = sensorValue * (5.0 / 1023.0); , but you do not use the variable voltage anywhere in your code

To start the timer when the input drops, you need another state variable that remembers the last state of the input. I would rather not use the global ledState or the local status for that, but I would add an extra global variable. Meanwhile, you are crawling towards an infinite state machine.

Hello everyone. Comments under questions are for clarifying the question, not to make a "mini answer". If you want to answer the question please type something into the "Your Answer" box and then submit it. Answers can then be voted on, and the best answer floats to the top of the answer chain, as Stack Exchange intended.

In a nutshell here is a summary of my goal.
Launch: Wait for voltage input from turnPin (turn signal).
Voltage Received: Supply constant V to output pin then wait for Voltage to drop to 0V for 500ms.
When Voltage = 0V for 500ms: Stop constant voltage to output pin and wait for input from turnPin (turn signal) again.

updated question/reworked code to help everyone better understand what I'm trying to do.

Thanks for everyone's input. I've come up with the solution.
Using the while function I was able to create two "states" for the code to be in. A timed-out state and not timed-out state, respectively. While in the timed-out state the output will be 0 and vice-versa for the latter and wait for the voltage to reach 0 for "X" amount of time.
I also integrated a "learn" feature to set the delay based on the alternating input voltage if necessary. Otherwise it will default to the value within the timeoutWait variable.
Code is below. Please let me know if you have any input/suggestions.
/*
  PURPOSE: This application was built for an automotive application. Client replaced OEM turn signal's with aftermarket multicolor
  LED strips controlled by an unknown controller. In order for the turn signal function of the LED strips to work the
  controller had to be powered on. It was undesired to run the LED's every time the vehicle was driven. Therefore, the
  controller needed to be supplied constant power when an input from the OEM turn signal wiring (which alternates 16V/0V/16V/0V...
  and so-forth was applied.

  OVERVIEW: In a nutshell: this application will supply constant output to any specified output (pin 13 in this case) when 5 Volts is
  applied to any specified Analog input (pin A1 in this case). When voltage to the input pin is discontinued after 250milliseconds
  the constant output will be terminated. The application will then wait for voltage to be resupplied to the input pin.

  This application will also support an alternating input source (turn signal in this case). The amount of time to wait before returning
  the output pin to an OFF state is determined one of two methods.

  METHOD 1: Setting a default by amending the timeoutWait variable.
  METHOD 2: Using the Learn Button to time voltage drops and adjust the time-out wait time accordingly (+ 50 milliseconds for any variations in timing)

  USING THE LEARN BUTTON: At any point in time, press and hold the push button for approximately 6-seconds (real time - non simulation). This will
  time the difference in time between Voltage > 1 and Voltage < 1 and set it as the timeoutWait time. NOTE: The variable timeoutWait is not updated!
  The variable blinkRate is updated with this data.

  CIRCUIT: For emulation purposes a circuit was built using a 5V Power Supply connected to an ATTINY microprocessor (to emulate the alternating
  turn signal of 5V/0V/5V/0V alternation every 250milliseconds) connected to pin A1 on an Arduino UNO R3. An LED with a 1kΩ resistor was connected to pin 13.
  The learn button is powered and grounded from the arduino board with a 10kΩ resistor and connected to Digital Pin 2 on the arduino board.*/

// Constants won't change
int output = 13;            // Pin to output voltage
int input = A1;             // Pin to receive voltage
int learnButton = 2;        // Pin to receive signal for learn mode
int waitTime = 500;         // Time to wait in milliseconds
int timeoutWait = 250;      // Time to wait in milliseconds

// These variables will change
int relayState = LOW;       // Track what state the relay is in
bool timeout = false;       // Track if we're timed-out or not
bool learnMode = false;     // Track if we're supposed to be in learn mode or not
int blinkRate = 0;          // Store blink interval in millis (obtained from learn mode)
int lastButtonState = 0;    // Track the last state of the learn button
int buttonState = 0;        // Track the current state of the learn button

// The following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long timerStart = 0;        // Track when timer started
long timerStop = 0;         // Track when timer stopped
long passedTime = 0;        // Track time elapsed =(timerStop - timerStart)
long blinkStart = 0;        // Track when blink HIGH (learn mode)
long blinkStop = 0;         // Track when blink LOW  (learn mode)

void setup()
{
  pinMode(relayState, OUTPUT); // Set output pin
  pinMode(input, INPUT);       // Set input pin
  pinMode(learnButton, INPUT); // Set input pin (learn mode)
}

void loop()
{
  int sensorValue = analogRead(input);          // Read voltage at input pin
  float voltage = sensorValue * (5.0 / 1023.0); // Convert
  buttonState = digitalRead(learnButton);       // Read the learnButton pin
  Serial.begin(9600);                           //  Begin serial communication

  if (buttonState == HIGH)  // If the learnButton is pressed
  {
    learnMode = true;   // Enter learnMode
  }
  delay(50);        // Debounce

      if (voltage > 1)    // If Voltage is Greater Than 1 Volt
  {
    timeout = false;  // Set timeout state to FALSE since there's no reason to timeout
    passedTime = 0;   // Reset passedTime variable
    timerStart = 0;   // Reset timerStart variable
    timerStop = 0;    // Reset timerStop variable
  }

  if (voltage < 1)  //If Voltage is Less Than 1 Volt
  {
    timerStart = millis();                 // Start the timeout timer
    delay(waitTime);                       // How long should we wait until it times out?
    timerStop = millis();                  // Stop the timeout timer
    passedTime = (timerStop - timerStart); // Calculate how much time we waited

    if (passedTime >= waitTime) //If the calculated time is greater than or equal to our wait time
    {
      sensorValue;      // Re-check the Voltage first

      if (voltage < 1)  // If the voltage is still Less Than 1 Volt
      {
        timeout = true; // Set timeout state to TRUE since the voltage has been less than 1 Volt for >= our Wait Time
        timerStart = 0; // Reseet timerStart variable
        timerStop = 0;  // Reset timerStop variable
        passedTime = 0; // Reset passedTime variable
      }
    }
  }

  while (timeout == true)                    // If TIMEOUT = TRUE
  {
    relayState = LOW;                        // Set the relay state to LOW/OFF
    sensorValue = analogRead(input);         // Read voltage at input pin
    voltage = sensorValue * (5.0 / 1023.0);  // Convert
    digitalWrite(output, relayState);        // Tell the relay to turn off

    if (voltage > 1)    // if the voltage is Greater Than 1 Volt
    {
      timeout = false;  // Set timeout state to FALSE since there's no reason to timeout
      timerStart = 0;   // Reseet timerStart variable
      timerStop = 0;    // Reset timerStop variable
      passedTime = 0;   // Reset passedTime variable

    }

    if (voltage < 1)
    {
      timeout = true; // Set timeout state to TRUE since the voltage has been less than 1 Volt
      timerStart = 0; // Reseet timerStart variable
      timerStop = 0;  // Reset timerStop variable
      passedTime = 0; // Reset passedTime variable
    }
  }

  while (timeout == false)  // If TIMEOUT = FALSE
  {
    sensorValue = analogRead(input);        // Read voltage at input pin
    voltage = sensorValue * (5.0 / 1023.0); // Convert
    relayState = HIGH;                      // Set the relay to ON/HIGH since we're not timed out
    digitalWrite(output, relayState);       // The the relay to turn on
    buttonState = digitalRead(learnButton); // Read the learnButton pin

    if (buttonState == HIGH)  // If the learnButton is pressed
    {
      learnMode = true; // Enter learnMode
    }
    delay(50);        // Debounce

    if (voltage < 1)  // If the voltage is Less Than 1 Volt
    {
      timerStart = millis();                // Start the timeout timer

      if (blinkRate > 100)          // If blinkRate is Greater Than 100
      {
        timeoutWait = blinkRate + 50; // Set timeoutWait to blinkRate value + 50 milliseconds for any variations in timing
      }
      else                // If blinkRate is not Greater Than 100
      {
        timeoutWait = timeoutWait; // Leave default value alone
      }

      delay(timeoutWait);                     // How long should we wait to timeout in this state?
      timerStop = millis();                   // Stop the timeout timer
      passedTime = (timerStop - timerStart);  // Calculate how much time we waited

      if (passedTime >= timeoutWait)  //If the calculated time is greater than or equal to our assigned wait time
      {
        sensorValue;        //Re-check the sensor first

        if (voltage < 1)    //If the sensor read less than 1 Volt
        {
          relayState = LOW; //Set the relay state to OFF/LOW.
          timeout = true;   //Keep us in the timed out state.
          timerStart = 0;   //Reset timerStart variable.
          timerStop = 0;    //Reset timerStop variable.
          passedTime = 0;   //Resed passedTime variable.
        }
      }
    }
  }
  while (learnMode == true)  // If LEARNMODE = TRUE
  {
    sensorValue = analogRead(input);        // Read voltage at input pin
    voltage = sensorValue * (5.0 / 1023.0); // Convert
    Serial.println("LEARN MODE ACTIVE");  // Print to Serial Monitor

    while (voltage > 1)
    {
      sensorValue = analogRead(input);        // Read voltage at input pin
      voltage = sensorValue * (5.0 / 1023.0); // Convert
      blinkStart = millis();          // Set blinkStart as running millis();
      Serial.print("Start: ");          // Print to Serial Monitor
      Serial.println(blinkStart);       // Print to Serial Monitor
      delay(50);                // Debounce
    }
    while (voltage < 1)
    {
      sensorValue = analogRead(input);        // Read voltage at input pin
      voltage = sensorValue * (5.0 / 1023.0); // Convert
      blinkStop = millis();           // Set blinkStop as running millis();
      Serial.print("Stop: ");         // Print to Serial Monitor
      Serial.println(blinkStop);        // Print to Serial Monitor
      delay(50);                // Debounce
    }

    blinkRate = (blinkStop - blinkStart);   // Calculate blinkRate
    Serial.print("Blink Interval: ");     // Print to Serial Monitor
    Serial.println(blinkRate);          // Print to Serial Monitor
    delay(50);                  // Debounce
    learnMode = false;              // Exit learnMode
  }
  digitalWrite(output, relayState);       // Send relayState
}

It's hard to know where to start here. :)

 if (currentMillis + 500)

OK, what is that doing? It is adding 500 to currentMillis so that will be true almost all the time.

if (status = 3)

That is assigning 3 to status and then checking if it is non-zero, which it will be (it will be 3).

int turnPin = A1;
...

  int sensorValue = analogRead(A1);

Why not write:
  int sensorValue = analogRead(turnPin);

float voltage = sensorValue * (5.0 / 1023.0);

You calculate voltage but never use it. Why bother?

As for your question regarding if (currentMillis + 500) I wanted this statement to take the current time and add 500 to it and then check ...

OK, then this is the way to do that:
// see if 1/2 a second is up
if (currentMillis - previousMillis >= 500)
   {
   previousMillis = currentMillis;  // reset previousMillis
   ... do something ...
   }

BTW, previousMillis is also a variable you weren't using anywhere else.

Thanks for the input Nick!
I've cleaned the code up a bit more - just a few minor oversights I missed. Thanks for pointing them out.
As for your question regarding
if (currentMillis + 500)
I wanted this statement to take the current time and add 500 to it and then check if the voltage is still less than 1V - if it is then execute the ledState = LOW

See my amended answer.


text:
Arduino or Raspberry? Self Balancing robot
Here's another one, as you probably have seen before.
I'm finishing college, and I'd like, base of my subscription to be a self balancing robot that can send data to a screen. What kind of data? I am in the brain-storming zone with this question and so far I have:

Distance to other objects
Time, temperature, direction N-S-W-E, pressure (as in a car where you measure oil temp, tire pressure etc)
State of balance (as on y axix, a point going from -y to y where 0 is the balance point)
Any othet possible inte-[deleted]-resting thing you could get as a response from a little two-wheels robot
Remote control via wireless preferably

Now, the big question. Is arduino the best choice, or should I consider Raspberry Pi?
Thanks in advance!

This depends on the type of screen you want to interface. An Arduino UNO can with big effort interface a VGA signal with very low resolution and only few colors. Better are little screens (like small OLED screens or small LCD displays with integrated controller). Using a more capable Arduino (like the Mega) can extent the capabilities of your project. The RaspberryPi has of course big display capabilities (like 1080p over HDMI).
There is also another side to the problem: A self balancing robot needs to control its motors very fast (changing the direction fastly depending in sensor input). A RaspberryPi is in principle a computer, not a microcontroller. Programs in it don't have a garanteed time of execution, so especially under high load the program might have to wait for its turn, effectively destabilizing the robot. For these real time fast applications a simple microcontroller is fitted better.
Since you also want wireless control you might be interested in using an ESP (WLAN) as a microcontroller.
All in all you should use a microcontroller for driving the balancing logic and motor control. Depending in your needs you can either use only this microcontroller to do all the other things too or connect another board as a master (eg over I2C vor SPI) which tells the microcontroller what to do. For this a raspberryPi is good.
If you provide more information about the concrete target capabilities you might get a better answer. The scope of your project is too open for clear answers.

I agree that the scope of this issue is a bit wide, but I just found some boundaries regarding the main ideas of it, which are very helpful for furthure progress. I.ll keep brainstorming and will cone back into this topic and try to expose a more on-point idea.


text:
Bitmap only displays correctly with PROGMEM keyword
I have a bitmap to draw defined as below.

PROGMEM const unsigned char ship1 [] = {0x18, 0x3C, 0x7E, 0xFF, 0x81, 0xC3};

It is then used by the arduboy library's draw slow bitmap function like so:
arduboy.drawSlowXYBitmap(5,5, ship1, 8 , 6, WHITE);

Can anyone explain to me why the bitmap only draws correctly with the PROGMEM keyword? I omitted it at first and it causes the bitmap to look completely different.
I see that this keyword makes the data get written to flash instead of SRAM.
The hardware I am using is the Arduboy.
The arduboy.drawSlowXYBitmap() function is from https://github.com/Arduboy/Arduboy
void Arduboy::drawSlowXYBitmap
(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color)
{
  // no need to dar at all of we're offscreen
  if (x+w < 0 || x > WIDTH-1 || y+h < 0 || y > HEIGHT-1)
    return;

  int16_t xi, yi, byteWidth = (w + 7) / 8;
  for(yi = 0; yi < h; yi++) {
    for(xi = 0; xi < w; xi++ ) {
      if(pgm_read_byte(bitmap + yi * byteWidth + xi / 8) & (128 >> (xi & 7))) {
        drawPixel(x + xi, y + yi, color);
      }
    }
  }
}

Imagine two programs identical apart from the PROGMEM keyword. The program only contains the lines mentioned above and the relevant calls to refresh the display. What I want an explanation of is why I get a garbled image without it and a fine image with it.

It depends on the application code (which you didn't give us!). If the code uses pgm_read_byte to read from the pointer, it will read from program memory (flash). Else, from RAM. If you change a variable's storage from PROGMEM to RAM but don't adapt the code, errors like yours happen (reading from the wrong mem addr).

@MaximilianGerhardt I have added the only other relevant line in the code but this is a library call so I will have to find the source code. In both cases the variable is a const the only difference was the Progmem keyword.

I was right on the money: https://github.com/Arduboy/Arduboy/blob/master/src/Arduboy.cpp#L630

@MaximilianGerhardt Ok that makes sense and it clearly works fine with the progmem keyword but could you explain why this happens then when the only change is whether the code is built with the keyword or not.

Because without the PROGMEM keyword your doesn't put the data in the same place that the library is going to look for it.  You put it in SRAM and the library is looking at the same address in flash.  Imagine sending a letter to the right street address but with the wrong city and zip.

@Delta_G Perfect that answers it. The function looks in flash and not SRAM. Max said it looked in flash first before looking in SRAM which confused me.

The point I wanted to make was that if it does pgm_read_byte( somePointer ) then it will read from flash, else, meaning "direct dereference" using *somePointer or somePointer[i] will load from RAM.

@MaximilianGerhardt Ok that makes sense.If you put your comments in an answer I will mark it as the answer. Thanks.


text:
How to send int[][] as a byte array through Serial
I have int arr[50][2]; and I need to send it through Serial. But I don't know how to do it. is it possible?

In what format? binary data or readable ascii? seperated with comma's?

@Jot Is it possible to get the same array on another side?

No, unless you make code that can do that. The most common way is to use Serial.print and transmit each element of the array (that is 100 times the Serial.print). You could transmit a single binary block of data, but the computer might have the MSB at the lower byte and the Arduino at the higher byte or vice versa. You need a very accurate description of the data which is transferred. It can be defined as a single block of 200 bytes consisting of 2 byte signed integers with MSB first with start byte and end byte and a crc checksum.

I forgot to mention to select a high baudrate. Not 9600 but 115200 or higher. The output tx buffer is 64 bytes, and if the tx buffer is filled, the Serial.print will wait and that will delay the sketch.

Send it to what through serial? A PC, another arduino, a printer, something else?

@Craig to another arduino

serial communication is like a tennis ball launcher .... in your example, it will fire 100 tennis balls at you, one after another .... it is up to you to arrange them any way you want after you catch them .... therefore, you have to know in which sequence they were fired

In the comment you write that the receiving end is an Arduino too. Then you can send the data in binary form.
To send the array:
Serial.write((byte*) arr, sizeof(arr));

(byte*) is cast of the memory location of arr to a byte array
sizeof returns the size of the array in bytes

To receive the binary data you must know the size. Here we read 100 16-bit integers:
Serial.readBytes((byte*) arr, 100 * sizeof(short));

Function readBytes is one of the 'timed' functions of Stream. It waits for the next byte (until timeout).
If one Arduino is 8-bit and the second is 32-bit, then use the type short instead of int, because the size of type int is different, but the type short is 16 bit long on all Arduinos.


text:
How to run Arduino code on Linux?
I want to use an MFRC522 module as explained in this video.
But is it possible to get around with Arduino and use a TTL to USB converter to connect RC522 directly to my PC running Ubuntu?
Using the RC222's UART interface, should I rewrite Arduino libraries from scratch for PC or is there a way to easily port the libraries?

are you wanting to keep it in c++?

no. the language is not important at all. Is it feasible in you opinion? @ChadG

Arduino libraries rely on the Arduino API to operate (usually). Things like the Serial object are expected to be defined.
Linux doesn't have any of that stuff, so you would have to implement it all yourself.
There is the "Wiring Pi" project for (obviously) the Raspberry Pi that implements the majority of the Arudino API, but whether that could be made to run on Linux on a PC is anyone's guess.
It may be simpler to just examine the existing library (and datasheet) and implement it yourself in your chosen language.


text:
If I use a biasing circuit for a signal going into an analog input pin, will it affect the ADC operation?
If I have a single 100Hz AC signal biased by two 1 M-ohm resistors (as per schematic below), and then output to an Arduino UNO analog input pin, with the UNO sampling at around 1 kHz using delays, would there be any issues with the ADC result?

(Source of schematic: http://tinyurl.com/ycprqsdx)
From the Atmega328P's spec sheet (the UNO's microprocessor) it recommends an output impedance of 10 k-ohms or less, as shown below.
If I used the pair of 1 M-ohm resistors as a biasing circuit and then deliberately slow down the sampling with delays (i.e.: in loop, do analogRead, then delay, then do analogRead, etc.), would it still be okay?

It will give bad results. You're not slowing down the sampling, you're taking samples at a longer interval - a very different thing.
The Arduino uses a Successive Approximation ADC. That uses a clock to control the output of a DAC and compare that voltage with the incoming voltage stored in the S&H capacitor.
In order for the S&H capacitor to get charged to the correct level it has to be connected to the GPIO pin long enough. Since there is only one ADC and 6 analog input pins, it goes through a MUX first.
The delay that needs increasing is the delay between the pin being connected to the capacitor and the capacitor being connected to the ADC.  This is called the acquisition time.
The analogRead() function does these basic operations in sequence:

Connect the SHC to the GPIO pin through the mux.
Wait
Disconnect the SHC from the GPIO and connect it to the ADC
Clock each bit from the comparator to the result registers.

Putting a delay between each analogRead would just delay the connecting of the SHC to the GPIO pin, not increase the time it's connected to the GPIO pin.
You would have to manipulate the ADC registers to do your own sample timing.  Or, just reduce your output impedance.

Thanks for the clarification between sampling interval and taking samples at a longer interval. I guess I can also reduce the output impedance with an op-amp-based buffer.

Yes, you could. Or replace the 1MΩ resistors with 10kΩ ones.

My concern with doing that is that the 100 nF with 10kΩ would effectively make a high pass filter cutting off at ~159 Hz; for my application, I do need those lower-frequency components too.

Increase the capacitor to compensate then?

Right, got it. So my previous 100 nF with 1 MΩ can be replaced by a 10 uF with 10 kΩ.

Yup. T=RC, so increase C and decrease R and T stays the same.

Adding capacitance to the input will help compensate for the high impedance but it also forms a low pass filter. For a 16 MHz Arduino the ADC clock is set to 16 MHz/128 = 125 KHz. Each conversion in AVR takes 13 ADC clocks so 125 KHz /13 = 9615 Hz. That is the maximum possible sampling rate, but the actual sampling rate in your application depends on the interval between successive conversions calls.


text:
how to know the channel i receive information from when i use nRF24L01 to connect between 3 of them
i am using nRF24L01 to connect between 3 of them ( 1 is master and the others are slaves) and i am using nRF24 library , my problem is that when the master receive something from the other slaves and do not know from which channel the infromation come so is there is a way to know from which channel
//master channel code:
  const byte addresses[][6] = {"00001", "00002","00003"};
  radio.openWritingPipe(addresses[1]); // mastr
  radio.openReadingPipe(2, addresses[0]); // carwl
  radio.openReadingPipe(2, addresses[2]); // carwl2
//slave 1 channel code :
  const byte addresses[][6] = {"00001", "00002","00003"};
  radio.openWritingPipe(addresses[0]); // carw1
  radio.openReadingPipe(2, addresses[1]); // mastr
//slave 2 channel code:
  const byte addresses[][6] = {"00001", "00002","00003"};
  radio.openWritingPipe(addresses[0]); // 00003
  radio.openReadingPipe(2, addresses[2]); // 00002
library i use: https://github.com/nRF24/RF24

You can pass theRF24.available function a pointer to a variable. The available function will write the pipe-number of the message to that variable.
An example can be found in the documentation

The nRF24 is highly versatile and can be programmed for a number of different network topologies.  It appears you want either

One-to-many network - where the master node sends data to the slave nodes
Many-to-one network - where the master receives data from many slaves.

Both networks are achieved with the same radio channel (RF_CH) on all nodes.
For a one-to-many network you need to have a different RX address for each slave node.  Set the master TX address to the RX address of the corresponding slave  that you want to receive the data.  Done.
For a many-to-one network you are limited to 6 slave nodes.  On the master radio you will need to set the addresses of data pipes 0-5 to the slave TX addresses.  The master will be listening for data on all pipes and signal an interrupt whenever data is received on any of them.
To achieve bi-directional communication with a (practically) unlimited number of slave nodes, your best bet is to use the in-built ACK PAYLOAD feature of nRF24.  In addition to configuring a one-to-many network, you need to enable ACK payload on each radio node.  The procedure to follow is given in the nRF24L01 data sheet.  I can't recommend strongly enough how important that is to read and learn from.  You will be able to send a message from the master to one slave, and get data back from that node in the same radio transmission, auto-retransmit etc included in the bargain.  This way you also know which node the data are coming from - without needed to encode the identity of the slave node in the message.  It's incredible what these little radios will let you achieve!