0

I may be asking about something that has already been done, so apologies if that is the case...

I have a USB GPS plugged into one of the USB ports on my RPi(2). It works now in that GPS data is passed and processed by RPi based applications.

What I want to do, is to take that same GPS data string moving to/from the GPS device via the RPi's USB port and move it to/from the GPIO as TTL level (not RS-232, but serial nonetheless) data that it may be used on other devices which do not have USB host capability and therefor cannot communicate to a USB GPS.

In the current setup, most application are looking at the USB GPS as being on a virtual com port (/dev/ttyUSBxx).

So I suppose what I am wanting to do is send/receive serial GPS data between a USB based virtual com port and a GPIO virtual com port.

A virtual 'router' or 'message switch' if you will.

What I am NOT looking to create is a USB port using the GPIO.

Physical: USB GPS <---> RPi USB port---RPi GPIO <---> GPS Data to/from other devices.

Logical: USB GPS Data <----- GPS Data Routed in RPi ----> GPIO GPS Data

0

You could do it with the pyserial package http://pyserial.readthedocs.io/en/latest/pyserial.html

Create two instances, one for the usb port, the second for the UART (GPIO14/GPIO15)

read from usb port, process the gps data, if it is necessary and finally write it to the uart.

import serial

reading = True

serial_usb = serial.Serial('/dev/ttyUSB0', 9600)
serial_uart = serial.Serial('/dev/ttyAMA0', 9600)

while reading:
    gps_data = str(serial_usb.readline(), 'utf-8').split(',')
    # process the gps_data
    serial_uart.write(bytes(gps_data))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.