Code: Select all
import machine
button = machine.Pin(0, machine.Pin.IN)
while True:
print(button.value())
Does anyone know what I am missing? Do I need to enable the pull-down resistors somehow?
Code: Select all
import machine
button = machine.Pin(0, machine.Pin.IN)
while True:
print(button.value())
Code: Select all
Pin(2, Pin.IN)
Code: Select all
button = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN)
I'm not sure how the mistake crept in, just one of those things that occasionally escape. Considering we have produced over 1000 pages of docs and this book, there's bound to be a few teething issues. And you are right, the book had to go to printing well before the actual release, and lots of stuff was changing right up to that point.Superkris wrote: ↑Fri Jan 29, 2021 9:41 pmI think i have the same problem. As i have no experience with Phyton i thought i'd just buy the book and work trough it for a basic understanding of how to program with MicroPhyton. I guess its a book that's mostly for children so it does make me feel a little bit stupid but i guess its fine to learn the basics.
So once you get to page 54 they explain that when you use the argument "machine.Pin.In" it defaults to a input with a pull down resistor. I got very random readings and feared i might have damaged the input with 5V logic. Other pins gave the same problem, and replacing the switch didnt either. Adding a pulldown however fixed it.
Luckily i have some Arduino experience so i understood what was happening. I was also lucky enough to find this topic because a quick google search did not help me in finding the right arguments. Hashdef's code works fine. Thank you dude!
I'm wondering what caused this. Obviously there was some time between the writing of the book, and the first Pico to be sold. Maybe the machine library changed, or something else was changed in code. In the book however its stated that for all experiments its not needed to activate a pull down resistor, and this seems to be very wrong!
Many thanks for your reply. Does this mean you confirm that by design the pins are floating when only "Pin.IN" is used?jamesh wrote: ↑Fri Jan 29, 2021 10:16 pmI'm not sure how the mistake crept in, just one of those things that occasionally escape. Considering we have produced over 1000 pages of docs and this book, there's bound to be a few teething issues. And you are right, the book had to go to printing well before the actual release, and lots of stuff was changing right up to that point.Superkris wrote: ↑Fri Jan 29, 2021 9:41 pmI think i have the same problem. As i have no experience with Phyton i thought i'd just buy the book and work trough it for a basic understanding of how to program with MicroPhyton. I guess its a book that's mostly for children so it does make me feel a little bit stupid but i guess its fine to learn the basics.
So once you get to page 54 they explain that when you use the argument "machine.Pin.In" it defaults to a input with a pull down resistor. I got very random readings and feared i might have damaged the input with 5V logic. Other pins gave the same problem, and replacing the switch didnt either. Adding a pulldown however fixed it.
Luckily i have some Arduino experience so i understood what was happening. I was also lucky enough to find this topic because a quick google search did not help me in finding the right arguments. Hashdef's code works fine. Thank you dude!
I'm wondering what caused this. Obviously there was some time between the writing of the book, and the first Pico to be sold. Maybe the machine library changed, or something else was changed in code. In the book however its stated that for all experiments its not needed to activate a pull down resistor, and this seems to be very wrong!
Thanks again for you reply. I really love the concept of the RP2040 and microphyton. I really hope the community for this microcontroller grows to similar size as the Atmel Arduino's. At this point its still hard to make a fair comparison, but i think the potential is huge!
I just started working through the book today and found other examples, too. In the traffic light with pedestrian button example, the given code will throw a NameError because “button” isn’t defined as a global variable inside and outside of the function used by the _thread. Had I not some experience with Python and help from the Python Discord (no response in the Raspberry Pie Discord, sadly), I would have been stuck.clickonben wrote: ↑Sun Jan 24, 2021 4:28 pmThanks, that works.
The official getting started book published by Raspberry Pi Press says that the default is pull down and the code examples are all of the form:
Which simply omits the parameter to specify whether it is pull down or pull up. The net result is that it seems to float so I think the book must be wrong.Code: Select all
Pin(2, Pin.IN)
Can you post any issue you find with the book in the github pico-feedback issue tracker please. We'll get them fixed as soon as possible.SilentRhetoric wrote: ↑Sun Jan 31, 2021 10:23 pmI just started working through the book today and found other examples, too. In the traffic light with pedestrian button example, the given code will throw a NameError because “button” isn’t defined as a global variable inside and outside of the function used by the _thread. Had I not some experience with Python and help from the Python Discord (no response in the Raspberry Pie Discord, sadly), I would have been stuck.clickonben wrote: ↑Sun Jan 24, 2021 4:28 pmThanks, that works.
The official getting started book published by Raspberry Pi Press says that the default is pull down and the code examples are all of the form:
Which simply omits the parameter to specify whether it is pull down or pull up. The net result is that it seems to float so I think the book must be wrong.Code: Select all
Pin(2, Pin.IN)
I had a great time with the original Raspberry Pi book, but this Pico book has been more frustration than fun, so far.
In the traffic light with pedestrian button example, the given code will throw a NameError because “button” isn’t defined as a global variable inside and outside of the function used by the _thread.
Code: Select all
def button_reader_thread():
global button_pressed
while True:
if button.value() == 1:
button_pressed = True
utime.sleep(0.01)
_thread.start_new_thread(button_reader_thread, ())
There is; since the Python SDK document is a potted summary of available commands, you have to go to the MicroPython docs for machine.Pin()
So pull=None should do it, in the rare occasions you'd want it.pull specifies if the pin has a (weak) pull resistor attached, and can be one of:
None - No pull up or down resistor.
Pin.PULL_UP - Pull up resistor enabled.
Pin.PULL_DOWN - Pull down resistor enabled.
Today i received a mail from the store that you/they will be providing new books free of charge.jamesh wrote: The book will be updated for its next printing I believe. I guess the PDF will be changed more quickly.
Excellent news!Superkris wrote: ↑Tue Feb 02, 2021 2:24 pmToday i received a mail from the store that you/they will be providing new books free of charge.jamesh wrote: The book will be updated for its next printing I believe. I guess the PDF will be changed more quickly.
Thank you very much for this great support. Keep up the good work!
To add to that: the PDF version as available through the Pi Bookshelf (and manual download) has had a couple of updates over the last week or so. Don't know exactly what changed though.