text:
I have just done this same code but not getting exact time as per Indian timezone...What thing should I add to get exact time?
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/

static const int RXPin = 10, TXPin = 11;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup() {
  Serial.begin(115200);
  ss.begin(GPSBaud);
  Serial.println(F("DeviceExample.ino"));
  Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
}

void loop() {
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();
  if (millis() > 5000 && gps.charsProcessed() < 10) {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
}

void displayInfo() {
  Serial.print(F("Location: "));
  if (gps.location.isValid()) {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  } else {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid()) {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  } else {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid()) {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  } else {
    Serial.print(F("INVALID"));
  }
  Serial.println();
}

Is this what you are looking for:
https://forum.arduino.cc/index.php?topic=473294.msg3237680#msg3237680

Use NeoGPS instead of TinyGPS, it has time and date functions for timezone offsets.
Ref:
https://forum.arduino.cc/index.php?topic=473294.msg3237680#msg3237680

This is a link-only answer, please provide the relevant parts in the answer here.

@Avamander changed the answer as requested.

Thank you, at least it won't be flagged as "link-only" now.


text:
getting " .error: failed sending 1116 bytes warning: espcomm_send_command: didn't receive command response"
I'm getting error while uploading sketch into nodemcu ch340g as shown below

I have tried these things to rectify the error
1) Changed usb cable
2) changed the port
3) flashed the firmware with nodemcu_float_0.9.6-dev_20150704.bin by esptool.py
4) flashed with nodemcu flasher
But no change at all and it is showing same error only what can i do now

I had a similar problem yesterday, I had plugged a shield into my D1 the wrong way around.  Is it possible you have made some incorrect connections?

I have disconnected all the things ,even though it is showing same error

3) flashed the firmware with nodemcu_float_0.9.6-dev_20150704.bin by esptool.py

So assuming that actually completed successfully you can rule out anything being wrong with your hardware. There is no difference between manually flashing a firmware file and flashing using the IDE.
You need to take a look at the command you used to flash that firmware successfully, especially things like which port you used and what baud rate, and make sure you replicate those same settings in the IDE. Especially the baud rate, which you can select in the Tools menu.

Problem solved by doing this
In boards, I have mentioned node MCU 1.0 and that's the mistake I have done, after changing the board to node MCU 0.9, then the program is uploading and thanks for all your suggestions

source: Stack Exchange

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

sort: votes


text:
What is the maximum SPI speed for a slave Uno/clone?
I have a Rapsberry Pi master sending SPI requests to an Uno Chinese clone slave : I send 16 characters to the Arduino, which answers 16 others characters. What I send is not important, it's the Arduino answer that matters.
When I set the speed on the Raspberry Pi at 1 Mbit/s with my C program, the received answer coming from the Arduino is mostly garbage (random characters), but this issue disappears with lower speeds.
So that leads me to this question : what is the maximum SPI speed for a slave Uno/clone, in order to have no errors ?
Edit : the Arduino code :
#include <SPI.h>

char receivingBuffer[5];
char sendingBuffer[5] = {'T', 'e', 's', 't', '!'};

volatile char bytes_received = 0;

void setup()
{

  SPCR |= bit(SPE);

  pinMode(MISO, OUTPUT);

  SPI.attachInterrupt();

  SPDR = sendingBuffer[bytes_received];

}

ISR(SPI_STC_vect)
{

  if (++bytes_received == 5)
  {

    bytes_received = 0;

  }

  SPDR = sendingBuffer[bytes_received];

}

void loop()
{

  //

}

Also, the C code on the RPi :
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPiSPI.h>

#define SPI_CHANNEL 0
#define SPI_SPEED   1000000 // Hz.

int main(void)
{

   wiringPiSPISetup(SPI_CHANNEL, SPI_SPEED);

   while (1)
   {

      char buf[5] = {'T', 'e', 's', 't', '?'};

      printf("Sending   : %s\n", buf);

      wiringPiSPIDataRW(SPI_CHANNEL, buf, 5);

      printf("Receiving : %s\n\n", buf);

      sleep(1);

   }

   return 1;

}

The theoretical maximum is 8Mbps, which is F_CPU/2. What matters though is that you react fast enough to the requests for each byte and fill the buffer fast enough. That's down to your program to determine.

Please show your code. What you are doing in order to answer is highly relevant. If you are sending at 1 Mbits/s then the slave doesn't have many clock cycles to formulate a response.

I added the Arduino code.

What happens if you set a transfer speed of >1Mbps and put a delay in between each byte (at the Pi side) - does it start working then?

With 1.5 or 2 Mbps, I receive the first character of the expected answer, and the other characters are the sent message's ones.

I have a 1 second delay in the while() loop between two messages, but I'm using the WiringPi library to work with SPI, and I don't think I can put a delay between two bytes.

Sure you can. Just send one byte instead of 5.

The maximum speed for Arduino as a slave is F_CPU/4, so it's 4Mbps.
When the Arduino is the master it can work at F_CPU/2, so it's 8Mbps

Thank you for your answer ! Do you have any source to confirm this ?

You can find this in ATmega328 datasheet. The ATmega328 is the chip on Arduino Uno.

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


text:
Problem reading from GPS
Right now I am working on a project where I need to turn on four LEDs in sequence, 1100 before 12 am and 1010 after 12 am. I am using a GPS in this project and I want to access the time from the GPS. The problem is that I am not getting it. How to make it possible?
GPS module: RoyalTek 4216
CODE:
#include <NMEAGPS.h>
#include <SoftwareSerial.h>
SoftwareSerial gpsPort( 50, 52 );
#define gps_port Serial1
NMEAGPS gps;
gps_fix fix;

void setup() {
  Serial.begin(9600);
  gpsPort.begin(9600);
  for (int thisPin = 2; thisPin <= 13; thisPin++) {
    pinMode(thisPin, OUTPUT);
    int i=0;
    long k;
  }
  for (int n = 22; n <= 52; n++) {
    pinMode(n, OUTPUT);
  }
}
// the loop routine runs over and over again forever:
void loop() {
  while (gps.available(gpsPort)) {
    gps_fix fix = gps.read();
    Serial.print(F("DATE:  "));
    if (fix.valid.date && fix.valid.time) {
      // Shift the date/time to local time
      NeoGPS::clock_t localSeconds;
      NeoGPS::time_t  localTime; {
        using namespace NeoGPS;
        localSeconds = (clock_t) fix.dateTime;
        localSeconds += 5 * SECONDS_PER_HOUR + 30 * SECONDS_PER_MINUTE;
        localTime = localSeconds;
      }
      Serial.print( localTime.date);
      Serial.print( '/' );
      Serial.print( localTime.month);
      Serial.print( '/' );
      Serial.println( localTime.year);
      delay(500);
      Serial.print("\n*************************\n");
      {
        Serial.print( F("TIME:  "));
        Serial.print( localTime.hours );
        Serial.print( ':' );
        Serial.print( localTime.minutes );
        Serial.print( ':' );
        Serial.print( localTime.seconds );
        delay(500);
        Serial.print("\n");
        k=localTime.hours;
        int i=0;
        long k;
        if (k>=0 &&  i==0) {
          digitalWrite(2, HIGH);
          digitalWrite(3, HIGH);
          digitalWrite(4, HIGH);
          digitalWrite(5, HIGH);
          delay(5000);
        } else {
          digitalWrite(2, LOW);
          digitalWrite(3, LOW);
          digitalWrite(4, LOW);
          digitalWrite(5, LOW);
          delay(5000);
        }
      }
    }
  }
}

Well, first you have to state your problem. What hardware are you using? What code did you write?

Guurav .  Please can you fill in the name of the GPS and board you are using (where the ??? are).  People need this information to be able to help you.  Also check the LED connections are correct, I guessed.  You have tagged mega and uno, please remove the one you are NOT using.

So what results are you getting? Your code isn't trying to do much with the LEDs, and you clearly need to read more about variable scopes because at first glance the way you declare the variable k is a wrong. Also avoid using single letter variables unless they only exist for a few lines, variable names should describe them not just be the first letter your fingers hit. Do you get any time displayed or not?

I hate to have to say this and I always try not to, but your code is awful.  Firstly it doesn't compile, and I can say that without even trying because the errors are very obvious.  If you reply is that it does compile then you have posted the wrong code.
In Setup() you are setting loads of pins to output, why?  You are only using 4 pins, 2,3 4 and 5!
Having a using namespace line at the top of your code is bad enough, it negates the purposes of a namespace, but having it in the middle of you code is really bad.  Just type the extra few characters, it will save you a lot of grief in the long run.
Scoping chunks of code can be good, but not in this case, it makes the code harder to read.  It would be better if you wrote a function to factor the date time printing out, i.e.
void PrintDT (char* type, int a, int b, int c, char sep)
{
    Serial.print(type);
    Serial.print( a );
    Serial.print( sep );
    Serial.print( b );
    Serial.print( sep );
    Serial.println( c );
}

And then called it:
PrintDT(F("DATE:  "), localTime.date, localTime.month, local.year, '/');
PrintDT(F("TIME:  "), localTime.hours, localTime.minutes, localTime.seconds, ':');

The less lines of code you have the easier it is to spot bugs.
Here is why I said it won't compile:
    k=localTime.hours;

    int i=0;
    long k;

    if (k>=0 &&  i==0)

You are assigning a value to k before you have declared it, but looking at setup it could be a copy and paste error, because you have similar lines up there.
Also assign meaningful names to your variables.  I'm guessing that k is the hours and i is meant to be minutes?  To be honest in this case I wouldn't use variables at all, just have this code
if (localTime.Hours >= 0 && localTime.Minutes == 0)

But that if statement doesn't do what you say you want to do at the top of the question.  When the time has any number of hours, including zero, and the minutes are zero.  According to you question you want
if (localTime.Hours == 0 && localTime.Minutes == 0)

But that means you will only see the lights on 1100 for 1 minute at midnight.
I hope that helps, There is nothing wrong with the process you are following, just some of the things you doing and the logic.  If it doesn't fix it, clarify what the exact error is and we'll see what we can do.

I have done my code and trust me it actually works. I know I did many common mistakes in my given code but reason is I have combined my two codes that's why. anyways sorry for that and thanks for help :-)

So you don't know how to read the time from a GPS?  Is that the problem?
Since you haven't stated the make and model of GPS and microprocessor I can only give you generic information.
GPS output their data in ASCII format over a serial link usually operating at 9600 BAUD.  So you need to connect you microprocessor to the GPS using a secondary serial port (Not the serial port you upload through).  On something with only one serial port (Uno, ESP8266, etc) you need to use the SoftwareSerial library to do this.
Then read from the serial port as you would do normally and parse the string you read to extract the time portion of the message, this should be quite easy to spot.  Most GPS's pump out two different messages at regular intervals and so you need to filter the message you don't want.
Relying on just a GPS for time is a bad idea, because you will get periods where the azimuth of the satellites is to low and you won't get sufficient coverage.  I would also use an real time clock (RTC) and use the GPS to update the RTC periodically and source the time from the RTC.


text:
How can I connect a force sensitive resistor to a vibration motor via Arduino?
Please forgive me if my knowledge is limited--still very new to this!
I'm currently working on my senior thesis for my Industrial Design program and I'm struggling to figure out the components and code I need to link a FSR and a vibration motor. Basically the idea would be that high pressure on the FSR would equate to high vibration on the motor and vice versa so you could get variable intensity based off of how hard you squeeze the sensor. I've looked up a lot of different circuit diagrams for using a vibration motor with an Arduino and many of them seem to indicate that I will need a 1N4001 Diode, a 2N2222 NPN Transistor, a 1KΩ Resistor, and a 0.1µF ceramic capacitor. I'm currently using the Arduino UNO R3 and I don't want to fry it so before I go tinkering too much I wanted to ask what you all might do to achieve what I'm aiming to do.
Thank you and I appreciate any and all feedback!

When asking about circuits it's best to include a circuit diagram. The editor here includes a tool that lets you draw them as part of the question.

I'm not sure why you need the Arduino at all.  If the force on the FSR increases resistance then you just need to invert that value and apply it the motor.  To be honest this sounds more like an electronics problem so you might want to get this moved to SE EE.

Can you provide a data sheet for the fsr?


text:
ATmega328p hangs on USART RX interrupt
I was able to use USART without interrupt driven and it worked perfectly! However, when I tried adding interrupt on USART_RX_vect, the program does not work as expected anymore.
Below is my small program. The expected behavior of this program is everytime I press a button the LED should toggle its state, but also by default the LED will toggle its state every 500ms. Right now, the LED toggles every 500ms but
 the moment I press a button on my machine keyboard to send data to the ATmega328p, the program stops (the led freezes on its last state).
I am not using an external clock, but I wonder if that could be the problem or I am missing something in my code that I can't figure out.
I appreciate any help. Thank you.
#ifndef F_CPU
#define F_CPU 1000000UL
#endif

#define FOSC F_CPU
#define BAUD 4800
#define MYUBRR FOSC/16/BAUD-1

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

void USART_Init(unsigned int ubrr) {
   UBRR0H = (unsigned char)(ubrr>>8);
   UBRR0L = (unsigned char)ubrr;
   UCSR0B = (1<<RXEN0) | (1<<RXCIE0);
   UCSR0C |= (1<<UCSZ00 | (1 << UCSZ01));
}

IRS(USART_RX_vect) {
    PORTC ^= (1 << PC5);
}

int main(void) {
    USART_Init(MYUBRR);
    DDRC |= (1 << PC5);
    sei();
    while(1) {
        PORTC ^= (1 << PC5);
        _delay_ms(500);
    }
    return 0;
}

Edit#1: I modified IRS handler:
Code:
IRS(USART_RX_vect) {
    while(!(UCSR0A&(1<<RXC0))){};
    unsigned char received = UDR0;
    PORTC ^= (1 << PC5);
}

Status: Program does not work.
Edit#2: Fixed typo ISR instead of IRS (pffff)
Solution: I was missing the code for consuming the RX buffer and I had a typo: IRS should be ISR. Thanks for @Edgar Bonet and @Majenko for the help!

Just replace IRS (Internal Revenue Service) with ISR (Interrupt Service Routine).

Nice catch, I didn'even think about this ... I thought the compiler would help me fix my syntax :/

@COMP: It did help me: warning: type of ‘__vector_18’ defaults to ‘int’ and warning: unused parameter ‘__vector_18’.

@COMP: And warning: return type defaults to ‘int’ for the IRS() function.

Good catch there ;) I suspect it may actually be a combined problem including not reading the RX buffer, and both needed to be fixed to see it work.

EdgarBonet you're right, I ignored my console as long as it passed the syntax analysis phase. @Majenko yes it's both answers combined that fixed my problem. Thanks!

I suspect if you were a fly you would see your LED flashing very very rapidly.
The reason is, your interrupt will constantly trigger itself over and over and over again.
Why? Because you aren't reading the incoming character from the RX buffer. And until you do the chip will keep alerting you that there is something there to read by triggering the interrupt.

I tried modifying my code, not sure if that is enough to consume the character from the buffer. (Refer to Edit#1)

It should be - if the compiler doesn't optimize it out (which it shouldn't since one half is volatile). However, I usually simplify it to: (void)URD0;

Unfortunately it did not fix my program, but it's for sure something I didn't know. Thanks!


text:
ESP8266 Send data to Firebase using Arduino Uno error
Good day everyone! I have a project, in which the data from a button (number of clicks) will be sent to a real-time Firebase database. Every time the button is clicked the counter increases and will be updated in the firebase database.
Wifi Module:
Esp8266 Esp-01 + Esp-01 Adapter

In my understanding, there are 2 ways to use this wifi module.

Upload the code to the Arduino Uno and use AT commands in the module to send data to the web.
Upload the code inside the WiFi Module itself and after that it can be a standalone SOC and does not need the Arduino anymore after the code has been uploaded.

I have tried the second way, but I got confused and stuck. So far I have successfully plugged the adapter in a breadboard and tested some AT commands.
Since I will be using the second way I won't be using these. So I tried this code:
 #include <ESP8266WiFi.h>
 #include <FirebaseArduino.h>

 #define FIREBASE_HOST "https://duck-917ba.firebaseio.com/"
 #define FIREBASE_AUTH "r3jNQCsxN2Y2dcfawimRlzjLjdBSXLjstwGeyB0oMK"

 #define WIFI_SSID "mywifi"
 #define WIFI_PASSWORD "621533515"

const int  buttonPin = 8;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

void setup() {
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.setInt("clicks",0);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
      Firebase.setInt("clicks", buttonPushCounter);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(100);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;
}

So I have plugged my 4-pin adapter to the following:

ARD(TX)-ADAPTER(TX)
ARD(RX)-ADAPTER(RX)
ARD(5V)-ADAPTER(VCC)
ARD(GND)-ADAPTER(GND)

I have set the Generic ESP8266 Module Board.
Problems Encountered:
I am supposed to select the port of the ESP8266 but I only see the Arduino UNO port in the port list. When I compile the code I get this error:

I am now confused on what the error is all about. I thought since I am using an adapter I can use the PROGRAMMING MODE of the module easily. But it seems like my adapter is not doing its job. According to some of my research I have to use  TTL or FTDI USB-to-serial dedicated module / Ground some wires while compiling which is very confusing for a beginner like me.
So here are my final thoughts:

Can I input/flash code in my module using my Arduino and adapter?
Since the button is plugged in the Arduino's pin 8, does that mean that the code in the module will be successfully inserted? I will still need the Arduino to be plugged in the buttons?
What could be the reason why the module won't appear in the Port List and generates the errors?

I know this is quite a long and boring topic but I know a lot of aspiring IOT developers out there are having the same issues about this wifi module. I hope we can solve it together. Thanks!

You will get all info at below link.. try it.. https://www.diyhobi.com/flash-program-esp-01-using-usb-serial-adapter/

1.) Can I input/flash code in my module using my arduino and adapter?

Yes

2.) Since the button is plugged in the pin 8 of arduino. Does that mean If the code in the module will be successfully inserted. I will still need the arduino to be plugged in the buttons?

The ESP8266 cannot magically know about the Arduino and the Arduino cannot magically know about the buttons. If you have buttons connected to the Arduino then the Arduino needs telling about them. If the Arduino and ESP8266 need to work together then they both need programming to work together. If, and only if, you connect the buttons to the ESP8266 and not the Arduino do you not need the Arduino.

3.) What could be the reason why the module won't appear in the Port List and generates the errors?

The Arduino is getting in the way. Connect Arduino RESET to Arduino GND to disable the ATMega328p chip which is also trying to use TX and RX and conflicting with the ESP8266. Or better still get a cheap USB to UART cable (just a couple of dollars on eBay) and connect the adaptor direct to your PC without the Arduino.

Thank you for the response. Like you said I tried to put the RESET to GND in the arduino. I tried to tweak my adapter so that the connection would go like this and enter programming mode: ARD(TXD)-TXD, ARD(RXD)-RXD, CH-PD&VCC TO 3.3V, RESET&GND&GPIO0 TO GND, GPIO2 unplugged. But unfortunately when I try to upload the Arduino UNO/ COM12 still appears on the port list and it seems like my module cannot be read in the arduino port list for some reasons.

