Interfacing Push Button With VisionFive RISCV Based Linux SBC
In this tutorial, we will interface the push button with our VIsionFive board. Led will be remained on until for next time the button is pressed. It will not be turned off otherwise. It is similar to Arduino's button debounce sketch. But as it is in python and on VisionFive, it will be a little different and easier and with fewer lines of code.
It can include the following things:· INPUT -|- Getting Values or state change detection at VisionFive’s GPIOs· OUTPUT -|- Setting State at VisionFive’s GPIOs· What is the button?· Default State of VisionFive’s GPIOs
So without further dragging it, let’s get into it.
Push-button is the same as any button whose function is to close
or open the circuit when pressed. It is the simplest Input device. It’s in almost every electronic appliance which includes users' inputs. It usually consists of 4 terminals or even 2 and 3. But technically all we have to use only 2 terminals.
We can easily interface it with VisionFive, Arduino, Raspberry Pi, Beaglebone, or any other microcontroller.
“VisionFive, the iteration version of StarLight single-board computer, has the same performance and configurations as the previous version. It is the world’s first generation of affordable RISC-V boards designed to run Linux. Based on the RISC-V architecture, VisionFive pushes open-source to the next level and gives developers more freedom and power to innovate and design industry-leading solutions.”
It has 40 GPIOs, making it easier to control and interface with the environment and the world.
Circuit Diagram is really simple and straightforward.
The following image is available on RVspace. It was followed for connections.
For More Information about GPIOs you can follow this link to RVSpace:
First, install Gpiod library using the following command:
$ sudo pip install gpiod
Or you can try:
$ sudo dnf install gpiod
Then you need to install libgpiod library. Here this thing takes us on two ways path. We have to take both of them :)
Firstly after gpiod is installed, we need to install the python3-libgpiod library. This was designed for python to access and manage gpios. So let's install it by using the following command.
$ sudo dnf install python3-libgpiod
after it is installed now we need to do the following commands "gpioinfo" , "gpiodetect" to get info about our gpio but for that, we need to install another library. So install it by:
$ sudo dnf install libgpiod-utils
Now after this we can check it by the following command:
$ sudo gpiodetect
This command should show you the output with different gpiochips available on the board. More about that was already discussed.
Note: In my case, I have to install everything in this sequence otherwise it was giving me an error. I don't know why the hell but it was. So I had to uninstall all the libraries first and then install them in this sequence, or at least the solution that I figured out.
Now if we run the
code by pressing F5, we will be able to see the value of c being printed on Screen. And now if we press the push button our led will be turned on and if we press it again it will be turned off.
If any error regarding indentation or inconsistent use of tabs and spaces appears then you can simply select that paragraph and press Alt + 5 and hit enter at any pop-up.
This python file should be run with administrative privileges or root privileges. by use of the following command.
$ sudo python
But before executing this command make sure that you are in the same directory where this code is downloaded.
The python file is available on my Github: