Jump to content
Sohrab

access GPIO pins on android 10

Recommended Posts

How can I access GPIO pins on android 10 without root access?

I have a 2s tinker board and I want to access serial pins.

 

Thank you in advance

  • Like 1

Share this post


Link to post
Share on other sites

Hello @yi-hsin_hung

I want to use the mraa library in Unity, can you tell me the package name?

ex unity C# code)
AndroidJavaObject _javaClass = new AndroidJavaObject ("com.tinkerboard.mraa");

Share this post


Link to post
Share on other sites

Hello @yi-hsin_hung

I want to use the mraa library in Unity, can you tell me the class name?

ex unity C# code)
AndroidJavaObject _javaClass = new AndroidJavaObject ("com.tinkerboard.mraa"); ?

Share this post


Link to post
Share on other sites

Hi @hisataro:

    Have a nice day! The mraa android library can be included by the following code on Android studio and we didn't support C# at current.

import mraa.*;

Thank a lot!

Share this post


Link to post
Share on other sites

Hi @yi-hsin_hung

It worked by using mraa-2.0.0.aar directly from Unity !

 

// Put aar to Unity Plugin Folder

UnityProjectFolder/Assets/Plugin/Android/mraa-2.0.0.aar

 

// Gpio Instance
AndroidJavaClass _TinkerBoard = new AndroidJavaClass("mraa.TinkerBoard");
AndroidJavaObject _TINKERBOARD_PIN3 = _TinkerBoard.GetStatic<AndroidJavaObject>("TINKERBOARD_PIN3");
int swigValue = _TINKERBOARD_PIN3.Call<int>("swigValue");
AndroidJavaObject _Gpio = new AndroidJavaObject("mraa.Gpio", swigValue);

// Dir instance
AndroidJavaClass _Dir = new AndroidJavaClass("mraa.Dir");
AndroidJavaObject _DIR_IN = _Dir.GetStatic<AndroidJavaObject>("DIR_IN");

// Mode Instance
AndroidJavaClass _Mode = new AndroidJavaClass("mraa.Mode");
AndroidJavaObject _MODE_PULLUP = _Mode.GetStatic<AndroidJavaObject>("MODE_PULLUP");

// Call Gpio.read()
AndroidJavaObject resultDir = null;
AndroidJavaObject resultMode = null;

resultDir = _Gpio.Call<AndroidJavaObject>("dir", _DIR_IN);
resultMode = _Gpio.Call<AndroidJavaObject>("mode", _MODE_PULLUP);
int result = _Gpio.Call<int>("read");
 

Tahnk you.

Share this post


Link to post
Share on other sites

Hi @yi-hsin_hung:

Thanks for your reply! I read that before and got the mraa.aar file but didn't know how to make it Android studio library. I've jut tried to put that file into app/libs then add the libs folder to the dependencies and it seems work

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...