How to do it...

  1. Create the following servo_control.py script:
#!/usr/bin/env python3 #servo_control.py import curses import os #HARDWARE SETUP # GPIO # 2[=VX==2=======]26[=======]40 # 1[===013=======]25[=======]39 # V=5V X=Gnd # Servo 0=Turn 1=Shoulder 2=Elbow 3=Claw name=["Turn","Shoulder","Elbow","Claw"] CAL=[90,90,90,90] MIN=[0,60,40,60]; MAX=[180,165,180,180] POS=list(CAL) KEY_CMD=[ord('c'),ord('x')] #Keys to rotate counter-clockwise KEY_LESS={ord('d'):0,ord('s'):1,ord('j'):2,ord('k'):3} #Keys to rotate clockwise KEY_MORE={ord('a'):0,ord('w'):1,ord('l'):2,ord('i'):3} STEP=5; LESS=-STEP; MORE=STEP #Define control steps DEG2MS=1.5/180.0; OFFSET=1 #mseconds IDLE=2000 #Timeout servo after command SERVOD="/home/pi/PiBits-mater/ServoBlaster/user/servod" ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.