Using Javelin Stamp

I bought the Dual Serial Motor Controller. The code I’m converting from Basic Stamp 2 PBasic (cited in the manual), using pin 14:

for speed = 0 to 127
serout 14, 84, [$80, 0, 0, speed]
pause 20
next

The conversion:

static Uart serialLineUart = new Uart(Uart.dirTransmit, CPU.pin14, Uart.dontinvert, Uart.speed9600, Uart.stop8);
for(int i = 0; i < 128; i++) {
serialLineUart.sendByte(0x80);
serialLineUart.sendByte(0x00);
serialLineUart.sendByte(0x00);
serialLineUart.sendByte(i);}
}

Every now and then the motor will twitch but not move. Is the Java code sending what the Dual Serial Motor Controller is expecting? All constructive suggestions welcome.

Thanks!

Hello,

I suspect that you have power or noise problems. Can you tell us what your power setup is, and what kind of current your motors are drawing? In general, I’d recommend taking out the loop and sending a single command, perhaps beginning with a speed like 75, and seeing what the result is. Also, I’m not sure what happens when your program ends; it might be helpful to stick in an explicit infinite loop in case the module goes to sleep or something like that at the end of the program.

- Jan

Jan,

Thanks for the quick reply. I’m at a client site and can’t get to the source code until later. Until then, are those the 4 bytes that the controller is expecting? I figured that the $80 translates into (0x080) and so forth.

-bxg

Yes, $80 is 0x80, and the commands are four bytes long. The protocol is covered on pages 10-12 of the user’s guide.

- Jan

Jan,

The code:


import stamp.core.*;

public class TestEngines {

static Uart serialLineUart = new Uart(Uart.dirTransmit, CPU.pin7, Uart.dontInvert, Uart.speed9600, Uart.stop1);

public static void main() {
CPU.writePin(7, true);
CPU.writePin(8, false);
CPU.writePin(8, true);
CPU.delay(100);
for(int i = 0; i < 128; i++) {
serialLineUart.sendByte(0x80);
serialLineUart.sendByte(0x00);
serialLineUart.sendByte(0x01);
serialLineUart.sendByte(i);
System.out.println(i);
CPU.delay(20);
}
for(int i = 127; i > -1; i–) {
serialLineUart.sendByte(0x80);
serialLineUart.sendByte(0x00);
serialLineUart.sendByte(0x01);
serialLineUart.sendByte(i);
System.out.println(i);
CPU.delay(20);
}
System.out.println(“DONE!”);
}
}


9V battery powers the microcontroller (5V on-board regulator). 12V motors are using a 12V DC adapter. Ground from 12V adapter and VSS from the microcontroller both feed negative into the motor controller.

-bxg

If my problem is related to noise, should I introduce a diode between the controller and the motor?

bxg

Definitely not! (What do you think it would do?) Putting a diode in there would just prevent the motor from turning in one of the directions.

In general, your favorite component in the context of noise reduction should be the capacitor. You should make sure you have small (0.1 uF) caps across the motor leads and from each lead to the motor can. You can also add big capacitors to the power supplies, especially when using wall-wart type supplies, which aren’t very good (especially for motors).

- Jan

Here’s a small page we’ve written about dealing with motor noise:

pololu.com/docs/0J15/9

- Ben

Thanks guys. I’ll give it a shot.

bxg

update of course the second I ask for help I figure it all out… reset wasn’t actually happening, had to change the code from ‘CPU.writePin(7, true);’ to ‘CPU.writePin(CPU.pins[7], true);’ I changed the code below to show what was done in case anyone else finds this helpful. Thank you all for getting me started. update

I stumbled upon this forum post and purchased the pololu micro dual serial motor controller.

I tried the code below (looks very similar to whats above…) but the controller doesn’t respond.

I am using 6 rechargable AA batteries, which gives the controller 7.5V. The javelin stamp is working correctly and I have tried plugging the motor controller into multiple pins.

Any help with this would be greatly appreciated, thank you.

  • Moe

import stamp.core.*;

public class TestEngines {
static Uart serialLineUart = new Uart(Uart.dirTransmit, CPU.pin7, Uart.dontInvert, Uart.speed1200, Uart.stop1);
public static void main() {
CPU.writePin(CPU.pins[7], true);
CPU.writePin(CPU.pins[8], false);
CPU.writePin(CPU.pins[8], true);
CPU.delay(100);
for(int i = 0; i < 128; i++) {
serialLineUart.sendByte(0x80);
serialLineUart.sendByte(0x00);
serialLineUart.sendByte(0x00);
serialLineUart.sendByte(i);
System.out.println(i);
CPU.delay(1000);
}
for(int i = 127; i > -1; i–) {
serialLineUart.sendByte(0x80);
serialLineUart.sendByte(0x00);
serialLineUart.sendByte(0x00);
serialLineUart.sendByte(i);
System.out.println(i);
CPU.delay(1000);
}
System.out.println(“DONE!”);
}
}

update If i leave this on after the code has finished, it sometimes jerks the motor in one direction and slowly spins.