[PYTHON] [Raspberry PI & Garmin GLO] Until you connect Bluetooth GPS to Raspberry Pi

Equipment used

Raspberry PI B+ raspbian: raspberrypi 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 ** Garmin GLO **: Bluetooth GPS receiver Bluetooth dongle: Elecom-Logitec ** LBT-UAN04C1 ** (CSR chipset with a reputation for Linux)

Preparation

Let's introduce modules

apt-get install bluez bluez-utils

Don't forget to apt-get install python-bluez for coding with python ver.2.

Command line Garmin GLO connectivity test

(1) hcitool scan Scan Garmin GLO. You should see an address like 12:34:56:78:90: AB. ** (2) Port connection **

sudo rfcomm bind /dev/rfcomm1 12:34:56:78:90:AB 1

This will create a Garmin GLO Virtual COM port as / dev / rfcomm1. However, the GLO bluetooth status LED remains blinking slowly. (Not paired) ** (3) Data dump from port ** Easy way is

cat < /dev/rfcomm1

is. If you do this, the GLO bluetooth status LED will be lit (ie paired) with a delay and you will see the NMEA output on the console. When you are finished, use ctrl -c to exit.

Or

dd if=/dev/rfcomm1 of= ...

Is also OK.

Python (ver.2) In python ver.2, PyBluez is used.

sudo apt-get install python-bluez

Let's introduce it with.

import bluetooth

bd_addr = "12:34:56:78:90:AB"
port = 1

sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((bd_addr, port))
data=sock.recv(1024)

sock.close()
print data

In this case, the data returned by sock.recv () will be of type str.

Python3 python3 uses the standard socket module.

import socket

bd_addr = "12:34:56:78:90:AB"
port = 1

sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
sock.connect((bd_addr, port))
data = sock.recv(1024)

sock.close()

dataReadable = data.decode('utf-8')
print(dataReadable)

In this case, the data returned by sock.recv () will be of type bytes. So, let's convert it to str with decode ().

Recommended Posts

[Raspberry PI & Garmin GLO] Until you connect Bluetooth GPS to Raspberry Pi
Connect two USB cameras to Raspberry Pi 4
Connect your Raspberry Pi to your smartphone using Blynk
Connect to MySQL with Python on Raspberry Pi
Introduced python3-OpenCV3 to Raspberry Pi
I talked to Raspberry Pi
Introducing PyMySQL to raspberry pi3
Connect Raspberry Pi to Alibaba Cloud IoT Platform with Python
A memo when connecting bluetooth from a smartphone / PC to Raspberry Pi 4
Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)
Port FreeRTOS to Raspberry Pi 4B
Output from Raspberry Pi to Line
[Raspberry Pi] Changed Python default to Python3
How to install NumPy on Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Connect to the console of Raspberry PI and display local IP and SD information