It sounds like you are expecting your module to appear separately on the computer. It's not the module that is connected to the computer, it is the Arduino that is connected to the computer. It is the Arduino that you will always see.

I see. I ordered an USB to UART cable online and would arrive in a couple of days. So in my understanding I will have to plug my module+adapter in the uart device and plug it in my computer so I can start programming directly inside the module without the need of arduino? Incase I successfully uploaded my code in the module I can use it in boot mode and use it with the arduino? To sum it up plug in UART(programming mode), plug in Arduino(Boot Mode)? Thank you for helping me

Sure. As long as both the Arduino and the ESP8266 have been programmed in such a way that they will work together. And that doesn't mean using AT commands since the ESP8266 would no longer understand them.

Connect GP00 to ground
This is required to flash ESP8266


text:
Video streaming by ESP32
I'm making an Arduino car and controlling it with a game-pad by bluetooth.  I want to have a live video from it by using ESP32 board and ov7670 camera or vc0706 camera. How can I do this ??

You start by reading the docs, running the examples, doing your own test and finally, implementing your solution. If you have some especific problem along the way, you ask here.

I don't know how to strat

Start with checking how feasible your requirements are (I guess Arduino and a camera is not feasible, same as esp32 for live video), but try and you will find out.

@MatsK - Are you sure its not feasible on an ESP32?  I can't find any examples, a but 240MHz dual core should be able to stream low res video I would have thought.

My bad, I missed that it was ESP32.

See the documents and information of arducam library it may help you.....
This lib uses to connect with OV5640 5MP Camera and in its examples you may got your answer...

There is only one sort of ESP32 type board supported by Arducam as far as I can see and it still seems to be limited to still images.


text:
Unexpected results and hard crash when modifying and addressing arrays & variables within a struct
I'm trying to use a 2D array inside a struct on my arduino to store sensor readings. I'm having two main problems:
1: My Arduino is crashing and resetting when I try to access certain directories in my Array
2: My arraysize variable doesn't seem to be incrementing the way I'm expecting it to.
I've attached snippets of my code that I think are relevant.
struct calibration
{
  float NTU[];
  unsigned int readings[][28];
  unsigned int arraysize = 0;
};

//Main
void loop() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Waiting...");
  if (digitalRead(inputPin) == HIGH)
    TakeReadings();
  delay(50);
}

//after taking many readings from a sensor and averaging...

Calibration.readings[Calibration.arraysize][0] = average;
Calibration.arraysize++;
PrintMatrixToSerial();

//serial print function

void PrintMatrixToSerial() {
  Serial.print("1.9,1  3.8,1  7.5,1  15,1   30,1   60,1   120,1");
  Serial.println();
  for (int i=0; i<Calibration.arraysize; i++) {
    for (int j=0; j<7; j++) {
      Serial.print(Calibration.readings[i][j]); Serial.print("   ");
    }
    Serial.print('\n');
  }
}

When trying to assign values to my Calibration.readings array in certain directories, the Arduino hard crashes. For instance, a crash happens when the arduino tries to execute:
Calibration.readings[Calibration.arraysize][2] = average;

Secondly, after running my TakeReadings() function only once, I expect Calibration.arraysize to be equal to 1, therefore the PrintMatrixToSerial() function should only print one row of data; however, the serial monitor prints many rows. The following is an example of the output:
1.9,1  3.8,1  7.5,1  15,1   30,1   60,1   120,1
11   298   0   65292   779   1284   6
167   167   167   167   167   167   167
167   167   167   167   167   167   167
167   167   167   167   167   167   167
167   167   167   167   167   167   167
167   167   167   167   167   167   167
167   167   167   167   167   167   167
167   167   167   167   167   167   167
0   167   167   167   167   4245   40853
167   167   167   167   167   167   167
319   167   167   167   167   167   167
Is there an issue with my struct, or array declaration? I'm stumped at the moment, so any help would be appreciated.

You're not allocating any memory to your readings array. Give it a size.

Thank you, that fixed both problems. I was under the impression that declaring the size of the first array in a matrix wasn't required, is that wrong for all cases?

You can skip the first one IF AND ONLY IF you supply a list of initializers in braces as part of the definition.  In that case the compiler will count the number of things in the list for you.

@Majenko - comments on questions are for clarifying the question. Please make a proper answer, especially as the system will throw this up as an unanswered question if you don't.

@NickGammon Many times I am using my phone and the android SE app. Writing answers on that is a real pain in the sphincter. So I get the OP up and running with a quick comment. Later on, when back at my PC (sometimes the next day) I convert my comments to a real answer. I do not need telling every time by you. I know how the site works.

You are not specifying a size for your readings array:
unsigned int readings[][28];

That is not saying "Give me an array of an unknown number of chunks, each of 28 values", it is actually saying "Give me a pointer to a block of memory (which I will provide later) which is arranged in rows of 28 values".
In C you must either provide a size for an array, in which case the memory is statically allocated for you, or manually allocate the memory at a later date.
unsigned int readings[16][28]; // 16 rows of 28 int values

Or, for dynamic allocation:
unsigned int readings[][28];

// allocate the memory ...
blah.readings = malloc(16 * 28 * sizeof(int));
// do things with your array ...
// and free up the memory when finished:
free(blah.readings);

On an embedded system it is generally to know how many readings you will be taking beforehand. That way you can allocate the correct number of rows to the array before you compile the program, which makes many things more efficient.


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


text:
Connecting Arduino Uno WiFi Developer Edition to the Internet
I recently bought an Arduino Uno WiFi Developer Edition from here. Although all the other functionality appears to work (I’m able to upload/run programs, read sensors I plug in, etc.), I am not able to connect the Arduino to the internet. The Arduino has a built in ESP8266 chip which is compatible with the WiFi Link library, however, running ScanNetworks in the Arduino mac IDE (File > Examples > WiFi Link > ScanNetworks) doesn't work, nor does it print any errors. Other example files in that library don't work either. The CheckWiFiLinkFirmwareVersion program in the same library will print the welcome message "WiFi Link firmware check." but nothing after that.
I have tried every other WiFi library I could find in the library manager window (Sketch > Include Library > Manage Libraries), namely

Arduino Uno WiFi Dev Ed Library
WiFiEsp
WiFi101
WiFi

However, none of them work. Is the Arduino's WiFi chip defective, or am I doing something wrong? One reviews on the website that I bought the Arduino from said this (see lenny):

Arduino.org (which is different from arduino.cc) has not made software available to access the WiFi capabilities of this board. As far as I can tell, the wifi cannot be used. They keep saying that the software is coming soon.
See this thread on their forum: http://www.arduino.org/forums/uno/arduino-uno-wifi-arduinowifi-library-incomplete-solution-for-mqtt-tcp-udp-socket-communication-540

In summary, is the Arduino Uno WiFi Developer Edition known to be defective? If not, what am I doing wrong? If it is, could I potentially get a WiFi shield and use that instead of the built in chip? I have other shields for the Arduino (e.g. an SD card shield) that are working fine.

Re your quote : Arduino and Genuino "merged" (maybe not technically, but in essence) a few days ago when the Chairman came back and the row ended and all became lovely in the world again.  So this may well change in the near future.  It may be worth posting a question to push the issue on the Arduino forum.

Do you have access to the Webgui?
with the Webgui you can configure the wifi settings.
you do not need to upload sketches for this.
It is a good test if there is no defect.
Connect your PC Wi-Fi or with your smartphone directly to the Aduino uno wifi.
Start your browser and type in the following IP: 192.168.240.1
and now you should see the WebGUI.

The correct WiFi library for that board is here:

https://github.com/arduino-libraries/UnoWiFi-Developer-Edition-Lib

If that is not working you may have a defective board. Maybe the ESP8266 firmware is incorrect.

That GitHub link is just the repo to the "Arduino Uno WiFi Dev Ed Library", which I already installed through the library manager window in the mac desktop IDE. The ReadMacAddress example program in that library prints "Please, push the  ESP B/L button on the board and plug the USB cable before run the sketch," but after doing both things, it doesn't work. Interestingly, I see "Arduino-Uno-WiFi-823889" in the list of WiFi networks on my computer. Is that a sign that it does work and I am just doing something wrong? I bought two Arduinos, and neither can connect.

If the built in WiFi chip does not work because the Arduino Uno WiFi is new and still in development, can you recommend a good WiFi shield that has been around a while, is supported by the community, and works with the Uno and its variants?

The Arduino WiFi Shield maybe?

This popular question on Arduino.SE gives all the ways to connect an Arduino to WiFi. It mentions both the Arduino WiFi Shield and the cheaper ESP8266 chip. However, if you click through the link, it says the WiFi shield is retired. Why is that? Am I better off with an ethernet shield?

I am sure it is not defective. You just don't understand how it works, because of it's architecture. In addition the original firmware and the UnoWifiDefEd library are strange and limited. I recommend using WiFi Link firmware and library.
I currently write a community documentation for the Uno WiFi & WiFi Link


text:
Format error with ESP8266 compile
I get this error when I try to compile and upload the code for the ESP826612E
fork/exec /home/c/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++: exec format error

I don't understand what the problem is, It was working fine for days until today.
Anyone has solutions?

I suspect you are running a 32-bit compiler on a 64-bit operating system. You will need to install the 32-bit support libraries.
$ sudo apt-get install libc6-i386


text:
is a 5V cellphone power supply stabilised?
can I feed my arduino UNO with a 5V cellphone USB power supply ?
Since the arduino board doesn't regulate the 5V from the USB input, is a cellphone power supply sufficiently regulated ?

