Pages: [1]   Go Down
Author Topic: Interfacing Arduino with Pololu JRK21v3 help please!  (Read 1105 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello!

I'm trying to interface my arduino due with the jrk21v3 using the following code (software serial):

Code:
#include <SoftwareSerial.h>


SoftwareSerial mySerial(2,3); // 2 - tx, 3 - rx

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
  mySerial.begin(9600);


}
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
  mySerial.write(0xAA);     //start byte
  mySerial.write(0x0B);     //device id
  mySerial.write(0x40);     //command number
  mySerial.write(serialBytes[0]); //speed
  mySerial.write(serialBytes[1]); //speed



}

which is similar to the code from this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1283904250

and my jrk is configured to:
serial input, UART detect baud rate, device number 11,no CRC, with analog feedback.

when i use to USB to my computer, i can control the motor no problem, but then i connect the arduino to the JRK, the jrk does not respond to the arduinos serial command

could anyone help out? (unfortunately this is for a school project smiley-sad )

Thanks!
« Last Edit: March 07, 2012, 04:49:37 pm by Evz » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <SoftwareSerial.h>


SoftwareSerial mySerial(10, 11); // RX, TX

void setup() 
{
  Serial.begin(9600);
  mySerial.begin(9600);
 }

void loop()
{
  if (mySerial.available())
    Serial.write(mySerial.read());
 
    mySerial.println("11, 700");
 
}

This is what I have right now my jrk 21v3 moves and but doesn't move correctly I have mine set to at 9600 though. Have used the code off of pololus websight and it only makes jrk kind of freeks out it it moves a little then it stops then it moves and then stops every time a new loops starts.  I have tested this by adding a delay from 500 to 1000 to 5000 and the start and stops with this delap.  Why the pololu doesn't keeop moving is what I'm trying to figure out right now. 
Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2544
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
mySerial.println("11, 700");

That's eight bytes. 1/1/,/ /7/0/0 and a carriage return, or 0x31, 0x31, 0x2C, 0x20, 0x37, 0x30, 0x30, 0x0A which are the hexadecimal values for those ascii characters.
You probably want:

Code:
mySerial.print(11);
mySerial.print(700);

That would be three bytes, 0x0B, 0x02, 0xBC (although I'm not suggesting that that is a valid command for the JRK -- I have no idea). Don't forget that "println" adds a carriage return character at the end of the string as opposed to "print" which does not.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


You were defiantly right although at the time I didn't know what all that meant all I knew was that my JRK was moving, it was responding.  This is what I have now with the help of a friend of mine.  Use it if you like.  As of right now this works with the use or a pot tapped in to the analog AO right now it moves but its kind of jerky.  Maybe someone else can help figure this out. Please post your code if you figure something out.

Code:
#include <SoftwareSerial.h>
int AN0pin = A0;

SoftwareSerial mySerial(7, 8); // RX, TX

void setup() 
{
  // Open serial communications and wait for port to open:
  mySerial.begin(9600);
  Serial.begin(9600);
  //while (!Serial) {
   // ; // wait for serial port to connect. Needed for Leonardo only
  //}


  //Serial.println("11, 341");

  // set the data rate for the SoftwareSerial port
  //mySerial.begin(9600);
    loop();
}

void loop() // run over and over
{
  char Command[10]={0xAA,11,0x45,0xAF};
  int RawA2D;
  RawA2D=analogRead(AN0pin);
  while(1){ 
    RawA2D=analogRead(AN0pin);
   
    Command[2]=0xC0 + ((char)RawA2D & 0x1F);
    Command[3]=(char)((RawA2D>>5) & 0x7F);
    Serial.write(Command[2]);
    Serial.write(Command[3]);
    mySerial.write(Command[0]);
    mySerial.write(Command[1]);
    mySerial.write(Command[2]);
    mySerial.write(Command[3]);
  }
}


Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2544
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just need to smooth out your analogRead() somehow.

Code:
void loop() // run over and over
{
  static int lastRawA2D;

  char Command[10]={0xAA,11,0x45,0xAF};
  int RawA2D;
  RawA2D=analogRead(AN0pin);
  while(1){ 
    if (analogRead(AN0pin) > lastRawA2D) {
      RawA2D += 1;
    } else if (analogRead(AN0pin) < lastRawA2D) {
      RawA2D -= 1;
    }
    lastRawA2D = RawA2D;

    Command[2]=0xC0 + ((char)RawA2D & 0x1F);
[...]
Logged

Pages: [1]   Go Up
Jump to: