Android Things [ADD I2C, PWM examples]

Post Reply
Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Android Things [ADD I2C, PWM examples]

Unread post by Luke.go » Mon Dec 16, 2019 12:13 pm

Have you ever tried to connect a peripheral device to the GPIO pins on your ODROID SBC with the Android OS? For example, you wished to connect a switch to launch an application or you would wish to connect a dimming sensor. The first problem you will face would be the difficulty to handle the GPIO pins from your Android application or service and maybe you would be faced the permission problems to access a GPIO, PWM or I2C since a general Android application is not denied to access a hardware resource. The alternative solution is to port a low-level library such as wiringPi based on C/C++ but will be burdened to interface to your application through JNI (Java Native Interface) using NDK. Still, you have to figure out the permission problem issue. :)

Google had introduced yet another OS as known as “Android Things” that is designed to run on light embedded devices and offers the framework with Java to handles peripherals. My idea was to invite the Android Things framework to ODROID and let users use the expansion pins easily. But the problem is that the Android Thing is not open source not like other Android OS therefore I had to implement the code in the Android for ODROID. Fortunately, Google opens the framework APIs with its document and Android Things SDK. This fact encourages me to implement the full stack of the framework that works like what Android Things do from bottom to top.

I use some apis from the Android things’ Peripheral managing parts. Android things has many other features, but that is not needed yet to the odroid. I made interfaces for using android things api. and for processing and managing the request from user layer via API, I build the server and client architecture and connect it to the hardware layer via the wiringPi to control real hardwares. First of all, GPIO, I2C and PWM features are implemented. because people use it more often than other features like spi and uart. Explaining all of the implementation is best, but I will just show you how to use it. that are more useful. I don't want to waste your time. :)

I made it by reverse engineering. As a result, it can be incompatible and degrade performance. But I expect that users who previously wanted to use GPIO pins on Android will relieve some of the difficulty of working in C or script by my work. Let me show you an example of android things about GPIO, I2C and PWM to learn how to use it.
android_things_diagram.png
android_things_diagram.png (71.5 KiB) Viewed 1174 times
[Android Things Implementation Architecture diagram]

There is nothing as simple as using the Android Studio to create, compile, and test an application or service that contains Android Things feature. You just need to install the Android studio, and add official option and official code to use android things, and install a package to odroid via otg port. and just execute a package. It just works! That's all. you don’t need to do anything else.

