Trying to read a digital pin

Hey all,

I’m trying to read a digital pin and if I can, I shall try to adjust some camera settings, on the fly.

I get an OpenMV IDE error trying to setup a button as follows:

button = machine.Pin(9, machine.Pin.IN, machine.Pin.PULL_UP)

TypeError: can’t convert ‘int’ objects to str implicitly.

I’m new to this as you can tell, any help offered, appreciated.

You have to make the PIN number a string.

Thanks, yes I got there by the following…

    pin0 = Pin('P9', Pin.IN, Pin.PULL_UP)
    pinstate0 = pin0.value()

Now I’m looking for a reference to the other GPIO pins so I can use them as well.

for example…

pin1 = Pin('TIM4_CH1', Pin.IN, Pin.PULL_UP)

gives an error…

Untitled-1

Hi, you use the stuff like this:

# PWM Control Example
#
# This example shows how to do PWM with your OpenMV Cam.

import time
from pyb import Pin, Timer

tim = Timer(4, freq=1000) # Frequency in Hz
# Generate a 1KHz square wave on TIM4 with 50%, 75% and 50% duty cycles on channels 1, 2 and 3 respectively.
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=50)
ch2 = tim.channel(2, Timer.PWM, pin=Pin("P8"), pulse_width_percent=75)
ch3 = tim.channel(3, Timer.PWM, pin=Pin("P9"), pulse_width_percent=50)

while (True):
    time.sleep_ms(1000)
1 Like

Thank you.

I found the pin names on the PCB screen-print.