text:
when i compile this code it always 'sendCommand' was not declare in this scope..plzz help
#include <SoftwareSerial.h>
#define DEBUG true

SoftwareSerial esp8266(10, 11); // RX, TX

void setup() { // Open serial communications and wait for port to open:
  Serial.begin(9600); //for monitoring purposes

  sendCommand("AT+CIFS+RST\r\n", 2000, DEBUG); // reset module
  sendCommand("AT+IPR=115200\r\n", 1000, DEBUG);
  sendCommand("AT+CWMODE=1\r\n", 1000, DEBUG); // configure as access point
  sendCommand("AT+CWJAP=\"ABCDEFG\",\"12345678\"\r\n", 3000, DEBUG); //connect to a network with name ABCDEFG with password 12345678
  delay(1000);
  sendCommand("AT+CIFSR\r\n", 1000, DEBUG); // get ip address
  sendCommand("AT+CIPSTA=\"192.168.43.16\"\r\n", 1000, DEBUG);
  sendCommand("AT+CIPMUX=1\r\n", 1000, DEBUG); // configure for multiple connections
  sendCommand("AT+CIPSERVER=1,6625\r\n", 1000, DEBUG); // turn on server on port 6625
  Serial.println("Server Ready");

}

void loop() { // run over and over
  if (esp8266.available()) {
    if (esp8266.find("+IPD,0,")) {
      delay(10);
      esp8266.find(":");
      delay(10);
      char letter = esp8266.read();
      Serial.print(letter); //for monitoring purposes
      //Gets the value/char from android app
    }

String sendCommand(String command, const int timeout, boolean debug) {
  String response = "";
  esp8266.print(command); // send the read character to the esp8266
  long int time = millis();
  while ((time + timeout) > millis()) {
    while (esp8266.available()) {
      // The esp has data so display its output to the serial window
      char c = esp8266.read(); // read the next character.
      response += c;
    }
  }

  if (debug) {
    Serial.print(response);
  }
  return response;
}

I formatted your code and now you can see two } missing to close the loop. (and misplaced comment). and I added char before letter

sir..i add change the code but still, i cant compile it, it still says 'sendCommand' was not declared in this scope..

Then edit your question to reflect the new code, so that we can help you

You did notice that you declared and defined SendCommand() inside loop(), right?

sir sorry for being slow..
what loop() do you mean sir?

there is only one loop()

In loop you have three opening braces and one closing brace. This won't end well:
void loop() { // run over and over
  if (esp8266.available()) {
    if (esp8266.find("+IPD,0,")) {
      delay(10);
      esp8266.find(":");
      delay(10);
      char letter = esp8266.read();
      Serial.print(letter); //for monitoring purposes
      //Gets the value/char from android app
    }

Two more closing braces would fix it.

tnx sir..i can upload it now..
sory again sir...can i ask again sir..
i can upload it now but when use at command in serial monitor, no words is going out,,


text:
making a LCD dice for catan
when I go to upload the code, I get
 Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\taran\Documents\Arduino\dice in progress\dice in progress1\diceinprogress\diceinprogress.ino:1:25: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.10.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/"DFRkeypad.h": Invalid argument
#include <"DFRkeypad.h">
                     ^
compilation terminated.
exit status 1 Error compiling for board Arduino/Genuino Uno.

and the code is
#include <"DFRkeypad.h">
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const char* DFRkeypad::sKEY[]=                          { "---",       "Right",   "Up", "Down", "Left", "Select", "???" };
const int DFRkeypad::iARV_VALUES[DFRkeypad::eNUM_KEYS]= { 1023,        0,         143,  328,    504,     740,      -1   };
int btnSELECT;

void setup() {
  lcd.begin(16, 2);
  lcd.setCursor(1, 0);
  lcd.print("Roll the dice!");
}

void loop() {
while (btnSELECT == 0){

  delay (50);
  buttonState = analogRead(btnSELECT);
}

 case btnSELECT:
     {
     lcd.print("Rolling dice");
       diceOne = random(1, 7);
       diceTwo = random(1, 7);
     break;
    }
}

Why have quotation marks around the first library you include and not the second (I believe you shouldn't have quotation marks). That's why it gives "invalid argument "DFRkeypad". Also make sure the library is properly installed and use some proven (library examples or off-the-web) testcode before slapping some code together.

You edit the question to ask a completely different questions. Different questions should be posted as different questions, otherwise the answers do not reflect the answer to the question anymore.

In C/C++ you either use the #include pre-processor statement in the form of
#include "someFile.h"

or
#include <someFile.h>

The form
#include <"someFile.h">

is not legal. You must correct it to one of the two forms above.
The difference between those forms is explained in https://stackoverflow.com/a/77092/5296568.

source: Stack Exchange

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

sort: votes


text:
i uploaded the code but when i open the serial monitor, but the 'sendCommand' isn't working in serial monitor...plzz help
#include <SoftwareSerial.h>
#define DEBUG true

SoftwareSerial esp8266(2, 3); // RX, TX

void setup() { // Open serial communications and wait for port to open:
Serial.begin(9600); //for monitoring purposes
esp8266.begin(9600);

  sendCommand("AT+CIFS+RST\r\n", 2000, DEBUG); // reset module
  sendCommand("AT+IPR=115200\r\n", 1000, DEBUG);
  sendCommand("AT+CWMODE=1\r\n", 1000, DEBUG); // configure as access point
  sendCommand("AT+CWJAP=\"ABCDEFG\",\"12345678\"\r\n", 3000, DEBUG);//connect to a network with name ABCDEFG with password 12345678
  delay(1000);
  sendCommand("AT+CIFSR\r\n", 1000, DEBUG); // get ip address
  sendCommand("AT+CIPSTA=\"192.168.43.16\"\r\n", 1000, DEBUG);
  sendCommand("AT+CIPMUX=1\r\n", 1000, DEBUG); // configure for multiple connections
  sendCommand("AT+CIPSERVER=1,6625\r\n", 1000, DEBUG); // turn on server on port 6625
  Serial.println("Server Ready");

  }

  void loop() { // run over and over
  if (esp8266.available()) {
  if (esp8266.find("+IPD,0,")) {
  delay(10);
  esp8266.find(":");
  delay(10);
  char letter = esp8266.read();
  Serial.print(letter); //for monitoring purposes
  //Gets the value/char from android app
   }
  }}

  String sendCommand(String command, const int timeout, boolean debug) {
  String response = "";
  esp8266.print(command); // send the read character to the esp8266
  long int time = millis();
  while ((time + timeout) > millis()) {
  while (esp8266.available()) {
  // The esp has data so display its output to the serial window
  char c = esp8266.read(); // read the next character.
  response += c;
  }
  }

  if (debug) {
   Serial.print(response);
  }
  return response;
  }

This isn't a "dump your code and make a statement" site. What is your question? This looks amazingly similar to your code at https://arduino.stackexchange.com/questions/52285/when-i-compile-this-code-it-always-sendcommand-was-not-declare-in-this-scope

sory sir..thats also my post...
that time...it already solve...
sory sir..

Questions like these are fine and well-answerable when they include a problem description, the expected behaviour, the actual behavior and the things you've tried, as it is highlighted in the How-To-Ask page (https://arduino.stackexchange.com/help/how-to-ask). But in this state no one can answer your question. If you solved it yourself you can also answer it yourself and accept it.

I don't know where you found (or how you came up with) this bit of code:
long int time = millis();
while ((time + timeout) > millis()) {
    while (esp8266.available()) {
        // The esp has data so display its output to the serial window
        char c = esp8266.read(); // read the next character.
        response += c;
    }
}

But it's horrible.
Not only is your time calculation completely wrong and will suffer a nasty death when millis() rollover occurs, but the whole concept of what you are doing there is bad.
The ESP8266 (assuming it's working, which hasn't been confirmed) sends a response that is terminated by a line-feed ("\n") character.  You are ignoring that and just reading for a pre-defined amount of time (badly).
Instead you should be reading up until you get that "\n" character, or breaking if your timeout has been exceeded.
For instance:
String sendCommand(String command, const int timeout, boolean debug) {
    String response = ""; // ugh... strings... yuck
    esp8266.println(command);
    uint32_t ts = millis();
    while (millis() - ts < timeout) {
        if (esp8266.available()) {
            char c = esp8266.read();
            if (c == '\n') {
                #ifdef DEBUG
                    Serial.println(response);
                #endif
                return response;
            } else {
                response += c;
            }
        }
    }
    return String("timeout");
}

Better that that though is to ditch those nasty String objects. Instead pass a char* buffer to collect the response in:
int sendCommand(const char *command, uint32_t timeout, char *response, uint32_t rlen) {
    esp8266.println(command);
    response[0] = 0;
    uint32_t rpos = 0;
    uint32_t ts = millis();
    while (millis() - ts < timeout) {
        if (esp8266.available()) {
            char c = esp8266.read();
            if (c == '\n') {
                if (debug) Serial.println(response);
                return rpos;
            } else {
                if (rpos < rlen - 2) {
                    response[rpos++] = c;
                    response[rpos] = 0;
                }
            }
        }
    }
    return -1;
}

Then you use that like this:
char response[80];

if (sendCommand("AT+CIFS+RST", 1000, response, 80) == -1) {
    Serial.println("CIFS Timed out!");
}
if (sendCommand("AT+IPR=115200", 1000, response, 80) == -1) {
    Serial.println("IPR Timed out!");
}

And so on.
By the way - that AT+IPR=115200 is a bit of a stupid thing to do. You create a software serial port at 9600 baud (fine), then almost immediately instruct the ESP8266 to switch to 115200 baud instead. You don't then start communicating at 115200 baud, but stay at 9600 baud, so communication can never continue from that point on.  Not only that, but SoftwareSerial is highly unstable at 115200 baud and is not recommended. Stick to 9600 baud.

thank you sir for the response sir..
i tried this change but the response is
= cannot convert 'bool' to 'char*' for argument '3' to 'int sendCommand(const char*, uint32_t, char*, uint32_t)'
i dont know why sir..

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


text:
Multiple node network communication over I²C
I am working on a project where I want to send data from and to different Arduinos on a network. At the moment I²C seems the best option for my needs since I can specify where to send the data. But using this method I have a bit of an issue I can't seem to find a solution for :(.
I will try to explain my problem using the following image:

In the backend all the nodes are connected like in the first image (above the example network). But the nodes may be connected in a different sequence by a user. See the example network.
In this example network, the node with ID 1 needs to send data to ID 10 and not to any other node on the network. Node ID 12 also needs to send data to node ID 10, but no other nodes. Etc. Etc. Etc. But the node that needs to send data to the next node doesn't know the id of the node it needs to send to.
So at first the nodes need to find out what nodes they are connected to and where they need to send their data.
I thought of doing this by connecting a wire between each node (blue wire in possible solution) and when a node gets added to the network the nodes send a high signal over the blue wire and sends its ID to all nodes on the network and then all nodes on the network check if they receive a high signal and an ID.
If this is true they will send its id to the node that has been added. This works fine if you add a node one by one to the network. But it fails when you replace a node in the middle of the network or disconnect power from the network.
What would be the best way to do this (I am also open to use different data transfer protocols)?

Do nodes really need to know which node is next door?

i think yeah because I2c requires an adres where it needs to transmit its data to. (and the node must only send its data to the node that is physically next) But if you think it is not necessary let me know

What purpose does the concept of "next door" achieve?

it makes sure the data goes through the network in chronological order

What do you mean "through the network in chronological order"?

With I2C your master communicates with a slave. It doesn't care where on the bus that slave is.

If you look at the example network the node with ID 1 must only send its data to the node with ID 10 and not to the nodes with other ID's. It is just something i want

So you send it to node 10.

Or are you looking to avoid bus contention in a multi-master scenario?

Yes indeed but node ID 1 doesnt know that to node it needs to send to has ID 10 how do i figure that out?

But you just stated that 1 has to send to 10.

yes what you just said is the problem

Let us continue this discussion in chat.

It sounds (after discussion) like what you are after is actually a mesh of multiple peer to peer devices.  That is, lots of devices, each one has multiple dedicated communication links each directly going to another device.
If you had enough UART ports you could create individual UART links between nodes. The bets Arduinos only have a handful of those, and the UNO only one.  So that's not really practical.
You could possibly do it with SPI if you wanted to put a lot of work in to developing a decent control protocol to go along with it.  Something along the lines of BUSRQ/BUSACK signalling:
BUSRQ: Signalling line pulled HIGH by resistor. All nodes INPUT.
BUSACK: Signalling line pulled HIGH by resistor. All nodes OPEN-DRAIN & LOW.
SS: Direct 1:1 GPIO links between nodes - all pulled HIGH. All nodes INPUT.

Node 1                   Node 2                  Node X
RELEASE BUSACK
DRIVE BUSRQ (OD Low)     Sees BUSRQ fall         Sees BUSRQ fall
                         RELEASE BUSACK          (could be busy...)
                                                 RELEASE BUSACK
Sees BUSACK rise
DRIVE BUSACK
SS Node 2 LOW            Sees SS go LOW
Send SPI data            Receives SPI data
SS Node 2 INPUT          Sees SS go HIGH
RELEASE BUSRQ                                    Sees BUSRQ rise
                         Sees BUSRQ rise         Drive BUSACK
                         Drive BUSACK

Only once all nodes have released BUSACK will the requesting node be able to send any data, and once a node has released BUSACK it knows that it must never send any data.  The requesting node has basically locked the bus from other nodes accessing it.
It's not perfect, and doesn't handle multiple devices requesting the bus at the same moment, but it does prevent one device trying to send while another is actively sending.


text:
Slave Select on Analog pin for Can Bus
I have recently made a shield for an arduino mega2560 with among others sensors, a CAN interface (MCP2515 and ISO1050).
The purpose is to create a CAN network with several arduino uno and one Mega.
Until now, the network is working well on all the Uno but unfortunately not on the Mega. As I have others sensors on the SPI bus, I've kept the MOSI, MISO and SCK pins unchanged (51,50,52) and I put the SS on the Analog pin A13 (number 67 for digital), which was the nearest unused pin I had during the routing process. Before making the shield I was careful and I've check if I could use it as a SS for my purpose.
Despite my caution, it appears that I'm not able to communicate within the CAN bus.
Before going futher, I'm using the SeeedStudio library made for their shield to test the connection.
I've tried to use A13 (using an #define)and 67 for the
SPI_CS_PIN = 67;

without any success.
I've also tried to force the bus to be active with a digitalWrite at the beginning of the setup().
// demo: CAN-BUS Shield, send data
// loovee@seeed.cc

#include <mcp_can.h>
#include <SPI.h>

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 67;

MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin

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

while (CAN_OK != CAN.begin(CAN_500KBPS))              // init can bus : baudrate = 500k
{
    Serial.println("CAN BUS Shield init fail");
    Serial.println(" Init CAN BUS Shield again");
    delay(100);
}
Serial.println("CAN BUS Shield init ok!");
}

unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};

void loop()
{
// send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf
stmp[7] = stmp[7]+1;
if(stmp[7] == 100)
{
    stmp[7] = 0;
    stmp[6] = stmp[6] + 1;

    if(stmp[6] == 100)
    {
        stmp[6] = 0;
        stmp[5] = stmp[6] + 1;
    }
}

CAN.sendMsgBuf(0x00, 0, 8, stmp);
delay(100);                       // send data per 100ms
}

If you have any idea on why it's not working and a way to solve this problem, please let me know :)
Undeadguy.

Try adding pinMode(53, OUTPUT); to the start of your setup().

I've tried : no success :(
However could you explain to me what effect making this pin as an output could have on the other pin ? Is this particular pin always selected as the SS ?

That is the hardware SS pin. The ATMega's SPI peripheral uses the direction of that pin to determine the direction of the SPI port. It has to always be OUTPUT for the SPI to work as a master.


text:
Decimal numbers sent over Serial get split and sent over multiple ticks
Here is my Arduino sketch:
#include <HX711.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
HX711 hx(9, 10, 128, 0.002229);
LiquidCrystal_I2C lcd(0x27,16,2);

void setup() {

  Serial.begin(9600);
  hx.set_offset(-9635);
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  lcd.begin(16,2);

}
void loop() {
  if(digitalRead(0) == LOW){
    lcd.clear();
    lcd.setCursor(2,0);
    lcd.print("tare recieved");
    hx.tare();
  }

  double sum = 0;
  for (int i = 0; i < 10; i++) {
    sum += hx.bias_read();
    if(sum < 0) {
      sum = 0.00;
    }

  }
  sum = sum/10;
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("Weight");
  lcd.setCursor(5, 1);
  lcd.print(sum);
  lcd.print("g");
  Serial.println(sum);
  delay(10);
 }

Here is an example output as seen on the Arduino Serial Monitor:
150.34
150.39
150.40
150.37
150.38

The Problem is when the data reaches node-serialport the value is split up on multiple lines.
 comport.on("data", function (data) {
    console.log(data.toString());
 }

When i log the data... it comes back like this:
1
50.4
5
150.
49
15
0.47
150.
48
15
0.45

Is there anyway to have Arduino only send the data if it is the full value and not the split up values?

There is no such thing as "the full value". Serial works in characters. That's what serial means. It's up to you at the receiving end to combine the individual characters up into full strings.

As explained in Majenko’s comment, the serial link is not packetized: it
transmits individual bytes and nothing else. If you need to convey a
notion of “data packet”, or “full message”, you will have to devise a
way to signal the message boundaries. This is called message “framing”.
Your Arduino is sending ASCII data. In this case, the most common way to
frame messages is linewise: each message is a single line, and each line
is terminated by an “end of line” sequence. The standard end of line
sequences are CR (carriage return, i.e. 0x0d or '\r'), LF (line
feed, i.e. 0x0a or '\n'), and the pair CRLF (CR followed by LF, or
"\r\n").
Actually you are already doing that: you are using Serial.println(),
and this method automatically appends CRLF at the end of whatever it
prints. So now you just have to parse that at the other end: you put
all the incoming characters into a buffer until you see that incoming
CRLF. Then you know you have a full line, which you can report as an
entire message.
This procedure is very common and there is a standard Node.js module for
it. It once was part of the serialport module, but it seems to have
split into a separate module. It is called parser-readline, and you
would use it like this:
const Readline = require("parser-readline"),
      parser = comport.pipe(new Readline({ delimiter: "\r\n" }));

parser.on("data", data => console.log(data.toString()));

C.f. the documentation of
ReadLineParser.


text:
Error when moving stepper motor - Alexa curtain opener
I've hit a wall with my code and keep getting a Panic error like this:

Panic /Users/lewisaburrow/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_main.cpp:98 __yield
ctx: sys
  sp: 3ffff9d0 end: 3fffffb0 offset: 01b0

Please can you help shed some light on the error?
It's used to open and close curtains using Alexa by tricking it into thinking it is a Belkin WeMo device. It runs on an Adafruit Feather HUZZAH with ESP8266.
When I test the Alexa connection code it works fine. It's based on Fauxmo https://bitbucket.org/xoseperez/fauxmoesp
    And when I try the code in isolation that moves the stepper motor it works just fine.(This is with an Adafruit Featherwing Motor Controller: https://www.adafruit.com/product/2927 ). It's after the two are 'blended' together that I experience this issue...
The entire code looks like this:
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include "fauxmoESP.h"
#include "credentials.sample.h"

#define SERIAL_BAUDRATE                 115200
#define LED                             2

fauxmoESP fauxmo;

//--------------------------------------------------
// Motor

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

//-------------------------------------------------------
//--------------------------

// -----------------------------------------------------------------------------
// Wifi
// -----------------------------------------------------------------------------

void wifiSetup() {

// Set WIFI module to STA mode
WiFi.mode(WIFI_STA);

// Connect
Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);

// Wait
while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
}
Serial.println();

// Connected!
Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());

}

void setup() {

// Init serial port and clean garbage
Serial.begin(SERIAL_BAUDRATE);
Serial.println();
Serial.println();

// Wifi
wifiSetup();

// LED
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);

// You can enable or disable the library at any moment
// Disabling it will prevent the devices from being discovered and switched
fauxmo.enable(true);

// Add virtual devices
fauxmo.addDevice("bedroom curtain");
//fauxmo.addDevice("switch two"); // You can add more devices
//fauxmo.addDevice("switch three");

// -------------------------------
// Motor

AFMS.begin();  // create with the default frequency 1.6KHz
//AFMS.begin(1000);  // OR with a different frequency, say 1KHz

myMotor->setSpeed(10);  // 10 rpm

//-------------------------------------------

// fauxmoESP 2.0.0 has changed the callback signature to add the device_id,
// this way it's easier to match devices to action without having to compare strings.
fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state) {
    Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF");
    digitalWrite(LED, !state);

    if (state == HIGH) {
      Serial.print("Closing the curtain...");
    }
    else {
      Serial.print("Opening the curtain...");
      openCurtain();
    }

});

