Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for wiring #5

Open
kaangoksal opened this issue Sep 23, 2024 · 0 comments
Open

Documentation for wiring #5

kaangoksal opened this issue Sep 23, 2024 · 0 comments

Comments

@kaangoksal
Copy link

Can you add documentation on what hardware used? Especially for esp32 demo. I'm trying to make it work with arduino uno and mcp2515, so far couldn't figure it out.

I used this code

#include <SPI.h>
#include <mcp_can.h>

const int SPI_CS_PIN = 10;
MCP_CAN CAN(SPI_CS_PIN);

void setup() {
  Serial.begin(115200);
  
  while (CAN_OK != CAN.begin(MCP_ANY, CAN_1000KBPS, MCP_8MHZ)) {
    Serial.println("CAN BUS initialization failed, retrying...");
    delay(100);
  }
  Serial.println("CAN BUS initialized successfully");
}

void sendCanMessage(byte* data, int length) {
  CAN.sendMsgBuf(0x070, 0, length, data);
  delay(10); // Small delay to ensure message is sent
}

void loop() {

  Serial.println("Sending commands");
  // Enter "AT command mode"
  byte atCommand[] = {0x41, 0x54, 0x2b, 0x41, 0x54, 0x0d, 0x0a};
  sendCanMessage(atCommand, sizeof(atCommand));
  delay(100); // Wait for command to be processed

  Serial.println("Switched to at mode!");
  // Rotate the motor forward for 1 second
  byte forwardCommand[] = {0x41, 0x54, 0x90, 0x07, 0xeb, 0xfc, 0x08, 0x05, 0x70, 0x00, 0x00, 0x07, 0x01, 0x95, 0x54, 0x0d, 0x0a};
  sendCanMessage(forwardCommand, sizeof(forwardCommand));
  delay(1000);

  // Stop the motor for 1 second
  byte stopCommand[] = {0x41, 0x54, 0x90, 0x07, 0xeb, 0xfc, 0x08, 0x05, 0x70, 0x00, 0x00, 0x07, 0x00, 0x7f, 0xff, 0x0d, 0x0a};
  sendCanMessage(stopCommand, sizeof(stopCommand));
  delay(1000);

  // Rotate the motor backward for 1 second
  byte backwardCommand[] = {0x41, 0x54, 0x90, 0x07, 0xeb, 0xfc, 0x08, 0x05, 0x70, 0x00, 0x00, 0x07, 0x01, 0x6a, 0xaa, 0x0d, 0x0a};
  sendCanMessage(backwardCommand, sizeof(backwardCommand));
  delay(1000);

  // Stop the motor for 1 second
  sendCanMessage(stopCommand, sizeof(stopCommand));
  delay(1000);

  // Wait before repeating the sequence
  delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant