text:
what is the difference between array of uint16_t data versus an array of uint16_t variables?
I've been struggling with weird behavior, crashes and general problems when trying to use an array of four uint16_t groups of data. When I create four separate variables and load that into an array, it works OK and is smaller.
This is for use with the irlib2 SendBase and HashRaw components.
What's going on here?
The code utterly fails with crashes, unresponsive hardware when I use the following variable assignment with an arduino micro. Additionally this version uses about 400 bytes more of memory than the second example
failed variable assignemnt
uint16_t sources[4][RAW_DATA_LEN] = {
  {8550, 4306, 530, 1606, 530, 566, 502, 1610, //POWER ON/OFF
  530, 566, 502, 574, 506, 1630, 506, 566,
  506, 1630, 506, 566, 502, 1610, 530, 566,
  502, 1634, 506, 1606, 530, 570, 498, 1634,
  506, 570, 510, 562, 506, 566, 502, 1634,
  506, 1606, 530, 1610, 530, 562, 538, 538,
  530, 542, 538, 1598, 538, 1570, 558, 542,
  538, 538, 530, 542, 538, 1598, 530, 1578,
  558, 1578, 562, 1000},

  {8546, 4310, 558, 1578, 562, 538, 498, 1638, //sourceCD
  530, 542, 506, 570, 502, 1634, 502, 570,
  498, 1638, 534, 538, 498, 1638, 530, 542,
  506, 1606, 554, 1582, 558, 538, 510, 1602,
  554, 546, 506, 566, 502, 570, 510, 1602,
  554, 1582, 558, 538, 510, 566, 502, 1606,
  554, 546, 502, 1610, 558, 1574, 554, 546,
  502, 570, 510, 1602, 526, 1610, 526, 574,
  506, 1602, 526, 1000},

  {8550, 4306, 530, 1606, 534, 566, 502, 1606,  //sourceCDR
  534, 566, 502, 570, 510, 1602, 526, 570,
  510, 1602, 534, 566, 502, 1606, 534, 566,
  506, 1602, 530, 1606, 534, 566, 502, 1610,
  530, 570, 498, 574, 506, 566, 502, 570,
  510, 1602, 526, 570, 510, 566, 502, 570,
  510, 1602, 526, 1610, 526, 1606, 534, 1602,
  534, 566, 502, 1610, 530, 1602, 534, 1602,
  526, 574, 506, 1000},

  {8550, 4310, 526, 1634, 506, 566, 502, 1634,  //sourceAUX
  506, 566, 502, 574, 506, 1626, 510, 566,
  506, 1630, 506, 566, 502, 1634, 506, 566,
  502, 1634, 506, 1606, 530, 566, 506, 1630,
  506, 566, 502, 1634, 506, 1630, 506, 1630,
  510, 1602, 526, 570, 510, 566, 502, 1634,
  502, 570, 502, 570, 510, 566, 502, 570,
  510, 562, 506, 1630, 506, 1630, 510, 562,
  506, 1630, 510, 1000}
} ;

When I instead assign each grouping to a variable and then create an array of those variables, the code is significantly smaller (about 400 bytes) and appears to run as expected without crashes.
Successful variable assignment
#define RAW_DATA_LEN 68
uint16_t powerOnOff[RAW_DATA_LEN] = {
  8550, 4306, 530, 1606, 530, 566, 502, 1610,
  530, 566, 502, 574, 506, 1630, 506, 566,
  506, 1630, 506, 566, 502, 1610, 530, 566,
  502, 1634, 506, 1606, 530, 570, 498, 1634,
  506, 570, 510, 562, 506, 566, 502, 1634,
  506, 1606, 530, 1610, 530, 562, 538, 538,
  530, 542, 538, 1598, 538, 1570, 558, 542,
  538, 538, 530, 542, 538, 1598, 530, 1578,
  558, 1578, 562, 1000
};

uint16_t sourceCD[RAW_DATA_LEN] = {
  8546, 4310, 558, 1578, 562, 538, 498, 1638,
  530, 542, 506, 570, 502, 1634, 502, 570,
  498, 1638, 534, 538, 498, 1638, 530, 542,
  506, 1606, 554, 1582, 558, 538, 510, 1602,
  554, 546, 506, 566, 502, 570, 510, 1602,
  554, 1582, 558, 538, 510, 566, 502, 1606,
  554, 546, 502, 1610, 558, 1574, 554, 546,
  502, 570, 510, 1602, 526, 1610, 526, 574,
  506, 1602, 526, 1000
};

uint16_t sourceAUX[RAW_DATA_LEN] = {
  8550, 4310, 526, 1634, 506, 566, 502, 1634,
  506, 566, 502, 574, 506, 1626, 510, 566,
  506, 1630, 506, 566, 502, 1634, 506, 566,
  502, 1634, 506, 1606, 530, 566, 506, 1630,
  506, 566, 502, 1634, 506, 1630, 506, 1630,
  510, 1602, 526, 570, 510, 566, 502, 1634,
  502, 570, 502, 570, 510, 566, 502, 570,
  510, 562, 506, 1630, 506, 1630, 510, 562,
  506, 1630, 510, 1000
};

uint16_t sourceCDR[RAW_DATA_LEN] = {
  8550, 4306, 530, 1606, 534, 566, 502, 1606,
  534, 566, 502, 570, 510, 1602, 526, 570,
  510, 1602, 534, 566, 502, 1606, 534, 566,
  506, 1602, 530, 1606, 534, 566, 502, 1610,
  530, 570, 498, 574, 506, 566, 502, 570,
  510, 1602, 526, 570, 510, 566, 502, 570,
  510, 1602, 526, 1610, 526, 1606, 534, 1602,
  534, 566, 502, 1610, 530, 1602, 534, 1602,
  526, 574, 506, 1000
};

//Set up array of codes
uint16_t sources[4] = {powerOnOff, sourceCD, sourceCDR, sourceAUX};

This is the code as it stands in an unfinished state. In an effort to trace back the crashes and odd behavior I systematically removed most of the code to the point where the last if statement is sending the IR codes.
Entire Code
#include <movingAvg.h>    // moving average library
#include <IRLibSendBase.h>    //We need the base code
#include <IRLib_HashRaw.h>    //Only use raw sender
#include <elapsedMillis.h>    //measure elapsed time

// ====REMOTE CODES====
//define the IR Sender
IRsendRaw mySender;
#define RAW_DATA_LEN 68
uint16_t powerOnOff[RAW_DATA_LEN] = {
  8550, 4306, 530, 1606, 530, 566, 502, 1610,
  530, 566, 502, 574, 506, 1630, 506, 566,
  506, 1630, 506, 566, 502, 1610, 530, 566,
  502, 1634, 506, 1606, 530, 570, 498, 1634,
  506, 570, 510, 562, 506, 566, 502, 1634,
  506, 1606, 530, 1610, 530, 562, 538, 538,
  530, 542, 538, 1598, 538, 1570, 558, 542,
  538, 538, 530, 542, 538, 1598, 530, 1578,
  558, 1578, 562, 1000
};

uint16_t sourceCD[RAW_DATA_LEN] = {
  8546, 4310, 558, 1578, 562, 538, 498, 1638,
  530, 542, 506, 570, 502, 1634, 502, 570,
  498, 1638, 534, 538, 498, 1638, 530, 542,
  506, 1606, 554, 1582, 558, 538, 510, 1602,
  554, 546, 506, 566, 502, 570, 510, 1602,
  554, 1582, 558, 538, 510, 566, 502, 1606,
  554, 546, 502, 1610, 558, 1574, 554, 546,
  502, 570, 510, 1602, 526, 1610, 526, 574,
  506, 1602, 526, 1000
};

//uint16_t sourceAUX[RAW_DATA_LEN] = {
//  8550, 4310, 526, 1634, 506, 566, 502, 1634,
//  506, 566, 502, 574, 506, 1626, 510, 566,
//  506, 1630, 506, 566, 502, 1634, 506, 566,
//  502, 1634, 506, 1606, 530, 566, 506, 1630,
//  506, 566, 502, 1634, 506, 1630, 506, 1630,
//  510, 1602, 526, 570, 510, 566, 502, 1634,
//  502, 570, 502, 570, 510, 566, 502, 570,
//  510, 562, 506, 1630, 506, 1630, 510, 562,
//  506, 1630, 510, 1000
//};

uint16_t sourceCDR[RAW_DATA_LEN] = {
  8550, 4306, 530, 1606, 534, 566, 502, 1606,
  534, 566, 502, 570, 510, 1602, 526, 570,
  510, 1602, 534, 566, 502, 1606, 534, 566,
  506, 1602, 530, 1606, 534, 566, 502, 1610,
  530, 570, 498, 574, 506, 566, 502, 570,
  510, 1602, 526, 570, 510, 566, 502, 570,
  510, 1602, 526, 1610, 526, 1606, 534, 1602,
  534, 566, 502, 1610, 530, 1602, 534, 1602,
  526, 574, 506, 1000
};

//Set up array of codes
uint16_t *sources[3] = {powerOnOff, sourceCD, sourceCDR};//, sourceAUX};

//This causes some sort of horrible crash - maybe an overflow of the uint16 data type?
//#define RAW_DATA_LEN 68
//uint16_t sources[4][RAW_DATA_LEN] = {
//  {8550, 4306, 530, 1606, 530, 566, 502, 1610, //POWER ON/OFF
//  530, 566, 502, 574, 506, 1630, 506, 566,
//  506, 1630, 506, 566, 502, 1610, 530, 566,
//  502, 1634, 506, 1606, 530, 570, 498, 1634,
//  506, 570, 510, 562, 506, 566, 502, 1634,
//  506, 1606, 530, 1610, 530, 562, 538, 538,
//  530, 542, 538, 1598, 538, 1570, 558, 542,
//  538, 538, 530, 542, 538, 1598, 530, 1578,
//  558, 1578, 562, 1000},
//
//  {8546, 4310, 558, 1578, 562, 538, 498, 1638, //sourceCD
//  530, 542, 506, 570, 502, 1634, 502, 570,
//  498, 1638, 534, 538, 498, 1638, 530, 542,
//  506, 1606, 554, 1582, 558, 538, 510, 1602,
//  554, 546, 506, 566, 502, 570, 510, 1602,
//  554, 1582, 558, 538, 510, 566, 502, 1606,
//  554, 546, 502, 1610, 558, 1574, 554, 546,
//  502, 570, 510, 1602, 526, 1610, 526, 574,
//  506, 1602, 526, 1000},
//
//
//  {8550, 4306, 530, 1606, 534, 566, 502, 1606,  //sourceCDR
//  534, 566, 502, 570, 510, 1602, 526, 570,
//  510, 1602, 534, 566, 502, 1606, 534, 566,
//  506, 1602, 530, 1606, 534, 566, 502, 1610,
//  530, 570, 498, 574, 506, 566, 502, 570,
//  510, 1602, 526, 570, 510, 566, 502, 570,
//  510, 1602, 526, 1610, 526, 1606, 534, 1602,
//  534, 566, 502, 1610, 530, 1602, 534, 1602,
//  526, 574, 506, 1000},
//
//  {8550, 4310, 526, 1634, 506, 566, 502, 1634,  //sourceAUX
//  506, 566, 502, 574, 506, 1626, 510, 566,
//  506, 1630, 506, 566, 502, 1634, 506, 566,
//  502, 1634, 506, 1606, 530, 566, 506, 1630,
//  506, 566, 502, 1634, 506, 1630, 506, 1630,
//  510, 1602, 526, 570, 510, 566, 502, 1634,
//  502, 570, 502, 570, 510, 566, 502, 570,
//  510, 562, 506, 1630, 506, 1630, 510, 562,
//  506, 1630, 510, 1000}
//} ;

