<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[esp32_adc2gpio not declared in pins_arduino.h for M5StickCPlus]]></title><description><![CDATA[<p dir="auto">The file <code>pins_arduino.h</code> in the 2.0.5 board files for the M5Stick-C-Plus contains a macro definition that refers to an array <code>esp32_adc2gpio</code> that appears to be undefined and causes a compile error.  I first ran into the problem when trying to compile a Blynk Quickstart example.</p>
<p dir="auto">Comparing this with the <code>pins_arduino.h</code> files for other M5Stack devices including Atom, Stick-C, and Core2, I noticed that they do not refer to <code>esp32_adc2gpio</code>, but instead call a function <code>analogChannelToDigitalPin</code> that compiles properly.  Is this a bug for Stick-C-Plus and should it call the same function as the Stick-C and other devices?  Any insights/comments would be appreciated!</p>
<p dir="auto">Here's a bunch more detail on what I've found.</p>
<p dir="auto">Here's the macro definition from the file <code>packages\m5stack\hardware\esp32\2.0.5\variants\m5stick_c_plus\pins_arduino.h</code></p>
<pre><code>#define analogInputToDigitalPin(p)  (((p)&lt;20)?(esp32_adc2gpio[(p)]):-1)
</code></pre>
<p dir="auto">Note that the same macro is also used in the <code>pins_arduino.h</code> files for several other device variants, including <code>m5stack_paper</code> and <code>m5stack_tough</code>.</p>
<p dir="auto">Here's a simple sketch that causes a compile error related that uses the macro:</p>
<pre><code>void setup() {
  analogInputToDigitalPin(5);
}

void loop() {
}
</code></pre>
<p dir="auto">Here's the error I get:</p>
<pre><code>C:\Users\xxx\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.0.5\variants\m5stick_c_plus/pins_arduino.h:10:48: error: 'esp32_adc2gpio' was not declared in this scope
 #define analogInputToDigitalPin(p)  (((p)&lt;20)?(esp32_adc2gpio[(p)]):-1)
</code></pre>
<p dir="auto">When I searched the entire m5stack for <code>esp32_adc2gpio</code> using <code>grep -r</code>, it wasn't anywhere to be found.</p>
<p dir="auto">If I change the device to M5Stack-Atom, it compiles fine.</p>
<p dir="auto">I looked at the <code>pins_arduino.h</code> files for a few other device variants and saw that they use a different definition for the macro.  For variants <code>m5stack_atom</code> and <code>m5stick_c</code>, the macro <code>analogInputToDigitalPin</code> is defined as:</p>
<pre><code>#define analogInputToDigitalPin(p)  (((p)&lt;20)?(analogChannelToDigitalPin(p)):-1)
</code></pre>
<p dir="auto">The function <code>analogChannelToDigitalPin</code> is defined in <code>packages\m5stack\hardware\esp32\2.0.5\cores\esp32\esp32-hal-gpio.c</code> This function refers to another array called <code>adc_channel_io_map</code> that does appear to be defined in the esp32 library archive files according to grep:</p>
<pre><code>(base) PS C:\Users\xxx\Downloads\m5stack-2.0.5\m5stack-2.0.5&gt; grep -r adc_channel_io_map .
./cores/esp32/esp32-hal-gpio.c:                if (adc_channel_io_map[i][j] == pin) {
./cores/esp32/esp32-hal-gpio.c:    return adc_channel_io_map[adc_unit][adc_chan];
./tools/sdk/esp32/include/soc/include/soc/adc_periph.h:extern const int adc_channel_io_map[SOC_ADC_PERIPH_NUM][SOC_ADC_MAX_CHANNEL_NUM];
Binary file ./tools/sdk/esp32/lib/libdriver.a matches
Binary file ./tools/sdk/esp32/lib/libhal.a matches
Binary file ./tools/sdk/esp32/lib/libsoc.a matches
</code></pre>
<p dir="auto">Perhaps the version of the macro <code>analogInputToDigitalPin</code> for the Stick-C-Plus is obsolete and should replaced with the version that calls <code>analogChannelToDigitalPin</code>?  Or maybe I'm missing something else?</p>
]]></description><link>https://community.m5stack.com/topic/4803/esp32_adc2gpio-not-declared-in-pins_arduino-h-for-m5stickcplus</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 11:29:20 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/4803.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 Nov 2022 20:35:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to esp32_adc2gpio not declared in pins_arduino.h for M5StickCPlus on Mon, 14 Nov 2022 14:07:52 GMT]]></title><description><![CDATA[<p dir="auto">I replaced the macro <code>analogInputToDigitalPin(p)</code>  in the file packages\m5stack\hardware\esp32\2.0.5\variants\m5stick_c_plus\pins_arduino.h and it seemed to work:</p>
<pre><code>//#define analogInputToDigitalPin(p)  (((p)&lt;20)?(esp32_adc2gpio[(p)]):-1)
#define analogInputToDigitalPin(p)  (((p)&lt;20)?(analogChannelToDigitalPin(p)):-1)
</code></pre>
<p dir="auto">I tested it with the following sketch, which printed the correct sequence of mappings (36, 37, 38, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26):</p>
<pre><code>#include &lt;M5StickCPlus.h&gt;
void setup() {
  M5.begin();
  M5.Lcd.fillScreen(RED);
  for (uint8_t i = 0;  i &lt; 20;  i++) {
    Serial.println(analogInputToDigitalPin(i));
  }
}

void loop() {
}
</code></pre>
<p dir="auto">With this change, I was able to get the Blynk Quickstart example working with my M5StickCPlus, which is what led me down this rabbit hole in the first place!</p>
]]></description><link>https://community.m5stack.com/post/19297</link><guid isPermaLink="true">https://community.m5stack.com/post/19297</guid><dc:creator><![CDATA[makingwaves]]></dc:creator><pubDate>Mon, 14 Nov 2022 14:07:52 GMT</pubDate></item></channel></rss>