I'm communicating with a closed loop stepper motor via serial. Not problem at all sending standard commands. Now I would like to send a command that has a variable component.
The message I send typically takes the following format:
const byte MotorMoverewind[] = {0xe0, 0xfd, 0x82, 0x00, 0x00, 0xc3, 0x50, 0x72};
I'll break the message components down:
0xe0 - UART identifier
0xfd - Command ID
0x82 - direction and speed byte
0x00, 0x00, 0xc3, 0x50 - Number of steps
0x72 - checksum byte
I've bolded the four bytes i'm interested in. in the above example, the number of steps is 50000 (dec)
So, for an example, if my varying number of steps is 57648671 (dec), i'd like to create the string of bytes thus:
const byte MotorMoverewind[] = {0xe0, 0xfd, 0x82, 0x03, 0x6f, 0xa6, 0x1f, 0x96}
The number of steps will vary each time, so I can't just code a set of known values. Some guidance on the best way to achieve this would be appreciated.
I may have a follow-up question on how to resolve the checksum, but hopefully i'll be able to resolve that myself when I get to it. One step at a time.