// Callback to retrieve current state (for GetBinaryState queries)
fauxmo.onGetState([](unsigned char device_id, const char * device_name) {
    return !digitalRead(LED);
});

}

void openCurtain() {
myMotor->step(100, FORWARD, SINGLE);
}

void closeCurtain() {
myMotor->step(100, BACKWARD, SINGLE);
}

void loop() {

// Since fauxmoESP 2.0 the library uses the "compatibility" mode by
// default, this means that it uses WiFiUdp class instead of AsyncUDP.
// The later requires the Arduino Core for ESP8266 staging version
// whilst the former works fine with current stable 2.3.0 version.
// But, since it's not "async" anymore we have to manually poll for UDP
// packets
fauxmo.handle();

static unsigned long last = millis();
if (millis() - last > 5000) {
    last = millis();
    Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());

}

}

and this is the full error being reported before the ESP8266 tries to reset itself:
[MAIN] Device #0 (bedroom curtain) state: OFF
Opening the curtain...
Panic
/Users/lewisaburrow/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_main.cpp:98 __yield

ctx: sys
sp: 3ffff9d0 end: 3fffffb0 offset: 01b0

>>>stack>>>
3ffffb80:  00000001 00000002 3ffee770 40204b82
3ffffb90:  4010702c 00007530 00000064 402059fd
3ffffba0:  00000001 00000064 00007530 40204eca
3ffffbb0:  00000001 00000000 3ffee984 402053e9
3ffffbc0:  3ffe84e7 65526574 3ffffba0 3ffffe00
3ffffbd0:  3ffee78c 00000000 3ffee984 40202204
3ffffbe0:  3ffee78c 00000000 3ffee984 40202271
3ffffbf0:  65707954 3ffffc00 00000000 40203881
3ffffc00:  54534f50 70752f20 632f706e 72746e6f
3ffffc10:  622f6c6f 63697361 6e657665 48203174
3ffffc20:  2f505454 0d312e31 736f480a 31203a74
3ffffc30:  312e3239 312e3836 3933312e 3032353a
3ffffc40:  0a0d3030 65636341 203a7470 0d2a2f2a
3ffffc50:  6e6f430a 746e6574 7079742d 74203a65
3ffffc60:  2f747865 3b6c6d78 61686320 74657372
3ffffc70:  7475223d 22382d66 4f530a0d 43415041
3ffffc80:  4e4f4954 7522203a 423a6e72 696b6c65
3ffffc90:  65733a6e 63697672 61623a65 65636973
3ffffca0:  746e6576 5323313a 69427465 7972616e
3ffffcb0:  74617453 0a0d2265 746e6f43 2d746e65
3ffffcc0:  676e654c 203a6874 0d393932 3c0a0d0a
3ffffcd0:  6c6d783f 72657620 6e6f6973 2e31223d
3ffffce0:  65202230 646f636e 3d676e69 66747522
3ffffcf0:  3f22382d 3a733c3e 65766e45 65706f6c
3ffffd00:  6c6d7820 733a736e 7468223d 2f3a7074
3ffffd10:  6863732f 73616d65 6c6d782e 70616f73
3ffffd20:  67726f2e 616f732f 6e652f70 6f6c6576
3ffffd30:  222f6570 653a7320 646f636e 53676e69
3ffffd40:  656c7974 7468223d 2f3a7074 6863732f
3ffffd50:  73616d65 6c6d782e 70616f73 67726f2e
3ffffd60:  616f732f 6e652f70 69646f63 222f676e
3ffffd70:  3a733c3e 79646f42 3a753c3e 42746553
3ffffd80:  72616e69 61745379 78206574 736e6c6d
3ffffd90:  223d753a 3a6e7275 6b6c6542 733a6e69
3ffffda0:  69767265 623a6563 63697361 6e657665
3ffffdb0:  22313a74 69423c3e 7972616e 74617453
3ffffdc0:  3c303e65 6e69422f 53797261 65746174
3ffffdd0:  752f3c3e 7465533a 616e6942 74537972
3ffffde0:  3e657461 3a732f3c 79646f42 732f3c3e
3ffffdf0:  766e453a 706f6c65 00003e65 40101ea2
3ffffe00:  3fff0a5c 00000002 3fff0d0c 4010020c
3ffffe10:  40102bb5 3ffec9a8 3ffffe60 3fff0d0c
3ffffe20:  00000000 3ffee78c 3ffeb7c2 40203a5c
3ffffe30:  54534f50 70752f20 632f706e 72746e6f
3ffffe40:  622f6c6f 63697361 6e657665 48203174
3ffffe50:  2f505454 00312e31 3ffe97fc 00000001
3ffffe60:  000001fa 00007fff 000000ed 4010020c
3ffffe70:  3ffee960 04c14103 00002200 00000000
3ffffe80:  3fff0d0c 3fff09bc 00000000 40203a80
3ffffe90:  3ffe97c0 00000000 3fff0084 40204504
3ffffea0:  3fff0bdc 00000030 0000000f ffffffff
3ffffeb0:  3fff026c 3fff0274 00000006 3fff0080
3ffffec0:  3fff0bdc 3fff0088 3fff0084 4020454f
3ffffed0:  3fff0bdc 3fff0088 3fff0084 40229c30
3ffffee0:  000001fa 8b01a8c0 00000018 000001fa
3ffffef0:  00000018 00000000 3ffeea40 401074e4
3fffff00:  40100000 00000000 00000064 3fff0270
3fffff10:  3ffeb79a 3fff0274 3fff09bc 40228139
3fffff20:  3ffeff94 3fff072c 3fff072c 3ffedaf0
3fffff30:  00000000 3fff09bc 0000001c 3fff072c
3fffff40:  3ffeb78c 00000000 3fff09bc 40227535
3fffff50:  6301a8c0 00000258 00000000 0000001c
3fffff60:  00000002 0000001a 40207f53 3ffec9a8
3fffff70:  3ffeb764 3fffdcc0 3ffe9040 3ffe9040
3fffff80:  40207ec6 3ffec9a8 00000000 3fff079c
3fffff90:  3fffdc80 00000000 3fff09bc 4021bfbb
3fffffa0:  40000f49 3fffdab0 3fffdab0 40000f49
<<<stack<<<

ets Jan  8 2013,rst cause:2, boot mode:(1,7)

ets Jan  8 2013,rst cause:4, boot mode:(1,7)

wdt reset

fauxmo.enable(true); is in different spot in the example at https://bitbucket.org/xoseperez/fauxmoesp

comment out all the motor code .... do you still get the error?

Hi @jsotola thanks for your suggestion.
I commented out all the motor code and nothing had a panic this time. I then went back and uncommented the motor code but removed any calls for functions that would involve invoking the code. (Specifically I commented out line 113 where I call for 'openCurtain();' This is also worked without a panic.
So it only seems to panic when the motor code tries to execute something.

I guess motor code does not finish executing within allowed time slot. Thus watchdog resets the esp.

That sounds like it could be the problem. Is there a way to execute the motor code whilst letting the watchdog know the code is working on something and not to restart?


text:
Combining two sketches that both work on their own, but don't work when combined
I've got a program for a password protected doorlock, which I got working.
I'm trying to add to the code, to add functionality where I can toggle an LED on/off with a button.
Both codes function on their own and serve their desired purpose, but when I try to combine them into the same sketch, the LED button works but the rest of my design stops working. I can no longer input a password to activate the motor.
How can I combine the two codes and have them both work?
Here is the working keypad/lock code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

#define Password_Length 5

int signalPin = 10;
int greenLedPin = 11;
int redLedPin = 12;
char Data[Password_Length] = "4";
char Master[Password_Length] = "1234";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;

const byte ROWS = 4;
const byte COLS = 3;
bool ledState = 0;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS,     COLS);

LiquidCrystal_I2C lcd(0x3f, 16, 2);

void setup()
{
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);
  lcd.clear();

  pinMode(redLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  digitalWrite(redLedPin, LOW);
  digitalWrite(greenLedPin, LOW);
}

void loop()
{
  lcd.setCursor(0,0);
  lcd.print("Enter Password:");

  customKey = customKeypad.getKey();
  if (customKey){
    Data[data_count] = customKey;
    lcd.setCursor(data_count,1);
    lcd.print(Data[data_count]);
    data_count++;
    }

if(data_count == Password_Length-1){
    lcd.clear();

    if(!strcmp(Data, Master)){
      lcd.print("Correct");
      pinMode(signalPin, OUTPUT);
      digitalWrite(signalPin, LOW); //turns on motor
      digitalWrite(greenLedPin, HIGH); //turns on led
      delay(2000);
      digitalWrite(signalPin, HIGH); //turns off motor
      digitalWrite(greenLedPin, LOW); //turns off led
      }
    else{
      lcd.print("Incorrect");
      digitalWrite(redLedPin, HIGH); //turns on led
      delay(2000);
      digitalWrite(redLedPin, LOW); //turns off led
      }

    lcd.clear();
    clearData();
  }
}

void clearData(){
  while(data_count !=0){
    Data[data_count--] = 0;
  }
  return;
}

and here is the code I'm using for the LED on/off toggle button
int button = 2;
int led = 13;
int status = false;

void setup(){
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP); // set the internal pull up resistor,
unpressed button is HIGH
}

void loop()
{
//a) if the button is not pressed the false status is reversed by !status
and the LED turns on
//b) if the button is pressed the true status is reversed by !status and
the LED turns off

if (digitalRead(button) == true) {
status = !status;
digitalWrite(led, status);
} while(digitalRead(button) == true);
delay(50); // keeps a small delay
}

I just figured out that the original password code will still function, but only if i keep the LED toggle button held down.

By the way, digitalRead does not return true or false, it returns HIGH or LOW. Coincidentally they are the same numbers internally, but it is better practice to check for what the function is documented to return. See: https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/

Let's step back from the Arduino for a minute and ask: assuming you know how to cook some bacon, and also how to boil some eggs, how would you simultaneously cook bacon and eggs?
Basically you would have to interleave any process (such as waiting for the water to boil) with some other process (such as waiting for the bacon to cook).
Once you have this concept in your head you can just take the two pieces of code, and wherever you are planning to wait for something to happen, see if the other thing is able to be done.
I have done a post about this: http://www.gammon.com.au/blink

I just figured out that the original password code will still function, but only if i keep the LED toggle button held down.

Well, you need to remove any blocking loops from either part of the code.
Your code here blocks:
if (digitalRead(button) == true) {
status = !status;
digitalWrite(led, status);
} while(digitalRead(button) == true);

That's like (in my analogy) of thinking "oh the water is boiling, I'll have to stare at the eggs until they are cooked". Instead you could check the bacon, check the eggs, check the bacon again, and so on.
I'm giving you these analogies to help you solve the general problem, not this particular bit of coding.

i understand that the code blocks, but that code also makes the LED toggle on and off like i need, so how do i integrate that in a way that it doesnt block the rest?

Replace the LED code with something like this (not compiled or tested):
void loop ()
  {
  static int oldReading = LOW;
  int newReading = digitalRead (button);
  if (newReading != oldReading)  // it changed!
    {
    oldReading = newReading;  // remember new reading state
    if (newReading == HIGH)
      {
      status = !status;
      digitalWrite(led, status);
      }  // end of a HIGH reading
    }  // end of changed state

   // password stuff here

   }  // end of loop

Now, whatever you do with the button, the code doesn't stop (block) so the password stuff is still executed.

thanks, that makes sense, but im too new to this stuff to know how to rectify that

i understand that the code blocks, but that code also makes the LED toggle on and off like i need, so how do i integrate that in a way that it doesnt block the rest?


