Main Site Documentation

Cerbuino AnalogInput problem


#1

Hello,
I’ve a cerbuino with a problem reading analog input.
I’m using a


  Private _adc As Microsoft.SPOT.Hardware.AnalogInput

to read data.
I’ve a pin connected to a sensor, that seems ok. All other pins are free. But

 _adc.ReadRaw

reports something through 200 and 600… why?

Is it better to use ReadRaw or Read to sample an analog sensor?

thanks


#2

did you specify which pin?
such as _adc = new AnalogInput(FEZCerbuino.Pin.AnalogIn.A0);


#3

sure:

Hardware.Cpu.Pin.GPIO_Pin10

for the pin A0 (where I’ve the sensor connected)
and

Hardware.Cpu.Pin.GPIO_Pin8

for the pin A1 (currently not connected)


#4

readraw returns the raw ad 0-1023. where
0= 0 volts
1023=3.3 volts
so if you want the voltage you need to divide the returned value by 310


#5

Ehm, how did I explain this reading? :frowning:


? _adc.ReadRaw 
2945


#6

sorry about that it is 12 bit adc not 10 bit as i thought so the range is
0=0
4095=3.3 volts
so to get the voltage divide your value by 1240.9


#7

So, if my sensor measures a value between 0 and 12.7, the right formula to read it from cerbuino ADC, rounded to 2 decimal digits, is

 
 Return System.Math.Round(cPrecision * (_adc.ReadRaw() * 12.7 / 4095) / cPrecision

?

thanks!