I have to communicate with a brushlesss motor controller (ADP 24S 200A) in order to get informations from it (voltage, RPM, temp, etc...). This ESC control a 20Kw motor for a paraglider.
The details of the protocol are detailed in the code
/*Data buffer format
0: Voltage Low
1: Voltage High
2: Temperature Low
3: Temperature High
4: Bus Current Low
5: Bus Current High
6: Reserved (Not Used)
7: Reserved (Not Used)
8: ERPM 1
9: ERPM 2
10: ERPM 3
11: ERPM 4
12: Throttle Duty Low
13: Throttle Duty High
14: Motor Duty Low
15: Motor Duty High
16: Reserved (Not Used)
17: Reserved (Not Used)
18: Fletcher Checksum Low
19: Fletcher Checksum High
20: Stop Byte Low
21: Stop Byte High
*/
and there is an example of a struct to hold that data
typedef struct {
// Voltage
int V_HI;
int V_LO;
// Temperature
int T_HI;
int T_LO;
// Current
int I_HI;
int I_LO;
// Reserved
int R0_HI;
int R0_LO;
// eRPM
int RPM0;
int RPM1;
int RPM2;
int RPM3;
// Input Duty
int DUTYIN_HI;
int DUTYIN_LO;
// Motor Duty
int MOTORDUTY_HI;
int MOTORDUTY_LO;
// Reserved
int R1_HI;
int R1_LO;
// checksum
int CSUM_HI;
int CSUM_LO;
} telem_t;```
To use the data you would read in 22 bytes and assign them to the struct as they arrive. The last 2 bytes read should both be 255 so if that is not the case then you know that reading is out of sync.
Once in the struct you can use the data to do whatever you want
For debugging while you're developing the software, I would choose an Arduino with multiple hardware serial ports like a Mega or one that does not use a serial port for communication with the PC (e.g. Leonardo, Micro, ...).
You can basically copy the code in the example in a sketch before the setup() function. You will have to modify the HandleSerial. E.g. if you use a global receive buffer, you don't have to pass it to the function. In loop, you must just make sure that you receive the 22 bytes before calling HandleSerial.
void HandleSerialData() {
if (buffer[20] != 255 || buffer[21] != 255) {
return; //Stop byte of 65535 not recieved
}
...
...
}
Oh, and I leave the puzzle with the 32bit value (ERPM) to you I suggest that you set Compiler warnings to All in file -> preferences in the IDE so you will see the warnings !!