text:
Problem while connecting two arduino with NRF24L01
I am a beginner in Arduino programming so that program is also little bit lengthy sorry for inconvenience.
I have make a program for wire less controlling of a servo motor and LED(7 Nos.) using ARDUINO UNO, Funduino Joy stick shield V1.A and NRF24L01.First i have prepare the program (using Array) only for controlling the LEDs and its become success as that LEDs working as per program.Than i added Servo motor also in circuit and make some  changes in existing LED program. Unfortunately the result is erratic out put.joy stick input signal interrupting the led signal and some time servo motor respond led input .Transmitting code and Reciever code  given below.
I came to know that this problem will solve using "struct" command in existing program . Please help me to modify the program with "struct".Because i have no thorough knowledge in C,C++
TRANSMITTER
    #include <SPI.h>
    #include <RF24.h>
    #include <nRF24L01.h

>

#define xAxis A0
RF24 radio(9,10);
const uint64_t pipe = 0xF0F0F0F0D2L;

int msg[1];
int buttonPin1 = 2;
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 5;
int buttonPin5 = 6;
int buttonPin6 = 7;
int buttonPin7 = 8;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
int buttonState7 = 0;

void setup(void)
{
  radio.begin();
  radio.openWritingPipe(pipe);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);
  pinMode(buttonPin4, INPUT_PULLUP);
  pinMode(buttonPin5, INPUT_PULLUP);
  pinMode(buttonPin6, INPUT_PULLUP);
  pinMode(buttonPin7, INPUT_PULLUP);
}

void loop(void)
{
  int potValue = analogRead(A0);                              //  INPUT FOR SERVO MOTOR
  int angleValue = map(potValue, 0, 1023, 0, 180); // INPUT FOR SERVO MOTOR
  radio.write(&angleValue, sizeof(angleValue));         // INPUT FOR SERVO MOTOR

  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  buttonState5 = digitalRead(buttonPin5);
  buttonState6 = digitalRead(buttonPin6);
  buttonState7 = digitalRead(buttonPin7);

 if (buttonState1 == LOW){
    msg[0] = 111;
    radio.write(msg, 1);               // INPUT FOR LED1
   }
 if (buttonState2 == LOW){
    msg[0] = 222;
    radio.write(msg, 1);               // INPUT FOR LED2
   }
 if (buttonState3 == LOW){
    msg[0] = 212;
    radio.write(msg, 1);               // INPUT FOR LED3
   }
 if (buttonState4 == LOW){
    msg[0] = 216;
    radio.write(msg, 1);                 // INPUT FOR LED4
   }
 if (buttonState5 == LOW){
    msg[0] = 218;
    radio.write(msg, 1);                // INPUT FOR LED5
   }
 if (buttonState6 == LOW){
    msg[0] = 220;
    radio.write(msg, 1);                 // INPUT FOR LED6
   }
    if (buttonState7 == LOW){
    msg[0] = 224;
    radio.write(msg, 1);
   }                                              // INPUT FOR LED7

  }

RECIEVER
 #include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>  // SERVO LIBRARY INCLUDED

Servo myServo;
RF24 radio(9,10);
const uint64_t pipe = 0xF0F0F0F0D2L;

int led1 = 2;
int led2 = A2;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int msg[1];
int angleValue ;

void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  myServo.attach(3);                  // SERVO CONNECTED TO PIN 3
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
}
void loop(void)
{
   // Receiving code for LED 1 TO LED 7

  if(radio.available()){
    bool done = false;
    while (!done) {
    done = radio.read(msg, 1);
    Serial.println(msg[0]);

    if (msg[0] == 111) {
      digitalWrite(led1, HIGH);
      digitalWrite(led7, LOW);
      }
    if(msg[0] == 222){
        digitalWrite(led1, LOW);
        digitalWrite(led2, HIGH);
        digitalWrite(led7, LOW);
        }
     else if (msg[0] == 111){
          digitalWrite(led2, LOW);
        }
     else if(msg[0] == 212){

          digitalWrite(led3, HIGH);
        }
    else if(msg[0] == 216){
          digitalWrite(led4, HIGH);
        }
    else if(msg[0] == 218){
          digitalWrite(led5, HIGH);
        }
    else if(msg[0] == 220){
          digitalWrite(led6, HIGH);
        }
    else if(msg[0] == 224){
          digitalWrite(led7, HIGH);
          digitalWrite(led1, LOW);
          digitalWrite(led2, LOW);
        delay(10);
        }
      }
   }

//Recieving code for servo motor

    if(radio.available()){
      bool done = false;
      while (!done) {
      done = radio.read(&angleValue,sizeof (angleValue) );
      myServo.write(angleValue);}
      delay(10);
     }
                  //Receiving code for LEDs
      else {
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
      digitalWrite(led5, LOW);
      digitalWrite(led6, LOW);

      }
 }

I have tried to make a program using "struct" for 6 button state and one angle input signal  to control using 6 LEDs and one Servo and its working fine(Program mentioned below.)
But problem is that when i add two more input signal that time output become erratic and output is not getting as per program.Please help to modify the program.
transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#define CE_PIN   9
#define CSN_PIN 10
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int upbut = 2;
int rightbut = 3;
int downbut = 4;
int leftbut = 5;
int nuetral = 6;
int starte = 7;
int stope = 8;
struct data {
    uint8_t leds;
    uint8_t angle;
};
struct data packet;
void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
  pinMode(upbut,INPUT_PULLUP);
  digitalWrite(upbut,LOW);
  pinMode(rightbut,INPUT_PULLUP);
  digitalWrite(rightbut,LOW);
   pinMode(downbut,INPUT_PULLUP);
  digitalWrite(downbut,LOW);
  pinMode(leftbut,INPUT_PULLUP);
  digitalWrite(leftbut,LOW);
  pinMode(nuetral,INPUT_PULLUP);
  digitalWrite(nuetral,LOW);
  pinMode(starte,INPUT_PULLUP);
  digitalWrite(starte,LOW);
  pinMode(stope,INPUT_PULLUP);
  digitalWrite(stope,LOW);
  //end pinMode and digitalWrite
}//--(end setup )---
void loop(){
int potValue = analogRead(A0);
packet.angle = map(potValue, 0, 1023, 0, 180);

packet.leds = 0;
packet.leds = digitalRead(upbut) ? 0x00 : 0x01;
packet.leds |= digitalRead(rightbut) ? 0x00 : 0x02;
packet.leds |= digitalRead(downbut) ? 0x00 : 0x04;
packet.leds |= digitalRead(leftbut) ? 0x00 : 0x08;
packet.leds |= digitalRead(nuetral) ? 0x00 : 0x10;
packet.leds |= digitalRead(starte) ? 0x00 : 0x20;
/*packet.leds |= digitalRead(starte) ? 0x00 : 0x30;*/

radio.write((uint8_t *)&packet, sizeof(struct data));
}

receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#include <Servo.h>
#define CE_PIN 6
#define CSN_PIN 7
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
const int servo1 = 9;
int servoVal;
Servo myservo1;
struct data {
    uint8_t leds;
    uint8_t angle;
};
struct data packet;
int led1 = 2; // digital out put
int led2 = 3; // digital out put
int led3 = 4; // digital out put
int led4 = 5; // digital out put
int led5 = 8; // digital out put
int led6 = A0; // digital out put
int led7 = A1; // digital out put
void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  myservo1.attach(servo1); // attaches the servo1 /analog output

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();;
}                             //--(end setup )---

void loop(){

if (radio.available()) {
    radio.read((uint8_t *)&packet, sizeof(struct data));
    myservo1.write(packet.angle);
   if (packet.leds ==0x01){
    digitalWrite(led1, packet.leds & 0x01);
    digitalWrite(led2, packet.leds & 0x00);
    digitalWrite(led6, packet.leds & 0x00);
    }
   else if (packet.leds ==0x02){
    digitalWrite(led2, packet.leds & 0x02);
    digitalWrite(led1, packet.leds & 0x00);
    digitalWrite(led6, packet.leds & 0x00);
    }
    else if (packet.leds ==0x20){
    digitalWrite(led6, packet.leds & 0x20);
    digitalWrite(led1, packet.leds & 0x00);
    digitalWrite(led2, packet.leds & 0x00);
    }
    digitalWrite(led3, packet.leds & 0x04);
    digitalWrite(led4, packet.leds & 0x08);
    digitalWrite(led5, packet.leds & 0x10);

   /*digitalWrite(led7, packet.leds & 0x30);*/
}
}

You are sending two bytes, which each carry different information (LED and servo values), but you don't have any method to tell them apart. Think about what happens, when one byte is lost on the transmission. Everything will get out of step. Maybe you should only send complete messages with a delimiter, that marks the end of a package. Inside this package you can use the byte positions. Also maybe you need some kind of error detection/correction.

No need for delimiters with the nRF systems - they send discrete packets.

Your whole method is completely wrong.
Instead of sending bytes with some unknown meaning at random times you need a far more structured approach to sending your data.
You need to either:

Send the meaning of the byte(s) along with the byte(s), or
Send all the information every time at pre-defined periods.

Of the two options I'd favour the latter, using a struct:
struct data {
    uint8_t leds;
    uint8_t angle;
};

And then:
struct data packet;

int potValue = analogRead(A0);
packet.angle = map(potValue, 0, 1023, 0, 180);

packet.leds = 0;
packet.led |= digitalRead(buttonPin1) ? 0x00 : 0x01;
packet.led |= digitalRead(buttonPin2) ? 0x00 : 0x02;
packet.led |= digitalRead(buttonPin3) ? 0x00 : 0x04;
packet.led |= digitalRead(buttonPin4) ? 0x00 : 0x08;
packet.led |= digitalRead(buttonPin5) ? 0x00 : 0x10;
packet.led |= digitalRead(buttonPin6) ? 0x00 : 0x20;

radio.write((uint8_t *)&packet, sizeof(struct data));

Then when reading you do the exact opposite:
struct data packet;

if (radio.available()) {
    radio.read((uint8_t *)&packet, sizeof(struct data));
    myServo.write(packet.angle);
    digitalWrite(led1, packet.leds & 0x01);
    digitalWrite(led2, packet.leds & 0x02);
    digitalWrite(led3, packet.leds & 0x04);
    digitalWrite(led4, packet.leds & 0x08);
    digitalWrite(led5, packet.leds & 0x10);
    digitalWrite(led6, packet.leds & 0x20);
}

The struct combines a number of variables together into one single block of data giving you easy access by name to the different portions.  One, the leds variable, is then used as a bitmap of whether each LED is on (1) or off (0). That way you can send the current state of up to 8 LEDs in just a single byte.  If you want to expand that to send different combinations of LEDs then just change which bits of the byte are set.
If you want to "toggle" the LEDs then it will be necessary to keep a record at the sender of the states and send that instead of the raw button data.

Up to 6 leds and one angle input this working fine.But i have add one led and angle input more that time output become erratic.#include

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


text:
Disable the Amplifier during the flashing ESP8266
I use ESP-12 and Adafruit Mono Amplifier for playing audio. It works but It has one big issue. My circuit uses RxD to transfer audio (A+ connect to RxD), also ESP uses for flashing the chip. This causes horrible noise when it is programming the ESP8266 from the speaker. The good thing about this module is it has SD pin which can be used to turn it off.
Now the question is how I can connect this SD pin to disable the amplifier during the flashing procedure and also keep it off by default in normal mode and use something like digitalWrite() to turn it on manually in my application when it is needed. Thanks

