Background:
I have two jrk21v3 firmware rev 1.3 connected up on a “shared” RX line coming out of an arduino. The TX lines from the jrk are not connected. One is set on device id “2”, the other “4”. They are using a pot for analog feedback and are responding properly over usb “manual” control. The PIDs are tuned and it in general seems happy. They are set to be hard coded at 9600baud.
Problem:
It seems that there is either something wrong with my code or a bug in the firmware… as both motor drives respond to commands regardless of the “device ID” I have them set to. Additionally, one of the devices “serial protocol error” bit is set, but it’s still responding to the commands.
Proof of concept:
I would expect this code to set one of the jrks to postition 100, and the other to position 1500. What’s really happening is that they both travel to position 100 and position 1500. Any ideas?
#include <SoftwareSerial.h>
#define rxPin 3
#define txPin 2
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
byte pinState = 0;
unsigned char focusbuff[6];
int focustarget = 0;
unsigned char zoombuff[6];
int zoomtarget = 0;
void setup() {
delay(50);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() {
focustarget = 100;
focusbuff[0] = 0xAA;
focusbuff[1] = 0x02;
focusbuff[2] = 0xC0 + (focustarget & 0x1F);
focusbuff[3] = (focustarget >> 5) & 0x7F;
for (int i=0; i<4; i++) {
mySerial.print(focusbuff[i],BYTE);
}
delay(3000);
zoomtarget = 1500;
zoombuff[0] = 0xAA;
zoombuff[1] = 0x04;
zoombuff[2] = 0xC0 + (zoomtarget & 0x1F);
zoombuff[3] = (zoomtarget >> 5) & 0x7F;
for (int i=0; i<4; i++) {
// mySerial.print(zoombuff[i],BYTE);
}
delay (3000);
}