Probleme en utilsant 2 ports rx/tx (pin 0 et 1, pin 2 et 3)

Bonjour,
Je ne suis pas loin d'arrivé à mon but même s'il y a encore beaucoup à faire.

J'ai arduino shield
un shield GPRS et un GPS.

J'ai eu beaucoup de mal a recevoir les position du GPS, jusqu'a en utilisant les pin 0 et 1
et les pin 2 et 3 pour le GPRS.

En gros j'ai fait comme ceci

#include <SoftwareSerial.h>
#include <TinyGPS.h>
#define TERMBAUD 9600
// ********* GPRS **************
#define GPRSBAUD 9600
#define GPRSRX 2
#define GPRSTX 3
SoftwareSerial cell(GPRSRX,GPRSTX);

// ************* GPS ****************** 
#define GPSBAUD 4800 // Don change it, the gps works only at 4800
#define GPSRX 0
#define GPSTX 1
SoftwareSerial uart_gps(GPSRX, GPSTX); //Create a fake serial port 0 and 1

J'ai constaté quand je démare cell et uart_gps dans le setup(), comme ceci:

  //Initialize serial ports for communication with computer
  Serial.begin(TERMBAUD);
  uart_gps.begin(GPSBAUD);
  cell.begin(GPRSBAUD);
  
  Serial.println(F(" "));
  Serial.println(F("*************************************"));
  Serial.println(F("* Starting iBip Communication... *"));
  Serial.println(F("*************************************"));
  Serial.println(F(" "));

  
}

