Pages: [1] 2   Go Down
Author Topic: Help with programming a motor controller  (Read 1241 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd like to program a pololu low voltage dual serial motor controller with an arduino uno but i'm having problems.
Here's the link to the user guide

http://www.robotshop.com/PDF/smc05a-low-voltage-dual-serial-motor-controller-guide.pdf

and here's a link to the example they put up which i can't seem to get working

http://www.robotshop.com/gorobotics/articles/microcontrollers/how-to-make-a-robot-lesson-10-
programming-your-robot

does any one have any suggestions?
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

add debugging printouts
post exactly the sketch you're using
post exactly how you've wired it (plus picture if possible)
post exactly what it's supposed to do
post exactly what it does instead
Logged

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

For now my goal is just to make the wheel's move forward

void setup()
{}
void loop()
{
unsigned char buff[6];

buff[0]=0×80; //start byte specific to Pololu motor controller
buff[1]=0; //Device type byte specific to this Pololu controller
buff[2]=1; //Motor number and direction byte; motor one =00,01
buff[3]=127; //Motor speed “0 to 128″ (ex 100 is 64 in hex)

Serial.write(buff);
}

sketch_dec25a:6: error: stray '\' in program
sketch_dec25a.cpp: In function 'void loop()':
sketch_dec25a:6: error: expected `;' before 'u00d780'
sketch_dec25a:11: error: call of overloaded 'write(unsigned char [6])' is ambiguous
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:58: note: candidates are: virtual size_t HardwareSerial::write(uint8_t) <near match>
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Print.h:49: note:                 size_t Print::write(const char*) <near match>


* IMG_0918.JPG (1903.4 KB, 2592x1936 - viewed 12 times.)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
buff[0]=0×80; //start byte specific to Pololu motor controller
That's not an x between the 0 and the 8. I don't know what it is, except that it isn't an x.

Code:
Serial.write(buff);
needs to be:
Code:
Serial.write(buff, sizeof(buff));

Then, the code compiles.
Logged

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

She compiles beautifully but i've now encountered a new problem

Code:
processing.app.SerialException: Serial port 'COM3' already in use. Try quiting any programs that may be using it.
at processing.app.Serial.<init>(Serial.java:171)
at processing.app.Serial.<init>(Serial.java:77)
at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:77)
at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:172)
at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
at processing.app.Sketch.upload(Sketch.java:1706)
at processing.app.Sketch.exportApplet(Sketch.java:1662)
at processing.app.Sketch.exportApplet(Sketch.java:1634)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2346)
at java.lang.Thread.run(Thread.java:619)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, do what the message says.

Do you have any bluetooth devices connected to your computer, or any bluetooth software running?
Logged

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

I don't believe so ive got a wireless usb stick, mouse and keyboard which there were no conflicts
for the first couple of uploads. I tried reinstalling the drivers with no luck I'm stumped.
« Last Edit: December 29, 2012, 06:11:47 pm by frostking73 » Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is serial port 'COM3' the right port for your Arduino?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

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

'Com3' problem solved
http://arduino.cc/forum/index.php/topic,25541.0.html

Still no response from the motor controller though
The user manuals mentrions configuring the motor controller by sending a three-byte packet consisting of a start byte, a configuration command byte, and the new configuration byte

start byte=0x80 change configuration=0x02 new settings, 0x00-0x7F
 
how would i implement that into
Code:
void setup()
{
  Serial.begin(9600);
}
void loop()
{
unsigned char buff[6];

buff[0]=128; //start byte specific to Pololu motor controller
buff[1]=0; //Device type byte specific to this Pololu controller
buff[2]=1; //Motor number and direction byte; motor one =00,01
buff[3]=127; //Motor speed “0 to 128? (ex 100 is 64 in hex)

Serial.write(buff, sizeof(buff));
}
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pretty much as you have it there, but (1) the byte values that code sends do not match the sequence you described, (2) you could write the byte values as hex literals for clarity, since that's how they're specified (3) the buffer is bigger than needed for that message so you would be sending some uninitialised bytes at the end of the command. You should send the number of bytes in your message, and not the whole buffer if that is bigger. You don't actually need to use the buffer at all - you could just Serial.write((byte)0x80); etc to output each byte in sequence.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

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

Below is my best interpretation of the user guide found below
http://www.robotshop.com/PDF/smc05a-low-voltage-dual-serial-motor-controller-guide.pdf
I'm kinda hoping that someone could translate the user guide for me as I don't think I'm getting it.
Code:
void setup()
{
  Serial.begin(9600);
  pinMode(6,OUTPUT); //hoping this is the pin that will send serial data
  pinMode(3,OUTPUT); //hoping this is the pin that will reset the motor controller after
                                    configuration so that it can receive the four byte command
  
}
void loop()
{
  digitalWrite(3,HIGH);

 Serial.write((byte)0x80); // start byte
  Serial.write(2); //config byte
  Serial.write(2); //new config byte
  delay(1000);
  
digitalWrite(3,LOW); //after configuration the motor controller must be reset before you can     continue using it
  delay(1000);
  
  //The four-byte Motor controller command
Serial.write((byte)0x80); //start byte
Serial.write((byte)0x00); //device type
Serial.write(5); //Motor Number and direction see pic below
Serial.write(127); //Motor Speed 0-127
}


* Capture.PNG (13.05 KB, 325x254 - viewed 5 times.)
« Last Edit: December 30, 2012, 10:44:06 am by frostking73 » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The start byte is 0x80. That is 10000000 in binary. Since none of the data that follows ever has the high bit set, a byte that does have the high bit set defines the start of the command sequence.

The command to change the configuration is 0x02. Why you insist on switching bases is a mystery, but, in this case it doesn't matter.

The third byte defines what the new configuration is to be. The 6th bit of the byte defines the number of motors. You are sending 2 (= 0x02 = 00000010). The 6th bit is 0, which means that you are setting it up to control 2 motors. The remaining 6 bytes define the motor number. The directions regarding the motor number don't make sense to me. If appears that the configuration step applies to 2 motors, in two motor mode, not to a single motor. It also appears as though the numbering convention would allow you to control 32 motors. The driver is not capable of that, so why the protocol supports it is a mystery.

Since the configuration command is always three bytes, it is unclear why you are sending 4 bytes, or what you expect the 4th byte to do.

Are you resetting the controller after sending the config command? Does the appropriate LED blink on the controller?

Why are you sending the config command in loop()?

How is the controller connected to the Arduino? A high res picture is needed.
Logged

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

I made an edit of my previous post to try and explain the four byte command.

Q1. Yes that was my attempt to reset the motor controller after configuration, unfortunately
no LEDs are blinking on the controller.

Q2. It was a shot in the dark.

Q3. How it should be and how I've got it



* motor controller diagram.PNG (148.61 KB, 856x625 - viewed 12 times.)

* IMG_0920.JPG (2027.48 KB, 2592x1936 - viewed 11 times.)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's very difficult to tell from that picture if anything is connected to pin 1 of the Arduino. It appears, in fact, that the pin connected to the serial port of the motor controller is connected to pin 5 of the Arduino. That is NOT the pin that Serial talks to.
Logged

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

It most definitely was pin 6 but after your most recent post I changed the pin to 1TX.
I also took your advice and transferred the configuration data to set up.
No luck on any response from the motor controller though.
I've got 4 double A batteries hooked up there reading aprox 5.16v and 48ua if that helps.

Code:
void setup()
{
  Serial.begin(9600);
  pinMode(3,OUTPUT);
 
 // Three byte Configuration packet
 
  Serial.write((byte)0x80); // Start byte
  Serial.write(2); //Configuration byte
  Serial.write(2); //New settings comes in three parts
  //(bits 0-5: motor number)(bit 6: # of motors 1=1 0=2)(bit 7: always 0)
 
  // Reset process required in order to allow Four byte motor controller command to follow
  digitalWrite(3,HIGH);
  delay(1000);
  digitalWrite(3,LOW);
  delay(1000);
  digitalWrite(3,HIGH);
  }

void loop()
{
  //Four byte motor controller command
Serial.write((byte)0x80); //Start byte
Serial.write((byte)0x00); //Device type
Serial.write(5);// Motor number and direction comes in three parts
//(bit 0: 1=forward 0=reverse) (bits 1-6: motor number) (bit 7:always 0)
Serial.write(127);//Motor speed 0-127
}
Logged

Pages: [1] 2   Go Up
Jump to: