[2021] Servo Winch Challenge! Micro:bit Car & IPad (IPhone) for Conquering Gravity
by hummingworks in Circuits > Remote Control
893 Views, 3 Favorites, 0 Comments
[2021] Servo Winch Challenge! Micro:bit Car & IPad (IPhone) for Conquering Gravity
A winch is a mechanical device used to wind the rope, and it is made of a spool attached to a crank. How can it be used and is it useful? Some examples of using winches are, elevators, wrecker trucks and sailing boats. In the field of robotics and off-road vehicle competitions, winches are often used for towing things.
Can we replicate a winch mechanism in electronics DIY? By using a continuous servo, we can powerfully wind the rope with the spool. Unlike ordinary servos with the internal potentiometer to control the rotating angle of its shaft, continuous servos can rotate 360 degrees, allowing the attached spool to wind the rope powerfully.
Can we code for a winch mechanism? If we use Microsoft MakeCode editor, we can use Servos extension blocks for easily maneuvering a continuous servo and we can replicate a winch! We will present how to set up micro:bit app on your iPad (iPhone), how to pair it with your micro:bit, and how to use Gamepad in the app for controlling a car with a winch! We will use Valenta micro:bit RC car and its winch mod parts.
In this tutorial, you can download ready-to-play MakeCode sample file and play immediately. Setting up the car is made simple. You can download official micro:bit app to your iPad (iPhone) and pair it with "receiver" micro:bit on the car. Micro:bit app has built-in Gamepad console. Pressing Gamepad button A, B, C or D will let the car go forward, backward, left or right. You can wind up and down the winch rope by pressing Gamepad button 1 or 2. Calibrate the steering by pressing Gamepad button 3 or 4.
This tutorial does not require coding at all. However, what's really fun is to reverse-engineer how it's running under the hood. If you want to discover more, you can further continue reading the following steps to go deeper in the knowledge. Good luck and have fun!
If you want to control your car using two (x2) micro:bits, please review this tutorial instead.
Supplies
iPad (iPhone)
We will use an iOS device (iPad or iPhone) in this tutorial. Make sure you've downloaded micro:bit app in the App store. Please check your device compatibility with the app for using Bluetooth.
Micro:bit
We will need one (x1) micro:bit for the receiver. We've tested and micro:bit version 1 (V1) and version 2 (V2) are working correctly.
Batteries
We recommend using new, single-use four (x4) 1.5V AA batteries for the car.
Car and Winch
We will need one (x1) Valenta off-roader micro:bit RC car. It is Lego technic compatible and equipped with two (x2) micro gear motors on the rear wheels and one (x1) steering servo based on Roberval balance arm mechanism.
You can also refer to the instruction for assembling the car.
Copying the Sample File to Micro:Bit
You can download MakeCode sample file (below) to your computer. This sample file is ready to play, and you can start playing immediately. This sample file can work with both micro:bit version 1 (V1) and version 2 (V2).
Please download Receiver.hex file below. Then, connect your computer and a micro:bit via USB cable. Drag and drop Receiver.hex file to the micro:bit and use this as "receiver" micro:bit. Once you've copied the sample file to the micro:bit, disconnect it from your computer.
Mount "receiver" micro:bit on the car and turn on the power switch on the motor controller. Now try pressing Gamepad button A, B, C or D. The car will run forward, backward, left or right.
By default, the steering is not always straight by the servo equipped in the car. If the steering is not straight ahead, try to calibrate it by pressing Gamepad button 3 or 4. If the steering is a little too right, press Gamepad button 3 several times to fix it to the left. If the steering is a little too left, press Gamepad button 4 several times to fix it to the right. Pressing either button will fix the steering angle by 2 degrees to the opposite side.
By pressing Gamepad button 1 or 2, you can wind up or down the string rope of the winch. Let's try climbing uphill using the winch!
Downloads
Installing the Winch to the Car
We will install the winch to Valenta micro:bit RC car.
The car is equipped with micro:bit based motor controller called Valenta Zero. It contains a small motor controller (DRV8833) for controlling two (x2) DC motors on the rear wheels. There are four (x4) input and output (I/O) pins P0, P1, P2 and P8 for connecting devices like servos. Each of P0, P1, P2, P8 pins have three pins, Signal (Yellow), Voltage (Red) and Ground (Black). Please check if they are connected correctly. These pins can operate at 3.3V or 5V (selectable) using the jumper switch, and please choose 5V for connecting the servo.
The winch is made of the continuous servo for winding the string rope. Let's use P1 pin for connecting the continuous servo in this tutorial. (The sample file uses P1 for connecting the continuous servo.) Use the pins and holes for interlocking the parts and mount the winch on the front of the car.
Micro:bit App and MakeCode Sample File
Setting up micro:bit app on your iPad (iPhone)
Please follow this tutorial's steps 2 through 12 for downloading, installing, pairing and setting up Gamepad on your iPad (iPhone).
Reviewing MakeCode sample code file
Please follow this tutorial's step 13 through 16 for adding required extensions, such as Bluetooth, Devices and Servos within MakeCode editor. Please also check how these blocks are constructed in the sample code file.
Coding Servo Winch Features
Now we will examine how to customize MakeCode sample file that we've developed in the previous tutorial, so now we could control the servo winch using iPad (iPhone).
Let's set up the actions for Gamepad button 1 and 2 such that
- by holding down Gamepad button 1, servo winch will unwind and on-board LEDs will turn on blue;
- by releasing Gamepad button 1, servo winch will stop unwinding and on-board LEDs will turn off;
- by holding down Gamepad button 2, servo winch will wind and on-board LEDs will turn on pink; and
- by releasing Gamepad button 2, servo winch will stop winding and on-board LEDs will turn off;
Let's set up the actions for Gamepad button 3 and 4 such that
- by pressing button 3, the steering will be fixed to the left by 2 degrees; and
- by pressing button 4, the steering will be fixed to the right by 2 degrees.
on gamepad button 1 down block
In Devices extension, you can find the block on gamepad button 1 down. This block is executed whenever you hold down Gamepad button 1 on your iPad (iPhone). When you hold down Gamepad button 1, let's turn on all the on-board LEDs "blue" and unwind the string rope by the servo winch. In Valenta extension, go to FireLed and drag and drop set LEDs to and choose "blue" for example. In Servos extension, drag and drop continuous servo P1 run at 50%. If you want to unwind faster, change it toward 100%. Make sure to plug the servo winch to the motor controller's P1 pins.
on gamepad button 1 up block
In Devices extension, you can find the block on gamepad button 1 up. This block is executed whenever you release Gamepad button 1 on your iPad (iPhone). When you release Gamepad button 1, let's turn off all the LEDs on-board and stop unwinding the string rope by the servo winch. In Valenta extension, go to FireLed and drag and drop clear all LEDs. In Servos extension, drag and drop stop servo P1.
on gamepad button 2 down block
In Devices extension, you can find the block on gamepad button 2 down. This block is executed whenever you hold down Gamepad button 2 on your iPad (iPhone). When you hold down Gamepad button 2, let's turn on all the on-board LEDs "pink" and wind the string rope by the servo winch. In Valenta extension, go to FireLed and drag and drop set LEDs to and choose "pink" for example. In Servos extension, drag and drop continuous servo P1 run at -50%. If you want to wind faster, change it toward -100%. Make sure to plug the servo winch to the motor controller's P1 pins.
on gamepad button 2 up block
In Devices extension, you can find the block on gamepad button 2 up. This block is executed whenever you release Gamepad button 2 on your iPad (iPhone). When you release Gamepad button 2, let's turn off all the LEDs on-board and stop winding the string rope by the servo winch. In Valenta extension, go to FireLed and drag and drop clear all LEDs. In Servos extension, drag and drop stop servo P1.
By default, the steering of your car is not always straight by the servo equipped in the car. If the car's steering is not straight ahead, you could calibrate it by pressing Gamepad button 3 or 4. Now let's define the functions to calibrate the steering of the car using Gamepad 3 and 4.
on gamepad button 3 down block
If the car's steering is a little too right, you can press Gamepad button 3 several times to fix it to the left. In Variable extension, drag and drop set center block and make it set center to center + 2. It means you could fix the steering to the left by 2 degrees. In Servos extension, drag and drop set servo P2 angle to center. This center has been updated to the left by 2 degrees.
on gamepad button 4 down block
If the car's steering is a little too left, you can press Gamepad button 4 several times to fix it to the right. In Variable extension, drag and drop set center block and make it set center to center - 2. It means you could fix the steering to the right by 2 degrees. In Servos extension, drag and drop set servo P2 angle to center. This center has been updated to the right by 2 degrees.
That's all! You can also customize the sample file to your own way. Have fun!