<?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[MicroPython unstable ADC readings +&#x2F;- 5% between reads]]></title><description><![CDATA[<p dir="auto">Using Arduino, readings were stable, but with Micropython &amp; UIFlow, the ADC is unaccurate with variations up to +/- 5% between each adc0.read()</p>
<p dir="auto">Also, when M5Stack is alone, not a single pin connected, I see occasional jumps to raw 150 or more (max 4095) instead of expected steady 0.</p>
<p dir="auto">Did you experience similar behaviour ?<br />
How can we fix this ?</p>
<p dir="auto"><strong>Context</strong><br />
M5Stack Core1 + uiflow<br />
Reading voltage drop by a water pressure sensor with 4-20mA through a 147 Ohms resistance. Power is 24V switching power supply, I added a 4700µF capacitor on the PSU. Reading every 1s.</p>
<p dir="auto"><strong>Code slice (uiflow)</strong></p>
<pre><code>adc0 = machine.ADC(35)
# Maximum attenuation for 0.17 to 3.10V Range
adc0.atten(machine.ADC.ATTN_11DB)

while True:
  adc_raw = adc0.read()
  label_adcraw.setText(str(adc_raw))
  # Just for info
  # Converts the raw value to the range of the sensor (0-300cm water column pressure)
  # Values adjusted after some testing.
  height = int((((adc_raw - 530) / (3600 - 530)) * 300))
  label_height.setText(str(height))
  wait_ms(1000)
</code></pre>
<p dir="auto"><strong>Probably irrelevant details</strong></p>
<ul>
<li>TL-136 Liquid Level Sensor Detector Liquid Level Transmitter 24VDC 4-20mA Signal Output</li>
<li>Using independant PSU for the sensor and the M5Stack Core1</li>
<li>Using pin 35 for ADC</li>
</ul>
]]></description><link>https://community.m5stack.com/topic/4507/micropython-unstable-adc-readings-5-between-reads</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Mar 2026 18:22:35 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/4507.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 06 Aug 2022 11:46:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MicroPython unstable ADC readings +&#x2F;- 5% between reads on Tue, 30 Aug 2022 09:49:59 GMT]]></title><description><![CDATA[<p dir="auto">There are lots of ways to filter this type of data. The mean is one but you can also use median or an FIR filter. Take a look 🤗</p>
<p dir="auto">Fábio Dias</p>
]]></description><link>https://community.m5stack.com/post/18499</link><guid isPermaLink="true">https://community.m5stack.com/post/18499</guid><dc:creator><![CDATA[bexybot]]></dc:creator><pubDate>Tue, 30 Aug 2022 09:49:59 GMT</pubDate></item><item><title><![CDATA[Reply to MicroPython unstable ADC readings +&#x2F;- 5% between reads on Sun, 28 Aug 2022 13:43:20 GMT]]></title><description><![CDATA[<p dir="auto">Replying to myself.</p>
<p dir="auto">The solution is to read many times, and take the mean.</p>
<p dir="auto">8000 reads takes about 31.7s with the default 2ms pause at the end of the UIFlow script, which is good enough for me. (Water level sensor). So I have a value published on mqtt twice/minute.<br />
From 1000 reads, I get a good accuracy / measures stability.<br />
Over 4000 reads, there's no visible improvement. I do not have more than 0.25% between 2 measures.</p>
<p dir="auto">Some tips &amp; links for other people interested in this kind of sensor reading or ADC :</p>
<ul>
<li>I found the power supply combining both 24v and USB really great for this project : <a href="https://www.amazon.fr/gp/product/B09PYMBPLK/" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.amazon.fr/gp/product/B09PYMBPLK/</a></li>
<li><a href="https://w4krl.com/esp32-analog-to-digital-conversion-accuracy/" target="_blank" rel="noopener noreferrer nofollow ugc">https://w4krl.com/esp32-analog-to-digital-conversion-accuracy/</a></li>
<li><a href="https://microcontrollerslab.com/adc-esp32-measuring-voltage-example/" target="_blank" rel="noopener noreferrer nofollow ugc">https://microcontrollerslab.com/adc-esp32-measuring-voltage-example/</a></li>
</ul>
<p dir="auto">François</p>
]]></description><link>https://community.m5stack.com/post/18475</link><guid isPermaLink="true">https://community.m5stack.com/post/18475</guid><dc:creator><![CDATA[Pivert]]></dc:creator><pubDate>Sun, 28 Aug 2022 13:43:20 GMT</pubDate></item></channel></rss>