8 Replies Latest reply on Jun 29, 2016 1:39 PM by CurtisR

    ADS1115 not working

    KimLorentz

      I tryed connecting an ADS1115 at i2c 1 and 0x48.

       

      var mraa = require('mraa');
      var version = mraa.getVersion();
      
      if (version >= 'v0.6.1') {
          console.log('mraa version (' + version + ') ok');
      }
      else {
          console.log('mraa version(' + version + ') is old - this code may not work');
      }
      
      var ADS1X15 = require('jsupm_ads1x15');
      var ads1115 = new ADS1X15.ADS1115(1, 0x48); 
      //var ads1015 = new ADS1X15.ADS1015(1, 0x48); 
      
      setInterval(function(){
          console.log(ads1115.getSample()); 
          //console.log(ads1015.getSample()); 
          console.log("*********************"); 
      }, 1000); 
      

       

       

      but only get an error:

       

      mraa version (v0.9.0) ok                                                                                                                                                                                                                                   

       

      ERROR: module.js:340

      ERROR:     throw err;

                ^

      ERROR: Error: Cannot find module 'jsupm_ads1x15'

          at Function.Module._resolveFilename (module.js:338:15)

          at Function.Module._load (module.js:280:25)

          at Module.require (module.js:364:17)

          at require (module.js:380:17)

          at Object.<anonymous> (/home/root/.node_app_slot/main.js:11:15)

          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)

        • 1. Re: ADS1115 not working
          CMata_Intel

          Hi KimLorentz

           

          On Edison image version 159.devkit you will need to update UPM and MRAA libraries by editing the /etc/opkg/iotkit.conf file. You can run the following command.

          root@edison:~# echo "src iotkit http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586" > /etc/opkg/iotkit.conf
          

          The run the following commands

          root@edison:~# opkg update
          root@edison:~# opkg install mraa
          root@edison:~# opkg install upm
          

           

          After this, download the code from: upm/ads1x15.js at master · intel-iot-devkit/upm · GitHub and run it with node ads1x15.js

           

          Regards,

          Charlie

          • 2. Re: ADS1115 not working
            KimLorentz

            Dont get any errors anymore, tnx.

             

            Console,log settings

            console.log(ads1115.getSample());
            console.log(ads1115.getGain());
            console.log(ads1115.getSPS());
            console.log(ads1115.getCompMode());
            console.log(ads1115.getCompPol());
            console.log(ads1115.getCompLatch());
            console.log(ads1115.getCompQue());
            console.log(ads1115.getContinuous());
            console.log(ads1115.getThresh());
            console.log("*********************");
            
            

             

            Console.log respons

            0
            1024
            128
            false
            false
            true
            3
            false
            -2.0479376316070557
            *********************
            
            

             

            How do I write to the ADS1115?

            • 3. Re: ADS1115 not working
              CMata_Intel

              Hi KimLorentz,

               

              Take a look in: upm/ads1x15.h at master · intel-iot-devkit/upm · GitHub you will see the available functions that the library has. Check for the set* functions like setGain and setSPS I think this will help you.

               

              Regards,

              Charlie

              • 4. Re: ADS1115 not working
                KimLorentz

                Tryed using the set function but dont know how to do that.

                Do you know?

                 

                var mraa = require('mraa');
                var version = mraa.getVersion();
                
                if (version >= 'v0.6.1') {
                    console.log('mraa version (' + version + ') ok');
                }
                else {
                    console.log('mraa version(' + version + ') is old - this code may not work');
                }
                
                // Instantiate on I2C bus
                var ADS1X15 = require('jsupm_ads1x15');
                var ads1115 = new ADS1X15.ADS1115(1, 0x48);
                ads1115.setGain();                              // Set to 2.048 (GAIN_TWO)
                ads1115.setSPS();                               // Set to 128 SPS
                
                
                setInterval(function(){
                   
                    console.log("*********************");
                    console.log("Sample: " + ads1115.getSample()); // Read DIFF 0-1
                    console.log("Gain: " + ads1115.getGain());
                    console.log("SPS: " + ads1115.getSPS());
                    console.log("*********************");
                   
                }, 100);
                
                • 5. Re: ADS1115 not working
                  CMata_Intel

                  Hi KimLorentz

                   

                  I don’t have your shield to test this so I’m getting error messages after trying to run different codes because the UPM library verifies if the shield is indeed connected to the board.

                  On your code, you are using ads1115, the ads1115.h offers the SPS constants you can use:

                                SPS_8            = ADS1115_DR_8SPS,

                                SPS_16           = ADS1115_DR_16SPS,

                                SPS_32           = ADS1115_DR_32SPS,

                                SPS_64           = ADS1115_DR_64SPS,

                                SPS_128          = ADS1115_DR_128SPS,

                                SPS_250          = ADS1115_DR_250SPS,

                                SPS_475          = ADS1115_DR_475SPS,

                                SPS_860          = ADS1115_DR_860SPS

                  In your case you have to use SPS_128, or you can try with the HEX value: 0x0080

                   

                  In the ads1x15.h you will find the constants for the gains.

                                GAIN_TWOTHIRDS    = ADS1X15_PGA_6_144V,

                                GAIN_ONE          = ADS1X15_PGA_4_096V,

                                GAIN_TWO          = ADS1X15_PGA_2_048V,

                                GAIN_FOUR         = ADS1X15_PGA_1_024V,

                                GAIN_EIGHT        = ADS1X15_PGA_0_512V,

                                GAIN_SIXTEEN      = ADS1X15_PGA_0_256V

                  Try with GAIN_TWO or with the HEX value: 0x0400

                   

                  Let me know your results.

                   

                  Regards,

                  Charlie

                  • 6. Re: ADS1115 not working
                    KimLorentz

                    Thayed that, only get funny responds.

                    how do I manualy write data to the i2c device without the library to se how that goes

                    • 7. Re: ADS1115 not working
                      CMata_Intel

                      Hi KimLorentz,

                       

                      I apologize for the delay in my response, I would like to know if you have been able to work on this and if you have some new results.

                      Regarding your question:

                      Check the following commands in order to interact from the Linux prompt:

                      i2cdetect(8): detect I2C chips - Linux man page

                      i2cdump(8): examine I2C registers - Linux man page

                      i2cset(8): set I2C registers - Linux man page

                      i2cget(8): read from I2C/SMBus chip registers - Linux man page

                       

                      Regards,

                      Charlie

                      • 8. Re: ADS1115 not working
                        CurtisR

                        Hi, I am trying to run the code in the original post. I have installed both mraa v1.0.0 and upm v0.7.0. When I run the code I get the error:

                         

                        mraa version (v1.0.0) ok

                        /home/root/node/adc.js:12

                        var ads1115 = new ADS1X15.ADS1115(1, 0x48);

                                      ^

                         

                         

                        Error: Illegal arguments for construction of _exports_ADS1115

                            at Error (native)

                            at Object.<anonymous> (/home/root/node/adc.js:12:15)

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

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

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

                            at Function.Module._load (module.js:300:12)

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

                            at startup (node.js:139:18)

                            at node.js:968:3

                         

                        Any ideas as to what is causing this issue? Could it be a versioning issue with upm?

                         

                        Thanks, Curtis

                         

                        Edit: It was a problem with my pull up resistors, it works now.