I uploaded all of the example code to my github repository (https://github.com/xiane/thingsGpioExample). And each of the examples is just separated by branches. On the master branch, You can control the GPIO pin. On the i2c_16x4 branch, you can use 16x4 lcd through I2C. On the PWM branch, you can control the PWM. and on the i2c_weather_board branch, you can use a weatherboard. Please use and test it for your help.

All of the behind code is based on the android thing official site. Please check the official site. https://developer.android.com/things
Last edited by Luke.go on Wed Jan 15, 2020 10:39 am, edited 1 time in total.
These users thanked the author Luke.go for the post (total 6):
rooted (Mon Dec 16, 2019 12:45 pm) • joerg (Mon Dec 16, 2019 1:53 pm) • mad_ady (Mon Dec 16, 2019 2:55 pm) • milesian (Mon Dec 16, 2019 3:27 pm) • benwillcox (Mon Dec 16, 2019 4:32 pm) • istanbulls (Mon Dec 16, 2019 6:02 pm)

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Mon Dec 16, 2019 12:25 pm

[GPIO]
GPIO Pin Number & Pin map
gpio_pinmap.png
gpio_pinmap.png (25.51 KiB) Viewed 1128 times
The table is based on the wiki.
https://wiki.odroid.com/odroid-n2/hardw ... _2x20_pins

Before using the Android things, you should add permission for using it. Please add some lines to your project manifest file.

Code: Select all

<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO"/>
<uses-library android:name="com.google.android.things"/>
And you should add dependencies to the build.gradle file.

Code: Select all

compileOnly 'com.google.android.things:androidthings:1.0'
First, you should get PeripheralManager. You can get a GPIO instance and available list of GPIO from the manager instance.

Code: Select all

...
import com.google.android.things.pio.PeripheralManager;
import com.google.android.things.pio.Gpio;
…

PeripheralManager manager = PeripheralManager.getInstance();
And you can get an available GPIO list via getGpioList method. This method provides an available GPIO name list. So you can select from the list to use. Each pin has a name that comes from a physical pin number. yes, GPIO pin name is pin number. You can get GPIO instance through oepnGpio method with pin name by parameter.

Code: Select all

...
List<String> gpioList = manager.getGpioList();

Gpio gpio = manager.openGpio(gpioList.get(0));
// or Gpio gpio = manager.openGpio(“7”);
...
In this example, I will introduce how to use a GPIO pin as an output. In the example, I want to use pin #7 as output and if I push the button of application, led that connected to GPIO pin #7 will be lighting. Like above, after getting a GPIO instance, you can set the direction IO of the GPIO pin. You can set direction by setDirection method and direction values are DIRECTION_IN, DIRECTION_OUT_INITIALLY_HIGH and DIRECTION_OUT_INITIALLY_LOW. I chose DIRECTION_OUT_INITIALLY_LOW to make GPIO value low.
Then you can set value via the setValue method. If you want to make output value too high or 1, You should pass the True parameter. or not, you pass the false parameter as low or 0.
In this example, I get input from the application's button. So when you click the button a led light.

Code: Select all

…
gpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
Switch gpioSwitch = find ViewById(R.id.gpio_switch);

gpioSwitch.setOnClickListener(new View.OnClickListener() {
	@Override
	public void onClick(View v) {
		try {
			Switch gpioSwitch = (Switch) v;
			if (gpioSwitch.isChecked()) {
				gpio.setValue(true);

			} else {
				gpio.setValue(false);
			}
		} catch (IOException io) {
			io.printStackTrace();
		}
	}
});
…
The Android Things also provide other many methods like getValue, setActiveType, setEdgeTriggerType and registerGpioCallback. You can learn about it from the official web page. However, The odroid still does not provide registerGpioCallback properly. In particular, Callback configuration using Handler has not been implemented yet. I hope it is implemented.

GPIO method reference - https://developer.android.com/reference ... s/pio/Gpio

+EDITED: Add manifest line for adding permission.
Last edited by Luke.go on Mon Jan 06, 2020 2:40 pm, edited 8 times in total.
These users thanked the author Luke.go for the post:
rooted (Mon Dec 16, 2019 12:45 pm)

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Mon Dec 16, 2019 12:25 pm

things_gpio_out_example_bb.png
things_gpio_out_example_bb.png (252.41 KiB) Viewed 1146 times
[GPIO OFF]
Screenshot_20191211-091410.png
Screenshot_20191211-091410.png (59.87 KiB) Viewed 1146 times
IMG-1724.jpg
IMG-1724.jpg (350.84 KiB) Viewed 1146 times
[GPIO ON]
Screenshot_20191211-091418.png
Screenshot_20191211-091418.png (64.08 KiB) Viewed 1146 times
IMG-1725.jpg
IMG-1725.jpg (349.94 KiB) Viewed 1146 times
You can control I2C and PWM like this way. Please check an example from my github. Also you can learn about each peripheral api from web site.

I2C - https://developer.android.com/things/sdk/pio/i2c
PWM - https://developer.android.com/things/sdk/pio/pwm

I hope it will help you use the peripherals easily!
Last edited by Luke.go on Mon Dec 16, 2019 1:46 pm, edited 1 time in total.

User avatar
rooted
Posts: 7126
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 381 times
Been thanked: 105 times
Contact:

Re: Android Things

Unread post by rooted » Mon Dec 16, 2019 12:45 pm

Wow this is very promising work, I look forward to trying this out over the Christmas holidays.

This is going to really make Android more serviceable for makers!
These users thanked the author rooted for the post:
Luke.go (Tue Dec 17, 2019 2:21 pm)

joerg
Posts: 924
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2
Location: Germany
Has thanked: 11 times
Been thanked: 27 times
Contact:

Re: Android Things

Unread post by joerg » Wed Dec 18, 2019 1:43 am

Hello Luke.go,
first of all let me say that it is very impressive what you have done.
Sadly I cannot open the peripheral manager. I have made an initial app, only try to open the gpio list. The app compiles, but I get this error right after start:

Code: Select all

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManager
I guess that the permission <uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" /> is unknown. Android shows that are no premissions are used by my app.
Could it be that your reverse engineered libraries of Android Things are missing?

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Wed Dec 18, 2019 9:45 am

@joerg, I added USE_PERIPHERAL_IO permission.
And, you should use the latest android img of odroid-N2.
I did nothing for other board yet. :(

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Thu Dec 19, 2019 11:06 am

Oh, Before do above the my example, you should add belows to your manifest.

<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO"/>
<uses-library android:name="com.google.android.things"/>
like this -> https://github.com/androidthings/sample ... nifest.xml

and you shuold add dependencies to a build.gradle file.
compileOnly 'com.google.android.things:androidthings:1.0'

please check my example repos. :)

joerg
Posts: 924
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2
Location: Germany
Has thanked: 11 times
Been thanked: 27 times
Contact:

Re: Android Things

Unread post by joerg » Fri Dec 20, 2019 1:31 am

OK. Thank you.
Yes I looked at your manifest already. But right now I can't try again, I'm on buisness trip.
At weekend I will try.
These users thanked the author joerg for the post:
Luke.go (Fri Dec 20, 2019 11:51 am)

joerg
Posts: 924
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2
Location: Germany
Has thanked: 11 times
Been thanked: 27 times
Contact:

Re: Android Things

Unread post by joerg » Sun Dec 22, 2019 2:27 am

Hello @Luke.go,
yes, this was missing in my manifest:

Code: Select all

<uses-library android:name="com.google.android.things"/>
Inputs and outputs are working.
But I tried to assign interrupt callback to the inputs, without success. I assume that it is not implemented yet?

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Fri Jan 03, 2020 9:30 am

joerg wrote:
Sun Dec 22, 2019 2:27 am
Hello @Luke.go,
yes, this was missing in my manifest:

Code: Select all

<uses-library android:name="com.google.android.things"/>
Inputs and outputs are working.
But I tried to assign interrupt callback to the inputs, without success. I assume that it is not implemented yet?
Did you teste registerGpioCallback(GpioCallback parameter) method?
It maybe work. But with Handler parameter, it doesn't. :(

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Fri Jan 03, 2020 6:11 pm

Luke.go wrote:
Fri Jan 03, 2020 9:30 am
joerg wrote:
Sun Dec 22, 2019 2:27 am
Hello @Luke.go,
yes, this was missing in my manifest:

Code: Select all

<uses-library android:name="com.google.android.things"/>
Inputs and outputs are working.
But I tried to assign interrupt callback to the inputs, without success. I assume that it is not implemented yet?
Did you teste registerGpioCallback(GpioCallback parameter) method?
It maybe work. But with Handler parameter, it doesn't. :(
I hope that next version fixed the problem. :)

joerg
Posts: 924
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2
Location: Germany
Has thanked: 11 times
Been thanked: 27 times
Contact:

Re: Android Things

Unread post by joerg » Mon Jan 06, 2020 3:13 am

Hello Luke.go,
sadly I can't try it further. I've made from the N2 an All-In-One PC for my 11y old daughter. She is happy. :)

Would it be a big work to port Android Things to the C2 Marshmallow? If you give me a hint where to find your ported libraries, I could try it by myself.

And this is the code I tried, it never was called from interrupt:

Code: Select all

    private GpioCallback gpioCallback = new GpioCallback() {
        @Override
        public boolean onGpioEdge(Gpio gpio) {
            // Read the pin state
            final String strGpio = gpio.getName();
            Log.i(TAG, "GPIO changed, " + strGpio);
            try {
                if (gpio.getValue()) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            CheckBox cb = findViewById(Integer.valueOf(strGpio) + 10000);
                            if (cb != null) cb.setChecked(true);
                        }
                    });
                } else {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            CheckBox cb = findViewById(Integer.valueOf(strGpio) + 10000);
                            if (cb != null) cb.setChecked(false);
                        }
                    });
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            // Continue listening for more interrupts
            return true;
        }

        @Override
        public void onGpioError(Gpio gpio, int error) {
            Log.w(TAG, gpio + ": Error event " + error);
        }
    };
