Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4829

General • Re: Using all GPIO pins

$
0
0
by arg001 » Sat Aug 03, 2024 3:27 pm

How are you generating the servo outputs? If using the PWM slices, you can get 16 separate outputs, but only if you pick the right combination of pins.

Otherwise, share your circuit arrangements. One difference between the ADC pins and the other GPIOs is in their protection diodes: that shouldn't matter if you are using the pins legitimately, but could be an effect if you are doing something marginal. Your assertion that you have enabled the on-chip pull-down also rings alarm bells - if you actually need it, that pull-down isn't strong enough to drive long wires that are at risk of picking up cross-talk from other cables.
The Pico is wired as follows
Image
by hippy » Sat Aug 03, 2024 3:35 pm
Could be but it could be something else.

If you move those four switches closer to the Pico, or disconnect what you have and add temporary switches, does it still behave oddly or as it would be expected to ?

The switches are as close as I can reasonably get them.

I would write some proof of concept code which reads and reports the status of input pins so you can test those without involving the servos or anything else.

Is your code MicroPython, C or something else ?
MicroPython

Do you have a schematic showing how things are connected ?
See above

Initialising with pull-down suggests your switches are wired as short-to-3V3. Perhaps try with pull-ups and short-to-0V wiring.

If it is an ADC related issue, other input switches do work, you could move your connections around so pins 26, 27 and 28 are outputs controlling servos.
I had thought of this and it may be the way to go.

My code is attached.

Code:

# Importsfrom machine import Pin, PWMfrom time import sleep#from servo import ServoMID = 1400000MIN = 1000000# Set up our button names and GPIO pin numbers# Also set pins as inputs and use pull downsswitch1 = Pin(0, Pin.IN, Pin.PULL_DOWN)switch2 = Pin(1, Pin.IN, Pin.PULL_DOWN)switch3 = Pin(2, Pin.IN, Pin.PULL_DOWN)switch4 = Pin(3, Pin.IN, Pin.PULL_DOWN)switch5 = Pin(4, Pin.IN, Pin.PULL_DOWN)switch6 = Pin(5, Pin.IN, Pin.PULL_DOWN)switch7 = Pin(6, Pin.IN, Pin.PULL_DOWN)switch8 = Pin(7, Pin.IN, Pin.PULL_DOWN)switch9 = Pin(22, Pin.IN, Pin.PULL_DOWN)switch10 = Pin(26, Pin.IN, Pin.PULL_DOWN)switch11 = Pin(27, Pin.IN, Pin.PULL_DOWN)switch12 = Pin(28, Pin.IN, Pin.PULL_DOWN)#Set up the servopwm1 = PWM(Pin(8))pwm1.freq(50)pwm2 = PWM(Pin(9))pwm2.freq(50)pwm3 = PWM(Pin(10))pwm3.freq(50)pwm4 = PWM(Pin(11))pwm4.freq(50)pwm5 = PWM(Pin(12))pwm5.freq(50)pwm6 = PWM(Pin(13))pwm6.freq(50)pwm7 = PWM(Pin(14))pwm7.freq(50)pwm8 = PWM(Pin(15))pwm8.freq(50)pwm9 = PWM(Pin(16))pwm9.freq(50)pwm10 = PWM(Pin(17))pwm10.freq(50)pwm11 = PWM(Pin(18))pwm11.freq(50)pwm12 = PWM(Pin(19))pwm12.freq(50)pwm13 = PWM(Pin(20))pwm13.freq(50)pwm14 = PWM(Pin(21))pwm14.freq(50)print ("start")while True: # Loop forever        #Reverse loop controls two points on one switch    if switch1.value() == 1:# If switch 1 is thrown        pwm1.duty_ns(MIN)        pwm2.duty_ns(MID)            if switch1.value() == 0:        pwm1.duty_ns(MID)        pwm2.duty_ns(MIN)#Access to station    if switch2.value() == 1:# If switch 2 is thrown        pwm3.duty_ns(MIN)            if switch2.value() == 0:        pwm3.duty_ns(MID)#_______________TO BE ADDED TO LAYOUT_________________________        #Quarry siding    if switch3.value() == 1:# If switch 3 is thrown        pwm4.duty_ns(MIN)                      if switch3.value() == 0:        pwm4.duty_ns(MID)#Quarry right loop    if switch4.value() == 1:# If switch 4 is thrown        pwm5.duty_ns(MIN)                      if switch4.value() == 0:        pwm5.duty_ns(MID)#Quarry left loop    if switch5.value() == 1:# If switch 5 is thrown        pwm6.duty_ns(MIN)                      if switch5.value() == 0:        pwm6.duty_ns(MID)       #Quarry access    if switch6.value() == 1:# If switch 6 is thrown        pwm7.duty_ns(MIN)            if switch6.value() == 0:       pwm7.duty_ns(MID)#Station siding    if switch7.value() == 1:# If switch 7 is thrown        pwm8.duty_ns(MIN)            if switch7.value() == 0:        pwm8.duty_ns(MID)#Station left loop and Goods yard access    if switch8.value() == 1:# If switch 8 is thrown        pwm9.duty_ns(MIN)                      if switch8.value() == 0:        pwm9.duty_ns(MID)#Goods yard and loco shed    if switch9.value() == 1:# If switch 9 is thrown        #print ("Switch9 ",switch9.value())        pwm10.duty_ns(MIN)                      if switch9.value() == 0:        pwm10.duty_ns(MID)#Head shunt    if switch10.value() == 1:# If switch 10 is thrown        #print ("Switch10 ",switch10.value())        pwm11.duty_ns(MIN)                      if switch10.value() == 0:        pwm11.duty_ns(MID)#Loco shed access    if switch11.value() == 1:# If switch 11 is thrown        pwm12.duty_ns(MIN)                      if switch11.value() == 0:        pwm12.duty_ns(MID)#Station loop right     if switch12.value() == 1:# If switch 12 is thrown        #print("Switch12 ",switch12.value())        pwm13.duty_ns(MID)        pwm14.duty_ns(MID)            if switch12.value() == 0:        #print("Switch12 ",switch12.value())        pwm13.duty_ns(MIN)                pwm14.duty_ns(MIN)
Thanks all
Untitled.jpg

Statistics: Posted by Andrew57 — Sat Aug 03, 2024 3:18 pm



Viewing all articles
Browse latest Browse all 4829

Trending Articles