This Python application demonstrates a CANopen master that communicates with the CANopen slave demo.
The application connects to a CANopen network and configures a slave node to:
- Read button states via TPDO1 (Transmit PDO from slave perspective)
- Control LEDs via RPDO1 (Receive PDO from slave perspective)
- Mirror button states to LEDs in real-time
- Python 3.x
canopenlibrary- SocketCAN interface (Linux) or compatible CAN adapter
Install dependencies using uv:
uv syncOr using pip:
pip install canopenWhen using pip it is recommend to create a virtual environment.
- Ensure your CAN interface is configured (e.g.,
can0for SocketCAN) - Run the application:
uv run python main.pyOr if using pip:
python main.py- Press the buttons - you should see the LED light up
- Press Ctrl+C to stop the application
While this example uses SocketCAN, the canopen library supports various CAN adapters. See the python-canopen documentation for other supported interfaces.
- Ensure the CAN interface is up:
ip link set can0 up type can bitrate 250000 - Verify the slave device is connected and powered
- Check that the EDS file path is correct