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

  1. Install MRAA:
  • Use your package manager or follow platform-specific instructions.
  1. Include MRAA in Your Code:
  • Add #include <mraa.h> to your C/C++ code.
  1. Initialize MRAA:
  • Call mraa_init(); at the beginning of your program.
  1. Create and Configure GPIO:
  • Create a GPIO object with mraa_gpio_init(pin);
  • Set direction with mraa_gpio_dir(gpio, MRAA_GPIO_OUT); (for output).
  1. Write and Read GPIO:
  • Use mraa_gpio_write(gpio, value); to set output.
  • Use int value = mraa_gpio_read(gpio); for input.
  1. Clean Up:
  • Release resources with mraa_gpio_close(gpio); when done.
  1. Compile and Run:
  • Compile with gcc your_program.c -o your_program -lmraa .
  • Run the executable.

Refer to the MRAA GitHub repository for more details and examples. Adjust pin numbers and functionalities based on your hardware and requirements.IF you want to change your mraa and anything names you must visit here.

HEY everyone today i found a site which creats everyliving and nonlivingthings names very correctly.I think it also create mraa name you must try once click here.