Trying to manage GPIO accessing/dev/mem through JNI on my android app.

Context:
I need to be able to manage GPIO to:

  • Read values of gpios
  • Write values of gpios
  • Set direction (read/write) of gpio
  • Set edges interruption and get events
  • Optional: Set pull up o pull down

Desire solution

Problem
Can't get access to /dev/mem through JNI on my android app.

Especifically, I'm try to: "open("/dev/mem", O_RDWR | O_SYNC)"
but it doesn't work. In one of my tests, I tried to change the access permissions of the file to 777 but nothing changed, always got -1.

Do you have any idea of how I can access it?

I read in this forum, "To open /dev/mem you need both regular access permissions on the device file and the security capability CAP_SYS_RAWIO, or to be root"

In other forum says,
"
1) Run the program via "sudo" (this will be the most common advice given on this forum)
2) Make the program setuid root - or setgid kmem
3) Make pi be in the kmem group (and reboot to make it take effect)
"

But I can't run the program as root and setuid is not a valid command on the shell of emteria OS.

Do you know if I can "setuid root" to an App on Emteria?

Does Emteria OS have any libs to be able to manage GPIO?

Tagged:

Comments

  • edited April 2022

    Hi @fjretamales,

    • raspi-gpio is already preinstalled on the device
    • Please try using /dev/gpiomem instead of /dev/mem.
    • You will need to set correct permissions to access it from your application. Do it manually from ADB shell for testing and create a init.d script for automatic configuration at boot: https://emteria.com/kb/device-configuration-style-initd-scripts
  • Thanks @kalkov.

    I found this C pigpio lib that use /dev/gpiomem. This lib has a mininum manage of GPIO.

    So through JNI, I could manage my gpio in Java.

    Now I'm trying to use interrupts in C to be able to call java callbacks.

  • @kalkov said:
    Hi @fjretamales,

    • raspi-gpio is already preinstalled on the device

    I'm using version 1.1.37 on a Pi 3, and raspi-gpio is not installed. Is there a recommended way to install packages on the system?

  • @AndyT said:

    I'm using version 1.1.37 on a Pi 3, and raspi-gpio is not installed. Is there a recommended way to install packages on the system?

    The recommended way is to install the OS update (and maybe to test it with a different sdcard first).

  • https://github.com/ShamSinha/RHA
    from this you can give permission access to Gpio pin 2 and 3 and can set and get direction and value.

  • Hi,

    Could you please let me know if anyone has been able to use GPIO interrupt and if so, could you please provide some guidance

Sign In or Register to comment.