Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SerialLCD.h>
- #include <SoftwareSerial.h>
- const int RX1 = 2;
- const int TX1 = 3;
- const int RX2 = 6;
- const int TX2 = 7;
- SoftwareSerial SoftSerial(RX1, TX1);
- SerialLCD slcd(RX2, TX2);//this is a must, assign soft serial pins
- char buffer[64]; // buffer array for data receive over serial port
- int count=0; // counter for buffer array
- void setup()
- {
- // setup the software serial pins
- pinMode(RX1, INPUT);
- pinMode(RX2, INPUT);
- pinMode(TX1, OUTPUT);
- pinMode(TX2, OUTPUT);
- }
- void loop()
- {
- SoftSerial.begin(9600);
- if (SoftSerial.available()) // if date is coming from software serial port ==> data is coming from SoftSerial shield
- {
- while(SoftSerial.available()) // reading data into char array
- {
- buffer[count++]=SoftSerial.read(); // writing data into array
- if(count == 64)break;
- }
- String gpsline(buffer);
- clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
- count = 0; // set counter of while loop to zero
- SoftSerial.end();
- if(gpsline.startsWith("$GPGGA")) {
- slcd.begin();
- slcd.clear();
- slcd.print("dd");
- slcd.setCursor(0, 0);
- slcd.print(gpsline.substring(17,19).c_str());
- slcd.setCursor(3, 0);
- slcd.print(gpsline.substring(19,21).c_str());
- slcd.setCursor(6, 0);
- slcd.print(gpsline.substring(22,24).c_str());
- slcd.setCursor(9, 0);
- slcd.print(gpsline.substring(24,26).c_str());
- slcd.setCursor(0, 1);
- slcd.print(gpsline.substring(30,32).c_str());
- slcd.setCursor(3, 1);
- slcd.print(gpsline.substring(32,34).c_str());
- slcd.setCursor(6, 1);
- slcd.print(gpsline.substring(35,37).c_str());
- slcd.setCursor(9, 1);
- slcd.print(gpsline.substring(37,39).c_str());
- slcd.end();
- delay(1000);
- }
- }
- }
- void clearBufferArray() // function to clear buffer array
- {
- for (int i=0; i<count;i++)
- {
- buffer[i]=NULL;
- } // clear all index of array with command NULL
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement