/can_around

Play around with CAN bus using micropython and MCP chips on ESP modules

Primary LanguagePython

can_around

Play around with CAN bus using micropython and MCP chips on ESP modules

micropython

Arduino Mega

Modules connection

Setting up USBTinyISP support in Ubuntu for flashing Arduino

sudo nano /etc/udev/rules.d/99-USBtiny

Then paste

SUBSYSTEM=="usb", SYSFS{idVendor}=="1781", SYSFS{idProduct}=="0c9f", GROUP="users", MODE="0666"

or

SUBSYSTEM=="usb", ATTR{idVendor}=="1781", ATTR{idProduct}=="0c9f", GROUP="adm", MODE="0666"

into the new file. Write it out by pressing Ctrl-O and Ctrl-X to exit.

sudo usermod -a -G plugdev YOURUSERNAME
sudo service udev restart
sudo udevadm control --reload-rules

Insert the USBtinyISP again.

Getting started

from mcpcan import CAN
can = CAN()
# can.stop()
can.start()
msg = {'ext':True, 'id':0x18ff50e5, 'data':b'\x12\x34\x56\x78\x90\xab\xcd\xef', 'dlc':8, 'rtr':False}
can.send_msg(msg)

Debugging script

cfg = b'\x02\x92\x04'
can.stop()
can._spi_reset()
can._spi_write_bit(b'\x0f', b'\xe0', b'\x80')
can._spi_write_reg(b'\x28', cfg)
can._spi_write_bit(b'\x60', b'\x64', b'\x64')

can._spi_write_bit(b'\x70', b'\x60', b'\x00')
can._spi_write_reg(b'\x08', b'\xff\xff\xff\xff')
can._spi_write_reg(b'\x10', b'\xff\xff\xff\xff')
can._spi_write_reg(b'\x14', b'\xff\xff\xff\xff')
can._spi_write_reg(b'\x18', b'\xff\xff\xff\xff')
can._spi_write_reg(b'\x24', b'\xff\xff\xff\xff')
can._spi_write_bit(b'\x0f', b'\xe0', b'\x00')
can.send_msg(msg)

Documentation and tools

Useful links