Self-Aligning Satellite Dish in Rust: Pan Motor

ian_ndeda

Ian Ndeda

Posted on November 29, 2024

Self-Aligning Satellite Dish in Rust: Pan Motor

To pan the PTZ kit through 360°, one could simply use a servo motor that spans 360°. In that case, the code that drove the regular 180° servo could have been simply altered to enable the kit's pan. I, however, modified a 180° motor to become a regular DC motor by removing its electronic controller and connecting the power terminals directly.

Table of Contents

Requirements

  • 1 x SG90 Servo Motor

Implementation

Modifications

servo-mod

To modify the servo, you only need to bypass the control circuitry—the green PCB—and directly connect the DC motor's power lines to the input lines.

Note the orange control line will now be redundant.

This turns the servo into a geared DC motor.

Connections & Operation

To operate this modified motor, we'll need two relays to control it's direction of rotation.

moded-servo-connection

We'll have one line run from the positive terminal of the motor through a relay, Relay 1, and to either the 5V line of our circuit or the common connection depending on the action status of the relay.

The other line will similarly run from the motor's negative terminal through another relay, Relay 2. 

The normally on (NO) terminals of both relays will be connected to the 5V line, while the normally closed (NC) terminals are connected to the common line of the circuit.

Initially, both relays are OFF, and the servo experiences no movement as both its terminals are connected to the common line. Putting Relay 1 ON while 2 is OFF, however, causes clockwise movement in the motor as its positive terminal will be on the 5V line while the negative will be on the common.

Relay 1 OFF while Relay 2 is ON results in movement in a counterclockwise direction. All this is summarized in the table below:

Relay 1 Enable Relay 2 Enable Servo Movement
0 0 OFF
0 1 Counterclockwise
1 0 Clockwise
1 1 OFF

Relays

The relays are controlled by enable pins, which in our case will be connected to RP2040's GPIO pins. We'll configure these as gp16 and gp17 for Relay 1 and 2 enable terminals, respectively.

// Configure GP16 for Relay 1 Enable
pads_bank0.gpio(16).modify(|_, w| w
               .pue().set_bit()// pullup enable
               .pde().set_bit()// pulldown enable
               .od().clear_bit()// output enable
               .ie().set_bit()// input enable
               );

io_bank0.gpio(16).gpio_ctrl().modify(|_, w| w.funcsel().sio());// set function as sio

sio.gpio_oe().modify(|r, w| unsafe { w.bits(r.gpio_oe().bits() | 1 << 16)});// Output enable for pin 16

// Configure GP17 for Relay 2 Enable
pads_bank0.gpio(17).modify(|_, w| w
               .pue().set_bit()// pullup enable
               .pde().set_bit()// pulldown enable
               .od().clear_bit()// output enable
               .ie().set_bit()// input enable
               );

io_bank0.gpio(17).gpio_ctrl().modify(|_, w| w.funcsel().sio());// set function as sio

sio.gpio_oe().modify(|r, w| unsafe { w.bits(r.gpio_oe().bits() | 1 << 17)});// Output enable for pin 17
Enter fullscreen mode Exit fullscreen mode

Final Code

Rearranging our code so far we'll have this final copy.

In the next part we'll write an example application code that will continuously pan the PTZ kit.

💖 💪 🙅 🚩
ian_ndeda
Ian Ndeda

Posted on November 29, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related