6 Replies Latest reply on Jun 11, 2015 2:48 AM by Refearl

    Wrong analog readings Edison Arduino board




      I´m having problems with the analog readings with the Edison Arduino Board


      I had made a program with Node.js and mraa library. the Yocto version is the latest 2.1 and Intel XDK 1912


      The circuit is made with one photocell, one analog temp sensor, one moist sensor, and a potentiometer which I don´t move the check the deviation readings. When one of the sensors change their measures the rest readings also change and thats the deviation you can check in the graph.



      Following I send the readings every half an hour of the potentiometer that to remind I didn´t move (change the value). If I´m not wrong the readings are 10 bits., from 0-1023. and the values

      are divided by 10 for the graph scale. On weekend the Edison was off.

      Using the Arduino IDE the readings are correct.


      Captura de pantalla 2015-05-15 a las 16.27.34.png



      Any hint?

        • 1. Re: Wrong analog readings Edison Arduino board



          Did you make sure to set the bit in the mraa function? Check mraa: /var/lib/jenkins/workspace/mraa-doc/api/mraa/aio.h File Reference and you’ll see the mraa_aio_set_bit function; it requires you to set the number of bits in order to work correctly.



          • 2. Re: Wrong analog readings Edison Arduino board



            Thanks for the response. I have reading around the setBit() method, is a function to set the bit value which mraa will shift the raw reading from de ADC.

            Using node.js I guess that the mraa library set it by default by 10. I have been toying around with different values, 8, 10, 12 and 0. Using 10 and 0 I got the same values as not  declaring the setBit() method in the program.


            I don´t know if it is a problem of the mraa but having 4 analog sensors connected when for example I change the value of the potentiometer the rest of the readings gone crazy for a while, around 10 seconds. With a tester I will try to read the voltage outputs to see if it corresponds to mraa readings or if there is any issue with the board


            Anybody has the same issue?

            • 3. Re: Wrong analog readings Edison Arduino board



              Did you have a chance to read the voltage outputs of the sensors? If you change the value of for example a potentiometer then the readings should not be throwing wrong readings for that long. Have you checked that this is not an issue with the components/sensors you are using rather than the board or the mraa library?

              You can update mraa with:


              echo "src mraa-upm http://iotdk.intel.com/repos/1.1/intelgalactic-dev" > /etc/opkg/mraa-upm.conf
              opkg update
              opkg install libmraa0


              You can also post the code you are using here to see if I can help you determine the cause of the issue.



              • 4. Re: Wrong analog readings Edison Arduino board

                Hello Sergio


                Yes, I had read the voltage outputs of every sensor and in the moment I read the readings are correct form the board, but when I check the graphs there are kind of spikes and patterns.

                I have a big problem is with the temperature sensor TMP36GZ that is driving me crazy. I change the TMP36GZ with other new one but I got the same results so for the moment I disconnected on Monday 25 to see if something changes in the rest of the readings.


                I post you some code of the main.js. The declaration of the variables and the pins and the function of the TMP36GZ. If you need any other part of the code please ask.


                As you see I had commented the TMP36GZ and disconnected form the board to see the behavior of the other variables. Below you can see the readings in a chart


                MRAA Version: V0.6.2-13-gf4d67b5



                /*jslint node:true,vars:true,bitwise:true,unparam:true */



                /*jshint unused:true */



                var express = require('express');

                var app = express();

                var server = require('http').createServer(app);

                var io = require('socket.io')(server);

                var MongoClient = require('mongodb').MongoClient;

                var mraa = require("mraa");



                var database;

                var coll;


                var myAnalogPin = new mraa.Aio(0);

                var lightPin= new mraa.Aio(1);

                var moistPin = new mraa.Aio(2);

                var waterLevelPin = new mraa.Aio(4);

                //var tempPin = new mraa.Aio(3);








                console.log('MRAA Version: ' + mraa.getVersion());



                function tempSensorWatch(socket){

                    'use strict';


                        d = tempPin.read();

                        tempC = d * 0.004882814; // for 5volts input

                        tempC = (tempC-0.5)*(-100); -------> IT SHOULDN´T HAVE THE '-' SING BUT IF NOT ALL THE READINGS WHERE NEGATIVE. SEE THE CHART TO SEE                     WHEN I PUT THE MINUS SING

                        tempC = tempC.toFixed(2);


                        //console.log("Temperatura " + tempC);


                        socket.emit('temp', tempC);

                    }, 1000);








                Captura de pantalla 2015-05-27 a las 19.28.28.png


                Potentiometer(It is written moist in the Y-axis but is the potentiometer) Word that I did´t change the value of the potentiometer.


                Captura de pantalla 2015-05-27 a las 19.29.18.png


                Temperature (It is crazy. On monday 25 I decided to disconnect and find another sensor)


                Captura de pantalla 2015-05-27 a las 19.29.06.png


                Just to point. In Tue 26 I connected another analog sensor, a Milone Etape , and can see the same pattern in the moist and in the potentiometer. Btw the pattern repeats all along the graph

                • 5. Re: Wrong analog readings Edison Arduino board



                  Thanks for posting the code. I looked at it and it seems ok, both the declaration of variables and the rest of the code. If you tested this with more than one sensor and got the same results it is unlikely that the errors were caused by a damaged device. Maybe a connection issue, I checked the datasheet of the TMP36 and it is supposed to be connected to a capacitor, did you connected one? Are you using an external power supply for the sensors, and making sure they are receiving enough current?


                  Take a look at Intel® XDK IoT Edition node.js Templates | Intel® Developer Zone . Even though your code seems correct you can double check taking this document into account to see if the is something you missed.



                  • 6. Re: Wrong analog readings Edison Arduino board

                    Hi Sergio


                    Sorry for taking so long to answer but I was waiting a 5V - 2amp power supply, mine was 5V - 500mAmp. After connecting the capacitor to the TMP36GZ and changing the power supply I still have problems with the temperature sensor. I will open another discussion to see if the people make it work.


                    Meantime disconnecting the TMP36GZ everything works fine so I´m going to change the sensor.