Skip to content

Instantly share code, notes, and snippets.

@kvico
Last active March 22, 2018 16:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvico/92969f73c60c709bbcdb728514f62552 to your computer and use it in GitHub Desktop.
Save kvico/92969f73c60c709bbcdb728514f62552 to your computer and use it in GitHub Desktop.
Parse Grove GPS values with Calliope Mini PXT block editor
/*
Snippet reads the first 3 digits of Latitude and Longitude values of Grove GPS connected to a Calliope Mini
Links:
- PXT editor for Calliope Mini: http://pxt.calliope.cc/index.html)
- Sensor description and Python example code for Grove GPS: http://wiki.seeed.cc/Grove-GPS/
- GPS sensor spec: http://www.vis-plus.ee/pdf/SIM28@SIM68R@SIM68V_NMEA_Messages_Specification_V1.01.pdf
Licensed under the Apache Software License 2.0 (ASL 2.0)
*/
let gpgga_value = ""
let indexplus = 0
let item = ""
let length = 0
let counter = 0
let value = ""
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
# . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
serial.redirect(
SerialPin.C17,
SerialPin.C16,
BaudRate.BaudRate9600
)
serial.writeString("$PMTK104*37<CR><LF>")
})
serial.onDataReceived(serial.delimiters(Delimiters.Dollar), () => {
value = serial.readString()
music.playTone(262, music.beat(BeatFraction.Whole))
length = value.length
counter = 0
for (let index = 0; index <= length; index++) {
item = value.charAt(index)
if (item == ",") {
counter += 1
// Latitude
if (counter == 1) {
indexplus = index
indexplus += 1
gpgga_value = value.substr(indexplus, 3)
basic.showString(gpgga_value)
}
// Longitude
if (counter == 3) {
indexplus = index
indexplus += 1
gpgga_value = value.substr(indexplus, 3)
basic.showString(gpgga_value)
}
music.playTone(147, music.beat(BeatFraction.Whole))
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment