Page 1 of 1

STM32F407: Not able to write binary data

Posted: Tue Jan 16, 2018 10:41 am
by nikhiledutech
Hello,

So i am currently reading the data from a sensor in an buffer created by byte array. So as usual the data recevied from the sensor are binary 1 or 0.

So when i try to write that byte array using uart.write(bytearray), i get garbage values printed on terminal.
So how can i solve this.

The baudrate is correctly arranged, and i am able to read data and also can write strings. But only binary data is not getting printed.

Even simple example like :
uart.writechar(1) is giving me garbage value.

Please help .
Thankyou

Re: STM32F407: Not able to write binary data

Posted: Tue Jan 16, 2018 5:33 pm
by dhylands
Most binary data looks like garabage. When you do uart.writechar(1) you're sending the character 0x01 which is a Control-A. If you're expecting something readable, then you need to convert the binary data into ASCII data. For example if you used binascii.hexlify then you can convert your binary data into a readable representation. There are many different ways of converting binary data into ASCII, it really depends on your data.

Re: STM32F407: Not able to write binary data

Posted: Wed Jan 17, 2018 10:33 am
by nikhiledutech
okay thanks :)

Re: STM32F407: Not able to write binary data

Posted: Fri Jan 19, 2018 9:36 am
by nikhiledutech
Hello,
What should i do to print a a variable on UART. I tried converting in binascii but its saying, object with buffer protocol required .

Binascii worked well with bytearray, as i converted my data. But with my variable it didnt worked?

eg:
x = 10
uart.write(x)

Any solution ?

Re: STM32F407: Not able to write binary data

Posted: Fri Jan 19, 2018 1:20 pm
by chuckbook

Code: Select all

uart.write('%d' % (x))