analogRead problem

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).

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?

Using the online build facility

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.

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)":

4 Likes

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

1 Like

Hi @richlyon

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

3 Likes