1

I am doing a project right now that involves a Neo 6M GPS module, a micro sd card module and 6 BH1750 light sensors. All the modules work fine when testing them standalone, especially the GPS module works as it should with TinyGPS++ example sketches. When i run the "DeviceExample" sketch, it takes around 6 seconds to revieve time and around 10 seconds to recieve the location. However in my own sketch it only updates time every 3 or more seconds as well as i think it also updates location very slow.

Sometimes it even works for a short time, sometimes it never works, no matter how long the sketch runs. Here is an example log: As you can see, the sketch did not retrieve full date 20 secs after starting, but time is updating every second. Yet you can see that the time isn't updated anymore 5 seconds before the module is retrieving location and then the update interval gets slowed down, even though the module itself still indicates the update interval of around .5-1 second.

The Neo 6M GPS module is connected directly to RX,TX,GND,VCC and works fine with the example sketches. Has anybody a solution to this?

ms(), longitude, latitude,month,day,year,hour,min,sec,centisecs,alt,6 lux values
17642, 0.000000, 0.000000,0,0,2000,22,26,13,95,0.00,106,106,6,0,3,106,
17980, 0.000000, 0.000000,0,0,2000,22,26,13,95,0.00,106,106,6,0,3,106,
18333, 0.000000, 0.000000,0,0,2000,22,26,13,95,0.00,106,106,6,0,3,106,
18803, 0.000000, 0.000000,0,0,2000,22,26,14,95,0.00,106,106,6,0,3,93,
19131, 0.000000, 0.000000,0,0,2000,22,26,14,95,0.00,33,33,6,0,3,0,
19530, 0.000000, 0.000000,0,0,2000,22,26,14,95,0.00,0,0,6,0,3,40,
19956, 0.000000, 0.000000,0,0,2000,22,26,15,95,0.00,106,106,6,0,3,106,
20311, 0.000000, 0.000000,0,0,2000,22,26,15,95,0.00,106,106,6,0,3,106,
20787, 0.000000, 0.000000,0,0,2000,22,26,16,95,0.00,106,106,6,0,3,106,
21114, 0.000000, 0.000000,0,0,2000,22,26,16,95,0.00,106,106,6,0,3,106,
21504, 0.000000, 0.000000,0,0,2000,22,26,16,95,0.00,106,106,6,0,3,106,
21942, 0.000000, 0.000000,0,0,2000,22,26,17,95,0.00,106,106,6,0,3,106,
22292, 0.000000, 0.000000,0,0,2000,22,26,17,95,0.00,106,106,6,0,3,106,

...

240540, 0.000000, 0.000000,10,14,2018,22,29,56,95,0.00,106,106,6,0,3,106,
240869, 0.000000, 0.000000,10,14,2018,22,29,56,95,0.00,106,106,6,0,3,106,
241249, 0.000000, 0.000000,10,14,2018,22,29,56,95,0.00,106,106,6,0,3,106,
241697, 0.000000, 0.000000,10,14,2018,22,29,57,95,0.00,106,106,6,0,3,106,
242035, 0.000000, 0.000000,10,14,2018,22,29,57,95,0.00,106,106,6,0,3,106,
242531, 0.000000, 0.000000,10,14,2018,22,29,58,95,0.00,109,109,6,0,3,106,
242859, 0.000000, 0.000000,10,14,2018,22,29,58,95,0.00,106,106,6,0,3,106,
243238, 0.000000, 0.000000,10,14,2018,22,29,58,95,0.00,106,106,6,0,3,106,
243687, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
244016, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
244425, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
244892, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
245260, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
245754, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
246083, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
246494, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,109,6,0,3,106,
246947, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,109,109,6,0,3,106,
247320, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
247820, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,109,106,6,0,3,106,
248160, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
248676, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
249027, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
249425, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
249889, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,109,6,0,3,106,
250253,xxxxx,xxxxx,10,14,2018,22,30,6,0,0.00,106,106,6,0,3,106,
250768,xxxxx,xxxxx,10,14,2018,22,30,6,0,0.00,106,106,6,0,3,106,
251097,xxxxx,xxxxx,10,14,2018,22,30,6,0,0.00,106,106,6,0,3,106,
251608,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,109,106,6,0,3,106,
252021,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
252412,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
252883,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,109,106,6,0,3,106,
253248,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
253765,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
254094,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
254608,xxxxx,xxxxx,10,14,2018,22,30,11,0,646.30,106,109,6,0,3,106,
255020,xxxxx,xxxxx,10,14,2018,22,30,11,0,646.30,106,106,6,0,3,106,
255412,xxxxx,xxxxx,10,14,2018,22,30,11,0,646.30,106,106,6,0,3,106,
255882,xxxxx,xxxxx,10,14,2018,22,30,11,0,646.30,106,106,6,0,3,106,

Here is the sketch:

////
//initialising constants
static const  int out_min = 5;
static const  int out_max = 10;
static
const uint8_t RXPin = 0,
              TXPin = 1;
