fabianpi
Posts: 13
Joined: Tue Mar 07, 2017 4:01 pm

communicating with bluetooth and serial module

Wed May 22, 2019 7:59 pm

I'm interfacing with a NEO‑6M GPS in a raspberry pi and I also getting some data from a HC-05 module connected to an arduino.

The script is basically reading both buffers to append them together in one json string. The problem is that this process works for 5 seconds and then program stopped with this exception:

Code: Select all

SerialException('device reporst rediness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)
What I'm basically reading is the gps module over the GPIO pins with /dev/ttyS0 and the bluetooth module is used working with /dev/ttyAMA0

As I said, I am able to connect to my bluetooth module and also able to read data from the gps module. but I am getting this error and I wanted to know if there are any possible solutions that I could follow. I also tried to disable the console and changing the gps module to be read by /dev/ttyAMA0 and the bluetooth module with the /dev/ttyS0 but without any sucess comunicating with my bluetooth module.

So I am open to ideas to find a solution for this.

Here's attached my code in python to handle data

Code: Select all

import subprocess, time
import serial
import numpy as np
import time
import datetime
import pynmea2
import json

ser = serial.Serial('/dev/rfcomm0', 9600)
gpsSerial = serial.Serial('/dev/ttyS0',9600, timeout = 0.5)
ser.flushInput()

print("Waiting for Data...")

def findGPSRead():
        gpsMsg = gpsSerial.readline()
        if gpsMsg.find('GGA') > 0:
            print("hello")
            gpsObj = pynmea2.parse(gpsMsg)  
            print (gpsObj.lat,gpsObj.lat_dir,gpsObj.lon,gpsObj.lon_dir)
   

try:
    while (True):
        if(ser.inWaiting() > 0 and gpsSerial.inWaiting() > 0):
            arduinoJSON = ser.readline()

            print(arduinoJSON)
            print("gps buffer {}".format(gpsSerial.readline()) )

except Exception as e:
            print("Error: ", e)
Thank you so much for your time and any reply will be helpful!

Return to “Python”