Interfacing Raspberry Pi Pico with SparkFun SAM-M8Q
Raspberry Pi Pico & SparkFun SAM-M8Q Currently, with the continuous development of science and technology, all daily activities are automated, robots gradually take over many positions in our daily lives. In order for automation devices to work correctly and efficiently, sensors are one of the important components. GPS is the main data we need to track here. We are going to use all popular Hardware like SparkFun SAM-M8Q and Raspberry Pi Pico. I will explain its working, pinout, protocol and interfacing with other microcontrollers in detail. I will also post some tutorial links where I have interfaced SparkFun SAM-M8Q with other microcontrollers. If you have any queries about it, ask in the comments and I will resolve it.
This article uses Thonny as ide and MicroPython-code for programming.
Raspberry Pi Pico Overview
Raspberry Pi Pico is the debut microcontroller-class board from Raspberry Pi. Built around our RP2040 silicon platform, Pico brings our signature values of high performance, low cost, and ease of use to the microcontroller space.
With a large on-chip memory, symmetric dual-core processor complex, deterministic bus fabric, and rich peripheral set augmented with our unique Programmable I/O (PIO) subsystem, RP2040 provides professional users
with unrivalled power and flexibility. With detailed documentation, a polished MicroPython port, and a UF2 bootloader in ROM, it has the lowest possible barrier to entry for beginner and hobbyist users.
RP2040 is manufactured on a modern 40nm process node, delivering high performance, low dynamic power consumption, and low leakage, with a variety of low-power modes to support extended-duration operation on battery power.
Raspberry Pi Pico pairs RP2040 with 2MB of Flash memory, and a power supply chip supporting input voltages from 1.8-5.5V. It provides 26 GPIO pins, three of which can function as analogue inputs, on 0.1”-pitch through-hole pads with castellated edges. Raspberry Pi Pico is available as an individual unit, or in 600-unit reels for automated assembly.
Raspberry Pi -Pico key features:
- ● RP2040 microcontroller with 2MByte Flash
- ● Micro-USB B port for power and data (and for reprogramming the Flash) ● 40 pin 21×51 ‘DIP’ style 1mm thick PCB with 0.1″ through-hole pins also with edge castellations
- ➢ Exposes 26 multi-function 3.3V General Purpose I/O (GPIO)
- ➢ 23 GPIO are digital-only and 3 are ADC capable
- ➢ Can be surface-mounted as a module.
- ● 3-pin ARM Serial Wire Debug (SWD) port .
- ● Simple yet highly flexible power supply architecture.
- ➢ Various options for easily powering the unit from micro-USB, external supplies or batteries.
- ● High quality, low cost, high availability.
- ● Comprehensive SDK, software examples and documentation.
- • Dual-core cortex M0+ at up to 133MHz
- ➢ On-chip PLL allows variable core frequency
- • 264kByte multi-bank high performance SRAM
- • External Quad-SPI Flash with eXecute In Place and 16kByte on-chip cache • High performance full-crossbar bus fabric Raspberry Pi Pico Datasheet • On-board USB1.1 (device or host)
- • 30 multi-function General Purpose IO (4 can be used for ADC) ➢ 1.8-3.3V IO Voltage (NOTE Pico IO voltage is fixed at 3.3V)
- • 12-bit 500ksps Analogue to Digital Converter (ADC)
- • Various digital peripherals
- ➢ 2 × UART, 2 × I2C, 2 × SPI, 16 × PWM channels
- ➢ 1 × Timer with 4 alarms, 1 × Real Time Counter
- • 2 × Programmable IO (PIO) blocks, 8 state machines total ➢ Flexible, user-programmable high-speed IO ➢ Can emulate interfaces such as SD Card and VGA
Figure 1. The pinout of the Raspberry Pi Pico Rev3 board.
|Interfacing:||26 GPIO pins, including 3 analogue inputs|
|CPU:||Dual-core Arm Cortex-M0+ @ 133MHz|
|Memory:||264 KB on-chip SRAM; 2MB on-board QSPI Flash|
|GIPO:||26 × multi-function GPIO pins 2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 8 × Programmable I/O (PIO) state machines for custom peripheral support Castellated module allows soldering directly to carrier boards|
|Input power:||1.8–5.5V DC|
Operating temperature: -20°C to +85°C
USB port: Micro USB
Production lifetime: Raspberry Pi Pico will remain in production until at least January 2028
Raspberry Pi Pico pinouts
GPIO Pins on Raspberry Pi Pico
|GPIO29: IP Used in ADC mode (ADC3) to measure VSYS/3|
|GPIO25: OP Connected to user LED|
|GPIO24: IP VBUS sense – high if VBUS is present, else low|
|GPIO23: OP Controls the on-board SMPS Power Save pin|
ADC or Analog to Digital Converter Pins
|ADC Pin GPIO Pins|
I2C Pins on Raspberry Pi Pico
I2C is a two-wire, bi-directional serial bus that provides an easy and quick method for transmission over a short distance between I2C enabled devices. The Raspberry Pi Pico comes with two I2C controllers, both I2C controllers are accessible through GPIO pins of Raspberry Pi Pico.
I2C Controller GPIO Pins
I2C0 SDA GP0/GP4/GP8/GP12/GP16/GP20
I2C0 SCL GP1/GP5/GP9/GP13/GP17/GP21
I2C1 SDA GP2/GP6/GP10/GP14/GP18/GP26
I2C1 SCL GP3/GP7/GP11/GP15/GP19/GP27
SPI Pins on Raspberry Pi Pico
Serial Peripheral Interface (SPI) is an interface bus that is used to transfer data between the microcontroller and SPI-enabled devices. Raspberry Pi Pico supports two SPI interfaces that are accessible through GPIO pins of the board.
|SPI Controller GPIO Pins|
UART Pins on Pico
The Raspberry Pi Pico also contains two identical UART peripherals. UART (universal asynchronous receiver-transmitter) pins are used for asynchronous serial communication between the micro-controller and UART devices or other microcontrollers.
|UART Pins GPIO Pins|
Other Pins on Pico board:–
GND: is the Ground pin used to complete the circuit.
VBUS: is the micro-USB input voltage connected to micro-USB port pin 1.
VSYS: is the main system input voltage, which can vary in the allowed range 1.8V to 5.5V, and is used by the on-board
SparkFun SAM-M8Q(Sensor Description)
The u-blox concurrent SAM-M8Q GNSS patch antenna module benefits from the exceptional performance of the u-blox M8 multi-GNSS engine. The SAM-M8Q module offers high sensitivity and minimal acquisition times in an ultra-compact form factor.
The SAM-M8Q module utilizes concurrent reception of up to three GNSS systems (GPS, Galileo and GLONASS), recognizes multiple constellations simultaneously and provides outstanding positioning accuracy in scenarios where urban canyon or weak signals are involved. For even better and faster positioning improvement, SAM-M8Q supports augmentation of QZSS, GAGAN and IMES together with WAAS, EGNOS, and MSAS. SAM-M8Q also supports message integrity protection, geofencing, and spoofing detection with configurable interface settings to easily fit to customer applications.
The SAM-M8Q GNSS patch antenna module is designed to receive and track the L1C/A signals provided at 1575.42 MHz by the Global Positioning System (GPS).
Standard Precision GNSS High Precision GNSS Dead Reckoning Timing
GPS / QZSS GLONASS Galileo BeiDou
3 Number of concurrent GNSS
SUPPLY-2.7 V – 3.6 V
Interfaces-UART USB SPI DDC (I2C compliant)
RTC crystal Oscillator
Built-in antenna supply and supervisor timepulse
Sparkfun GPS SAM-MQ8 PINOUTS:
Pin Connection Table
import time import board #import busio import machine from ublox_gps import UbloxGps sda=machine.Pin(1) scl=machine.Pin(2) i2c = machine.I2C(0,sda=sda, scl=scl, freq=400000) gps = UbloxGps(i2c, debug=False) def run(): try: print("Listening for UBX Messages") while True: try: geo = gps.geo_coords() print("Longitude: ", geo.lon) print("Latitude: ", geo.lat) print("Heading of Motion: ", geo.headMot) except (ValueError, IOError) as err: print(err) finally: port.close() if __name__ == '__main__': run()
import time import board import busio import machine from ublox_gps import UbloxGps sda=machine.Pin(1) scl=machine.Pin(2) i2c = machine.I2C(0,sda=sda, scl=scl, freq=400000) gps = UbloxGps(i2c, debug=False)
Import the libraries time, board, busio,machine and from the library ublox_gps import the element named UbloxGps. Declare the I2C pins in the board i.e, 1 and 2.
def run(): try: print("Listening for UBX Messages") while True: try: geo = gps.geo_coords() print("Longitude: ", geo.lon) print("Latitude: ", geo.lat) print("Heading of Motion: ", geo.headMot) except (ValueError, IOError) as err: print(err) finally: port.close() if __name__ == '__main__': run()
Define a function named ‘run’ which is made to run again and again. Print the message
Listening for UBX Messages
When the data is received then print the geo coordinates i.e, Latitude, Longitude and also the Heading Direction. And keep the loop run again and again so that the location can be displayed at the shortest interval possible.
This concludes the tutorial of interfacing a Raspberry Pi Pico with a Sparkfun SAM-MQ8 GPS module. The tutorial uses MicroPython as programming language and requires the use of terminal. Code and Schematic diagram can be found in the git link. We have found Sparkfun-GPS satellite locking is faster than any other module we have tested, In our test we found it takes around 6 to 8 sec to acquire and lock gps signal, This module has been tested with various boards and it is quite reliable.