chipKIT® Development Platform

Inspired by Arduino™

SoftSerial library problem for pololu simple motor driver

Created Fri, 12 Oct 2012 12:00:17 +0000 by merto85


merto85

Fri, 12 Oct 2012 12:00:17 +0000

Hi folks,

I have a trouble with SoftSerial library. I have been trying tho communicate with Pololu Simplme motor driver 24v12 via serial port according to the reference design on Pololu website but everytime i try to compile the sketch on mpide 0023 it gives the following error message:

In function 'void exitSafeStart()': error: 'class SoftwareSerial' has no member named 'write'

so far i have searched so much sites but I was not able to find a cure for my problem. Any suggestions for the problem.

P.S: The project is carried out on Max 32 board


EmbeddedMan

Fri, 12 Oct 2012 12:50:09 +0000

This error happens because you are using example code from an Arduino 1.0 sketch. Our libraries have not yet been fully converted to Arduino 1.0 format, and so you have to use print() with SoftwareSerial rather than write().

Why don't you post your sketch and I can modify it for you so it runs under the current version of MPIDE.

*Brian


merto85

Fri, 12 Oct 2012 12:55:51 +0000

Thank you for the reply. Sorry I fotgot to post the sketch. Actually the sketch belongs to pololu. Here is the sketch:

#include <SoftwareSerial.h> #define rxPin 3 // pin 3 connects to smcSerial TX (not used in this example) #define txPin 4 // pin 4 connects to smcSerial RX SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);

// required to allow motors to move // must be called when controller restarts and after any error void exitSafeStart() { smcSerial.write(0x83); }

// speed should be a number from -3200 to 3200 void setMotorSpeed(int speed) { if (speed < 0) { smcSerial.write(0x86); // motor reverse command speed = -speed; // make speed positive } else { smcSerial.write(0x85); // motor forward command } smcSerial.write(speed & 0x1F); smcSerial.write(speed >> 5); }

void setup() { // initialize software serial object with baud rate of 19.2 kbps smcSerial.begin(19200);

// the Simple Motor Controller must be running for at least 1 ms // before we try to send serial data, so we delay here for 5 ms delay(5);

// if the Simple Motor Controller has automatic baud detection // enabled, we first need to send it the byte 0xAA (170 in decimal) // so that it can learn the baud rate smcSerial.write(0xAA); // send baud-indicator byte

// next we need to send the Exit Safe Start command, which // clears the safe-start violation and lets the motor run exitSafeStart(); // clear the safe-start violation and let the motor run }

void loop() { setMotorSpeed(3200); // full-speed forward delay(1000); setMotorSpeed(-3200); // full-speed reverse delay(1000); }

Thanks in advance


merto85

Fri, 12 Oct 2012 12:58:06 +0000

And also the source of the sketch :

http://www.pololu.com/docs/0J44/6.7.1


EmbeddedMan

Fri, 12 Oct 2012 16:11:30 +0000

OK, I don't have the exact same hardware as you do (the motor controller), but I've converted all write calls to print calls, and it compiles and downloads properly on my MAX32 board. Can you try out the code below to see if it actually runs the motor controller properly?

*Brian

#include &lt;SoftwareSerial.h&gt;
#define rxPin 3 // pin 3 connects to smcSerial TX (not used in this example)
#define txPin 4 // pin 4 connects to smcSerial RX
SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);

// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart()
{
smcSerial.print(0x83);
}

// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed)
{
if (speed &lt; 0)
{
smcSerial.print(0x86); // motor reverse command
speed = -speed; // make speed positive
}
else
{
smcSerial.print(0x85); // motor forward command
}
smcSerial.print(speed &amp; 0x1F);
smcSerial.print(speed &gt;&gt; 5);
}

void setup()
{
// initialize software serial object with baud rate of 19.2 kbps
smcSerial.begin(19200);

// the Simple Motor Controller must be running for at least 1 ms
// before we try to send serial data, so we delay here for 5 ms
delay(5);

// if the Simple Motor Controller has automatic baud detection
// enabled, we first need to send it the byte 0xAA (170 in decimal)
// so that it can learn the baud rate
smcSerial.print(0xAA); // send baud-indicator byte

// next we need to send the Exit Safe Start command, which
// clears the safe-start violation and lets the motor run
exitSafeStart(); // clear the safe-start violation and let the motor run
}

void loop()
{
setMotorSpeed(3200); // full-speed forward
delay(1000);
setMotorSpeed(-3200); // full-speed reverse
delay(1000);
}

merto85

Wed, 17 Oct 2012 09:15:23 +0000

Hey Brian

It has been awhile to answer you on tryin' the sketch on real time system. Unfortunately it did not work altough replace the "write" commands with "print".

It does not give an error on MAX 32 but not command the motor driver. I think the problem is related with the library file because it has written in form of ATMEL. I mean the registers, pin numbers are different than the PIC32 ones. I can work with Arduino MEGA 2560 properly but in my studies I need more speed. 32 bit is quiet better than 8 bit you know. You or anyone got suggestions how to overcome this problem. Thanx lot.

Mert from Turkey


EmbeddedMan

Wed, 17 Oct 2012 15:09:50 +0000

Mert,

I looked through the library file a little bit, and it didn't look like it was accessing AVR registers. Can you point me to where in the library it looks like it uses AVR specific things? Maybe I can easily convert the library for chipKIT.

*Brian


ajitnayak

Mon, 19 Nov 2012 08:46:17 +0000

how can download softwareSerial lib for the MPIDE 023 ide


gamini

Sat, 26 Jan 2019 02:22:22 +0000

I know I am responding to an old thread.

I was told by Pololu " If you want to have separate functions for sending the exit safe start command to each controller like that, you should give them unique names."

Is that like this?

[code] motor1.exitSafeStart(); motor2.exitSafeStart(); motor3.exitSafeStart();

[\code]

Or like this?

[code] exitSafeStart(motor1); exitSafeStart(motor2); exitSafeStart(motor3); [\code]

I can get one motor (device #13) to work with

[code] #include <SoftwareSerial.h> #define rxPin 3 // pin 3 connects to smcSerial TX
#define txPin 5 // pin 5 connects to smcSerial RX SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);

// required to allow motors to move // must be called when controller restarts and after any error void exitSafeStart() { smcSerial.write(0xAA); //This lets all of the attached devices know that this is the start of a Pololu protocol command packet smcSerial.write(0x0D); //This lets device number 13 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command) smcSerial.write(0x03); //This is the specific command to tell the addressed device to exit safe-start }

[\code]

I am trying to get the second motor (device #13) to work

Thank you


EmbeddedMan

Sat, 26 Jan 2019 19:47:20 +0000

gamini,

What chipKIT board are you using? Most of them have more than one hardware UART - which may save you quite a bit of trouble (SoftwareSerial is fine for some things, but a real PITA for most)

*Brian