First of all thank you for this great product and I’m loving it! I’m here to get clarified/advised what I’m doing wrong?
I’m working on image classification (specific object sub type) based use case. The expected workflow demands user to trigger the action and give feedback to the running program. It’s a kind of correcting the category by the user if classification fails. In this situation i required two buttons for feedback interaction and proximity sensor for triggering the inference. Proximity sensor module is working fine.
I did configured the ports P4 and P5 as input with internal pull up and read the port status for different button event logic, in software.
Here is the circuit i tried.
If i put it in breadboard and tried it, all the configured button is giving zero till it is connected with momentary button in the breadboard.
However, i tried connecting directly with wire (without button) in series with 1k resistor from ground to P4 or P5, it is giving LOW when button (wire is in contact between port and ground) is being pressed and HIGH otherwise. [Active LOW]. Tested and verified the entire software flow as expected by using wire and resistor. My question is that, what I’m doing wrong with momentary switch interface circuit?
Honestly speaking, I’m not a hardware geek. Your support will be really helpful and thank you!
Can you post the button code?
# Button related code alone.
proximity_active = 0
timer_button_A_press = 0
timer_button_B_press = 0
TIME_TICK_HZ = 10
This Function is a system tick (kind of) callback function that is being called for TIME_TICK_HZ
times every second. This function handles the button and sensor event triggering logic. This
function has to be short as possible and shall not call any other data handling functions.
global proximity, ButtonA, ButtonB
global proximity_activ , timer_button_A_press, timer_button_B_press
if (proximity.value() == 0):
proximity_active = proximity_active + 1
if (ButtonA.value() == 0):
timer_button_A_press = timer_button_A_press + 1
if (ButtonB.value() == 0):
timer_button_B_press = timer_button_B_press + 1
proximity = Pin('P1', Pin.IN, Pin.PULL_UP)
ButtonA = Pin('P5', Pin.IN, Pin.PULL_UP)
ButtonB = Pin('P4', Pin.IN, Pin.PULL_UP)
tim = Timer(2, freq=TIME_TICK_HZ) # create a timer object using timer 2 - trigger at 1Hz
# Print the high level debug info.
print(proximity.value(), proximity_active, ButtonA.value(), timer_button_A_press,
# Application code starts here...
This is the button related code alone. Key idea is that, all buttons are configured with internal pull up and button event tract is handled in callback function (using timer 2 of 10HZ). So, the resource used are timer 2, and some set of button tracking variables which is later used in application code of while loop.
Even additionally, I tested too, the simple example program Pin_Control.py (File->Example->OpenMV->Pin_Control.py) also gives the same wrong behavior for the circuit. Look the modified code below
# Pin Control Example
# This example shows how to use the I/O pins in GPIO mode on your OpenMV Cam.
from pyb import Pin
# Connect a switch to pin 0 that will pull it low when the switch is closed.
# Pin 1 will then light up.
pin5 = Pin('P5', Pin.IN, Pin.PULL_UP)
pin1 = Pin('P1', Pin.OUT_PP, Pin.PULL_NONE)
Dear friend… you must test with a multimeter which contacts of the switch are the throw contacts. In your switch there are 2 ways. You must ensure that while installing the switch on breadboard you will not short those contacts. Test again with multimeter for properly operation of the switch. You can add a capacitor from input to ground around 100 nano to reduce button noise too…