GPIO pin output works in REPL, not in main.py
Posted: Thu Apr 12, 2018 11:37 pm
I have something wrong here and cannot see it yet.
Here is my program,
boot.py
main.py
I can cut and paste some commands in the REPL like this:
to get a volts observed output on A5, but the while loop does not make output.
Can you see anything wrong with my code? It's built with v1.9.3 micropython.
Here is my program,
boot.py
Code: Select all
# boot.py -- run on boot-up
import pyb
pyb.main('main.py')
Code: Select all
# main.py -- put your code here!
import machine
import pyb
# Define pins so they can be set with a pin reference like: pin10.value(1) on the fly.
pinA5 = machine.Pin(machine.Pin.cpu.A5, machine.Pin.OUT_PP, machine.Pin.PULL_NONE)
# pinB3 = pyb.Pin(pyb.Pin.cpu.B3, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB4 = pyb.Pin(pyb.Pin.cpu.B4, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB5 = pyb.Pin(pyb.Pin.cpu.B5, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB6 = pyb.Pin(pyb.Pin.cpu.B6, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB7 = pyb.Pin(pyb.Pin.cpu.B7, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB8 = pyb.Pin(pyb.Pin.cpu.B8, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB9 = pyb.Pin(pyb.Pin.cpu.B9, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB10 = pyb.Pin(pyb.Pin.cpu.B10, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB13 = pyb.Pin(pyb.Pin.cpu.B13, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB14 = pyb.Pin(pyb.Pin.cpu.B14, pyb.Pin.OUT_PP, Pin.PULL_NONE)
# pinB15 = pyb.Pin(pyb.Pin.cpu.B15, pyb.Pin.OUT_PP, Pin.PULL_NONE)
count = 0
while ( count < 20):
pinA5.value(1)
# pinB5.value(0)
# pinB3.value(1)
# pinB4.value(0)
# pinB8.value(1)
# pinB9.value(0)
pyb.delay(200)
pinA5.value(0)
# pinB5.value(1)
# pinB3.value(0)
# pinB4.value(1)
# pinB8.value(0)
# pinB9.value(1)
# pyb.delay(400)
count = count + 1
Code: Select all
>>> import machine
>>> import pyb
>>> pinA5 = pyb.Pin(pyb.Pin.cpu.A5, pyb.Pin.OUT_PP, Pin.PULL_NONE)
>>> pinA5.value(1)
>>> pinA5.value(0)
>>> pinA5.value(1)
Can you see anything wrong with my code? It's built with v1.9.3 micropython.