And this to setup the gpio:

Code: Select all

           gpio = manager.openGpio(strGpio);
           gpio.setDirection(Gpio.DIRECTION_IN);
           gpio.setActiveType(Gpio.ACTIVE_HIGH);
           gpio.setEdgeTriggerType(Gpio.EDGE_BOTH);
           gpio.registerGpioCallback(gpioCallback);

User avatar
mad_ady
Posts: 7090
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 305 times
Been thanked: 209 times
Contact:

Re: Android Things

Unread post by mad_ady » Mon Jan 06, 2020 4:14 am

I've made from the N2 an All-In-One PC for my 11y old daughter. She is happy. Image
Sorry for the offtopic, but I'd like to know more. What OS are you using and what is she mostly using it for? Web apps? What about gaming requirements, or isn't she into gaming?

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Mon Jan 06, 2020 9:37 am

joerg wrote:
Mon Jan 06, 2020 3:13 am
Hello Luke.go,
sadly I can't try it further. I've made from the N2 an All-In-One PC for my 11y old daughter. She is happy. :)

Would it be a big work to port Android Things to the C2 Marshmallow? If you give me a hint where to find your ported libraries, I could try it by myself.

And this is the code I tried, it never was called from interrupt:

Code: Select all

    private GpioCallback gpioCallback = new GpioCallback() {
        @Override
        public boolean onGpioEdge(Gpio gpio) {
            // Read the pin state
            final String strGpio = gpio.getName();
            Log.i(TAG, "GPIO changed, " + strGpio);
            try {
                if (gpio.getValue()) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            CheckBox cb = findViewById(Integer.valueOf(strGpio) + 10000);
                            if (cb != null) cb.setChecked(true);
                        }
                    });
                } else {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            CheckBox cb = findViewById(Integer.valueOf(strGpio) + 10000);
                            if (cb != null) cb.setChecked(false);
                        }
                    });
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            // Continue listening for more interrupts
            return true;
        }

        @Override
        public void onGpioError(Gpio gpio, int error) {
            Log.w(TAG, gpio + ": Error event " + error);
        }
    };
And this to setup the gpio:

Code: Select all

           gpio = manager.openGpio(strGpio);
           gpio.setDirection(Gpio.DIRECTION_IN);
           gpio.setActiveType(Gpio.ACTIVE_HIGH);
           gpio.setEdgeTriggerType(Gpio.EDGE_BOTH);
           gpio.registerGpioCallback(gpioCallback);
Yeah.. that is bug. :cry:
I can reproduce that, and I also can't make interrupt.

You can make it work with EDGE_RISING or EDGE_FALLING. :)
And... that works like EDGE_BOTH. :oops:

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Mon Jan 06, 2020 11:53 am

Luke.go wrote:
Mon Jan 06, 2020 9:37 am
joerg wrote:
Mon Jan 06, 2020 3:13 am
Hello Luke.go,
sadly I can't try it further. I've made from the N2 an All-In-One PC for my 11y old daughter. She is happy. :)

Would it be a big work to port Android Things to the C2 Marshmallow? If you give me a hint where to find your ported libraries, I could try it by myself.

