Difference between revisions of "Rotary encoder with GPIOs"

From ArmadeusWiki
Jump to: navigation, search
(Created page with "{{Under_Construction}} =Introduction= This page will explain you how to drive a rotary encoder connected to GPIOs of your APF/OPOS. =Hardware= The instructions were tested o...")
 
(Hardware)
 
(4 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
=Hardware=
 
=Hardware=
 
The instructions were tested on [[OPOS6ULDev]] where rotary encoder is connected to GPIOs on RPi compatible connector:
 
The instructions were tested on [[OPOS6ULDev]] where rotary encoder is connected to GPIOs on RPi compatible connector:
Encoder || RPi connector
+
{| border="1" cellpadding="5" cellspacing="0" summary="Restart of NFS server depending on your distribution"
+ || 1
+
|- style="background:#efefef;"
GND || 6
+
! Encoder !! Pin number <br>on RPi connector !! Function
SW ||
+
|-
DT 32 ||
+
| + || 1 || Power
CLK 40 ||
+
|-
 +
| GND || 6 || GND
 +
|-
 +
| SW || 38 (with 4.7k pullup) || Key press
 +
|-
 +
| DT || 32 ||  
 +
|-
 +
| CLK || 40 ||
 +
|}
  
 
=Software=
 
=Software=
Device Tree need to be adapted:
+
* Device tree need to be adapted:
 
<source lang=diff>
 
<source lang=diff>
 
         gpio-keys {
 
         gpio-keys {
Line 61: Line 69:
 
...
 
...
 
</source>
 
</source>
 +
 +
* you can then replace ''/boot/imx6ul-opos6uldev.dtb'' file on your rootfs and reboot
 +
* Rotary should then be recognized by ''evtest'' tool:
 +
<pre class="apf">
 +
# evtest
 +
No device specified, trying to scan all of /dev/input/event*
 +
Available devices:
 +
/dev/input/event0:      iMX6UL Touchscreen Controller
 +
/dev/input/event1:      rotary1
 +
...
 +
Select the device event number [0-6]: 1
 +
</pre>
  
 
=Links=
 
=Links=
  
 
[[Category:Multimedia]]
 
[[Category:Multimedia]]

Latest revision as of 15:56, 14 March 2017

Page under construction... Construction.png Informations on this page are not guaranteed !!

Introduction

This page will explain you how to drive a rotary encoder connected to GPIOs of your APF/OPOS.

Hardware

The instructions were tested on OPOS6ULDev where rotary encoder is connected to GPIOs on RPi compatible connector:

Encoder Pin number
on RPi connector
Function
+ 1 Power
GND 6 GND
SW 38 (with 4.7k pullup) Key press
DT 32
CLK 40

Software

  • Device tree need to be adapted:
        gpio-keys {
                compatible = "gpio-keys";
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_gpio_keys>;

                user-button {
                        label = "User button";
                        gpios = <&gpio2 11 GPIO_ACTIVE_LOW>;
                        linux,code = <BTN_MISC>;
                        wakeup-source;
                };

+                rotary1_button {
+                        label = "rotary1_button";
+                        gpios = <&gpio5 2 GPIO_ACTIVE_LOW>;
+                        debounce-interval = <10>;
+                        linux,code = <28>;
+                };
        }

+        rotary1 {
+                compatible = "rotary-encoder";
+                pinctrl-names = "default";
+                pinctrl-0 = <&pinctrl_rotary1>;
+                gpios = <&gpio5 0 1>, <&gpio5 1 1>;
+                linux,axis = <1>; /* REL_Y */
+                rotary-encoder,relative-axis;
+        };

...
&iomuxc {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_gpios>;

...

+        pinctrl_rotary1: rotary1grp {
+                fsl,pins = <
+                        MX6UL_PAD_SNVS_TAMPER0__GPIO5_IO00      0x0b0b0
+                        MX6UL_PAD_SNVS_TAMPER1__GPIO5_IO01      0x0b0b0
+                >;
+        };

...
  • you can then replace /boot/imx6ul-opos6uldev.dtb file on your rootfs and reboot
  • Rotary should then be recognized by evtest tool:
# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:      iMX6UL Touchscreen Controller
/dev/input/event1:      rotary1
...
Select the device event number [0-6]: 1

Links