void loop(){
 
  if(firstTimeInLoop) {
    
    firstTimeInLoop = 0;
    
    #ifdef GPRS_ACTIVE
    
      #ifdef DEBUG
      Serial.println(F("Wait for module is registered (+SIND: 11) and  ready (+SIND: 4) ..."));
      #endif

    
      while (GPRS_registered == 0 || GPRS_AT_ready == 0) {
        
        String ready = getMessage();
        
         
         if(ready == "+SIND: 1"){
           Serial.println(F("> SIM is inserted ..."));
         }
         
         if(ready == "+SIND: 10,\"SM\",1,\"FD\",1,\"LD\",1,\"MC\",1,\"RC\",1,\"ME\",1"){
           Serial.println(F("> SIM is ready ..."));
         }
         
         if(ready == "+SIND: 11"){
           GPRS_registered = 1;
           Serial.println(F("> Module is registered to network ..."));
         }
         
         if(ready == "+SIND: 3"){
           Serial.println(F("> GPRS is partially ready ..."));
         }
         
         if(ready == "+SIND: 4"){
           GPRS_AT_ready = 1;
           Serial.println(F("> GPRS is ready ..."));
         }
         
         if(ready == "+SIND: 7"){
           Serial.println(F("> Emergency only ..."));
         }
         
         if(ready == "+SIND: 0"){
           Serial.println(F("> SIM card removed"));
         }
         
         
      }
    #endif
    
    Serial.println(F(" "));
    Serial.println(F("READY TO GO"));
    Serial.println(F("***********"));
    Serial.println(F("1. Collecting GPS coords"));
    Serial.println(F("2. Sending the coords via GPRS"));
    Serial.println(F("3. Record the coords to a logger (Later)"));

 }  
 [... suite du code ...]

Mon terminal arrête d'afficher les messages après

#ifdef DEBUG
Serial.println(F("Wait for module is registered (+SIND: 11) and ready (+SIND: 4) ..."));
#endif

En fait j'ai comme l'impression que

 cell.begin(GPRSBAUD);

est "en panne", "coucicuiter". Comme s'il y avait un conflit.

Dans mon setup(), j'ai inversé les begin comme ceci

void setup()
{
  //Initialize serial ports for communication with computer
  Serial.begin(TERMBAUD);
cell.begin(GPRSBAUD);  
uart_gps.begin(GPSBAUD);

[... suite du code ...]

et là, il affiche les +SIND: 1, +SIND: 10 etc, mais il bloque au niveau du GPS.

J'ai aussi commenter ceci

void setup()
{
  //Initialize serial ports for communication with computer
  Serial.begin(TERMBAUD);
//uart_gps.begin(GPSBAUD);
cell.begin(GPRSBAUD);  
[...suite du code...]
}

pour le mettre au niveau de ma fonction qui exécute la fonctionnalité du GPS comme ceci

// START CHECK GPS
void checkGPS(void)
{

[b]  uart_gps.begin(GPSBAUD);[/b]

  
  #ifdef DEBUG
    Serial.println("");
    Serial.println(F("GPS gathering data... (processGps)"));
  #endif

  // Parse GPS data for 2 second
  for (unsigned long start = millis(); millis() - start < 2000;){
    
    while (uart_gps.available())
    {
      char c = uart_gps.read();
      // New valid NMEA data available
      if (gps.encode(c)) 
      {
        newGpsData = true;
      }
    
    }
  }  
  
 [b] uart_gps.end();[/b]

  
    #ifdef DEBUG
    if (newGpsData)
    {
      Serial.println(F("New GPS data available."));
    }
    else
    {
      Serial.println(F("No GPS fix available.")); 
    }
    #endif

}
// END CHECK GPS

et là, encore une fois, il bloque a ce niveau.

Donc j'en déduit que j'ai mal procédé, en ce qui concerne l'utilisation de 2 ports.

Pourriez-vous m'éclairecir à ce sujet??

Milles mercis à tous

Une petite idée?
Dites moi si vous avez besoin de plus de précision.

Mais les pin0 et 1 c'est l'UART matérielle (supportée par Serial) utiliser ces broches pour faire une UART logiciel cela n'a aucun sens.

Ok, mais alors comment puis-je faire?
Dois.-utiliser les port 4 et 5?

Mais lors je ne copmprends pas un truc.

Comment puis utiliser l'UART material?
Pourquoi alors faisons nous

Serialsoftware cell(2,3)

si on a deja les port materiel 0 et 1

Dasns quel cas alors utilisons nous les port 0 et 1?

Je suis un peu confu, aussi parce que je suis un beginer? :~

Déjà ça laisse les pin 0-1 libre pour charger le programme ..... et ensuite tu peux avoir besoins de plusieurs périf "série"

Bonjour,

Serial -> port série hardware, broches D0 / D1

Ton code est dangereux dans son état actuel, utiliser D0/D1 en port série software n'as certes pas de sens, mais en plus tu risques de bloquer ta carte !

Une solution simple : changer de broches :

#define GPRSRX 2
#define GPRSTX 3

#define GPSRX 4
#define GPSTX 5

Bonjour,

ok alors je reste confu.
J'ai essayé ceci

#define GPRSRX 2
#define GPRSTX 3

#define GPSRX 4
#define GPSTX 5

et ca ne marche pas.

Aussi j'ai essayé ce code basic que j'utilise pour tester mon GPS.

/*
  6-8-10
  Aaron Weiss
  SparkFun Electronics
  
  Example GPS Parser based off of arduiniana.org TinyGPS examples.
  
  Parses NMEA sentences from an EM406 running at 4800bps into readable 
  values for latitude, longitude, elevation, date, time, course, and 
  speed. 
  
  For the SparkFun GPS Shield. Make sure the switch is set to DLINE.
  
  Once you get your longitude and latitude you can paste your 
  coordinates from the terminal window into Google Maps. Here is the 
  link for SparkFun's location.  
  http://maps.google.com/maps?q=40.06477,+-105.20997
  
  Uses the NewSoftSerial library for serial communication with your GPS, 
  so connect your GPS TX and RX pin to any digital pin on the Arduino, 
  just be sure to define which pins you are using on the Arduino to 
  communicate with the GPS module. 
  
  REVISIONS:
  1-17-11 
    changed values to RXPIN = 2 and TXPIN = to correspond with
    hardware v14+. Hardware v13 used RXPIN = 3 and TXPIN = 2.
  
*/ 

// In order for this sketch to work, you will need to download 
// TinyGPS library from arduiniana.org and put them 
// into the hardware->libraries folder in your ardiuno directory.
#include <SoftwareSerial.h>
#include <TinyGPS.h>

// Define which pins you will use on the Arduino to communicate with your 
// GPS. In this case, the GPS module's TX pin will connect to the 
// Arduino's RXPIN which is pin 3.
#define RXPIN 2
#define TXPIN 3
//Set this value equal to the baud rate of your GPS
#define GPSBAUD 4800

// Create an instance of the TinyGPS object
TinyGPS gps;
// Initialize the NewSoftSerial library to the pins you defined above
SoftwareSerial uart_gps(RXPIN, TXPIN);

// This is where you declare prototypes for the functions that will be 
// using the TinyGPS library.
void getgps(TinyGPS &gps);

// In the setup function, you need to initialize two serial ports; the 
// standard hardware serial port (Serial()) to communicate with your 
// terminal program an another serial port (NewSoftSerial()) for your 
// GPS.
void setup()
{
  // This is the serial rate for your terminal program. It must be this 
  // fast because we need to print everything before a new sentence 
  // comes in. If you slow it down, the messages might not be valid and 
  // you will likely get checksum errors.
  Serial.begin(9600);
  //Sets baud rate of your GPS
  uart_gps.begin(GPSBAUD);
  
  Serial.println("");
  Serial.println("GPS Shield QuickStart Example Sketch v12");
  Serial.println("       ...waiting for lock...           ");
  Serial.println("");
}

// This is the main loop of the code. All it does is check for data on 
// the RX pin of the ardiuno, makes sure the data is valid NMEA sentences, 
// then jumps to the getgps() function.
void loop()
{
  while(uart_gps.available())     // While there is data on the RX pin...
  {
      int c = uart_gps.read();    // load the data into a variable...

      if(gps.encode(c))      // if there is a new valid sentence...
      {
        getgps(gps);         // then grab the data.
      }
  }
}

// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
  // To get all of the data into varialbes that you can use in your code, 
  // all you need to do is define variables and query the object for the 
  // data. To see the complete list of functions see keywords.txt file in 
  // the TinyGPS and NewSoftSerial libs.
  
  // Define the variables that will be used
  float latitude, longitude;
  // Then call this function
  gps.f_get_position(&latitude, &longitude);
  // You can now print variables latitude and longitude
  Serial.print("Lat/Long: "); 
  Serial.print(latitude,5); 
  Serial.print(", "); 
  Serial.println(longitude,5);
  
  // Same goes for date and time
  int year;
  byte month, day, hour, minute, second, hundredths;
  gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
  // Print data and time
  Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/"); 
  Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
  Serial.print("  Time: "); Serial.print(hour, DEC); Serial.print(":"); 
  Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC); 
  Serial.print("."); Serial.println(hundredths, DEC);
  //Since month, day, hour, minute, second, and hundr
  
  // Here you can print the altitude and course values directly since 
  // there is only one value for the function
  Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());  
  // Same goes for course
  Serial.print("Course (degrees): "); Serial.println(gps.f_course()); 
  // And same goes for speed
  Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());
  Serial.println();
  
  // Here you can print statistics on the sentences.
  unsigned long chars;
  unsigned short sentences, failed_checksum;
  gps.stats(&chars, &sentences, &failed_checksum);
  //Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
  //Serial.println(); Serial.println();
}

Ca marche quand

#define RXPIN 0
#define TXPIN 1

mais quand elles sont a 3,4 ou 7,8, etc.

Ce qui me surpant c'est que ca marche après env20h (suisse) mais le len demain matin il ne détecte plus rien!!!!!!!!!!! Vu qu ela terre tourne, est que la journée il ne détecte pas les satelittes "qu'il veut bien reconnaitre"??

Il faur aussi savoir que j'utilise ce GPS

qui est fixé sur cette shield

Je dois donc pousser le boutton de DLINE pour uploader mon code et pousser le bonton sur UART pour exécuter mon code.

L'autre point qui me surprend
J'ai débranchà ma shield GPRS https://www.sparkfun.com/products/9607 pour n'avoir que mon GPS (avec la carte) sur mon Arduino Uno.
Là, quand je configure mes pins sur

#define RXPIN 4
#define TXPIN 5

ca marche quand je laisse mon bouton poussoir sur DLINE mais ca ne marche plus quand je remets mon bouton poussoir sur UART.
Si je modifie mes PIN come ceci

#define RXPIN 0
#define TXPIN 1

Ca marche quand je laisse mon bouton poussoir sur UART, et ca ne marche plus qaud il est sur DLINE
:~ :slight_smile: :drooling_face:.

Et évidement, quand je remets ma shield GPRS, elle ne fonction que quand mon bouton poussoir est sur UART.

