The SparkFun AST-CAN485 IO Shield is an electronic component designed to facilitate communication between a microcontroller, such as an Arduino, and devices using the CAN (Controller Area Network) protocol. This shield operates at 24V, making it suitable for industrial applications where higher voltage levels are common. It is an ideal choice for automotive systems, home automation, and other projects requiring robust communication between various electronic devices.
Pin Number | Description | Notes |
---|---|---|
1 | CAN_H | CAN High |
2 | CAN_L | CAN Low |
3 | GND | Ground |
4 | V+ (24V) | Supply Voltage |
5 | NC | Not Connected |
6 | NC | Not Connected |
7 | Digital IO | Configurable digital input/output |
8 | Analog Input | Analog sensor input |
Q: Can I use this shield with a 5V Arduino? A: Yes, the shield is compatible with 5V Arduinos, but the CAN network operates at 24V.
Q: How do I program the Arduino to communicate over CAN?
A: You will need to use a CAN library for Arduino, such as the MCP_CAN
library, to handle the CAN communication.
Q: What is the maximum length for the CAN bus wiring? A: The maximum length depends on the baud rate; for lower baud rates, longer lengths are possible. Typically, up to 40 meters at 1 Mbps is acceptable.
#include <mcp_can.h>
#include <SPI.h>
// Initialize CAN controller at CS pin 10
MCP_CAN CAN0(10);
void setup() {
Serial.begin(115200);
// Initialize CAN controller at 500 kbps
if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) {
Serial.println("CAN controller initialized");
} else {
Serial.println("CAN controller initialization failed");
}
// Set normal operation mode
CAN0.setMode(MCP_NORMAL);
}
void loop() {
// Check for incoming messages
if (CAN0.checkReceive() == CAN_MSGAVAIL) {
unsigned char len = 0;
unsigned char buf[8];
// Read data: len = data length, buf = data byte(s)
CAN0.readMsgBuf(&len, buf);
// Print received message
for (int i = 0; i < len; i++) {
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println();
}
}
Note: This example assumes the use of the MCP_CAN
library for handling CAN communication. Ensure that the library is installed in your Arduino IDE before compiling and uploading the code to your microcontroller.