Sketch incompatibility between Duemilanove and Pro Mini

Hi all.

I have written a sketch which is running correctly on the Duemilanove. But when try to use it on an Arduino Pro Mini 328 (3.3V, 8Mhz), the sketch give me wrong data. I choose the correct board in arduino-22 for the two board.

So my question : Is there a difference between the two boards ? Have I to modify my sketch to be used on the Pro Mini ?

More information : I use a SKM53 GPS receiver which give me the time, date and speed through the TinyGPS library. The data are incorrect when I use the Pro Mini and I don't understand why...

The data are incorrect when I use the Pro Mini and I don't understand why...

Without seeing any code, neither do we.

Sorry...

/*  CONNEXIONS :
  GPS 
    RX : 3
    TX : 2
  
  SD CARD
    MOSI : 11
    MISO : 12
    CLK  : 13
    CS   : 10
    
  Red Led : 5
  Green Led : 6
*/


#include <NewSoftSerial.h>
#include <TinyGPS.h>
#include <SD.h>

#define Rled 5
#define Gled 6
#define LEDON 125
#define LEDOFF 0

#define SDChipSelect 10

TinyGPS gps;
NewSoftSerial nss(2, 3);

boolean actualiseGPS();

unsigned long LogLastUpdate = 0;
unsigned long DELAI_LOGGER = 5000;
boolean Track = true;

void setup(){
 
  byte month, day, hour, minute, second, hundredths;
  int year;
  unsigned long age;
  
  boolean output = HIGH;
  
  Serial.begin(9600);
  
  pinMode(Rled,OUTPUT);
  pinMode(Gled,OUTPUT);
  pinMode(SDChipSelect, OUTPUT); //SS obligatoire sur le pin 10
  
  analogWrite(Rled, LEDON); 
  analogWrite(Gled, LEDOFF); 
  
  //initialisation de la carte SD
  if(!SD.begin(SDChipSelect)){
    while(1){
      analogWrite(Rled, LEDON);
      delay(250);
      analogWrite(Rled, LEDOFF);
      delay(250);
    }
  }
  
  //on vérifie que l'entête du fichier correspond à ce que l'on veut
  File dataFile = SD.open("data.txt");
  if (dataFile){
    if (dataFile.size() < 66 ){
      dataFile.close();
      SD.remove("data.txt");
      File dataFile = SD.open("data.txt", FILE_WRITE);
      dataFile.println("type,new_track,time,latitude,longitude,alt,speed,name");
      dataFile.close();
    }
  }
  
  //initialisation du GPS
  nss.begin(9600);
  Serial.print("Attente GPS...");
  while(!actualiseGPS()){
    if(output) analogWrite(Gled, LEDON);
    else analogWrite(Gled, LEDOFF);
    output = !output;
    delay(100);    
  }
  Serial.println("OK");
  
}

void loop(){
  
  float vitesse;
  
  //on allume la led verte
  analogWrite(Rled, LEDOFF);
  analogWrite(Gled, LEDON); 
  
  //on actualise le GPS
  while(!actualiseGPS()){      //tant qu'on a pas de données
    analogWrite(Rled, LEDON);  //on laisse la led rouge allumée
  }
  analogWrite(Rled, LEDOFF);   //on éteint la led rouge en sortant
  
  vitesse = gps.f_speed_kmph(); //on lit la vitesse
  
  Serial.print("Vitesse actuelle : ");
  Serial.println(vitesse);
  
  if (vitesse < 2 || vitesse > 500){      
    DELAI_LOGGER = 300000; // toutes les 5 minutes
  }else if(vitesse > 75){ // > 80km/h
    DELAI_LOGGER = 1000; // toutes les secondes
  }else if(vitesse > 45){ // > 45km/h
    DELAI_LOGGER = 2000; // toutes les 2 secondes
  }else if(vitesse > 25){ // > 25km/h
    DELAI_LOGGER = 3000;  // toutes les 3 secondes
  }else{
    DELAI_LOGGER = 5000; // toutes les 5 secondes
  }
  
  //forçage pour test de DELAI_LOGGER
  //DELAI_LOGGER = 2000;
  
  if((millis() - LogLastUpdate) > DELAI_LOGGER){
    GPS2SD(gps);
    LogLastUpdate = millis();
  }
  
}


void GPS2SD(TinyGPS &gps){
  
  // type,new_track,time,latitude,longitude,alt,speed,course,name
  
  float flat, flon, falt, fspeed;
  byte month, day, hour, minute, second, hundredths;
  int year;
  unsigned long age;
  
  File dataFile = SD.open("data.txt", FILE_WRITE); //on ouvre le fichier  
  if (dataFile){
    
    gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
    gps.f_get_position(&flat, &flon, &age);
    falt = gps.f_altitude();
    fspeed = gps.f_speed_kmph();
    
    dataFile.print('T');
    
    dataFile.print(',');
  
    if(Track){ 
      dataFile.print('1');
      Track = false;
    }else dataFile.print('0');
    
    
    dataFile.print(',');
    
    if(static_cast<int>(hour + 2) < 10) dataFile.print('0');
    
    dataFile.print(static_cast<int>(hour + 2));
    dataFile.print(':');
    if(static_cast<int>(minute) < 10) dataFile.print('0');
    dataFile.print(static_cast<int>(minute));
    dataFile.print(':');
    if(static_cast<int>(second) < 10) dataFile.print('0');
    dataFile.print(static_cast<int>(second));
  
    dataFile.print(',');
  
    printFloatSD(flat,5,dataFile);
    
    dataFile.print(',');
  
    printFloatSD(flon,5,dataFile);
  
    dataFile.print(',');
  
    printFloatSD(falt,0,dataFile);
    
    dataFile.print(',');
  
    printFloatSD(fspeed,0,dataFile);
    
    dataFile.print(',');
    
    if(static_cast<int>(day) < 10) dataFile.print('0');
    dataFile.print(static_cast<int>(day));
    dataFile.print('/');
    if(static_cast<int>(month) < 10) dataFile.print('0');
    dataFile.print(static_cast<int>(month));
    dataFile.print('/');
    dataFile.print(year);
    
    dataFile.println();
    
    dataFile.close();
  }
}


void printFloatSD(double number, int digits, File &dataFile)
{
  // Handle negative numbers
  if (number < 0.0)
  {
     dataFile.print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;
  
  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  dataFile.print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    dataFile.print("."); 

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    dataFile.print(toPrint);
    remainder -= toPrint; 
  } 
}


void printFloatSerial(double number, int digits)
{
  // Handle negative numbers
  if (number < 0.0)
  {
     Serial.print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;
  
  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  Serial.print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    Serial.print("."); 

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    Serial.print(toPrint);
    remainder -= toPrint; 
  } 
}

boolean actualiseGPS(){
  while (nss.available()){
    if (gps.encode(nss.read())) return true;
  }
  return false;
}

You might have to double the declared speeds so the serial interfaces run at the correct speeds on the 8 MHz part.
I have a couple I had to do that with.

I extract latitude, longitude, altitude, time, date & speed, but only the date and speed are incorrect. Are you sure it is only a question of speeds ? For me, the communication between the ProMini and the GPS receiver is correct. Futhermore, TinyGPS returns only good sentences...

You might have to double the declared speeds so the serial interfaces run at the correct speeds on the 8 MHz part.
I have a couple I had to do that with.

I just try it but it doesn't work, TinyGPS said it was only wrong sentenses...

I don't understand what is happening to my ProMini ?????? :0

I don't understand what is happening to my ProMini

Perhaps you could show us the output from the Duemilanove and from the ProMini. Might trigger some ideas. I don't see anything obvious.

    DELAI_LOGGER = 300000; // toutes les 5 minutes

In the absence of directives to the contrary, literals are treated as ints. 300000 is NOT a valid int value. Add UL to the end of the value to tell the compiler to treat the value as an unsigned long, instead.

CrossRoads, I apologize because you were completly right. By default, my GPS receiver is set to 9600 baud. First, I tryed to set up NewSeriaSoft to 19600 baud without result (keeping gps data rate to 9600). But decreasing the GPS data rate to 4800 with NewSerialSoft to 4800 give to the Arduino Pro Mini full satisfaction.

Thanks a lot !. :smiley:

My project is now completed, so I can use my GPS-Tracker. :wink:

Ok, glad you got it working.
My explanation wasn't quite the right thing - I was thinking you would need 9600 on promini to interface to 4800 on the GPS, but as long as you started looking in the right areas I guess my advice wasn't too too bad ... :grin: