Community
cancel
Showing results for 
Search instead for 
Did you mean: 
PPang2
Novice
1,768 Views

Checking Analog 4 input pin in Linux

This example is for Analog 0, but what are the commands for Analog 4 where the Mux is on GPIO21 = 0 and GPIO29= 1, and I need to read from in_voltage4_raw?

A short explanation of how the commands works would be nice. Why are "echo -n "37" >export" creating the directory "gpio37"?

Thanks in advance..

 

 

"I do this by first set the MUX for A0 to 0, the MUX is on GPIO37:

cd /sys/class/gpio

echo -n "37" >export

cd gpio37

echo -n "out" >direction

echo -n "0" >value

The reading from the ADC:

cat /sys/bus/iio/devices/iio:device0/in_voltage0_raw"

 

4 Replies
Carlos_M_Intel
Employee
94 Views

Hi,

You can read the in_voltage4_raw by using the command: cat /sys/bus/iio/devices/iio:device0/in_voltage4_raw

The command echo -n "37" > export, creates the directory gpio37 because in the /sys/class/gpio folder you can see all the gpio's you can use to control the muxes in the board. For more information about these gpio's and muxes take a look at the table "Pin configuration options for Galileo Gen 2" in http://www.emutexlabs.com/component/content/article?id=203:getting-started-with-intel-galileo-gen-2 Gettig Started with Galileo Gen2

The raw readings on /sys/bus/iio/devices/iio:device0/ can be translated to decimal values by multiplying the value for the in_voltageX_scale value that is also located on that folder.

If you are using the image with uname –a: Linux galileo 3.8.7-yocto-standard # 1 Tue Sep 29 22:16:33 GMT 2015 i586 GNU/Linux you shouldn't need to change the muxes to be able to read the value from the in_voltage4_raw file.

From where are you getting the example:

cd /sys/class/gpio

echo -n "37" >export

cd gpio37

echo -n "out" >direction

echo -n "0" >value

Regards,

Charlie

PPang2
Novice
94 Views

Hi Charlie,

Thanks for your reply.

I am trying to find the reason why my node.js program doesn't work anymore.

I have now tested all analog input pins(a0-a5) and they all seem to work, with a little difference on A0.

When I connected A1-A5 to GND pin the readout was 0, but A0 was 4?

 

 

 

A0 by itself(with pullup)

 

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage0_raw

2980

 

A0 connected to GND pin.

 

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage0_raw

4

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage0_raw

4

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage0_raw

 

A5 to 5volt pin

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage5_raw

4092

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage5_raw

4084

 

A5 to 3.3volt pin

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage5_raw

2744

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage5_raw

2740

A5 to Gnd pin

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage5_raw

0

root@galileo:/sys/bus/iio/devices/iio:device0# cat in_voltage5_raw

0

 

 

 

What can cause this error?

 

 

"/home/root/Mlabs/IIOT_prot/main.js:30

var analogPin0 = new mraa.Aio(0); //setup access analog input Analog pin # 0 (A

^

Error: Invalid AIO pin specified - do you have an ADC?

at Object. (/home/root/Mlabs/IIOT_prot/main.js:30:18)

at Module._compile (module.js:456:26)

at Object.Module._extensions..js (module.js:474:10)

at Module.load (module.js:356:32)

at Function.Module._load (module.js:312:12)</span...

Carlos_M_Intel
Employee
94 Views

Hi,

Thanks for the information and for your results while reading the pins. I would like to know more information about this.

The last time that the code was working fine, did you update a library or did you change the state of one of the muxes?

Which MRAA version are you using?

Are you using the XDK or are you running the code on the Terminal?

What is the output of running uname -a?

Have you tried to run the AnalogReadSerial example on the Arduino IDE?

Also, could you post a part of the code you are using? Just the part related to [var analogPin0 = new mraa.Aio(0); ]

Regards,

Charlie

Carlos_M_Intel
Employee
94 Views

Hi,

Do you have updates on this? I would like to know if you had improvements in this.

Regards,

Charlie

Reply