Cloud and Software Architecture, Soft skills, IOT and embedded
Adding an analog feedback tap to a 9g Micro Servo
Get link
Facebook
Twitter
Pinterest
Email
Other Apps
Internally the servo has a feedback loop that is driven off of a variable resistor. The resistance value changes as the servo sweeps across its range of motion. This can act as a proxy for the servo's position. You can buy servos with an extra wire that exposes the voltage across that variable resistor or you can make your own. Or, you can add your own sensing wire to the potentiometer.
I have a bunch of the 9g micro servos for various projects. The one below has an extra green wire coming out of it that is connected to an analog input on this ESP32 C3. The ESP32 can see the location of the servo while it is in motion.
The sample MicroPython tester moves a servo from 0 degrees to 180 degrees in steps and then returns to 0 degrees. It logs the analog value of the potentiometer at the end of every move. It is actually before the next move but there is no effective difference for this discussion.
This is from an ESP32 with a 16-bit ADC. The sample code works for the ESP8266 10-bit ADCs also.
The low-end number shows that there may be more range below 600usec or that it is just a potentiometer artifact.
The last row shows that we have probably gone past the maximum range of the servo. The test data is for 180 degrees and a lot of servos only go to 170 degrees.
You will have to calibrate your code against individual servos and allow for minor variations. I didn't run enough tests to know how repeatable the values are but suspect not so much on a $5.00 device.
degrees
servo1
servo2
0
9410
9650
10
12210
12210
20
15251
15299
30
18612
18884
40
21637
21925
50
24533
24822
60
27638
28022
70
30633
30967
80
33768
34024
90
36808
37273
100
39833
40313
110
43450
43978
120
46507
47035
130
49596
50124
140
52924
53421
150
56029
56733
160
59550
60318
170
63647
63935
180
65535
65535
analog readings on two servos in 10 degree increments
Opening up the Servo
The 9g servos seem to be produced in only a couple styles. They have 4 screws on the bottom that breaks down the case into 3 parts. We need to remove those screws and pull off the bottom of the case.
I did not have to do any more disassembly for my servo.
Finding the potentiometer pins
The potentiometer is often mounted directly to the motor control board via through-hole solder connections. You can see the external three wires on the right and the two white motor wires running from the motor to the chip.
The potentiometer is mounted via the three holes on the left side of the board. One will be power, one will be ground and the third is the current proportional voltage for the location, the center tap.
We want to attach our sensing wire to the middle solder blob.
Attaching the sending wire wire
We're going to need to solder a wire to the middle solder blob of the potentiometer. Tin the wire to get a little solder on it. Then hit the blob with your soldering iron and touch the wire to it. That was enough to get a decent connection.
At this point, I kind of wanted to add some hot glue to protect the but didn't get around to it. Mostly because I thought I might want to redo this later.
We now have a servo with the extra wire and need to figure out a way to get the wire to exit the case with just enough pinch to protect it.
Notching the case for the new wire.
The bottom piece of the case has a notch for the existing three wires. It is undersized enough to pinch the wires and act as a strain relief.
I filed a notch into the existing one. I hoped that the insulation on the stacked would have the right amount of give to pinch them in the case. You can see the notch in the picture.
Hook Up
The servo will operate as it has in the past whether you hook up the sensing wire or not. You can see in this picture that we attached 4 wires to the ESP32 C3 on the right. There is power, ground and the servo control line, and the new green sensing wire. The analog wire mustbe attached to an ADC if you want to read any values. Otherwise, just leave it unattached. The green wire exists for you to sense the position and does not affect servo operation. Note: it could affect servo operation if you suck too much current through the line.
This picture shows the servo control wire attached to GPIO 5 and the servo sensing wire attached to GPIO 4. This is because GPIO 4 is one of the ADC-capable pins in this particular board and CPU.
Video
Sample Code
This code comes from https://github.com/freemansoft/ESP8266-MicroPython It may be different from the version you see when you look at the repo. I tend to run this class from the REPL using the instructions in the class.
checkswee.py makes use of the logging code inside Servo() and ServoSweep(). You've seen the output above. The code
Creates an ADC to read the values
Creates a Servo
Creates a Sweeper and injects the ADC and Servo configurations
Calls sweep() at regular intervals. sweep() advances the servo and logs it's positions.
"""
Usage in REPL:
from checksweep import sweep_esp_32
sweep_esp_32()
Depends on classes from this project:
Servo
ServoSweep
"""
fromservosweepimportServoSweep
fromservoimportServo
from machine import Pin, ADC
importtime
defsweep_esp_32():
"""
Exercises ServoSweep.
Originally written to verify logging of servo position.
Later extended to log the analog read back position if available.
"""
adc = ADC(Pin(4))
# set full attenuation to have full 0-3v range
adc.atten(adc.ATTN_11DB)
servo =Servo(Pin(5))
sweeper =ServoSweep(servo, pin_adc=adc)
whileTrue:
# this advances the stepper by whatever the current step size is
The Windows Subsystem for Linux operates as a virtual machine that can dynamically grow the amount of RAM to a maximum set at startup time. Microsoft sets a default maximum RAM available to 50% of the physical memory and a swap-space that is 1/4 of the maximum WSL RAM. You can scale those numbers up or down to allocate more or less RAM to the Linux instance. The first drawing shows the default WSL memory and swap space sizing. The images below show a developer machine that is running a dev environment in WSL2 and Docker Desktop. Docker Desktop has two of its own WSL modules that need to be accounted for. You can see that the memory would actually be oversubscribed, 3 x 50% if every VM used its maximum memory. The actual amount of memory used is significantly smaller allowing every piece to fit. Click to Enlarge The second drawing shows the memory allocation on my 64GB laptop. WSL Linux defaults to a maximum RAM size of 5
I wanted to access all my Azure resources without making any of them visible to the Internet. The easiest give my local machine access to everything on my Azure Virtual Network (VNET) was to connect to it over VPN. It turns out creating Azure VPN gateways and connecting to Azure VPN endpoints is easy. There are some subtleties in getting DNS name resolution to work that can confuse when first starting out. Setting the Stage There are a few ways to get to Azure endpoints and resources that are blocked from the internet. We can Create a Point-to-Site connection from our local machines to Azure Network Gateways Create a Site-to-Site network connection from our local networks to Azure Network Gateways. Use Bastion Hosts Use Cloud Shell Leave everything open to the internet. I chose a Point-to-Site (P2S) VPN connection that connects from my laptop to a VNet Gateway. That joins my laptop
Create Storage Spaces in Windows 10 Windows Server O/S contains Storage Spaces support for Server Spaces tiered storage. You can front slower spinning disks with smaller faster SSDs. Windows 10 has a Storage Spaces GUI Control Panel that does not include the tiered storage GUI. This means Powershell must be used for all configuration. https://github.com/freemansoft/win10-storage-spaces contains scripts that create tiered storage pools that integrate SSDs as caching drives and HDDs as storage drives. They assume you have at least one SSD and one HDD. The scripts automatically find all raw drives and add them to the pool. Some HDDs have their types incorrectly identified. The script can coerce them to be MediaType:HDD The entire virtual drive is added to the system as a single large volume You need at least 1 SSD and 1 HDD to run cached storage / Simple resiliency 2 SSD and 2 HDD to run cached storage / Mirror resiliency / 1 SSD and 2 HDD to run cached storage / Simple re
Comments
Post a Comment