Hello everyone,
I'm working on a project where I'm trying to control a motor using an Arduino Mega 2560 board, a CAN-BUS Shield V2.0 from SEEED, and an Elegoo joystick. I'm new to Arduino and electronics, so any help or advice would be greatly appreciated.
For starters, I'm using the joystick to send signals to the Arduino which then sends commands to the motor via the CAN-BUS Shield. However, I'm having trouble getting the motor to move, even though I'm not getting any errors in my code.
Here's my setup:
Arduino Mega 2560 board
CAN-BUS Shield V2.0 from SEEED
Elegoo joystick
Motor
And here's my code:
I'm currently using the Serial monitor to test the joystick commands, but I'm not getting any response from the motor. I'm not sure if there's something wrong with my code or my hardware setup.
If anyone has any suggestions or advice on how to troubleshoot this issue, I would greatly appreciate it.
Thank you!
I'm working on a project where I'm trying to control a motor using an Arduino Mega 2560 board, a CAN-BUS Shield V2.0 from SEEED, and an Elegoo joystick. I'm new to Arduino and electronics, so any help or advice would be greatly appreciated.
For starters, I'm using the joystick to send signals to the Arduino which then sends commands to the motor via the CAN-BUS Shield. However, I'm having trouble getting the motor to move, even though I'm not getting any errors in my code.
Here's my setup:
Arduino Mega 2560 board
CAN-BUS Shield V2.0 from SEEED
Elegoo joystick
Motor
And here's my code:
Code:
#include <SPI.h>
#include <mcp_can.h>
MCP_CAN CAN(10);
void setup() {
Serial.begin(9600);
while (CAN_OK != CAN.begin(CAN_1000KBPS)) {
Serial.println("CAN BUS Shield init fail");
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
Serial.println("CAN BUS Shield init ok!");
}
void loop() {
if (Serial.available() > 0) {
int joystickValue = Serial.read();
if (joystickValue == 'u') {
CAN.sendMsgBuf(0x001, 0, 8, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00});
Serial.println("Joystick moved up");
} else if (joystickValue == 'd') {
CAN.sendMsgBuf(0x001, 0, 8, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00});
Serial.println("Joystick moved down");
} else {
Serial.println("Invalid joystick command");
}
}
}
I'm currently using the Serial monitor to test the joystick commands, but I'm not getting any response from the motor. I'm not sure if there's something wrong with my code or my hardware setup.
If anyone has any suggestions or advice on how to troubleshoot this issue, I would greatly appreciate it.
Thank you!