Atomic CAN Base
This is the driver library for the ATOM CAN Base to accept and send data from the CAN module.
Support the following products:
UiFlow2 Example
CAN communication
Open the atoms3_can_example.m5f2 project in UiFlow2.
This example shows how to receive and send data using the Atom CAN Base.
UiFlow2 Code Block:
Example output:
Output of received CAN message data via serial port.
MicroPython Example
CAN communication
This example shows how to receive and send data using the Atom CAN Base.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from base import ATOMCANBase 9import time 10 11 12title0 = None 13label0 = None 14label1 = None 15base_can = None 16 17 18def setup(): 19 global title0, label0, label1, base_can 20 21 M5.begin() 22 title0 = Widgets.Title("CAN Base", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 23 label0 = Widgets.Label("TX:", 1, 38, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 24 label1 = Widgets.Label("RX:", 1, 68, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 25 26 base_can = ATOMCANBase(0, (6, 5), ATOMCANBase.NORMAL, baudrate=1000000) 27 28 29def loop(): 30 global title0, label0, label1, base_can 31 M5.update() 32 if BtnA.isPressed(): 33 label0.setText(str("TX: Send")) 34 base_can.send("uiflow2", 0, timeout=0, rtr=False, extframe=False) 35 time.sleep(1) 36 label0.setText(str("TX: Not Send")) 37 if base_can.any(0): 38 label1.setText(str("RX: Rec")) 39 print(base_can.recv(0, timeout=5000)) 40 time.sleep(1) 41 label1.setText(str("RX: Not Rec")) 42 43 44if __name__ == "__main__": 45 try: 46 setup() 47 while True: 48 loop() 49 except (Exception, KeyboardInterrupt) as e: 50 try: 51 from utility import print_error_msg 52 53 print_error_msg(e) 54 except ImportError: 55 print("please update to latest firmware")
Example output:
Output of received CAN message data via serial port.
API
ATOMCANBase
- class base.atom_can.ATOMCANBase(*args, **kwargs)
Bases:
CANCreate an ATOMCANBase object
- Parameters:
UiFlow2 Code Block:

MicroPython Code Block:
from base import ATOMCANBase base_can = ATOMCANBase(0, (6, 5), ATOMCANBase.NORMAL, baudrate=1000000)
ATOMCANBase class inherits CAN class, See
hardware.CANfor more details.


