AirQuality Grove Sensor - Problem with UDOO NEO

Discussion in 'UDOO NEO' started by Andrea Rovai, Jun 21, 2016.

  1. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    I have code for Air Quality Sensor (http://www.seeedstudio.com/wiki/Grove_-_Air_Quality_Sensor)
    Code:
    /*
    AirQuality Demo V1.0.
    connect to A1 to start testing. it will needs about 20s to start
    * By: [URL='http://www.seeedstudio.com/']http://www.seeedstudio.com[/URL]
    */
    #include "AirQuality.h"
    #include "Arduino.h"
    AirQuality airqualitysensor;
    int current_quality =-1;
    void setup()
    {
        Serial.begin(9600);
        airqualitysensor.init(14);
    }
    void loop()
    {
        current_quality=airqualitysensor.slope();
        if (current_quality >= 0)// if a valid data returned.
        {
            if (current_quality==0)
            Serial.println("High pollution! Force signal active");
            else if (current_quality==1)
            Serial.println("High pollution!");
            else if (current_quality==2)
            Serial.println("Low pollution!");
            else if (current_quality ==3)
            Serial.println("Fresh air");
        }
    }
    ISR(TIMER2_OVF_vect)
    {
        if(airqualitysensor.counter==122)//set 2 seconds as a detected duty
        {
    
            airqualitysensor.last_vol=airqualitysensor.first_vol;
            airqualitysensor.first_vol=analogRead(A0);
            airqualitysensor.counter=0;
            airqualitysensor.timer_index=1;
            PORTB=PORTB^0x20;
        }
        else
        {
            airqualitysensor.counter++;
        }
    }
    
    How avoid (ISR(TIMER2_OVF_vect) and PORTB=PORTB^0x20; ) in this code? Udoo neo not supported this function.
    Thanks!

    NOTE: this question was originally posted by @Andriy in this topic.
     
    Last edited by a moderator: Jun 24, 2016
    I Hate Google! likes this.
  2. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    The ISR part is an interrupt so if you don't need it you can just skip this line (and the attached brackets). Leave the If statement in the sketch and put some delay() in it and it will run.

    The only part that puzzles me personally is the PortB part. It seems to be a direct access to the digital pins on a Arduino. You have to change that into a digitalwrite() but on what pin?

    The sketch can only run on some Arduino's so it is not the best example that Grove could give.
     
    Andrea Rovai likes this.
  3. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    The PortB function switches pin 13 so the led. So you can do that also with a digitalwrite.
     
    Andrea Rovai likes this.
  4. Andriy

    Andriy Member

    Joined:
    Nov 10, 2015
    Messages:
    30
    Likes Received:
    2
    I am a beginner in programming. If you have the opportunity to write the desired function in the code. I will be grateful.
     
  5. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Quick and dirty and did not run it trough the compiler so no guarantees :)
    And I was a beginner too when i bought the Neo, there is a lot of info out there!
    Code:
    /*
    AirQuality Demo V1.0.
    connect to A1 to start testing. it will needs about 20s to start
    * By: [URL='http://www.seeedstudio.com/']http://www.seeedstudio.com[/URL]
    */
    #include "AirQuality.h"
    #include "Arduino.h"
    int current_quality =-1;
    void setup()
    {
        Serial.begin(115200);
        delay(100);
        AirQuality airqualitysensor;
        airqualitysensor.init(14);
    }
    void loop()
    {
        current_quality=airqualitysensor.slope();
        if (current_quality >= 0)// if a valid data returned.
        {
            if (current_quality==0)
            Serial.println("High pollution! Force signal active");
            else if (current_quality==1)
            Serial.println("High pollution!");
            else if (current_quality==2)
            Serial.println("Low pollution!");
            else if (current_quality ==3)
            Serial.println("Fresh air");
        }
       if(airqualitysensor.counter==20) //set 2 seconds as a detected duty
         {
            airqualitysensor.last_vol=airqualitysensor.first_vol;
            airqualitysensor.first_vol=analogRead(A0);
            airqualitysensor.counter=0;
            airqualitysensor.timer_index=1;
            digitalwrite(13, HIGH);
        }
        else
        {
            delay(100);
            airqualitysensor.counter++;
            digitalwrite(13, LOW);
        }
    }
    
     
    I Hate Google! and Andrea Rovai like this.

Share This Page