I’m currently trying to run the CAN protocol example in OpenMV. However, I get the error “ImportError: cannot import name CAN” when trying to run the script .
I’m using the example code provided in the pyb.CAN documentation:
from pyb import CAN
can = CAN(2, CAN.LOOPBACK)
can.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126)) # set a filter to receive messages with id=123, 124, 125 and 126
can.send('message!', 123) # send a message with id 123
can.recv(0) # receive message on FIFO 0
I’m using OpenMV IDE 1.5.2 on Windows 7, 64-bit.
I’m relatively new to python. Is it possible that I’m doing something wrong so that the CAN library is not being imported properly?
I say you need to do this because I really can’t help you if there are any errors since I’ve never tested the code myself. That said, following the C code isn’t that hard and will illuminate how to call the code in Python.
I’ve debugged and figured out how to do UART/I2C pretty well and I know those things are solid. SPI works good too for master mode. Slave mode is rather made to use however as it’s difficult to get in sync with a spi master, but, it’s possible. See the Pixy emulation example scripts for how to code this stuff up.