Please state the reason for downvoting this question. The blog posted by Look Alterno proves that the question is relevant.

Yes. USB is a standard. You can even use 5V power packs for portable gizmos.
Caution: Ken Shirrif have a good post about non-original USB chargers and its perils. (A dozen USB chargers in the lab: Apple is very good, but not quite the best). Read them and learn a lot.
I only use the original charger that comes with the cell or tablet (and that usually last longer that the cell or tablet that it comes with). I don't trust any third party USB charger or car adapter after Ken's analysis

but is a cellphone power supply sufficiently regulated ?

I think so. I don't have hard data, but I had been using cell USB chargers for powering Arduino with no problems.

It's impossible to give specific answers to vague generalised questions. 99.9% of them are fine but how can anyone be sure about the one in your hand when you've not said what it is.

The posted blog perfectly answered my question !

It is a USB (1.0 & 2.0) requirement that a USB Host power lines are 5 volts and can supply up to 500mA.  Here is a USB power standards table from wikipedia.org.
If your Arduino project pulls more, then the 5 volt level may drop.  That is to say, for more than 500mA you will need to consult the power pack specifications.

In general terms yes, the output of a USB power adaptor for a mobile phone will be suitably stabilised.
Most phones have the ability to monitor the voltage and adjust the charging current depending on the voltage they see. If the voltage drops below, say 4.5V, they will reduce the current they draw until it rises back above that threshold (as can be seen if you use a 1A cable on a 2A charger, the phone will throttle the current to within the 1A range since the cable imposes too high a voltage drop).
For this reason it is important that power adaptors put out the correct voltage otherwise mobile phones wouldn't be able to work properly with them.
Cheap imported USB power adaptors often fall far below proper safety standards, though, so you should use a proper branded one (Apple, Samsung, etc) from a reputable dealer, not something for $4 off eBay. Those cheap ones are a serious safety hazard and can cause electric shocks and fires.

So this means that the stabilisation is done by the phone and not by the adaptor. Since the Arduino will not reduce its current draw, using a USB power adaptor for mobile phone is a bad idea.

No. The power supply has to be stabilised for the phone to be able to detect a voltage drop from incorrect cable, etc. If the supply wasn't stabilised the phone would get confused and not be able to charge.


text:
How can I know if I can stack some shield on another shield?
Yesterday I tried to stack a motor shield on a servo motor shield already stacked on my Arduino Uno.
But I realized that I have some problem when I try to use both of them. It seems like some energy is lost or the stepper motor connected to my servo motor shield move weirdly slowly.
I already checked online, and I found some explanations about stacking many shields. About making sure the shields don't use the same pins or SS. As a beginner, help would be very helpful. Thank you.
Here are the two shields I use.

Smart Servo Shield for dynamixel
https://store.arduino.cc/arduino-motor-shield-rev3
Smart Arduino Digital Servo Shield for Dynamixel AX
https://www.dfrobot.com/product-958.html

wiki : https://www.dfrobot.com/wiki/index.php/Digital_Servo_Shield_for_Arduino_SKU:DRI0027
On these links, you can find all the specs with the pins used. I think I have some pinß shared by both of them... But not sure.
Does anyone have a solution please? Many thanks in advance.

The real answer, you don't know.  For example, a shield may need to use the serial port.  So a second identical shield may not work as it too may need to use the same serial port.  Or it may be that the designer of the shield did something clever and used a software serial port of the 2nd shield.

The above comment refers only to hardware.  There is also the software problem of sharing resources.  For instance, a motor shield may use the same timer as an SDCard shield.  So the software for each may not work when both are active on the same Arduino.

Thank you for your example. but for my problem , both of my shields is different. They are not same. I just want to kknow if i need buy another arduino , or have a way for make it work

Mhh ok , so , the best choice is to use one shield per arduino i know. But i know too, sometimes we can stack more than one shield. And for my project i want try to make it the lightest and thinest possible

When using more than 1 shield or Arduino library you will always be taking a risk of running out of resources.  The only true way to be sure this will not happen is to backwards engineer the shield and / or library until you understand what resources each need.  It is a lot of work for a beginner. Many people simply experiment / test to see if a given combination works.  Usually for software nothing much bad happens.  But for hardware there is always a chance of "burning something up".

First you have to compare the pinouts of the two shields. If the shields use completely different pins then yes, you can use them together.
However if they share pins then you need to look in more detail at what those pins are and how they are being used.
In your example you have SPI being used (pins 10-13) for one shield and PWM (3/11) and GPIO (8/9/12/13) and analog input (A0/A1) for the other shield.
You can see now that there is a conflict. For instance pin 13 for the SPI clock for the DFRobot shield is also being used for one of the GPIO pins of the Arduino shield. Pin 12 for MISO is being used as GPIO. Pin 11 for MOSI is also being used for PWM.
Those are disparate functions on the pin, so it can never work.
However if the SPI pins were being used for both shields as SPI then that could work. In that case it's only the "chip select" pin that needs to be unique for each shield, since SPI is a Master-Slave Bus protocol which can be shared amongst multiple shields.

Ok thank you , That's a nice answer !! So even if i want to use a arduino Mega, it's will not work . I think i will use two separate Arduino Uno.


text:
Writing on a SdCard
I'm writing on a SD card the value of a measured voltage. I've a good sampling/writing frequency but regularly the acquisition take a lot of time (like 4000us instead of 400us). I noticed that this "pause" appears every 85 values (my values are 6 bytes long, so it appears every 510 bytes).
So I have hypothesized that there is a buffer of 512 bytes somewhere which is full and need some times to empty.
But I don't know where is this buffer. In SDcard? in Arduino? And how can I avoid this issue?
Here, my results on 1Hz sinus with a zoom on the "break":
And here my loop to read the value and write it on sd card:

Hope you can help me guys !

Possibilities:

