Use an Angle Unit to control a Servo.
Keyword Search:Servo, Unit, Loop, Wait, Angle, Grove, Core, 180,
IntroductionIn the previous project I showed you a simple single servo project. In this example, I will show you how to use two servo's on one port.
AimThe aim of this project is to show you how to control a single unit using just the Angle Unit.
Apparatus- M5Stack Core,
- An M5Stack 180 degree servo,
- Grove Cable,
- Angle Unit,
- Internet enabled computer,
- Grove2servo adapter.
Connection of the hardware is relatively simple. The Angle unit is plugged into port B (the black port) and the servo is connected to port A (the red port) via a Grove2servo adapter and thats it for the hardware. In the photo I have added some additional Technic Lego parts just to make it easer to mount the servo and Angle unit as well as making the servo movement easer to see.
Important Note: Before powering up the M5Stack, make sure the angle unit is rotated all the way anti-clockwise to the 0 value position.
To program the Servo tester in UIFlow we use some very simple code.
First I have added a Servo Rotate to Degree block to set the initial position of the Servo to its 0 degree position to match the 0 position of the Angle Unit. Next I added the Loop block and a Label Block. The label block is used to show the value of the Angle Unit on the screen.
Next we add a Servo Rotate to Degree block to the loop and place a Get Angle Value block to the position value. The example code cannot be run at this point because the Servo Unit only has a movement range of 0 to 180 degrees but the Angle Unit has a value range of 0 to 1024. In order to make the ranges match we use a simple math block that takes the reading from the Angle Unit and decides its buy 5.6. the 5.6 value is the movement value of the Angle Unit (1024) divided by the movement range of the Servo Unit (180).
ResultsOn initial power up and run, the servo will rotate to its 0 position and 0.0 will be shown on the screen. When you start to rotate the Angle sensor there is a little pause before the servo moves as a result of the crude way the angle is calculated.
With this we can test to see how far a servo is out of alignment, check rotation or just to test if a servo works.
ConclusionThis was designed as a very basic guide and there are many possibilities that this can be expanded upon. I will leave those possibilities to you the reader to work work out but if you do make any interesting use from this, please share your design on the M5Stack Forums and Communities. You can even share on Twitter and Instagram using the #M5Stack hashtag.
Comments