Skip to content

Instantly share code, notes, and snippets.

@mithi
Created March 6, 2020 11:48
Show Gist options
  • Select an option

  • Save mithi/5b14bb64f7046f600362c4ce954dabf7 to your computer and use it in GitHub Desktop.

Select an option

Save mithi/5b14bb64f7046f600362c4ce954dabf7 to your computer and use it in GitHub Desktop.
from __future__ import print_function # Make print work with python 2 & 3
print('Please wait while modules load...')
import time
import pigpio
import smbus
import subprocess
#Setup I2C
try:
bus = smbus.SMBus(1)
address = 0x48
except FileNotFoundError:
print('')
print('')
print('I2C not enabled!')
print('Enable I2C in raspi-config')
pi.set_mode(servo_20, pigpio.OUTPUT)
pi.set_mode(servo_21, pigpio.OUTPUT)
servo_channels = [7, 8, 9, 10, 11, 5, 6, 13, 27, 20, 21, 22]
print("Set mode of servo channels to output")
for channel in servo_channels:
pi.set_mode(channels, pigpio.OUTPUT)
DELAY = 2.0
PWM_VALUE = 100
print(f"set all channels to have pwm of {PWM_VALUE} for {DELAY} seconds")
for channel in servo_channels:
pi.set_servo_pulsewidth(channel, PWM_VALUE)
time.sleep(DELAY)
print("Turning all channels off")
for channel in servo_channels:
pi.set_servo_pulsewidth(channel, 0)
print("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment