text:
Playing MP3 Shield tracks
I have an MP3 shield on a Arduino Uno. When using "File Player" I can get the tracks to play by keyboard entry with three digits (001-009).
The problem is that I want to use (SFEMP3Shield > examples > MP3ButtonPlayer2) that is looking for files 1-9. Any file numbers other than 1,2,3,4,5,6,7,8,9 doesn’t work. Any suggestions?

Welcome to Arduino:SE.  Please post the code that you are trying to use.  You might find this post on our Meta site helpful: How to ask a good question for Arduino Stack Exchange.

The playTrack function used in MP3ButtonPlayer2 example plays file with name created with printf format "track%03d.mp3". %03d creates a number prefixed with zeros to lenght 3. For example track005.mp3 or track042.mp3 or track999.mp3.
implementation of the playTrack function:
uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){

  //a storage place for track names
  char trackName[] = "track001.mp3";
  uint8_t trackNumber = 1;

  //tack the number onto the rest of the filename
  sprintf(trackName, "track%03d.mp3", trackNo);

  //play the file
  return playMP3(trackName);
}

change it to:
uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){

  //a storage place for track names
  char trackName[13];
  int trackNumber = trackNo;

  //tack the number onto the rest of the filename
  sprintf(trackName, "track%03d.mp3", trackNumber);

  //play the file
  return playMP3(trackName);
}

Thank you, makes sense, but I'm not a programmer, I don't know how to edit the SFEMP3Shield > examples > MP3ButtonPlayer2 to make it work.

put the SD card in a computer and rename the files. You should buy an MP3 player, not an Arduino, if you don't want to code

It's part of a larger program that uses code that I have worked out. This is the only thing I haven't been able to work, although Sparkfun says it should out of the box. It just need to play 3 tracks when things happen. I have renamed the tracks may times. Does the code you gave go on the SD card or into the MP3ButtonPlayer2 code?

it doesn't go anywhere. it is in the library. (and it's a shame for the author of the library, because it should not be coded as it is)

The SFEMP3Shield library is included in the sketch. What am I supposed to rename the tracks to? When I run File Player I get;

Received command: l
Music Files found :
00001: SndoSil.mp3
00002: Stmup.mp3
00003: Blndblt.mp3
I have renamed the files 001,002,003 with no change.

The 5 digit number is not on the SD card. It is generated in file player.

it should be track001.mp3

It’s not, that’s my point.I have renamed it track001.mp3 and somewhere in the upload it appears as track00001.mp3. Sparkfun tech support told me to input two leading zeros and since I proved the shied works they're done and told me to figure it out myself. Do you know how to add two leading zeros @ int8_t track = 0; in the MP3ButtonPlayer2 sketch?

C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp: In member function 'uint8_t SFEMP3Shield::vs_init()':
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:292:34: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
if(VSLoadUserCode("patches.053")) return 6;

function playTrack will add two leading zeros, if you have the same library. call it as playTrack(1), playTrack(2), playTrack(3),

It needs to add two "ADDITIONAL" zeros. The library is SFEMP3Shield and I have downloaded it from many places and having different dates. here is what I get from "FilePlayer"
Received command: l
Music Files found :
00001: SndoSil.mp3
00002: Stmup.mp3
00003: Blndblt.mp3
00004: track001.mp3
Sparkfun told me that they noticed it was adding additional zeros and to input two additional zeros via keyboard in "FilePlayer"  and it would work which it does but I want to use MP3ButtonPlayer2 which generates it's own number and doesn't work.

The MP3ButtonPlayer2 sketch does call for playTrack(1), playTrack(2), playTrack(3) it should cal for playTrack(001), playTrack(002), playTrack(003) or the SFEMP3Shield library need to be fixed.

the parameter of function playTrack is int. the function builds the name as you see in my answer. read the answer again

I've read your answer several times.I understand the sketch does add two zeros. it needs to add two MORE zeros or the SFEMP3Shield library needs to be fixed.

but SD card supports only 8 characters long names (plus file extension)

from where do you have the library?

The names are 8 characters or less. The five digit number shouldn't be there. I didn't put it there. Like I said, I have downloaded from several places older & newer versions all with the same result. Could you send me a link to where you believe I can get a right one?

https://github.com/madsci1016/Sparkfun-MP3-Player-Shield-Arduino-Library

Thank You, I'll download and replace existing library.

Did it. No change!

so MP3ButtonPlayer2 example doesn't play track001.mp3? is the file a valid mp3 file? or you have some other sketch? if yes, add it to Question

Yes MP3ButtonPlayer2 example doesn't play track001.mp3 that is a valid mp3 file. As explained above it does play using "File Player" when I serial input  0000X.

and you have buttons connected to A0, A1, A2? And when you press button on A2 it prints "B_NEXT pressed, Start Playing Next Track #1" and doesn't play?

Yes, buttons are connected to A0, A1, A2? And when A2 is pressed it prints "B_NEXT pressed, Start Playing Next Track #1" and doesn't play

can you make a small modification to playTrack function in library? change char trackName[] = "track001.mp3"; to char trackName[13];

Where? Examples, keywords, SFEMP3Shield.cpp, SFEMP3Shield.h, SFEMP3ShieldConfig.h, SFEMP3Shieldmainpage.h

SFEMP3Shield.cpp

next you can try to change the parameter type from uint8_t trackNo to int trackNo, because that is right for sprintf.

Okay, I found it in SFEMP3Shield.cpp and can only open in wordpad or notepad When I change it it won't let me save because I don't have administrator permission

uint8_t trackNo to int trackNo is that in the sketch?

I changed uint8_t track =0; to int track =0; in the sketch. No change.

Okay, I opened SFEMP3Shield.cpp with visual studio and changed char trackName[] = "track001.mp3"; to char trackName[13]; No change.

Do you know what this means? C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp: In member function 'uint8_t SFEMP3Shield::vs_init()':
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:292:34: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
if(VSLoadUserCode("patches.053")) return 6;

variable track is unused. you should change the parameter trackNo

I'm sorry, I don't know what that means.

There is no trackNo in the sketch

the snippet in my answer. first line

uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){ to uint8_t SFEMP3Shield::playTrack(int trackNo){

There is no "trackNo" in the sketch are you referring to somewhere else?

in SFEMP3Shield.cpp playTrack

will not compile. 'uint8_t SFEMP3Shield::playTrack(int)' does not match any in class 'SFEMP3Shield'

sorry, I forgot that it will require change in the .h. I add to answer a modified version of the playTrack function. try this

I'm sorry, I can cut and paste, but I need to know what & where.

from the Answer to SFEMP3Shield.cpp

I don't know what the Answer to SFEMP3Shield.cpp is.

copy/paste from answer, here on SE. my Answer to your Question. I edited it. scroll up

I'm lost, Where is here on SE?

https://arduino.stackexchange.com/questions/57147/playing-mp3-shield-tracks/57148#57148

still lost, I went through that before, you said will require change in the .h.

which we do not make, instead we use the unused variable to have type int. sprintf doesn't like uint8_t

I'm not a programmer, I don't know what any of that means, sorry.

I'm sure I made all the changes you specified with the following result; C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp: In member function 'uint8_t SFEMP3Shield::vs_init()':
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:292:34: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
if(VSLoadUserCode("patches.053")) return 6;
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp: At global scope:
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:1025:9:

error: prototype for 'uint8_t SFEMP3Shield::playTrack(int)' does not match any in class 'SFEMP3Shield'
uint8_t SFEMP3Shield::playTrack(int trackNo){
In file included from C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:9:0:
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.h:691:13: error: candidate is: uint8_t SFEMP3Shield::playTrack(uint8_t)
uint8_t playTrack(uint8_t);
exit status 1
Error compiling for board Arduino/Genuino Uno.

yes. the parameter must be uint8_t. revert this change. the first 'error' is only a warning. it was always there

It seems I'm going in circles, we're right back where we were. Are you able to make the changes you want to SFEMP3Shield\SFEMP3Shield.cpp and give me a link to it so you can be sure it's the way you want it? I still believe the problem is the 5 digit index. Where is that generated?

it is generated in FilePlayer example with SerialPrintPaddedNumber(count, 5 );

I cannot find SerialPrintPaddedNumber(count, 5 ); in FilePlayer example.

I do find it in SFEMP3Shield\SFEMP3Shield.cpp Line 184& Line 621

I would expect the index to change when I change the 5 to 3 but it does not.

Are you able to make the changes you want to SFEMP3Shield\SFEMP3Shield.cpp and give me a link to it so you can be sure it's the way you want it?

in the Answer is the original and the modified version of playTrack function

SerialPrintPaddedNumber is the last function in the sketch. this numbering is nothing general. it is the way the sketch uses to get user's choice

Where is the Answer?

we are commenting it here. scroll up

reloaded SFEMP3Shield\SFEMP3Shield.cpp modified playTrack function from above. No progress, MP3ButtonPlayer2 does everything but play. I asked you before, do you know how to add leading zeros to a string?

yes. the playTrack function does it as you can see in Answer and the SerialPrintPaddedNumber function in FilePlayer example does it too


text:
Not receiving data from NRF24L01
I'm trying to send data from one Arduino board to another using NRF24L01 connect to the two ends of the two Arduino boards. The Tx blinks in the transmitting end(Arduino board 1) but the receiving end(Arduino board 2) is not getting any value from it. Here is my code.
Transmitting end (Arduino board 1)
#include <SPI.h>
#include "RF24.h"

RF24 myRadio(0, 1);
byte addresses[][6] = {"0"};

struct package
{
    int id = 1;
    float longitude = 0.0;
    float latitude = 0.0;
    char text[100] = "Geographic coordinates";
};

typedef struct package Package;
Package data;

void setup()
{
    Serial.begin(115200);
    delay(1000);
    myRadio.begin();
    myRadio.setChannel(115);
    myRadio.setPALevel(RF24_PA_MAX);
    myRadio.setDataRate(RF24_250KBPS);
    myRadio.openWritingPipe(addresses[0]);
    delay(1000);
}

void loop()
{
    myRadio.write(&data, sizeof(data));

    Serial.print("\nPackage:");
    Serial.print(data.id);
    Serial.print("\n");
    Serial.println(data.longitude);
    Serial.println(data.latitude);
    Serial.println(data.text);
    data.id = data.id + 1;
    data.longitude = data.longitude + 0.1;
    data.latitude = data.latitude + 0.1;
    delay(1000);
}

Receiving end (Arduino board 2)
#include <SPI.h>
#include "RF24.h"

RF24 myRadio(7, 8);
struct package
{
    int id = 0;
    float longitude = 0.0;
    float latitude = 0.0;
    char text[100] = "empty";
};

byte addresses[][6] = {"0"};

typedef struct package Package;
Package data;

void setup()
{
    Serial.begin(115200);
    delay(1000);
    myRadio.begin();
    myRadio.setChannel(115);
    myRadio.setPALevel(RF24_PA_MAX);
    myRadio.setDataRate(RF24_250KBPS);
    myRadio.openReadingPipe(1, addresses[0]);
    myRadio.startListening();
    delay(1000);
}

void loop()
{

    if (myRadio.available())
    {
       while (myRadio.available())
       {
           myRadio.read(&data, sizeof(data));
       }
        Serial.print("\nPackage:");
        Serial.print(data.id);
        Serial.print("\n");
        Serial.println(data.longitude);
        Serial.println(data.latitude);
        Serial.println(data.text);
    }

}

This is how i connected the Arduino and NRF24L01

Any reason why im not getting the the data from the transmitting end?

try myRadio.readBytes(&data, sizeof(data)); What nRF24 library you use?

@Juraj RF24.h by TMRh20

it doesn't implement Stream so it doesn't have readBytes

@Juraj you mean like myRadio.available() >= sizeof(data) ?

it will not work. I deleted the comment. the struct is bigger then the receive buffer

it can transfer only 32 bytes payload. send and receive the data in 32 byte parts

So should i change the struct?. This worked few weeks ago and now it is not. i bought new Arduino and NRF24 module still no luck :(

with the same library and this struct? perhaps it worked, but it didn't transfer the whole char array

change while (myRadio.available()) to if (myRadio.available())

Check the reading and writing pipe addresses.
First, the default is 0xE7E7E7E7E7 for pipe 0 (RX_ADDR_P0) and 0xC2C2C2C2C2 for pipe 1 (RX_ADDR_P1), see the data sheet.  Check that the transmitter (TX) address is the same as the receiver
(RX) pipe address.
Secondly, you should not set the pipe address to 0x0 even if that's common between the TX and RX.  This note comes from the data sheet:

Addresses where the level shifts only one time (that is, 000FFFFFFF) can often be detected in
  noise and can give a false detection, which may give a raised Packet Error Rate. Addresses
  as a continuation of the preamble (hi-low toggling) also raises the Packet Error Rate

Actually the pipe address is "0" which is a string with implicit null terminator, which corresponds to 30 00 - which is still as bad. Also I don't know how the library fills up the missing 3 bytes from the address. In any case not knowing the real address can be troublesome. Better try something like "Link1" or something with 5 characters.

source: Stack Exchange

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

sort: votes


text:
Can I switch from Serial to SoftwareSerial at runtime with the same baud?
I'm trying to use a GPS and the Adafruit thermal printer module with an Arduino Nano in the same project (both use baud 9600) and was wondering if I could do something like in the code below? Basically, in the example I made, I'm getting the time from the GPS and when it's on the minute, it will call the printTime() method.
What I'm wondering is if it's okay to do what I did in my disableGPS, enablePrinter methods by ending the serial connection for GPS and starting it for my printer? I feel like this should work, but I don't fully understand serial connections.
If this doesn't work, is there an alternative I could do? I never need to read from GPS and write to the printer at the same time in code.
#include <Adafruit_Thermal.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define PrinterTXPin 6 // Arduino transmit  YELLOW WIRE  labeled RX on printer
#define PrinterRXPin 5 // Arduino receive   GREEN WIRE   labeled TX on printer

static const uint32_t baud = 9600;
//Printer
SoftwareSerial PrinterSerial(PrinterRXPin, PrinterTXPin);
Adafruit_Thermal printer(&PrinterSerial);
//we only want to print on the minute
boolean havePrinted = false;

//GPS
TinyGPSPlus gps;
TinyGPSDate lastDate;

void setup() {
  enableGPS();
}

void loop()
{
  if(gps.time.isValid() && checkDate(gps.time)){
    printTime(gps.time);
  }
}

boolean checkDate(TinyGPSTime theTime)
{
 if(theTime.second() == 0 && !havePrinted)
 {
    havePrinted = true;
    return true;
 }
 if(theTime.second() == 1){
    havePrinted = false;
 }
}

void printTime(TinyGPSTime theTime)
{
  //Disable since we can only have 1 serial connection per baud
  disableGPS();
  enablePrinter();

  printer.doubleHeightOn();
  printer.println(theTime.hour() + ":" + theTime.minute());
  printer.feed(1);

  disablePrinter();
  enableGPS();
}

void enablePrinter()
{

  PrinterSerial.begin();
  printer.begin();
  printer.wake();
}

void disablePrinter()
{
  printer.sleep();
  PrinterSerial.end();
}

void disableGPS()
{
  Serial.end();
}

void enableGPS()
{
  Serial.begin(baud);
}

your description is not completely clear ... are you connecting the printer and the GPS to the same serial pins?

Serial.end() does not take any parameters. So Serial.end(baud) is wrong

Hey jsotola, hardware serial Serial is done through the serial pins on the nano 0 and 1 while SoftwareSerial can use any digital pins (In this case PrinterTXPin and PrinterRXPin).
chrisl - noted.

I think you are missing what the baud rate is.  It is the speed at which the data is transmitted.   So the fact that your two devices are the same is not an issue.   It looks like from the code that your gps is connected to the hardware serial(pins 0,1 on uno) and the printer is on a software serial( pins 5,6)   If this is the case, there is no reason to turn off either of them, they can both work. In the case of using multiple SOFTWARE serial connections, only one can be 'listening' at any time, so you must switch between them. This is not the case in your code, as there is only one software serial connection.

Ohhh. Thank you so much! For some reason, I assumed all Serial transmissions were pooled into the same I/O and the baud had to be unique for each Serial device!

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


text:
Decoding RF receiver signals
By using the following draft i decode the signals from an RF receiver
#define CH1 2
#define CH2 3
#define CH3 4
#define CH4 5
#define CH5 6
#define CH6 7

int ch1Time, ch2Time, ch3Time, ch4Time, ch5Time, ch6Time = 0;
void channels()
{
  TCNT1 = 0;
  ch1Time = 0; ch2Time = 0; ch3Time = 0; ch4Time = 0; ch5Time = 0; ch6Time = 0;

  while ((PIND & ((1 << CH1) | (1 << CH2) | (1 << CH3) | (1 << CH4) | (1 << CH5) | (1 << CH6))))
  {
    if (PIND & (1 << CH1))
      ch1Time = TCNT1;

    if (PIND & (1 << CH2))
      ch2Time = TCNT1;

    if (PIND & (1 << CH3))
      ch3Time = TCNT1;

    if (PIND & (1 << CH4))
      ch4Time = TCNT1;

    if (PIND & (1 << CH5))
      ch5Time = TCNT1;

    if (PIND & (1 << CH6))
      ch6Time = TCNT1;
  }
}

The issue is that i need also to use the 6 PWM's of the nano board.
So i thought of moving the channels 1-6 to the analog pins like so..
#define CH1 A0
#define CH2 A1
#define CH3 A2
#define CH4 A3
#define CH5 A4
#define CH6 A5

while ((PINC & ((1 << CH1) | (1 << CH2) | (1 << CH3) | (1 << CH4) | (1 << CH5) | (1 << CH6))))
  {
    if (PINC & (1 << CH1))
      ch1Time = TCNT1;
etc...

but it simply does not work. Any thoughts please?

I see two immediate problems:

The macros A0-A5 are the numbers 14 to 19, not the numbers 0 to 5 - so you're looking at (1 << 14) for CH1 not (1 << 0).
The analog pins are port C not port B, so you need to use PINC not PINB.
Your ch?Time variables should be volatile.

Oups. I am actually using PORTC and that is a typo. I will edit it asap. The channels method is called by... attachInterrupt(0, channels, RISING);

Actually i do not get it. (PINC & (1 << 0)) for CH1 does not work also, with pinMode(A0, INPUT);

Added the volatile option but the issue remains.

@OrElse Are you sure you want to be clearing TCNT1 just before you read from it?

Actually yes. This way by counting the time, i decode the RF receiver signal which is from 1ms to 2ms. Plus this works great on digital inputs. TCCR1A = 0;
TIMSK1 = 0;
TIFR1 = 0;
TCNT1 = 0;
TCCR1B = (1 << CS10); Thank you for all your effort

Ah yes, I see what you're doing with it now.


text:
SIM808 GPS+GSM Vehicle Tracking using Maduino Zero SIM808 GPS Tracker V3.5
I'm learning about GPS technology and I bought the Maduino Zero SIM808 board V3.5 to design a vehicle tracker. I have found source code for the project online.  After I upload the code to Maduino board, the code executes fine.
I'm sending "Location" to the device and i'm expecting reply with google map on my phone to be able to check device location, but i'm not getting reply from the device. i have changed the AT commands to test if i will get reply from the device, here is the source where i got the project: https://how2electronics.com/gps-gsm-based-vehicle-tracking-system-using-arduino/
Here is my output from the code:
Text Mode: ON
GPS Intializing…
GPS Initialized
Location:
Send sms to get the location

#include<string.h>

#define DEBUG true

int PWR_KEY = 9;
int RST_KEY = 6;
int LOW_PWR_KEY = 5;

String msg = String("");
int SmsContentFlag = 0;
String mob;
String loct;
void setup()
{
  pinMode(PWR_KEY, OUTPUT);
  pinMode(RST_KEY, OUTPUT);
  pinMode(LOW_PWR_KEY, OUTPUT);
  digitalWrite(RST_KEY, LOW);
  digitalWrite(LOW_PWR_KEY, HIGH);
  digitalWrite(PWR_KEY, HIGH);

  //      String msg = String("");
  //    int SmsContentFlag = 0;

  SerialUSB.begin(115200);
  Serial1.begin(115200);
  //modulePowerOn();
  delay(2000);
  SerialUSB.println("Checking Module...");
  int i = 1;
  String res;
  while (i) {
    Serial1.println("AT");
    while (Serial1.available() > 0) {
      if (Serial1.find("OK"))
        i = 0;
    }
    delay(500);
  }
  SerialUSB.println("Module Connected");
  //GprsTextModeSMS();
  SerialUSB.print("Text Mode: ");
  i = 1;
  while (i) {
    Serial1.println("AT+CSMP=17,167,0,0");
    delay(100);
    Serial1.println("AT+CMGF=1\r");
    while (Serial1.available() > 0) {
      if (Serial1.find("OK"))
        i = 0;
    }
    delay(500);
  }
  SerialUSB.println("ON");
  Serial1.println("AT+CGNSPWR=1");
  delay(100);
  Serial1.println("AT+CGNSSEQ=RMC");
  SerialUSB.println("GPS Intializing...");
  delay(5000);
  SerialUSB.println("GPS Initialized");
  SerialUSB.flush();
  i = 1;
  String str;
  while (i) {
    Serial1.println("AT+CGPSINF=0");
    delay(100);
    while (Serial1.available() <= 0);
    if (Serial1.find("AT+CGPSINF=0")) {
      str = Serial1.readString();
      //SerialUSB.println(str);
      i = 0;
    }
    delay(500);
  }
  loct = str.substring(4, 23);
  SerialUSB.print("Location: ");
  SerialUSB.println(loct);
  //while(1);
  SerialUSB.println("Send sms to get the location");
}

void loop()
{
  char SerialInByte;

  if (Serial1.available())
  {
    //char SerialInByte;
    SerialInByte = (unsigned char)Serial1.read();
    if ( SerialInByte == 13 ) //0x0D
    {
      ProcessGprsMsg();
    }
    if ( SerialInByte == 10 )
    {
    }
    else
    {
      //EN: store the current character in the message string buffer
      msg += String(SerialInByte);
    }
  }
  if (SmsContentFlag == 1) {
    int i;
    SerialUSB.println("Flag Cleared");
    SerialUSB.print("Message: ");
    SerialUSB.println(msg);
    if (msg.indexOf("Location")) {
      SerialUSB.println("Message Received");
      i = msg.indexOf("+27");
      //SerialUSB.print("index: ");
      //SerialUSB.println(i);
      //SerialUSB.println(msg[i+1]);
      i = i + 3;
      for (int j = 0; j < 10; j++, i++) {
        mob += msg[i];
      }
      SerialUSB.print("Mobile: ");
      SerialUSB.println(mob);
      String cmd = "AT+CMGS=\"";
      cmd += mob;
      cmd += "\"";
      cmd += "\r";
      Serial1.println(cmd);
      delay(100);

      Serial1.print("Your Vehicle Current Location ");
      Serial1.print(loct);
      Serial1.print("\n");
      Serial1.print("Check Map: \n");
      Serial1.print(" https://www.google.com/maps/@");
      Serial1.println(loct);
      Serial1.println((char)26);
      delay(1000);
    }
    ClearGprsMsg();
    SmsContentFlag = 0;
    msg.remove(0);
    mob.remove(0);
  }
  delay(100);
}

// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS()
{
  Serial1.println( "AT+CMGF=1" );
}

void GprsReadSmsStore( String SmsStorePos )
{
  // Serial.print( "GprsReadSmsStore for storePos " );
  // Serial.println( SmsStorePos );
  Serial1.print( "AT+CMGR=" );
  Serial1.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg()
{
  msg = "";
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg()
{
  SerialUSB.println("");
  //  Serial.print( "GPRS Message: [" );
  SerialUSB.print( msg );
  //    Serial.println( "]" );
  if ( msg.indexOf( "Call Ready" ) >= 0 )
  {
    SerialUSB.println( "*** GPRS Shield registered on Mobile Network ***" );
    GprsTextModeSMS();
  }

  //EN: unsolicited message received when getting a SMS message
  if ( msg.indexOf( "+CIEV" ) >= 0 )
  {
    SerialUSB.println( "*** SMS Received ***" );
  }

  //EN: SMS store readed through UART (result of GprsReadSmsStore request)
  if ( msg.indexOf( "+CMT:" ) >= 0 )
  {
    // EN: Next message will contains the BODY of SMS
    SmsContentFlag = 1;
    // EN: Following lines are essentiel to not clear the flag!
    //ClearGprsMsg();
    return;
  }

  // EN: +CMGR message just before indicate that the following GRPS Shield message
  //     (this message) will contains the SMS body
  if ( SmsContentFlag == 1 )
  {
    SerialUSB.println( "*** SMS MESSAGE CONTENT ***" );
    SerialUSB.println( msg );
    SerialUSB.println( "*** END OF SMS MESSAGE ***" );
    //ProcessSms( msg );
  }

  /*ClearGprsMsg();
    //EN: Always clear the flag
    SmsContentFlag = 0; */
}

Did you mean "device will not reply with google map link"?  It's not clear (to me anyway) what the problem is that you're suggesting may have something to do with your network connection.

I'm sending "Location" to the device and i'm expecting reply with google map to be able to check device location, but i'm not getting reply from the device.  i have changed the AT commands to test if i will get reply from the device, here is the source where i got the project: https://how2electronics.com/gps-gsm-based-vehicle-tracking-system-using-arduino/

remove all GPS code ... reduce your code to only a simple text reply ... something like receive any text, reply "hello world"


text:
Is this LED Strip Schematic correct?
I am trying to simulate a 12V LED strip as per this tutorial. However the schematic I tried to make on EasyEDA looks quite different from the images on the website. I wanted to know if what I did is correct.

Schematic and wiring diagram are not the same. They seem to use different RGB LEDs. The wiring diagram has common anode RGB LEDs, while your schematic uses a common cathode RGB LED. The difference is, which side of the LED gets switched.
In the common anode configuration, all anodes (positive lead) of the individual color LEDs are connected together, while the cathodes (negative leads) are brought out, so that you can switch them via the MOSFETs. That means, that the MOSTFETs are connected between the strips color component pins and ground.
In the common cathode configuration, all cathodes (negative lead) of the individual color LEDs are connected together, while the anodes (positive leads) are brought out for you to switch them. In this case, the MOSFETs are connected between the strips color component pins and Vcc.

Besides that, you should be careful with providing 12V at Vin of an Arduino Uno. While it is possible, you can very fast get the linear voltage regulator to overheat, when providing 12V. It dissipates the excess voltage (so 7V, to get it to 5V down) as heat. The voltage regulator is not cooled, so you might run into this issue, with the wiring diagram. It depends on your much current you draw from the regulator.


text:
How do i improve this Code? (or how to pass a Char String into a Function to behave like a Variable)
Sorry i am a beginner and amateur when it comes to coding, can somebody help me to make the code inside the loop() less "monkey-like" by using a proper function?
I have tried a lot and at some point i am running out of ideas about how to even phrase the question on google.
My main problem when writing a function for this case is that i don't know how to pass a variable into a function which has to be written out as part of a Variable but also as part of Char Strings if that makes sense.
If you look at the code inside the loop() i actually only had to pass the number to the function, like "3" to change some Variables and Char Strings accordingly. I would be able to solve the issue with those Char Strings but i am completely clueless how to handle the Variable (rmd3, rmd4...).
"3" as in:
Variable:        rmd3,    Char String      "rmd3 = 1",   Variable Value:  rotary_mode = 3   and Char String:     "rotary_mode = 3"
This is a simplified version of my code but boils down to where i am stuck at. It refers to a rotary selector i am using which has 6 Positions (rmd1 - rmd6). However if i knew how to solve this issue i could use it in many other situations as well.

Bounce rmd3 = Bounce(45,10);    //rotary selector on pos.3
Bounce rmd4 = Bounce(44,10);    //rotary selector on pos.4
int rotary_mode = 0;            //Rotary Mode

void setup() {
  Serial.begin(11520);
  pinMode(45, INPUT_PULLUP);   //pin of pos.3
  pinMode(44, INPUT_PULLUP);   //pin of pos.4
  }

void loop() {
             rmd3.update();
             if (rmd3.fallingEdge()) {
                Serial.print("rmd3 = 1");
                rotary_mode = 3;
                Serial.print("rotary_mode = 3");
             }
             if (rmd3.risingEdge()) {
                Serial.print("rmd3 = 0");
                rotary_mode = 0;
                Serial.print("rotary_mode = 0");
             }

             rmd4.update();
             if (rmd4.fallingEdge()) {
                Serial.print("rmd4 = 1");
                rotary_mode = 4;
                Serial.print("rotary_mode = 4");
             }
             if (rmd4.risingEdge()) {
                Serial.print("rmd4 = 0");
                rotary_mode = 0;
                Serial.print("rotary_mode = 0");
             }
}´´´

Pseudocode:

´´´void loop() {
int rmd_int;            //Mode numbers as int from 1 to 6
char rmd_char = [2];    //Mode numbers as char from "1" to "6"

              rmd3.update();
              rmd_int = 3;
              rmd_char = "3";
              void selected_mode(rmd_int, rmd_char);
}

void selected_mode(int rmd_int, char rmd_char ){
             if (rmd[rmd_int].fallingEdge()) {
                Serial.print("rmd[rmd_char] = 1");
                rotary_mode = [rmd_int];
                Serial.print("rotary_mode = [rmd_char]");
             }
             if (rmd[rmd_int].risingEdge()) {
                Serial.print("rmd[rmd_char] = 0");
                rotary_mode = 0;
                Serial.print("rotary_mode = 0");
             }
}```

I really don't understand, what you are saying there. You are talking about providing a char string as function parameter, but I don't see such a function in your code. You don't show any function other than the standard loop() and setup() functions. And the description unfortunately is a mess. I understand, that it is difficult to explain, when you may have misconceptions or not understanding enough to find the correct words. Maybe you can show us directly with your code, what you are trying to do.

Do you want to pass a character array, as an argument, to a function?

It can sometimes help to write "pseudocode" to describe how you want your program to work. There's no syntax rules, and nothing you cannot do - just write your code as if everything you wanted to do could be done in any way you want to do it. Then we may be able to work out from that what it is you intend your code to do.

Whenever you start putting numbers on variable names and then want to use them, what you really want is an array.  With an array you can use those numbers to refer to different things.  What you want to do with a char array won’t work.   Aria me names only exist in the code as you write it.  They all become memory addresses once the code is compiled.  There is no concept of a variable name at runtime.

I added a Pseudocode so you could mabye get a picture what i mean. Left it out at first because i know its wrong and may cause confusion.

It's still unclear why you want to use the char though.  Is it just so you can print out the number 3 ?  If that's what you want the Serial.print(rmd_int); will do that for you. And if you want to printout the integer inside of a string you can use Serial.printf("here is an int : %i", rmd_int);

The question is somewhat confused, but I think I got what you mean. Your
code suffers from too much repetition. You only showed the handling of
two selectors, but you want to handle 6 of them. Repeating all the logic
6 times would make the code unwieldy and hard to maintain. So you
want to put the logic in a function and just call that function six
times.

I actually only had to pass the number to the function, like "3" to
change some Variables and Char Strings accordingly

You do not need to pass the number as a string: you can use
Serial.print() to format the number instead. And you do not need to
write a function either: you can just put a for loop inside the
loop() function:
const int rmd_count = 6;

Bounce rmd[rmd_count] = {
    Bounce(48, 10),  // rotary selector on pos. 0
    Bounce(47, 10),  // rotary selector on pos. 1
    Bounce(46, 10),  // rotary selector on pos. 2
    Bounce(45, 10),  // rotary selector on pos. 3
    Bounce(44, 10)   // rotary selector on pos. 4
    Bounce(43, 10)   // rotary selector on pos. 5
};

void loop() {
    for (int i = 0; i < rmd_count; i++) {
        rmd[i].update();
        if (rmd[i].fallingEdge()) {
            Serial.print("rmd[");
            Serial.print(i);
            Serial.println("] = 1");
            rotary_mode = i;
            Serial.print("rotary_mode = ");
            Serial.println(i);
        }
        if (rmd[i].risingEdge()) {
            Serial.print("rmd[");
            Serial.print(i);
            Serial.println("] = 0");
            rotary_mode = 0;
            Serial.println("rotary_mode = 0");
        }
    }
}

The key to using for loops is to structure your data in arrays,
instead of collections of variables named with numbers. Thus, instead of
rmd3 you would use rmd[3]. Note that array indices start at zero.
Obviously, you could put the body of the for loop inside a function,
but at this point that would not help much in simplifying the code.

Edit: As a clarification, and per Delta_G's suggestion, I'll try to
explain the difference between an array and a collection of variables.
Each variable you define is mapped by the compiler (technically, the
linker) to a memory area. You can think of the variable names as
convenient names assigned to those memory locations. If you write:
Bounce rmd0(48, 10), rmd1(47, 10), rmd2(46, 10), ...;

You get:
      ┌───────┐        ┌───────┐        ┌───────┐
rmd0: |       |  rmd1: |       |  rmd2: |       |  ...
      └───────┘        └───────┘        └───────┘

In the picture above, the boxes are the memory areas. They are large
enough to hold a Bounce object, i.e. their size is sizeof(Bounce).
Each one has a name. You have no control over where, within the memory,
those variables are allocated: it's the linker's call.
In contrast, when you declare an array, you get a single variable
which is mapped to a contiguous memory area large enough to hold the
whole array:
Bounce rmd[6] = { ... };

Gives:
     ┌───────┬───────┬───────┬───────┬───────┬───────┐
rmd: |       |       |       |       |       |       |
     └───────┴───────┴───────┴───────┴───────┴───────┘

The individual cells do not have a name, and you instead use indices to
access them. For instance, rmd[0] references the first cell. Please,
note that in this example there is no variable named rmd0: if you try
to use that identifier the compiler will complain it is not defined.
Again, an array is not a “collection of variables”: it is a single
variable.
The array cells do behave in some sense much like individual variables
(they are called lvalues), as you can use rmd[0] in the same way you
would have used rmd0 in the previous code. The point of using an array
is that the indices do not need to be literals: you can use a variable
instead (rmd[i], where i is a variable), which comes handy when you
want to loop over all the cells.

Edgar pointed out that I can write the variable rmd3 by int i = 3
and rmd[i].

I hope it is now clear that this is not the case. There is no variable
named rmd3 unless you create it explicitly. Declaring an array named
rmd does not create such a variable.

[Can I] "form" a variable by "characters"?

Your question is not very clear, but my guess is you are talking about
computed variable names. This is a programming technique where you
access a variable by computing its name at run time. For example, you
combine the strings "rmd" and "3" in order to build the name of the
variable "rmd3". Then you use this computed name to access the variable
that has this name.
Computed variable names are quite often supported by interpreted
languages. For example, in PHP this is called variable variables:
$foobar = 42;           // the variable we want to access
$start = "foo";         // one piece of the name
$end = "bar";           // the other piece
$name = $start . $end;  // build the name from its pieces
print $name . "\n";     // prints the variable name: "foobar"
print $$name . "\n";    // prints the variable's value: "42"

Computed variable names are not supported by C++, which is the
language you use to program an Arduino. And for a good reason: when the
compiler translates your program to machine code, the names of the
variables are lost, they do not make their way to the actual Arduino.
And this is a good thing, as you would not want those names to consume
memory on the microcontroller.
Note that the names are present in the .elf file, as they could be
useful for debugging. If you were programming for a PC, you program
could in principle look into the file and find those names. On Linux you
would do that with the dlopen() and dlsym()
functions, from the libdl library. The libdl technique is, however, very
far from the capabilities of your typical Arduino, orders of magnitude
more complex than a simple array, and perfectly useless for your use
case.

Brilliant, thanks! I did not know i can form the Variable rmd3 by rmd[i] and int i=3. Now i am wondering if this only works with numbers or if it would work as well by something like char i[] = "3".

I think this answer would be greatly improved by making sure it is apparent that you are using an array and not the list of variables that the OP had.  From the question in this comment it would seem that the OP is still confused about how that will work.

You're not "forming a variable" with rmd[i] and a 3.  He's gotten rid of your variables entirely and created an array.  With an array you can use an index to choose which member of the array you want to talk about, in this case member 3 which is the fourth member since counting always starts at 0.  Note the line that starts "Bounce rmd[rmd_count]" where the array is created.  Note that at no point to we create anything called rmd3.  We instead create an array simply called rmd (without any numbers) which contains several of those Bounce objects.

Yeah i got that, he is using an array but english is not my native tongue so i didn't knew how else to call it. So if variables are just adresses would it work with pointers somehow? All i care is the result... i got over 1800 lines of code for the same crap repeating over and over again but just with different variables. The only point of the code i posted at first as to make it "easy" otherwise i had to past 1800 lines of code.


text:
Sensor to measure distance on inverted pyramid filled with maize
I'm struggling with the following problem:
I have an inverted pyramid, supported in four points, filled with maize up to 600KG.
I want to keep track of the level of maize inside the inverted pyramid.
I've thought about using a load cell but this can be expensive and I need a cheap solution to implement. I also thought about using a sensor centred on top of the inverted pyramid.
The problem here is that I really dont't know what kind of sensor can be used to get correct values.
Can ultrasonic sensors give me bad values? The pyramid form is tricky...
PS: Theoricly can mill be too reflective and influence the result of measures?
I'm sorry for the English :P. I'm still learning.
If anyone can help I really appreciate.
Best Regards

About what size are we speaking here?

are you talking about the whole ears of corn or just the seeds?

The pyramid has 1.80 m of height and at the top (inverted pyramid)  is 2m.

@jsotola It's just the seeds to be ground (milled?).

i am guessing that the "inverted pyramid" is a funnel, so there is a discharge port on the bottom .... i wonder if a large rubber ball would "float" on top of the seeds ... if it does "float", then you could monitor its position somehow, but you would have to keep it out of the discharge port

other thought ... some type of a pressure sensor placed near the bottom of the container

@jsotola Yes. It's a funnel and at the bottom have a discharge port.
Floating is possible but with this mechanism when I will fill the pyramid I need to put the rubber ball at the top and after that start... And I'm trying to get a full automatic fill. I think that with this solution I can get some troubles right?

@jsotola I forgot to mention but the container can hold up to 600KG.

Maybe a laser time-of-flight distance sensor (as the ones you can get in a hardware store) is working here. Though I'm not sure, if the maize is a good reflector for the light. Can you try out, or is this theoretical for now?

@chrisl I'm trying to understand the behaviour of the suggested sensor and could be possible with that. And Yes I can do some experiments. Have you any reference of the sensor? Could be a VL53L0X?
Did you know if the surface of corn seed can disperse the laser beam and get wrong values?

Yes, this seems to be a reasonable choice. You can by a breakout board on amazon for it. And it would perfectly fit your range. I think you don't need a precision of 1mm, so the error due to the non-optimal reflective surface of the maize may not be a problem at all. But this is something you have to try. I don't have experience in measuring my distance to maize :D The sensor is interfaced with I2C and I'm sure there are some libraries for it out there in the internet

optical sensors may fail because of the amount of dust that would collect on the sensor or on a window used by the sensor

@jsotola good point.

i just googled grain level sensor and got this http://www.rhinohydeproducts.com/products/grain/bin-level-sensors/  .... it indicates that it is a capacitive sensor .... no idea how it would work

look at the top leftmost one on this page ... https://www.binmaster.com/products .... there is a mechanical drawing on the website

The surface of corn is hard enough to reflect sound from an ultrasonic sensor. It reflects from fabric, skin and of course, plastic, and corn fits into the realm of reflectivity.
An Arduino with an ultrasonic sensor may scatter a good bit of the reflection, but some of it will get back to the receiver in sufficient condition to be registered.
The components necessary to test this are low enough cost to suggest a prototype. A simple pail or bucket filled with the grain and attached to a rope and pulley will give you distance information, and that would be for a relatively small surface area.
Ultrasonic sensors typically have a minimum distance and of course, a maximum distance. If your concern is for both full and empty conditions, dual sensors placed a sufficient distance apart with suitable range considerations are likely to work. The code would be written to avoid cross-pulse readings, which is likely to be trivial, as these devices operate at the speed of sound.
Lasers are point devices and may not necessarily reflect to the sensor for reading.
I have constructed a DME (distance measuring equipment) that displayed passing vehicles within a range of ten feet (~3 meters) down to slightly less than three feet (<1 meter) with good results. There was tremendous lag in the reading, but that's due to code ignorance, not hardware problems. I suspect the depth finder is not going to have much lag in determining its value to this application.

And dust can give me bad values?

I'll bet if you have enough dust to make visibility difficult, it would give you very short readings on the ultrasonic or none at all. It's not out of the question that the ultrasound would be absorbed by small enough dust particles. I'm aware that some grain silos have explosion danger due to dust.  The cost is still low enough to justify a test build, even if only in breadboard form.

You can let the sensor "sense" 20 times and let your Arduino figure out the average.
More on Using the HC-SR04 Ultrasonic Distance Sensor with Arduino.
Maybe the ultrasound also scares rodents. I am using IR sensor Sharp GP2Y0A02YK which reaches from 20-150 cm

Hi Gerrit and welcome to SE.Arduino! This is a bit of a link only answer. If the link dies, then your answer will not be terribly useful. Please consider editing your answer and quoting/including pertinent information from your link in your answer. Please take a look at the tour and How do I write a good answer. Also, take a look at other high voted answers, in order to get an idea of the standard required.


text:
Sim900a AT+HTTPREAD does not get fully answer
changed the firmware on SIM900B
try to send get request http://dummy.restapiexample.com/api/v1/employee/1
AT+HTTPACTION=0returned +HTTPACTION:0,200,98
but, when I try to read (AT+HTTPREAD or AT+HTTPREAD=0,98)the response data
I got broken response
expected result:
+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999","employee_age":"0","profile_image":""}

and actual results:
+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999","empe_"0"olme"

+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999","empe_"0"fea"}

+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999""pea:,piig"

+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999",moeg""reae}

my Arduino code looks like that
void setup() {
  Serial.begin(9600);
  mySerial.begin(57600);
  delay(5000);
  mySerial.println("AT");
  Serial.println("End of the setup");
}

void loop() {
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

Edit the question : post your arduino code.  Looks like a string overflow might be happening.

Maybe you're doing that silly "wait 5 seconds and assume there's a reply" thing I see all over the place. Or maybe you're using SoftwareSerial at 115200 baud...  No one can know - unless you share your code...

@Majenko, thanks, I've changed the baud to 9600 and it started work fine

@Majenko After doing
mySerial.println("AT+HTTPACTION=0");
mySerial.println("AT+HTTPREAD");
delay(1000);  //how do i get response without waiting a specific time.

Apparently you were running software serial at too high of a baud rate (57600) and bringing it down to 9600 fixed the issue.


text:
Sim900b(chinese sim900a) AT+HTTPACTION=(0/1)reboots the module
I am trying to make an HTTP request in two ways

Connecting sim900 to pc using TTL converter (without external power, only USB power)
Connecting sim900 using Arduino nano (tried with and without external power, with common ground)

in the first case, everything is ok
but in the second case after sending AT+HTTPACTION= the module resets
Arduino sketch
#include <SoftwareSerial.h>
SoftwareSerial sim900(3, 2);

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

void loop() {
  if (sim900.available())
    Serial.write(sim900.read());
  if (Serial.available())
    sim900.write(Serial.read());
}

Serial monitor:
AT

OK
AT+SAPBR=1,1

OK
AT+HTTPINIT

OK
AT+HTTPPARA="URL","http://veterok.xyz:8888/service/time"

OK
AT+HTTPACTION=0

OK
⸮⸮⸮⸮
RDY

+CFUN: 1

+CPIN: READY

Call Ready

how are you powering the sim900?

@jsotola I've updated the question, I tried with external power (5V ~12W) and power from Arduino

Your code SoftwareSerial sim900(3, 2); means D3 is Rx, which means that it should connect to SIM900A's Tx, but your wiring diagram connect to SIM900A's Rx.


text:
ESP32 servo runs continuous
I have ESP32 connected to TZT servo SG90.
This is the code
#include <ESP32Servo.h>
#define TURN_TIME 175

Servo myservo;  // create servo object to control a servo
// 16 servo objects can be created on the ESP32

int pos = 0;    // variable to store the servo position
// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33
#define servoPin  17
#define MOTOR_1_PIN 22

void setup() {
  pinMode(servoPin, OUTPUT);
  Serial.begin(9600);
    // Allow allocation of all timers
    ESP32PWM::allocateTimer(0);
    ESP32PWM::allocateTimer(1);
    ESP32PWM::allocateTimer(2);
    ESP32PWM::allocateTimer(3);
    myservo.setPeriodHertz(50);    // standard 50 hz servo
    // using default min/max of 1000us and 2000us
    // different servos may require different min/max settings
    // for an accurate 0 to 180 sweep
}

void loop() {

  myservo.attach(servoPin, 700, 2500); // attaches the servo on pin 18 to the servo object
  myservo.write(0);
  delay(TURN_TIME);
  for(int i =0; i<180; i++)
  {
    myservo.write(i);
    delay(TURN_TIME);
  }
  delay(3000);
  for(int i =180; i>0; i--)
  {
    myservo.write(i);
    delay(TURN_TIME);
  }
  myservo.detach();
  delay(3000);

}

My servo starts rotating one way and reverse for few degrees, then after 5 seconds the servo starts rotating at one way forever..
I had no problems with arduino and nodemcu board. What should I change in the code?
EDIT: I have connected the servo with battery, they have common ground.
The pin on esp32 that I am using is G17. "#define servoPin 17" in the code

There is no need to detach the servo in the loop. Just attach it in setup and never detach it. Detaching will stop the pwm signal, but a servo needs a continuous pwm signal even when stationary.

Without detach() the result is the same.

I didn't expect it to be the root cause... rotating at one way forever - is it actually an angle-controlled servo that you are using and do you use the exact same hard- and software like you did on the arduino/nodeMCU?

It's servo which can be rotated in 360 degrees. But when I control it with other microcontroller I can control it only 0-180. Here I have random moves and at some point rotation to infinity..

Can you figure out, at which point in your code the servo behaves unexpectedly?

I used other servo library and it worked.. Then i changed the pulse width with this line of code.
The default is 1000-2000. But it rotates only 95 degrees. When it's pushed to around ~2850us the servo rotates up to 181-185 degrees.
servo1.attach(servoPin,CHANNEL_NOT_ATTACHED, 0,180,544,2840/);
#include <Servo_ESP32.h>

static const int servoPin = 16; //printed G14 on the board
int delayTime = 20;
Servo_ESP32 servo1;

int angle =0;
int angleStep = 5;

int angleMin =0;
int angleMax = 180;
#define CHANNEL_NOT_ATTACHED -1
void setup() {
    Serial.begin(115200);
    servo1.attach(servoPin,CHANNEL_NOT_ATTACHED, 0,180,544,2840/);

}

void loop() {
    for(int angle = 0; angle <= angleMax; angle +=angleStep) {
        servo1.write(angle);
        Serial.println(angle);
        delay(delayTime);
    }

    for(int angle = 180; angle >= angleMin; angle -=angleStep) {
        servo1.write(angle);
        Serial.println(angle);
        delay(delayTime);
    }
}


text:
Getting some strange data from an MPU-6050
I'm trying to create an IMU unit using MPU-6050 unit.
I've got 100k data records, and this is the result:

It seems to me that's a kind of offset in gx. Why?

Why I'm getting this kind of drifting in acz?
This is the setup code:
void setup_mpu_6050_registers(){

  //Activate the MPU-6050

  //Start communicating with the MPU-6050
  Wire.beginTransmission(0x68);
  //Send the requested starting register
  Wire.write(0x6B);
  //Set the requested starting register
  Wire.write(0x00);
  //End the transmission
  Wire.endTransmission();

  //Configure the accelerometer (+/-8g)

  //Start communicating with the MPU-6050
  Wire.beginTransmission(0x68);
  //Send the requested starting register
  Wire.write(0x1C);
  //Set the requested starting register
  Wire.write(0x10);
  //End the transmission
  Wire.endTransmission();

  //Configure the gyro (500dps full scale)

  //Start communicating with the MPU-6050
  Wire.beginTransmission(0x68);
  //Send the requested starting register
  Wire.write(0x1B);
  //Set the requested starting register
  Wire.write(0x08);
  //End the transmission
  Wire.endTransmission();

}

And this is the reading code:
void read_mpu_6050_data(){

  //Read the raw gyro and accelerometer data

  //Start communicating with the MPU-6050
  Wire.beginTransmission(0x68);
  //Send the requested starting register
  Wire.write(0x3B);
  //End the transmission
  Wire.endTransmission();
  //Request 14 bytes from the MPU-6050
  Wire.requestFrom(0x68,14);
  //Wait until all the bytes are received
  while(Wire.available() < 14);

  //Following statements left shift 8 bits, then bitwise OR.
  //Turns two 8-bit values into one 16-bit value
  myData.msecs = millis();
  myData.acc_x = Wire.read()<<8|Wire.read();
  myData.acc_y = Wire.read()<<8|Wire.read();
  myData.acc_z = Wire.read()<<8|Wire.read();
  myData.temp = Wire.read()<<8|Wire.read();
  myData.gyro_x = Wire.read()<<8|Wire.read();
  myData.gyro_y = Wire.read()<<8|Wire.read();
  myData.gyro_z = Wire.read()<<8|Wire.read();
}

The structure that stores data is:
struct datastore {
   long msecs;
   int acc_x, acc_y, acc_z;
   int temp;
   int gyro_x, gyro_y, gyro_z;
};

Then I save data in the card:
logFile.write((const uint8_t *)&myData, sizeof(myData));

where do the graphs come from? ... how is the data in the graphs selected? ... maybe you are graphing an incorrect parameter

The graphs were made based on data saved on a CSV file in a SD card connected to arduino.

I changed the question including the data structure that's is used to store data and the code that save it.

The graphs show values much larger than can be stored in an int. Could you show a line from your CSV file?


text:
How to make 1 second delay more accurate?
I have written two (1 second) delay programs.
The first program as follows:
void setup()
{
Serial.begin(9600);
TCCR1A = 0;
TCCR1B |= (1<<CS12);
TCCR1B &= ~(1<<CS11);
TCCR1B &= ~(1<<CS10);
TCNT1 = 3036;
TIMSK1 |= (1<<TOIE1);
}

ISR(TIMER1_OVF_vect)
{
  Serial.println(millis());
  TCNT1 = 3036;
}
void loop()
{
}

Whose output is as follows:
999  // 1 sec
1999 // 2 sec
3000
3999
5000
6000
7001
8000
9000
10001
.
.
.
58012
59013
60013
61012
62013 //60 sec

It has an error of around 13 ms at 1 minute and at 1 hour it will be 780 ms and in one day it will be around 19 seconds.
The second program is as follows:
void setup() {
Serial.begin(9600);
}

void loop() {
  Serial.println(millis());
  delay(1000);
}

Whose output is near about as same as the first one's.
Is there any way to decrease the error and make it more precise? So that I can use it in my Arduino based stopwatch?

Printing to serial is the culprit here. Print the count after 1sec , 60sec, 1 hour and one days only. the result won't be as bad as you calculated

OR OR OR take a value of millis in a variable before you go for printing

Swap the Serial.println and TCNT1=... lines. As the print will take different amounts of time depending on the decimal length of the millis value.

your problem is that you are measuring time in multiple inaccurate sections .... the error of each section accumulates .... it is like measuring a 2 meter distance with a 10cm ruler .... you measure off 10cm, then move the ruler to the 10cm mark and measure off another 10cm to get the 20cm mark and so on .... each of the measurements has a small error that accumulates ..... if you use a 2m tape measure, then the error is the same as the 10cm measurement with the ruler ..... the millis() function is like a "time tape measure" that is 50 days long  ..... simply monitor millis() inside loop()

Majenko is perfectly right: you cannot expect much accuracy from an
Arduino clocked by a ceramic resonator. Typical drift is of the order of
1,000 ppm, and is affected by temperature and aging. You can,
however, get a delay which is pretty close to the CPU's idea of one
second. In other words, you can get something that is really close to a
perfect period of 16,000,000 CPU cycles. If that is what you want,
your best bet is to use a timer.
In your overflow ISR, you wrote:

Serial.println(millis());

There are two issues here. The first is the use of Serial.println()
within an ISR. This should normally avoided: since Serial relies on
interrupts, using it with interrupts disabled can lock your program if
you ever fill the output buffer. In this particular instance, it happens
to be safe, because at this rate you are never going to fill the output
buffer anyway. However, while it can be OK to do that in a small test
program like yours, I would advise you against doing it in production
code.
The other issue is the use of millis(). This function does not provide
true millisecond resolution: it is a counter that is updated every
1024 µs. Every now a then it is updated by 2 ms at once in
order to compensate for the drift. Thus, you should think of millis()
as being good to within ±2 ms. If you need anything better, use
micros().

TCNT1 = 3036;

This should be avoided. Dispatching an interrupt takes time, and this
time depends on whether there is already an interrupt handler (or other
critical section) running. If the timer happens to increment after the
interrupt fires but before you have time to execute the line above, then
you miss a timer tic. It has been suggested to you to move this line
before the Serial.println(). That would certainly reduce the risk, but
it will not completely prevent it.
The right thing to do is to never reset a timer if you want it to have
time continuity. Instead, set it to CTC mode (clear timer on compare
match) and let it reset itself when it reaches a value of your choosing.
In this case, you would have it repeatedly count from 0 to 62,499
instead of from 3,036 to 65,535.
Here is a modified version of your program illustrating the points
above:
void setup()
{
    Serial.begin(9600);
    TCCR1A = 0;            // undo the Arduino's timer configuration
    TCCR1B = 0;            // ditto
    TCNT1  = 0;            // reset timer
    OCR1A  = 62500 - 1;    // period = 62500 clock tics
    TCCR1B = _BV(WGM12)    // CTC mode, TOP = OCR1A
           | _BV(CS12);    // clock at F_CPU/256
    TIMSK1 = _BV(OCIE1A);  // interrupt on output compare A
}

ISR(TIMER1_COMPA_vect)
{
    // OK in test code, don't do this in production code.
    Serial.println(micros());
}

void loop(){}

The output is as follows;
1000048
2000048
3000048
...
58000048
59000048
60000048  // 60 seconds

Your biggest problem is that you don't know what a second is.  You have no reliable time-base to measure time against.
millis() is not accurate. You can't rely on that giving you a precise time - otherwise, something as simple as:
uint32_t secs = 0;

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

void loop() {
    if (millis() / 1000 > secs) {
        secs = millis() / 1000;
        Serial.println(millis());
    }
}

would give you a precise 1000 millisecond "delay". However, all that gives you is a precise "Arduino 1000 millisecond" delay.  That is - it triggers on the rollover between 1000 millisecond blocks where 1 millisecond is whatever the Arduino's millis() function thinks 1 millisecond is.
While it may appear to be accurate, in that it would give you round numbers "1000, 2000, 3000, 4000" etc, compare that to an external clock and you would find it's actually drifting just as bad (if not worse) than your existing methods.
The problem is, since what you are measuring the drift against is itself drifting, your measurements are completely meaningless.
If you require an exact 1-second pulse with near zero drift you will have to use an external clock source. The most accurate would be GPS. Many GPS modules have the ability to output a 1-second pulse which is synchronised to the GPS clock.
An RTC module would improve accuracy somewhat as well - again most of those have a 1Hz square wave output that can be used to synchronise things - however, even those aren't 100% accurate and rely on the accuracy of the attached crystal.  They're more accurate than the Arduino's ceramic resonator, though.

I never would have thought this day would come, but I disagree with @Majenko and @EdgarBonet.
The source of your clock is important. If the Arduino resonator is accurate enough, then you can use millis(). If you want more accuracy, then you can use a rtc like the ds3231. The ds3231 is temperature compensated for more accuracy. If you want something even better then you can use gps or a internet time server or even a long wave radio signal time server.
When you need a 1 second timer as the basis for a clock or stopwatch, then you can start by using millis() which is based upon the 16MHz resonator. The millis() is compensated with a offset, it will not drift. It runs 100% perfect with the same accuracy as the resonator. Use the blink without delay example and change the increment of previousMillis to this:
if (currentMillis - previousMillis >= interval) {
  // increment the previousMillis with the interval
  previousMillis += interval;

That way the one second interval will stay in sync with the time, even when there is a big delay now and then in the sketch.
You will not get more accuracy by using a internal timer.
Some Arduino clones have a crystal instead of a resonator. If you use one of those clones with a crystal and use millis as I mentioned above, then your timing is as accurate as the crystal. When you build a clock with that, it might run a few minutes per year out of sync with the real time.

I'm sorry... ceramic resonator "accurate enough...?"  That made my day... XD

The ceramic resonator is ±0.5%. That's 5 parts in a thousand, or 5000ppm...! A typical crystal is in the order of 100ppm. GPS is about as close to zero drift as you can get. An RTC is only as good as the crystal, regardless of temperature compensation - that only keeps the drift the same over a certain temperature range. If the crystal is already 100ppm out from the target frequency you will still drift. It just means it'll drift the same at -10C as it does at 30C.

@Majenko I don't know what the stopwatch is for. Perhaps for a toy. Perhaps a photographic or scientific experiment. The clone boards with a real crystal that is always at room temperature might be okay for many applications. Peouse Dutta, please add more information to your question. What is the stopwatch for? What is the maximum time that you want to measure? Should it operate at a large range of temperatures?

@Jot It is for a scientific experiment

@PeouseDutta: If it's for a scientific experiment, you may want to calibrate your clock and, most importantly, be aware of its limitations.


text:
1602 16×2 LCD display is not lighting up for my Automatic watering system project
I'm working on a project to create an automatic watering system using an Arduino Uno R3 board, a 16x2 LCD display, a water pump, and a soil moisture sensor. However, I've hit a roadblock and could really use some assistance.
The issue I'm facing is that my LCD display isn't lighting up at all. I've double-checked all the connections, made sure the code is correct.
Here's a rundown of my setup:

Arduino Uno R3 board
16x2 LCD display
Water pump
Soil moisture sensor

I connected:

the LCD pin VCC and GND to the breadboard + and -
the SCA pin of the LCD to the A4 analog pin of the Arduino
the SCL pin of the LCD to the A5 analog pin of the Arduino

I've followed tutorials and guides closely, but I can't seem to figure out what's causing the problem.
If anyone has experienced a similar issue or has any suggestions on how to troubleshoot this problem, I would greatly appreciate your help.
Here's the code I used:
#Include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(2, OUTPUT);
  digitalWrite(2, HIGH);
  delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("IRRIGATION");
  lcd.setCursor(0, 1);
  lcd.print("SYSTEM IS ON ");
  lcd.print("");
  delay(3000);
  lcd.clear();
}

void loop() {
  int value = analogRead(A0);
  Serial.println(value);
  if (value > 950) {
    digitalWrite(2, LOW);
    lcd.setCursor(0, 0);
    lcd.print("Water Pump is ON ");
  } else {
    digitalWrite(2, HIGH);
    lcd.setCursor(0, 0);
    lcd.print("Water Pump is OFF");
  }

  if (value < 300) {
    lcd.setCursor(0, 1);
    lcd.print("Moisture : HIGH");
  } else if (value > 300 && value < 950) {
    lcd.setCursor(0, 1);
    lcd.print("Moisture : MID ");
  } else if (value > 950) {
    lcd.setCursor(0, 1);
    lcd.print("Moisture : LOW ");
  }
}

Describing electrical connections isn't particularly helpful. A schematic diagram (or at worst a Fritzing diagram) would be an improvement. Also which LCD display? What is the pinout? There are many different versions out there. The water pump and the soil sensor seem to be irrelevant to your problem, and just confuse the issue. You should remove anything that isn't directly related to the display issue. Address one module at a time.

run the I2CScanner sketch to see if and on what address it detects the LCD

the LCD pin VCC and GND to the breadboard + and -  ... is the breadboard bus connected to the + and -? ... some breadboard buses have a break in the middle, usually indicated by a break in the red line

The LCD address might not be 0x27.
Verify the address of your LCD, by checking the manufacturer of the PCF8574 (on the back of the LCD panel). From Interface an I2C LCD with Arduino:

If your LCD has a PCF8574 chip from Texas Instruments, its I2C address is 0x27;
If it has a PCF8574 chip from NXP Semiconductors, its I2C address is 0x3F.

Or from 6v6gt's comment:

It is actually the "A" suffix (or lack of) on the chip identifier which distinguishes the I2C address range supported by the chip. NXP PCF8574 and PCF8574A see 7.1 : Remote 8-bit I/O expander for I2C-bus with interrupt TI PCF8574 see 8.4 : PCF8574 Remote 8-Bit I/O Expander for I2C Bus TI PCF8574A see ch. 7 : PCF8574A Remote 8-Bit I/O Expander for I2C Bus. Within that range, the user can of course also alter 3 solder jumpers to fine tune the address.

To quote the relevant sections:
From Remote 8-bit I/O expander for I2C-bus with interrupt

7.1 Device address
Following a START condition, the bus master must send the address of the slave it is
accessing and the operation it wants to perform (read or write). The address format of the
PCF8574/74A is shown in Figure 6. Slave address pins A2, A1 and A0 are held HIGH or
LOW to choose one of eight slave addresses. To conserve power, no internal pull-up
resistors are incorporated on A2, A1 or A0, so they must be externally held HIGH or LOW.
The address pins (A2, A1, A0) can connect to VDD or VSS directly or through resistors.

The last bit of the first byte defines the operation to be performed. When set to logic 1 a
read is selected, while a logic 0 selects a write operation (write operation is shown in
Figure 6).

From PCF8574 Remote 8-Bit I/O Expander for I2C Bus, section 8.4, Device Functional Modes, shows the address and timing diagrams for the write and read modes.
From PCF8574A Remote 8-Bit I/O Expander for I2C Bus, section 7, gives the Parameter Measurement Information, with schematics and timing diagrams.

Alternatively, as per Juraj's comment, run I2CScanner:
 // --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

void setup()
{
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

from i2c_scanner

It is actually the "A" suffix (or lack of) on the chip identifier which distinguishes the I2C address range supported by the chip.
NXP PCF8574 and PCF8574A see 7.1 : https://www.mouser.ch/datasheet/2/302/PCF8574_PCF8574A-3139141.pdf
TI PCF8574 see 8.4  : https://www.ti.com/lit/ds/symlink/pcf8574.pdf
TI PCF8574A see ch. 7 : https://www.ti.com/lit/ds/symlink/pcf8574a.pdf. Within that range, the user can of course also alter 3 solder jumpers to fine tune the address.

Ok, many thanks. Answer updated.


text:
Different pin names in 0V7670 Camera Module
I am trying to follow this tutorial, SIMPLIFIED! How to Use OV7670 Camera with Arduino (other tutorials are also the same) and I noticed that my Camera module has different pin names, what do I do?
Here are images of my module:

How do the pin names differ? Please edit and list the differences. Have you looked for a tutorial that uses the same module as yours..?

The connections are exactly the same as the tutorial that you have linked to - it is only the pin labels that differ.
Tutorial           Module
-------            ------
SIOC               SCL
SIOD               SDA
VSYNC              VS
PCLK               PCLK
XCLK               MCLK
RESET              RST
PWDN               PWWN


text:
Using tinyGPS++ with millis errors
Hi I am trying to make search GPS (using tinGPSplus) every x time. The problem is when I do compile the code:
void loop()
{
    read=BP_mnger.pressedButton();
    navigateMenus(read);
    dealWithUsedEvents(getmenuUsed());
    setmenuUsed(0);

    if (isStarted && (GPSSearchPeriod<=millis()-oldMillisVallue)) {

        oldMillisVallue=millis();// if i comment this line it works
        Serial.print(F("oldMillisVallue: "));
        Serial.println(oldMillisVallue);
        while (ss.available() > 0){
            if (gps.encode(ss.read()))
                if (gps.location.isUpdated() || gps.date.isUpdated() || gps.time.isUpdated() || gps.altitude.isUpdated() || gps.satellites.isUpdated() || gps.hdop.isUpdated())
                    GPSSentence=makeGPSSentence( );
        }

    }

I get this:
oldMillisVallue: 22355
oldMillisVallue: 24356
oldMillisVallue: 26357
oldMillisVallue: 28358
oldMillisVallue: 30359

When I comment out:
oldMillisVallue=millis();// if i comment this line it works

I get this :
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
2000,0,0,4294967295,15,43,3,36,5,41,4.066298,48.269157,77,0.12,90,380,98,2,1,3
2000,0,0,4294967295,15,43,3,39,5,43,4.066298,48.269157,79,0.122200,92,380,98,2,1,3
------------------------
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0

oldMillisVallue: 0
oldMillisVallue: 0
2000,0,0,4294967295,15,43,4,39,5,43,4.066265,48.269126,80,0.12,94,380,101,3,2,5
2000,0,0,4294967295,15,43,4,41,5,45,4.066265,48.269127,82,0.121900,94,380,103,3,2,5
------------------------
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0
oldMillisVallue: 0

You're only reading from the serial port every GPSSearchPeriod milliseconds. That gives plenty of time for the small serial read buffer to overflow and lose the data.
Instead you should be reading all the time regardless of your desire to only do things periodically. Sure, report the data periodically, but you must read all the time as well.

Just to be sure you are talking about the Serial buffer ?
"reading all the time" wouldn't that drain the battery ? my goal was like to make one GPS search each 2 seconde to save battery

The SoftwareSerial buffer, yes. Unless you are sleeping the MCU reading all the time will make no difference. You are just looking at the content of the serial buffer.

thank you very much, now i can read properly the data.
last question i tried putting the while (ss.available() > 0) with declaration of the gps in a function that i call every time as u said to save sram (the SoftwareSerial is still global) i had no output is it because the decalring the gps as local variable ?

Yes. You need the gps instance to either be global or local and static - the effect is the same (just the scope is different).

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


text:
ESP8266 WiFi Not Connecting to Internet Without Static IP
I am seeing some very strange behavior with my ESP8266. When I connect it to the WiFi for the first couple of times I am not seeing any issues and the ESP8266 connects just fine.
But after an arbitrary amount of times (like when I restart the unit) it tries to connect for AGES (like multiple minutes). Eventually it says "Connected" but the IP is completely wrong and it is not connected to the internet (GET request fails).
Here are the odd things:

If I assign a static IP then it ALWAYS works and connects within seconds
If I factory reset my router then it works again for a few times
I have not seen this with any other device (like laptops or cellphones)

It is almost as if the DHCP is failing to assign an IP and then returns some random default.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

// Replace these with your WiFi network settings
const char* ssid = "MYSSID"; //replace this with your WiFi network name
const char* password = "MYPASSWORD"; //replace this with your WiFi network password

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

  IPAddress ip(192,168,1,77);
  IPAddress gateway(192,168,1,1);
  IPAddress subnet(255,255,255,0);

// If I uncomment this line then it works fine
//  WiFi.config(ip, gateway, subnet);

  WiFi.begin(ssid, password);

  Serial.println();
  Serial.print("Connecting");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("success!");
  Serial.print("IP Address is: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  HTTPClient http;

  String serverPath = "http://www.google.com";
  http.begin(serverPath.c_str());

  // Send HTTP GET request
  int httpResponseCode = http.GET();
  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
  String payload = http.getString();
  Serial.println(payload);
  // Free resources
  http.end();

  delay(1000);
}

When DHCP magically works it assigns: 192.168.1.159
When DHCP does not work I get: 169.254.104.241
When I use a static IP then the static IP is assigned.
So the question is: Has anyone seen this behavior and maybe give some hints about how I can get the internet connection to be consistent without needing a static IP?
Update:
If I run a ping to 169.254.104.241 I get a reply. But if I try to get anything from the internet I get HTTP Response Code = -1.

Does the esp connect to wifi either case? That ip 169.254.104.241 is not valid, I guess, but does it actually get this ip (did you scan the network in that case)?

@SimSon I just ran a ping to that IP and it is responding and if I do "arp -a" then the IP shows up.
I did another test and it seems like the device doesn't have an internet connection (I think... I get HTTP Response Code -1). I updated the question.

Finally I figured out a solution. I downgraded the ESP8266 board version in Arduino Studio to 2.5.2 and it worked.

That is interesting. Is there any particular reason why you went to version 2.5.2 (the current version is 2.7.4)? What version was causing the problem? Did you try other versions?

This is normal behavior. well not really, that address is called a apipa address.
It's normal behavior for alot of O.S's to give itself an address in the 169.254.x.x range when they fail to get DHCP responses.
My guess is your library is doing this for you.
It's kind of like the ad-hoc of addressing, if all devices fail to get a dhcp response they will all be assigned to the same subnet, and can communicate with those apipa addresses.
My suspicion is that it may be your router.
You can verify this by downloading a free DHCP server application for your OS. Plug in via Ethernet for the PC that's running the DHCP App, Turn off DHCP in the router. If it stops happening you know it's the router.
Edit: Also, this may be a firmware caveat in the router. Check the router manufacturers website and see if any firmware updates are available. if it hangs with DHCP, most likely every customer with that firmware revision has had this problem. This sort of thing usually gets patched very quickly.

This was very useful information. Thanks! After your comment I just left the ESP to keep trying to GET a page from the internet and eventually like after 10 minutes it got a successful connection. I still have no idea why this is happening but for the sake of what I need I am good to leave it like this.
I will test that DHCP tool you mentioned when I get a break from work and see what happens.

Thanks for posting the question and the solution. I spent hours on google and reading message boards before coming across this. I am not sure if my root cause was the same, but to me the "strange" IP for my ESP8266 (nodemcu) came from them connecting through the Guest Network of my Asus router. This resulted in an identical problem to OP with complete random connecting and long duration of no connections to WiFi, Internet and Blynk
Reverting back to ESP8266 2.5.2 in Arduino Studio seems to have magically solved the issue. Someone should alert the makers of the library.

Glad I am not the only one that saw this issue! Spent so many hours on this. I thought I was alone. Haha.

I know this is way too late and a dollar short, but I have been searching for this for a long time and finally found the same problem. I have been wrestling with this for the past day. So I did the same thing and downgraded from 3.1.1 (I know this thread is 4 years old however).
What I just figured out, is it appears that if I uploaded the sketch with the 3.1.1 board installed and just let the soft reset do it's thing, I would get this same problem. If I did a hard reset pushing the reset button then the wifi connected worked as expected so in my case that soft reset after the upload was the culprit.


text:
nRF24l01+ Problems. Data is being recieved as 0
I am trying to transmit the values of three potentiometers via the nRF24L01+ (w/antenna). I am using the regulator designed for the nRF24L01+, so I don't think I need to add a decoupling capacitor. I am using a data structure to send the POT outputs as bytes. On the transmitter end, the values of the data structure are correct. On the receiver, however, each value of the data structure is being received as 0. I have an if statement to verify if radio.available() and apparently the radio is available. If I change the wiring of either the receiver or the transmitter, the radio is not available, so I am assuming it is wired correctly. Plus, the regulator makes it pretty simple.
I have :

CE = D7
CSN = D8
(and all the other mandatory pins 11, 12, 13 connected correctly) and D10 set to output with nothing connected. (I read on another post that D10 must be set to output to make it the SPI master, or something like that)...

I have been trying for days and can't seem to figure out what I'm doing wrong. Let me know if you need anymore information.
//Transmitter//
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

// Define the digital inputs
#define liftPOT A2  // Joystick button 1
#define thrustPOT A0  // Joystick button 2
#define rudderPOT A1   // Toggle switch 1

RF24 radio(7, 8);   // nRF24L01 (CE, CSN)
const byte address[6] = "00001"; // Address
// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
  byte thrustPOT;
  byte liftPOT;
  byte rudderPOT;
};
Data_Package data; //Create a variable with the above structure
void setup() {
  Serial.begin(9600);
  // Define the radio communication
  radio.begin();
  radio.openWritingPipe(address);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_LOW);

  // Set initial default values
  data.thrustPOT = 127; // Values from 0 to 255. When Joystick is in resting position, the value is in the middle, or 127. We actually map the pot value from 0 to 1023 to 0 to 255 because that's one BYTE value
  data.rudderPOT = 127;
  data.liftPOT = 1;
}
void loop() {
  // Read all analog inputs and map them to one Byte value
  data.thrustPOT = map(analogRead(A1), 0, 1023, 0, 255); // Convert the analog read value from 0 to 1023 into a BYTE value from 0 to 255
  data.rudderPOT = map(analogRead(A0), 0, 1023, 0, 255);
  data.liftPOT = map(analogRead(A2), 0, 1023, 0, 255);
  radio.write(&data, sizeof(Data_Package));

  int liftVal, thrustVal, rudderPOS;
  liftVal = map(analogRead(A2), 0, 1023, 0, 255);
  thrustVal = map(analogRead(A0), 0, 1023, 0, 255);
  rudderPOS = map(analogRead(A1), 0, 1023, 0, 255);
  Serial.print("Lift : ");
  Serial.print(data.liftPOT);
  Serial.print(" Thrust : ");
  Serial.print(data.thrustPOT);
  Serial.print(" Rudder : ");
  Serial.println(data.rudderPOT);

//Receiver//
    #include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>

RF24 radio(7, 8);   // nRF24L01 (CE, CSN)
const byte address[6] = "00001";
unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;
Servo thrustESC;  // create servo object to control the ESC
Servo liftESC;
Servo rudder;
int thrustVal, liftVal, rudderVal;
// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
  byte thrustPOT;
  byte liftPOT;
  byte rudderPOT;
};
Data_Package data; //Create a variable with the above structure
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening(); //  Set the module as receiver
  resetData();
  thrustESC.attach(6);
  liftESC.attach(5);
  rudder.attach(3);
  pinMode(10, OUTPUT);

}
void loop() {
  // Check whether we keep receving data, or we have a connection between the two modules
  currentTime = millis();
  if ( currentTime - lastReceiveTime > 1000 ) { // If current time is more then 1 second since we have recived the last data, that means we have lost connection
    resetData(); // If connection is lost, reset the data. It prevents unwanted behavior, for example if a drone jas a throttle up, if we lose connection it can keep flying away if we dont reset the function
  }
  // Check whether there is data to be received
  if (radio.available()) {
    radio.read(&data, sizeof(Data_Package)); // Read the whole data and store it into the 'data' structure
    lastReceiveTime = millis(); // At this moment we have received the data
    Serial.print("recieving");
  }
  // Controlling servos
  rudderVal = map(data.rudderPOT, 0, 255, 0, 50);
  rudder.write(rudderVal);
  // Controlling brushless motor with ESC
  // Lift propeller
  liftVal = map(data.liftPOT, 0, 255, 1000, 2000); // Map the receiving value form 0 to 255 to 0 1000 to 2000, values used for controlling ESCs
  liftESC.writeMicroseconds(liftVal); // Send the PWM control singal to the ESC

  // Thrust propeller
  thrustVal = constrain(data.thrustPOT, 130, 255); // Joysticks stays in middle. So we only need values the upper values from 130 to 255
  thrustVal = map(thrustVal, 130, 255, 1000, 2000);
  thrustESC.writeMicroseconds(thrustVal);
  Serial.print("Lift : ");
  Serial.print(data.thrustPOT);
  Serial.print(" Thrust : ");
  Serial.print(thrustVal);
  Serial.print(" Rudder : ");
  Serial.println(rudderVal);
}
void resetData() {
  // Reset the values when there is no radio connection - Set initial default values
  data.thrustPOT = 127;
  data.liftPOT = 1;
    data.rudderPOT = 127;
    Serial.println("reset");

}

Further details:

Further details:I have soldered all my wires as this the setup is meant to be permanent. I have done a continuity check with a multimeter on 100% of the system and everything is connected correctly. The nRF24L01 is sourced by: 9V power supply connected to Vin, 5V out connected to VCC of nRF24L01 Regulator VCC pin, and that regulator powers the actual nRF24L01. I am transmitting and receiving from two Nanos (old bootloader).

Please [edit] your question to add all the details, don't hide them in comments.

Your question seems a potential duplicate of this.  I would have expected a wiring problem to manifest differently, but apparently what you're seeing is possible under that scenario.  If that turns out to be your problem, let us know and we can close this as a duplicate.

@RobertSpiers you are debugging a communication problem ... focus your code to achieving that ... remove all code that is not related to data transmission .... send something like "abc124" once every 5 seconds, nothing more ... simplify the receive code to only validate that you have received the data correctly

Are you feeding the nRF24 with 5volt? The operating voltage of the module is from 1.9 to 3.6V!

And what @jsotola is saying is KISS (Keep It Simple and Stupid) with other words, do a basic send a number and receive a number code before advancing.

I have checked many times the pins that I am connecting... I cant seem to find anything out of place. I have simplified the code completely and have included nothing but radio.isChipConnected(); which returns false... I  have rewired it, and still have the same issue. IsChipConnected tells me that the Rf24 is not properly connected, right? I have double checked and even re soldered the connections...

@MatsKarlsson, I am running 5V to the additional RF24 regulator, designed specifically for it, which regulates the voltage down to 3.3.

@timemage, Running the radio.isChipConnected function showed me that I do have a connection error. Feel free to remove this post.

Add that as a answer and choose it as the answer. And as to simplify the code I mean it even simpler, check : https://forum.arduino.cc/index.php?topic=217865.0

Does this answer your question? NRF24L01 only receiving zeros

I case you're wondering, it apparently adds the above comment automatically if you mark  as duplicate.  Seems sort of awkward at this stage, but removing it doesn't seem like a good idea not knowing the normal procedure for this.

In order to diagnose my proplem, I used the radio.isChipConnected() function. When the function returns 0, you have a wiring problem. If you are getting consistent high or low values, run the above function. If you return a 1, that means that the nRF24L01 is connected correctly and there is likely a software error. Simplify everything in the code to where only one simple thing is being transmitted and received. I would recommend starting small with nothing attached to the arduino other than the radio module. Once that is behaving properly, build up to your goal step by step, checking along the way. My mistake was soldering my entire set up directly to the arduino and then trying to troubleshoot.


text:
Piezo sensor requires parallel or pull-down resistor?
Apologies but I didn't happen to find ultimate answer to this.
I'm trying to make a simple piezo sensor (https://www.sparkfun.com/products/10293) which triggers something (e.g. a sound or lights up a LED) when it's pressed. This is similar to Arduino "Knock Lock" project.
However, I see there are 2 different basic ways to connect the piezo as vibration sensor:
Way 1) [as in Arduino project]

Piezo + to 5V
Piezo - to A0
1MΩ Resistor between A0 and GND

Way 2) [as in many other references on the internet]

Piezo + to A0
Piezo - to GND
1MΩ Resistor between A0 and GND

I tried both and have very different behaviours.
Way 1 seems working correctly: analogRead(A0) returns a value related to how strong the vibration is, and then decays to almost 0 (I expected 0 but it stays to 50-60ish).
Way 2 provide more of an impulse-type response, and stays at 400ish after triggered.
Are these behaviors correct and what's the proper way for piezo sensor?
Using Arduino UNO powered via USB.

what piezo sonsor are yout talking about?

@jsotola this one https://www.sparkfun.com/products/10293


text:
I want a code for 6 LDR/LED pair
Each LDR is connected to one LED because I am doing a parking lot model. I have tried but with no luck. Help!
    int ledPin = 11;
int sensorInput = A0;

boolean ledIsOn = false;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int lightLevel = analogRead(A0);

  if (ledIsOn) {
    if (lightLevel > 600) {
      ledIsOn = false;
    }
  } else {
    if (lightLevel < 400) {
      ledIsOn = true;
    }
  }

  digitalWrite(ledPin, ledIsOn);

  Serial.println(lightLevel);
}

*this is the code for one LED to one LDR Sensor but I cannot make the 6 led to 6 ldr
and I did this code for 6 LDR
#define pin_size 6
const int pin[pin_size] = { A0, A1, A2, A3, A4, A5};

void setup() {

  Serial.begin(9600);

}

void loop() {
  for (int i = 0 ; i < pin_size; i++) {
    Serial.print(analogRead(pin[i]));
    Serial.print(" - ");
    Serial.print(i);
    Serial.print("  |  ");

  }
  Serial.print("\n");
  delay(1000);

}

Welcome to Arduino:SE. Please be aware that this is not a free design house or an on-demand online technical encyclopedia. Please revise your question showing your work and findings so far. You might find it helpful to review the site tour and Help Centre and, in particular, [ask].

I have tried ... please show the work that you have done .... do you have a question? ... you have  not asked anything.

When you want to have the same thing happen multiple times with multiple settings or values it can be useful to generalise it by creating a class, then instantiating one object per LED + LDR pair.

can u explain more?

you posted working code for one LDR/LED pair .... please post the code that does not work

this is the code for one LED to one LDR Sensor but I cannot make the 6 led to 6 ldr

note: you do not need this statement if (ledIsOn) {  ..... only two lines if (lightLevel > 600)  ledIsOn = false; and if (lightLevel < 400)  ledIsOn = true;

ok can you please help me with the 6 LDR and 6 LED code I cannot seem to be able to do it

use lightLevel_1, ledIsOn_1, lightLevel_2, ledIsOn_2, lightLevel_3, ledIsOn_3, etc.

I cannot seem to be able to do it ... you still have not posted your code that you tried, but that does not work as expected

I edited my post now

I have the code for 6 LDR but I don't know how to make the code with 6 ldr and 6 led

does that code print out the values from the 6 LDRs? ..... do your comparison inside the for loop .... add code that uses lightLevel[i] and ledIsOn[i]

this code is just for 6 LDR and I need to add on it 6 led because my project is to create 6 LDR/LED pair

can you just please help me with the codes

Do you really understand, what the code for 1 LDR/LED pair does exactly? It doesn't seem so. You already created a for loop, that iterates through all the analog inputs. Now create an array with the LEDs pin numbers like you did with the analog pins. Inside the for loop, do what you have done before with 1 LDR/LED pair: Read the analog value into a variable, check if the variable is above 600 or below 400 and use digitalWrite() with the corresponding pin number (from the array) to set the correct value. If you cannot do this, you haven't understood, what the original code does.

You need to convert all the regular variables to arrays. The loop through each index and run the the same as before for each index.
const int pin_size 6
int ledPins[] = {3, 4, 5, 6, 7, 8};
int sensorPins[] = {A0, A1, A2, A3, A4, A5};
boolean ledIsOn[] = {false, false, false, false, false, false};

void setup() {
  for (int i = 0 ; i < pin_size; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
  Serial.begin(9600);
}

void loop() {
  for (int i = 0 ; i < pin_size; i++) {
    int lightLevel = analogRead(sensorPins[i]);

    if (ledIsOn[i]) {
      if (lightLevel > 600) {
        ledIsOn[i] = false;
      }
    } else {
      if (lightLevel < 400) {
        ledIsOn[i] = true;
      }
    }

    digitalWrite(ledPins[i], ledIsOn[i]);

    Serial.println(lightLevel);
  }
}

it seems that you may have done the OP's school assignment.

@jsotola I wasn’t really convinced, and gave it the benefit of the doubt.

you may be correct in your thinking .... i do not mean to put down your choice to answer, i just wonder if the OP learned anything


text:
How to solve this "xpected primary-expression before ',' token"
I'm new in this arduino world, and I'm having some trouble. I am programming something for a school assignment. The program gives an error, and my teacher also doesn't know how to solve it. Maybe someone can help me?
#include <CapacitiveSensor.h>
#define speaker

CapacitiveSensor   cs_2_3 = CapacitiveSensor(2,3);
CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4);
CapacitiveSensor   cs_2_5 = CapacitiveSensor(2,5);
CapacitiveSensor   cs_2_6 = CapacitiveSensor(2,6);
CapacitiveSensor   cs_2_7 = CapacitiveSensor(2,7);
CapacitiveSensor   cs_2_8 = CapacitiveSensor(2,8);
CapacitiveSensor   cs_2_9 = CapacitiveSensor(2,9);
CapacitiveSensor   cs_2_10 = CapacitiveSensor(2,10);

int s1;
int s2;
int s3;
int s4;
int s5;
int s6;
int s7;
int s8;

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

void loop()
{

  s1 =  cs_2_3.capacitiveSensor(3000);
  s2 =  cs_2_4.capacitiveSensor(3000);
  s3 =  cs_2_5.capacitiveSensor(3000);
  s4 =  cs_2_6.capacitiveSensor(3000);
  s5 =  cs_2_7.capacitiveSensor(3000);
  s6 =  cs_2_8.capacitiveSensor(3000);
  s7 =  cs_2_9.capacitiveSensor(3000);
  s8 =  cs_2_10.capacitiveSensor(3000);

  Serial.print("s1: ");
  Serial.println(s1);
  Serial.print("s2: ");
  Serial.println(s2);
  Serial.print("s3: ");
  Serial.println(s3);
  Serial.print("s4: ");
  Serial.println(s4);
  Serial.print("s5: ");
  Serial.println(s5);
  Serial.print("s6: ");
  Serial.println(s6);
  Serial.print("s7: ");
  Serial.println(s7);
  Serial.print("s8: ");
  Serial.println(s8);

  if (s1 > 500){
    tone(speaker,131);
   }
  else if (s2 > 500){
    tone(speaker,147);
   }
  else if (s3 > 500){
    tone(speaker,165);
   }
  else if (s4 > 500){
    tone(speaker,175);
   }
  else if (s5 > 500){
    tone(speaker,196);
   }
  else if (s6 > 500){
    tone(speaker,220);
   }
  else if (s7 > 500){
    tone(speaker,247);
   }
  else if (s8 > 500){
    tone(speaker,262);
   }

  if (s1<=500  &&  s2<=500  &&  s3<=500 && s4<=500  &&  s5<=500  &&  s6<=500 &&  s7<=500 &&  s8<=500){
    noTone(speaker);
  }
}

Tell the line where the error is given.

This is unrelated to your question but the else if construct does not look very elegant, especially if tone s1 is supposed to have an equal priority to say s8.  Can you find another way of doing this part of the code?

Hint: What does "tone(speaker,131); " become if "#define speaker"?

This is the line where the error is given: else if (s8 > 500){
tone(speaker,262);

This:
#define speaker

defines "speaker" as nothing, an empty string. Then:
tone(speaker,131);

is translated into
tone(,131);

which makes no sense. The compiler expected to find an expression before the comma.


text:
RTC DS1307 VCC not getting connected to 5V of Arduino Uno
I am using RTC DS1307 with "TINY RTC I2C modules" written on it.I had downloaded RTClib library from adafruit and using the example code. I connected GND->GND, VCC->5V, SDA->A4 and SCL->A5. However after connecting the VCC to 5V the "ON" Led does not lights up and the code is not getting uploaded. I tried connecting the VCC to 3.3 V the code gets uploaded but does not shows any output on the screen.

Soldering was not done properly. The vcc and ground got "short" that's what the shopkeeper said. We again soldered it on the other side. Now its working

It seems an hardware problem on Arduino Uno board.
Try to connect the 5V pin of Arduino Uno to a digital pin (e.g D7) and write a program for read a digital pin.
int inPin = 7;     // digital pin 7
int val = 0;       // variable to store the read value

void setup()
{
  pinMode(inPin, INPUT);        // sets the digital pin 7 as input
}

void loop()
{
  val = digitalRead(inPin);     // read the input pin
  Serial.println(val);          // print read value on serial
}

If you're not able to load this sketch on your Arduino, most likely it's an hardware problem on Arduino.

But 5V of Arduino is drawing current to VCC of bluetooth HC05 module

You remove temporary the HC 05 module and try it.

I had tried that and I think there is some hardware problem with my RTC.

Just another point,
From my experience, any module that uses a serial connection can disrupt the sketch uploading process to the Arduino.
The best is to upload to Arduino when all serial connections are dis-connected.


text:
Is there software to make an interactive GUI for my TFT touch screen shield?
I was wondering this, because realized it takes quite time consuming due to all the lines of code I have to write.

Not for Arduino, no. Only for things like 4D or Nextion displays.

Thank you, I guess I'll get to writing that code ☹