Serial communication w/ Micro dual serial motor control & Javelin
payala159
Posts: 4
Hello All,
I'm fairly new to the javelin stamp (or any stamp for that matter).· I have some experience w/ Basic and C, but I'm being forced to work on the Javelin which works off of java...· I familiar w/ reading java, but not writing.· Any way, I purchased a micro dual serial motor controller from pololu that will control 2 independant motors.· I'm stuck as to how I can send the data from the Javelin in the format that the serial control likes.· I found a great program example off of the Motor controller's user guide, but it's written for the BASIC Stamp.· The only thing that I would need to add to this program is an extra motor.· Can someone help me convert this to java for the javelin?· Also, how would I talk to the other motor?· Do i need to use UART? Thanks!!!
speed var byte
high 14· ·'take serial line high
low 15··'reset motor control
high 15
pause 100·'motor controller start up time
for speed = 0 to 127
·serout 14,84,[noparse][[/noparse]$80,0,0,speed]
·pause 20
next
for speed = 127 to 0
·serout 14,84,[noparse][[/noparse]$80,0,0,speed]
·pause 20
next
for speed = 0 to 127
·serout 14,84,[noparse][[/noparse]$80,0,1,speed]
·pause 20
next
for speed = 127 to 0
·serout 14,84,[noparse][[/noparse]$80,0,1,speed]
·pause 20
next
I'm fairly new to the javelin stamp (or any stamp for that matter).· I have some experience w/ Basic and C, but I'm being forced to work on the Javelin which works off of java...· I familiar w/ reading java, but not writing.· Any way, I purchased a micro dual serial motor controller from pololu that will control 2 independant motors.· I'm stuck as to how I can send the data from the Javelin in the format that the serial control likes.· I found a great program example off of the Motor controller's user guide, but it's written for the BASIC Stamp.· The only thing that I would need to add to this program is an extra motor.· Can someone help me convert this to java for the javelin?· Also, how would I talk to the other motor?· Do i need to use UART? Thanks!!!
speed var byte
high 14· ·'take serial line high
low 15··'reset motor control
high 15
pause 100·'motor controller start up time
for speed = 0 to 127
·serout 14,84,[noparse][[/noparse]$80,0,0,speed]
·pause 20
next
for speed = 127 to 0
·serout 14,84,[noparse][[/noparse]$80,0,0,speed]
·pause 20
next
for speed = 0 to 127
·serout 14,84,[noparse][[/noparse]$80,0,1,speed]
·pause 20
next
for speed = 127 to 0
·serout 14,84,[noparse][[/noparse]$80,0,1,speed]
·pause 20
next
Comments
import stamp.core.*;
public class Pololu_DualSerialMotor_ test {
· static final int resetPin = CPU.pin15;
· static final int txPin = CPU.pin14;
· static Uart txUart = new Uart(Uart.dirTransmit,txPin,Uart.invert,Uart.speed9600,Uart.stop1);
· static void main() {
··· int speed;·//speed var byte
····//high 14· ·'take serial line high
··· CPU.writePin(resetPin,false); //low 15··'reset motor control
··· CPU.writePin(resetPin,true); //high 15
··· CPU.delay(1050); //pause 100·'motor controller start up time
··· for (speed=0; speed<128; speed++) { //for speed = 0 to 127
····· txUart.sendByte(0x80);· //serout 14,84,[noparse][[/noparse]$80,0,0,speed]
····· txUart.sendByte(0x00);
····· txUart.sendByte(0x00);
····· txUart.sendByte(speed);
····· CPU.delay(210); //pause 20
··· }·//next
··· for (speed=127; speed>=0; speed--) { //for speed = 127 to 0
····· txUart.sendByte(0x80);· //serout 14,84,[noparse][[/noparse]$80,0,0,speed]
····· txUart.sendByte(0x00);
····· txUart.sendByte(0x00);
····· txUart.sendByte(speed);
····· CPU.delay(210); //pause 20
··· }·//next
··· for (speed=0; speed<128; speed++) { //for speed = 0 to 127
····· txUart.sendByte(0x80);· //serout 14,84,[noparse][[/noparse]$80,0,1,speed]
····· txUart.sendByte(0x00);
····· txUart.sendByte(0x01);
····· txUart.sendByte(speed);
····· CPU.delay(210); //pause 20
··· }·//next
··· for (speed=127; speed>=0; speed--) { //for speed = 127 to 0
····· txUart.sendByte(0x80);· //serout 14,84,[noparse][[/noparse]$80,0,1,speed]
····· txUart.sendByte(0x00);
····· txUart.sendByte(0x01);
····· txUart.sendByte(speed);
····· CPU.delay(210); //pause 20
··· }·//next
··· while (true) { //keep javelin alive
··· }
· }
}
You have to check baudrate and mode in the basic stamp help file. Mode can be true (Uart.dontInvert)
or inverted (as entered) for the basic stamp the program was written for.
Save file as Pololu_DualSerialMotor_test.java
regards peter
·
-Rosie
Thanks again for all your help!
so you could try to change the uart declaration to
static Uart txUart = new Uart(Uart.dirTransmit,txPin,Uart.dontInvert,Uart.speed9600,Uart.stop1);
and see if that resolves that issue. If it appears not to work at all, change it back.
regards peter
·