// ====PIN ASSIGNMENTS====
const int audioPin1 = A1;     //Channel 1
const int audioPin2 = A2;
const int debugPin = A3;     //when low, run in debug mode
const int statusLight = 10;   //active channel indicator light

//  ====CHANNEL MEASUREMENTS====
# define CHANNELS 3     //number of channels to sample from
int audioChannels[CHANNELS] = {audioPin1, audioPin1, audioPin2};      //element 0 will be ignored
int channelValues[CHANNELS] = {0, 0, 0};
const int SAMPLES = 300;
movingAvg audioAverages[CHANNELS] = {movingAvg(SAMPLES), movingAvg(SAMPLES), movingAvg(SAMPLES)};

//  ====CHANNEL VARIABLES====
int currentChannel = 0;     //channel that is currently active (0 is off)
int previousChannel = 0;    //channel that was active before change (0 is off)
const int audioThreshold = 15;      //minimum value for an "active" channel

//  ====TIMERS===
int counter = 0;
const int heartBeat = 500;
int channelReleaseTimeOut = 5000;      //time to wait before releasing an inactive timer
int powerTimeOut = 10000;       //time to wait before turnning off
int powerOnDelay = 7000;
elapsedMillis channelReleaseTimer = 0;
elapsedMillis powerTimer = 0;

// ====CONTROL VARIABLES====
bool debugMode = true;

void sendCode(int myChannel=0) {
//  debug("sending code", -1);
  for (int i=0; i < 20; i++) {
//  INCLUDING THE FOLLOWING LINE BREAKS THE DEBUG FUNCTION AND CAUSES OTHER STRANGE BEHAVIOR
//    mySender.send(sources[myChannel], RAW_DATA_LEN, 36);
    Serial.println("send code here");
    delay(2);
  }
} //END sendCode()

int findActiveChannel() {   //returns first active channel in the array or 0 if none are active
  int myChannel = 0;
  for (int i = 0; i < CHANNELS; i++) {
    if (channelValues[i] >= audioThreshold) {
      myChannel = i;
      break;
    }
  }
  return myChannel;
} //END findActiveChannel()

void debug(String message, int val) {

  if (debugMode) {
    Serial.print(message);
    Serial.println(val);
  }
} //END debug()

void setup() {
  delay(1000); //delay in case of runaway loop - allow programmer time to interrupt
  //  ====PIN SETUP====
  pinMode(statusLight, OUTPUT);
  pinMode(debugPin, INPUT);
  pinMode(audioPin1, INPUT);
  pinMode(audioPin2, INPUT);

  if (debugMode) {
    Serial.begin(9600);
    delay(2000);
    debug("starting up ", -1);
  }

  // ====INIT VARIABLES====
  for (int i = 0; i < CHANNELS; i++) { //init and reset the moving averages
    audioAverages[i].begin();
    audioAverages[i].reset();
  }
}

void loop() {
  int activeChannel = 0;
  for (int i=0; i < CHANNELS; i++) {      //sample channels
    int audioValue = 0;
    if (i > 0) {      //only sample channels > 0
      audioValue = analogRead(audioChannels[i]) - 512;      //voltage divider on amp circuit shifts all values +512 (2.5V)
      audioValue = abs(audioValue);     //abs() funciton is actually a macro; needs to be on own line
      channelValues[i] = audioAverages[i].reading(audioValue);    //update and store the moving average for each channel
    }

//    if (counter >= heartBeat) {
//      debug("channel: ", i);
//      debug("    audioValue: ", audioValue);
//      debug("           avg: ", channelValues[i]);
//    }
  }     //end sample channels

//  if (counter >= heartBeat) {
//    debug("======================", -1);
//  }

  if (channelValues[currentChannel] >= audioThreshold) {      //reset the channel release timer if the current channel is active
    channelReleaseTimer = 0;
    powerTimer = 0;
  } else {
    activeChannel = findActiveChannel();

    //DEBUGGING - show countdown to channel release
    if(channelReleaseTimer < channelReleaseTimeOut and counter >= 500) {
      debug("Channel became inactive: ", currentChannel);
      debug("     releasing in: ", channelReleaseTimeOut - channelReleaseTimer);
    }
    //END DEBUGGING

    if (activeChannel != currentChannel and channelReleaseTimer >=channelReleaseTimeOut) {      //change channel
      debug("Changing channel from: ", currentChannel);
      debug("Changing channel to: ", activeChannel);
      currentChannel = activeChannel;
      powerTimer = 0;
    }
  }
  //END else find active channel

  if (currentChannel > 0) {     //reset the power timeout if there is an active channel
    powerTimer = 0;
  }

  if (previousChannel != currentChannel) {      //check for a channel change and send appropriate codes
    if (previousChannel == 0) {     //state change from off to on
      digitalWrite(statusLight, true);
      debug("power state change -> ON ", -1);
      sendCode(0);
      debug("     delaying for reciver to power up: ", powerOnDelay);
      delay(powerOnDelay);
      previousChannel = currentChannel;
    }

    if (currentChannel < 1 and powerTimer >= powerTimeOut) {
      digitalWrite(statusLight, false);
      debug("power state change -> OFF ", -1);
      sendCode(0);
      previousChannel = currentChannel;
    }

    if (currentChannel > 0) {
      sendCode(currentChannel);
      previousChannel = currentChannel;
    }

  }

  if (counter >= heartBeat) {
    debug("\nheartBeat ", -1);
    counter = 0;
  }

  counter++;
  delay(2);

}

Including the line mySender.send(sources[myChannel], RAW_DATA_LEN, 36); in the sendCode() function causes the debug() function to behave erratically and the arduino to get stuck in a variety of states that require a hard reset, sometimes disconnecting the power.
This is the expected output from the serial console:
20:18:20.188 -> Channel became inactive: 2
20:18:20.188 ->      releasing in: 4666
20:18:20.188 ->
20:18:20.188 -> heartBeat -1
20:18:21.377 -> Channel became inactive: 2
20:18:21.377 ->      releasing in: 3492
20:18:21.377 ->
20:18:21.377 -> heartBeat -1
20:18:22.528 -> Channel became inactive: 2
20:18:22.528 ->      releasing in: 2317
20:18:22.528 ->
20:18:22.528 -> heartBeat -1
20:18:23.713 -> Channel became inactive: 2
20:18:23.713 ->      releasing in: 1144
20:18:23.713 ->
20:18:23.713 -> heartBeat -1
20:18:24.864 -> Changing channel from: 2
20:18:24.864 -> Changing channel to: 1
20:18:24.864 -> send code here

When including the mysender line indicated above, the serial output becomes as follows for a similar situation:
0:21:14.965 -> 1
20:21:14.965 -> 4984
20:21:14.965 -> -1
20:21:16.121 -> 1
20:21:16.121 -> 4986
20:21:16.121 -> -1
20:21:17.299 -> 1
20:21:17.299 -> 3814
20:21:17.299 -> -1
20:21:18.463 -> 1
20:21:18.463 -> 2640
20:21:18.463 -> -1
20:21:19.650 -> 1
20:21:19.650 -> 1468
20:21:19.650 -> -1
20:21:20.804 -> 1
20:21:20.804 -> 294
20:21:20.804 -> -1
20:21:21.116 -> 1
20:21:21.116 -> 0
20:21:21.998 -> -1

In the first example, you probably mean uint16_t sources[4][RAW_DATA_LEN] (4, not 2). In the second one, uint16_t *sources[4] (mind the star). With these fixes, I would expect both to work, But it is impossible to tell what's wrong with your program without seeing it.

those look like remote control codes ..... what is the device? ..... there may be a way to reduce the amount of data

@EdgarBonet Thanks for pointing out the typo in the snip. It does read uint16_t sources[4][RAW_DATA_LEN] in the actual code. The second example appears to work without the star which I find to be unexpected as I was lead to believe that I needed the star to indicate a pointer reference. Both compile, and run though the first example causes issues when a function uses that variable.

If you don't have the star, the second version should not work. That is, unless you do something very wacky in your code. Which seems to be the case: your program may be bug-compatible with the buggy version of the array definitions, and incompatible with the correct definitions. But then, let me repeat again: “it is impossible to tell what's wrong with your program without seeing it”.

@EdgarBonet Thanks for your patience. I've added the entire program. I'm running this against the 1.6.21 board manager due to some incompatibility with the IRLIB2 libraries as suggested here

I have no solution for you, but I would argue that your problem has
nothing to do the choice between an array of arrays and an array of
pointers. You will have to search somewhere else.
I tried a minimal test by removing everything that is not central to the
question. Assuming you are using this library, the prototype of
IRsendRaw::send() is
void IRsendRaw::send(uint16_t *buf, uint8_t len, uint8_t khz)

I thus wrote this dummy test class to replace the library:
class IRsendRaw {
public:
    void send(uint16_t *buf, uint8_t len, uint8_t khz) {
        Serial.print(F("Sending at "));
        Serial.print(khz);
        Serial.println(F(" kHz"));
        for (int i = 0; i < len; i++) {
            Serial.print(" ");
            Serial.print(buf[i]);
        }
        Serial.println();
    }
};

and used it in the following test program:
// Comment this line out to use an array of arrays instead:
#define ARRAY_OF_POINTERS

// ====REMOTE CODES====
//define the IR Sender
IRsendRaw mySender;

#define RAW_DATA_LEN 68

#ifdef ARRAY_OF_POINTERS

uint16_t powerOnOff[RAW_DATA_LEN] = {
  // ...
};

// And so on sourceCD[], sourceCDR[]...

//Set up array of codes
uint16_t *sources[3] = {powerOnOff, sourceCD, sourceCDR};//, sourceAUX};

#else

//This causes some sort of horrible crash
//- maybe an overflow of the uint16 data type?
uint16_t sources[4][RAW_DATA_LEN] = {
  {8550, 4306, 530, 1606, 530, 566, 502, 1610, //POWER ON/OFF
  // ...
  506, 1630, 510, 1000}
};

#endif

