Ligne 37 : |
Ligne 37 : |
| |} | | |} |
| | | |
− | == Code Source == | + | == Code Source - Arduino < 1.0 == |
| | | |
− | <nowiki> | + | Vous pouvez le télécharger en cliquant sur [http://mchobby.be/data-files/gprsshield/SerialRelay2.pde SerialRelay2.pde]. |
− | // Serial Relay v2.0 | + | |
| + | Le code est commenté en anglais et en français. |
| + | |
| + | <nowiki>// Serial Relay v2.0 |
| // EN: | | // EN: |
| // Arduino will patch serial link between the computer and | | // Arduino will patch serial link between the computer and |
Ligne 129 : |
Ligne 132 : |
| | | |
| Serial.print((unsigned char)mySerial.read()); | | Serial.print((unsigned char)mySerial.read()); |
| + | } |
| + | |
| + | } |
| + | </nowiki> |
| + | |
| + | == Code Source - Arduino >= 1.0 == |
| + | |
| + | Vous pouvez le télécharger en cliquant sur [http://mchobby.be/data-files/gprsshield/SerialRelay2_Ard10.ino SerialRelay2_Ard10.ino]. |
| + | |
| + | Le code est commenté en anglais et en français. |
| + | |
| + | <nowiki>// Serial Relay v2.0 - Arduino >= 1.0 |
| + | // EN: |
| + | // *** PATCHED VERSION for Arduino 1.0 *** |
| + | // Arduino will patch serial link between the computer and |
| + | // the GPRS Shield at 19200 bps 8-N-1 |
| + | // Computer is connected to Hardware UART |
| + | // GPRS Shield is connected to the Software UART |
| + | // |
| + | // This version allows to send escape sequence to GPRS Shield (for SMS messaging) |
| + | // use <tilde>z for Ctrl-z |
| + | // use <tilde>e for ESC |
| + | // use <tilde><tilde> for <tilde> |
| + | // |
| + | // Require the Arduino serial monitor to be configured on |
| + | // 19200 bds + Carriage Return |
| + | // |
| + | // FR: |
| + | // *** VERSION CORRIGEE POUR Arduino 1.0 *** |
| + | // Arduino va établir une liaison série entre l'ordinateur et |
| + | // le shield GPRS a 19200 bauds 8-N-1 |
| + | // L'ordinateur est connecté à un UART matériel |
| + | // Le shield GPRS est connecté a un UART logiciel. |
| + | // |
| + | // Cette version permet d'envoyer des séquences d'échappement au |
| + | // shield GPRS (pour envoyer une fin de message pour les SMS) |
| + | // utiliser <tilde>z pour Ctrl-z |
| + | // utiliser <tilde>e pour ESC |
| + | // utiliser <tilde><tilde> pour un tilde |
| + | // |
| + | // Le moniteur série d'Arduino doit etre configuré sur |
| + | // 19200 bds + Carriage Return |
| + | // |
| + | // Licence: CC-BY-SA |
| + | // Meurisse D. |
| + | // http://www.mchobby.be |
| + | // |
| + | #include <SoftwareSerial.h> |
| + | |
| + | SoftwareSerial mySerial(7, 8); |
| + | |
| + | // EN: 1 means than escape caracter (tilde) has been detected from Serial Monitor (Arduino Side) |
| + | // FR: 1 indique que le caractere d'echappement est détecté sur le moniteur serie (coté Arduino) |
| + | int escapingFlag = 0; |
| + | |
| + | void setup() |
| + | { |
| + | mySerial.begin(19200); // the GPRS baud rate |
| + | Serial.begin(19200); // the GPRS baud rate |
| + | } |
| + | |
| + | void loop() |
| + | { |
| + | char SerialInByte; |
| + | if(Serial.available()) |
| + | { |
| + | // EN: Listen to Arduino IDE serial Moniteur |
| + | // FR: Ecouter les envois du serial moniteur d'Arduino IDE |
| + | char SerialInByte; |
| + | SerialInByte = Serial.read(); |
| + | |
| + | // EN: Intercept escape character (tilde) for escape sequence |
| + | // FR: Intercepter le caractere d'echappement (tilde) for une sequence d'echappement |
| + | if( (SerialInByte == 126) && (escapingFlag==0) ) { |
| + | escapingFlag = 1; |
| + | return; // wait next caracter / attendre caractere suivant |
| + | } |
| + | else { |
| + | // EN: complete escaping sequence (if appropriate) |
| + | // FR: complete la séquence d'echappement (if appropriate) |
| + | if( escapingFlag == 1 ){ |
| + | if( SerialInByte == 122 ){ // (tilde) z = Ctrl Z |
| + | SerialInByte = 26; |
| + | } |
| + | if( SerialInByte == 101 ){ // (tilde) e = ESC |
| + | SerialInByte = 27; |
| + | } |
| + | escapingFlag = 0; |
| + | } |
| + | |
| + | // EN: Normal working. Simply send character (escaped or not) to GPRS shield |
| + | // FR: Fonctionnement normal. Envoyer le caractere (echappé ou non) vers GPRS shield |
| + | mySerial.print( SerialInByte ); |
| + | } |
| + | |
| + | } |
| + | else if(mySerial.available()) |
| + | { |
| + | // EN: Listen to GRPS shield + relay to Arduino Serial Monitor |
| + | // FR: Ecouter les envois du GPRS shield + Renvoi vers Arduino Serial Monitor |
| + | char c = mySerial.read(); |
| + | Serial.print( c ); |
| } | | } |
| | | |