Donc j'ai boucoup de mal a comprendre et à savoir comment faire marché, et choisir les bon ports

[code]#define RXPIN 0
#define TXPIN 1

pour que mon GPS fonctionne en UART.

L'autre chose que je vais essayer ces prochain jour, c'est de supprimer la shield du GPS pour connecter le GPS sur l'arduino.....
En suivant cet exemple : BasicPositioning \ Learning \ Wiring

Bref, pourriez-vous m'aider à ce sujet???, je ne suis plus loind de mon but, et je rame, car c'est mon premier projet avec Arduino.

Toute bonne journée à vous tous
Pierrot
[/code]

skywodd:
Serial -> port série hardware, broches D0 / D1

Ton code est dangereux dans son état actuel, utiliser D0/D1 en port série software n'as certes pas de sens, mais en plus tu risques de bloquer ta carte !

B@tto:

skywodd:
Ton code est dangereux dans son état actuel, utiliser D0/D1 en port série software n'as certes pas de sens, mais en plus tu risques de bloquer ta carte !

On peut pas faire plus voyant ... arrête de faire du SoftwareSerial sur D0/D1 !
Ou au moins utilise directement Serial !

L'interrupteur UART/DLINE de la shield GPS permet de choisir si le gps doit être connecter sur le port série hardware ou sur D2/D3 :

Hello,
Ok, mais ca ne m'avance pas...
Ok mon gps je le fais fonctionné sur le pin 4 et 5

Serialsoftware gps(4,5); Mais la je ne recois aucun signal alors que je dois mettre mon bouton poussoir sur UART car ma carte GPRS ne fonctione pas sur le DLINE.

D'ailleur, meme si je ne mets que mon shiled GPS (avec le GPS) sur mon Arduino Uno, et que je choisi les ports 4 et 5, ca ne marche par sur UART, mais ca marche sur DLINE. J'aimerais bien que ca marche sur UART.....

Avec l'interrupteur sur DLINE le port série du GPS est sur D2/D3.
Tu as deux jumper marqués D2 et D3 sur la shield, sont ils bien fermés ?

Frerait, tu veux dire fermés??

Heu, je n'en vois pas

Mais paralellement, j'ai trouvà une solution que j'esaye.

J'ai supprimé

void setup()
{
  //Initialize serial ports for communication with computer
  Serial.begin(4800);
  //uart_gps.begin(GPSBAUD); SUPPRIME!
  cell.begin(9600);
  
  

  #ifdef DEBUG
    Serial.println(F(" "));
    Serial.println(F("*************************************"));
    Serial.println(F("* Starting iBip Communication... *"));
    Serial.println(F("*************************************"));
    Serial.println(F(" "));
  #endif
/*
  Serial.println(F("Wait for module registered"));
  waitTil("+SIND: 11"); // keep printing cell output til we get "+SIND: 11"
  Serial.println(F("Module Registered"));
  */
  
}

Puis, l'écoute d emon GPS je le fais aisni:
(j'ai vu ca dans un code que j'avais trouvé)

// START CHECK GPS
void checkGPS(void)
{

 // uart_gps.begin(GPSBAUD);

  
  #ifdef DEBUG
    Serial.println("");
    Serial.println(F("GPS gathering data... (processGps)"));
  #endif

  // Parse GPS data for 2 second
  for (unsigned long start = millis(); millis() - start < 2000;){
    
    //while (uart_gps.available()) SUPPRIME ET REMPLACE PAR
    while(Serial.available())
    {
      char c = Serial.read();
      //char c = uart_gps.read(); SUPPRIME ET REPLACE PAR
      // New valid NMEA data available
      if (gps.encode(c)) 
      {
        newGpsData = true;
      }
    
    }
  }  
}

Alors ca va bien, mais quand il appelle la fonction void sendGPRS(), il crash et reboot. J'ai constaté que ca devait etre un problème de mémoire.

Chais pas si je me dirige vers la bonne voie, mais ca semble bien mieux fonctionner sauf que ca .... crash :o)

J'ai ouvert un autre post à ce sujet,