void setup()
{
    Serial.begin(9600);
#ifdef ARRAY_OF_POINTERS
    Serial.println(F("== Using an array of pointers =="));
#else
    Serial.println(F("== Using an array of arrays =="));
#endif
    for (int myChannel = 0; myChannel < 3; myChannel++) {
        Serial.print(F("\nChannel "));
        Serial.println(myChannel);
        mySender.send(sources[myChannel], RAW_DATA_LEN, 36);
    }
}

void loop(){}

The parts with ellipses (“...”) are just copied from your question. Now,
this test program works as expected, both in “array of pointers” and in
“array of arrays” mode.
It would then seem your problem comes from somewhere else. How full is
the memory of your Arduino? Quite often memory problems lead to strange
behaviors, where a crash can be triggered by a piece of code that is
perfectly legitimate and has nothing to do with the root cause of the
crash.

I think you're right. I'm starting to think this is a memory issue as well. The compiler reports that the sketch is 8408 bytes (29%) of program space. Global vars use 727 bytes (28%) of dynamic memory. I've narrowed down the problem to the function that calls the ir sender. Moving that fragment into another sketch works fine. Commenting out chunks of the logic in this sketch and getting the the dynamic memory down around 23% also works. Perhaps this micro has some bad memory? Is there a way to test for that?

@AaronCiuffo: You can find Arduino memory test sketches designed to test old RAM ICs. I am not aware of any published sketch designed to test the Arduino's own memory. The chances of the internal SRAM going bad are almost zero. What you can find is code for measuring the memory usage at run time, which accounts for heap and stack allocation. That could be a good thing to check.

I found a great article on this over at Adafruiit Memories of an Arduino. It covers some steps to take to decrease memory usage such as using the F() macro and moving large constants into PROGMEM. I'll give that a shot. Thanks again for your help.


text:
Read data from SD
I have logged  some data in my sdcard/FAT32 (format).
I can read and display them on the serial monitor but additionally I want to use these data as float.
Here is my code:
       byte index = 0;

       Tfile = SD.open("DATALOG.TXT",FILE_READ);

       while (Tfile.available()) {

         x[index++] = Tfile.read();
         x[index] = '\0'; // NULL terminate the array
       }

Printing the data using:
   Serial.print(fileContents);

I receive  the following float values that are correct:
   .63
   15.63
   16.60
   16.60
   16.60
   16.60
   etc

Now I want to work with values so i need to store them on a double index:
    double dtemp[320];
    for(index = 0, i=0; index < 320; index++, i++) {
       dtemp[i] =  fileContents[index];
       Serial.println(dtemp[i]); }

but i receive fault values:
      46.00
      54.00
      51.00
      13.00
      10.00
      49.00
      53.00
      etc

Any comment is welcomed !
Thank you in advance !

The "fault" values are the ASCII code...ok there is a solution reading the valid values(excluding the new line and carriage return) an putting them in an index 5x320, each line will be whole number and then I can store it in a float... but is there a faster way?

You have to parse the character array in order to convert it to
floats. There is no fast way to do this: since the Arduino has no FPU,
anything involving floats is slow.
Unless you really have to, I would not recommend slurping the whole file
into RAM. You will save memory by parsing the file on the fly. This
should be as simple as calling the parseFloat() method of the File
object:
double dtemp[320];
int i;
for (i = 0; Tfile.avalable() && i < 320; i++) {
    dtemp[i] = Tfile.parseFloat();
    Serial.println(dtemp[i]);
}
if (i < 320)
    Serial.println("WARNING: Premature end of file.");

Be careful with i declaration, byte is too small tp hold a value as big as 320.

@jfpoilpret: Oops! My bad. Just fixed it, thanks.

using double or float, arduino (UNO in my case) stops responding and it doesn't print anything in the serial monitor. Using int, it parses the integer part of the number correctly....

This is very weird. The parseInt() and parseFloat() functions are extremely similar, and they both implement timeouts. Neither should hang your Uno. I suspect your error lies somewhere else in your code. Could you please update your question with a minimal – but complete – sketch that reproduces the problem? Both the int version that works and the float version that does not please.

source: Stack Exchange

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

sort: votes


text:
time error in controlling a clock
I have designed and 3d printed a clock.
I am controlling the clock using a Arduino sketch running on a Attiny2313. The stepper motor I am using is a 12v 1:12 ratio stepper. The total number of steps per revolution are 288.
The problem I am facing is that I am unable to get the time right. I have got the steps per revolution of the minute ring bang on, but some how the motor gains 10/11 minutes every 24 hours.
I have used a lot of the code from the stepper motor library. I am not using the stepper motor library as the code gets larger than what can fit into the 2k attiny memory.
Any help is appreciated.
int number_of_steps = 288;
int motor_pin_1 = 9;
int motor_pin_2 = 10;
int motor_pin_3 = 11;
int motor_pin_4 = 12;
int ledpin = 13;
int delayTime = 4;
int buttonPin = 4;
int buttonState = 0;
int enablepin = 8;
int whatspeed = 40;
int last_step_time =0;
int step_number = 0;
[color=red]int blinkDelay = 939; [/color]
int step_delay = 60L * 1000L / number_of_steps / whatspeed;
int step_direction = 0;
void setup() {

 pinMode(motor_pin_1, OUTPUT);
 pinMode(motor_pin_2, OUTPUT);
 pinMode(motor_pin_3, OUTPUT);
 pinMode(motor_pin_4, OUTPUT);
 pinMode(buttonPin,INPUT);
 pinMode(ledpin, OUTPUT);
 pinMode(enablepin,OUTPUT);

}

void loop() {
 buttonState = digitalRead(buttonPin);
 if (buttonState ==HIGH){
   enablemotor();
   movestep(20);
   digitalWrite(ledpin,HIGH);
 }
 else{
   digitalWrite(ledpin,LOW);

   for (int xx = 0; xx<59;xx ++){

     enablemotor();
     movestep(42);
     //delay(100);
     motoroff();
     blinkk();
   }
   enablemotor();
   movestep(89);//85;

   motoroff();
   blinkk();
  //delay(3000);
 }
}

void enablemotor(){
 digitalWrite(enablepin,HIGH);
}

void movestep(int steps_to_move){
 int steps_left = abs(steps_to_move);

 if (steps_to_move > 0) {
   step_direction = 1;
 }
 if (steps_to_move < 0) {
   step_direction = 0;
 }

 while(steps_left > 0) {
   // if (millis() - last_step_time >= step_delay ) {
   //last_step_time = millis();
   if ( step_direction == 1 ){
     step_number++;
     delay(step_delay);
     if (step_number == number_of_steps) {
       step_number = 0;
     }
   }
   else {
     if (step_number ==0){
       step_number = number_of_steps;
     }
     step_number--;
   }
   steps_left--;

   stepmotor(step_number % 4);

   //}
 }
}

void stepmotor(int thisStep){

 switch (thisStep) {
 case 0:    // 1010
   digitalWrite(motor_pin_1, HIGH);
   digitalWrite(motor_pin_2, LOW);
   digitalWrite(motor_pin_3, HIGH);
   digitalWrite(motor_pin_4, LOW);
   break;
 case 1:    // 0110
   digitalWrite(motor_pin_1, LOW);
   digitalWrite(motor_pin_2, HIGH);
   digitalWrite(motor_pin_3, HIGH);
   digitalWrite(motor_pin_4, LOW);
   break;
 case 2:    //0101
   digitalWrite(motor_pin_1, LOW);
   digitalWrite(motor_pin_2, HIGH);
   digitalWrite(motor_pin_3, LOW);
   digitalWrite(motor_pin_4, HIGH);
   break;
 case 3:    //1001
   digitalWrite(motor_pin_1, HIGH);
   digitalWrite(motor_pin_2, LOW);
   digitalWrite(motor_pin_3, LOW);
   digitalWrite(motor_pin_4, HIGH);
   break;
 }

}

void blinkk(){
 for (int i = 0 ; i<30;i++){
   buttonState = digitalRead(buttonPin);
   if (buttonState ==HIGH){
     break;
   }
   else{
     digitalWrite(ledpin, HIGH);   // set the LED on
     delay(blinkDelay);  // 968           // wait for a second
     digitalWrite(ledpin, LOW);    // set the LED off
     delay(blinkDelay); //968
   }
 }
}

