Python in Bionic Prosthetics
Many of us have seen sci-fi movies where someone gets a futuristic robotic arm or leg that moves as smoothly as a real limb. But in reality, limb loss affects millions of people worldwide, and advanced prosthetics that move with the user’s intention can cost upwards of $100,000. This makes them completely out of reach for the people who would benefit most, those who are retired veterans, people born without a limb, those who have lost limbs to accidents and diseases, and furthermore.
While more basic prosthetics fill their roles well, there is always a route to improve on these abilities. So what if we can use accessible electronics, motors, sensors, and Python to build more responsive and affordable alternatives?
While it would be easy to set up a basic push-button system on a robotic hand to open and close fingers on command, it quickly gets more complicated when a user needs to perform different everyday tasks — like gently picking up a water bottle, opening a door, or supporting their body to stand up after a fall. So how can software determine when and how a prosthetic hand should move?
An ideal solution is to use biological sensors on the user’s skin to pick up on electrical nerve signals and measure how a person wants to move. Then, use this data to “teach” the prosthetic how to react in different situations. A threshold can be set, and when the user contracts a muscle in their residual limb, the prosthetic reads the incoming electrical signal and executes a basic movement.
Here’s a basic CircuitPython code snippet sourced from Adafruit documentation (1) for reading sensor data:
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""CircuitPython Essentials Analog In example"""
import time
import board
from analogio import AnalogIn
analog_in = AnalogIn(board.A1)
def get_voltage(pin):
return (pin.value * 3.3) / 65536
while True:
print((get_voltage(analog_in),))
time.sleep(0.1)This code can be extended by connecting the microcontroller to servo motors inside a 3D-printed hand. Putting these pieces together creates a basic, signal-driven prosthetic limb. It checks sensor voltage continuously, and when the voltage spikes past a desired threshold, it triggers a simple movement for the limb.
While this works well for basic open-and-close motions, creating multiple distinct grips (pinching and pointing, for example) requires more data and execution. Since high-end commercial prosthetics remain out of reach for many, adapting the software to calculate these nerve pulses over small windows of time helps to both simplify the complexity and increase the response speed. This makes it a more practical approach for using Python code with the prosthetics.
These nerve signals switch back and forth between positive and negative signals, and the body generates these signals hundreds of times per second. Therefore, instead of relying on a single snapshot, this data can be grouped into short windows of time. Once this data is recorded, it can be used to calculate how much energy is being used. In other words, how much force the person wants to use when operating the prosthetic. This can range from a gentle flex of the fingers to a strong contraction like squeezing a fist.
This can be achieved using libraries like NumPy on a microcontroller and linking this controller with a sensor. This sensor will generate the data needed, and the Python software will process this data to determine the effort being used to move the user’s muscles over time. This code is an example of the conceptual approach that can be used to calculate the amplitude, a single value representing the muscle contraction force.
Get Cmgrant’s stories in your inbox
Join Medium for free to get updates from this writer.
To handle this data, developers can use functions adapted from the open-source BioSPPy framework (2) to calculate this energy over time. Here is a conceptual example:
import numpy as np
np.dot(3, 4)np.dot([2j, 3j], [2j, 3j])a = [[1, 0], [0, 1]]
b = [[4, 1], [2, 2]]
np.dot(a, b)a = np.arange(3*4*5*6).reshape((3,4,5,6))
b = np.arange(3*4*5*6)[::-1].reshape((5,4,6,3))
np.dot(a, b)[2,3,2,1,2,2]
sum(a[2,3,2,:] * b[1,2,:,2])Once the function is set up, it can process incoming signals in real time. In the script, evaluating a short window provides a clean summary of muscle contraction strength without overloading the microcontroller. It can also be adjusted for different thresholds depending on individual user needs. Someone with stronger muscle signals might generate higher energy values, whereas someone with subtle signals might need a lower threshold. Keeping the feature calculation simple keeps the software responsive.
Combining signal processing with physical motor output produces a loop that can be utilized. Sending Pulse Width Modulation (PWM) signals to servo motors allows Python to figure out what the person wants to do based on the nerve signals and then tell the motor what physical movements to make (3):
By combining hardware documentation with custom Python logic, a prosthetic limb can respond dynamically to muscle contractions. Shrinking the windows being measured improves the movement of the prosthetic, making movements smoother and more specific, though they come at the downside of needing stronger controllers and quality motors.
When testing or calibrating a limb, logging sensor readings over time helps measure user muscle fatigue. By saving signal energy calculations over extended trials, engineers can see how the electrical pulse strength changes as a user’s muscles tire out.
If signal strength drops over extended use, the software thresholds can be reprogrammed dynamically to adapt to changing signal levels. This flexibility makes open-source Python implementations a compelling way to advance accessible assistive technology for amputees worldwide.
In conclusion, we can use coding languages like Python to facilitate producing both effective and affordable prosthetic limbs. Significant progress has already been made towards these efforts, but there is still plenty of improvement that can be made to make the lives of amputees safer and more comfortable.
References:
Kattni Rembor. (2018, April 2). CircuitPython Essentials. Adafruit Learning System. https://learn.adafruit.com/circuitpython-essentials/circuitpython-analog-in
PIA-Group/BioSPPy. (2024, May 31). GitHub. https://github.com/PIA-Group/BioSPPy
pwmio — Support for PWM based protocols — Adafruit CircuitPython 1 documentation. (2019). Circuitpython.Org. https://docs.circuitpython.org/en/latest/shared-bindings/pwmio/
Cutipa-Puma, D. R., Coaguila-Quispe, C. G., & Yanyachi, P. R. (2023). A low-cost robotic hand prosthesis with apparent haptic sense controlled by electroencephalographic signals. HardwareX, 14, e00439. https://doi.org/10.1016/j.ohx.2023.e00439
Images:
Tisshaw, E. (2024, July 15). Open Bionics Hero Gauntlet Prosthetic Review: Price, Specs, Availability. Wired; WIRED. https://www.wired.com/review/review-open-bionics-hero-gauntlet/


