From 02f69a304a0e55a8f3164b7b1fbafbf0ba7f07b4 Mon Sep 17 00:00:00 2001 From: inmcm Date: Mon, 2 Feb 2015 20:53:34 -0500 Subject: [PATCH] Add external interrupt updater example --- pyboard/GPIO_interrupt_updater.py | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 pyboard/GPIO_interrupt_updater.py diff --git a/pyboard/GPIO_interrupt_updater.py b/pyboard/GPIO_interrupt_updater.py new file mode 100644 index 0000000..2daf885 --- /dev/null +++ b/pyboard/GPIO_interrupt_updater.py @@ -0,0 +1,47 @@ +from pyb import UART +from pyb import ExtInt +from pyb import Pin +from micropyGPS import MicropyGPS + +# Global Flag to Start GPS data Processing +new_data = False + + +# Callback Function +def pps_callback(line): + print("Updated GPS Object...") + global new_data # Use Global to trigger update + new_data = True + +print('GPS Interrupt Tester') + +# Instantiate the micropyGPS object +my_gps = MicropyGPS() + +# Setup the connection to your GPS here +# This example uses UART 3 with RX on pin Y10 +# Baudrate is 9600bps, with the standard 8 bits, 1 stop bit, no parity +# Also made the buffer size very large (1000 chars) to accommodate all the characters that stack up +# each second +uart = UART(3, 9600, read_buf_len=1000) + +# Create an external interrupt on pin X8 +pps_pin = pyb.Pin.board.X8 +extint = pyb.ExtInt(pps_pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, pps_callback) + +# Main Infinite Loop +while 1: + # Do Other Stuff Here....... + + # Update the GPS Object when flag is tripped + if new_data: + while uart.any(): + my_gps.update(chr(uart.readchar())) # Note the conversion to to chr, UART outputs ints normally + + print('UTC Timestamp:', my_gps.timestamp) + print('Date:', my_gps.date_string('long')) + print('Latitude:', my_gps.latitude_string()) + print('Longitude:', my_gps.longitude_string()) + print('Horizontal Dilution of Precision:', my_gps.hdop) + print() + new_data = False # Clear the flag