Testing GPIO Pins #16
-
|
I am trying to test the GPIO pins to connect to a simple servo motor. Here is the code I am using: from pycubed import cubesat setup transmitterTx = digitalio.DigitalInOut(board.PA22) i=0 while(i<10) : I have a multimeter attached to the pin to check whether the pin is successfully turned on and off. When I run the program, the multimeter only ever reads 3.3V. Why does the pin never get set low? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hey @ecburns33 It looks like your while loop doesn't sleep any amount after you set it low, meaning PA22 is set low for such a short period of time that your multimeter wont catch it (an oscilloscope or logic analyzer would be what you'd use to see fast pulses like this). Try this: while(i<10) :
Tx.value=1 # set it high
print(Tx.value)
time.sleep(1)
Tx.value=0 # set it low
print(Tx.value)
i=i+1
print('end')
time.sleep(1) # sleep here so you can measure the voltageNow just like how your micromag example was "bit banging" the SPI bus, you likely don't want to manually implement your stepper motor protocol. I googled "circuitpython stepper motor" and see that there's a couple simple libraries you can use. Here's an adafruit example as well as the adafruit_motor.stepper API docs. Regardless if that stepper library is applicable to your specific motor or not, you don't have to use the library, but you should at least use the built-in PWM module in CircuitPython if you're going to be doing pulse-width modulation control. Here's the PWM API docs as well as an adafruit tutorial. P.S. Just cuz I think Python can be liberating compared to traditional C/C++ 😄 Here are some other ways you could do your while loop (the way you did it was PERFECTLY valid, this just shows you options)
|
Beta Was this translation helpful? Give feedback.
Hey @ecburns33
It looks like your while loop doesn't sleep any amount after you set it low, meaning PA22 is set low for such a short period of time that your multimeter wont catch it (an oscilloscope or logic analyzer would be what you'd use to see fast pulses like this).
Try this:
Now just like how your micromag example was "bit banging" the SPI bus, you likely don't want to manually implement your stepper motor protocol. I googled "circuitpython stepper motor" and see that…