What you can do it measure what you need inside an interrupt routine (I hope the measurement itself does not take too long). Write it to a buffer in the interrupt routine. Your 'normal' loop can do the writing to the SD card.
A possible very extensive solution would be to send the sampled data to another Arduino which can store it on an SD without affecting the sampling (since it's done on another Arduino).
Using DMA (Direct Memory Access), however afaik this option is not available for an Arduino.

That a good idea thank you, but my measure is did with an external ADC wich communicate in I2C. And I2C use interrupt so i can't communicate in another interrupt. And Sdcard communicate in SPI, so i will probably miss values too while interrupt is disable during SPI communication

True, to be honest, I don't have experience with interrupts myself, but it seemed appropriate here, but it already uses interrupts.

Other interrupts are disable during an interrupt vector, maybe i can do a software SPI and software I2C, but i'm thinking it will take a lot of devellopment to finally lost a lot of speed.

I never tried software SPI or I2C, but tried software UART/Serial for MIDI (which is slow, 31250 baud) and it didn't work at all, so I assume you will not have much luck with software solutions.
You might need to use DMA , but afaik the Arduino does not have that.

A possible very extensive solution would be to send the sampled data to another Arduino which can store it on an SD without affecting the sampling (since it's done on another Arduino).

This idea interests me a lot, i think i will try this ! Thanks !

@bouaah I added it in the answers (easier for others too)

The buffer is in the SD card library. It is the size of one block on the SD card. When it is full it needs flushing out to the SD card, which takes time. Once that is done the buffer is then empty again and can be filled back up by your code.
It has to be done this way because SD cards work in blocks of 512 bytes.

Thanks a lot, I was confused to don't know where was this buffer. I have to find a solution now to keep the best regular sampling rate.


text:
Arduino IDE missing libread.s0.6
I just recently installed the ESP8266 libraries on the arduino IDE using the boards manager, the code compiles fine with the ESP, but when the board is changed to UNO, i get this error,
opt/arduino-1.6.7/hardware/tools/avr/bin/avrdude: error while loading shared libraries: libreadline.so.6: cannot open shared object file: No such file or directory

Any solution to this?

You have to keep your software updated. Arduino IDE is currently in version 1.8.3.

So install it?
$ sudo apt-get install libreadline6

Or, if you need the i386 version on an x64 platform:
$ sudo apt-get install libreadline6:i386


text:
Use Print library to set string variable
I need a function that has the basic functionality of the Print library, accepting different kinds of argument types and parsing them. However, I would like to then store the result in a string/char array. Does anybody know how I might utilize the Print library to do so?

RTFM: https://www.arduino.cc/en/Reference/StringConstructor

Sorry. I typically work in C. I didn't realize the string constructor was so robust. Thanks.

my StreamLib published in 2018 has CStringBuilder

You can get all the functionality of Print by creating your own class
that inherits from it. For this, you only need to implement the
size_t write(uint8_t) method that prints a single character. Here is a
simple class that inherits from both Print and String, i.e. you get
a String you can print() and println() into:
// A String you can print() and println() into.
class PrintString : public Print, public String
{
public:
    PrintString() : String() {}

    size_t write(uint8_t c) {
        *this += (char) c;
        return 1;
    }
};

And here is how you could use it:
PrintString answer;
answer.print("The answer is ");
answer.println(42);


text:
ESP8266 connecting keypad and lcd display
I have ESP8266 type -
I have added a keypad
With a standard lcd display.
I have connected the keypad from d0 to d7, however after watching some tutorials i have to connect the lcd display(SDA,SCL) to D0 and D1, where i should connect the display to when they are taken by the keypad?

You can read the keypad using a single analog input (A0 in ESP8266) using this circuit:

When you press a key, some resistors are connected between Vcc and Ground. For each key, the total resistence is different, and the voltage at the input pin is different.
To read the keypad, you read the voltage at the input pin A0. You also have a table that associate the readings with keys. You search in the table for the nearest entry to the value you get. That's your key.
Wire the circuit and make a little sketch to read the values for each key you press. That's how you construct your table.
The value at A0 will be a little different each time you read the pin. That's is normal. Don't expect a exact macht.

This won't work! the ADC of ESP is in range 0.0-1.0v!


text:
Coding or Wiring? Dual Piezo sensor not triggering LED lights
I am running two piezos off an Arduino UNO and trying to get 10 LED lights to trigger when the piezo voltage exceeds a certain threshold. Problem is, the LEDs wont fire when the Piezo voltage exceeds that threshold and I'm not sure if it is a coding or wiring problem.
Below are pictures of the wiring (Top and bottom) and code. Any help is much appreciated!!

/*
  Dual Piezo Bond Auger Sensor; Blinking LED Light Stack Sketch

  -----------------------------------------------------*/

//Piezo 1 Pin (PiezoPin1)
//Piezo 1 connected to A0
int PP1 = 0;

//Piezo 1 Pin (PiezoPin1)
//Piezo 2 connected to A1
int PP2 = 1;

//Sets the threshold for the detected sound to trigger the LED
const int threshold = 0.01;

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

  for (int i = 4; i < 12; i++) {
    pinMode(i, OUTPUT);
    //sets the led pins 2-11 to output
  }
}

void loop() {
  //Ensure to turn off ALL LEDs before continuing
  for (int i = 4; i < 12; i++) {
    digitalWrite(i, LOW);
  }

  /* Read the Piezos
    Reads both piezos and outputs the values. Triggers LED lights
    to fire when a peak voltage is exceeded
    Adjust the value based on the peak signal voltage you
    want to trigger the LED lights*/
  int Piezo1ADC = analogRead(PP1); // Read Piezo 1 ADC value
  float Piezo1V = Piezo1ADC / 1023.0 * 5.0; // Convert to voltage
  int Piezo2ADC = analogRead(PP2); // Read Piezo 2 ADC value
  float Piezo2V = Piezo2ADC / 1023.0 * 5.0; // Convert to voltage
  Serial.println(Piezo1V); //Print the voltage from Piezo 1
  Serial.println(Piezo2V); //Print the voltage from Piezo 2
}

// The blink function - used to turn the LEDs on and off
void blink(int LEDPin11, int LEDPin2, int LEDPin3, int LEDPin4, int LEDPin5, int LEDPin6, int LEDPin7, int LEDPin8, int LEDPin9, int LEDPin10, int Piezo1V, int Piezo2V, int threshold) {
  if (Piezo1V >= threshold || Piezo2V >= threshold) {  //toggle status of LED pins linked to PP1
    // Blink the LEDs on for both Piezos
    { digitalWrite(LEDPin2, HIGH);
      // Delay so that you can see the LEDs go On.
      delay(10);
      // Turn the LEDs Off
      digitalWrite(LEDPin2, LOW);
      // Increase this Delay if you want to see an actual blinking effect.
      delay(10);
    }
    { digitalWrite(LEDPin3, HIGH);
      delay(10);
      digitalWrite(LEDPin3, LOW);
      delay(10);
    }
    { digitalWrite(LEDPin4, HIGH);
      delay(10);
      digitalWrite(LEDPin4, LOW);
      delay(10);
    }
    { digitalWrite(LEDPin5, HIGH);
      delay(10);
      digitalWrite(LEDPin5, LOW);
      delay(10);
    }
    { digitalWrite(LEDPin6, HIGH);
      delay(10);
      digitalWrite(LEDPin6, LOW);
      delay(10);
    }
    { digitalWrite(LEDPin7, HIGH);
      delay(10);
      digitalWrite(LEDPin7, LOW);
      delay(10);
    }
    { digitalWrite(LEDPin8, HIGH);
      delay(10);
      digitalWrite(LEDPin8, LOW);
      delay(10);
    }
    { digitalWrite(LEDPin9, HIGH);
      delay(10);
      digitalWrite(LEDPin9, LOW);
      delay(10);
    }
    { digitalWrite(LEDPin10, HIGH);
      delay(10);
      digitalWrite(LEDPin10, LOW);
      delay(10);
    }
    { digitalWrite(LEDPin11, HIGH);
      delay(10);
      digitalWrite(LEDPin11, LOW);
      delay(10);
    }
    { digitalWrite(LEDPin10, HIGH);
      delay(10);
      digitalWrite(LEDPin10, LOW);
      delay(10);
    }
  }
}

Edit your question to format the code. Select all the code and hit Ctrl-K.

Well, you never call blink, so leds never get a chance to light up.
Also, you are turning down the led at the begining of each loop. That will cause flickring.
And you don't need so many parameters for blink. In fact, what you need is a little function for blinking just one led.
I think this sketch is what your are looking for (but I can't assure it's correct)
/*
  Dual Piezo Bond Auger Sensor; Blinking LED Light Stack Sketch

  -----------------------------------------------------*/

//Piezo 1 Pin (PiezoPin1)
//Piezo 1 connected to A0
int PP1 = 0;
//Piezo 1 Pin (PiezoPin1)
//Piezo 2 connected to A1
int PP2 = 1;

//Sets the threshold for the detected sound to trigger the LED
const int threshold=0.01;

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

    for(int i = 4; i<12; i++) {
        pinMode(i, OUTPUT);
        //sets the led pins 2-11 to output
    }
}

void loop()
{
    /* Read the Piezos
      Reads both piezos and outputs the values. Triggers LED lights
      to fire when a peak voltage is exceeded
      Adjust the value based on the peak signal voltage you
      want to trigger the LED lights*/
    int Piezo1ADC = analogRead(PP1); // Read Piezo 1 ADC value
    float Piezo1V = Piezo1ADC / 1023.0 * 5.0; // Convert to voltage
    int Piezo2ADC = analogRead(PP2); // Read Piezo 2 ADC value
    float Piezo2V = Piezo2ADC / 1023.0 * 5.0; // Convert to voltage
    Serial.println(Piezo1V); //Print the voltage from Piezo 1
    Serial.println(Piezo2V); //Print the voltage from Piezo 2

    if(Piezo1V >= threshold||Piezo2V >= threshold)  //toggle status of LED pins linked to PP1
        // Blink the LEDs on for both Piezos
    {
        {
            littleBlink(2);
            littleBlink(3);
            littleBlink(4);
            littleBlink(5);
            littleBlink(6);
            littleBlink(7);
            littleBlink(8);
            littleBlink(9);
            littleBlink(10);
            littleBlink(11);
        }
    }
}

void littleBlink(int pin)
{
    digitalWrite(pin, HIGH);
    delay(10);
    digitalWrite(pin, LOW);
    delay(10);

}

Use a for loop for the littleBlink calls, e.g. for (int n = 2; n  < 12; n++) { littleBlink(n); }

@Michel. I know, but I'm not sure about what pins he is using and a for will confuse him. Keep things simple, one small step at time.

yes, that's also true


text:
Multiple SPIs on one Arduino [SOLVED]
Setup

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

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

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

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

uint32_t counter = 0;

static const int PAYLOAD_SIZE = 16;

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

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

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

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

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

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

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

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

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

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

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

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

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

uint32_t prevResponse = -1;
uint32_t response;

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

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

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

  // Receive.
  byte pipeNo = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


text:
Mega + SIM808 GPRS GSM GPS IPX-SMA module power on from code
Is it possible to turn on the SIM808 module from code? There is a button in the SIM808 board to activate the module, but I need to turn it on from the code automatically. This is because my device will be stored hidden inside a vehicle so I do not have to keep turn on and off by hand.
This is the model.

Looking at the pictures it looks like it should be possible to take the two exposed connections of the switch and add flying leads to them and run them back to the microprocessor to allow it to turn them on and off.  The possible problem is the current that has to run through the switch.
You will need to investigate, but it looks like it could be done like that if you can't find a better solution.

Actually that switch should just be turned on. The problem is with the power button, I need to hold it for about 2 seconds and then release it to fully activate the module functions. That is the problem.

Sorry I said switch but I meant the button near where it says "Press this to Start"


text:
How to add this old BASIC code snippet to work in Arduino C++ for FastLED?
I've been trying to implement this old code that randomly transitions to RGB color into my Arduino board that uses FastLED.
Static Col1, Col2, Col3 As Integer
Static C1, C2, C3 As Integer
If (Col1 = 0 Or Col1 = 250) And (Col2 = 0 Or Col2 = 250) And (Col3 = 0 Or Col3 = 250) Then
  C1 = Int(Rnd * 3)
  C2 = Int(Rnd * 3)
  C3 = Int(Rnd * 3)
End If
If C1 = 1 And Col1 <> 0 Then Col1 = Col1 - 10
If C2 = 1 And Col2 <> 0 Then Col2 = Col2 - 10
If C3 = 1 And Col3 <> 0 Then Col3 = Col3 - 10
If C1 = 2 And Col1 <> 250 Then Col1 = Col1 + 10
If C2 = 2 And Col2 <> 250 Then Col2 = Col2 + 10
If C3 = 2 And Col3 <> 250 Then Col3 = Col3 + 10
leds[x] = RGB(Col1, Col2, Col3)

Here is my Arduino setup:
#include <FastLED.h>

#define LED_COUNT 60
#define LED_OUT       13
#define BUTTON_IN     10
#define ANALOG_INPUT  A9
#define EXTRA_PIN_A    7
#define EXTRA_PIN_B   11

struct CRGB leds[LED_COUNT];

void setup() {
  Serial.begin(57600);
  LEDS.addLeds<WS2812B, LED_OUT, GRB>(leds, LED_COUNT);
  LEDS.show();
}