since you can't set pins during/before flashing, afaik, you have to use pins 4 or 5, which are LOW during RESET

Are they LOW during RESET or Flashing? Do you mean GPIO4 and GPIO5?

low from power-on, yes, gpio 4-5. useful for relays, buzzers, and other output where an uncontrolled state is annoying or dangerous,.

SD is pulled up to VIN by a 10kΩ resistor. You will need to pull it down to ground with something "stronger" that 10kΩ - a 1kΩ resistor would probably do it.
Then you can drive the pin HIGH and override that 1kΩ resistance to enable the module.
You could also modify the module to remove the 10kΩ pull-up resistor (the one right by the VIN label which has 1002 printed on it) and use a weaker pull-down resistor (10kΩ would be good).

Thank you, I change 10K pull-up to the ground and it works perfectly. The only problem now is the pin (I'm using GPIO16 now) is HIGH when it flashes the new ROM and it still makes the noisy sound. Is there any other pin (LOW during flashing) to use to fix that too?

16 is a special pin used for wakeup. 0, 2 and 15 have special meanings too. Anuthing other than those pins should be fine.


text:
Connecting LCD TFT shield to NodeMCU
I have the following screen:

I want to connect it to a NodeMCU device:

I read somewhere that it is not possible. However, I am not interested in the touch ability nor the SD card. I just want to draw something on the screen.
Is it possible to make the connection in somehow?

This is well possible. The TFT just has a SPI interface (SCLK, MISO, MOSI, CS) with additional DC and BL lines (DC = Data/Command, BL = no idea). You need a driver library for the LCD. What driver chip does it say it has? Do you have a buy link for the module?

The device appears to be this https://www.waveshare.com/wiki/2.8inch_TFT_Touch_Shield

BL = Back Light

The driver chip was identified by https://www.waveshare.com/wiki/2.8inch_TFT_Touch_Shield and https://www.waveshare.com/w/upload/8/84/2.8inch-TFT-Touch-Shield-UserManual-EN.pdf as being the HX8347D.
At https://github.com/jshnaidman/UTFT_ESP8266_HX8347D there seems to be a library, with which you can use the HX8347D display type to instantiate a UTFT object, with which you can draw. You can build upon this demo code.
The connections for the SPI interface are detailed here. BL (backlight) pin is detailed here. The pin number for the D/C pin must be given in the code in the constructor and can be chosen freely.
Other reference code (which you might have to port) are:

HX8347D by Majenko
Code from Watterott


text:
Is it correct to use a 9V 1A transformer to power my project?
I have a quick question:
I have a small alarm project running on an ArduinoNanoV3 (a chinese clon). Counting sensors, actuators and the arduino itself the consumed current (theoretically speaking, calculated by the data provided by the datasheets) doesn't approach to a max of 300mA. Now, the way I plan to feed the project is using a 110V (AC) transformer that gives me 9V output with 1A maximum output. My fear is the output of this transformer (that says 1A) when in all places recommend not to use sources that give currents greater than 500mA when you are going to feed it by the pin VIn with 9V.
My question is: if my project is not going to consume more than 300mA, is there any danger/trouble when connecting the 9V ~ 1A transformer for energize my Arduino based project?

in all places recommend not to use sources that give currents greater than 500mA when you are going to feed it by the pin VIn with 9V.

Nowhere says that.  They say you should not draw more than 500mA when you supply with 9V.
The heat generated by the 5V voltage regulator is proportional to the current multiplied by the voltage.  The more current you draw the hotter the regulator will get. The higher the input voltage, the more voltage it has to drop, and thus the hotter it gets.
So the higher the input voltage the lower the current drawn by your project can be before the regulator gets too hot.
Since you are only around 300mA that's below the recommended maximum for a 9V input.


text:
Rc receiver giving wrong values when controlling servo
So I'm building a helicopter. That why I need a receiver (tgy 9x) to read the values from my controller. Those values get passed to my Arduino due where some calculation happen and then get sent to the servos.
Now the problem is the moment I move my servo all the value I get from my receiver immediately become gibberish.
The values I should get and get when I am not sending anything to my servos. These values are in microseconds.
Channel1 Channel2 Channel3 Channel4
1486     1484     1482     1472
1486     1484     1482     1472
1486     1484     1482     1472
1486     1484     1482     1472

What I get after moving the servo. These should be between 1000 and 2000.
Channel1 Channel2 Channel3 Channel4
1495     18660    1105     17182
1495     2337     5667     3070
8828     7674     8795     6198
10289    7674     8795     11404

The Arduino gets power from the USB (at the moment) and the servo from the ESC of my motor. All the grounds are connected. There is only one servo hooked up and all wires from the receiver are not anywhere near any power lines or servos.
So the question is why is the receiver giving me gibberish and how do I fix it.
Right now I have commented everything out except this:
RC_controller.h
#ifndef RC_controller
#define RC_controller

#include <Arduino.h>
#include "eeprom.h"

void RC_init();
void calc_input0();
void calc_input1();
void calc_input2();
void calc_input3();
void calc_input4();
void calc_input5();
#endif

RC_controller.cpp
#define RC_NUM_CHANNELS  8
uint32_t volatile rc_start[RC_NUM_CHANNELS];
uint32_t volatile rc_shared[RC_NUM_CHANNELS];
uint32_t volatile rc_raw[RC_NUM_CHANNELS];

int rc_channels_pin[8] = {2, 3, 4, 5, 6, 7, 8, 9};

void calc_input0() {
 int identifyer = 0;
   if (digitalRead(rc_channels_pin[identifyer]) == HIGH) {
     rc_start[identifyer] = micros();
   } else {
     rc_raw[identifyer] = (uint16_t)(micros() - rc_start[identifyer]);
   }
}

...

void RC_init()
{

 for (byte i = 0; i > RC_NUM_CHANNELS; i++)
   pinMode(rc_channels_pin, INPUT);

 attachInterrupt(digitalPinToInterrupt(rc_channels_pin[0]), calc_input0, CHANGE);
 attachInterrupt(digitalPinToInterrupt(rc_channels_pin[1]), calc_input1, CHANGE);
 attachInterrupt(digitalPinToInterrupt(rc_channels_pin[2]), calc_input2, CHANGE);
 attachInterrupt(digitalPinToInterrupt(rc_channels_pin[3]), calc_input3, CHANGE);
 attachInterrupt(digitalPinToInterrupt(rc_channels_pin[4]), calc_input4, CHANGE);
 attachInterrupt(digitalPinToInterrupt(rc_channels_pin[5]), calc_input5, CHANGE);
}

main.cpp
...
void setup()
{
Serial.begin(115200);
  Wire.begin();
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
    Fastwire::setup(400, true);
#endif
for (int a = 0; a < 3; a++)
  swashplate[a].attach(10+a, 1200, 1800);
RC_init();
}

void loop()
{
if (rc_raw[0] < 2000)
  {
    swasplate[0].write(rc_raw[0]);
  }

  Serial.print(rc_raw[0]);
  Serial.print("    ");
  Serial.print(rc_raw[1]);
  Serial.print("    ");
  Serial.print(rc_raw[2]);
  Serial.print("    ");
  Serial.print(rc_raw[3]);
  Serial.print("    ");
  Serial.print(rc_raw[4]);
  Serial.print("    ");
  Serial.print(rc_raw[5]);
  Serial.print("    ");
  Serial.println();
}

You could well have a problem with the servo introducing power supply noise.  A literal Arduino is a very poor fit in this application - too big, too high a supply voltage, too unreliable in physical implementation.  Typical solutions are more integrated with a lot more attention to the engineering of how the parts work together and avoid interfering with each other - the flight control projects that used Arduino back in their early era have long since moved on to more suitable custom boards.

Can you name an example of these "more suitable custom boards"? Do you mean preprogrammed flight controllers? The thing is I still want to program it myself ...

Any relevant search engine or ecommerce site will be full of boards for the well known open source flight control projects; of course you need to pay attention to details and look at other's experience.  I've always made my own, so no help there.  At this point having a distinct radio receiver connected via PWM seems a bit antiquated compared to an onboard radio as well - part of the problem with stringing modules together is that it means a larger, heavier, more hazardous test aircraft, while compact solutions mean featherweight things you can fly off the lab bench.

So when you make your own, you place the receiver and CPU on the same board?

Yes, like most now do.  It's not only more compact but a more natural interface, without going through the legacy PWM or even still-multiplexed PPM.

I found the problem. The problem was with the interrupts when the program was running and doing calculations at that moment the Arduino would be interrupted and stop in the middle of it, and change the value it was doing calculations with. This somehow caused the Arduino to sent interference over the signal wires. Reading the signals with a reading guard fixed the problem.
void read_inputs()
{
  noInterrupts();

  byte identifyer = 0;
  rc_shared[identifyer] = rc_raw[identifyer];

  ...

  interrupts();
}

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


text:
NodeMCU ESP12 Voltage
I'd like to power an NodeMCU off of four 1.5v batteries.  That's 6v.
Depending on the source I've read that 5.1v will fry the board and, just a few clicks later, that the board will take up to a 20v input.
What is the real, practical input voltage range for an NodeMCU?  Even the spec sheets seem to disagree.

I edited your question and changed ESP-12 to NodeMCU, based on the title and tag.
5.1 V will 'fry' a plain ESP12, but the NodeMCU is development board with esp8266 and the board has a power regulator for USB power or Vin pin. The parameters of the regulator depend on the regulator used by the manufacturer of your board.


text:
Motor shield not providing enough current to 2 12V DC fans
I have 2 fans and they require up to 3A current, but my motor shield (Arduino Motor Shield Rev3) on my Arduino MEGA can only provide 2A per channel (4A max).  Is it ok to run the fans at a lower speed or are there other options to run (H-bridge)? Thanks.
Fans:
https://www.amazon.com/HIGHFINE-4000RPM-Cooling-FFC1212DE-Computer/dp/B01LLYQ2VE/ref=sr_1_1?ie=UTF8&qid=1523596613&sr=8-1&keywords=12V+dc+fan+200+cfm

The fan you linked is marked as being a Brushless DC motor.  Looks like the Motor shield you have is not designed to drive that kind of motor.

What sort of shield would you recommend in that case?

I kinda doubt that that fan will actually draw 3A. You could probably get away with using your shield--just measure the fan current draw by directly connecting it up to a 12V supply and measuring with a multimeter.
If it actually draws 3A, any of these sounds like a decent idea:
https://www.amazon.com/WGCD-Controller-Module-Stepper-Arduino/dp/B06X9D1PR9/ref=sr_1_4?s=electronics&ie=UTF8&qid=1523692716&sr=1-4&keywords=arduino+h+bridge
https://www.amazon.com/Diymall-Module-Stepper-Modules-Arduino/dp/B00NJOTBOK/ref=sr_1_8?s=electronics&ie=UTF8&qid=1523692716&sr=1-8&keywords=arduino+h+bridge
https://www.amazon.com/SainSmart-Stepper-Controller-Mega2560-Duemilanove/dp/B00AJGM37I/ref=sr_1_11?s=electronics&ie=UTF8&qid=1523692716&sr=1-11&keywords=arduino+h+bridge


text:
"Serial does not name a type error"
I m getting serial does not name a type error, expected declaration before '}' token line 69
const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;
const int ledPin = 13;

// defines variables
long duration;
int distance;
int safetyDistance;

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  pinMode(buzzer, OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600); // Starts the serial communication
}

