SyRen application note
Using a SyRen with a Basic Stamp II microcontroller
The Basic Stamp II is a popular microcontroller for beginners and is
often sold in stores as part of intro to robotics kits. Using one, you
can digitally control the direction and throttle on your robot.
To connect your BS2 to a SyRen, please follow this wiring diagram:
Note that for the sake of this example, we have used I/O pin1 on the
BS2 for motor control. You can use another pin if you want. We are also
using the internal voltage regulator on the SyRen to directly power the
BS2 with 5V simply because it makes wiring a little easier.
Next, set the DIP switches on your SyRen to the following:
This is the setting for R/C mode, with failsafe timeout disabled. If
you are using lithium batteries, you can flip switch 3 to enable the
low voltage cutoff.
We will be using the PULSOUT command on the Basic Stamp II to
simulate a radio control receiver. It will send out pulses with widths
corresponding to different states of throttle.
Note that this code is specific to the Basic Stamp II, because
different Basic Stamps have different pulse durations for the same
PULSOUT command. For example, if you are using a BS2sx or a BS1, you
may have to scale the timing.
You can download the source code here, or just copy and paste it from below.
' {$STAMP BS2}
' {$PBASIC 2.5}
SyRen PIN
1
' I/O Pin 1 is connected to S1 on SyRen
throttle VAR Word ' throttle variable used later on in loop
PAUSE
500
'wait for everything else to start up
'---speed and direction control------------
PULSOUT SyRen, 500 'full reverse: 1000us pulse width
PAUSE
1000
'stay at full reverse for a moment
PULSOUT SyRen, 625 'half throttle reverse: 1250us pulse width
PAUSE 1000
PULSOUT SyRen, 750 'complete stop: 1500us pulse width
PAUSE 1000
PULSOUT SyRen, 875 'half throttle forwards: 1750us pulse width
PAUSE 1000
PULSOUT SyRen, 1000 'full forward: 2000us pulse width
PAUSE 1000
PULSOUT SyRen, 750 'stop
PAUSE
1000
'stay stopped for a second
'---slow ramping of throttle------------------
' go from stopped to full forwards
FOR throttle = 0 TO 250
PULSOUT SyRen, 750 + throttle '750 is the neutral point, then add the throttle for forwards
PAUSE
10
' wait 10ms before the next change in speed
NEXT
PAUSE
1000
'stay at full forwards for a second
' go from stopped to full reverse
FOR throttle = 0 TO 250
PULSOUT SyRen, 750 - throttle '750 is the neutral point, then subtract throttle for reverse
PAUSE
10
'wait 10ms before the next change in speed
NEXT
PAUSE
1000
'stay at full reverse for a second
PULSOUT SyRen, 750 'stop
STOP
Back to Dimension Engineering