void motoroff(){
 digitalWrite(enablepin,LOW);
 digitalWrite(motor_pin_1, LOW);
 digitalWrite(motor_pin_2, LOW);
 digitalWrite(motor_pin_3, LOW);
 digitalWrite(motor_pin_4, LOW);

What is your clock source?

I guess the value for blinkDelay is too low. How did you even get that value? Even so, the clock of the ATTiny2313 isn't that accurate. Better get an RTC chip of sorts.

It is very difficult to accurately control timings with delay(),
because you have to account for the time needed to execute the rest of
the code, including interrupts. You can easily have better accuracy by
using millis() like this:
static unsigned long last_step_time;
unsigned long now = millis();
if (now - last_step_time >= step_delay) {
    do_one_step();
    last_step_time += step_delay;
}

This is almost what you have commented out in your own code, except that
millis() should be called only once per iteration, hence the now
variable.
This may still have less than perfect accuracy due to your clock source.
If your Arduino is clocked from a quartz you should be able to get
decent timing accuracy. If it is clocked from a ceramic oscillator you
are out of luck. In any case, you can always improve the accuracy by
calibrating your clock: you measure its drift and correct for it in
software. Then you have only to worry about thermal fluctuations of the
clock frequency, which should not be an issue with a quarts.
For best accuracy, you can use either an RTC or a watch crystal
connected directly to your ATmega chip. This last solution is only
possible if you go for a bare microcontroller, without the Arduino
board. See this answer
for more details about this option, as well as the way to correct
for the drift in software.

the millis i used in my code was acting weird. the clock worked for 288 steps and then the step delay value would become zero and the motor would stall . i couldnt figure out what was wrong and went back to using delay. i will try your code .

@ekaggrat: Beware I just edited a mistake in the code above. last_step_time should be incremented by step_delay instead of becoming now, because it is intended to contain the time when the motor should have been pulsed, irrespective of whether the pulse has been delayed by some interrupt.

You should consider using hardware timers (millis() uses this, see answer of edgarBonnet.
Or you might want to use a Real Time (Calendar) Clock chip, which often has even better accuracy (some even adjust to temperature).
Also a possibility is using a GPS module, and using the GPS time which should be extremely accurate and will not drift (since it's synchronized).
Post on AVR timer precision (hardware timers):
http://www.seanet.com/~karllunt/interval.html
RTC (Real Time Clock) example:
http://www.instructables.com/id/Real-Time-Clock-DS1302/
GPS example:
http://blog.arduino.cc/2014/01/06/simple-arduino-micro-gps-clock-project-arduinomicromonday/

millis() is based on a hardware timer, and is as accurate as your primary clock source.

@EdgarBonet I was unaware of that, edited it in my answer.
Though, you could say the primary clock source isn't 'accurate'.
It'll drift in time by temperature differences, some RTC's even adjust for this. And (somehow) synchronizing (gps?) would be the best way to go.

Yes. By “as accurate as” I mean: no more accurate, no less accurate. It’s synonymous with “as inaccurate as”.

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


text:
ESP32 thingboard broker mqtt error
Hello so i have this code, but it gives me this error , i have no idea why is not connection to broker mqtt? on the dash board say is active
"Conectando ao broker MQTT...Falha na conexao ao broker - Estado: 5"
#include <WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <ArduinoOTA.h>
const char* ssid         = "MEO-743D70_plus";
const char* password     = "861f6cbe4a";
const char* mqttServer   = "demo.thingsboard.io";
const int   mqttPort     = 1883;
const char* mqttUser     = "soundmeter";       //User name
const char* mqttPassword = "esp32";        //Password
const char* mqttClient   = "soundmeteresp32"; //ID

WiFiClient espClient;
PubSubClient client(espClient);
const int capacity = JSON_OBJECT_SIZE(21);
StaticJsonDocument<capacity> doc;

int contador = 1;
char mensagem[30];

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Iniciando conexao com a rede WiFi..");
  }
  Serial.println("Conectado na rede WiFi!");
}

void loop() {
   reconectabroker();

  doc["Dado0"] = random(100);
  doc["Dado1"] = random(100);
  doc["Dado2"] = random(100);
  doc["Dado3"] = random(100);
  doc["Dado4"] = random(100);
  doc["Dado5"] = random(100);
  doc["Dado6"] = random(100);
  doc["Dado7"] = random(100);
  doc["Dado8"] = random(100);
  doc["Dado9"] = random(100);

  String string1 = "v1/devices/me/telemetry";
  char Buf1[256];  string1.toCharArray(Buf1, 256);
  Serial.println(Buf1);

  char docBuffer1[256];
  size_t n = serializeJson(doc, docBuffer1);
  Serial.println(docBuffer1);
  client.publish(Buf1, docBuffer1, n);
  sprintf(mensagem, "MQTT ESP32 - Mensagem no. %d", contador);
  Serial.print("Mensagem enviada: ");
  Serial.println(mensagem);

  client.publish(Buf1, mensagem);
  Serial.println("Mensagem enviada com sucesso...");
  delay(1000);
  contador++;
}

void reconectabroker() {
  client.publish("v1/devices/me/telemetry", mensagem);
  Serial.println(mensagem);
  String string1 = "v1/devices/me/telemetry";
  char Buf1[256];
  string1.toCharArray(Buf1, 256);
  Serial.println(Buf1);
  client.setServer(mqttServer, mqttPort);

  while (!client.connected()) {
    Serial.println("Conectando ao broker MQTT...");
    if (client.connect(mqttClient, mqttUser, mqttPassword )) {
      Serial.println("Conectado ao broker!");
    }else {
      Serial.print("Falha na conexao ao broker - Estado: ");
      Serial.println(client.state());
      delay(2000);
    }
  }
}

client.state() returned 5 when attempting to connect to the MQTT broker. According to the PubSubClient documentation for int state(), this means the client was not authorized to connect. I.e. you used a wrong username and/ or password. Please add the code to your question.

i posted the code trought a link because is not formating correctly in the post, now i just edited, im using the correct user and password

Working now, thanks

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


text:
Recursive listing of sd card files
I'm working on a MP3 player and I want to list all files on the SD card.
I have found this code on internet :
void displaySdCardContent(FileItem& item, int numTabs) {
  for (int i = 0; i < numTabs; i++) {
    Serial.print('\t');
  }
  if (item.isDir) {
    Serial.println(item.name);
    for (FileItem fileElement : item.elements) {
      displaySdCardContent(fileElement, numTabs + 1);
    }
  } else {
    Serial.println(item.name);
  }
}

void displaySdCardContent(FileItem& item, int numTabs) {
  for (int i = 0; i < numTabs; i++) {
    Serial.print("...");
  }
  if (item.isDir) {
    Serial.println(item.name);
    for (FileItem& fileElement : item.elements) {
      displaySdCardContent(fileElement, numTabs + 1);
    }
  } else {
    Serial.println(item.name);
  }
}

It lists all the files but I can display only the first level directory. Here is my full code.
#define pushButton_pin   32
// Include required libraries
#include "Audio.h"
#include "SD.h"
#include "FS.h"
#include <Wire.h>
#include <TFT_eSPI.h>
#include <SPI.h>

// microSD Card Reader connections
#define SD_CS          5
#define SPI_MOSI      21
#define SPI_MISO      19
#define SPI_SCK       18

// I2S Connections
#define I2S_DOUT      22
#define I2S_BCLK      26
#define I2S_LRC       25

 // Create Audio object
Audio audio;

TFT_eSPI tft = TFT_eSPI();
//digitalWrite(TFT_BL, 1);

int maxIndex;
uint32_t Freq = 0;
int Val;
String Btn, SongName;
String Status = "Idle";
bool state = true;
bool Current_State = state;
int Current_Millis;
int Previous_Millis;
int Debounce = 175;
int Xindex = 0;
int Yindex = 0;

const uint8_t maxFileNameSize = 50;
struct FileItem {
  bool isDir;
  char name[maxFileNameSize + 1];
  FileItem* upDir;
  std::vector<FileItem> elements;
};

File dir;
String CurrDir;
String NextDir;
String Song;
String Liste[50];

void setup() {
  pinMode(pushButton_pin, INPUT);
  setCpuFrequencyMhz(160);
  tft.init();
  tft.setRotation(3);
  tft.fillScreen(TFT_BLACK);
  tft.setTextWrap(false);

  // Set microSD Card CS as OUTPUT and set HIGH
  pinMode(SD_CS, OUTPUT);
  digitalWrite(SD_CS, HIGH);

  // Initialize SPI bus for microSD Card
  SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);

  // Start Serial Port
  Serial.begin(115200);

  // Start microSD Card
  if (!SD.begin(SD_CS))
  {
    Serial.println("Error accessing microSD card!");
    while(true);
  }
  Serial.println("initialization done.");
  Serial.println("Creating structure of files");
  File root = SD.open("/");
  FileItem rootItem;
  if (strlen(root.name()) != 0)
    strncpy(rootItem.name, root.name(), maxFileNameSize);
  else
    strncpy(rootItem.name, "/", maxFileNameSize);
  rootItem.name[maxFileNameSize] = '\0';
  rootItem.isDir = true;
  readSdCard(root, rootItem);
  //Fin du listing

  Serial.println ("----Disp----");
  displaySdCardContent(rootItem, 0);
}

void readSdCard(File dir, FileItem& parentItem) {
  while (true) {
    File entry = dir.openNextFile();
    if (!entry) {
      break;  // no more files
    }
    FileItem item;
    item.isDir = entry.isDirectory();
    strncpy(item.name,  entry.name(), maxFileNameSize); // https://cplusplus.com/reference/cstring/strncpy/
    item.name[maxFileNameSize] = '\0';
    parentItem.elements.push_back(item);
    Serial.printf("Add %s to %s\n", item.name, parentItem.name);
    if (entry.isDirectory()) {
      readSdCard(entry, item);
    }
  }
}

void displaySdCardContent(FileItem& item, int numTabs) {
  for (int i = 0; i < numTabs; i++) {
    Serial.print("...");
  }
  if (item.isDir) {
    Serial.println(item.name);
    for (FileItem& fileElement : item.elements) {
      displaySdCardContent(fileElement, numTabs + 1);
    }
  } else {
    Serial.println(item.name);
  }
}

I have tried this to access the second level directories :
  FileItem* subFolder = &rootItem.elements.at(0);
  Serial.println ("----Disp----");
  FileItem _subFolder= *subFolder;

  displaySdCardContent(_subFolder, 0);

But it doesn't work ...
Here is what I get with the serial monitor :
23:36:23.419 -> Add 11-Avalanche.mp3 to War Eternal
23:36:23.419 -> Add 12-Down To Nothing.mp3 to War Eternal
23:36:23.419 -> Add 13-Not Long For This World.mp3 to War Eternal
23:36:23.451 -> Add folder.jpg to War Eternal
23:36:23.451 -> Add Will To Power to Arch Enemy
23:36:23.483 -> Add 01-Set Flame To The Night.mp3 to Will To Power
23:36:23.483 -> Add 02-The Race.mp3 to Will To Power
23:36:23.515 -> Add 03-Blood In The Water.mp3 to Will To Power
23:36:23.515 -> Add 04-The World Is Yours.mp3 to Will To Power
23:36:23.515 -> Add 05-The Eagle Flies Alone.mp3 to Will To Power
23:36:23.547 -> Add 06-Reason To Believe.mp3 to Will To Power
23:36:23.547 -> Add 07-Murder Scene.mp3 to Will To Power
23:36:23.579 -> Add 08-First Day In Hell.mp3 to Will To Power
23:36:23.579 -> Add 09-Saturnine.mp3 to Will To Power
23:36:23.612 -> Add 10-Dreams Of Retribution.mp3 to Will To Power
23:36:23.643 -> Add 11-My Shadow And I.mp3 to Will To Power
23:36:23.643 -> Add 12-A Fight I Must Win.mp3 to Will To Power
23:36:23.675 -> Add folder.jpg to Will To Power
23:36:23.675 -> ----Disp----
23:36:23.675 -> Arch Enemy

Edit :
Attributes item i can print  in displaySdCardContent()
14:58:54.763 -> ----Disp----
14:58:54.763 -> name : Arch Enemy
14:58:54.763 -> IsDir : 1