void loop() {
// Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

// Calculating the distance
  distance = duration * 0.034 / 2;

  safetyDistance = distance;
  if (safetyDistance <= 5) {
    digitalWrite(buzzer, HIGH);
    digitalWrite(ledPin, HIGH);

    tone(buzzer, 1000);
    delay(100);
    noTone(buzzer);
    delay(100);
  }

  else {
    digitalWrite(buzzer, LOW);
    digitalWrite(ledPin, LOW);
  }
  if (safetyDistance > 5 && safetyDistance <= 10) {
    digitalWrite(buzzer, HIGH);
    digitalWrite(ledPin, HIGH);

    tone(buzzer, 3000);
    delay(3000);
    noTone(buzzer);
    delay(3000);
  } else {
    digitalWrite(buzzer, LOW);
    digitalWrite(ledPin, LOW);
  }
  }
  Serial.print("Distance: ");
  Serial.println(distance);

}

I formatted your code and now you can see that you have a redundant } before the line with error report

  if (safetyDistance > 5 && safetyDistance <= 10) {
    digitalWrite(buzzer, HIGH);
    digitalWrite(ledPin, HIGH);

    tone(buzzer, 3000);
    delay(3000);
    noTone(buzzer);
    delay(3000);
  } else {
    digitalWrite(buzzer, LOW);
    digitalWrite(ledPin, LOW);
  }
  }                           //<--
  Serial.print("Distance: ");
  Serial.println(distance);

}

There is a duplicate } after the else clause is closed. Remove it and your code will compile.

is this worth an Answer?

@Juraj Because it answers the question, yes. Even beginner questions deserve to be answered. We have to be more inclusive, as I read in https://stackoverflow.blog/2018/04/26/stack-overflow-isnt-very-welcoming-its-time-for-that-to-change/.

Maximilian, I somehow don't like that I formatted the code in question to show the problem and you write an answer equivalent to my comment

@Juraj that's true and good that you formatted the question 3 hours ago, but questions are still to be answered in answers and not in comments. And since the question does not really allow for any different answer but this, we also have identical answers


text:
USBasp problem: could not upload sketches to Arduino clone with PL2303 USB-to-UART chip
I'm trying to upload sketch to a Gizduino board (these boards have PL2303 chip for USB-to-Serial communication; other than that they are entirely similar with Arduino Uno).
I have installed the driver for it and can verify that the board associates to a COM Port whenever the board is connected to my PC (Win10) via USB. But everytime I try to upload a sketch, IDE (tried with 1.8.2 and 1.6.9) throws the error below, with or without the PL2303 driver installed on my PC.
avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor='www.fischl.de' product='USBasp'

I'm certain that I have selected the right board from the Boards List.
So my intuition was that the PL2303 driver is not working the way it should be. I've been trying to get more information about avrdude and USBasp but so far was not able to find anything remotely similar to my case.
UPDATE: Realized that all I needed to do is install the driver for USBasp (whihch I'm having trouble doing); this post could be off-topic. But I'm urged to raise another question: Which programmer should I select from the programmer list? Currently its "AVRISP mkII". In fact it doesn't matter which one I use. Same error about USBasp occurs with any of them selected.

You told the IDE to upload through an USBASP, but apparently you are no using an USBASP, so avrdude complains it cannot find it.

Hi. I updated the post.

Really frustrating. Tried on 3 different pc's. same board. same problem. Found nothing related in the internet. Not even in stackexchange is there somebody who got any idea about this seemingly ubiquitous issue. at this point I'll just take it that my board is broken.

Do you have a USBasp plugged into the computer? if yes then you need to install USBasp driver else why don't you just use the bootloader option from the arduino IDE.


text:
nodemcu pins + sensors reading values
what are the SDA & SCL pins in NodeMCU? (Pins 20 & 21 in Arduino MEGA2560) I already implemented a simple project to read 2 accelerometers values from Arduino and send them through wifi to firebase database. I used Arduino Mega before for the same project and the sensors gave me readings between approximately -300 to 300. Now when I moved to NodeMCU the sensors became very sensitive and are getting values up to 65500+. And with a very small angle change the axis reading drop down to 20 or less.
I used pins D1 and D2 for SCL and SDA. Are the pins correct? And What about the reading values how to fix that?

The ESP8266 doesn't have a hardware Two Wire Interface. I²C is done in software, so you can use any 2 pins, as long as you specify them in your code using Wire.begin(SDA, SCL).
My guess would be that there's another problem. 65500+ sounds like an integer overflow, for example. ((uint16_t) -1 == 65535)


text:
Arduino Communication with Xbee
I'm trying to establish a wireless connection between two Arduino's(M0) using xbee s2c, one Arduino as the sender and other as the receiver. But I am not able to receive the message what the Arduino is sending.
The two radio modules are configured as:
Sender
pan id- 1234
CE- enable
DH- 13A200
DL- 40F8D876
AP- Transparent mode

Receiver
pan id- 1234
CE- Disable
JV- Enable
DH- 13A200
DL- 40F8D874
AP- Transparent mode

SENDER CODE
void setup() {
  // Begin the Serial at 9600 Baud
  Serial1.begin(9600);
  SerialUSB.begin(9600);
}

void loop() {
  SerialUSB.print(int(Serial1.write("1")));
  delay(1000);
}

RECEIVER CODE
void setup() {
  // Begin the Serial at 9600 Baud
  Serial1.begin(9600);
  SerialUSB.begin(9600);
}

void loop() {
  if (Serial1.available()){
  SerialUSB.print(int(Serial1.read()));
  delay(1000);
}}


text:
Bluetooth a pushbutton from one arduino to another to turn on a LED
For a major project at school i need to get a bluetooth module to be able to communicate between two  HC-05 modules as a master and slave. They need to be able to press a pushbutton on the slave and it lights up a LED on the master.
I have been able to get the two hc-05's to connect to each other but i cant find a code and wiring that will work for what i need to do.
any help will be appreciated. Thanks

When you already have two arduinos and two hc-05 connected to each other, what wireup and code is missing?

The HC-05s are serial bluetooth modules. If you have connected the two HC-05 you already have send them AT commands via your serial interface. What is your problem with sending the needed information over the serial interface?

please post the code that you have so far .... we can then give you some hints  .... please do not expect any ready made solutions, since this is a school assignment

Do not post code as pictures. There is a function in the question editor to properly format code you inserted as text. Please use it

So, you have done the hard part and now need the easy bit :)
Firstly you need a button (failing that touching two wire together will just about do).  There are loads of quick tutorials on the web, here is one https://www.arduino.cc/en/Tutorial/Button.  They will end up with you having a pin that goes high or low when the button is pressed, you can either poll/loop to detect the press or go posh and use interrupts (leave that for later).  When the pin detects the press you need to send some data via your HC05 link to the master, something like 'ON' or 1, who cares so long as the master understands it.  And when it disconnects you need to send a off or 0 message (Remember the number 1 and the character '1' are not the same thing, so make sure you know what you are sending).
When the master receives the command it will execute a bit of code that will send a pin high (lets say pin 7).  Connected to pin 7 will be the +ve side of a LED, the -ve leg of the led will be connected to a resistor of 200-250 ohms and the other end of the resistor will be connected to ground.  Then when pin7 goes high it will light the resistor.

simulate this circuit – Schematic created using CircuitLab
As always you probably will need to break it down to test it, have a little app that toggles pin 7 high for 2 seconds and low for two seconds, etc (just like blink).
There is a phenomenon called 'bouncing' which is where the useless human finger presses a switch and doesn't instantly create a perfect connection and perfect disconnection.  This might make the slave send 101010101010101 when you just expect 1, you can either debounce using software or hardware, but only worry about that if you have a good quality switch :)


text:
transmit a sequence of bit using arduino uno
How do i code to transmit a sequence of bit using arduino uno?My project is about a transmitter and a receiver.Arduino as the transmitter and an application as the receiver.Light sensor will detect the bits sent.How do i send a sequence of bit for example 00101010.What kind of function should i use? i am a beginner for arduino. thank you.

Transmit how? Using morse-code with the led?

Optical transmission is quite a broad field. What are your requirements regarding speed, error-correction? How do you want to receive and decode the data? You might be better of using an IR library or a different medium (WiFi, Bluetooth, ..)

transmit using morse-code but transmit binary. That will sent 1's and 0's that is 8 bit. the arduino uno act as a transmitter and an application will be receiver and accept the sequence of bit.

transmit using morse-code but transmit binary say again. If you have "A" would you like this transmitted as "short-long" or "01000001" (ASCII value).

Serial.print("hello"); is transmit binary (ASCII). So your sketch is already doing that.

woahh i just knew a lot of this. i just want to send a simple binary value. a sequence of 8 bit character continuously. which library or example should i refer to learn and code. thank you so much.

what i mean was. i want to send a binary transmitter. a simple one. not using morse-code

people usually use manchester coding. but my receiver is a light sensor from android

send it where? At what rate?

38400rate. send it through an led

read the Serial TX LED or create SoftwareSerial with TX on pin 13

you are already sending a sequence of bits through an LED. 1 second ON followed by 1 second OFF, repeating indefinitely .... please update your question with what you really want to ask

Also asked here: https://arduino.stackexchange.com/questions/52837/sending-a-character-a-through-blinking-led

Bit-wise sending of a chunk of data is really just:

go through each byte of the data
for each byte (= 8-bits), put each bit on the LED and wait

This also has some substantial drawbacks:

no error detection or correction. If you get interference on your light sensor / camera due to the environment, you will read wrong data. For this you would need to code the data with some coding scheme or append a checksum
outputting on the built-in LED on the Arduino Uno / Nano is a bad idea sine it's directly next to the power, RX and TX LED
outputting in the visible spectrum is asking for interference. That's why we have InfraRed transmissions.
receiver and transmitter might out of sync; that means that the receiver does not sample the output of the transmitter at the correct time -- you should use a preamble, oversampling and averaging at the receiver to overcome this

That said, you might be better off using other proven methods such as IR, 2.4GHz transceivers, et cetera, from my point of view. Other microcontrollers (example) have even built-in peripherals to do IR transmission according to some protocol.
On the Arduino Uno/Nano you could also use the IRemote library to send and receive data using a cheap IR LED and a IR receiver, many of which are included in starter kits (and are also otherwise cheap).
The code below simply takes a stream of bytes and outputs them bit-wise on the LED. Nothing else done. Also, digitalWrite is slow and should be replaced by a faster variant.
#include <Arduino.h>

