You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys. I am trying to detect button actions with a GPIO pin and a GND pin at milk-v DUO.
I connected the GPIO14 pin and the button to the GND pin. In the program, I set the GPIO14 in an input mode and read digital value per second, which worked for Raspberry Pi 4b GPIO. However when I closed the switch, it seemed to short-circuit, and the Milkv automatically restarted. I googled it and found it seems I need a resistance between the switch and the two pins. I managed to add a 150Ω resistance but the GPIO14 can not read the switch closing this time.
I am a newbie in embedded development. If there are any mistakes in what I did above, or if you have better suggestions, I would be happy to accept them. Thank you in advance.
The code:
#include<stdio.h>#include<unistd.h>#include<wiringx.h>#defineGPIO_14 19
intmain() {
if(wiringXSetup("duo", NULL) ==-1) {
wiringXGC();
return-1;
}
if(wiringXValidGPIO(GPIO_14) !=0) {
printf("Invalid GPIO %d\n", GPIO_14);
return-1;
}
pinMode(GPIO_14, PINMODE_INPUT);
while(1) {
intret;
ret=digitalRead(GPIO_14);
printf("value: %d\n", ret); // should print 0 if I close the switch or press the button?sleep(1);
}
return0;
}
The text was updated successfully, but these errors were encountered:
Hi guys. I am trying to detect button actions with a GPIO pin and a GND pin at milk-v DUO.
I connected the GPIO14 pin and the button to the GND pin. In the program, I set the GPIO14 in an input mode and read digital value per second, which worked for Raspberry Pi 4b GPIO. However when I closed the switch, it seemed to short-circuit, and the Milkv automatically restarted. I googled it and found it seems I need a resistance between the switch and the two pins. I managed to add a 150Ω resistance but the GPIO14 can not read the switch closing this time.
I am a newbie in embedded development. If there are any mistakes in what I did above, or if you have better suggestions, I would be happy to accept them. Thank you in advance.
The code:
The text was updated successfully, but these errors were encountered: