Shop OBEX P1 Docs P2 Docs Learn Events
Serial communication w/ Micro dual serial motor control & Javelin — Parallax Forums

Serial communication w/ Micro dual serial motor control & Javelin

payala159payala159 Posts: 4
edited 2005-12-01 18:12 in General Discussion
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

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-30 20:22
    This is quite easy.

    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

    ·
  • payala159payala159 Posts: 4
    edited 2005-11-30 20:56
    thanks... I'll try it tonight and let you know the results

    -Rosie
  • payala159payala159 Posts: 4
    edited 2005-12-01 15:57
    It worked perfectly!... I added it to the java program that I was working on and all seemed well. The only problem I had was that I used a switch and created cases for "forward", "back", "Right", and "Left". If I did one case (i.e. forward), it would work perfectly, but once I started jumping around to different cases to move around an object, I noticed I had to type in the reset commands at the end of each case. It works great, but did I have to do this because of the baud rate/memory issue? I'm just curious.

    Thanks again for all your help!
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-01 17:05
    I checked the bs manual and 84 equals 9600 baud true mode
    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
    ·
  • payala159payala159 Posts: 4
    edited 2005-12-01 18:12
    Thats how I have it in my program.· I used dontInvert since I saw it used in other· controller programs.· It works as is though...· Since I'm still learning, its more important to have workinging code rather than efficient code.· Thanks again for your help! I, along w/ my grouop, greatly appreciate it.
Sign In or Register to comment.