void loop() {
  //where to implement
}

To be continued ... https://arduino.stackexchange.com/questions/43485/leds-randomly-smooth-transitioning-accounting-for-black-or-how-to-switch-using.

I think this should work fine:
#include <FastLED.h>

#define LED_COUNT     96
#define LED_OUT       13
#define BUTTON_IN     10
#define ANALOG_INPUT  A9
#define EXTRA_PIN_A    7
#define EXTRA_PIN_B   11

struct CRGB leds[LED_COUNT];

void setup() {
  Serial.begin(57600);
  LEDS.addLeds<WS2812B, LED_OUT, GRB>(leds, LED_COUNT);
  LEDS.show();
}

void colorLoop() {

  static int Col1;
  static int Col2;
  static int Col3;

  static int C1;
  static int C2;
  static int C3;

if ((((Col1 == 0) || (Col1 == 250)) && (((Col2 == 0) || (Col2 == 250)) && ((Col3 == 0) || (Col3 == 250))))) {

// select a random number from 1 to 2 for the array
C1 = random(1, 3);
C2 = random(1, 3);
C3 = random(1, 3);
}

if (((C1 == 1) && (Col1 != 0))) {
    Col1 = (Col1 - 10);
}
if (((C2 == 1) && (Col2 != 0))) {
    Col2 = (Col2 - 10);
}
if (((C3 == 1) && (Col3 != 0))) {
    Col3 = (Col3 - 10);
}

if (((C1 == 2) && (Col1 != 250))) {
    Col1 = (Col1 + 10);
}
if (((C2 == 2) && (Col2 != 250))) {
    Col2 = (Col2 + 10);
}
if (((C3 == 2) && (Col3 != 250))) {
    Col3 = (Col3 + 10);
}

for (uint8_t i = 0; i < LED_COUNT; i++) {
   leds[i] = CRGB(Col1, Col2, Col3);
  }
delay(100);
LEDS.show();
}

void loop() {
  colorLoop();
}

Fairly simple. Understand what the basic code is trying to do and recreate that functionality in c.
In this case, it is looking for a set of conditions to trigger the generation of three random numbers which are then combined into a code for the run array.


text:
Arduino Micro disappears on osX 10.11.6
so I have an arduino micro, and it was working fine until the latest security update for OSX 10.11.6 now the port won't show up in the arduino IDE. This doesn't seem to be a problem with the Uno / Huzzah / Mega or Makey Makey, but the port shows up when the micro is booting up, then disappears when the boot is done.
Anyone else having this issue? I've googled and found something about signed ktels. I've also installed some extra FTDI drivers, but no dice. Cord is fine, and works w/ other devices.
Suggestions?
Thanks!

Please, accept your own answer to close the question.

Found it. It was a weird timing thing, and I had to hit reset as the sketch was uploading. Seems to be fine now.


text:
Garbage when listening to serial
This is the atmega328p code that is supposed to send a predefined message repeatedly.

#include <avr/io.h>
#include <util/delay.h>

#define BAUD 9600
#define BAUD_PRESCALLER (((F_CPU / (BAUD * 16UL))) - 1)

void USART_init(void) {
    UBRR0H = (uint8_t) (BAUD_PRESCALLER >> 8);
    UBRR0L = (uint8_t) (BAUD_PRESCALLER);
    UCSR0B = (1 << RXEN0) | (1 << TXEN0);
    UCSR0C = (3 << UCSZ00);
}

void USART_send(unsigned char data) {
    while (!(UCSR0A & (1 << UDRE0)));
    UDR0 = data;
}

unsigned char USART_receive(void) {
    while (!(UCSR0A & (1 << RXC0)));
    return (unsigned char) UDR0;
}

void USART_putstring(char *StringPtr) {
    while (*StringPtr != 0x00) {
        USART_send((unsigned char) *StringPtr);
        StringPtr++;
    }
}

char String[] = "Hello world!!";

int main(void) {
    USART_init();
    while (1) {
        USART_putstring(String);
        _delay_ms(1000);
    }
    return 0;
}

If I try and listen to my serial port screen /dev/tty.wchusbserial141120 9600, only unicode nonsense comes back.
���

I am not quite sure what's the issue here.

Repeatedly send the character U non-stop and examine the TX waveform with an oscilloscope. If it's not 4800Hz you have a baud rate problem.

Might want to add the wiring. Might be missing something there.

Your program works as expected on an Uno (I would just add \r\n at the end of the message). How are you clocking your ATmega?

Do you have correct F_CPU in Makefile? Is the DIV8 fuse disabled?

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


text:
Can I connect a voltage, higher that the 1.1V bandgap voltage, to an ADC pin
Can I (attempt to) measure a voltage that is higher that the ADCs Vref, without damaging my IC?
I'm trying to measure the battery voltage using a resistive divider, and using the internal 1.1V bandgap voltage. I selected the resistors so the voltage would be around 1V when fully charged.
My project can however also be power by a wall-adapter, which exceeds the batteries voltage, resulting in a voltage higher than 1.1V at the ADC.
In the datasheet the table of ADC Characteristics seems to indicate that the maximum input voltage is Vref. Though I'm not sure if that's the maximum voltage is can convert, or if that's the maximum voltage that's allowed.
Elsewhere in the datasheet it says: Single ended channels that exceed VREF will result in codes close to 0x3FF, which seems to indicate it isn't a problem to exceed Vref (as long as it's below Vcc).
The part I'm using is an ATtiny13A, but the relevant sections of the datasheet seem identical to the ATMega328.

Yes, you can go above VRef.

Voltage on any Pin except RESET
with respect to Ground ................................-0.5V to VCC+0.5

And as the ADC reference says anything above VREF will give you the maximum value (it will saturate).
So powered from 5V you can apply anything from -0.5V to +5.5V safely. That's basically the supply voltage plus one diode drop for the ESD protection diodes within the pin.
The ADC is just comparing two voltages. The VREF isn't used to power anything.


text:
Controlling an analog potentiometer using an Arduino
I want to be able to control an analog potentiometer. I'd like to be able to go from the minimum range to the maximum range possibly using an Arduino and a motor/servo. I want to be able to control vintage equipment, so the knobs on the pot must still work. I want to be able to rotate both by hand and by sending  a (MIDI) signal.How would I go about doing this?

Hello and welcome to Arduino StackExchange! Just a small question, why not just use a digital potentiometer?

I want to be able to control  vintage equipment, so the knobs on the pot must still work. I want to be able to rotate both by hand and by sending  a (MIDI) signal.

I think what you are looking for is a motorized fader.

Can you replace the original potentiometer? Can you drill holes for attaching a servo?

Ideally I'd like to use the original pot and have the servo/whatever the solution is inside the case so that you can't tell a mod was made.

Add a pulley wheel to the shaft of the pot and drive it with a DC motor and a rubber belt? Like a belt drive from an old tape deck. You may be able to fit it on the inside of the housing.

Like this but with the gubbins on the inside of the case, not the outside.

That works, but I would need it on multiple pots and on the inside. Maybe I'm looking for motorized potentiometers?

The first problem we have is that replacing the original potentiometer might be wrong thing to do. Analog audio hardware is usually nonlinear, because the volume of the sound is actually a logarithmic function. So the potentiometers might be fine tuned specifically for particular device, and impossible to acquire today since it's vintage.
I suggest a different approach. Connect the knobs to rotary encoders, or cheap linear potentiometers. That way you will receive data about what the user is doing, and what setting does he want to change. They usually are small and you might even fit an extra el-cheapo 28BYJ485V stepper motor to move the knobs to provide feedback. (It can be modified doubling it's torque)
Move all the audio potentiometers inside the case of the device and connect them directly to a stepper motor or a servo to move them only with Arduino.


text:
How can I work with two devices that use the SPI protocol?
I'm working with a project in which I need to use an SD card module and an RFID antenna simultaneously. The devices that I'm using are the MFRC522 and the CATALEX SD Card Adapter. Both have SPI Protocol, and they're using the libraries MFRC522.h and SD.h.
This is the pin layout that I'm using:
/////// For RFID //////////
             Arduino
             Mega
  Signal     Pin
  ---------------------
  RST/Reset  5
  SPI SS     53 (CUSTOM)
  SPI MOSI   51
  SPI MISO   50
  SPI SCK    52

//////// For SD ///////////
             Arduino
             Mega
  Signal     Pin
  ----------------------
  SPI SS     49 (CUSTOM)
  SPI MOSI   51
  SPI MISO   50
  SPI SCK    52

As you can see the only line that they are not sharing is the Slave Select (aside from the RST pin of the RC522 module), so I believe that my wiring is correct.
I tried setting in LOW the chip select of the device that I wanted to use and in HIGH the one that I didn't. But this didn't work.
Any help you could provide would be appreciated! Thanks!

If that SD card adapter looks similar like the picture, I never could get it to work together with another SPI device.
What I used was a data logger shield for Arduino (with SD card slot and proto part, unused in my case), something like this: SD logger

That's the exact same SD adapter that I have. What I did was connecting the Vcc of the SD adapter to an specific pin, and whenever I want to use it I have to set a HIGH signal on it, and whenever I want to use the RFID reader I have to set a LOW signal. The only issue is that it might be dangerous for the device (SD adapter). I'm right?

I think you mean the Chip Select or Slave select to switch LOW when you want to use it. But maybe it helps if you add your sketch and scheme. The adapter contains a voltage regulator for 5->3.3V so that should cause not cause any harm. Switching Vcc too often might do, but I think you mean the CS or SS pin.

No, I did mean Vcc. Actually I'm powering the SD card with a digital pin that I switch when I want to use it.

Ok ... to preserve power? There might be better ways for that possibly. I don't know happens if you write, the function returns, while writing is not finished and you switch off the power. Check the power consumption when not in use, or otherwise check if it has a sleep mode. Or wait long enough to be sure there is no write active.l

I have a few of those in my parts box and I have left a little note with them that says "exlusive SPI" to remind myself. A search brings up this which seems to confirm it. The OP's solution of powering it on and off with a pin seems pretty smart to me - assuming it doesn't draw too much current from the output pin.
Update: I found this which suggests that powering the SD card adapter from an output pin is a bad idea. The card could be drawing more than the pins can reliably supply.


text:
LEDs on Arduino WiFi Shield
I would like to know the purpose of the LEDs on top of the Arduino WiFi Shield: L9/Link/Error/Data (left in the picture). What do they indicate?

The web page on the Arduino site for the board tells you in plain words what they mean:

On board indicators The shield contains a number of informational LEDs:

L9 (yellow) : this is tied to digital pin 9
LINK (green) : indicates a connection to a network
ERROR (red) : indicates when there is a communication error
DATA (blue) : indicates data being transmitted/received


text:
Function for converting milliseconds to minutes?
I'm playing around with a Neopixel strip and want to be able to enter the amount of minutes I want an LED to do something rather than in milli seconds. So for example,
void loop() {

colorWipe(strip.Color(0, 0, 255), 50);
delay(sConversion(5));

colorWipe(strip.Color(0, 0, 0), 50);
delay(sConversion(5));

In my mind this should then delay the code by 5 minutes instead of doing
void loop() {
colorWipe(strip.Color(0, 0, 255), 50);

delay(300000);

The function I wrote is
sConversion(int minutes) {
    int milli = minutes * 60000;

    return milli
};

When I write this same function in JS it returns the correct value, 300000. But when I run it in the Arduino IDE the blue light never changes.
I have this function outside my void loop() and void setup(). Is that the correct place to put it? I have no errors returned.
Full code sample
void setup() {

strip.begin();
strip.show();

}

int sConversion(int minutes) {
    int milli = minutes * 60000;

return milli;
}

void loop() {

colorWipe(strip.Color(0, 0, 255), 50); // Blue
delay(sConversion(1));

colorWipe(strip.Color(102, 204, 0), 50); // Green
delay(300000);
}

void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
    };
};

Is this the reason?

No other reading of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect, it brings most other activity to a halt.

https://www.arduino.cc/en/Reference/Delay

Your sConversion returns an int as argument. You need to declare it as unsigned long.
This is what you are lookin for:
unsigned long conv(int x) {
  return x * 600000L;
}

Perhaps this is backwards. The question was about converting minutes (int) into milliseconds (unsigned). You should put the long as the return type, and keep the int as the parameter type. Also, multiply by 60000, rather than divide. Another commonly accepted type, that is platform neutral is uint16_t, which is an unsigned 16-bit integer. This bypasses the ambiguity of "long", which can by whatever number of bytes the compiler for that architecture decides.

@josecanuc My bad. I corrected it.

@LookAlterno This worked. I did not know about unsigned longs. New to C. Thanks!

Take a look at the numeric data types in https://www.arduino.cc/en/Reference/HomePage and see what each one can hold. Keep that limits in mind when dealing with numeric values.

Function for converting milliseconds to minutes?

1 min has 60 seconds and 1s has 1000 me.
So take the ms and divide it by 60k you will get its equivalent min.

While you are rigth, using a function avoids stupid mistakes like writing an extra '0' (or missing one '0'). In a large program, where you have to do that conversion in many places, that is a likely error to occurs, and a nightmare to debug.

int sConversion(int minutes) {
    int milli = minutes * 60000;

return milli;
}

If minutes is greater than 1, you will overflow the int and not get the right answer.  Use unsigned long here instead.
unsigned long sConversion(int minutes) {
    unsigned long milli = minutes * 60000ul;

return milli;
}


text:
Can anyone identify these headers?
I'm very new to the Arduino platform and micro-controller projects in general, which is why I'm still learning about all the parts needed for circuit creation. There is one particular part that I would need for my current project but I'm having troubles figuring out what exactly this "thing" is ...
Please take a look at this picture: https://i2.wp.com/makezine.com/wp-content/uploads/2015/08/rolljam-hardware.jpg?fit=929%2C724
I need to know, please, what exactly these dual row female headers are called that are placed right to the Teensy board and are holding the two CC1101 units (so I can find them on Amazon or in other shops).
Obviously, they are spanning the gap on the breadboard but is there something you can buy like this? Or are these common dual row headers that have had their pins bent and put into single row headers?
I can't quite tell. The whole thing looks custom made though (to me it even looks like some hot glue was used, but I might be entirely wrong about that).
^^ And if my assumption is right, what might be the purpose of doing this? From my understanding this would create a full row for the power (instead of having two shorter rows), which the gap on the breadboard is meant to prevent?!
Thank you for suggestions.

https://www.creatroninc.com/category/idc-ribbon-breakout-board/prototyping/breadboard-adapter

Thank you very much! Now I know that you can buy these things (but I still can't shake the feeling that the ones on the picture are custom made). I would still like to know, please, what might be the purpose of bridging the gap with one of these? Why not just use common dual row headers on one half of the breadboard?

All the rows on one side of the breadboard are tied together. Without such an adapter you can't access each pin individually.

Yes, my mistake. You are right. Please see my previous comment to the answer below. Thank you.

Btw: There is another slightly different version of this device that makes it more clear what you mean --> http://www.popsci.com/sites/popsci.com/files/styles/large_1x_/public/_rolljam2-web.jpg?itok=9pmUGcrd If there's just one row of pins like on the two RF433 modules, you can put either one on one half of the breadboard.

From the pic, it looks like a 2x16 female header, PCB mount, with the pins bent outward and soldered to some male header pins.
I think they do this to provide mating sockets for the 2x5 male pins on the CC11001s that can be hooked up to a breadboard.
You could avoid this by prototyping on something like "stripboard' or 'Veroboard' like https://www.amazon.com/Soldering-Prototype-Printed-Circuit-Stripboard/dp/B019Q14GRQ/ and cutting/soldering a few traces where appropriate.
Or you could use a small chunk of stripboard tor protoboard to do the adapting from the 2x5 at 0.1" centers, to 2x5 on 0.1"x0.4" centers.

Yes, these headers are there so all the pins of the CC1101 units can be connected to the breadboard. The one thing I'm curious about is: why do it exactly this way? Why bridge the gap? Why not just use common dual row headers on one half of the breadboard? Since the creator of the device on the picture obviously put in some effort to create these custom made "bridge", I can only assume that there must be some purpose behind it. That's what I need to find out next. But you guys already answered my initial question. Thank you for that!

Edit: Just saw Ignacio's comment above. That seems to be the right answer. I understand now why this "bridge" was necessary for the CC1101s.

Ah, it seems that you are missing the fact that each set of 5 holes on one half of the breadboard are shorted together with a metal clip.  If you do as you say, you will short the C1101's pin 1 to pin 2, pin 3 to pin 4, etc....  You need to bridge the gap to break those connections.


text:
How to know physical address of XBee?
I have a system with a server (a personal computer with an XBee Dongle plugged in, running a Java program) and some Boe-Bots with XBees attached and Arduino programs. I know how to get the Boe-Bots to send a message to the server. I want the server to obtain the Boe-Bot's XBee's physical address so that it can send a message to that particular Boe-Bot with the Java method
com.digi.xbee.api.XBeeDevice.sendData(RemoteXBeeDevice remoteXBeeDevice, byte[] data)
knowing what argument to put for remoteXBeeDevice.
I can think of two ways this might be possible.
1) There might be a method in the Arduino XBee library to obtain an XBee's physical address. Then the Boe-Bot can get its own address and send it in a message to the server. I have not found such a method.
2) On the server side, there might be a method in the Java XBee library that allows it to automatically determine the physical address of a client that is communicating with the server. I thought that XBeeMessage.getDevice() was such a method, but it returned a RemoteXBeeDevice with an XBee64BitAddress of FFFFFF... which is not the proper address of the Boe-Bot's XBees.
Does anyone know the correct Arduino method for option 1 or the correct Java method for option 2?
Edit: XBee S1

What XBees are you using?

XBee S1 for both the server and robots.

First you can check the signal received from the xbee connected with the server by using coolterm or arduino serial monitor. This is to ensure there are connections between the two xbees.
Then, you will receive some funny characters which is normal, you need to change these characters into hexadecimal form which is more preferable to use coolterm as it has the ability to do so.
Laslty, the characters received will be about 21 characters long. It starts with 7E as a starting character. That is what I received when using XBee S2. These characters then can be translated into other form.
I would suggest a book entitled Wireless Sensor Network by Robert Faludi to understand more.

I am looking for a method where I could just load the Arduino code onto the robots and start the server and it would work. I don't want to find the address of each robot manually. Is such a thing possible?

It would be possible if there is the exact code that apply the same thing. However, there is high chances that there is not. You need to configure every pins that changes when a signal is sent. You need to understand the configuration and then apply it in your code.


text:
Which is RX and TX pin of the HM-10 module?
i recently bought hm-10 ble module which works using cc2541 ti SOC but problem is there are many ports the the bluetooth module but the seller has not mentioned which is rx and tx pins so...
I wanted to connnect it with Arduino uno and use AT commands but now i am stuck can anyone in this community help me finding which pin is Tx and Rx and the data sheet of the module is difficult to find on the net .....

http://www.electrodragon.com/w/EY-08 might help

Seems like the link is broken. Here is another https://github.com/nickswalker/ble-dev-kit/wiki/HM-10-Pinout