/* LED to output from */
const int LEDTrans = 13;
/* Length of a symbol */
const int timeWait = 500;

const char dataToSend[] = "Hello World";

/* Transmits data bitwise */
void transmitData(const char* data, size_t length) {
    //go through each byte of the data
    for(size_t i = 0; i < length; i++) {
        uint8_t currentByte = (uint8_t) data[i];

        //Go through each of the 8 bits in the byte
        //Goes from LSB to MSB (right-to-left)
        for(int j = 0; j < 8; j++) {
            //uses Arduino.h macro "bitRead"
            bool currentBit = bitRead(currentByte, j);

            //Set the LED on/off
            digitalWrite(LEDTrans, currentBit);
            //Wait for the symbol time
            delay(timeWait);
        }
    }
}

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

void loop() {
    transmitData(dataToSend, strlen(dataToSend));
    //turn LED OFF again
    digitalWrite(LEDTrans, 0);
    delay(2000);
}

transmit using morse-code but transmit binary say again. If you have "A" would you like this transmitted as "short-long" or "01000001" (ASCII value)..... i'm sorry i didn't notice your question Maximilian. i want to transmit in the form of 01000001.

can i have your email?i need to ask a lot..


text:
Arduino receive response from SIM800H to AT+CCLK? command
I've been trying to make a program that interacts with SIM800H trough AT commands. It worked with the String class, but it was full of "memory leaks" and after a few hours it just hanged. Then I tried to write it again with char arrays, but for some reason I couldn't get it to work properly.
Can someone suggest me a correction to my program and also a way to get char by char with loop and Serial.read();? Serial in this case (Arduino Leonardo) is the USB port and Serial1 is the port to the modem.
Here is my code:
const long interval = 2000;
static long currentMillis;

char wherecclk = 0; // To determine where is the + in +CCLK in the char array

char serialdata[256] = ""; // Array to store the chars before parsing

char rtcy1[3]; // Current year  Format: yy\0
char rtcm1[3]; // Current month  Format: mm\0
char rtcd1[3]; // Current day  Format: dd\0
char rtch1[3]; // Current hour  Format: hh\0
char rtcmm1[3]; // Current minute  Format: mm\0
char rtcs1[3]; // Current second  Format: ss\0

int rdpos = 0;

void setup() {
  Serial.begin(9600); // USB to Computer
  Serial1.begin(9600); // UART to Modem
  Serial1.print("ATE0\r"); // Disable echo
}

void loop() {
  wherecclk = 0;
  if (Serial1.available () > 0) { // when something comes on real serial
    strcpy(serialdata, "OK\n\n+CCLK: \"04/01/01,01:35:31+00\"\n\nOK\n"); // This is a real sample of the response coming from the modem emulated

    while (rdpos < 256) { // loop timeout: 256 bytes
      if (serialdata[rdpos] == '+') {
        break; // We have reached the first + char. Stop incrementing it
      }
      rdpos++;
    }

    if (serialdata[rdpos + 1] == 'C' && serialdata[rdpos + 2] == 'C' && serialdata[rdpos + 3] == 'L' && serialdata[rdpos + 4] == 'K') { // If the serial command mathes +CCLK save its position
      wherecclk = rdpos;
    }
    rdpos = 0;

    if (wherecclk != 0) {
      rtcy1[0] = serialdata[wherecclk + 8]; // getting first char with its offset
      rtcy1[1] = serialdata[wherecclk + 9];
      rtcy1[2] = '\0';
      rtcm1[0] = serialdata[wherecclk + 11];
      rtcm1[1] = serialdata[wherecclk + 12];
      rtcm1[2] = '\0';
      rtcd1[0] = serialdata[wherecclk + 14];
      rtcd1[1] = serialdata[wherecclk + 16];
      rtcd1[2] = '\0';
      rtch1[0] = serialdata[wherecclk + 17];
      rtch1[1] = serialdata[wherecclk + 18];
      rtch1[2] = '\0';
      rtcm1[0] = serialdata[wherecclk + 20];
      rtcm1[1] = serialdata[wherecclk + 21];
      rtcm1[2] = '\0';
      rtcs1[0] = serialdata[wherecclk + 23];
      rtcs1[1] = serialdata[wherecclk + 24];
      rtcs1[2] = '\0';
    }
  }

  if (millis() - currentMillis >= interval) { // This is done every second
    Serial1.print("AT+CCLK?\r"); // ask for the time
    // delay(50);
    Serial.println("");
    Serial.println("=====");
    Serial.println(millis());
    Serial.println("YEAR: ");
    Serial.print(rtcy1[0]);
    Serial.println(rtcy1[1]);
    Serial.println("MONTH: ");
    Serial.print(rtcm1[0]);
    Serial.println(rtcm1[1]);
    Serial.println("DAY: ");
    Serial.print(rtcd1[0]);
    Serial.println(rtcd1[1]);
    Serial.println("HOUR: ");
    Serial.print(rtch1[0]);
    Serial.println(rtch1[1]);
    Serial.println("MINUTE: ");
    Serial.print(rtcmm1[0]);
    Serial.println(rtcmm1[1]);
    Serial.println("SECOND: ");
    Serial.print(rtcs1[0]);
    Serial.println(rtcs1[1]);

    currentMillis = millis();
  }
}

Here is the output (a screenshot, because serial monitor doesn't give me full code):

You declare your variables for month and minute differently (rtcm1[3] vs rtcmm1[3]), but you load rtcm1 with month, and then a few lines later, with minutes.

Silly me! I guess I overlooked the typo and thought it's some other error

Here's the final code in case someone needs it:
const long interval = 1000;
static long currentMillis;

char wherecclk = 0; //To determine where is the + in +CCLK in the char array

char serialdata[256] = ""; //Array to store the chars before parsing

char rtcy1[3]; //Current year  Format: yy\0
char rtcm1[3]; //Current month  Format: mm\0
char rtcd1[3]; //Current day  Format: dd\0
char rtch1[3]; //Current hour  Format: hh\0
char rtcmm1[3]; //Current minute  Format: mm\0
char rtcs1[3]; //Current second  Format: ss\0

int rdpos = 0;

int pointingfinger = 0;

void setup() {
  Serial.begin(9600); //USB to Computer
  Serial1.begin(9600); //UART to Modem
  Serial1.print("ATE0\r"); //Disable echo
}

void loop() {
  if (Serial1.available () > 0) { //when something comes on real serial
    rdpos = 0;
    wherecclk = 0;
    if (pointingfinger == 255) {
      pointingfinger = 0;
    }

    serialdata[pointingfinger] = Serial1.read();

    while (rdpos < 256) //loop timeout: 256 bytes
    {
      if (serialdata[rdpos] == '+') {
        break; //We have reached the first + char. Stop incrementing it
      }
      rdpos++;
    }
    if (serialdata[rdpos + 1] == 'C' && serialdata[rdpos + 2] == 'C' && serialdata[rdpos + 3] == 'L' && serialdata[rdpos + 4] == 'K') { //If the serial command mathes +CCLK save its position
      wherecclk = rdpos;
    }

    pointingfinger++;
  }

  if (millis() - currentMillis >= interval) //This is done every second
  {
    pointingfinger = 0;
    //Serial.println("=========");
    //Serial.println(serialdata);
    //Serial.println("=========");
    if (wherecclk != 0) {
      rtcy1[0] = serialdata[wherecclk + 8]; //getting first char with its offset
      rtcy1[1] = serialdata[wherecclk + 9];
      rtcy1[2] = '\0';
      rtcm1[0] = serialdata[wherecclk + 11];
      rtcm1[1] = serialdata[wherecclk + 12];
      rtcm1[2] = '\0';
      rtcd1[0] = serialdata[wherecclk + 14];
      rtcd1[1] = serialdata[wherecclk + 15];
      rtcd1[2] = '\0';
      rtch1[0] = serialdata[wherecclk + 17];
      rtch1[1] = serialdata[wherecclk + 18];
      rtch1[2] = '\0';
      rtcmm1[0] = serialdata[wherecclk + 20];
      rtcmm1[1] = serialdata[wherecclk + 21];
      rtcmm1[2] = '\0';
      rtcs1[0] = serialdata[wherecclk + 23];
      rtcs1[1] = serialdata[wherecclk + 24];
      rtcs1[2] = '\0';
    }
    Serial1.print("AT+CCLK?\r"); //ask for the time
    //delay(50);
    Serial.println("");
    Serial.println("=====");
    Serial.println(millis());

    Serial.println("YEAR: ");
    Serial.print(rtcy1[0]);
    Serial.println(rtcy1[1]);
    Serial.println("MONTH: ");
    Serial.print(rtcm1[0]);
    Serial.println(rtcm1[1]);
    Serial.println("DAY: ");
    Serial.print(rtcd1[0]);
    Serial.println(rtcd1[1]);
    Serial.println("HOUR: ");
    Serial.print(rtch1[0]);
    Serial.println(rtch1[1]);
    Serial.println("MINUTE: ");
    Serial.print(rtcmm1[0]);
    Serial.println(rtcmm1[1]);
    Serial.println("SECOND: ");
    Serial.print(rtcs1[0]);
    Serial.println(rtcs1[1]);

    currentMillis = millis();
  }
}


text:
Arduino - use print(.., DEC) to save into variable
I am using:
Serial.print(rawCodes[i - 1], DEC);

to print into serial monitor, but how can I save (rawCodes[i - 1], DEC) to save into variable?

The string value or the integer value of rawCodes[i-1]? How is rawCodes declared?

@MaximilianGerhardt rawCodes is unsigned int

rawCodes is already a variable. What do you actually want to achieve?

@Majenko I want get rawCodes[i - 1] to int variable

NO!!! That is what you think you want to do. Not what the end result is that you desire.

Assuming your code comes from here: https://www.alanzucconi.com/2015/08/19/how-to-hack-any-ir-remote-controller/
Since rawCodes is declared as
unsigned int rawCodes[35];

I.e., it is a 35-element array of unsigned int elements, we can access a single unsigned int element at some index and save it in a variable like
unsigned int myVariable = rawCodes[i - 1]; //assuming i is some integer variable
                                           //and exists in this scope

If conversion to a String object is needed it can be passed into the constructor of the String class as
String myString = String(myVariable);

That answers your syntactical question on how to save that element into a variable; however, it is unlikely that this is your real underlying problem. We cannot determine that until you tell us what exactly you actually want.
References:

Arrays in C tutorial


text:
how to send FFT array consist of 512 Samples Data From arduino to raspberry pi using i2c and this is the code for FFT any Suggestion plz?
#include "arduinoFFT.h"
float y, x = 0;
#define t PE_0
#define SAMPLES 1024             //Must be a power of 2
#define SAMPLING_FREQUENCY 1024 //Hz, must be less than 10000 due to ADC
arduinoFFT FFT = arduinoFFT();

unsigned int sampling_period_us;
unsigned long microseconds;

double  vReal[SAMPLES];
double vImag[SAMPLES];

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

  sampling_period_us = round(1000000 * (1.0 / SAMPLING_FREQUENCY));
}