Debug in ReadsdCard
⸮⸮item name : 07. [Through The Eyes Of A Raven].mp3
item IsDir : 0
item size :0
parent item name : CD1 - Khaos Legions
parent item IsDir : 1
Parent item size :7
Add 07. [Through The Eyes Of A Raven].mp3 to CD1 - Khaos Legions
item name : 08. [Cruelty Without Beauty].mp3
item IsDir : 0
item size :0
parent item name : CD1 - Khaos Legions
parent item IsDir : 1
Parent item size :8
Add 08. [Cruelty Without Beauty].mp3 to CD1 - Khaos Legions
item name : 09. [We Are A Godless Entity].mp3
item IsDir : 0
item size :0
parent item name : CD1 - Khaos Legions
parent item IsDir : 1
Parent item size :9
Add 09. [We Are A Godless Entity].mp3 to CD1 - Khaos Legions
item name : 10. [Cult Of Chaos].mp3
item IsDir : 0
item size :0
parent item name : CD1 - Khaos Legions
parent item IsDir : 1
Parent item size :10
Add 10. [Cult Of Chaos].mp3 to CD1 - Khaos Legions
item name : 11. [Thorns In My Flesh].mp3
item IsDir : 0
item size :0
parent item name : CD1 - Khaos Legions
parent item IsDir : 1
Parent item size :11
Add 11. [Thorns In My Flesh].mp3 to CD1 - Khaos Legions
item name : 12. [Turn To Dust].mp3
item IsDir : 0
item size :0
parent item name : CD1 - Khaos Legions
parent item IsDir : 1
Parent item size :12
Add 12. [Turn To Dust].mp3 to CD1 - Khaos Legions
item name : 13. [Vengeance Is Mine].mp3
item IsDir : 0
item size :0
parent item name : CD1 - Khaos Legions
parent item IsDir : 1
Parent item size :13
Add 13. [Vengeance Is Mine].mp3 to CD1 - Khaos Legions
item name : 14. [Secrets].mp3
item IsDir : 0
item size :0
parent item name : CD1 - Khaos Legions
parent item IsDir : 1
Parent item size :14
Add 14. [Secrets].mp3 to CD1 - Khaos Legions
item name : CD2 - Kovered In Khaos
item IsDir : 1
item size :0
parent item name : 2011 - Khaos Legions (2xCD, Ltd)
parent item IsDir : 1
Parent item size :2
Add CD2 - Kovered In Khaos to 2011 - Khaos Legions (2xCD, Ltd)
item name : 01. [Warning].mp3
item IsDir : 0
item size :0
parent item name : CD2 - Kovered In Khaos
parent item IsDir : 1
Parent item size :1
Add 01. [Warning].mp3 to CD2 - Kovered In Khaos
item name : 02. [Wings Of Tomorrow].mp3
item IsDir : 0
item size :0
parent item name : CD2 - Kovered In Khaos
parent item IsDir : 1
Parent item size :2
Add 02. [Wings Of Tomorrow].mp3 to CD2 - Kovered In Khaos
item name : 03. [The Oath].mp3
item IsDir : 0
item size :0
parent item name : CD2 - Kovered In Khaos
parent item IsDir : 1
Parent item size :3
Add 03. [The Oath].mp3 to CD2 - Kovered In Khaos
item name : 04. [The Book Of Heavy Metal].mp3
item IsDir : 0
item size :0
parent item name : CD2 - Kovered In Khaos
parent item IsDir : 1
Parent item size :4
Add 04. [The Book Of Heavy Metal].mp3 to CD2 - Kovered In Khaos
item name : Folder.jpg
item IsDir : 0
item size :0
parent item name : 2011 - Khaos Legions (2xCD, Ltd)
parent item IsDir : 1
Parent item size :3
Add Folder.jpg to 2011 - Khaos Legions (2xCD, Ltd)
item name : War Eternal
item IsDir : 1
item size :0
parent item name : Arch Enemy
parent item IsDir : 1
Parent item size :4
Add War Eternal to Arch Enemy
item name : 01-Tempore Nihil Sanat (Prelude in F minor).mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :1
Add 01-Tempore Nihil Sanat (Prelude in F minor).mp3 to War Eternal
item name : 02-Never Forgive, Never Forget.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :2
Add 02-Never Forgive, Never Forget.mp3 to War Eternal
item name : 03-War Eternal.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :3
Add 03-War Eternal.mp3 to War Eternal
item name : 04-As The Pages Burn.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :4
Add 04-As The Pages Burn.mp3 to War Eternal
item name : 05-No More Regrets.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :5
Add 05-No More Regrets.mp3 to War Eternal
item name : 06-You Will Know My Name.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :6
Add 06-You Will Know My Name.mp3 to War Eternal
item name : 07-Graveyard Of Dreams.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :7
Add 07-Graveyard Of Dreams.mp3 to War Eternal
item name : 08-Stolen Life.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :8
Add 08-Stolen Life.mp3 to War Eternal
item name : 09-Time Is Black.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :9
Add 09-Time Is Black.mp3 to War Eternal
item name : 10-On And On.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :10
Add 10-On And On.mp3 to War Eternal
item name : 11-Avalanche.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :11
Add 11-Avalanche.mp3 to War Eternal
item name : 12-Down To Nothing.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :12
Add 12-Down To Nothing.mp3 to War Eternal
item name : 13-Not Long For This World.mp3
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :13
Add 13-Not Long For This World.mp3 to War Eternal
item name : folder.jpg
item IsDir : 0
item size :0
parent item name : War Eternal
parent item IsDir : 1
Parent item size :14
Add folder.jpg to War Eternal
item name : Will To Power
item IsDir : 1
item size :0
parent item name : Arch Enemy
parent item IsDir : 1
Parent item size :5
Add Will To Power to Arch Enemy
item name : 01-Set Flame To The Night.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :1
Add 01-Set Flame To The Night.mp3 to Will To Power
item name : 02-The Race.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :2
Add 02-The Race.mp3 to Will To Power
item name : 03-Blood In The Water.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :3
Add 03-Blood In The Water.mp3 to Will To Power
item name : 04-The World Is Yours.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :4
Add 04-The World Is Yours.mp3 to Will To Power
item name : 05-The Eagle Flies Alone.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :5
Add 05-The Eagle Flies Alone.mp3 to Will To Power
item name : 06-Reason To Believe.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :6
Add 06-Reason To Believe.mp3 to Will To Power
item name : 07-Murder Scene.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :7
Add 07-Murder Scene.mp3 to Will To Power
item name : 08-First Day In Hell.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :8
Add 08-First Day In Hell.mp3 to Will To Power
item name : 09-Saturnine.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :9
Add 09-Saturnine.mp3 to Will To Power
item name : 10-Dreams Of Retribution.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :10
Add 10-Dreams Of Retribution.mp3 to Will To Power
item name : 11-My Shadow And I.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :11
Add 11-My Shadow And I.mp3 to Will To Power
item name : 12-A Fight I Must Win.mp3
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :12
Add 12-A Fight I Must Win.mp3 to Will To Power
item name : folder.jpg
item IsDir : 0
item size :0
parent item name : Will To Power
parent item IsDir : 1
Parent item size :13
Add folder.jpg to Will To Power
----end of listing ----
rootItem.element[0] name : Arch Enemy
rootItem.element[0] IsDir : 1
rootItem.element[0] size :0

i am trying to access sub directories, but "it doesn't work". The original code with displaySdCardContent(rootItem,0); display the first level, and my test also display the only first level

OT: You set no upDir value in your items. However, you don't use it.

I see no apparent error on a first glance, and I don't have the hardware to reproduce. Please [edit] your question with the results of debugging output of item's attributes in displaySdCardContent(). If this looks fishy, do the same while building the tree of items in readSdCard().

the debugging output is already in my question . Before the "23:36:23.675 -> ----Disp----" it's the output while building the tree, and after is the output of '''displaySdCardContent().

Please read closer: I'd like to see all attributes of each item given to displaySdCardContent().

i can only acces items in root, and there is one folder. I can just print name and isDir. upDir is an item and Elements a vector items, i can't print  it.

Thanks. As isDir is 1, item.elements should be iterated. Apparently it is not, so please print item.elements.size(). And so on, you will want to "single-step" through the data with multiple prints.

item.elements.size return 0  ... o_O?
20:20:47.622 -> name : Arch Enemy 20:20:47.622 -> IsDir : 1 20:20:47.622 -> size :0

The next step is logical: Add debug prints to readSdCard() for each completed item before appending it, and to setup() for rootItem.elements[0].

i have edited the question with readSdCard() debug. I don't know why i can't get the begining but what i understand, each item have a size equal to 0, but each time it's add to the parent directory, parentdirectory size rise by 1 and when it change the directory, parent item size restart to 0.

Thanks for the debug log! It looks as if the readSdCard() works like expected and populates your tree. There must be something else. Unfortunately I need some sleep now, I'll get back in some hours.

I think I see what you are trying to do; you appear to be building a tree structure on the stack by recursively navigating the SD file structure. You are clearly expecting that tree structure to still exist intact after the recursively called function's final invocation returns so you can then navigate that tree structure with another recursive function. Are you sure that the tree will exist at the you try to navigate it ?

In the meantime you've got an answer and maybe that solves it but I set up a quick Wokwi ESP32 simulation including a sample file structure but using the LittleFS instead of the SD filesystem so that it can be experimented with online. The core is similar to your original simple recursive scan rather that your two pass solution. It based on a general "randomnerd" tutorial and that appears to work. https://wokwi.com/projects/383917656227391489

thank you, yes the answer solve my problem, but i keep your code, just in case ^^

The error is hard to see, but it is essentially in this original sequence (irrelevant statements omitted):
    FileItem item;
    // ...
    parentItem.elements.push_back(item);
    // ...
      readSdCard(entry, item);
    }

The method push_back() copies the item to elements. Since at that moment item has no elements, the copy also has none. Later modifications of item do not change the copy.
There are multiple alternatives to correct.
1. Recurse first, then push:
    FileItem item;
    // ...
      readSdCard(entry, item);
    }
    // ...
    parentItem.elements.push_back(item);

This way item's elements vector collect its entries before the push_back().
However, the order of debug messages changes.
2. Recurse with the copy:
    FileItem item;
    // ...
    parentItem.elements.push_back(item);
    // ...
      readSdCard(entry, parentItem.elements.back());
    }

In this case readSdCard() uses the copy of item in parentItem's elements to collect the entries.

Thank you so much !! it seems to work, i have quickly try to navigate in tree and Serial.println(rootItem.elements[0].elements.at(1).elements[1].name); return an mp3 file ! Now i have to deal with this tree to print it on my screen but the hardest thing is done :) thank you again !

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


text:
Best Solution to Parallel UART reads with Arduino Due
I have 4 Arduino boards pushing data over UART to 4 serial ports on the Arduino Due at 115200 baud rate.
Data format - <Short URL>,<Number of the Node>
Eg: px.ht/d/mCxG,1"
Arduino Due has 4 hardware serial ports and one native USB port. I want to interface all the 4 UART nodes to each hardware serial of the Due and then push this data onto the SerialUSB port which is native USB at baud rate of 2000000.
What did I try?

Sequential read of all Serial ports - Obviously poor performance
Used Serial Events - For some reason never able to get the callback triggered.
Used some FreeRTOS library and there are a lot of data misses.

When using RTOS, the data from multiple nodes is getting mixed up and printed incorrectly. I'm looking for some efficient way to read parallel data from all UARTs without data overlap and stream data and given the MCU on Arduino Due is very powerful I don't think that's what is bottlenecking the performance.

Sequential read of all Serial ports - Obviously poor performance ... why should the performance be poor? ... have you tested this?

Add a line terminator to your data format (e.g. '\n'). This will make your life much easier.

@jsotola It seems the arduino's wrappers for serial API's are very slow and reading/managing the data is very slow. Yes i did test it

@EdgarBonet Yes I do have a delimiter at the end, however what's the idea you have that could make it easier? You want me to implement a logic to look for this \n and not print until it is found?

this may help ... https://gammon.com.au/serial

@Ergophobia - FWIW, "Grammer" is spelt grammar, i.e. with an "a", not an "e".

It seems the arduino's wrappers for serial API's are very slow

