Setting High Resolution speed from Arduino to JRK

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.

How do I convert target value from 0-4095 to target low 5 bits, target high 7 bits the in the Arduino programming language? I don’t understand the C example that was provided in the user guide.

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


Even though Arduino advertises itself as a language, it is actually just C++ with some libraries and some preprocessing to make it easier to use. Almost all valid C code will work in C++, so you should be able to use the example code provided in the Jrk user’s guide in section 4.e (Motor Control Commands) to generate the two serial bytes. These bytes can then be passed to NewSoftSerial with the appropriate NewSoftSerial function (make sure you use a function that actually sends raw bytes, not ASCII).

What don’t you understand about the example C code provided? Every operator used in that code is a standard C operator which you can read about on the web, and also they are all documented in the “Arduino Language (C++) Reference”. You’ll also have to learn about arrays in C++, and Arduino has documentation about arrays.


Thanks so much for your help. You guys offer the best customer support of any company!!
I started learning about robotics with the 3Pi robot and I appreciate you guys helping out
beginners. You have made a lifetime customer.

Also I was able to make the code for an Arduino to send high resolution commands to the JRK. I thought posting this example code would be helpful to someone who was looking at this post.

#include <NewSoftSerial.h>

NewSoftSerial softSerial(4,5);

int target = 2500;  // this is the target speed  that I want for the jrk motor controller. 

byte serialBytes[2]; // declare an array for the speed command

void setup()

  // set the data rate for the SoftwareSerial port

  pinMode(4, INPUT);
  digitalWrite(5, HIGH); // keeps pololu board from getting spurious signal
  pinMode(5, OUTPUT);

void loop()

  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.  

  //0xAA, device number, 0x40 + target low 5 bits, target high 7 bits

  //Send a Pololu Protocol command
  softSerial.print(0xAA,BYTE);     //start byte
  softSerial.print(0x0B,BYTE);     //device id
  softSerial.print(0x40,BYTE);     //command number
  softSerial.print(serialBytes[0], BYTE); //speed 
  softSerial.print(serialBytes[1], BYTE); //speed



Thank you for the kind words, and thank you for sharing your code with us.

- Ben