4 Replies Latest reply on Jan 29, 2016 4:23 PM by CMata_Intel

    Checking Analog 4 input pin in Linux

    JadeDragon

      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"


        • 1. Re: Checking Analog 4 input pin in Linux
          CMata_Intel

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

          • 2. Re: Checking Analog 4 input pin in Linux
            JadeDragon

            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.<anonymous> (/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)

                at Function.Module.runMain (module.js:497:10)

                at startup (node.js:119:16)

                at node.js:935:3"


            Thanks

            plp



            • 3. Re: Checking Analog 4 input pin in Linux
              CMata_Intel

              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

              • 4. Re: Checking Analog 4 input pin in Linux
                CMata_Intel

                Hi,

                 

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

                 

                Regards,

                Charlie