"Error Compiling for board Arduino Leonardo

Hi all. I created some code to program a pollution monitor that measures temperature/humidity, sound level, and air quality using the Seeed Grove Air Quality sensor v1.3, the Grove Sound Sensor, and the TH02 Sensor for Seeed Grove. When I try to upload my code to my Arduino Leonardo, it gives me a bunch of error messages. Me, being new to code, would appreciate some assistance regarding this. Could you take a look at my code and see what’s wrong with it? Thanks in advance.

/*
Pollution Monitor
*/

#include"AirQuality.h"
#include"Arduino.h"
#include <TH02_dev.h>
#include “Wire.h”

AirQuality airqualitysensor;
int current_quality =-1;
const int pinAdc = A0;
void setup()
{
Serial.begin(9600);

airqualitysensor.init(A1);

Serial.println(“TH02_dev demo by seeed studio\n”);
/* Power up,delay 150ms,until voltage is stable /
delay(150);
/
Reset HP20x_dev /
TH02.begin();
delay(100);
/
Determine TH02_dev is available or not */
Serial.println(“TH02_dev is available.\n”);
Serial.println(“Grove - Sound Sensor Test…”);
}

void loop()
{
current_quality=airqualitysensor.slope();
if (current_quality >= 0)// if a valid data returned.
{
if (current_quality==0)
Serial.println(“High pollution! Preventive measures should be taken immediately!”);
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”);
}

float temper = TH02.ReadTemperature() * 1.8 + 32;
Serial.println("Temperature: ");
Serial.print(temper);
Serial.println(“F\r\n”);

float humidity = TH02.ReadHumidity();
Serial.println(“Humidity: “);
Serial.print(humidity);
Serial.println(”%\r\n”);
delay(1000);

long sum = 0;
for(int i=0; i<32; i++)
{
sum += analogRead(pinAdc);
}

sum >>= 5;

Serial.print("Sound Level: ");
Serial.print(sum);
Serial.println(“dB\r\n”);
delay(550);
}

ISR(TIMER1_OVF_vect)
{
if(airqualitysensor.counter==122)//set 2 seconds as a detected duty
{
airqualitysensor.last_vol=airqualitysensor.first_vol;
airqualitysensor.first_vol=analogRead(A1);
airqualitysensor.counter=0;
airqualitysensor.timer_index=1;
PORTB=PORTB^0x20;
}
else
{
airqualitysensor.counter++;
}
}

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor you will not have access to this useful tool but it’s still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

When you encounter an error you’ll see a button on the right side of the orange bar “Copy error messages”. Click that button. Paste the error in a message here USING CODE TAGS (</> button on the forum toolbar).

Thanks for the heads up. In proper formatting (I think)

 /*
Pollution Monitor
*/

#include"AirQuality.h"
#include"Arduino.h"
#include <TH02_dev.h>
#include "Wire.h" 

AirQuality airqualitysensor;
int current_quality =-1;
const int pinAdc = A0;
void setup()
{
    Serial.begin(9600);
    
    airqualitysensor.init(A1);
    
    Serial.println("****TH02_dev demo by seeed studio****\n");
    /* Power up,delay 150ms,until voltage is stable */
    delay(150);
    /* Reset HP20x_dev */
    TH02.begin();
    delay(100);
    /* Determine TH02_dev is available or not */
    Serial.println("TH02_dev is available.\n");  
    Serial.println("Grove - Sound Sensor Test...");  
}

void loop()
{
    current_quality=airqualitysensor.slope();
    if (current_quality >= 0)// if a valid data returned.
    {
        if (current_quality==0)
            Serial.println("High pollution! Preventive measures should be taken immediately!");
        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");
    }
    
   float temper = TH02.ReadTemperature() * 1.8 + 32; 
   Serial.println("Temperature: ");   
   Serial.print(temper);
   Serial.println("F\r\n");
   
   float humidity = TH02.ReadHumidity();
   Serial.println("Humidity: ");
   Serial.print(humidity);
   Serial.println("%\r\n");
   delay(1000);    

   long sum = 0;
    for(int i=0; i<32; i++)
    {
        sum += analogRead(pinAdc);
    }

    sum >>= 5;                                                                   

    Serial.print("Sound Level: ");
    Serial.print(sum);
    Serial.println("dB\r\n");
    delay(550);
}

ISR(TIMER1_OVF_vect)
{
    if(airqualitysensor.counter==122)//set 2 seconds as a detected duty
    {
        airqualitysensor.last_vol=airqualitysensor.first_vol;
        airqualitysensor.first_vol=analogRead(A1);
        airqualitysensor.counter=0;
        airqualitysensor.timer_index=1;
        PORTB=PORTB^0x20;
    }
    else
    {
        airqualitysensor.counter++;
    }
}[code]


My error messages:

[code] Arduino: 1.8.6 (Mac OS X), Board: "Arduino Leonardo"

Build options changed, rebuilding all
In file included from /Users/tejshah/Library/Arduino15/packages/arduino/hardware/avr/1.6.23/cores/arduino/Arduino.h:30:0,
                 from /Users/tejshah/Documents/Arduino/libraries/Grove_Air_quality_Sensor-master/AirQuality.h:23,
                 from /Users/tejshah/Desktop/AirQuality_TempHumid_Sound/AirQuality_TempHumid_Sound.ino:6:
/Users/tejshah/Desktop/AirQuality_TempHumid_Sound/AirQuality_TempHumid_Sound.ino: In function 'void TIMER2_OVF_vect()':
/Users/tejshah/Desktop/AirQuality_TempHumid_Sound/AirQuality_TempHumid_Sound.ino:71:5: warning: 'TIMER2_OVF_vect' appears to be a misspelled signal handler, missing __vector prefix [-Wmisspelled-isr]
 ISR(TIMER2_OVF_vect)
     ^
/Users/tejshah/Documents/Arduino/libraries/Grove_Air_quality_Sensor-master/AirQuality.cpp: In member function 'void AirQuality::init(int)':
/Users/tejshah/Documents/Arduino/libraries/Grove_Air_quality_Sensor-master/AirQuality.cpp:80:5: error: 'TCCR2A' was not declared in this scope
     TCCR2A=0;//normal model
     ^
/Users/tejshah/Documents/Arduino/libraries/Grove_Air_quality_Sensor-master/AirQuality.cpp:81:5: error: 'TCCR2B' was not declared in this scope
     TCCR2B=0x07;//set clock as 1024*(1/16M)
     ^
/Users/tejshah/Documents/Arduino/libraries/Grove_Air_quality_Sensor-master/AirQuality.cpp:82:5: error: 'TIMSK2' was not declared in this scope
     TIMSK2=0x01;//enable overflow interrupt
     ^
exit status 1
Error compiling for board Arduino Leonardo.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The formatting is very close to proper, but you should make sure that the code and error messages are in separate code tags for readability. It's useful to click the "Preview" button before posting to check how the forum will render your markup.

It looks like the Grove_Air_quality_Sensor library is not compatible with the ATmega32U4 microcontroller on your Leonardo. It will work on the ATmega328P used on the Uno, Nano, etc. and the ATmega2560 of the Mega. It should be possible to add support for the ATmega32u4 after some studying of the datasheets for the ATmega328P and the ATmega32U4 and this would be a valuable contribution to make back to the library, which I'm sure Seeed would appreciate.