Dear Team,
I have purchased a Grid Localisation Sensor (GLS611) and we are trying to configure the sensor with Arduino Mega 2560 via CAN bus shield. We want to read the qr codes using this Sensor and Arduino.
The sensor uses CanOpen communication interface which can be directly connected to can shield and then to arduino.
The problem we are facing is that after connection with Arduino we are unable to get any data from the sensor when it scans the qr code.
We have gone through the google and search for the solution regarding the same but could not get any satisfactory answer.
We are mentioning the code for the same. Any help would be greatly appreciated.Use code tags to format code for the forum.
#include <SPI.h>
#include <mcp_can.h>
#define CAN_CS_PIN 10 // Chip Select pin for CAN controller
MCP_CAN CAN(CAN_CS_PIN); // Set CS pin for CAN controller
void setup() {
Serial.begin(115200); // Initialize Serial Monitor
while (!Serial); // Wait for serial port to connect
// Initialize CAN bus at 500kbps
if (CAN_OK == CAN.begin(CAN_500KBPS)) {
Serial.println("CAN BUS Shield init OK!");
} else {
Serial.println("CAN BUS Shield init failed");
while (1); // Halt if initialization fails
}
}
void loop() {
unsigned char len = 0;
unsigned char buf[8];
if (CAN_MSGAVAIL == CAN.checkReceive()) { // Check for received CAN message
CAN.readMsgBuf(&len, buf); // Read the message into buf
// Process received message (e.g., print it)
Serial.print("ID: ");
Serial.print(CAN.getCanId(), HEX); // Print message ID
Serial.print(" Data: ");
for (int i = 0; i < len; i++) {
Serial.print(buf[i], HEX); // Print message data
Serial.print(" ");
}
Serial.println();
}
}
Connections:
CAN BUS SHIELD CONNECTED TO ARDUINO MEGA
GLS WIRE----------------------------------------CAN BUS SHIELD
GREEN WIRE --------------------------------- CAN_H
WHITE WIRE ---------------------------------- CAN_L
GND --------------------------------------------- GND