CAN Receiver
Introduction
This tutorial covers how to use the CAN (Controller Area Network) port on the NEXTuino BASE to receive data. CAN is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate without a host computer.
Prerequisites
- Installed Arduino IDE
- NEXTuino BASE board
Example Code
CAN Receiver Example on GitHub
Overview
The example initializes the CAN bus at 500 kbps and continuously checks for incoming CAN packets. When a packet is received, its details and data are printed to the Serial Monitor.
Key Functions
CAN.begin(speed)— Initializes the CAN bus at the specified speedCAN.parsePacket()— Checks for incoming packets and returns their sizeCAN.packetId()— Returns the ID of the received packetCAN.packetExtended()— Checks if the packet uses an extended IDCAN.packetRtr()— Checks if the packet is a Remote Transmission Request (RTR)CAN.read()— Reads a byte of data from the received packet
Step-by-Step Guide
Step 1: Set Up Your Environment
- Connect your NEXTuino BASE to your computer
- Open the Arduino IDE and select the correct board and port
Step 2: Understand the Code
Serial.begin(115200)— starts serial communication for debuggingCAN.begin(500E3)— initializes the CAN bus at 500 kbps- In
loop(),CAN.parsePacket()checks for incoming packets and prints their details
Step 3: Upload and Test
- Copy the example code into a new Arduino IDE sketch
- Upload to your NEXTuino BASE
- Open the Serial Monitor (115200 baud) to view output
Troubleshooting
- Verify CAN bus wiring and that all devices are properly connected
- Check baud rate and CAN bus speed settings match between devices
Conclusion
You now have a basic understanding of how to use the CAN port on the NEXTuino BASE to receive data, as a foundation for vehicle network or industrial automation applications.