gps + temperatur

hi,

im have setup 2 alone codes working one for gps another for the temperature, now im trying to put them together, but im failing to add the temperature loop. the code only run one time, and i need him to keep running getting gps info + temperature

void loop()
{
  bool newdata = false;
  unsigned long start = millis();
    while (millis() - start < 500)
  {
    if (feedgps())
      newdata = true;
  }
          gpsdump(gps);

// temperature sensor
float temperature = getTemp();
 int reading = analogRead(sensorPin);  
 float voltage = reading * 5.0;
  voltage /= 1024.0; 
  float temperatureC = (voltage - 0.5) * 100 ;
 Serial.print(temperatureC); Serial.print("degreesC");Serial.print(" | ");Serial.print(temperature); Serial.println(" Waterproof ");
// temperature end
}

i cant find the error, and i'm not a pro coder.
The full code used his here

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

File myFile;


TinyGPS gps;
SoftwareSerial nss(2, 3);            
int DS18S20_Pin = 10;
int sensorPin = 0;
OneWire ds(DS18S20_Pin); 

void setup()
{
  Serial.begin(115200);
  nss.begin(115200);
  Serial.println("Reading GPS");
// Initialize SD card
 Serial.print("Initializing SD card...");
   pinMode(8, OUTPUT);
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

}

void loop()
{
  bool newdata = false;
  unsigned long start = millis();
    while (millis() - start < 500)
  {
    if (feedgps())
      newdata = true;

  }
          gpsdump(gps);

 float temperature = getTemp();
 int reading = analogRead(sensorPin);  
 float voltage = reading * 5.0;
  voltage /= 1024.0; 
  float temperatureC = (voltage - 0.5) * 100 ;
 Serial.print(temperatureC); Serial.print(" degrees C - Pequeno");Serial.print(" ||||||| ");Serial.print(temperature); Serial.println(" degrees C - Waterproof");
}

// Get and process GPS data
void gpsdump(TinyGPS &gps) {
  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  Serial.print(flat, 4); 
  Serial.print(", "); 
  Serial.print(flon, 4);

  /// And write it to SD card
       myFile = SD.open("tracking.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to tracking.txt...");
    myFile.print(flat, 4);
    myFile.print(", ");
    myFile.println(flon, 4);
  
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening tracking.txt");
  }
    ///  
  
}

// Feed data as it becomes available 
bool feedgps() 
{  while (nss.available()) 
  {
    if (gps.encode(nss.read()))
      return true;  
  }
  return false;
}

float getTemp(){
 byte data[12];
 byte addr[8];
 if ( !ds.search(addr)) {
   ds.reset_search();
   return -1000; }
 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -1001; }
 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -1002;}
 ds.reset();
 ds.select(addr);
 ds.write(0x44,1); 
 byte present = ds.reset();
 ds.select(addr);  
 ds.write(0xBE); 
 for (int i = 0; i < 9; i++) { // we need 9 bytes
  data[i] = ds.read(); }
 ds.reset_search();
 byte MSB = data[1];
 byte LSB = data[0];
 float tempRead = ((MSB << 8) | LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;
 return TemperatureSum;
}

thanks for the help

jGaf

  while (millis() - start < 500)

This test will always be true because start has been set equal to millis() on the previous line. What is it supposed to do ?

  int reading = analogRead(sensorPin);

Can you read an analog value from pin zero ? What Arduino are you using ?

hi, thanks for the reply

  while (millis() - start < 500)

is the repeat of, as a delay

  int reading = analogRead(sensorPin);

i have one of the temperature sensor on 0 and the second on 10

the temperature work alone, the gps work alone, the 2 together fail!

thanks

unsigned long start = millis();  //set start to the elapsed time in milliseconds
while (millis() - start < 500)    //a few microseconds later (at the most) test whether 500 milliseconds have passed

Your code does this every time that loop() executes so the test will be true every time. I assume what you are trying to do is to create a delay of 500 millseconds but to do this you must not keep initialising start on every pass through loop(), only after the delay has occurred so that it starts again, and you need to test whether millis() - start is greater than 500, not less than 500.

Apologies for the question about analogRead on pin zero. I was thinking about pin zero rather than analogue pin zero (A0)