That's not an HM-10 but an EY-08. It's the same chip, but it's been provided in a different footprint (and maybe with different firmware installed).
Pin P03 is TX and pin P02 is RX.
The AT command set, pinouts, and examples for wiring it are detailed here (Thanks to Mikael Patel for finding that link).


text:
Accessing a C++ static variable from gcc inline asm
For some reason I want to mix a bit of assembly with C++ (not C).
To allow the code to be compilable using the standard Arduino IDE, I don't want to use direct assembly source.
I don't want to use a wrapper C file either.
My problem is as follows:
I have a class with a single instance (implementing some kind of driver) that looks like this:
class cDriver {
public:
    char ISR_param;
    // ...
};

cDriver Driver;

If I want to access the ISR_param of this single instance from within an ISR, I can do something like:
ISR (TIMER2_COMPA_Vect) {
    do_something_with (Driver.ISR_param);
}

This works like a charm: the address of Driver.ISR_param beign a constant, the compiler simply generates an lds r24, &Driver.ISR_param instruction to load the proper byte as a parameter for do_something_with.
Now when I try to replicate the same mechanism with inline assembler, things get a lot more complicated.
The address of Driver.ISR_param is only known to the C++ compiler as an mangled label, and I can't find a way to pass it to the inline assembler to generate the equivalent lds r24, <&Driver.ISR_param>.
trying to remane the variable
The renaming of variables for assembly like so:
char global_var asm("my_var");

and an attempt to use it like so:
asm ("lds r24, my_var\n");

will compile, but produce a linker error (my_var is undefined).
Looking at the object symbol table, the only label for global_var is a C++-like mangled name.
However hard I tried this renaming trick, I could not bring the compiler to generate a my_var label.
trying to use asm constraints
A constraint like
asm (lds r24, %0\n" : : "I"(&global_var));

will simply not compile. I scoured the possible parameter types and could not find a way to let the assembler know about this bloody address.
a terribly awkward workaround
The only way I found to make the compiler generate this dreaded lds r24,... instruction is to perform an actual function call.
So you can do something like:
__attribute__((always_inline)) give_me_my_friggin_variable(char data)
{
    asm volatile ("cmp  %0,%0\n"::"r"(data));
}

ISR (TIMER2_COMPA_Vect, ISR_NAKED) {

    <some prologue to save SREG and all needed registers>

    //...

    give_me_my_friggin_variable(Driver.ISR_param);

    // continue assembly code with r24 properly initialized
}

That will generate:
    lds r24, <the proper address> // added by the compiler...
    cmp r24,r24                   // ...because of the register constraint here

Well, that sort of works, but at the cost of generating a totally useless instruction.
so my question is...
Is there a simpler way to let the assembler know about addresses of C++ static variables?

Try this:
asm volatile("lds r24, %0" : : "i" (&Driver.ISR_param));

The "i" constraint means you provide an integer constant. It can be
any integer, unlike the uppercase "I" constraint which is limited to
6-bit positive integers.
Addendum:
The constraints supported by gcc are listed in the gcc documentation,
section Constraints for asm Operands:

The "i" constraint is listed in the subsection “Simple Constraints”
and is described as:

An immediate integer operand (one with constant value) is allowed.
  This includes symbolic constants whose values will be known only at
  assembly time or later.

The "I" constraint is in the subsection “Machine Constraints” and,
for the AVR architecture, is defined as

Constant greater than -1, less than 64.

Dang... And thanks :). This "i" type was not listed in the online manuals I found. For completeness, could you add a link to an up to date documentation? Btw. I wonder why an example of such an obvious use of the inline assembler is so hard to come by.

@kuroineko: The "i" constraint is indeed missing from the avr-libc's Inline Assembler Cookbook. I added a link to the gcc documentation that lists it.

Thanks a lot. That sort of cooking is pretty confidential I guess :).

The "i" constraint does not mean "integer". "i" specifies an immediate operand, which is the union of "n" (integral operand known at compile-time) and "s" symbolic operand known at link time. For example, addresses of variables in static storage are known at link time, thus "i" will work for them.


text:
LEDs Randomly smooth transitioning, accounting for black or how-to switch using HSV
I am stuck trying to get it not to account for black in RGB.  My first instinct was to use the HSV color spectrum over the RGB rainbow but, the same code will behaves differently in HSV.  If i could get the same effect in HSV I would, and that would account for the black, but I have not found a solution for that or the accounting for black in RGB.  Here is my code:
#include <FastLED.h>

#define LED_COUNT     96
#define LED_OUT       13
#define BUTTON_IN     10
#define ANALOG_INPUT  A9
#define EXTRA_PIN_A    7
#define EXTRA_PIN_B   11

struct CRGB leds[LED_COUNT];

void setup() {
  Serial.begin(57600);
  LEDS.addLeds<WS2812B, LED_OUT, GRB>(leds, LED_COUNT);
  LEDS.show();
}

void colorLoop() {

  static int Col1;
  static int Col2;
  static int Col3;

  static int C1;
  static int C2;
  static int C3;

  if ((((Col1 == 0) || (Col1 == 250)) && (((Col2 == 0) || (Col2 == 250)) && ((Col3 == 0) || (Col3 == 250))))) {

    // select a random number from 1 to 2 for the array
    C1 = random(1, 3);
    C2 = random(1, 3);
    C3 = random(1, 3);
  }

  if (((C1 == 1) && (Col1 != 0))) {
    Col1 = (Col1 - 10);
  }
  if (((C2 == 1) && (Col2 != 0))) {
    Col2 = (Col2 - 10);
  }
  if (((C3 == 1) && (Col3 != 0))) {
    Col3 = (Col3 - 10);
  }

  if (((C1 == 2) && (Col1 != 250))) {
    Col1 = (Col1 + 10);
  }
  if (((C2 == 2) && (Col2 != 250))) {
    Col2 = (Col2 + 10);
  }
  if (((C3 == 2) && (Col3 != 250))) {
    Col3 = (Col3 + 10);
  }

  for (uint8_t i = 0; i < LED_COUNT; i++) {
    leds[i] = CRGB(Col1, Col2, Col3);
  }
  delay(100);
  LEDS.show();
}

void loop() {
  colorLoop();
}

Does your definition of black refers to all the LEDs off?

yes, RGB(0, 0, 0) displays the same as the option "off".

Black will basically be when all the colours have reduced to 0. That can only happen when all three of C1, C2 and C3 are 1. So you basically need to ensure that never happens.
And that is simple enough to arrange, with a "try again" construct:
if ((((Col1 == 0) || (Col1 == 250)) && (((Col2 == 0) || (Col2 == 250)) && ((Col3 == 0) || (Col3 == 250))))) {

    // select a random number from 1 to 2 for the C1,C2,C3 array
    do {
        C1 = random(1, 3);
        C2 = random(1, 3);
        C3 = random(1, 3);
    } while ((C1 == 1) && (C2 == 1) && (C3 == 1));
}

Pick three numbers. If they are all 1 then you are destined towards black. So go back and pick three new random numbers. Keep trying until you get at least one result that isn't 1.

nice approach @Majenko but, that would simply take away from the functionality.

How so? It gives you the same range of random numbers for the three values except it rules out getting 1,1,1 which would fade all the channels to black. It would give you 1,1,2 1,2,1 1,2,2 ... 2,2,2 but never 1,1,1

For it not to be black, at least one color (R,G,B) have to be on.
Before assigning the color values to the LED, maybe you can try using the constrain function to keep the values within a range. For example,
...

Col1 = constrain(Col1, 50, 150);  //If anything falls below 50, set it to the minimum value (50)
Col2 = constrain(Col2, 50, 150);
Col3 = constrain(Col3, 50, 150);

for (uint8_t i = 0; i < LED_COUNT; i++) {
   leds[i] = CRGB(Col1, Col2, Col3);
}

....

Sure enough! adding the constrain function to one of the static integers fixed the RGB from going to black. Now simply set 50 as the min value in the rest of the code:
void colorLoop() {
    //Set the minimum value to 50
    static int Col1 = constrain(Col1, 50, 255);
    static int Col2;
    static int Col3;

    static int C1;
    static int C2;
    static int C3;

    if ((((Col1 == 50) || (Col1 == 250)) && (((Col2 == 0) || (Col2 == 250)) && ((Col3 == 0) || (Col3 == 250))))) {

        // select a random number from 1 to 2 for the C1,C2,C3 array
        C1 = random(1, 3);
        C2 = random(1, 3);
        C3 = random(1, 3);
    }

    if (((C1 == 1) && (Col1 != 50))) {
        Col1 = (Col1 - 10);
    }
    if (((C2 == 1) && (Col2 != 0))) {
        Col2 = (Col2 - 10);
    }
    if (((C3 == 1) && (Col3 != 0))) {
        Col3 = (Col3 - 10);
    }
    if (((C1 == 2) && (Col1 != 250))) {
        Col1 = (Col1 + 10);
    }
    if (((C2 == 2) && (Col2 != 250))) {
        Col2 = (Col2 + 10);
    }
    if (((C3 == 2) && (Col3 != 250))) {
        Col3 = (Col3 + 10);
    }

    for (uint8_t i = 0; i < LED_COUNT; i++) {
        leds[i] = CRGB(Col1, Col2, Col3);
    }
    delay(100);
    LEDS.show();
}

great approach @Photon! however, using the constrain eliminates a lot of color possibilities.

I found this approach works:
if (((Col1 <= 50) && ((Col2 <= 50) && (Col3 <= 50)))) {  //avoid black
   C1 = 2;
   C2 = 2;
   C3 = 2;
}