common:android_things:pwm

Android Things with PWM

  • ODROID-C4
  • ODROID-N2
  • ODROID-M1
target
gpio readall
target
+-----+-----+---------+------+---+--- N2 ---+---+------+---------+-----+-----+
| I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
|     |     |    3.3V |      |   |  1 || 2  |   |      | 5V      |     |     |
| 493 |   8 |   SDA.2 | ALT1 | 1 |  3 || 4  |   |      | 5V      |     |     |
| 494 |   9 |   SCL.2 | ALT1 | 1 |  5 || 6  |   |      | 0V      |     |     |
| 473 |   7 |  IO.473 | ALT1 | 0 |  7 || 8  | 1 | IN   | TxD1    | 15  | 488 |
|     |     |      0V |      |   |  9 || 10 | 1 | IN   | RxD1    | 16  | 489 |
| 479 |   0 |  IO.479 |   IN | 1 | 11 || 12 | 1 | IN   | IO.492  | 1   | 492 |
| 480 |   2 |  IO.480 |   IN | 1 | 13 || 14 |   |      | 0V      |     |     |
| 483 |   3 |  IO.483 |   IN | 1 | 15 || 16 | 1 | IN   | IO.476  | 4   | 476 |
|     |     |    3.3V |      |   | 17 || 18 | 1 | IN   | IO.477  | 5   | 477 |
| 484 |  12 |    MOSI |   IN | 1 | 19 || 20 |   |      | 0V      |     |     |
| 485 |  13 |    MISO |   IN | 1 | 21 || 22 | 1 | IN   | IO.478  | 6   | 478 |
| 487 |  14 |    SCLK |   IN | 1 | 23 || 24 | 1 | IN   | CE0     | 10  | 486 |
|     |     |      0V |      |   | 25 || 26 | 0 | IN   | IO.464  | 11  | 464 |
| 474 |  30 |   SDA.3 | ALT2 | 1 | 27 || 28 | 1 | ALT2 | SCL.3   | 31  | 475 |
| 490 |  21 |  IO.490 |   IN | 1 | 29 || 30 |   |      | 0V      |     |     |
| 491 |  22 |  IO.491 |   IN | 1 | 31 || 32 | 0 | IN   | IO.472  | 26  | 472 |
| 481 |  23 |  IO.481 |   IN | 1 | 33 || 34 |   |      | 0V      |     |     |
| 482 |  24 |  IO.482 |   IN | 0 | 35 || 36 | 0 | IN   | IO.495  | 27  | 495 |
|     |  25 |   AIN.3 |      |   | 37 || 38 |   |      | 1V8     | 28  |     |
|     |     |      0V |      |   | 39 || 40 |   |      | AIN.2   | 29  |     |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| I/O | wPi |   Name  | Mode | V | Physical | V | Mode |  Name   | wPi | I/O |
+-----+-----+---------+------+---+--- N2 ---+---+------+---------+-----+-----+

PWM Hardware Pin-map

You can access each PWM pin using sysfs interface.
The following table shows the pwm pins availables.

ODROID-N2
The pwm chip number is based on the below table.
The top index show your dtbo selection.
PWM_CD Only PWM_EF Only PWM_CD & PWM_EF
PWM_CD pwmchip4 X pwmchip4
PWM_EF X pwmchip4 pwmchip8
Hardware connection Linux kernel sysfs control
PWM gpio 40-pin num. pwmchip pwm_pins export command
/sys/class/pwm/
PWM_C GPIOX.5 33 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_D GPIOX.6 35 pwmchip<num> 1 echo 1 > pwmchip<num>/export
PWM_E GPIOX.16 12 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_F GPIOX.7 15 pwmchip<num> 1 echo 1 > pwmchip<num>/export

pwmchip#NUM can be found in /sys/class/pwm/

target
root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# ls
pwmchip0  pwmchip12  pwmchip16  pwmchip4  pwmchip8
root@odroid:/sys/class/pwm#
ODROID-C4
The pwm chip number is based on the below table.
The top index show your dtbo selection.
PWM_AB Only PWM_EF Only PWM_AB & PWM_EF
PWM_AB pwmchip0 X pwmchip0
PWM_EF X pwmchip0 pwmchip4
Hardware connection Linux kernel sysfs control
PWM gpio 40-pin num. pwmchip pwm_pins export command
/sys/class/pwm/
PWM_A GPIOX.6 33 pwmchip<num> 1 echo 1 > pwmchip<num>/export
PWM_B GPIOX.19 35 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_E GPIOX.16 12 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_F GPIOX.7 15 pwmchip<num> 1 echo 1 > pwmchip<num>/export

pwmchip#NUM can be found in /sys/class/pwm/

target
root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# ls
pwmchip0  pwmchip4  pwmchip8
root@odroid:/sys/class/pwm#
ODROID-M1
The pwm chip number is based on the below table.
The top index show your dtbo selection.
PWM_1 Only PWM_2 Only PWM_9 Only PWM_1 & 2 PWM_1 & 9 PWM_2 & 9 PWM_1 & 2 & 9
PWM_1 pwmchip0 X X pwmchip0 pwmchip0 X pwmchip0
PWM_2 X pwmchip0 X pwmchip1 X pwmchip0 pwmchip1
PWM_9 X X pwmchip2 X pwmchip3 pwmchip3 pwmchip4
Hardware connection Linux kernel sysfs control
PWM gpio 40-pin num. pwmchip pwm_pins export command
/sys/class/pwm/
PWM_1 GPIO0B.5 33 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_2 GPIO0B.6 7 pwmchip<num> 0 echo 1 > pwmchip<num>/export
PWM_9 GPIO3B.2 15 pwmchip<num> 0 echo 0 > pwmchip<num>/export

pwmchip#NUM can be found in /sys/class/pwm/

target
root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# ls
pwmchip0  pwmchip1  pwmchip2  pwmchip3  pwmchip4
root@odroid:/sys/class/pwm#
2020/03/18 16:49 · luke.go

Create the Project

Android Studio → Check out project from Version Control → Git → URL: https://github.com/xiane/thingsGpioExample → Clone

Change a branch to the LED

VCS → Git → Branches → origin/pwm → Checkout As… → OK

Uploading

After changing the branch to the PWM, connect to ODROID-N2 otg port.
Click the Run 'app' Button.

  • common/android_things/pwm.txt
  • Last modified: 2022/06/27 14:39
  • by luke.go