Help interfacing Arduino and JrK 21v3

Hi everyone,
I have a project and I want to control a Linear actuator, the LACT6P, according to values given by an accelerometer. So the accelerometer is connected to an arduino and the actuator is controlled by the JrK 21v3. The problem is how to interface the arduino and the motor controller.
I searched in many places over internet, found that a connection via serial is possible using the RX and TX inputs in boath board so here's what I made:
I connected the RX of the 21v3 to the TX (pine 1) of the arduino
I connected both GND of the 21v3 and the arduino
I selected UART detect baude rate in the configuration utility
I loaded this code I found on the forum to the arduino:

/*
* Motor control setup for pololu jrk21v3 with Arduino UNO R3, verified using linear actualtor LACT2P
*
* Pololu jrk config utility in Serial mode using UART detect baud rate interface. 
* starting with the default configuration settings for LACT2P linear actuators provided on the pololu website
*
* pin 8 connected to jrk pin Rx
* jrk grnd connected to arduino ground
*/


#include <SoftwareSerial.h>
SoftwareSerial mySerial(7,8); // RX, TX, plug your control line into pin 8 and connect it to the RX pin on the JRK21v3

int myTarget = 0; // target position, 0-4095 is the range of the JRK21V3 controller. 

//stuff used for input from pc
char buffer[5] ;
int pointer = 0;
byte inByte = 0;



// announcer for PC Serial output
void announcePos(int (position)) {
  Serial.print("positiion set to ");
  Serial.println(position);
  Serial.flush();
} 




//sets the new target for the JRK21V3 controller, this uses pololu high resulution protocal
void Move(int x) {
  word target = x;  //only pass this ints, i tried doing math in this and the remainder error screwed something up
  mySerial.write(0xAA); //tells the controller we're starting to send it commands
  mySerial.write(0xB);   //This is the pololu device # you're connected too that is found in the config utility(converted to hex). I'm using #11 in this example
  mySerial.write(0x40 + (target & 0x1F)); //first half of the target, see the pololu jrk manual for more specifics
  mySerial.write((target >> 5) & 0x7F);   //second half of the target, " " " 
}  




void setup()
{
  mySerial.begin(9600);
  Serial.begin(9600);
  Serial.println("Initialized");
  Serial.flush();// Give reader a chance to see the output.

  int myTarget = 0; //the health level at any point in time
  Serial.println("Enter '#' and 4 digit position level (#0000-#4095)");

}

    

void loop()
{

  if (Serial.available() >0) {
   // read the incoming byte:
   
   inByte = Serial.read();
   delay(10);
   
   // If the marker's found, next 4 characters are the position
   if (inByte == '#') {
   

     while (pointer < 4) { // accumulate 4 chars
        buffer[pointer] = Serial.read(); // store in the buffer
        pointer++; // move the pointer forward by 1
      }
      Serial.flush();
      //translating into an int
      myTarget=(buffer[0]-48)*1000+(buffer[1]-48)*100+(buffer[2]-48)*10+(buffer[3]-48);
      pointer =0;
   }
   
    
   //makes sure the target is within the bounds
   if (myTarget < 0){
      myTarget = 0;
      }
   else if (myTarget > 4095){
      myTarget=4095;
      }
      
   Move(myTarget);  
   announcePos(myTarget); 


  } 
}

when I load it to the arduino, there is a vibration in the actuator so it seems something happens, but when I open serial monitor and give values there is no reaction at all! Notice that the actuator works properly when I manually set target with the configuration utility.
Can you help me plz, I'm not familiar with this language to properly understand what's wrong with that code or make my own!

That's a pretty complex outfit, I have no idea, but:
There is a search box at the top of the page, "Search the Arduino forum", type in: jrk 21v3

What is a JrK 21v3 ? Post a link to its datasheet. Also post a link to the datasheet for the LACT6P.

...R

I agree with Robin2 about adding links to the items you're asking about.

I have a Jrk 21v3 but I haven't used it. I looked through the datasheet and the code you posted and I don't see any obvious problems.

Does the program announce back to you the position you entered into the terminal?

You mentioned using the Jrk 21v3 with a PC and it working correctly. When you send commands via the Arduino do you still have the PC connected to the Jrk 21v3?

It looks as if the Jrk 21v3 should be able to be connected to both the PC and the Arduino at the same time, but I'm not sure about this. If the PC was connected, you ought to try the program with the Jrk 21v3 disconnected from the PC.

DuaneDegn:
I have a Jrk 21v3 but I haven't used it.

Or told us what it is :slight_smile:

...R

Robin2:
Or told us what it is :slight_smile:

...R

I meant to add a link (not that it was my job to do so) but I forgot. It's there now.

The Jrk 21v3 is one of Pololu's small motor control boards. It has a MC33926 h-bridge chip and a PIC microcontroller. I've been interested in motor control and I wanted to see if I could duplicate the feature of the Jrk 21v3 so I added on to my last Black Friday sale purchases. I've had it for 11 months but I haven't used it yet.

The other device mentioned in the OP was the LACT6P linear actuator. I don't have one of these but they look pretty cool. The one thing I don't really like about the actuator is it uses a potentiometer for position feedback.

I personally don't like potentiometers for position feedback. Pots seem wear out much too fast for my liking. I prefer either optical encoders or some sort of magnetic encoder. I'm sure pots are used so frequently since they're so easy to use.

@sinisterdes, neither Robin2 or myself should have had to look for these devices. Please add links to devices you're asking about in the future.

Thank you @DuaneDegn - I had not intended that you should provide the links.

To respond to the OP ...

So the accelerometer is connected to an arduino and the actuator is controlled by the JrK 21v3. The problem is how to interface the arduino and the motor controller.

From what I can see the Jrk 21v3 requires a USB connection which means it cannot be controlled by an Arduino - unless, perhaps, by a Yun. A RaspberryPi may be another option.

Alternatively the actuator could probably be controlled with an Arduino and a different motor driver board.

...R

Robin2:
Thank you @DuaneDegn - I had not intended that you should provide the links.

I didn't think so. I intended to add a link to my earlier post since I knew what the device was. I think they're both interesting devices.

Robin2:
From what I can see the Jrk 21v3 requires a USB connection which means it cannot be controlled by an Arduino - unless, perhaps, by a Yun. A RaspberryPi may be another option.

The Jrk 21v3 has both a USB connection and a TTL connection.

This page kind of explains the serial connections.

I'm not sure how it all works but I'm almost positive the Jrk 21v3 can be controlled with a TTL connection from a microcontroller.

DuaneDegn:
The Jrk 21v3 has both a USB connection and a TTL connection.

That's the second time today I have got hold of the wrong end of the stick. Must be because I'm older than I was yesterday.

Thanks for the correction.

Would be nice to hear from the OP :slight_smile:

...R