working with gps and eeprom

hello! This is my first post. I have made a coat that has 2 embroidered sensors, sleeve sensors of conductive fabric and a temp sensor. I am using the eeprom library to write the sensor data while I am out and playback when I am at my computer. I would like to add a gps em-406 to this project. (The gps would only record course and speed when 2 of the sensors are activated). I have used this gps in another project with a lcd and am able to parse the code- but I am not sure about how to use the parsed gps code with the eeprom. If anyone has any suggestions about how to do do this I would be very grateful!

If you are parsing the GPS data, you have integer or float values you have extracted from the string, right?

You know how to write them to EEPROM, right?

What is it you need help with?

Yes- but when you are using a gps with sensor readings and eeprom write and read-do the sensor readings need to be in an array or string, to eeprom write a reading from each sensor e.g.1,2,3,4,+latitude,longitude and then eeprom read this data and get a result in the serial monitor like: 1,2,3,4,latitude, longitude?

i extracted chars from the gps ..

You can store integers and floats in EEPROM, or strings. Your choice. Numbers generally take fewer bytes. But, which to use depends on why you are storing the data in EEPROM, which doesn't have an infinite number of write cycles.

thanks -Well, the sensors are all fabric and when certain sensors are touched with these conductive pom-poms then the other sensor readings are brought into play. The eeprom data from the sensors + gps read at certain times when one or two of the two sensors are touched.At this point all I want to do is get the sets of sensor readings and gps printed together on the serial monitor. Thats it. So would strings be the best choice or does it matter in this case?

Saving in EEPROM is useful when you need to save data when the Arduino is powered down, so that it can be restored when the Arduino is powered up again.

I don't see, in your case, any value in saving GPS data in EEPROM when the Arduino is powered down. Is there something I am missing?

It is important to the game that is part of this project that the sensor readings are linked to a location. So if I write the sensor reading as ints and the gps as chars then this will keep the data correctly?

The Arduino has memory. It can hold in memory the GPS location when a sensor is pressed. Unless there is some need to remember where the sensor was pressed even after the Arduino is turned off, you don't need to write data to EEPROM.

Now, why would the Arduino need to remember where it was when the sensor was pressed, after it has been turned off?

That is what I want to do. :slight_smile:

That is what I want to do.

OK. Fine. Go for it.

I have tried to write the code to read the sensors and combine this with gps. See above posts here is the code I am working on:

#include <EEPROM.h>

#include <WString.h>
#include <NewSoftSerial.h>
                                     // these strings have a maximum length of 64 bytes/chars
String silly1(64);
String silly2(64);
String silly3(64);
String silly4(64);
String silly5(64);
String silly6(64);
String spd(64);
String c(64);
NewSoftSerial GPS = NewSoftSerial(4,3);
#define tempsensor 5                      //temp sensor
#define sleeve1 0                        //silk sleeve 1
#define sleeve2 4                        //silk sleeve 2
#define pocket1 1                        //embroidery on pocket 1  
#define pocket2 3                        //embroidery on pocket 2
#define button  8                        // button (if HIGH-clear EEPROM)
#define LED = 6                             //LED will turn on when EEPROM is clear
#define LED1 =13                                         // led will blink when EEPROM is recording and stay on when EEPROM is full
int index = 0;  
int val1 =0;                            //variables for each sensor v
int val2 =0;
int val3 =0;
int val4 =0;
int val5 =0;

int  sensval[] = {0,1,2,3,4};
byte val = 0;
int state = 0;
int laststate = 0;


void setup(){              
  GPS.begin(4800);
  Serial.begin(4800);
  Serial.begin(9600);
  pinMode(6, OUTPUT);
  pinMode(13,OUTPUT);
  pinMode(8,INPUT);
}
  
  
  
  
  void waitForGPRMC(void) {                          //this section of code gathers and parses the gps string
  String s(1024);                                   // this (temporary) string has a maximum length of 1024 chars (half the Arduino's memory...)
  s.clear();
  while(! s.contains("$GPRMC,")) {
    if(GPS.available()) {
      char c = GPS.read();                         // it's important that the Serial values be stored as chars, because of the way append works...
      s.append(c);
    }
  }
}


                                                  // this function collects characters from the (hardware) serial port until a , is received
void collect(String& s) { 
  char c = 0;                                     // it's important that the Serial values be stored as chars, because of the way append works...
  s.clear();
  while ( c != ',' ) {
   if(GPS.available()) {
      c = GPS.read();
      if( c != ',') s.append(c); 
    }
  }
}







void readSensors(void) {
  
 val1 = analogRead(5);
 val2 = analogRead(0)/4;
 val3 = analogRead(4)/4;
 val4 = analogRead(1)/4;
 val5 = analogRead(3)/4;
  
}

void writetoEEPROM(void) {
 if(index < 507 ){ 
   readSensors();
  
EEPROM.write(index,val1); 
EEPROM.write(index +1 ,val2);
EEPROM.write(index +2,val3);
EEPROM.write(index +3,val4);
EEPROM.write(index +4,val5);
  
} 

 
                                    // or this could be wrtten for(int x=0;x<5;x++)EEPROM.write(index+x,sensval[5]);
 
char* a = c1.getChars();
for(int x=0;x<4;x++){EEPROM.write(index+x,a[index]);
}
char* b = c1.getChars();
for(int x=0;x<4;x++){EEPROM.write(index+x,b[index]);
}  
 
index = index + 13;
}


void walkmode(void) {            //this function determines what happens when the data is being recorded out in the field
                                  //the EEPROM should record all sensor readings from temp and sleeves etc. + gps if the embroidered potentiometers are touched with the pom-pomreadSensors();

 if (analogRead(1)>500) {          //|| (analogRead(4)>300) {
 (digitalWrite(6, HIGH));
   delay(100);
  (digitalWrite(6,LOW));
    writetoEEPROM();                      
   }
 }

 void homemode(void) {

val1 = EEPROM.read(index);
Serial.print("\t");
Serial.print(val1, DEC);
Serial.print(" ");
index = index + 1;

val2 = EEPROM.read(index);
Serial.print("\t");
Serial.print(val2,DEC);
Serial.print(" "); 
index = index + 2;

val3 = EEPROM.read(index); 
Serial.print("\t");
Serial.print(val3,DEC);
Serial.print(" "); 
index = index + 3;

val4 = EEPROM.read(index);
Serial.print("\t");
Serial.print(val4,DEC);
Serial.print(" ");
index = index + 4;

val5 = EEPROM.read(index);
Serial.print("\t");
Serial.print(val5,DEC);
Serial.print("/ ");
index = index+ 5;
delay(500);


 Serial.print('/');
 delay(200);
 
 index=index+13;
  
if (index == 507){
digitalWrite(6, HIGH);                       //if the EEPROM is full then turn led 6 on.

}
 }

void clearEEPROM(void) {
 for (int i = 0; i < 507; i++)
    EEPROM.write(i, 0);
}

int buttonLong(void){
int x = 0;
while(digitalRead(8)) {          
x++;                              
delay(50);
}
if (x>200) return true ;        
else return false;
}
 
void determineState (void) {
  
if (digitalRead(8)==HIGH) {
   if(buttonLong()==true)
   state=2;
   
}
else {
  
  if (state==0)state=1;
//  else if (state==1)state=0;
  
}     
}

void expressState(void) {
  
  if (state==0) {
    walkmode();
    
}  if (state==1); {
   homemode();
}  if (state==2) {
   digitalWrite(13,HIGH);
   clearEEPROM();                  //if the state is 2 then clear eeprom, turn led on and if index is cleared then statis 0.
   state = 0;
   delay(5000);
   digitalWrite(13,LOW);
    } 
  }

void loop () {
  determineState();
  expressState();
  
}

If you go back to your last post, highlight all the code and then click the "#" button on the editor's toolbar, you'll make a lot of people a little happier / a lot less angry.

(Also, "ctrl-T" is a useful key combination in the IDE)

Think about what this code is doing:

void waitForGPRMC(void)
{                          //this section of code gathers and parses the gps string
  String s(1024);     // this (temporary) string has a maximum length of 1024 chars (half the Arduino's memory...)
  s.clear();
  while(! s.contains("$GPRMC,")) {
    if(GPS.available()) {
      char c = GPS.read();   // it's important that the Serial values be stored as chars, because of the way append works...
      s.append(c);
    }
  }
}

You create a local variable, s, to collect the GPS data in. That variable goes out of scope at the end of the function. What was the reason for collecting the data in the string?

So, then you have the collect() function that does exactly the same thing, except that it stores the data in the string that was passed in. Why are there two functions?

Why are there 2 readSensors() functions?

In the writetoEEPROM function, where is c1 declared? Valued? Why is the first character in c1 written to EEPROM four times, twice?

I made a copy/paste error and printed readSensors twice.
Should I just use the function collect Strings?
It is necessary to write the null strings(silly strings#) as well as the ones I want spd. and c1. I am not sure how to do this obviously.
Thanks for your comments. I have a lot to learn.

Is there some reason you are not using the TinyGPS library to parse the GPS data for you? If you used this library, you could store whatever numeric values interested you (latitude, longitude, heading, whatever) in EEPROM. There is a library that simplifies writing integers and floats to EEPROM, too.

Do you mean the EXROM library? You suggest using that in conjunction with the Tiny GPS?