Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. /*
  2. ### Get GPS data
  3. 1. This example is used to test SIM808 GPS/GPRS/GSM Shield's reading GPS data.
  4. 2. Open the SIM808_GetGPS example or copy these code to your project
  5. 3. Download and dial the function switch to Arduino
  6. 4. open serial helper
  7. 4. Place it outside, waiting for a few minutes and then it will send GPS data to serial
  8.  
  9. create on 2016/09/23, version: 1.0
  10. by jason
  11.  
  12. */
  13. #include <DFRobot_sim808.h>
  14. #include <SoftwareSerial.h>
  15.  
  16. #define PIN_TX 7
  17. #define PIN_RX 8
  18. SoftwareSerial mySerial(PIN_TX,PIN_RX);
  19. DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
  20.  
  21.  
  22.  
  23. void setup() {
  24. mySerial.begin(9600);
  25. Serial.begin(9600);
  26.  
  27. //******** Initialize sim808 module *************
  28. while(!sim808.init()) {
  29. delay(1000);
  30. Serial.print("Sim808 init errorrn");
  31. }
  32.  
  33. //************* Turn on the GPS power************
  34. if( sim808.attachGPS())
  35. Serial.println("Open the GPS power success");
  36. else
  37. Serial.println("Open the GPS power failure");
  38.  
  39. }
  40.  
  41. void loop() {
  42. //************** Get GPS data *******************
  43. if (sim808.getGPS()) {
  44. Serial.print(sim808.GPSdata.year);
  45. Serial.print("/");
  46. Serial.print(sim808.GPSdata.month);
  47. Serial.print("/");
  48. Serial.print(sim808.GPSdata.day);
  49. Serial.print(" ");
  50. Serial.print(sim808.GPSdata.hour);
  51. Serial.print(":");
  52. Serial.print(sim808.GPSdata.minute);
  53. Serial.print(":");
  54. Serial.print(sim808.GPSdata.second);
  55. Serial.print(":");
  56. Serial.println(sim808.GPSdata.centisecond);
  57. Serial.print("latitude :");
  58. Serial.println(sim808.GPSdata.lat);
  59. Serial.print("longitude :");
  60. Serial.println(sim808.GPSdata.lon);
  61. Serial.print("speed_kph :");
  62. Serial.println(sim808.GPSdata.speed_kph);
  63. Serial.print("heading :");
  64. Serial.println(sim808.GPSdata.heading);
  65. Serial.println();
  66.  
  67. //************* Turn off the GPS power ************
  68. sim808.detachGPS();
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement