Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #include <SerialLCD.h>
  2. #include <SoftwareSerial.h>
  3.  
  4. const int RX1 = 2;
  5. const int TX1 = 3;
  6. const int RX2 = 6;
  7. const int TX2 = 7;
  8.  
  9. SoftwareSerial SoftSerial(RX1, TX1);
  10. SerialLCD slcd(RX2, TX2);//this is a must, assign soft serial pins
  11.  
  12. char buffer[64]; // buffer array for data receive over serial port
  13. int count=0; // counter for buffer array
  14. void setup()
  15. {
  16. // setup the software serial pins
  17. pinMode(RX1, INPUT);
  18. pinMode(RX2, INPUT);
  19. pinMode(TX1, OUTPUT);
  20. pinMode(TX2, OUTPUT);
  21.  
  22. }
  23.  
  24. void loop()
  25. {
  26. SoftSerial.begin(9600);
  27. if (SoftSerial.available()) // if date is coming from software serial port ==> data is coming from SoftSerial shield
  28. {
  29.  
  30. while(SoftSerial.available()) // reading data into char array
  31. {
  32. buffer[count++]=SoftSerial.read(); // writing data into array
  33. if(count == 64)break;
  34. }
  35.  
  36. String gpsline(buffer);
  37.  
  38. clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
  39. count = 0; // set counter of while loop to zero
  40. SoftSerial.end();
  41.  
  42. if(gpsline.startsWith("$GPGGA")) {
  43. slcd.begin();
  44.  
  45. slcd.clear();
  46. slcd.print("dd");
  47.  
  48. slcd.setCursor(0, 0);
  49. slcd.print(gpsline.substring(17,19).c_str());
  50. slcd.setCursor(3, 0);
  51. slcd.print(gpsline.substring(19,21).c_str());
  52. slcd.setCursor(6, 0);
  53. slcd.print(gpsline.substring(22,24).c_str());
  54. slcd.setCursor(9, 0);
  55. slcd.print(gpsline.substring(24,26).c_str());
  56.  
  57. slcd.setCursor(0, 1);
  58. slcd.print(gpsline.substring(30,32).c_str());
  59. slcd.setCursor(3, 1);
  60. slcd.print(gpsline.substring(32,34).c_str());
  61. slcd.setCursor(6, 1);
  62. slcd.print(gpsline.substring(35,37).c_str());
  63. slcd.setCursor(9, 1);
  64. slcd.print(gpsline.substring(37,39).c_str());
  65. slcd.end();
  66.  
  67. delay(1000);
  68. }
  69. }
  70.  
  71.  
  72. }
  73.  
  74.  
  75. void clearBufferArray() // function to clear buffer array
  76. {
  77. for (int i=0; i<count;i++)
  78. {
  79. buffer[i]=NULL;
  80. } // clear all index of array with command NULL
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement