D
D
Danil12532022-02-15 15:02:39
Python
Danil1253, 2022-02-15 15:02:39

I press the button, it does not work, while the circuit is assembled correctly, What is wrong with the code?

import pyfirmata
board = pyfirmata.Arduino("COM3")
pin = 5
while True:
if board.digital[pin].read():
print("Pressed button")

620b9654454d6869043902.jpeg

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
kalapanga, 2022-02-15
@kalapanga

It is not visible in the photo - the resistor is turned on, it seems between the ground and what? There is a chance that just the circuit is assembled incorrectly. See the example \examples\02.Digital\Button from the Arduino IDE. There is also a diagram of how to connect the button. And by the way, it's not a sin to start this example without any "firms".
Well, do not forget about the possible bad contact. In these layouts, this is all the time.

V
Vindicar, 2022-02-15
@Vindicar

Check the documentation, maybe the pin number is wrong? The bit number in the Digital I/O register is not the same as the pin number on the board.
And I have no idea what numbering the python wrapper uses. But judging by the lack of an indication of the board model in the code, it is unlikely that the pin number on the board ...

D
Dmitry Makarov, 2022-02-15
@MDiMaI666

1. pin = 5 => pin = D5
2. Pull-up resistor to the signal pin (yellow wire) reconnect

B
Borys Latysh, 2022-02-15
@nava2002

First: The circuit is NOT 100% correct.
The program is difficult to analyze "pyfirmata" did not use.
You need to pull the resistor to Power Supply + 5V (in this case). This is due to the design of the input circuits of the microcontroller.
The photo clearly shows that the resistor is connected to the ground - NOT correct.
Solution:
An excellent material explaining the principle of the "button".
To justify the author of the question:
With surprise, in Google I found a huge number of links to very strange schemes, which, as I understand it, the author took as a basis. I was very surprised by this behavior of "Google".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question