UIFlow Guide
Use ESP32 internal CAN controller resources to realize CAN bus data sending and receiving, Note: Before using, you need to access CAN UNIT for the device.
from m5stack import *
from m5ui import *
from uiflow import *
from machine import CAN
import time
setScreenColor(0x222222)
frame = None
label0 = M5TextBox(16, 53, "Device State: ", lcd.FONT_Default, 0x00ff7c, rotate=0)
label1 = M5TextBox(126, 53, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(16, 97, "message: ", lcd.FONT_Default, 0x00ff7c, rotate=0)
label3 = M5TextBox(16, 132, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(16, 162, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(16, 192, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
def buttonA_wasPressed():
global frame
can.send([0, 1, 2, 3, 4, 5, 6, 7], 0)
pass
btnA.wasPressed(buttonA_wasPressed)
def buttonB_wasPressed():
global frame
can.clear_tx_queue()
can.clear_rx_queue()
pass
btnB.wasPressed(buttonB_wasPressed)
def buttonC_wasPressed():
global frame
can.restart()
pass
btnC.wasPressed(buttonC_wasPressed)
can = CAN(0, extframe=True, mode=CAN.NORMAL, baudrate=CAN.BAUDRATE_25K, tx_io=17, rx_io=16, auto_restart=False)
while True:
label1.setText(str(can.state()))
if can.any():
frame = can.recv()
label3.setText(str(frame[0]))
label4.setText(str(frame[1]))
label5.setText(str(frame[3]))
wait_ms(30)
wait_ms(2)
from machine import CAN
can = CAN(0, extframe=True, mode=CAN.NORMAL, baudrate=CAN.BAUDRATE_25K, tx_io=17, rx_io=16, auto_restart=False)
can.any()
frame = can.recv()
can.send([0, 1, 2, 3, 4, 5, 6, 7], id)
list
or tuple
, and the data length of the data frame is required to be 8 bytes
.can.setfilter(0, CAN.FILTER_RAW_SINGLE, [])
can.state()
can.clear_rx_queue()
can.clear_tx_queue()
can.clearfilter()
can.restart()
can.deinit()