Void setup() Error of looping

Hi all,

I m facing a wierd error on my Arduino MEGA...
I have a program to dump sensors data on my SD card...
Sadly, the commands in void setup() seem to loop...

This is my code:

#include <SPI.h>
#include <SD.h>
#include <Wire.h>

#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#include <SoftwareSerial.h>
#include <TinyGPS.h>


TinyGPS gps;
SoftwareSerial ss(2, 3);  //D2-TX, D3-RX

float T, P, RH;
const int chipSelect = 53;

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;

static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);

void setup() 
{
  Serial.begin(9600);
  while (!Serial)
  {
    Serial.println("Accessing SD card......");
    }
  

  // Open serial communications and wait for port to open:
  Serial.print("\n Oh God Why...");
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }

  ss.begin(9600);
}

void loop() {
.....
}

The output I get is:

Oh God Why....
Oh God Why....
Oh God Why....
...
..
.

Can someone help me...

I have never seen this error before...

The likely cause is that the Mega is continuously re-starting. Possibly something is overloading it?

Why are you using SoftwareSerial on a Mega which has 3 spare HardwareSerial ports?

...R

Thanks Robin...

I am using GPS module, it dumps data to Arduino via Software serial...

How to use it without Software serial..?

Thanks....

How to use it without Software serial..?

Use Serial1, Serial2 or Serial3

See Serial pins for details of the associated pins

pr01284:
I am using GPS module, it dumps data to Arduino via Software serial...

How are you powering it? If from the Mega 5V pin then maybe the GPS receiver is taking more current than is available.

Too bad a snippet was posted and we can't see what the loop() function is doing.

For example, if loop() calls setup() I would expect to see results like this. There are other ways as well. I don't think that this is the case, but only the one asking for help knows for sure.

One thing to try is to have an empty (do-nothing) loop() function. If this works, start putting things back in loop() a little bit at a time.

  while (!Serial)

{
    Serial.println("Accessing SD card......");
    }

So while the serial interface is not ready, print something over serial?

And while (!Serial) is not usefull / needed on a Mega, it will always evaluate to true. It might or might not be needed on Arduinos with native USB ports (depending on your needs).

Thanks UKHeliBob,

Yes I I tried that way and now am stuck with the fact the Serial Port is not working... Is there a way to test the working of Serial ports RX-TX1, 2, 3 ?

If yes please let know, thanks....

UKHeliBob:
Use Serial1, Serial2 or Serial3

See Serial pins for details of the associated pins

pr01284:
Thanks UKHeliBob,

Yes I I tried that way and now am stuck with the fact the Serial Port is not working... Is there a way to test the working of Serial ports RX-TX1, 2, 3 ?

Loopback or loop one to the next.

Hi I made a simple code for loopback...

Will this work or am i missing something...?

#include <SPI.h>

int a;

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

void loop() {
// Check for SERIAL 2
  while(Serial2.available()){
    Serial3.print(45);
    a = Serial2.read();
    Serial.print(a);
  }
}

TheMemberFormerlyKnownAsAWOL:
Loopback or loop one to the next.

Also from referring many tutorials, I use only 3.3V for Neo GPS

PerryBebbington:
How are you powering it? If from the Mega 5V pin then maybe the GPS receiver is taking more current than is available.