[Tutor] Pi GPIO question was: Hi

Alan Gauld alan.gauld at yahoo.co.uk
Sat Apr 9 14:17:56 EDT 2022


On 09/04/2022 17:42, Chidinma Ufomadu wrote:
> I need help with a project. I can't seem to be able to make the green led
> come on when the servo is rotating, the red led just stay on. from machine

This isn't really a Pi forum so we have limited experience here.
ut I'll make some general comments based on no knowledge whatsoever
of what you are actuall doing!


> Pot = ADC(0)# Pot at channel 0 for servo
> servo = PWM(Pin(0)) # GPIO pins
> servo.freq(50)
> switch = (3, Pin.IN, Pin.PULL_UP) # PMW wave input
> 
> L1 = Pin(1, Pin.OUT) #GPIO2 set as pin for RED LED
> L2 = Pin(2, Pin.OUT) #GPIO3 set as pin for Green LED

Might be better to call them Red and Green rather than L1 L2.
Saves you remembering which is which.

> ch1 = PWM(Pin(2)) # set ch1 for L1 to PWM using GP2
> ch1.freq(1000)

redCh maybe?

> ch2 = PWM(Pin(3)) # set ch2 for L2 to PWM using GP3
> ch2.freq(1000)

greenCh maybe?

> while True:                 # Do forever
>     duty = Pot.read_u16()   # Copy pot Raw value to duty
>     value = int(1350 + (Pot.read_u16() / 9.57))
>     # adds the ruired offset to raw value of pot.
>     servo.duty_u16(value) # final value needed a bit of weaking
>     print(value)

Apart from printing value you never use it for anything.
Is that correct?

>     utime.sleep(0.5)
>     L1.value(1)
>     L2.value(0)

You always set the same hard coded values. Should these
maybe be related to the value calculated above?

>     utime.sleep(0.5)

I don't know if that helps!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list