They aren't. There are some functions that depend on timeouts: these can
indeed be very slow. However, if you read the ports in a non blocking
fashion, everything should be fast. Non blocking basically means never
waiting, and never trying to read more bytes than what is currently
available(). For example:
const int buffer_size = 64;  // tune to taste

char buffer1[buffer_size];
int size1 = 0;
// same for buffer2, size2, etc.

void loop() {
    while (Serial1.available()) {
        char c = Serial1.read();
        if (size1 < buffer_size - 1)
            buffer1[size1++] = c;  // buffer the incoming character
        if (c == '\n') {  // found end-of-message
            buffer1[size1] = '\0';  // terminate the string
            Serial.print(buffer1);  // send through USB
            size1 = 0;  // get ready for next message
        }
    }
    // then the same for Serial2, ...
}

If you know a bit about object oriented programming, you can easily
rewrite this in a more elegant way, with no repeated code.

Thanks @EdgarBonet, I'll definitely try out this logic, however I'm wondering if there's a way I can utilize DMA of the SAM3X to directly push data from UART buffer into the USB buffers. I believe this significantly increases performance. What do you say? Is there a DMA wrapper you're aware of that I can use with Arduino IDE?

There is no DMA-specific support in the Arduino APIs that I know about. But given that you have a fast CPU, I would expect you don't need it.

@Hako don't lose sight of the fact that the data arrives at snail's pace ... if the computer was a person, a byte would arrive once a week

@jsotola hahahaha, ofcourse i understand sam3x runs at high frequencies but my concern is these nodes might increase in future and I need my code to be scalable. Anyway, let me first try out the edgar's code and come back with some quick results.


text:
Can't program Arduino via Bluetooth (HC-06) with a Mac
I bought a HC-06 Module for my Arduino Uno the other day, yesterday it arrived and I'm having trouble using it with the Arduino IDE.
I set it up, connecting 5V, GND and RX/TX crossed. After a bit of searching, it shows up on the bluetooth settings on the macbook. When I click "connect", it fails, after I click "Options", then set the Pin to 1234 it says "Connected". The LED on the HC-06 is still blinking (which is OK I guess, since I'm not yet communicating).
I have a Sketch running on the Uno that prints out some text. When I open the serial monitor (after connecting like above) it works, displaying the values I expect. However, after closing the serial monitor the HC-06 changes to "not connected" on the mac.
Also, if I try to upload code via the Arduino IDE it states: avrdude: ser_open(): can't open device "/dev/tty.HC-06-DevB": Resource busy
ioctl("TIOCMGET"): Inappropriate ioctl for device or throws a processing.app.SerialException: Fehler beim Öffnen des seriellen Ports "/dev/tty.HC-06-DevB". (German for "Error while opening Serial Port "/dev...." ").
Do I have to configure the HC-06 or the Arduino IDE in any way to make this work, and, if so, how can I do that?
Edit:
I've also connected TX and RX uncrossed, though that alone doesn't solve the problem.
Thanks in advance for your Support!

not enough rep to vote up Roldofo's comment, but his suggestion to rename to "ArduinoBT01" seem to make all the difference!

The on-board USB-to-serial pulses the reset line to start the bootloader. HC-0x don't have the extra signal available that USB uses for that so you'll have to manually reset the Arduino just as - or very slightly after - you click to start the upload on your Mac; you may need to experiment to get the timing right, but once you know it, it isn't hard to do. Keep Rx & Tx crossed as you do for Bluetooth terminal communication. And even with all that, I've never achieved anything like USB upload speeds (baud rate for baud rate) using Bluetooth.
Update:
In brief, it could be timing, baud-rate, or pairing.
I find it easy to get the timing: hold reset / click (and let go) the upload button / release reset. It doesn't need to be so fast that it's a challenge to coordinate but do it faster than counting seconds.
Your HC-06's baud rate will have to match the baud-rate your boot-loader expects. It looks like Uno's bootloader's use 19200 baud (and there are some way older ones that used 9600). My bare, pre-programmed chips' boot-loaders from Adafruit.com use 57600 baud. Your preferences.txt file should contain a line like 'atmega328o.upload.speed=115200'; assuming you're able to upload via USB, then use this baud rate for the HC-06. (The path to your preferences file is displayed on the Arduino IDE's preferences dialog.)
The 'Resource busy' message sounds like your Mac isn't paired with your HC-06. In the MacOS Bluetooth System Preferences pane, pair the Mac with the HC-06 and be sure HC-06's LED is on steady (not blinking).

So it's a timing Problem? I tried countless times to reset the arduino while I uploaded, but I never succeeded. Is there a way to reset the arduino automatically? And does the baud rate of the HC-06 matter?

Did you also try it with Tx Rx crossed?
And the baudrate of both devices should be the same.

In bootloader code baud rate is set 19200: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/bootloaders/atmega/ATmegaBOOT_168.c

I'm having similar problems: http://forum.arduino.cc/index.php?topic=314356 Any thoughts

If I remember correctly, you do not want to cross TX and RX.
Usually, you cross TX/RX because you are looking at it from the opposite side - the PC's TX is the Arduino's RX and vice-versa.
However, in the case of BlueTooth, the HC-06 has the same perspective as the Arduino - TX (transmit) is TX on the HC-06, since that is what the HC-06 transmits (over Bluetooth).
Also, if you are connect your Arduino via USB, the TX & RX are also connected via USB; I don't know if this would cause cross-talk. It shouldn't (so long as you don't send to your Arduino using Bluetooth AND USB at the same time), but it may. Also, as you're programming the Arduino using Bluetooth, you may get the Arduino's responses coming back to you via Bluetooth.
ADDITIONAL:
Go read http://arduino.cc/en/Hacking/Bootloader?from=Tutorial.Bootloader - this is all about the bootloader.
It seems from that that current bootloaders run at 19200, some older ones run at 9600. There are commands to program the speed on HC-06 - instructions can be found at http://www.instructables.com/id/AT-command-mode-of-HC-05-Bluetooth-module/ (this covers the hc-06 too).
Based on the bootloader tutorial, I think you have "less than a second" (only two specific boards are mentioned, so this is a best guess; I am amazed that it is this long, I expected a few milliseconds). If you have a USBISP, you could compile and upload a new firmware, with settings more to your liking - this is outside the scope of this article.
Another option is to create a completely separate uploader - an AtTiny could do it. Connect the AtTiny to the serial port, and then get the AtTiny to reset and program the board, or even program it via ICSP. This is a lot of work, and also outside the scope of this article.

Yeah, makes sense. Thank you! Unfortunately, it doesn't solve the problem if I connect the cables uncrossed. I've updated the question to reflect this.

Regarding the ability to upload, that is correct - you won't be able to upload code via Bluetooth. In addition to providing a serial connection, the USB connection does something extra (hold reset, I think), when you upload via serial-over-usb.

So it's not possible at all to upload code via Bluetooth? That's bad..

Well, if this is true, you can try to hold reset while uploading over serial?

You can also implement software reset: f.e. sending 'secret reset command' and searching is in input stream. If found - reset

After dealing with the problem for several hours I unexpectedly solve the problem.
The HC-06's LED keep blinking after I entered the "1234" code. In my case (I'm using Windows 10), the HC-06 status changed to "connected" for few seconds and then changed to "Paired". Once I opened the correct COM port to receive data from the HC-06 to my PC computer, the LED changed to solid ON. Then I was able to catch data from my Arduino UNO. As soon as I closed the COM port in my PC (I used CoolTerm), the LED changed to blinking back again. The COM port I used to receive the data was the one indicated with direction "Outgoing" in the PC's Bluetooth settings. So, I was expecting the HC-06 to behave as my Bluetooth speakers or my Bluetooth headphones: Always connected. I was wrong and it cost me several hours of testing.
In my firsts tests I focused opening the COM port with direction "Incoming". Nothing happened here and I lost a lot of time. I tested my wiring between the arduino and the HT-06 module by changing the device name from "HC-06" to "ArduinoBT01" and it worked.
This is the sketch I used to receive data form the Arduino via Bluetooth:

This is the CoolTerm's window capture:

Mysteriously, the CoolTerm speed setting is 14400bps but the speed in the device manager for COM34 is 9600bps. After triying opening many times the COM34 port with 9600bps I got this error in CoolTerm:
"An error occurred while attempting to open the port".
"1168: Error 1168"
So, it only works with 14400 bps. Crazy!!
I hope this helps.
Sorry for bugs in my English.


text:
NRF24 Mixing with/without antenna
Is it possible to have the NRF24 module on an Arduino Mini transmitting to an NRF24 with SMA antenna on a Mega?  In that case, would the antenna on the Mega help pickup the signal of the transmitting Arduino Mini?

See https://www.youtube.com/watch?v=gtM832Z0ujE for an extensive comparison between different types of modules and antennas. What specific model are you talking about? A PA+LNA model, or just one with an SMA antenna instead of the prevalent  PCB antenna?

@Gerben  Just the antenna http://www.aliexpress.com/item/NRF24L01-Wireless-Transceiver-Module-SMA-Antenna-Microcontroll-for-Arduino-2-4G/32230572315.html?spm=2114.031010208.3.2.NyZjhh&ws_ab_test=201526_5,201527_4_71_72_73_74_75,201409_3

The regular antenna and PCB antenna have different polarization, so not ideal. But you will still get some extended range.

Yes, and yes.
A module without an antenna is exactly the same as a module with an antenna, it's just that the antenna is part of the PCB. Yes, the module with the antenna will have more sensitivity (able to receive fainter signals) as well as more transmitting power.
The same is true of the modules with the power amplifier.  They again have even more sensitivity and transmitting power.
It is quite common to have a single powerful transceiver with power amplifier and antenna as a base station and then smaller modules as the remote slave devices.  Especially if you couple the base station with a suitable parabolic or uni-directional high gain antenna to point directly at where the slave devices are.

Your answer is mainly right, but I have to warn that most models with an antenna are fake. You will have compatibility issues when there is a mixed environment with both original and fake chips.

As an update, I purchased this and it worked http://www.aliexpress.com/item/NRF24L01-Wireless-Transceiver-Module-SMA-Antenna-Microcontroll-for-Arduino-2-4G/32230572315.html?spm=2114.031010208.3.2.NyZjhh&ws_ab_test=201526_5,201527_4_71_72_73_74_75,201409_3 I get about 2 meters extra range compared to no antenna when using it through a concrete wall.


text:
Cant upload sketches
I started using the arduino as a hobby and it really is quite fun. I took a break for a bit and when I came back I wasnt able to upload a sketch to my UNO. I checked to see if I was using the correct port and programmer and everything seemed fine. Not exactly sure what to do so I was hoping someone could help me.
Thanks in advance.
Here is the error message I receive every time I try to upload a sketch:
Arduino: 1.8.13 (Windows 7), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\User\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\User\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\User\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10813 -build-path C:\Users\User\AppData\Local\Temp\arduino_build_36096 -warnings=none -build-cache C:\Users\User\AppData\Local\Temp\arduino_cache_693101 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avrdude.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -verbose C:\Users\User\Desktop\Arduino\Blink\Blink.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\User\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\User\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\User\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10813 -build-path C:\Users\User\AppData\Local\Temp\arduino_build_36096 -warnings=none -build-cache C:\Users\User\AppData\Local\Temp\arduino_cache_693101 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avrdude.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -verbose C:\Users\User\Desktop\Arduino\Blink\Blink.ino

Using board 'uno' from platform in folder: C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3

Using core 'arduino' from platform in folder: C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3

Detecting libraries used...

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

Generating function prototypes...

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp" -o "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\preproc\\ctags_target_for_gcc_minus_e.cpp" -DARDUINO_LIB_DISCOVERY_PHASE

"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\preproc\\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp" -o "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp.o"

Compiling libraries...

Compiling core...

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\wiring_pulse.S.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\WInterrupts.c.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\wiring_analog.c.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\wiring.c.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\wiring_digital.c.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\hooks.c.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\wiring_pulse.c.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\wiring_shift.c.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\CDC.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\HardwareSerial.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\HardwareSerial1.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\HardwareSerial2.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\HardwareSerial3.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\HardwareSerial0.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\Print.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\Stream.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\Tone.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\WMath.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\PluggableUSB.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\WString.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\USBCore.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\new.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\abi.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\IPAddress.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\main.cpp.o

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\core.a

Archiving built core (caching) in: C:\Users\User\AppData\Local\Temp\arduino_cache_693101\core\core_arduino_avr_uno_cac111a68e84b6e7f84741aaeecd4f29.a

Linking everything together...

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.elf" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp.o" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/core\\core.a" "-LC:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096" -lm

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.elf" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.eep"

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.elf" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.hex"

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.elf"

Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.

Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x33

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x33

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x33

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x33

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x33

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x33

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x33

avrdude: stk500_recv(): programmer is not responding

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x33

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x33

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x33

Hope you will be able to help

It's a generic communications error between the Arduino and your PC, there can be many reasons for this, going through the steps outlined in Juraj's link above may get you closer to the cause. Another thing worth trying is holding down the Arduino reset button until uploading starts then releasing it.

Still nothing.  I tried everything except trying a new computer or arduino because I only have one of each.  I'm thinking of ordering a new Arduino. Still deciding if it should be another UNO or maybe a Micro or Nano. Thank you so much for helping.


text:
Arduino | external power supply and USB at the same time
Arduino | external power supply and USB at the same time
I have got an Arduino Mega 2560 project with many sensor and outputs.
Right now I’m supplying it with an external stabilized 5V over the 5V pin (so that I’m using only one power source for all sensor, outputs and Arduino.)
I also have a Raspberry PI connected to the Arduino via USB for flashing and also logging.
The Raspberry PI has got an external power supply (and also a board with SSD.)
The problem:
If I unplug the RPI external power supply, the Arduino Mega is supplying the RPI with power!!! That’s exactly what I do not want. (Also it’s far too little power for RPI, which isn’t even booting correctly.)
Even when I power the Arduino Mega 2560 over the barrel plug (stable 9V), the RPI will be provided with a 5V over the USB cable.
I’m looking in the electrical wiring diagram: I can see the FDN304V
The comparison circuit (LM358D) controls this p-channel mosfet FPN340P. But why is it USBVCC connected if the Gate provides 5V over the LM358D?

I saw this interesting articles but I'm a bit confused:
https://arduino.stackexchange.com/questions/893/what-happens-if-i-power-the-arduino-with-both-the-usb-and-external-power-voltage
What happens if I power the Arduino with both the USB and external power voltage simultaneously?

In previous work coworkers solved this by adding Schottky diode to the cable usb cable. But it's also possible to change 3V3 reg to 1.8 and connect VIN with 5V (It's turning off the mosfet if VIN is 2 times 3V3)

get a short USB type A extender and cut the 5 V wire inside the extender cable

@jsotola
Yes, that was exactly my idea. Actually is very simple in my situation: My RPI is connected with a cable soldered to the usb plug of the Arduino (just because of space problems) -> so I just have to disconnect the 5V pin
But I'm more interested in an "professional" solution also I'm very curious why the this circuit with the FDN340P is not working as I thought!

-KIIV A schottky diode sounds actually nice, but there will be a voltage drop (even when its much less than a normal diode). Probably about 0.2-0.3V which result in a power loss of 90mW @300mA current consumption.

@stevo the question about the circuit is not about arduino ... it belongs at https://electronics.stackexchange.com/questions ... anyway, look closely at the MOSFET symbol ... MOSFETs contain a body diode

@jsotola
ah ok thanks. I did not really realize this body diode inside the MOSFET. now it makes sense.
Do you have any idea, why Arduino uses this type of circuit: Where current can flow to the usb device?

Assuming your question is more along the lines of "How to prevent back driving a USB connected RPi through an externally powered Arduino".
Consider cutting the positive power wire in the USB cable connected between the RPi and the Arduino.
As for this specific question:

But why is it USBVCC connected if the Gate provides 5V over the
LM358D?

Is it possible you are describing how a N-Channel MOSFET works?  The MOSFET in the schematic is a P-Channel MOSFET. The net USBVCC is connected to the net +5V when the P-Channel MOSFET gate is LOW. And is not connected when the gate is HIGH.

Yes correct, I'm asking exactly this: Why is this circuit powering ("back driving") the USB device.
Well I think @jsotola answered already my question: There is a small body diode within this p-channel mosfet which allows current to flow into the USBVCC direction.
Yes, I'm disconnecting the 5V pin, that was also my workaround idea. (Actually is very simple in my situation: My RPI is connected with a cable soldered to the usb plug of the Arduino.)


text:
SIM900A Module doesn't send SMS to user anymore, after previously working
I'm trying to make a hydroponics project that collects data from sensors and sends it to the user through SMS every 15 minutes. However, when I try to run tests now, the pump part of the code works perfectly fine but the earlier part of the code that deals with sending the SMS doesn't work. I've tested the sim module by itself and it works, so it's not a hardware problem. What seems to be the problem here?
#include <SoftwareSerial.h>
#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <EEPROM.h>
#include <GravityTDS.h>
#include <Servo.h>

#define ONE_WIRE_BUS 5
#define DHTPIN 7
#define DHTTYPE DHT11
#define TdsSensorPin A1
#define PUMPPIN 11

SoftwareSerial mySerial(9, 10);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DHT dht(DHTPIN, DHTTYPE);
GravityTDS gravityTds;
Servo myservo;

char msg;
char call;

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  dht.begin();

  sensors.begin();

  gravityTds.setPin(A1);
  gravityTds.setAref(5.0);
  gravityTds.setAdcRange(1024);
  gravityTds.begin();

  myservo.attach(PUMPPIN);
}

void loop()
{
  const unsigned long SECOND = 1000;
  const unsigned long MINUTE = 60*SECOND;
  const unsigned long HOUR = 60*MINUTE;

  delay(30L * SECOND);
  int h = dht.readHumidity();
  float t = dht.readTemperature();
  float tdsValue = 0;
  float temperature = t;
  gravityTds.setTemperature(temperature);
  gravityTds.update();
  tdsValue = gravityTds.getTdsValue();

  sensors.requestTemperatures();

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+************\"\r"); // Replace x with mobile number
  mySerial.print(h);// The SMS text you want to send
  mySerial.print("% humidity, ");
  mySerial.print(t);
  mySerial.print(" degrees Celsius air temperature, ");
  mySerial.print(sensors.getTempCByIndex(0));
  mySerial.print(" degrees Celsius water temperature, ");
  mySerial.print(tdsValue,0);
  mySerial.print(" ppm");

  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

  myservo.write(0);   //Clockwise maximum speed rotation
    delay(30L * SECOND);
  myservo.write(90);
  delay(15L * MINUTE);
}

You might want to [edit] out your phone number

maybe you forgot to pay your cellphone bill ... test the SMS function without any of the other code

I've checked the module itself and it still sends, so the SMS module by itself cans till send text messages.

When you do AT+CMGS="+xxxxxxxxx\r", you are supposed to wait for the acknowledge return by the module, it will shows a prompt >, only then you can send the message out. If you don't do that, add a delay(1000) after the AT+CMGS line. You basically send the data prematurely.


text:
The Arduino Oscilloscope - Error message: 'ADCSRA' was not declared in this scope
Project: The Arduino Oscilloscope - published in The MagPi No. 71 July 2018
This is my first Arduino project!
I'm porting over the sketch "Gather_A0.ino" but I'm encountering compile errors:
Error message: 'ADCSRA' was not declared in this scope.
What am I missing?
Error message:

Arduino: 1.8.12 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
D:\Arduino & Raspberry Pi\Oscilloscope\Arduino_Scope\Software\Gather_A0\sketch_apr09a\sketch_apr09a.ino: In function 'void setup()':
sketch_apr09a:15:3: error: 'ADCSRA' was not declared in this scope
   ADCSRA = (ADCSRA & 0xf8) | 0x04; // set 16 times division
   ^
D:\Arduino & Raspberry Pi\Oscilloscope\Arduino_Scope\Software\Gather_A0\sketch_apr09a\sketch_apr09a.ino: In function 'void trigger()':
sketch_apr09a:58:4: error: expected 'while' before '{' token
   }{
    ^
sketch_apr09a:58:4: error: expected '(' before '{' token
sketch_apr09a:58:4: error: expected primary-expression before '{' token
sketch_apr09a:58:4: error: expected ')' before '{' token
sketch_apr09a:58:4: error: expected ';' before '{' token
sketch_apr09a:60:1: error: expected '}' at end of input
 }
 ^
exit status 1
'ADCSRA' was not declared in this scope

ADSCRA is a register involved in analog inputs on an AVR board.  The analog input on an ESP8266 works completely differently.  You'll have to figure out what the AVR code does and then figure out how to do the same thing on the ESP.  It's not going to be a simple "change this to that" sort of solution.

I see, my best solution is to order a real Arduino board. I will do that. Thank you -Delta.

The article is using an Arduino Nano. You can get the source code without the bugs you've introduced at https://github.com/Grumpy-Mike/Mikes-Pi-Bakery/tree/master/Arduino_Scope

the esp8266 like to hang if you read its ADC more than ~1000 times per sec.


text:
Tapered log potentiometer to linear formula
I have a tapered log 10K potentiometer. I would like some function which returns tapered log value to linear values.
The potentiometer is a slider. When connected to the Arduino the wiper displays the values ranging from 0 to 1023.  Currently if I set the slider to the half way position it displays the value 856 (approx), when I'd expect (or want) the value it to be more like 512 (as it's half way). The quarter way mark for example shows a value in the region of 570, where I'd expect the value to be 256. I hope that this makes sense.
This is about the extent of the code so far :))
  curpos1 = analogRead(potPin);

  Serial.println(curpos1);

You can search for gamma correction which probably helps you find a suitable formula.

If it's a log, you could convert in back to linear by using the exponent. A lot of these pots have just two linear sections in them which approximates a log, (or inverse log in your case). I'd just put a ruler next to the slider; move the slider in small even increments; put the values in excel, and create a plot. You can then see if it's an actual log pot, or just aproximated. You can then, in excel, play with some formulas to get back a linear value.

Or just use a lookup table...

what are you using the pot for?


text:
Encrypting and decryption RSA (Or other asymetric encryption) on Arduino Mega
I want to encrypt and decrypt like 200 char strings on arduino mega, but I failed to find any library/code that can do that. Do you have any experience with doing that? Thanks.
I'd like to use any asymmetric encryption
The key should be ideally at least 128bit long.

what search terms did you use? ... google returns a lot of hits for arduino encryption lib

Arduino RSA, Arduino asymetric encryption, arduino mega RSA… but I didn’t find any that supports this.

Try "public key" as a substitute term for "asymetric". I see EC-related stuff that would seem to qualify as "other asymetric" per title.

try arduino encryption lib


text:
Neo 6m outputting something i as a noob can't understand
So i connected my ublox neo 6m gps breakout board GY-GPS6MV2 to the arduino software serial and got this result, i used resistors and only supplied 3.3v to the board, gps encode library couldn't give me anything out of this. if possible please help and if this is the wrong forum please suggest a better one. also the board thinks that the date for some reason is Mar 17 2011 16:18:34*59. which is pretty wierd.

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*5D

$GPTXT,01,01,02,ROM CORE 7.03 (45969) Mar 17 2011 16:18:34*59

$GPTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*20

$GPTXT,01,01,02,ANTSTATUS=DONTKNOW*33

$GPRMC,,V,,,,,,,,,,N*53

$GPVTG,,,,,,,,,N*3⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*5D

$GPTXT,01,01,02,ROM CORE 7.03 (45969) Mar 17 2011 16:18:34*59

$GPTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*20

$GPTXT,01,01,02,ANTSTATUS=DONTKNOW*33

$GPRMC,,V,,,,,,,,,,N*53

$GPVTG,,,,,,,,,N*3⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 F⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*5D

$GPTXT,01,01,02,ROM CORE 7.03 (45969) Mar 17 2011 16:18:34*59

$⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*5D

$GPTXT,01,01,02,ROM CORE 7.03 (45969) Mar 17 2011 16:18:34*59

$GPTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*20

$GPTXT,01,01,02,ANTSTATUS=DONTKNOW*33

$GPRMC,,V,,,,,,,,,,N*53

$GPVTG,,,,,,,,,N*30

$GPGGA,,,,,,0,00,99.99,,,,,,*48

$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30

$GPGSV,1,1,00*79

$GPGLL,,,,,,V,N*64

$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

Here is the full unedited output after 40 mins
https://drive.google.com/file/d/148W_6shE0U2lprimApvtvG1i3Vf2-Izx/view?usp=sharing
edit:- i also connected the tx pin to the rx and vice versa and used a resistor as told by an tutorial on the tx pin from the arduino or the rx pin of the board. it is also sending many gptxt messages which some say on other forums are usally send when some error occurs or the board restarts. idk why it is coming on my board.

does anyone know anything i can do to fix it?

What do you mean by " i used resistors and only supplied 3.3v to the board" ?

@Majenko i followed a tutorial which said me to attach 3.3v to vcc pin and use resistors on the tx pin which sends data from arduino.

Why do you think there's something wrong? What kind of output did you expect? The GPS is outputting NMEA data just like it's supposed to. It's not supposed to be human readable. You mention a date in 2011 but that's looks to be the date the ROM core was compiled, not wat the GPS thinks is the current date. Not weird at all. You need software to interpret the NMEA output, like TinyGPS. Try it.

@StarCat the gps is supposed to atleast give proper nema data and a nema lat long, but if you open the drive doc, the nema is just sending gptxt texts and most of the nema fields are empty. and tinygps just gives 0,0 at lat long and this is after keeping it on for 40 mins

That's because it probably does not have a fix yet. That may take a very long time and your GPS needs to have an unobstructed view of the sky. Many "U-blox" GPS chips are fake and can have all kinds of problems (like taking impossibly long to get a fix).

It looks to me like it's browning out and resetting repeatedly.

@Majenko yeah thats what i thought too. please help if you can

@StarCat the chip is real and i can assure you the chip is real.

@gamer1478 Ok, if you say so. Did you run checks to confirm it and did you buy it from a reputable seller? Do you have a link to where you bought it or do you have any documentation for the module? It looks like the power supply might be an issue. Maybe a photo of your setup might help.

@StarCat Yes. I bought 10 chips from the seller and the seller is reputable from china. I buy from him using alibaba. And all other chips are working and getting gps lock and data using the same circuit and Arduino. Due to the low value of 1 chip replacement is not an option as delivery value from india to china with export taxes is higher than the value of the chip. If possible please tell some way to fix this. My power supply is just normal Arduino Uno 3.3v supply. I can't share a photo due to some privacy concerns.

@StarCat I am very new to gps and gps chips but I am by no means new to coding or  arduino. I meant I am noob in like gps and stuff. I have used the gps chip also in my drone following a tutorial and it works absolutely fine there.

Ok, I understand. I'm asking because I know there are a lot of fakes around (have run into them myself). Is there any way you can check for a stable power supply or a marginal connection? Or do you have a schematic? It's hard to troubleshoot something that I can't see. If you say that all of the other chips you bought are functioning well, I would consider the possibility that this one is faulty. I know some GPS boards are 5V tolerant and have their own 3.3V stabilizer. Maybe yours is too?

@StarCat i have a GY-GPS6MV2 chip. this is the wiring-(https://www.xarg.org/image/GY-GPS6MV2.png) (but instead of vcc to 5v it is connected to  3.3v), many people online say that this breakout board is 5v tolerant and has an onboard regulator, haven't tested that yet but all other chips are working too, so it might be that this one is faulty. but i don't think so as this problem is pretty new to me, it is printing stuff in the console but has no data in it.

@StarCat thanks for help, someone on ublox portal recommended me to connect the boards vcc to 5v's and when i did that, it stopped rebooting, and after 20 mins got a lock, thanks for your help.

someone on ublox portal recommended me to connect the boards vcc to 5v's and when i did that, it stopped rebooting, and after 20 mins got a lock, thanks for your help.
the guy on ublox portal

Post a photo of the board and a link of where you bought it so that we can point out that 5V is needed.
The reboot symptom is usually caused by an inadequate voltage source --- when the 6m starts, current draw is low, when it finishes initial startup, it goes to work looking for sats and current draw jumps up. The higher current draw on a poor power source causes supply voltage to drop too.low which then causes the 6m to reset and restart and will happily repeat the cycle forever.
Use a good DVM or oscilloscope to verify the inadequate voltage source.

after connecting the board to 5v supply the problem seemed to be fixed


text:
Arduino OR operator
I have been trying OR conditional operator in a if condition statement in my arduino program and the result is not what I expected.
My program:
// three variables assigned to const int datatype as the
// pin numbers they are assigned to are  going to remain
// constant through out the program.
const int led1=10;
const int led2=11;
const int led3=12;

void setup(){
  // assigning the pins as input/output.
  pinMode(10,INPUT);
  pinMode(11,INPUT);
  pinMode(12,OUTPUT);
}

void loop(){
  control();
}

void control()
{
  int task1 = digitalRead(led1);
  int task2 = digitalRead(led2);
  if (task1==HIGH || task2==HIGH)
  {
    digitalWrite(led3,HIGH);
  }
  else
  {
    digitalWrite(led3,LOW);
  }
}

if the 'IF' conditional statement used without 'OR' operator is working fine that is not including both the tasks instead only one task either task1 or task2, else it is working without errors but the result is not as expected.
hardware part is all fine. i reckon that there is a problem with the OR || operator.

The 'or' operator is fine, your error lies elsewhere. But you do not give enough detail to help people diagnose your problem. How did you test the program? What behavior do you expect? What behavior does it show instead?

Could you try the ^ operator instead of (||), if this works for you, I'll explain it in greater detail.

I would also not advice using "led" as input. You might want to rename it to button or whatever other input device you're using.

@EdgarBonet - my objectice is to switch on the 3rd led pin high if any of the tasks i have assigned in my programme goes high. for example i have two push buttons thats assigned to task1 and task2 respectively.so when i press either of the push button the 3rd led pin must go high instead its low. i have tested it on PCB which has an atmega328 IC and the IDE is arduino IDE.

@FuaZe - i tried your input idea,but that didnt work as well. and i have no idea how i can use the bitwiseXOR operator for my application.

Could you please show the circuit schematic? How did you wire the LED on output 12? And the push-buttons? And why are those push-buttons called “led”?

Okay, could you specify when you want the led3 to go high. The code you have does it if any of these two is high and/or when both are high. What result do you think it should've had, or what do you want to achieve?

@EdgarBonet@FuaZe. thank you foremost for helping me out through this problem. i am a beginner to arduino platform thats why the variable name led occured to a push button  :-D. i wil make sure i work on the ethics of programming. your work is really appreciated.

Your code is correct for what you described you want it to do - raise led3 when either or both of led1 or led2 is high, and make it low otherwise. Some things to check:

Do the push-buttons pull their respective pins HIGH? (Pulling LOW is more common).
Are the pins pulled to ground with a 5K or 10K resistor, and not left floating, when the respective button is not active?
Real buttons need to be de-bounced. They behave as if their contacts bounce several times before making contact (even though that isn't really what happens). If this is an experiment and you hold the button down, even briefly, you should get proper results without de-bouncing, but it's something to be aware of as you move on.

If you aren't getting the expected result, as JRobert suggested you should look at your hardware. Ensure pull-ups/downs are being used correctly, your interpretation of your hardware's logic is correct (positive/negative logic), and maybe even use a simple sketch to check that everything is working correctly. Firstly I would simplify the control function. You could try replacing the OR with a bitwise OR, or changing your variables to booleans. Realistically, more code and a diagram illustrating your implementation would help us reproduce and troubleshoot this with you. I'm a little confused as to whether pins 10 & 11 are LEDs or Buttons. I would be happy to help you get a test program together if you can provide more detail. :)
void control()
{
    boolean task1 = digitalRead(led1);
    boolean task2 = digitalRead(led2);

    // Note that the if isn't needed
    digitalWrite(led3, (task1 || task2));

    // If your buttons use negative logic
    // digitalWrite(led3, (!task1 || !task2));
}

For humour-sake when I hit a problem that doesn't make sense, I rework my logic to break down the problem and output in stages, or use the Serial library to output what is going on periodically.

Arduino Serial Reference
Arduino Serial Tutorial

Typically for inputs and outputs I define a structure which buffers everything per IO, and write my code with a loop-based mentality, much like how a game loop is implemented in video games. It is easy to print and trace when troubleshooting, and the positive/negative/default-state logic is abstracted. This will help you get started if you are curious.

Game Loop Example