As discussed in previous blog posts here, there is a 3rd party Arduino Board Support Package for The Raspberry Pi Pico W. A port of the Azure SDK for C Arduino for the RPi Pico with that BSP was also implemented and discussed here. The Pico W has built-in WiFi and Bluetooth capabilities although Bluetooth wasn’t implemented in the original BSP. The BSP has been updated this year to support Bluetooth. A suite of sketches have been developed invoking the simple use of Bluetooth to echo characters, the sending of parsed GPS location data over Bluetooth and sending location data to an Azure IoT Hub.

The Arduino RPi Pico W with GPS

The Repository on GitHub

djaus2/RPI Pico W GPS and Bluetooth



The Sketches

  1. USART1 Echo
  2. Basic GPS
  3. InteractiveGPS
  4. LocationGPS
  5. BTSerialUppercase.
  6. BluetoothGPS
  7. Azure_IoT_Hub_GPS
  8. read_d2c_messages

As can be seen, there is a sequential build up to sending the location data, as json, over Bluetooth. For example, the first Sketch exercises the second serial port on the Pico that is subsequently connected to the GPS device. The second gets and separates the GPS sentences. The third allows stopping and starting the reception of messages as well as filtering the accepted messages, with a focus upon location messages. The fourth parses and interprets the location data displaying it optionally as a tuple or as a json string. The fifth implements a simple example of using Bluetooth as a text echo. The sixth completes the sending of location data as a json string over Bluetooth. The seventh Sketch doesn’t use Bluetooth but sends that location json string to an Azure IoT Hub using the Azure SDK for C Arduino as ported and discussed on this blog site. read_d2c_messages is a C# Console app monitoring telemtry sent to the IoT Hub.


The Bluetooth supported by the BSP is Classic as well as BLE. Classic is used here. When installed, samples in the Arduino IDE the BT samples are :

  • Classic: Files-Examples-SerialBT-SerialBluuetoothUppercase
  • BLE: Files-Examples-BTStack-_(there are 6 examples.)_

The BT Sketches here only require a Bluetooth terminal on a device paired to the Pico. Whilst I could get it to work on my Windows 11 desktop, I did find it problematic. Would pair or connect sometimes but not others. I found a BT Serial Terminal app on my Android phone work OK each time it was called upon: Android phone app Serial Bluetooth Terminal.


The Arduino GPS Receiver

  • Arduino Compatible GPS Receiver Module Jaycar (Australia) CAT.NO: XC3710
  • nblox NEO-7M Module BAUD is 9600
  • There are a number of similar devices that could be seamlessly substituted.

This supplies streams of NMEA sentences serially as text over RS232. The connectivity info is:

// // Nb: GPn pin numbers not package pin numbers
#define TXD2 4  // Not used
#define RXD2 5  // Connect to GPS Unit TX

// Pins Ceramic Antenna side of GPS device:
// =========================================
// PPS nc
// RXD nc
// TXD --> RXD2
// GND --> GND
// Vcc --> 3.3V

// Note: USART1 is Serial2
// RPI Pico has has 2 USART, USART0 is Serial/Serial1/USB

NMEA sentence processing

Whilst the second Sketch demonstrates the reception of all GPS NMEA sentences, the latter Sketches target:

  • $GPGLL
  • $GPAGG
  • $GPGSV

The sixth Sketch uses the $GPAGG sentences to get location latitude, longitude and height.

In parsing these, use is made of string processing rather than any GPS libraries, such as TinyGPSPlus:

  • Ignore NMEA text until $ then read until end of line (/n and /r accommodated).
  • Filter out all sentences except those that start with “$GPGGa”
  • Split the sentence using a comma delimiter, into SplitNMEA
// Locations in GPAGG of entities
#define latIndex 2
#define longIndex 4
#define heightIndex 9

So, for example, SplitNMEA[latIndex] is the latitude as string.

The latitude is made negative, by prepending a ‘-‘, if SplitNMEA[latIndex+1] direction is ‘S’ and the longitude is made negative if SplitNMEA[longIndex+1] is ‘W’.

Also latitude and longitude are 100x so their decimal points are shifted left by 2 decimal places by string manipulations.

This algorithm has been corrected. See the next blog post: GPS:NMEA101

Rather than use an existing library such as ArduinoJson (that is used in the 7th Sketch), the tuple and json strings are “manually” created by explicitly adding values in sequence with fixed strings naming the properties.

This processing was subsequently refactored in Sketch 4 into a separate function to simplify reuse in Sketch 6. This could be separately published.

Sketch Outputs


NMEA Messages



  • $GPGGA is the first entity on each line
  • Latitude is 4th
  • Longitude is 6th
  • Altitude is 12th
Mode: Display Location as a tuple

Location Data as a tuple

Mode: Display Location as Json Telemetry string

Location Data as json string

Bluetooth Terminal on Phone displaying raw NMEA Data

Bluetooth Terminal on Phone displaying json location Data

Connecting to WIFI SSID APQLZM
............WiFi connected, IP address:
Setting time using SNTP.done!
Current time: Wed Aug 16 13:20:15 2023
MQTT connecting ... connected.
GPS is Setup
13084 RPI Pico (Arduino) Sending telemetry . . . 

RPi Pico connecting to an Azure IoT Hub and sending telemetry using MQTT

Listening for messages on: 0
Message received on partition 0:
Application properties (set by device):
Listening for messages on: 0
Message received on partition 0:
Application properties (set by device):
Listening for messages on: 0
Message received on partition 0:
Application properties (set by device):

Console app monitoring telemetry sent to IoT Hub

  Next: > GPS
<  Prev:   Jekyll
 This Category Links 
Category:Pico W AzSDK Index:Pico W AzSDK
<  Prev:   RPI-Pico-Arduino-AzSDK