Go Down

Topic: Arduino to Jrk motor controller with SoftSerial (Read 1 time) previous topic - next topic

Jswan

Hello,
 I am new to programming and I am trying to send  high resolution speed values to a motor jrk motor controller from an arduino.
I need to send the target value is in hex from 0-4095 over serial using the SoftSerial library. I am not sure how to do this in the Arduino programming language. I would appreciate any help on this topic.




Below is an example tha I pulled from the Pololu JRK user guide.


Pololu protocol, hex: 0xAA, device number, 0x40 + target low 5 bits, target high 7 bits


Here is some example C code that will generate the correct serial bytes, given an integer "target" that holds the
desired target (0-4095) and an array called serialBytes:
serialBytes[0] = 0xC0 + (target & 0x1F); // Command byte holds the lower 5 bits of target.
serialBytes[1] = (target >> 5) & 0x7F; // Data byte holds the upper 7 bits of target.

PaulS

Once you have the two bytes (in serialBytes), use NewSoftSerial::print(serialBytes[n], BYTE); twice to send the two bytes (with n=0 then n=1).

Go Up