Adafruit Feather M4 CAN Express - weird output: b'\xff\xf0tU

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Twisy
 
Posts: 2
Joined: Mon Jul 26, 2021 10:40 am

Adafruit Feather M4 CAN Express - weird output: b'\xff\xf0tU

Post by Twisy »

Hello Forum

I'm trying to read a CAN_Bus and get on certain IDs a strange output with which I can not work further (B2).

Code: Select all

b'\xff\xf0<]\x00\x00'

what is this? <] they are always other characters.

I have checked the bus speed 500 kBaund is correct.
When I read the CAN_Bus with my oscilloscope I get correct data.
What is the problem? is something wrong with my code?
I am using a: Adafruit Feather M4 CAN Express with Adafruit CircuitPython 7.0.0

Code: Select all

import struct
import board
import canio
import digitalio
import time


if hasattr(board, 'CAN_STANDBY'):
    standby = digitalio.DigitalInOut(board.CAN_STANDBY)
    standby.switch_to_output(False)

if hasattr(board, 'BOOST_ENABLE'):
    boost_enable = digitalio.DigitalInOut(board.BOOST_ENABLE)
    boost_enable.switch_to_output(True)

can = canio.CAN(rx=board.CAN_RX, tx=board.CAN_TX, baudrate=500_000, auto_restart=True)

force_sensor = can.listen(matches=[canio.Match(0x48)], timeout=.9)

while True:
    time.sleep(0.1)
    message = force_sensor.receive()
    if not message is None:
        data = message.data
        print(data)

"""
Output:
b'\xff\xf0r\xc6\x00\x00'
b'\xff\xf0s)\x00\x00'
b'\xff\xf0s\x8d\x00\x00'
b'\xff\xf0s\xf0\x00\x00'
b'\xff\xf0tU\x00\x00'
b'\xff\xf0%\n\x00\x00'
b'\xff\xf0(\xed\x00\x00'
b'\xff\xf0,\xce\x00\x00'
b'\xff\xf00\xb2\x00\x00'
b'\xff\xf04\x96\x00\x00'
b'\xff\xf08y\x00\x00'
b'\xff\xf0<]\x00\x00'
b'\xff\xf0@>\x00\x00'
b'\xff\xf0D"\x00\x00'
"""


User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: Adafruit Feather M4 CAN Express - weird output: b'\xff\x

Post by tannewt »

Python prints byte strings as a mix of ASCII and escaped values. I'd recommend printing out each value separately to see what you are getting. The <] are ASCII for those particular values rather than the escaped version that starts with \x.

User avatar
joost
 
Posts: 8
Joined: Thu Jan 07, 2016 9:16 pm

Re: Adafruit Feather M4 CAN Express - weird output: b'\xff\x

Post by joost »


User avatar
Twisy
 
Posts: 2
Joined: Mon Jul 26, 2021 10:40 am

Re: Adafruit Feather M4 CAN Express - weird output: b'\xff\x

Post by Twisy »

Thank you for the hint and the help. I was now able to read out the data with the module struct.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”