void loop() {

  /*SAMPLING*/
  for (int i = 0; i < SAMPLES; i++)
  {
    microseconds = micros();    //Overflows after around 70 minutes!
    y=(analogRead(t))*(3.3/4095.0)-1.65;
    x=((1000.0*y)/201.0);
    vReal[i] = x;
    vImag[i] = 0;

    while (micros() < (microseconds + sampling_period_us)) {
    }
  }

  /*FFT*/
  FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HANN , FFT_FORWARD);
  FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
  FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
  double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);

  /*PRINT RESULTS*/
  //Serial.println(peak);     //Print out what frequency is the most dominant.

  for (int i = 0; i < (SAMPLES / 2); i++)
  {
    /*View all these three lines in serial terminal to see which frequencies has which amplitudes*/

    //Serial.println((i * 1.0 * SAMPLING_FREQUENCY) / SAMPLES, 1);
    //Serial.print(" ");
    Serial.println(vReal[i], 1);    //View only this line in serial plotter to visualize the bins
  }

  delay(1000);  //Repeat the process every second OR:
  //while (1);      //Run code once
Serial.println("//");
}

this is the line that you have to replace with I2C comm Serial.println(vReal[i], 1);  .......... you have to start by writing code that sends just one Double between the two devices .... then merge the two codes

Are you thinking of using the Arduino as the master or the Pi as the master?


text:
Why is this variable giving me always the value of 0?
I am doing a project and here is the code that I am using, but I do not know why the values of duration and sofia is always 0 so the values of distance and monroy are also 0
const int trigPin = 9;
const int echoPin = 10;

const int t = 8;
const int e = 7;

long duration, sofia;
int distance, monroy;
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  pinMode(t, OUTPUT);
  pinMode (e, INPUT);
  Serial.begin(9600); // Starts the serial communication
}
void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  digitalWrite (t, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  digitalWrite (t, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  digitalWrite (t, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  sofia = pulseIn(e, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  monroy = sofia * 0.034 / 2;
  Serial.print(duration);
  if (distance = 15);
  {
    digitalWrite (3, HIGH);
    delay (5000);
    digitalWrite (3, LOW);
  }

  if ((monroy >= 0) && (monroy <= 5));
  {
    digitalWrite (4, HIGH);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
  }
  if ((monroy >= 5.1) && (monroy <= 9));
  {

    digitalWrite (5, HIGH);
    digitalWrite (6, LOW);
  }
  if (monroy >= 9.1);
  {

    digitalWrite (5, LOW);
    digitalWrite (6, HIGH);
  }
}

do you have the Arduino connected to anything?

My Arduino is connected to my laptop

What do you have connected to pins 9 and 10 of your Arduino? You might find this post on our meta site helpful: How to ask a good question for Arduino Stack Exchange

In the 9th and 10th pins I have the echo and trig pins connected. Thanks!

Please do a Serial.print of sofia so we can see what value is being used for the subsequent calculation.

when i write Serial.print(sofia) it always prints 0

It looks like it is timing out after one second, in that case. See: https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/

What is connected to pin 7?

When I formatted your code for readability and then compiled it I got these warnings:
/tmp/arduino_modified_sketch_71221/sketch_may02a.ino: In function 'void loop()':
/tmp/arduino_modified_sketch_71221/sketch_may02a.ino:34:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   if (distance = 15);
                    ^
/tmp/arduino_modified_sketch_71221/sketch_may02a.ino:34:21: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
   if (distance = 15);
                     ^
/tmp/arduino_modified_sketch_71221/sketch_may02a.ino:41:38: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
   if ((monroy >= 0) && (monroy <= 5));
                                      ^
/tmp/arduino_modified_sketch_71221/sketch_may02a.ino:47:40: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
   if ((monroy >= 5.1) && (monroy <= 9));
                                        ^
/tmp/arduino_modified_sketch_71221/sketch_may02a.ino:53:21: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
   if (monroy >= 9.1);

These are important - you should pay attention to them. For example, here:
  if (distance = 15);  // <-- NO SEMICOLON NEEDED HERE!
  {
    digitalWrite (3, HIGH);
    delay (5000);
    digitalWrite (3, LOW);
  }

Putting a semicolon there means that stuff under the if is always executed - the semicolon terminates the scope of the if.

To see the warnings open the Preferences dialog in the IDE GUI and change "Compiler warnings" to "All".

Also:
  if (distance = 15);

This assigns 15 to distance, so distance will always be 15. You mean:
  if (distance == 15)


text:
add ID number to the feather m0 bootloader (flash)
I'm trying to add a serial number to the bootloader's flash area of Adafruit Feather m0 board. Seems like feather m0 0-0x2000 area on the flash is non writable by the arduino sketch. i wanted to add a serial number to address 0x2000 - 8 on the flash.
The idea is for the data to be included in the bootloader elf\bin so i can easily flash it on devices and later on access it using flash address  (0x2000 - 8) with NVMCTRL.
I've started out with this solution:
downloaded the code from samd21 arduino bootloader github directory and in ./bootloaders/zero edited the boololoader ld script, first the "Memory" section
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x2000 /* First 8KB used by bootloader */
FLASHID (rx) : ORIGIN = 0x00002000 - 0x0008, LENGTH = 8

Then the 'sections' section:
.id_sec :
  {
    KEEP(*(.myid))
  } > FLASHID

This should have saved some room in the end of the flash for the id. now in the main.c file:
__attribute__ ((section(".myid"))) const unsigned long ID = 0xdead1234;

Which should have saved the 0xdead1234 hex value in the (0x2000-8) address.
The issue is this:
I compiled this code and linked it just fine, got .hex,.bin,.elf files.
If i'm correct (unless they are somehow compressed) i should be able to see the code 0xdead in the binary.
BUT i don't.
After objdump on the binary(any of them) i can't find the 0xde 0xad in any order anywhere.
The arm-none-eabi-size" --format=sysv -t -x build/.elf does not show the new section i added no where.
Also i do wonder, as i said the 0x2000 address on the flash is non writable once i flashed with atmel-ice \j-link even the bootloader code cannot write to it, i did define in the ld script that i want that memory region part of the flash so i do expect that the compiler + linker + jlink flasher will know to write that data to the right place but not sure.
Anyone got some experience with it ? did it before ?

instead of 0xde 0xad, look for 0xed 0xda ... maybe it is stored in little endian

Your question is amazingly hard to read. See How to ask a good question. Take a bit of time to make some paragraphs, spell "I" with a capital "I", and generally explain what you are trying to do.

@jsotola i did try that, well aware of the endianess. i basically tried just to use objdump and xxd and then grep it twice once for 'ed' and once for 'da' which should capture all possibilities.

Hi @NickGammon sorry , i see what u are talking about some parts slipped in from stackoverflow, i posted there too and copy-paste it and it needs some fixing, but in general i explain exactly what i wanted to achieve and what i did to achieve it, i was asking what can i do actually get it done.

Hey @NickGammon changed the question a bit i hope it's clearer now.

Cross-posted here. The question looks better, however see See Is cross-posting a question on multiple Stack Exchange sites permitted if the question is on-topic for each site? - you have to decide which site you want to ask on. Stack Exchange does not want you to ask your question over multiple of its sites.

Can understand them, though i think at times it's unjust as the question does fit nicely to any of them, stackoverflow is more generic and this is indeed a programming question, however it is in need of someone that also flashed a boot-loader or did a  certain procedure for embedded devices  in the past. which i guess i'll see mostly here.
In any case deleted it from stackoverflow and will repost if i don't get any answer here.

You know the samd21 already has a unique serial number that you can access.

This is quite an easy fix, actually.
The problem here is the compiler doesn't think the const is used for anything - so it (quite rightly) throws it away.
All you need to do is tell the compiler that it's used and all should be good:
__attribute__((section(".myid"),used)) const unsigned long ID = 0xdead1234;

And when you compile:
build/.elf  :
section             size         addr
.vectors            0x40          0x0
.text             0x18d4         0x40
.data               0x5c   0x20000000
.bss               0x34c   0x2000005c
.id_sec              0x4       0x1ff8
.ARM.attributes     0x28          0x0
.comment            0x80          0x0
.debug_frame        0x68          0x0
Total             0x1dd0

Properly, though, you should make some more changes to the linker script to properly isolate those 8 bytes of flash (though you don't have to).

You should reduce FLASH by 8 bytes.
You should include the FLASHID length in the __sketch_vectors_ptr calculation.

That's:
MEMORY
{
  FLASH   (rx) : ORIGIN = 0x00000000, LENGTH = 0x1FF8 /* First 8KB used by bootloader */
  FLASHID (rx) : ORIGIN = 0x00001FF8, LENGTH = 8
  RAM    (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000-0x0004 /* 4 bytes used by bootloader to keep data between resets */
}

And:
PROVIDE(__sketch_vectors_ptr = ORIGIN(FLASH) + LENGTH(FLASH) + LENGTH(FLASHID));

That way the compiled bootloader code can never be placed in the FLASHID area (not that it would at the moment, but if a new version of the bootloader were released that used 100% of the lower block of flash it would conflict).
Of course, if all you need is something unique to identify the board with, all AVR and SAMD devices that have built-in USB support have a unique ID number. This is intended to be used as the Serial Number for the USB, but could also be used for a MAC address for Ethernet (or for portions of it anyway) or other unique "node" addresses.

thanks! checking myself, if indeed i can see it i'll mark as the solution

@codeScriber note first the comment that the chip already has a unique ID.  Next, if you want to serialize like this, after setting a default from the compiler, in practice you'd probably want to directly overwrite the values in the binary to be flashed (dd or many other tools can write at an offset) rather than recompile for each unit.

I do something similar to set a unique USERID value on PIC32 chips when programming a bootloader from a HEX file. Allocate it from a database, then filter the HEX file changing the values that need changing and recalculating the checksums.

@ChrisStratton  thanks that's exactly what i planned to do though i planned to use python script to do that... but no, i didn't know it had a serial and i did look for it! are you sure it's unique ? i actually looked for arm m0 unique id and not samd21, probably my mistake was there...

@Majenko ineed it worked, if i xxd -g0 the .bin file i can see in the end :'00000000000000003412adde' ! marked your answer as the solution but maybe you should copy the remark about the fact that there is already a uniq id for samd21...

All the AVR parts with USB have a unique ID which is intended for use as the USB serial number. I'm not sure about the SAMD21 though - check the datasheet.

From the datasheet: "Each device has a unique 128-bit serial number....The uniqueness of the serial number is guaranteed only when using all 128 bits."

Excellent. I've not worked at a low level with these chips yet, though doing so is on the cards over the next few months, as well as the E70 series. Pretty soon I will be a world authority on them :(.