1

I've tried to use hexadecimal for the GPIO address to see if it would work with GPA0 on the MCP23017

import pigpio
import time
pi = pigpio.pi()
gpio_num = 0x21
while True:
        pi.set_servo_pulsewidth(gpio_num, 1500)

but this results in the error

  File "i2cpigpio.py", line 6, in <module>
    pi.set_servo_pulsewidth(gpio_num, 1500)
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1647, in set_servo_pulsewidth
    self.sl, _PI_CMD_SERVO, user_gpio, int(pulsewidth)))
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 979, in _u2i
    raise error(error_text(v))
pigpio.error: 'no permission to update GPIO'

I also tried using one of Adafruit's libraries (with python3) to see if that would make it more compatible

import pigpio
import time
from adafruit_mcp230xx.mcp23017 import MCP23017
import board
import busio
import digitalio
i2c = busio.I2C(board.SCL, board.SDA)
mcp = MCP23017(i2c)  # MCP23017
pin0 = mcp.get_pin(0)
pin0.switch_to_output(value=True)

pi = pigpio.pi()
gpio_num = pin0
while True:
        pi.set_servo_pulsewidth(gpio_num, 1500)

but I get the error

Traceback (most recent call last):
  File "i2cpigpio.py", line 15, in <module>
    pi.set_servo_pulsewidth(gpio_num, 1500)
  File "/usr/local/lib/python3.5/dist-packages/pigpio.py", line 1647, in set_servo_pulsewidth
    self.sl, _PI_CMD_SERVO, user_gpio, int(pulsewidth)))
  File "/usr/local/lib/python3.5/dist-packages/pigpio.py", line 993, in _pigpio_command
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
struct.error: required argument is not an integer

since pin0 doesn't represent a Broadcom SOC channel. What can I use for the GPIO number to send a pulsewidth to GPA0?

1

pigpio only provides PWM and servo pulses to the Pi GPIO on the expansion header. For the Pis with the 40 pin header this means (Broadcom) GPIO 0-27 inclusive.

In practical terms I doubt you will have much joy using a MCP23017 to provide servo signals. It will be extremely difficult to time synchronise accurately on/off pulses over the relatively slow I2C bus.

  • I see, is there any other method you might recommend for when you need more servos than the expansion header will allow (preferably without servo jitter)? – pinkie pAI Dec 2 at 22:46
  • 1
    Look at pca9685 based modules. – joan Dec 3 at 8:11
  • Put pca9685 into eBay search – joan Dec 3 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.