How can I use mraa?

someone please tell me !!!

I’m currently using Rock4SE.
I have confirmed that the port can be turned on/off using the following method.

1)Move directory
cd /sys/class/gpio/
2)Create a file for the GPIO
sudo sh -c “echo 154 > export”
3) Specify as input port
sudo sh -c “echo in > gpio154/direction”
4) Pull up
sudo sh -c “echo ‘high’ > gpio154/direction”
5) Check port status
cat gpio154/value

However, even if I check the port switching using the source code below, it does not turn ON/OFF.
What’s wrong?

I think mraa is functioning because it displays the I/O list and the mraa version.


import mraa
import time

gpio16 = mraa.Gpio(154, owner=True, raw=True)
gpio16.mode(mraa.MODE_PULLUP)
gpio16.dir(mraa.DIR_IN)

while True:
if gpio16.read() == 1:
print(“ON”)
else:
print(“OFF”)
time.sleep(1)

gpio16.close()

@Nasca can you help me to give some advices to @WATANABE

This worked.

sudo mraa-gpio get 16

Display it like this.

Pin 16 = 1

please try this :

gpio16 = mraa.Gpio(16, owner=True, raw=True)

Thanks for the reply! !

That was the first thing I tried!

It’s no good.

How do you test the input?

I checked by directly contacting the GPIO No. 16 terminal with 3.3V using tweezers.

import mraa
import time

pin = 3 # set pin num

try:
gpio = mraa.Gpio(pin)
gpio.dir(mraa.DIR_IN) # set mode as input

while True:
    value = gpio.read()  # read from pin 3
    print("value: {}".format(value))
    time.sleep(1)

except KeyboardInterrupt:
print("\nstop\n")

please try this example which I have tested

Thanks for testing! !
But when I try it, this error occurs.
Maybe the mraa installed on my Rock4SE is not good?

==========

Traceback (most recent call last):
File “/home/radxa/Documents/mraa_test_003.py”, line 7, in
gpio = mraa.Gpio(pin)
File “/usr/local/lib/python3.9/dist-packages/mraa.py”, line 479, in init
_mraa.Gpio_swiginit(self, _mraa.new_Gpio(pin, owner, raw))
ValueError: Invalid GPIO pin specified

I’ve uploaded it just in case.
I think mraa is working as shown in this image.

really sorry! ! !

solved.

The program you tested worked when I ran it as super user.

sudo pyhton XXXX.py
*XXXX is the Python program name

It is like this.

When value: 1, the corresponding pin is set to high level of 3.3V.

This program also worked when I started it as super user! !

Nasca, thank you so much for your response! !

Just one thing.

Perhaps this pull-up setting is not working, right?
Looking at the mraa source code, it doesn’t seem to be working.
(Intel’s edison seems to support programmatic pull-ups, but no other boards seem to support it.)
Does this mean that the only solution to this problem is to wire a pull-up resistor?

@Nasca please help to answer this quesiton

@WATANABE i am newbie to rock4se project board. i am operating debian 11 bullseye on it.
i am unable to install mraa for debian. however i have installed mraa python 3 binding, can you please guide me how can i install mraa for debian.
i am also trying to read gpio pins using mraa.

Hello! !

I’m also a newbie, so I can’t say much, but I installed it as follows.

  1. RockPi’s official libmraa cannot be downloaded, and the explanation Wiki is currently unavailable.
    https://wiki.radxa.com/Rockpi4/dev/libmraa

  2. However, I would like to use a library to use GPIO.

  3. There are not many GPIO libraries like RaspPi.

  4. RockPi has no choice but to use mraa.

  5. By the way, the mraa library itself is a general-purpose library and is compatible with RockPi, as announced on the official website.
    https://github.com/eclipse/mraa/blob/master/docs/rockpi4.md

  6. Therefore, we have determined that the RaspPi method is also valid for installation.

  7. Although it is a Japanese site, there was a site with instructions on how to install it, so I installed it using that as a reference.

  8. Currently, I have installed this method and there are no problems.


sudo apt update
sudo apt install git build-essential swig python3-dev cmake libjson-c-dev
git clone https://github.com/eclipse/mraa
cd mraa
mkdir build
cd build
cmake -DBUILDSWIGNODE=OFF …
make
sudo make install
sudo ldconfig

Reference: Eclipse MRAA on Raspberry Pi 4 - Python

Just wondering, are you tied to Debian or could you use Armbian?
If you can go Armbian, the answer and results are different (as in easier).