HI ,
I have written the code to send hex value to the Arduino board serially , and the hex data is converted to Manchester formate and then sent to ARduino board .
But when i tap the receiver pin on the arduino board using Pico scope can see the 8 bits data splitted in to nibbles and each nibble is flipped and an additional bit is added b/w each nibble . Can you please help me where I am doing wrong , I have given print statement in the python , in python can see the encoded and decoded byte is printing correct value ,now i can see the issue only when i check the data on the RX pin data is corrupted.
Need help on this matter pls
import typing
import serial
import time
import manchester_code
type or paste code here
def send_data_to_arduino(encoded_data):
arduino_port='COM4'
baud_rate=19200
with serial.Serial(arduino_port,baud_rate,timeout=1) as ser:
time.sleep(2)
ser.write(encoded_data)
#data_to_send1 = bytearray(b'\x15\x16\x00\x00\x77\x7C\xFA\xCC\xF4\xA4\x7C\x81') # Frame 1
data_to_send1 = bytearray(b'\x00\x11') # Frame 1
#data_to_send =bytearray(b'\x17') # note in the picoscope binary value is it shown as 1000001110- need to check what issue is
#data_to_send2 = bytearray(b'\x15\x16\x00\x00\x77\x7C\xFA\xCC\xF4\xA4\x7C\x81') # Frame 2
data_to_send2 = bytearray(b'\x00\x12') # Frame 2
try:
while True:
delay =0.1
############################## sending frame 1 ##############################
encoded_data1 =manchester_code.encode(data_to_send1)
send_data_to_arduino(encoded_data1)
print(''.join(['{:08b}'.format(m) for m in encoded_data1])) # this is to print the hex data converted to machester in to binary format.
print("Encoded Data1 : ",encoded_data1 )
delay=0.12
############################# sending frame 2 ####################################
encoded_data2 =manchester_code.encode(data_to_send2)
send_data_to_arduino(encoded_data2)
print(''.join(['{:08b}'.format(m) for m in encoded_data2])) # this is to print the hex data converted to machester in to binary format.
print("Encoded Data2 : ",encoded_data2 )
############################# decoding frame 1 ######################################
decoded_data1=manchester_code.decode(encoded_data1)
Result in the terminal
Received data in binary1: 00000000 00010001
Decoded_Data 2: b'\x00\x12'
Received data in binary2: 00000000 00010010
01010101010101010101011001010110
Encoded Data1 : b'UUVV'
01010101010101010101011001011001
Encoded Data2 : b'UUVY'
Decoded_Data 1: b'\x00\x11'
Received data in binary1: 00000000 00010001
Decoded_Data 2: b'\x00\x12'
Received data in binary2: 00000000 00010010
And on the Arduino side I am using the below code
type or paste code here
void setup() {
Serial.begin(19200);
}
void loop() {
while( Serial.available()>0)
{
char receivedData= Serial.read();
Serial.print("Received : ");
Serial.println(receivedData);
}
}