Introduction
Connect a Thumbstick to a Bit Board and use it to control a 270˚ Servo.
Video Overview
Featured Document
-
-
We'll connect the Thumbstick with a Crazy Circuits Ribbon Cable using all four wires.
-
Plug the three-wire connector of the Crazy Circuits Ribbon Cable into the row with Pin 0 on the Bit Board. The wire colors should match the pin header colors, with S1 (yellow) going to the yellow pin.
-
Next, plug S2 (orange) into Pin 1. (S2 is separated from the three-wire connector to allow you to plug it into another row.)
-
To the Thumbstick plug - (black) into GND, + (red) into +5V; S1 (yellow) into VRx; S2 (orange) into SW.
-
We won't plug anything into VRy pin for this example.
-
-
-
The 270 Degree Servo Motor has a 3-wire connector on the end that can plug directly into the pins on the back of the Bit Board.
-
Make sure the Orange Wire from the servo is closest to the number 13 for the Pin 13 column.
-
Then the Brown Wire should be closest to the micro:bit (in the - row) and the Red Wire will be in the middle (the +5v row).
-
-
-
We used a 3D printed part we designed to hold the Thumbstick in place on a LEGO baseplate.
-
We attached two 2x4 LEGO Bricks to the bottom of the 3D printed holder to allow it to snap onto the LEGO Baseplate a bit easier.
-
Alternately you can try to use some LEGO bricks and some rubber bands to hold the sensor in place, or just hold it in your hand.
-
3D print your own Thumbstick Sensor Holder.
-
-
-
If you've never used a micro:bit before you'll want to check out this guide: Bit Board V2 Setup and Use
-
We're going to load the following code for our Thumbstick 270 Servo Sweep Half program: https://makecode.microbit.org/_dWu0JX568...
-
In the on start block we'll disable the LED matrix and set Pin 1 to pull up, as we'll attach this to the button on the Thumbstick.
-
In the forever loop we'll read analog Pin 0 and map the value from 512 to 1023 to a scale going from 90 to 0.
-
Note that we will also constrain the value we get between 0 and 90. Without this constraint any input lower than 512 would cause our low value to go higher than 90.
-
Yes, this is weird! The map does not restrict the values so when we go outside of our from low or from high settings those values will be used... potentially in unexpected ways. So constrain prevents that.
-
We will assign the value to the variable named angleVal and then move the servo (attached to Pin 13) to the appropriate value/angle.
-
After that we will check if the button is pressed, and if pressed move the servo to 180 degrees for one second.
-
-
-
Once the code is loaded it should start running immediately.
-
You can power the micro:bit via the USB cable you used to load the code or you can use a battery pack plugged into the Bit Board.
-
Move the Thumbstick left and the servo should not move. Move the Thumstick to the right and you should see the beam attached to the servo shaft move right.
-
Press the Thumbstick (button) down and the servo will go to the 180 degree position for one second.
-
Chapter 24 has a few notes on using 270 Servos with the Bit Board and some MakeCode limitations: CH24-A - Servo Sweep
-
-
-
Follow along with our recorded Live Stream!
-
(We'll add the video to this step after we do the stream!)
-
