I have been struggling with this for the last 24 hours, I am trying to get PySerial to talk to a VEX Cortex over bluetooth using UART / HC-05. I guess this would be very similar to communicating with a Arduino.
The devices are connected together and data is flowing but its junk
In RobotC:(as you can see no encoding is apparent, i believe its just going over as bytes)
#include "BNSlib_HC05.h"
task main()
{
setBaudRate(UART1, baudRate19200);
bnsATGetBaudrate(UART1)
char stringBuffer[100];;
while(1==1)
{
bnsSerialRead(UART1, stringBuffer, 100, 100);
writeDebugStreamLine(stringBuffer);
delay(500);
bnsSerialSend(UART1, (char*)&"simon");
}
}
In python PySerial
import serial
import time
import struct
ser = serial.Serial(port='COM8', baudrate=19200)
print("connected to: " + ser.portstr)
message = "Simon"
while True:
ser.write(message.encode()) # I guess this is encoding via utf8?
#for b in bytearray("simon was here","UTF-8"):
#ser.write(b)
print("sent")
time.sleep (100.0 / 1000.0);
result = ser.read(25) # tried readline, just hangs
print(">> " + result.decode('cp1252')) # tried utf8, ascii
ser.close()
print("close")
In robotC I get back f˜fžþžøž In Python I am getting back ýýýýýýýýýýýýýýýýýýýýýýýýý
It turned out the HC-05 module was not configured correctly :(