<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>EC11 Rotary Encoder with Sensor API</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112945/ec11-rotary-encoder-with-sensor-api</link><description>I have an EC11 rotary encoder wired to my nRF52840 and I am trying to get readings from it using the sensor API. However, I&amp;#39;m having issues with (seemingly) garbage data. When I rotate one &amp;quot;click&amp;quot; I get a variety of readings. Sometimes no readings whatsoever</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 18 Jul 2024 14:33:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112945/ec11-rotary-encoder-with-sensor-api" /><item><title>RE: EC11 Rotary Encoder with Sensor API</title><link>https://devzone.nordicsemi.com/thread/494619?ContentTypeID=1</link><pubDate>Thu, 18 Jul 2024 14:33:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc0f983f-7ffe-4276-933e-22c6894a70e4</guid><dc:creator>zciwor</dc:creator><description>&lt;p&gt;This is what I needed!&lt;/p&gt;
&lt;p&gt;I got the encoder working correctly using the inputs library.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s my new .overlay file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/ {
    gnd_pins {
        compatible = &amp;quot;gpio-leds&amp;quot;;
        qdec_gnd: qdec_gnd_pin {
            gpios = &amp;lt;&amp;amp;gpio1 14 (GPIO_ACTIVE_HIGH)&amp;gt;;
            label = &amp;quot;Rotary GND&amp;quot;;
        };
        qdec_btn_gnd: qdec_btn_gnd_pin {
            gpios = &amp;lt;&amp;amp;gpio0 5 (GPIO_ACTIVE_HIGH)&amp;gt;;
            label = &amp;quot;Rotary btn GND&amp;quot;;
        };
    };
    buttons: buttons {
        compatible = &amp;quot;gpio-keys&amp;quot;;
        debounce-interval-ms = &amp;lt;50&amp;gt;;
        qdec_btn: btn_pin {
            gpios = &amp;lt;&amp;amp;gpio0 29 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)&amp;gt;;
            label = &amp;quot;Encoder switch interrupt&amp;quot;;
            zephyr,code = &amp;lt;INPUT_BTN_0&amp;gt;;
        };
    };
    qdec_btn {
        input = &amp;lt;&amp;amp;buttons&amp;gt;;
        compatible = &amp;quot;zephyr,input-longpress&amp;quot;;
        input-codes = &amp;lt;INPUT_BTN_0&amp;gt;;
        short-codes = &amp;lt;INPUT_BTN_1&amp;gt;;
        long-codes = &amp;lt;INPUT_BTN_2&amp;gt;;
        long-delay-ms = &amp;lt;1000&amp;gt;;
    };
    qdec {
        compatible = &amp;quot;gpio-qdec&amp;quot;;
        status = &amp;quot;okay&amp;quot;;
        gpios = &amp;lt;&amp;amp;gpio1 13 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)&amp;gt;,
                &amp;lt;&amp;amp;gpio1 15 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)&amp;gt;;
        steps-per-period = &amp;lt;4&amp;gt;;
        zephyr,axis = &amp;lt;INPUT_REL_WHEEL&amp;gt;;
        sample-time-us = &amp;lt;2000&amp;gt;;
        idle-timeout-ms = &amp;lt;200&amp;gt;;
    };
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;My&amp;nbsp;test main.c file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/pm/pm.h&amp;gt;
#include &amp;lt;zephyr/pm/policy.h&amp;gt;
#include &amp;lt;zephyr/pm/state.h&amp;gt;
#include &amp;lt;zephyr/pm/device.h&amp;gt;
#include &amp;lt;zephyr/input/input.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;

static const struct gpio_dt_spec qdec_gnd = GPIO_DT_SPEC_GET(DT_NODELABEL(qdec_gnd), gpios);
static const struct gpio_dt_spec qdec_btn_gnd = GPIO_DT_SPEC_GET(DT_NODELABEL(qdec_btn_gnd), gpios);

static void test_cb(struct input_event *evt)
{
        if (evt-&amp;gt;code == INPUT_REL_WHEEL)
        {
                printk(&amp;quot;z event %d\n&amp;quot;, evt-&amp;gt;value);
        }
        if (evt-&amp;gt;code == INPUT_BTN_1 &amp;amp;&amp;amp; evt-&amp;gt;value == 1)
        {
                printk(&amp;quot;short press %d\n&amp;quot;, evt-&amp;gt;value);
        }
        if (evt-&amp;gt;code == INPUT_BTN_2 &amp;amp;&amp;amp; evt-&amp;gt;value == 1)
        {
                printk(&amp;quot;long press %d\n&amp;quot;, evt-&amp;gt;value);
        }
}

INPUT_CALLBACK_DEFINE(NULL, test_cb);

int main(void)
{
        if (!gpio_is_ready_dt(&amp;amp;qdec_gnd) || !gpio_is_ready_dt(&amp;amp;qdec_btn_gnd))
        {
                printk(&amp;quot;Device not ready\n&amp;quot;);
        }

        gpio_pin_configure_dt(&amp;amp;qdec_gnd, GPIO_OUTPUT_LOW);
        gpio_pin_configure_dt(&amp;amp;qdec_btn_gnd, GPIO_OUTPUT_LOW);

        while (1)
        {
                k_sleep(K_FOREVER);
        }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And prj.conf file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Config encoder
CONFIG_INPUT=y
CONFIG_INPUT_GPIO_QDEC=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;For anyone wondering about the ground pins, here&amp;#39;s how I have my encoder connected:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/IMG_5F00_2255.jpg" /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/microknob_2D00_wiring.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Full sample project also included.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/xiao_2D00_pp.zip"&gt;devzone.nordicsemi.com/.../xiao_2D00_pp.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EC11 Rotary Encoder with Sensor API</title><link>https://devzone.nordicsemi.com/thread/494518?ContentTypeID=1</link><pubDate>Thu, 18 Jul 2024 09:22:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a306390-61d5-4822-8b27-15b1616929e6</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;I&amp;#39;m afraid that there is not much help from my side with Zephyr drivers, as we do not have much rotary encoders in our products.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Looking at&amp;nbsp;&lt;code&gt;zephyr/dts/bindings/input/gpio-qdec.yaml&lt;/code&gt; please make sure that you have configured the rotary encoder with the following&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  qdec {
          compatible = &amp;quot;gpio-qdec&amp;quot;;
          gpios = &amp;lt;&amp;amp;gpio0 14 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)&amp;gt;,
                  &amp;lt;&amp;amp;gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)&amp;gt;;
          steps-per-period = &amp;lt;4&amp;gt;;
          zephyr,axis = &amp;lt;INPUT_REL_WHEEL&amp;gt;;
          sample-time-us = &amp;lt;2000&amp;gt;;
          idle-timeout-ms = &amp;lt;200&amp;gt;;
  };&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is used in&amp;nbsp;&lt;code&gt;zephyr/samples/subsys/display/lvgl/boards/native_posix.overlay&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Does this help with your rotary encoder output? Next step would be to debug using e.g. logic analyzer to ensure the signals are correct&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Skjermbilde-2024_2D00_07_2D00_18-kl.-11.11.03.png" /&gt;&lt;/p&gt;
&lt;p&gt;Looking at the&amp;nbsp;&lt;code&gt;zephyr/samples/subsys/display/lvgl/src/main.c&lt;/code&gt; the following snippet should provide some help, and perhaps help with debugging i.e. setting break points&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#ifdef CONFIG_LV_Z_ENCODER_INPUT
	lv_obj_t *arc;
	lv_group_t *arc_group;

	arc = lv_arc_create(lv_scr_act());
	lv_obj_align(arc, LV_ALIGN_CENTER, 0, -15);
	lv_obj_set_size(arc, 150, 150);

	arc_group = lv_group_create();
	lv_group_add_obj(arc_group, arc);
	lv_indev_set_group(lvgl_input_get_indev(lvgl_encoder), arc_group);
#endif /* CONFIG_LV_Z_ENCODER_INPUT */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;zephyr/modules/lvgl/input/lvgl_encoder_input.c&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;And I assume you have been looking at the QDEC sameple (&lt;code&gt;zephyr/samples/sensor/qdec/src/main.c&lt;/code&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EC11 Rotary Encoder with Sensor API</title><link>https://devzone.nordicsemi.com/thread/494190?ContentTypeID=1</link><pubDate>Tue, 16 Jul 2024 14:18:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d65656d0-50bc-456f-8df3-510fb0e73b8f</guid><dc:creator>zciwor</dc:creator><description>&lt;p&gt;No response yet on the Zephyr channel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EC11 Rotary Encoder with Sensor API</title><link>https://devzone.nordicsemi.com/thread/494038?ContentTypeID=1</link><pubDate>Tue, 16 Jul 2024 06:13:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6be294ef-bdee-4dd0-a490-dda4451b39bc</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;No, I&amp;#39;m afraid I&amp;#39;ve had no luck so far.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you have any luck in the Zephyr channel?&lt;/p&gt;
&lt;p&gt;-Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EC11 Rotary Encoder with Sensor API</title><link>https://devzone.nordicsemi.com/thread/493991?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2024 20:05:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce2f26f5-55da-4a10-8701-0a864d995743</guid><dc:creator>zciwor</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/oys"&gt;Øyvind&lt;/a&gt;&amp;nbsp;have you had any luck identifying the issue with your encoder? I still have not been able to find an answer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EC11 Rotary Encoder with Sensor API</title><link>https://devzone.nordicsemi.com/thread/493420?ContentTypeID=1</link><pubDate>Thu, 11 Jul 2024 12:33:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b56f414-27cb-4e7f-aa83-5285b100c705</guid><dc:creator>zciwor</dc:creator><description>&lt;p&gt;Thanks for your quick response! I am on nRF Connect version 2.6.1. I can try the latest release and see if there is any difference.&lt;/p&gt;
&lt;p&gt;Unfortunately I do not have access to an oscilloscope or logic meter at this time. I will try cross-posting in the Zephyr Discord&amp;nbsp;to see if anyone has any ideas and report back.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EC11 Rotary Encoder with Sensor API</title><link>https://devzone.nordicsemi.com/thread/493363?ContentTypeID=1</link><pubDate>Thu, 11 Jul 2024 10:11:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6f051f4-395f-4a93-974f-2b88d063fea6</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What version of the nRF Connect SDK are you using? I&amp;#39;ve tested with a similar rotary encoder here but with no luck. Saw similar output and put aside. Let&amp;#39;s look into this together. Your overlay looks correct. What about the signals on the encoder, have you tried looking at these with a logic analyzer or oscilloscope? The issue is most like in the SDK.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The &lt;a href="https://discord.com/invite/Ck7jw53nU2"&gt;Zephyr Community on Discord&lt;/a&gt; might be the best chance of figuring out this issue. There are relevant discussions there e.g.&amp;nbsp;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/73529"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/73529&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>