static
const uint16_t GPSBaud = 9600;
static
const uint16_t chipSelect = 4;
//initialising Objects
SoftwareSerial ss(RXPin, TXPin);
TinyGPSPlus gps;

BH1750 active_sensor(0x23); // We will use this adress for stating the active sensor
BH1750 inactive_sensor(0x5C);
SdFat sd;
SdFile file;

//initialising variables for collecting data
float lng_;
float lat_;

String month_ = "";
String day_ = "";
String year_ = "";

uint16_t lux_ = 0;
uint8_t hour_ = 0;
uint8_t min_ = 0;
uint8_t second_ = 0;
uint8_t centisecond_ = 0;
float altitude_ = 0;

unsigned long runtime_ = 0;

uint16_t values[6];
char buf[6];
char data_buffer[12];
char fileName[13] = FILE_BASE_NAME "00.csv";
uint8_t lines = 0;


void setup() {
  digitalWrite(2, HIGH);
  pinMode(2, INPUT);
  Serial.begin(115200);
  Wire.begin();

  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);


  for (int i = out_min; i <= out_max; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }

  ss.begin(GPSBaud); 


  if (active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
   Serial.println(F("BH1750 Advanced begin"));
  } else {
    Serial.println(F("Error initialising BH1750"));
  }
}

void(* resetFunc) (void) = 0;
void loop() {

  while (ss.available() > 0)
    if (gps.encode(ss.read())) {
      digitalWrite(3, HIGH);  
    }
  if (millis() > 5000 && gps.charsProcessed() < 10) {
    while (true);
  }
  if (gps.location.isValid()) {
    lat_ = gps.location.lat();
    lng_ = gps.location.lng();
  }

  if (gps.date.isValid()) {
    day_ = gps.date.day();
    month_ = gps.date.month();
    year_ = gps.date.year();
  }

  if (gps.time.isValid()) {
    hour_ = gps.time.hour();
    min_ = gps.time.minute();
    second_ = gps.time.second();
    centisecond_ = gps.time.centisecond();
    altitude_ = gps.altitude.meters();
  }

  int i;
  for (i = 5; i <= 10; i++) {
    digitalWrite(i, LOW);
    switch (i) {
      case 7:
        active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE);
      case 8:
        active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE);
      case 9:
        active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE_2);
      case 10:
        active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE_2);
      case 5:
        active_sensor.begin(BH1750::CONTINUOUS_LOW_RES_MODE);
      case 6:
        active_sensor.begin(BH1750::CONTINUOUS_LOW_RES_MODE);
    }
    delay(15);
    lux_ = active_sensor.readLightLevel();
    values[i - 5] = lux_;
    digitalWrite(i, HIGH);
  }
  delay(10);
  digitalWrite(3, LOW);
  delay(5);
  file.print(millis());
  file.write(',');
  dtostrf(lng_, 9, 6, data_buffer);
  file.print(data_buffer);
  file.write(',');
  dtostrf(lat_, 9, 6, data_buffer);
  file.print(data_buffer);
  file.write(',');

  file.print(month_);
  file.write(',');
  file.print(day_);
  file.write(',');
  file.print(year_);
  file.write(',');

  file.print(hour_);
  file.write(',');
  file.print(min_);
  file.write(',');
  file.print(second_);
  file.write(',');
  file.print(centisecond_);
  file.write(',');
  file.print(altitude_);
  file.write(',');

  for (int i = 0; i <= 5; i++) {
    file.print(values[i]);
    file.write(',');
  }
  file.println();
  lines++;

  int state = digitalRead(2);

}

Example Output:

1

You can't (and certainly shouldn't ever even try to) use SoftwareSerial on pins 0 and 1. Not when you're using Serial, since they are the same pins.

Pick a different pair of pins for your GPS connection.

  • But Pin 0 and 1 are the only Serial Pins on the arduino nano i use. Could i instead just remove all Serial functions? (Yet i think, i already tried that and it did not help) – Th3Fi3nD Oct 15 '18 at 0:19
  • The whole point of SoftwareSerial is that it doesn't use the serial pins. – Majenko Oct 15 '18 at 0:26
  • I just had to look that up, since i never heard about that before. So i tried and even without using Serial it does not work. Why would all the internet still use the standard RX and TX pins, if they also use the SoftwareSerial library... – Th3Fi3nD Oct 15 '18 at 4:55
  • Just use different pins for SoftwareSerial. The point behind it is, that you can use it, if you need more serial interfaces, than the board already has. Serial is the Hardware serial interface and it's definitely better than SoftwareSerial, which has some serious limitations. You are using it because you don't have a second hardware serial on an Arduino UNO. – chrisl Oct 15 '18 at 7:18
  • @Th3Fi3nD Because once upon a time some idiot without a clue did it, and then another idiot without a clue copied him. And then more idiots without a clue copied those, and since the internet is peopled by idiots without clues it rapidly became the norm. Now whenever anyone looks for example code they get a derivative of that original clueless idiot's code. I wish it were like a vampire - then I could hunt down the original and kill it and all the descendants would revert to good code - but alas it isn't.... – Majenko Oct 15 '18 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.