# analogRead problem

**URL:** <https://community.particle.io/t/analogread-problem/3351>\
**Category:** Firmware\
**Created:** [March 10, 2014, 8:43pm UTC](https://community.particle.io/t/analogread-problem/3351 "2014-03-10T20:43:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![richlyon](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@richlyon](https://community.particle.io/u/richlyon)\
**Post date:** [March 10, 2014, 8:43pm UTC](https://community.particle.io/t/analogread-problem/3351/1 "2014-03-10T20:43:15Z")

</div>

```
voltage_temperature = analogRead(A0);

```

generates the correct value for `voltage_temperature`.

```
voltage_temperature = analogRead(A0);
voltage_light = analogRead(A7);

```

causes `voltage_temperature` value to double.

Can anyone advise what might be happening to cause reading one pin to affect another (there is nothing connected to A7 that might be altering A0’s voltage).

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [March 10, 2014, 9:00pm UTC](https://community.particle.io/t/analogread-problem/3351/2 "2014-03-10T21:00:01Z")

</div>

Hi @richlyon

There were some problems with analogRead() that I think have largely been fixed in the current master for local build but are only partially fixed in the “Sparkulator” web IDE.

How are you compiling your code?

---

<div class="post-metadata">

**Author:** ![richlyon](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@richlyon](https://community.particle.io/u/richlyon)\
**Post date:** [March 10, 2014, 10:47pm UTC](https://community.particle.io/t/analogread-problem/3351/3 "2014-03-10T22:47:58Z")

</div>

Using the online build facility

---

<div class="post-metadata">

**Author:** ![dega](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@dega](https://community.particle.io/u/dega)\
**Post date:** [March 10, 2014, 11:10pm UTC](https://community.particle.io/t/analogread-problem/3351/4 "2014-03-10T23:10:31Z")

</div>

I have the same problem. Ok If i read just one analog input, but if you read two analog inputs i get completely wrong values.

Compiled with command line & the IDE, I got the same result in both cases.

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [March 10, 2014, 11:39pm UTC](https://community.particle.io/t/analogread-problem/3351/5 "2014-03-10T23:39:04Z")

</div>

Hi @dega and @richlyon

This is unfortunately a known problem and the fix is already in place in the lastest "master" branch, so if you can build locally you can get the fix right now. I am sure that the fix will make it way to the "compile-server2" branch used by the web IDE when it is fully tested by Spark.

Just for reference, here is the thread where this got explored and fixed in "Odd analog readings (part 2)":

> [@Odd analog readings (part 2)](https://community.particle.io/t/odd-analog-readings-part-2/2718/34):
>
> @bko, Provided a fix for the extra zero in the converted data by:1)Changing the DMA mode from "circular" to "normal"2)Enabling ADC2 external trigger conversion for each analogRead3)Reset the buffer and DMA counter before starting the ADC-DMA command
> 
> Commt : [#137 Fixed bug related to odd analog readings · particle-iot/device-os@b7ce24a · GitHub](https://github.com/spark/core-firmware/commit/b7ce24a4fb2dfe4f90e597e3a0f568f9ae098cfe)

---

<div class="post-metadata">

**Author:** ![richlyon](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@richlyon](https://community.particle.io/u/richlyon)\
**Post date:** [March 11, 2014, 8:05pm UTC](https://community.particle.io/t/analogread-problem/3351/6 "2014-03-11T20:05:13Z")

</div>

Thanks @bko. BTW - I didn’t realise you could build locally!

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [March 11, 2014, 8:12pm UTC](https://community.particle.io/t/analogread-problem/3351/7 "2014-03-11T20:12:33Z")

</div>

Hi @richlyon

See this thread for a great how-to on building locally.

> **[The Spark Core Firmware](https://community.particle.io/t/the-spark-core-firmware/532)**
>
> The Spark Core Firmware This firmware depends on two other libraries: the Spark Common Library and the Spark Communication Library Download and Install Dependencies Download and Build Repositories Edit and Rebuild Flash It! 1. Download and Install...
