Code to test SMC02B / 30052 with a Stamp


After pulling my hair out and spending fruitless hours searching the web for a good example of how to use the Parallax #30052 / SMC02B Pololu controller I gave up and created my own.

Maybe it will help someone down the road.

The attached file will quickly test a pair of DC motors connected to a Stamp and also (I hope) explain the commands and operation of the motor controller.

Pololu SMC02B (2.34 KB)

Have fun,


Thanks for sharing. Have you seen our Basic LEGO Robot sample project? It uses the micro dual serial motor controller with a BS2.

I didn’t look at all of your code, but I noticed that you indicate that the second byte in the protocol is for single or dual motor mode; that is not correct. The second byte is always 0, unless you want to reconfigure the motor controller for single motor mode or change the motor numbers it responds to, in which case the device type byte is 2.

- Jan

Hi Jan,

No, I had no idea and after searching for hours was thinking I would not find any examples. So I will check that link out and thanks for the correction.



I dont mean to be dense but I am trying to hook up a motor in single motor mode. I read that if this is not set correctly and you hook up wiring for single motor you could damage the controller.

Are the following the right commands for the basic stamp?

SEROUT 0,84,[$80, 2, 0, speed] "reverse at speed"
SEROUT 0,84,[$80, 2, 1, speed] “forward at speed”




The serial command sequences you wrote for controlling the motor are not correct. You need to configure the motor controller for one-motor mode before you use it.

Since the motor controller defaults to two-motor mode, you need to send a configuration command to change it to one-motor mode. The serial configuration protocol is described on page 7 of the User’s Guide (The User’s Guide is available for download on the resources tab of the product page.). The three-byte sequence that puts the motor controller in one-motor mode is:

[128, 2, 64]

The configuration is a one-time operation you should do with a separate program so you don’t run it over and over. Once it is configured correctly, the control commands look the same as in two-motor mode.

Please take a look at the “Using the Motor Controller” section on page eight of the User’s Guide which explains how to send serial commands to the motor controller. The second byte of the four-byte command should always be 0x00. (A second byte of 2 is used only for motor controller configuration commands.) The correct four-byte commands for controlling the motor are:

[128,0,0,speed] //reverse
[128,0,1,speed] //forward

- Ryan


Thank you so much for this. I had read the documentation over and over and just was not getting it.