SHOW:
|
|
- or go back to the newest paste.
| 1 | - | #include <string.h> |
| 1 | + | /* |
| 2 | - | #include <ctype.h> |
| 2 | + | Example code for connecting a Parallax GPS module to the Arduino |
| 3 | - | #include <LiquidCrystal.h> |
| 3 | + | Igor Gonzalez Martin. 05-04-2007 |
| 4 | [email protected] | |
| 5 | English translation by djmatic 19-05-2007 | |
| 6 | Listen for the $GPRMC string and extract the GPS location data from this. | |
| 7 | - | int rxPin = 0; // RX PIN |
| 7 | + | Display the result in the Arduino's serial monitor. |
| 8 | - | int txPin = 1; // TX TX |
| 8 | + | */ |
| 9 | - | int rx_val =0 ; |
| 9 | + | #include <string.h> |
| 10 | #include <ctype.h> | |
| 11 | int ledPin1= 10; // LED test pin | |
| 12 | int ledPin2= 9; //LED warning limit | |
| 13 | int ledPin3= 8; //LED warning over limit | |
| 14 | int byteGPS=-1; | |
| 15 | char linea[300] = ""; | |
| 16 | char comandoGPR[7] = "$GPRMC"; | |
| 17 | - | LiquidCrystal lcd(12, 11, 5, 4, 3, 2); |
| 17 | + | |
| 18 | - | void setup() {
|
| 18 | + | |
| 19 | - | pinMode(10,OUTPUT); // Initialize LED pin |
| 19 | + | |
| 20 | - | pinMode(9, OUTPUT); |
| 20 | + | |
| 21 | - | pinMode(8, OUTPUT); |
| 21 | + | |
| 22 | - | pinMode(rxPin, INPUT); |
| 22 | + | int lat = 0; |
| 23 | - | pinMode(txPin, OUTPUT); |
| 23 | + | void setup() |
| 24 | - | lcd.begin(16,2); |
| 24 | + | {
|
| 25 | - | lcd.setCursor(0,0); |
| 25 | + | pinMode(ledPin1,OUTPUT); // Initialize LED pin |
| 26 | - | lcd.print("Lat:");
|
| 26 | + | pinMode(ledPin2, OUTPUT); |
| 27 | - | //lcd.setCursor(0,1); |
| 27 | + | pinMode(ledPin3, OUTPUT); |
| 28 | - | //lcd.print("Long:");
|
| 28 | + | |
| 29 | for (int i=0;i<300;i++){ // Initialize a buffer for received data
| |
| 30 | linea[i]=' '; | |
| 31 | } | |
| 32 | ||
| 33 | ||
| 34 | - | void loop() {
|
| 34 | + | |
| 35 | - | digitalWrite(10,HIGH); //indikator runing data reciver |
| 35 | + | void loop() |
| 36 | - | byteGPS=Serial.read(); // Read a byte of the serial port |
| 36 | + | {
|
| 37 | - | //lcd.write(Serial.read()); // TAMBAHAN |
| 37 | + | digitalWrite(ledPin1, HIGH); |
| 38 | byteGPS=Serial.read(); // Read a byte of the serial port | |
| 39 | if (byteGPS == -1) { // See if the port is empty yet
| |
| 40 | delay(100); | |
| 41 | } else {
| |
| 42 | // note: there is a potential buffer overflow here! | |
| 43 | linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer | |
| 44 | conta++; | |
| 45 | - | |
| 45 | + | |
| 46 | if (byteGPS==13){ // If the received byte is = to 13, end of transmission
| |
| 47 | // note: the actual end of transmission is <CR><LF> (i.e. 0x13 0x10) | |
| 48 | - | digitalWrite(10, LOW); |
| 48 | + | digitalWrite(ledPin1, LOW); |
| 49 | cont=0; | |
| 50 | bien=0; | |
| 51 | // The following for loop starts at 1, because this code is clowny and the first byte is the <LF> (0x10) from the previous transmission. | |
| 52 | for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR
| |
| 53 | if (linea[i]==comandoGPR[i-1]){
| |
| 54 | bien++; | |
| 55 | } | |
| 56 | } | |
| 57 | - | |
| 57 | + | |
| 58 | for (int i=0;i<300;i++){
| |
| 59 | if (linea[i]==','){ // check for the position of the "," separator
| |
| 60 | // note: again, there is a potential buffer overflow here! | |
| 61 | indices[cont]=i; | |
| 62 | cont++; | |
| 63 | } | |
| 64 | if (linea[i]=='*'){ // ... and the "*"
| |
| 65 | indices[12]=i; | |
| 66 | cont++; | |
| 67 | } | |
| 68 | } | |
| 69 | Serial.println(""); // ... and write to the serial port
| |
| 70 | Serial.println("");
| |
| 71 | Serial.println("---------------");
| |
| 72 | for (int i=0;i<12;i++) | |
| 73 | - | for (int i=0;i<12;i++){
|
| 73 | + | {
|
| 74 | - | switch(i){
|
| 74 | + | switch(i) |
| 75 | - | |
| 75 | + | {
|
| 76 | - | case 0 :Serial.print("Time in UTC (HhMmSs): "); break;
|
| 76 | + | case 0 :Serial.print("Time in UTC (HhMmSs): ");break;
|
| 77 | - | case 1 :Serial.print("Status (A=OK,V=KO): ");break;
|
| 77 | + | case 1 :Serial.print("Status (A=OK,V=KO): ");break;
|
| 78 | - | case 2 :Serial.print("Latitude: ");break;
|
| 78 | + | case 2 :Serial.print("Latitude: ");break;
|
| 79 | - | case 3 :Serial.print("Direction (N/S): ");break;
|
| 79 | + | case 3 :Serial.print("Direction (N/S): ");break;
|
| 80 | - | case 4 :Serial.print("Longitude: ");break;
|
| 80 | + | case 4 :Serial.print("Longitude: ");break;
|
| 81 | - | case 5 :Serial.print("Direction (E/W): ");break;
|
| 81 | + | case 5 :Serial.print("Direction (E/W): ");break;
|
| 82 | - | case 6 :Serial.print("Velocity in knots: ");break;
|
| 82 | + | case 6 :Serial.print("Velocity in knots: ");break;
|
| 83 | - | case 7 :Serial.print("Heading in degrees: ");break;
|
| 83 | + | case 7 :Serial.print("Heading in degrees: ");break;
|
| 84 | - | case 8 :Serial.print("Date UTC (DdMmAa): ");break;
|
| 84 | + | case 8 :Serial.print("Date UTC (DdMmAa): ");break;
|
| 85 | - | case 9 :Serial.print("Magnetic degrees: ");break;
|
| 85 | + | case 9 :Serial.print("Magnetic degrees: ");break;
|
| 86 | - | case 10 :Serial.print("(E/W): ");break;
|
| 86 | + | case 10 :Serial.print("(E/W): ");break;
|
| 87 | - | case 11 :Serial.print("Mode: ");break;
|
| 87 | + | case 11 :Serial.print("Mode: ");break;
|
| 88 | - | case 12 :Serial.print("Checksum: ");break;
|
| 88 | + | case 12 :Serial.print("Checksum: ");break;
|
| 89 | } | |
| 90 | - | for (int j=indices[i];j<(indices[i+1]-1);j++){
|
| 90 | + | for (int j=indices[i];j<(indices[i+1]-1);j++) |
| 91 | - | Serial.print(linea[j+1]); |
| 91 | + | {
|
| 92 | - | lcd.print(linea[j+15]); |
| 92 | + | Serial.print(linea[j+1]); |
| 93 | - | delay(0); |
| 93 | + | |
| 94 | - | |
| 94 | + | |
| 95 | - | // lcd.setCursor(5,1); // set cursor valLong : |
| 95 | + | Serial.println("");
|
| 96 | - | // lcd.print(linea[j+35]); |
| 96 | + | |
| 97 | - | // delay(0); |
| 97 | + | //********** Checking Latitude limit ****************** |
| 98 | - | |
| 98 | + | if(i==2)//i=2 indicate latitude |
| 99 | - | if (linea[j+21]>4 ){
|
| 99 | + | {
|
| 100 | - | digitalWrite(9, HIGH); //indikator warning limit |
| 100 | + | //convert latitude data to int |
| 101 | - | }else{
|
| 101 | + | int k = indices[i]; |
| 102 | - | digitalWrite(9, LOW); |
| 102 | + | lat = (linea[k+1]-48)*1000 + (linea[k+2]-48)*100 + (linea[k+3]-48)*10 +(linea[k+4]-48); |
| 103 | - | // delay(100); |
| 103 | + | if(lat > 55) |
| 104 | - | |
| 104 | + | {
|
| 105 | - | if (linea[j+21]>9 ){
|
| 105 | + | //Led on when latitude value larger than 0055 |
| 106 | - | digitalWrite(8, HIGH); //indikator over limit |
| 106 | + | digitalWrite(ledPin2, HIGH); |
| 107 | - | }else{
|
| 107 | + | } |
| 108 | - | digitalWrite(8, LOW); |
| 108 | + | else |
| 109 | - | // delay(100); |
| 109 | + | {
|
| 110 | - | |
| 110 | + | digitalWrite(ledPin2, LOW); |
| 111 | - | } |
| 111 | + | } |
| 112 | } | |
| 113 | - | |
| 113 | + | //*************************************************** |
| 114 | } | |
| 115 | ||
| 116 | - | Serial.println("");
|
| 116 | + | Serial.print("Latitude: ");
|
| 117 | Serial.println(lat); | |
| 118 | Serial.println("---------------");
| |
| 119 | } | |
| 120 | conta=0; // Reset the buffer | |
| 121 | for (int i=0;i<300;i++){ //
| |
| 122 | linea[i]=' '; | |
| 123 | } | |
| 124 | } | |
| 125 | } | |
| 126 | - | lcd.setCursor(4,0); // set cursor val Lat : |
| 126 | + |