And this is the code I tried, it never was called from interrupt:

Code: Select all

    private GpioCallback gpioCallback = new GpioCallback() {
        @Override
        public boolean onGpioEdge(Gpio gpio) {
            // Read the pin state
            final String strGpio = gpio.getName();
            Log.i(TAG, "GPIO changed, " + strGpio);
            try {
                if (gpio.getValue()) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            CheckBox cb = findViewById(Integer.valueOf(strGpio) + 10000);
                            if (cb != null) cb.setChecked(true);
                        }
                    });
                } else {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            CheckBox cb = findViewById(Integer.valueOf(strGpio) + 10000);
                            if (cb != null) cb.setChecked(false);
                        }
                    });
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            // Continue listening for more interrupts
            return true;
        }

        @Override
        public void onGpioError(Gpio gpio, int error) {
            Log.w(TAG, gpio + ": Error event " + error);
        }
    };
And this to setup the gpio:

Code: Select all

           gpio = manager.openGpio(strGpio);
           gpio.setDirection(Gpio.DIRECTION_IN);
           gpio.setActiveType(Gpio.ACTIVE_HIGH);
           gpio.setEdgeTriggerType(Gpio.EDGE_BOTH);
           gpio.registerGpioCallback(gpioCallback);
Yeah.. that is bug. :cry:
I can reproduce that, and I also can't make interrupt.

You can make it work with EDGE_RISING or EDGE_FALLING. :)
And... that works like EDGE_BOTH. :oops:
Please test it with updating dtbs files :)
meson64_odroidn2_android.zip
(18.8 KiB) Downloaded 6 times
These users thanked the author Luke.go for the post:
joerg (Mon Jan 06, 2020 2:12 pm)

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Wed Jan 15, 2020 10:32 am

[I2C]
Available I2C Table
I2C_pintable.png
I2C_pintable.png (5.72 KiB) Viewed 319 times
You can also use I2C on the ODROID board with Android things. You can use any I2C API provided by the Android things. The Android Things supports various sizes of data transmission, byte, word and buffered data.

