STM32F407: Not able to write binary data

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

STM32F407: Not able to write binary data

Post by nikhiledutech » Tue Jan 16, 2018 10:41 am

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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: STM32F407: Not able to write binary data

Post by dhylands » Tue Jan 16, 2018 5:33 pm

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.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: STM32F407: Not able to write binary data

Post by nikhiledutech » Wed Jan 17, 2018 10:33 am

okay thanks :)

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: STM32F407: Not able to write binary data

Post by nikhiledutech » Fri Jan 19, 2018 9:36 am

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 ?

chuckbook
Posts: 135
Joined: Fri Oct 30, 2015 11:55 pm

Re: STM32F407: Not able to write binary data

Post by chuckbook » Fri Jan 19, 2018 1:20 pm

Code: Select all

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

Post Reply