Components and supplies
Enclosure for Arduino Mega 2560
Tools and machines
Beitian BN-280 GPS-Receiver
Project description
Code
GPS-accuracy
arduino
Measure the precision of your Arduino [GPS-time-stamp PPS -vs- measured time with micros() and millis()]
1///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2// 3// demonstrate how to receive GPS-data character by character with an Beitian BN-280 and an Arduino Mega 2560 4// 5// with the 2.nd and 3.rd listing you can test the accuracy of your Arduinos - the clock-rate is mostly not very precise 6// 7// 8// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 9// x x 10// x BN-280 x 11// x x 12// x x 13// x ceramic-antenna upwards x 14// x x 15// x x 16// x LED's (downside) x blue LED flasches 1x per sec - 17// x x red LED flashes only if you receive valid data 18// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 19// | | | | | | 20// pin-nr. 6 5 4 3 2 1 21// | | | | | | 22// | | | | | 1-- = PPS (1 short pulse pes second if BN-280 received valid data) 23// | | | | 2----- = GND ( 0V from Arduino Mega) 24// | | | 3 ------- = TX ( GPS-data to PC) 25// | | 4----------- = RX ( data from PC - mostly not needed) 26// | 5-------------- = VCC ( +5V from Arduino Mega) 27// 6----------------- = BOOT (NC) normally not used 28// 29// 30// wiring diagram BN-280 to Arduino Mega 2560: 31// 32// BN-280 --- Arduino Mega 2560 33// ------------------------------------ 34// pin-1 --- pin 2 (used in anothe program for Interrupt to test the accuracy of the Arduino) 35// pin-2 --- GND 36// pin-3 --- pin 19 (used as Serial1 with 9600) 37// pin-4 --- not used 38// pin-5 --- VCC 39// pin-6 --- not used 40// 41////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 42 43 44 45///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46// // 47// Listing 1 can be used for a High-Precision Clock, for a GPS-Tracker or someone else - Time is GPS-time // 48// // 49// With Listings 2 and 3 you can check the accuracy of your Arduino Mega (or other Arduini too) // 50// The PPS of your BN-280 has a very high accuracy (like GPS) // 51// // 52// The internal 'clock' or 'timer' of an Arduino is not very precise // 53// // 54// My Mega 2560 works not like discribed with 16MHz // 55// It works with about 16,017MHZ // 56// This value is relatively constant, only with a small temperature-drift // 57// // 58// Program 2 and 3 counts the PPS-signal and read the time of your Arduino with micros() or nanos() // 59// // 60// Tis listing contains 3 programs - please choose only one at the same time // 61// // 62// // 63// Response of Listing 1 is: 155230 = 15:52:30 ; lat ; 51.362358093261; lon ; 7.077597618103 // 64// // 65// Time h m s Lat Lon // 66// // 67///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 68 69 70 71 72 73/* 74///////////////////////////////////////////////////// Begin Program 1 /////////////////////////////////////////////// 75// // 76const byte interruptPin = 2; // 77char vergleich='$'; // new line start with "$" // 78char zeichen; // 79char teil0[20]; // 80char teil1[20]; // 81char teil2[20]; // 82String zeichenkette, gesamttext,text1, text2, text3, text4, text5, text6;; // 83int pos=1; // 84double latoriginal; // lat = 52,... // 85double lonoriginal; // lon = 7,... // 86double Zeit,Puffer,stunde,minute,sekunde;; // 87//-----------------------------------------------------------------------------------------------------------------// 88void setup() // 89{ // 90 Serial.begin(115200); // speed to computer // 91 Serial1.begin(9600); // speed from BN-280 // 92 pinMode(interruptPin, INPUT_PULLUP); // Important: INPUT_PULLUP !!! // 93 zeichenkette=" "; // 94} // 95//-----------------------------------------------------------------------------------------------------------------// 96void loop() // 97 { // 98 if(zeichenkette=="$") // a new line starts with "$" // 99 { // 100 do // 101 { // 102 zeichen=Serial1.read(); // 103 if((zeichen>36)&&(zeichen<91)) // valid character from ASCII 36 to ASCII 91 // 104 { // 105 if (zeichen!=',') // data are separated by "," // 106 { // 107 zeichenkette = zeichenkette + zeichen; // add each character to a string // 108 } // 109 else // 110 { // 111 if (pos==6) // 112 { // 113 text6=zeichenkette; // 114 zeichenkette=""; // 115 pos++; // 116 } // 117 if (pos==5) // 118 { // 119 text5=zeichenkette; // 120 zeichenkette=""; // 121 pos++; // 122 } // 123 if (pos==4) // 124 { // 125 text4=zeichenkette; // 126 zeichenkette=""; // 127 pos++; // 128 } // 129 if (pos==3) // 130 { // 131 text3=zeichenkette; // 132 zeichenkette=""; // 133 pos++; // 134 } // 135 if (pos==2) // 136 { // 137 text2=zeichenkette; // 138 zeichenkette=""; // 139 pos++; // 140 } // 141 if (pos==1) // 142 { // 143 zeichenkette=""; // 144 pos++; // 145 } // 146 } // 147 } // 148 } // 149 while(zeichen!=vergleich ); // 150 } // 151 else // 152 { // 153 if (text3=="A") // Ist die ein gltiger Datensatz ? // valid data? // 154 { // // 155 text2.toCharArray(teil0,20); // // 156 Zeit=strtod(teil0,NULL); // convert time(text) to time(number) // 157 // // 158 text4.toCharArray(teil1,20); // // 159 latoriginal=strtod(teil1,NULL); // convert lat(text) to lat(number) // 160 latoriginal=latoriginal/100; // // 161 // // 162 text6.toCharArray(teil2,20); // // 163 lonoriginal=strtod(teil2,NULL); // convert lon(text) to lon(number) // 164 lonoriginal=lonoriginal/100; // // 165 // // 166 stunde=int(Zeit/10000.0); // separate time in: // 167 Puffer=Zeit-stunde*10000; // hours // 168 minute=int(Puffer/100.0); // minutes // 169 sekunde=Zeit-stunde*10000-minute*100; // seconds // 170 // 171 //////////////////////////////////////////////////////////////////////// Output only with valid data // 172 // // 173 Serial.print(Zeit,0); // print received time // 174 Serial.print(" = "); // // 175 Serial.print(stunde,0); // print hours // 176 Serial.print(":"); // // 177 Serial.print(minute,0); // print minutes // 178 Serial.print(":"); // // 179 Serial.print(sekunde,0); // print seconds // 180 // // 181 Serial.print(" ; lat ; "); // // 182 Serial.print(latoriginal,12); // print lat // 183 Serial.print("; lon ; "); // // 184 Serial.println(lonoriginal,12); // print lon // 185 } // 186 zeichenkette = vergleich; // 187 pos=1; // 188 } // 189 } // 190///////////////////////////////////////////////////////// End Program 1 ///////////////////////////////////////////// 191*/ 192 193 194 195 196//////////////////////////////////////////////////////// Begin Program 2 //////////////////////////////////////////// 197// // 198// This program show the difference between GPS-precision und Arduino // 199// This Program uses micros() // 200// // 201// Arduino is triggerd vis interrupt from BN-280 // 202// The PPS-signal has GPS-accuracy // 203// // 204// PPS has the highest precision you get free if your board has a pps-output // 205// // 206// At the beginning you have a countdown // 207// On 0 the time is reset to 0 // 208// Then every sec you get a new response like: // 209// -2 8188288 // 210// -1 9189348 // 211// 0 0 // 212// 1 1001064 // 213// 2 2002124 // 214// 3 3003188 // 215// and so on // 216// // 217// The example values of my Arduino shows, that every sec the internal // 218// counter - called by micros() - added not exactly 1000000microsecons // 219// // 220// Here the difference is 1064microsec in the first sec // 221// After 2sec the differece is 2124microsec // 222// // 223// My Arduino is to fast. In 3sec it counts 3188microsec to much // 224// In 12 hours the different was 46,119484sec // 225// // 226// That's nothing for high precision // 227// But it's good enogh for many experiments // 228// // 229// You can copy the values from the monitor-program into Win-Editor // 230// Save the file to test.txt // 231// Open the file with Excel, separated by " " (blank) // 232// Then show an x-y plot // 233// // 234//-----------------------------------------------------------------------------------------------------------------// 235// // 236const byte interruptPin = 2; // 237const byte ausgang1 = 5; // 238const byte ausgang2 = 7; // 239const byte ledPin = 13; // 240double Ausgabe,Zeitpunkt,microsPrevious, microsNow1,microsDelta1; // 241int identifier; // 242int messwerte; // 243int messpos = 0; // 244int idlevel = 0; // 245int gesendet = 0; // 246//----------------------------------------------------------------------- // 247void setup() // 248 { // 249 Serial.begin(115200); // 250 pinMode(ledPin, OUTPUT); // 251 pinMode(ausgang1, OUTPUT); // 252 pinMode(ausgang2, OUTPUT); // 253 pinMode(interruptPin, INPUT_PULLUP); // Important: INPUT_PULLUP !!! // 254 attachInterrupt(digitalPinToInterrupt(interruptPin), blink, RISING); // 255 Zeitpunkt=-10; // 256 microsPrevious = micros(); // 257 } // 258//-----------------------------------------------------------------------------------------------------------------// 259void loop() // 260 { // 261 // nothing to do - Program run through the Interrupt // 262 } // 263//-----------------------------------------------------------------------------------------------------------------// 264void blink() // 265 { // 266 microsNow1 = micros(); // 267 microsDelta1=microsNow1-microsPrevious; // 268 microsPrevious=microsNow1; // 269 if(Zeitpunkt==0) // 270 { // 271 Ausgabe=0; // 272 } // 273 else // 274 { // 275 Ausgabe=Ausgabe+microsDelta1; // 276 } // 277 Serial.print(Zeitpunkt,0); // , 0); // 278 Serial.print(" "); // 279 Serial.println(Ausgabe,0); // , 0); // 280 Zeitpunkt++; // 281 } // 282//-----------------------------------------------------------------------------------------------------------------// 283//////////////////////////////////////////////////////// End Program 2 ////////////////////////////////////////////// 284 285 286 287 288 289/* 290//////////////////////////////////////////////////////// Begin Program 3 //////////////////////////////////////////// 291// // 292// Show the difference between GPS-precision und Arduino // 293// This Program uses millis() // 294// // 295// Arduino is triggerd vis interrupt from BN-280 // 296// The PPS-signal has GPS-accuracy // 297// // 298// PPS has the highest precision you get free if your board has a pps-output // 299// // 300// At the beginning you have a countdown // 301// On 0 the time is reset to 0 // 302// Then every sec you get a new response like: // 303// -3 7133 // 304// -2 8134 // 305// -1 9135 // 306// 0 0 // 307// 1 1002 // 308// 2 2002 // 309// 3 3003 // 310// and so on // 311// // 312// The example values of my Arduino shows, that every sec the internal // 313// counter - called by millis() - added not exactly 1000msec // 314// // 315// Here the difference is about 2msec in the first sec // 316// After 2sec the differece show 2msec too // 317// But it's rounded, so sometimes it shows the same difference // 318// // 319// My Arduino is to fast - the same like with micros() // 320// A short test shows: // 321// 598 598638 // 322// 599 599638 // 323// ---> 600 600640 <--- // 324// 601 601641 // 325// 602 602641 // 326// // 327// In 10min the difference was 640msec - see marking above --> <-- // 328// In 938sec the difference was about 1sec // 329// That's the same like the test's with micros() // 330// // 331// That's nothing for high precision // 332// But it's good enogh for many experiments // 333// // 334// You can copy the values from the monitor-program into Win-Editor // 335// Save the file to test.txt // 336// Open the file with Excel, separated by " " (blank) // 337// Then show an x-y plot // 338// // 339// left: time in sec (GPS) right: counts called by millis() // 340// // 341// at the beginning you have a countdown to compare the time with a clock // 342// // 343// if you run the program for 1000sec and Arduino is perfect then // 344// you get "1000 1000000" // 345// (in 1000sec you get 1000000msec) // 346// // 347// With my Arduino I get "1000 1001069" // 348// (That's very bad for long-time experiments) // 349// (For short-time-use it's o.K) // 350// // 351//-----------------------------------------------------------------------------------------------------------------// 352// // 353const byte interruptPin = 2; // 354double Zeitpunkt,Ausgabe,millisPrevious,millisDelta,millisNow; // 355//----------------------------------------------------------------------- // 356void setup() // 357 { // 358 Serial.begin(115200); // 359 pinMode(interruptPin, INPUT_PULLUP); // 360 attachInterrupt(digitalPinToInterrupt(interruptPin), blink, RISING); // 361 Zeitpunkt=-10; // 362 Ausgabe=0; // 363 millisPrevious = millis(); // 364 } // 365//-----------------------------------------------------------------------------------------------------------------// 366void loop() // 367 { // 368 // nothing to do - Program run through the Interrupt // 369 } // 370//-----------------------------------------------------------------------------------------------------------------// 371void blink() // 372 { // 373 millisNow = millis(); // 374 millisDelta=millisNow-millisPrevious; // 375 millisPrevious=millisNow; // 376 if(Zeitpunkt==0) // 377 { // 378 Ausgabe=0; // 379 } // 380 else // 381 { // 382 Ausgabe=Ausgabe+millisDelta; // 383 } // 384 //messwerte=microsDelta1; // 385 //Serial.println(messwerte, 0); // 386 Serial.print(Zeitpunkt,0); // , 0); // 387 Serial.print(" "); // 388 Serial.println(Ausgabe,0); // , 0); // 389 Zeitpunkt++; // 390 } // 391//-----------------------------------------------------------------------------------------------------------------// 392//////////////////////////////////////////////////////// End Progam 3 /////////////////////////////////////////////// 393*/ 394
GPS-accuracy
arduino
Measure the precision of your Arduino [GPS-time-stamp PPS -vs- measured time with micros() and millis()]
1///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2// 3// 4 demonstrate how to receive GPS-data character by character with an Beitian 5 BN-280 and an Arduino Mega 2560 6// 7// with the 2.nd and 3.rd listing you 8 can test the accuracy of your Arduinos - the clock-rate is mostly not very precise 9// 10// 11// 12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 13// x 14 x 15// x BN-280 16 x 17// x x 18// 19 x x 20// x 21 ceramic-antenna upwards x 22// x x 23// 24 x x 25// x 26 LED's (downside) x blue LED flasches 1x per sec - 27// x 28 x red LED flashes only if you receive valid data 29// 30 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 31// | 32 | | | | | 33// pin-nr. 6 5 4 3 2 1 34// 35 | | | | | | 36// | 37 | | | | 1-- = PPS (1 short pulse pes second if BN-280 received valid data) 38// 39 | | | | 2----- = GND ( 0V from Arduino 40 Mega) 41// | | | 3 ------- = TX ( 42 GPS-data to PC) 43// | | 4----------- 44 = RX ( data from PC - mostly not needed) 45// | 46 5-------------- = VCC ( +5V from Arduino Mega) 47// 6----------------- 48 = BOOT (NC) normally not used 49// 50// 51// wiring diagram BN-280 to Arduino 52 Mega 2560: 53// 54// BN-280 --- Arduino Mega 2560 55// ------------------------------------ 56 57// pin-1 --- pin 2 (used in anothe program for Interrupt 58 to test the accuracy of the Arduino) 59// pin-2 --- GND 60// 61 pin-3 --- pin 19 (used as Serial1 with 9600) 62// pin-4 63 --- not used 64// pin-5 --- VCC 65// pin-6 66 --- not used 67// 68////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 69 70 71 72///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 73// 74 // 75// 76 Listing 1 can be used for a High-Precision Clock, for a GPS-Tracker or someone 77 else - Time is GPS-time // 78// // 79// 80 With Listings 2 and 3 you can check the accuracy of your Arduino Mega (or other 81 Arduini too) // 82// The PPS of your BN-280 has a very high 83 accuracy (like GPS) // 84// 85 // 86// 87 The internal 'clock' or 'timer' of an Arduino is not very precise // 88// 89 // 90// 91 My Mega 2560 works not like discribed with 16MHz // 92// 93 It works with about 16,017MHZ // 94// 95 This value is relatively constant, only with a small temperature-drift // 96// 97 // 98// 99 Program 2 and 3 counts the PPS-signal and read the time of your Arduino with micros() 100 or nanos() // 101// // 102// 103 Tis listing contains 3 programs - please choose only one at the same time // 104// 105 // 106// 107 // 108// 109 Response of Listing 1 is: 155230 = 15:52:30 ; lat ; 51.362358093261; lon ; 110 7.077597618103 // 111// // 112// 113 Time h m s Lat Lon 114 // 115// // 116///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 117 118 119 120 121 122/* 123///////////////////////////////////////////////////// 124 Begin Program 1 /////////////////////////////////////////////// 125// // 126const 127 byte interruptPin = 2; // 128char 129 vergleich='$'; // new line start with "$" // 130char 131 zeichen; // 132char 133 teil0[20]; // 134char 135 teil1[20]; // 136char 137 teil2[20]; // 138String 139 zeichenkette, gesamttext,text1, text2, text3, text4, text5, text6;; // 140int 141 pos=1; // 142double 143 latoriginal; // lat = 52,... // 144double 145 lonoriginal; // lon = 7,... // 146double 147 Zeit,Puffer,stunde,minute,sekunde;; // 148//-----------------------------------------------------------------------------------------------------------------// 149void 150 setup() // 151{ 152 // 153 154 Serial.begin(115200); // speed to computer // 155 156 Serial1.begin(9600); // speed from BN-280 // 157 158 pinMode(interruptPin, INPUT_PULLUP); // Important: 159 INPUT_PULLUP !!! // 160 zeichenkette=" "; // 161} 162 // 163//-----------------------------------------------------------------------------------------------------------------// 164void 165 loop() // 166 167 { // 168 169 if(zeichenkette=="$") // a new line starts with "$" 170 // 171 { // 172 173 do // 174 175 { // 176 177 zeichen=Serial1.read(); // 178 179 if((zeichen>36)&&(zeichen<91)) // valid character from ASCII 180 36 to ASCII 91 // 181 { // 182 183 if (zeichen!=',') // data are separated by "," 184 // 185 { // 186 187 zeichenkette = zeichenkette + zeichen; // add each character to a string 188 // 189 } // 190 191 else // 192 193 { // 194 195 if (pos==6) // 196 197 { // 198 199 text6=zeichenkette; // 200 201 zeichenkette=""; // 202 203 pos++; // 204 205 } // 206 207 if (pos==5) // 208 209 { // 210 211 text5=zeichenkette; // 212 213 zeichenkette=""; // 214 215 pos++; // 216 217 } // 218 219 if (pos==4) // 220 221 { // 222 223 text4=zeichenkette; // 224 225 zeichenkette=""; // 226 227 pos++; // 228 229 } // 230 231 if (pos==3) // 232 233 { // 234 235 text3=zeichenkette; // 236 237 zeichenkette=""; // 238 239 pos++; // 240 241 } // 242 243 if (pos==2) // 244 245 { // 246 247 text2=zeichenkette; // 248 249 zeichenkette=""; // 250 251 pos++; // 252 253 } // 254 255 if (pos==1) // 256 257 { // 258 259 zeichenkette=""; // 260 261 pos++; // 262 263 } // 264 265 } // 266 267 } // 268 269 } // 270 271 while(zeichen!=vergleich ); // 272 273 } // 274 275 else // 276 277 { // 278 279 if (text3=="A") // Ist die ein gltiger Datensatz 280 ? // valid data? // 281 { // 282 // 283 text2.toCharArray(teil0,20); 284 // // 285 286 Zeit=strtod(teil0,NULL); // convert time(text) to time(number) 287 // 288 // 289 // 290 text4.toCharArray(teil1,20); 291 // // 292 293 latoriginal=strtod(teil1,NULL); // convert lat(text) to lat(number) 294 // 295 latoriginal=latoriginal/100; // 296 // 297 // 298 // 299 text6.toCharArray(teil2,20); 300 // // 301 302 lonoriginal=strtod(teil2,NULL); // convert lon(text) to lon(number) 303 // 304 lonoriginal=lonoriginal/100; // 305 // 306 // 307 // 308 stunde=int(Zeit/10000.0); 309 // separate time in: // 310 311 Puffer=Zeit-stunde*10000; // hours // 312 313 minute=int(Puffer/100.0); // minutes // 314 315 sekunde=Zeit-stunde*10000-minute*100; // seconds // 316 317 // 318 319 //////////////////////////////////////////////////////////////////////// Output 320 only with valid data // 321 // // 322 323 Serial.print(Zeit,0); // print received time // 324 325 Serial.print(" = "); // // 326 327 Serial.print(stunde,0); // print hours // 328 329 Serial.print(":"); // // 330 331 Serial.print(minute,0); // print minutes // 332 333 Serial.print(":"); // // 334 335 Serial.print(sekunde,0); // print seconds // 336 337 // // 338 339 Serial.print(" ; lat ; "); // // 340 341 Serial.print(latoriginal,12); // print lat // 342 343 Serial.print("; lon ; "); // // 344 345 Serial.println(lonoriginal,12); // print lon // 346 347 } // 348 349 zeichenkette = vergleich; // 350 351 pos=1; // 352 353 } // 354 355 } // 356///////////////////////////////////////////////////////// 357 End Program 1 ///////////////////////////////////////////// 358*/ 359 360 361 362 363//////////////////////////////////////////////////////// 364 Begin Program 2 //////////////////////////////////////////// 365// // 366// 367 This program show the difference between GPS-precision 368 und Arduino // 369// This Program uses 370 micros() // 371// // 372// 373 Arduino is triggerd vis interrupt from BN-280 374 // 375// The 376 PPS-signal has GPS-accuracy // 377// 378 // 379// 380 PPS has the highest precision you get free 381 if your board has a pps-output // 382// // 383// 384 At the beginning you have a countdown // 385// 386 On 0 the time is reset to 0 // 387// 388 Then every sec you get a new response like: 389 // 390// -2 391 8188288 // 392// 393 -1 9189348 // 394// 395 0 0 // 396// 397 1 1001064 // 398// 399 2 2002124 // 400// 401 3 3003188 // 402// 403 and so on // 404// 405 // 406// 407 The example values of my Arduino shows, that 408 every sec the internal // 409// counter 410 - called by micros() - added not exactly 1000000microsecons // 411// // 412// 413 Here the difference is 1064microsec in the 414 first sec // 415// After 416 2sec the differece is 2124microsec // 417// // 418// 419 My Arduino is to fast. In 3sec it counts 3188microsec 420 to much // 421// In 12 hours the 422 different was 46,119484sec // 423// // 424// 425 That's nothing for high precision // 426// 427 But it's good enogh for many experiments // 428// 429 // 430// 431 You can copy the values from the monitor-program 432 into Win-Editor // 433// Save the 434 file to test.txt // 435// Open 436 the file with Excel, separated by " " (blank) // 437// 438 Then show an x-y plot // 439// 440 // 441//-----------------------------------------------------------------------------------------------------------------// 442// 443 // 444const 445 byte interruptPin = 2; // 446const 447 byte ausgang1 = 5; // 448const 449 byte ausgang2 = 7; // 450const 451 byte ledPin = 13; // 452double 453 Ausgabe,Zeitpunkt,microsPrevious, microsNow1,microsDelta1; // 454int 455 identifier; // 456int 457 messwerte; // 458int 459 messpos = 0; // 460int 461 idlevel = 0; // 462int 463 gesendet = 0; // 464//----------------------------------------------------------------------- 465 // 466void setup() // 467 468 { // 469 470 Serial.begin(115200); // 471 472 pinMode(ledPin, OUTPUT); // 473 474 pinMode(ausgang1, OUTPUT); // 475 476 pinMode(ausgang2, OUTPUT); // 477 478 pinMode(interruptPin, INPUT_PULLUP); // Important: 479 INPUT_PULLUP !!! // 480 attachInterrupt(digitalPinToInterrupt(interruptPin), 481 blink, RISING); // 482 Zeitpunkt=-10; 483 // 484 485 microsPrevious = micros(); // 486 487 } // 488//-----------------------------------------------------------------------------------------------------------------// 489void 490 loop() // 491 492 { // 493 494 // nothing to do - Program run through the Interrupt // 495 496 } // 497//-----------------------------------------------------------------------------------------------------------------// 498void 499 blink() // 500 501 { // 502 503 microsNow1 = micros(); // 504 505 microsDelta1=microsNow1-microsPrevious; // 506 507 microsPrevious=microsNow1; // 508 509 if(Zeitpunkt==0) // 510 511 { // 512 513 Ausgabe=0; // 514 515 } // 516 517 else // 518 519 { // 520 521 Ausgabe=Ausgabe+microsDelta1; // 522 523 } // 524 525 Serial.print(Zeitpunkt,0); // , 0); // 526 527 Serial.print(" "); // 528 529 Serial.println(Ausgabe,0); // , 0); // 530 531 Zeitpunkt++; // 532 533 } // 534//-----------------------------------------------------------------------------------------------------------------// 535//////////////////////////////////////////////////////// 536 End Program 2 ////////////////////////////////////////////// 537 538 539 540 541 542/* 543//////////////////////////////////////////////////////// 544 Begin Program 3 //////////////////////////////////////////// 545// // 546// 547 Show the difference between GPS-precision 548 und Arduino // 549// This 550 Program uses millis() // 551// // 552// 553 Arduino is triggerd vis interrupt from BN-280 554 // 555// The 556 PPS-signal has GPS-accuracy // 557// 558 // 559// 560 PPS has the highest precision you get free 561 if your board has a pps-output // 562// // 563// 564 At the beginning you have a countdown // 565// 566 On 0 the time is reset to 0 // 567// 568 Then every sec you get a new response like: 569 // 570// -3 571 7133 // 572// 573 -2 8134 // 574// 575 -1 9135 // 576// 577 0 0 // 578// 579 1 1002 // 580// 581 2 2002 // 582// 583 3 3003 // 584// 585 and so on // 586// 587 // 588// 589 The example values of my Arduino shows, that 590 every sec the internal // 591// counter 592 - called by millis() - added not exactly 1000msec // 593// // 594// 595 Here the difference is about 2msec in the 596 first sec // 597// After 598 2sec the differece show 2msec too // 599// But 600 it's rounded, so sometimes it shows the same difference // 601// 602 // 603// 604 My Arduino is to fast - the same like with 605 micros() // 606// A 607 short test shows: // 608// 609 598 598638 // 610// 611 599 599638 // 612// 613 ---> 600 600640 <--- // 614// 615 601 601641 // 616// 617 602 602641 // 618// 619 // 620// 621 In 10min the difference was 640msec - see 622 marking above --> <-- // 623// In 624 938sec the difference was about 1sec // 625// 626 That's the same like the test's with micros() 627 // 628// // 629// 630 That's nothing for high precision // 631// 632 But it's good enogh for many experiments // 633// 634 // 635// 636 You can copy the values from the monitor-program 637 into Win-Editor // 638// Save the 639 file to test.txt // 640// Open 641 the file with Excel, separated by " " (blank) // 642// 643 Then show an x-y plot // 644// 645 // 646// 647 left: time in sec (GPS) right: counts called 648 by millis() // 649// // 650// 651 at the beginning you have a countdown to compare 652 the time with a clock // 653// // 654// 655 if you run the program for 1000sec and Arduino 656 is perfect then // 657// you get 658 "1000 1000000" // 659// (in 660 1000sec you get 1000000msec) // 661// 662 // 663// 664 With my Arduino I get "1000 1001069" // 665// 666 (That's very bad for long-time experiments) 667 // 668// (For 669 short-time-use it's o.K) // 670// // 671//-----------------------------------------------------------------------------------------------------------------// 672// 673 // 674const 675 byte interruptPin = 2; // 676double 677 Zeitpunkt,Ausgabe,millisPrevious,millisDelta,millisNow; // 678//----------------------------------------------------------------------- 679 // 680void setup() // 681 682 { // 683 684 Serial.begin(115200); // 685 686 pinMode(interruptPin, INPUT_PULLUP); // 687 688 attachInterrupt(digitalPinToInterrupt(interruptPin), blink, RISING); // 689 690 Zeitpunkt=-10; // 691 692 Ausgabe=0; // 693 694 millisPrevious = millis(); // 695 696 } // 697//-----------------------------------------------------------------------------------------------------------------// 698void 699 loop() // 700 701 { // 702 703 // nothing to do - Program run through the Interrupt // 704 705 } // 706//-----------------------------------------------------------------------------------------------------------------// 707void 708 blink() // 709 710 { // 711 712 millisNow = millis(); // 713 714 millisDelta=millisNow-millisPrevious; // 715 716 millisPrevious=millisNow; // 717 718 if(Zeitpunkt==0) // 719 720 { // 721 722 Ausgabe=0; // 723 724 } // 725 726 else // 727 728 { // 729 730 Ausgabe=Ausgabe+millisDelta; // 731 732 } // 733 734 //messwerte=microsDelta1; // 735 736 //Serial.println(messwerte, 0); // 737 738 Serial.print(Zeitpunkt,0); // , 0); // 739 740 Serial.print(" "); // 741 742 Serial.println(Ausgabe,0); // , 0); // 743 744 Zeitpunkt++; // 745 746 } // 747//-----------------------------------------------------------------------------------------------------------------// 748//////////////////////////////////////////////////////// 749 End Progam 3 /////////////////////////////////////////////// 750*/ 751
Downloadable files
2560
Tested board
2560
Documentation
GPS-accuracy with BN-280
Used GPS-Receiver
GPS-accuracy with BN-280
GPS-accuracy with BN-280
Used GPS-Receiver
GPS-accuracy with BN-280
Comments
Only logged in users can leave comments