As I explained in some of my previous
I connected the BMP085 sensor via I²C, the Adafruit Ultimate GPS via USB with an USB to UART bridge (CP2102, borrowed from a friend), and the NTX2 radio telemetry via UART.
Now, I'd like to connect the GPS via UART too (to save weight and easier testing), so, I'd like to connect two devices to a single port capable to manage only one. That could seem a problem without solution, but... From the GPS I only need to read data (therefore I only need the RX pin) and the NTX2 only need to send data (therefore I only need the TX pin). I've already tried to connect them one at a time and they work.
I connected the GPS only with the RX pin and I was able to read the data. Then I rebooted and connected the radio only with the TX pin, and I was able to send those data via radio.
Then I tried to connect them altogether... and it kinda worked... Briefly.
After a few data sent correctly, the software stops working, gives me some kind of error and quit.
Or, while is working, the character on the screen are replaced with something strange! I took a photo:
N.B. I didn't change the code in the above tests, and I always had the GPS fix.
In the first two tests the software stopped with the "IndexError", in the last one something weird was coming out and I used ctrl+C to interrupt.
Then I tried to run the software for the last time and again the weird character appeared, but I didn't do anything this time and in a few seconds I had the "IndexError" again, plus, all the character on screen were sort of "corrupted", even the "[email protected]". Unfortunately I didn't take a photo.
Anyway, this is my code:
Code: Select all
import serial import time import crcmod crc16f = crcmod.predefined.mkCrcFun('crc-ccitt-false') def send(data): NTX2 = serial.Serial('/dev/ttyAMA0', 50, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_TWO) NTX2.write(data) print data NTX2.close() def read_gps(): alt = 0 ora = 0 lat = 0 lon = 0 gps = serial.Serial('/dev/ttyAMA0', 9600, timeout=1) NMEA = gps.readline() gps.close() print "Lettura GPS ok" print NMEA data = NMEA.split(",") lat = data northsouth = data lon = data westeast = data alt = int(float(data)) ora = data ora = float(ora) string = "%06i" % ora hours = string[0:2]; minutes = string[2:4]; seconds = string[4:6] ora = str(hours) + ':' + str(minutes) + ':' + str(seconds) return lat, lon, alt, ora id = 0 while True: GPS = read_gps() lat = GPS; lon = GPS; alt = GPS; ora = GPS; temp=15 #temperatura di prova con BMP scollegato nome = "EOSO_TRY" stringa=str(nome + ',' + str(id) + ',' + str(lat) + ',' + str(lon) + ',' + str(alt) + ',' + str(temp)) csum = str(hex(crc16f(stringa))).upper()[2:] csum = csum.zfill(4) dati = str("$$" + stringa + "*" + csum + "\n") send(dati) id += 1 time.sleep(1)
Any thoughts? Should I stop trying so hard and just buy my own USB to UART bridge instead?