digitalio blink confusion

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
RoseNose
 
Posts: 17
Joined: Thu Jan 25, 2018 2:50 pm

digitalio blink confusion

Post by RoseNose »

I'm sure I'll feel like a real idiot when I figure this out, but I'm not sure what I'm seeing. I'm trying to make a basic blink using an n-channel transistor and some 5v 1a leds in parallel. I can force them to blink just fine in the REPL, so this isn't a wiring question. This is my (stripped down for testing) code:

Code: Select all

import time
import board
import digitalio

mosfet_pin = digitalio.DigitalInOut(board.D0)
mosfet_pin.direction = digitalio.Direction.OUTPUT
mosfet_pin.value = False

while True:
    print(mosfet_pin.value)
    mosfet_pin.value = not mosfet_pin.value
    print(mosfet_pin.value, "\n")
    time.sleep(1)
In the terminal I see

Code: Select all

False
False 

False
False 
But the light stays on. I'm very confused. From what I can see, the mosfet_pin.value is never True, but the light stays on the whole time and doesn't blink. Can anybody enlighten me on what I've done wrong, and a way I could troubleshoot a problem like this on my own moving forward?

Thanks!

Ps. Further weirdness. I ran the code line by line in the REPL.

Code: Select all

Adafruit CircuitPython 7.0.0 on 2021-09-20; Adafruit QT Py RP2040 with rp2040
>>> import board
>>> import digitalio
>>> 
>>> mosfet_pin = digitalio.DigitalInOut(board.D0)
>>> mosfet_pin.direction = digitalio.Direction.OUTPUT
>>> mosfet_pin.value = False
>>> mosfet_pin.value = not mosfet_pin.value # LED ON
>>> mosfet_pin.value = not mosfet_pin.value # LED OFF
>>> mosfet_pin.value = not mosfet_pin.value # LED ON
>>> print(mosfet_pin.value)                               # LED ON
False                                                                   # LED ON
>>> mosfet_pin.value = not mosfet_pin.value # LED STILL ON
>>> 
It works fine blinking the light *up until* I print. Once I print the state of the value the light stops blinking and stays on while I only get False as the read value.

User avatar
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: digitalio blink confusion

Post by dastels »

What happens if you take the prints out of the non-REPL code?

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”