Micro Maestro & Basic Stamp

I am new to the Pololu product line, so far so good. I picked up a SMC05a and Micro Maestro. The motor controller was easy, however I am stuck trying to figure out the how to get the lo-byte and hi-byte correct to control the Micro Maestro with the basic stamp.

I have successfully controlled the Micro Maestro based on the examples by passing the HEX included in the manual. It goes to 1500us as confirmed by the USB connection (BTW, being able to monitor the serial control from the uController on the USB is slick!!).

' {$STAMP BS2}
' {$PBASIC 2.5}

Motor           PIN     0

PAUSE 100
SEROUT Motor,84,[$AA]
PAUSE 100
SEROUT Motor,84,[$AA, 12, $04, 0, $70,$2e]  'set to 1500uS

Any help with the binary calculation in pBasic would be great. I have been reading this https://www.pololu.com/docs/0J40/all

Thanks
ms

Well, using C syntax, you need to be able to compute target & 0x7F and (target >> 7) & 0x7F. I do not know PBASIC at all, but I took a quick look at the manual just now, and I am wondering whether it is possible that you can just do it like this:

SEROUT Motor,84,[$AA, 12, $04, 0, target & 0x7F, (target >> 7) & 0x7F]

The variable target should be specified in units of 0.25us. Please do let me know whatever you get to work, and I will add it as an example in the User’s Guide!

-Paul

You should be able to figure out the bitshifting in basic, but if you can’t then you can alternatively use the simpler Mini-SSC II protocol described in the Serial Servo Commands section of the Maestro User’s Guide. Then you just need to have target be a number from 0 to 254 and send it as the last serial byte.

-David

Thanks Paul. I need to do some work on my bit math.

This is what I ended up with as a demo using the Basic Stamp2.

' {$STAMP BS2}
' {$PBASIC 2.5}

'Program to demo serial command of the Polou Micro Maestro servo controller
'1 servo hooked to Masestro line 0
'Servero performs a scan pattern of 0 to 90 to 180 to 90 to 0 repeat

controller      PIN     0
target          VAR     Word(4)
index           VAR     Nib

'servo positions in uS stored in array used in loop
'save memory by calculating before using byte vs word var type, following is demo use only
target(0) = 4 * 448    'servo position 0'
target(1) = 4 * 1337   ' 90'
target(2) = 4 * 2176   ' 180'
target(3) = 4 * 1337   ' 90'

'init Micro Maestro controller
PAUSE 100                    'allow controller startup
SEROUT controller,84,[$AA]   'allow baud to be determined
PAUSE 100

'Move servo through scan pattern stored in target
scan_pattern:

     FOR index = 0 TO 3
        SEROUT controller, 84,  [$AA, 12, $04, 0, target(index) & $7F, (target(index) >> 7) & $7F]
        PAUSE 500
     NEXT

     GOTO scan_pattern
END

Hope that helps someone else in the future! I am looking forward to working with some other Pololu products in the future!!!

-Matt Stemple