I ported the Weather board 2(https://www.hardkernel.com/product-category/sensor/) example to Android with Android things. Also I ported I2C display(https://www.hardkernel.com/product-category/display/).
Like other familiar I2C devices, both of above devices are connected with 4 wires, Voltage, Ground, I2C SDA and I2C SCL. In the examples, I connected I2C wires to the I2C-2.

[Weather Board 2 Diagram]
weather_board_n2.png
weather_board_n2.png (186.17 KiB) Viewed 319 times
[I2C LCD Diagram]
odroid-n2-i2c-lcd.png
odroid-n2-i2c-lcd.png (58.75 KiB) Viewed 319 times
Most of pre-procedure are same to GPIO procedure. Add permission to the manifest, import and call the instance of PeripheralManager to the project source code. But you do not need to get a GPIO instance. You need to call the openI2cDevice method to get the I2C device instance.

Code: Select all

...
List<String> i2cBusList = manager.getI2cBusList();

I2cDevice device  = manager.openI2cDevice(i2cBusList.get(0), I2C_DEVICE_ADDRESS);
// or i2cDevice device = manager.openI2cDevice(“I2C-2”, I2C Device Address);
…
The I2C Interface names are I2C-2 and I2C-3. Each I2C interface consists of pins 3,5 and pins 27, 28. When you get the I2C bus device, you should set the I2C device address for each I2C chip. In this case, a weather board2 is consist of two I2C chip. so I create two I2C device instance. One instance is linked by 0x76 to the BME280. The chip offers temperature, pressure and humidity values. And the other instance is linked by 0x60 to the SI1132. The chip offers UV, Visible and IR values. And I2C LCD has one I2C chip, so I create one I2C instance. It linked by 0x27 for control the LCD. Like this, you should create I2C device instance for the each device with their own address.

Through the I2C instance, you can communicate with the device. Android things provide many methods. For reading the data from a device, it provide read, readRegBuffer, readRegByte and readRegWord method. Also for writing data to device, it provide write, writeRegBuffer, writeRegByte and writeRegWord.
The Android Things official website provides a lot of information.

I2C Device method reference -
https://developer.android.com/reference ... ce#summary

By using the I2C API, I build a wrapper class for weather board2 and I2C LCD. Here is a part of the example code to read and write data with the Android things API.

Code: Select all

…
private void softrst() throws IOException {
	device.writeRegByte(reg.RST, POWER_MODE.SOFT_RESET_CODE);
}

private byte getPowerMode() throws IOException {
	return (byte) (device.readRegByte(reg.CTRL_MEAS) & 0b11);
}
...
The code is part of BME280.java. First method is called to soft reset the chip and second method is called to get chip’s power mode. Each API’s first parameter is address of register in the chip. On the write method, second parameter is usually the data to transfer. also on the read method, second parameter is usually not exist. But if you want to read data by buffer, you need buffer to read and the buffer is passed as a second parameter.

You can test or use the project. Here is the link.

Weather board2 with android things example - https://github.com/xiane/thingsGpioExam ... ther_board

I2C LCD with android things example - https://github.com/xiane/thingsGpioExample/tree/i2c_lcd
These users thanked the author Luke.go for the post:
rooted (Thu Jan 16, 2020 12:23 am)

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Wed Jan 15, 2020 10:34 am

[Weather board 2 Hardware connection]
wb2_a_things.jpg
wb2_a_things.jpg (478.33 KiB) Viewed 318 times
[weather board 2 Output Result]
Screenshot_20200106-045534.png
Screenshot_20200106-045534.png (84.54 KiB) Viewed 318 times
[I2C LCD hardware connection and result]
i2c_lcd_1.jpg
i2c_lcd_1.jpg (310.58 KiB) Viewed 318 times
i2c_lcd_2.jpg
i2c_lcd_2.jpg (309.54 KiB) Viewed 318 times
These users thanked the author Luke.go for the post:
rooted (Thu Jan 16, 2020 12:24 am)

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Wed Jan 15, 2020 10:37 am

PWM

Available PWM Table
PWM_pintable.png
PWM_pintable.png (3.99 KiB) Viewed 317 times
The android Things also support the PWM. There is many methods to configure and control the PWM interface. You can set the PWM Frequency via setPwmFrequency. Before enabling the pin, you must set frequency via this method. Also you can set PWM duty cycle by setPwmDutyCycle between 0 and 100. Frequency and duty cycle settings can be set in both enabled and disabled state and will be remembered.
Please check the Reference.
https://developer.android.com/things/sdk/pio/pwm

Here is PWM testing project. In this example, you can turn on and off a PWM pin. and change duty cycle via progress bar on the Application.
https://github.com/xiane/thingsGpioExample/tree/pwm

[PWM OFF state]
Screenshot_pwm_off.png
Screenshot_pwm_off.png (61.07 KiB) Viewed 317 times
pwm_led_off.jpg
pwm_led_off.jpg (358.99 KiB) Viewed 317 times
pwm_led_scope_off.jpg
pwm_led_scope_off.jpg (462.68 KiB) Viewed 317 times

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Wed Jan 15, 2020 10:38 am

[PWM ON 50%]
Screenshot_pwm_on_2.png
Screenshot_pwm_on_2.png (65.84 KiB) Viewed 317 times
pwm_led_on_2.jpg
pwm_led_on_2.jpg (357.18 KiB) Viewed 317 times
pwm_led_scope_on_2.jpg
pwm_led_scope_on_2.jpg (453.76 KiB) Viewed 317 times
These users thanked the author Luke.go for the post:
odroid (Wed Jan 15, 2020 10:56 am)

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things

Unread post by Luke.go » Wed Jan 15, 2020 10:38 am

[PWM ON 100%]
Screenshot_pwm_on_3.png
Screenshot_pwm_on_3.png (62.69 KiB) Viewed 317 times
pwm_led_on_3.jpg
pwm_led_on_3.jpg (363.98 KiB) Viewed 317 times
pwm_led_scope_on_3.jpg
pwm_led_scope_on_3.jpg (475.38 KiB) Viewed 317 times

kafan1986
Posts: 126
Joined: Tue Feb 27, 2018 8:05 am
languages_spoken: english
Has thanked: 5 times
Been thanked: 7 times
Contact:

Re: Android Things [ADD I2C, PWM examples]

Unread post by kafan1986 » Thu Jan 16, 2020 12:20 am

@Luke I am currently using one of the 5V pin and Ground pin to light some LEDs, which gets switched on when the system gets powered ON. Now, I am planning to move the LEDs, so that they can be controlled within the app using your framework. Can you tell me the output voltage of GPIO pins? Is it 5V or 3.3V?

User avatar
tobetter
Posts: 4426
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 66 times
Been thanked: 294 times
Contact:

Re: Android Things [ADD I2C, PWM examples]

Unread post by tobetter » Thu Jan 16, 2020 12:46 am

kafan1986 wrote:
Thu Jan 16, 2020 12:20 am
@Luke I am currently using one of the 5V pin and Ground pin to light some LEDs, which gets switched on when the system gets powered ON. Now, I am planning to move the LEDs, so that they can be controlled within the app using your framework. Can you tell me the output voltage of GPIO pins? Is it 5V or 3.3V?
The voltage at GPIO pins on ODROID-N2 are all 3.3V

User avatar
FntX
Posts: 61
Joined: Mon Jun 03, 2019 7:15 pm
languages_spoken: english, german
ODROIDs: N2
Has thanked: 7 times
Been thanked: 4 times
Contact:

Re: Android Things [ADD I2C, PWM examples]

Unread post by FntX » Thu Jan 16, 2020 5:22 pm

Sorry for asking but I'm a little bit confused. Does that mean we now can access and use the android things API from inside the full fledged android OS?

User avatar
rooted
Posts: 7126
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 381 times
Been thanked: 105 times
Contact:

Re: Android Things [ADD I2C, PWM examples]

Unread post by rooted » Thu Jan 16, 2020 5:26 pm

FntX wrote:Sorry for asking but I'm a little bit confused. Does that mean we now can access and use the android things API from inside the full fledged android OS?
Yes

User avatar
FntX
Posts: 61
Joined: Mon Jun 03, 2019 7:15 pm
languages_spoken: english, german
ODROIDs: N2
Has thanked: 7 times
Been thanked: 4 times
Contact:

Re: Android Things [ADD I2C, PWM examples]

Unread post by FntX » Thu Jan 16, 2020 5:38 pm

rooted wrote:
Thu Jan 16, 2020 5:26 pm
FntX wrote:Sorry for asking but I'm a little bit confused. Does that mean we now can access and use the android things API from inside the full fledged android OS?
Yes
Great!
What a time to be alive. This opens a truckload of possibilities!

Luke.go
Posts: 393
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 11 times
Been thanked: 29 times
Contact:

Re: Android Things [ADD I2C, PWM examples]

Unread post by Luke.go » Thu Jan 16, 2020 5:42 pm

FntX wrote:
Thu Jan 16, 2020 5:22 pm
Sorry for asking but I'm a little bit confused. Does that mean we now can access and use the android things API from inside the full fledged android OS?
You can use Peripheral I/O APIs of the android things except SPI and UART. :D
This 2 kind of peripherals are not implemented yet. :(
AND It just work on ODROID-N2. :twisted:
These users thanked the author Luke.go for the post:
rooted (Thu Jan 16, 2020 6:20 pm)

Post Reply

Return to “Android”

Who is online

Users browsing this forum: No registered users and 1 guest