Arduino IDE 2.1.0.
Code: Select all#include <mcp_can.h>
#include <SPI.h>
MCP_CAN CAN0(10); // Set CS to pin 10
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
if (CAN0.begin(MCP_ANY, CAN_250KBPS, MCP_8MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!");
else Serial.println("Error Initializing MCP2515...");
CAN0.setMode(MCP_NORMAL);
}
//Motor
byte Motor=0x01; //
byte StartSpeed=0x01; //Soft/Fast start
byte MaxSpeed=0x28; //MaxSpeed 0F = 15km/h 14 = 20km/h 19 = 25km/h 1E = 30km/h 23 = 35km/h 28 = 40km/h 2D = 45km/h 32 = 50km/h
byte DirectStart=0x01; //0: kick to start, 1: thumb throttle
//Display
byte Unit=0x01; //0: mph, 1: km/h
byte Light=0x01; //0: off, 1: on, 2: blink
byte Display=0x01; //0: off, 1: on
byte TestDisp=0x00; //0: normal, 1: test display
byte Charger=0x01; //0: off, 1: Turning on the charger
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
byte NumberBytes[29] = { 8, 8, 8, 8, 7, 7, 8, 8, 2, 8, 2, 8, 8, 8, 8, 4, 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
unsigned long IDs[29] = { 0x02181606, 0x03FF1601, 0x03FF1602, 0x02FF2602, 0x05124609, 0x05124609, 0x02203606, 0x04FF3400, 0x05124500, 0x02FF2602, 0x05124501, 0x03FF1500, 0x03FF1501, 0x05124502, 0x05124503, 0x04FF3502, 0x05124504, 0x03FF1502, 0x03FF1503, 0x03FF1504, 0x05124611, 0x04FF3400, 0x02FF2602, 0x05124612, 0x05124613, 0x05124614, 0x03FF1601, 0x03FF1602, 0x03FF1400 };
byte MessageBytes[29][8] = {
{ Motor, StartSpeed, MaxSpeed, DirectStart, 0x01, 0x00, 0x00, 0x01 }, //1 Motor: 1.Enable Module, 2.StartSpeed , 3.MaxSpeed, 4.DirectStart Push away/direct start
{ 0x6E, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //2
{ 0xF2, 0x43, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00 }, //3
{ 0x98, 0x40, 0xEC, 0xDB, 0x09, 0xD1, 0x69, 0x0B }, //4
{ 0x03, 0x00, 0x03, 0x70, 0x03, 0xE8, 0x00, 0x00 }, //5
{ 0x03, 0x00, 0x03, 0xB8, 0x03, 0xCA, 0x00, 0x00 }, //6
{ Unit, Light, 0x00, Display, TestDisp, Charger, 0x00, 0x00 }, //7 Display: 1.Unit kmh/mph, 2.Light off/on/flash, 3.Reservation (Should be 0), 4.Display on/off, 5.Test display off/on, 6.Charger off/on
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //8
{ 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //9
{ 0xEE, 0xF8, 0xAA, 0xD3, 0x2C, 0x1C, 0xDF, 0x1F }, //10
{ 0x01, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //11
{ 0x00, 0x00, 0x00, 0xCE, 0x00, 0x00, 0x00, 0x00 }, //12
{ 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00 }, //13
{ 0x52, 0x50, 0x31, 0x33, 0x53, 0x32, 0x30, 0x41 }, //14
{ 0x00, 0x13, 0x09, 0x18, 0x00, 0x00, 0x00, 0x6A }, //15
{ 0x00, 0x6F, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00 }, //16
{ 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //17
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //18
{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //19
{ 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00 }, //20
{ 0x00, 0x64, 0x25, 0xFA, 0x00, 0x00, 0x21, 0x64 }, //21
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //22
{ 0x27, 0xF0, 0xD7, 0x53, 0x29, 0x3E, 0x33, 0x5B }, //23
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //24
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //25
{ 0x0F, 0x94, 0x05, 0x0F, 0x8C, 0x0A, 0x00, 0x08 }, //26
{ 0x6E, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //27
{ 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 }, //28
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } //29
};
void loop()
{
// send data: ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' = array of data bytes to send
for (int i = 0; i < 29; i++) {
byte sndStat = CAN0.sendMsgBuf(IDs[i], 1, NumberBytes[i], MessageBytes[i]);
if (sndStat == CAN_OK) {
Serial.println(IDs[i]);
} else {
Serial.println("Error Sending Message...");
}
//delay(100);
}
delay(500);
}
First you download the Arduino IDE program and download the mcp_can.h library.
Sketch can now be loaded and then the board can be connected. Atmel atmega328p Xplained mini can be selected as board. Then verify and upload. Now the board can be connected to the scooter.
Sorry for my English I'm from Germany.
It works with the 3 switches. You could still build the switches somewhere, but it would be best to use Arduino for it. You would probably need a relais board. The best way to do this is to program it over time. Since my knowledge of programming is not so good, it may take a while
But I still have a question, especially for those who have the ES400B/C. If I connect the charger to the charging port and just turn on the IoT, it works. But I don't know if the BMS is then also switched on. does anyone know more Or does anyone know how to check that without cutting open the battery? It also works without the IoT but you can see the status on the display.