General

Problem with Barometric pressure software and LCD Keypad Shield V1.1

userHead [email protected] 2014-02-02 12:02:03 4637 Views0 Replies
I have one little problem.
I would like to use LCD Keypad Schield V1.1 (DF Robot) over Arduino Uno to communicate with BMP085 pressure sensor, but it is impossible to get data from it for me.
I would use the following software :
Code: Select all
/*
 **************************  Barometric (atmospheric pressure) Arduino project *************************
 * LINK: http://coolarduino.wordpress.com/2013/04/10/barometric-atmospheric-pressure-arduino-project/
 *
 * Created for  Arduino UNO board: Anatoly Kuzmenko 10 April 2013 
 *                                 [email protected]
 *
 * SOFTWARE COMPILES USING Arduino 1.0.4 IDE (Tested on Linux OS only).
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute copies of the Software, 
 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY,  dfrobot FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *
 * Copyright (C) 2013 Anatoly Kuzmenko.
 * All Rights Reserved.
 ********************************************************************************************
 */
#include <Wire.h>
#include <Adafruit_MPL115A2.h>
#include <LiquidCrystal.h>

#define  ABS_MINIM     97.325         // absolute pressure minimum, kPa
#define  UPD_HISTR     7200           // update history interval in sec, 2 hours

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7);

Adafruit_MPL115A2      mpl115a2;

         byte          prs_bars[8][8];// Custom characters array
         byte          prs_hist[8] = { 8, 11, 15, 7, 3, 0, 5, 8};  // Start-up "demo" data.

volatile uint8_t       sec_tick = 0;
         uint16_t      sec_cntr = 0;

         float         lpf_pres = 0.0;
         float         lpf_temp = 0.0;    
         
void setup(void) 
{
//  Serial.begin(115200);
  mpl115a2.begin();
  lcd.begin(16, 2);      

  for (uint8_t j = 0; j < 8; j++)  
  {
    for (uint8_t i = 0; i < 8; i++)
    {
      if ( i <= j )  prs_bars[j][7-i] = B11111;
      else           prs_bars[j][7-i] = B00000;
    }
  }  
  for ( uint8_t i = 0; i < 8; i++)
  {
    lcd.createChar(i, prs_bars[i]);
  }

  for ( uint8_t j = 0; j < 16; j++)          // Taking time for sensor to settle
  {
    print_Bars( j, j );
    delay(500);
  }

  lcd.clear();

    lcd.setCursor( 3, 0);
    lcd.print("*Magician*");
    
    lcd.setCursor( 5, 1);
    lcd.print("ver. 2a");

  delay(2000);

  lcd.clear();

  for ( uint8_t i = 0; i < 8; i++)
  {
    print_Bars( i, prs_hist[i]);             // Show nice picture
  } 

  lpf_pres = mpl115a2.getPressure();  
  lpf_temp = mpl115a2.getTemperature();  

 /* Set up TIMER 1 - 1 seconds tick-er */
  TIMSK1 = 0x00;
  TCCR1A = 0;
  TCCR1B = 0;
  TCCR1C = 0;

  TCCR1A =  ((1<<WGM11) | (1<<WGM10));       // Mode 15, Fast PWM
  TCCR1B =  ((1<<WGM13) | (1<<WGM12));       // Mode 15, Fast PWM

  TCCR1B |=  ((1<<CS10) | (1<<CS12));        // clk/1024 prescaling.
  OCR1A  = 15625;                            // 1 sec.

  TCNT1  = 0;
  TIFR1   |= (1<<TOV1); 
  TIMSK1  |= (1<<TOIE1);
}
 
void loop(void) 
{
 float    pressureKPA = 0, temperatureC = 0;    
 uint16_t temp;

  if (sec_tick) { 
    pressureKPA = mpl115a2.getPressure();  
//    Serial.print("Pressure (kPa): "); Serial.print(pressureKPA, 4); Serial.println(" kPa");
    temperatureC = mpl115a2.getTemperature();  
//    Serial.print("Temp (*C): "); Serial.print(temperatureC, 1); Serial.println(" *C");
    lpf_pres = 0.99 * lpf_pres + 0.01 * pressureKPA;
    lpf_temp = 0.99 * lpf_temp + 0.01 * temperatureC;

    lcd.setCursor( 9, 1);
    lcd.print( lpf_temp, 2);
    lcd.print("*C");
    
    lcd.setCursor( 9, 0);
    lcd.print( lpf_pres, 1);
    lcd.print("kP");
   
    if (sec_cntr > UPD_HISTR)
    {
      lcd.clear();
      for ( uint8_t i = 0; i < 7; i++)
      {
        prs_hist[i] = prs_hist[i+1];
        print_Bars( i, prs_hist[i]);
      } 
    temp = 2 *(lpf_pres - ABS_MINIM);
    prs_hist[7] = temp;
    print_Bars( 7, prs_hist[7]);

    sec_cntr = 0;
    }
  sec_tick = 0;
  }
}

ISR(TIMER1_OVF_vect)
{
  sec_tick = 1;
  sec_cntr++;
}

void print_Bars( uint8_t location, uint8_t value )
{
  if ( value < 8 )
  {
    lcd.setCursor( location, 1);  
    lcd.write(value);
  }
  else
  {
    lcd.setCursor(location, 1);
    lcd.write(7);
    lcd.setCursor(location, 0);
    lcd.write(value - 8);
  }        
}

I have the following problem:
when I transfer the sketch to arduino uno I see no data on Display of my LCD Keypad shield.
In contrast , when the Adafruit_MPL115A2 library is not activate , I see the hystogram and both Temperature=0*C and pressure =0KP.

Sketch, when the Adafruit_MPL115A2 library is not activate.
Code: Select all
/*
 **************************  Barometric (atmospheric pressure) Arduino project *************************
 * LINK: http://coolarduino.wordpress.com/2013/04/10/barometric-atmospheric-pressure-arduino-project/
 *
 * Created for  Arduino UNO board: Anatoly Kuzmenko 10 April 2013 
 *                                 [email protected]
 *
 * SOFTWARE COMPILES USING Arduino 1.0.4 IDE (Tested on Linux OS only).
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute copies of the Software, 
 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY,  dfrobot FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *
 * Copyright (C) 2013 Anatoly Kuzmenko.
 * All Rights Reserved.
 ********************************************************************************************
 */
#include <Wire.h>
//#include <Adafruit_MPL115A2.h>
#include <LiquidCrystal.h>

#define  ABS_MINIM     97.325         // absolute pressure minimum, kPa
#define  UPD_HISTR     7200           // update history interval in sec, 2 hours

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7);

//Adafruit_MPL115A2      mpl115a2;

         byte          prs_bars[8][8];// Custom characters array
         byte          prs_hist[8] = { 8, 11, 15, 7, 3, 0, 5, 8};  // Start-up "demo" data.

volatile uint8_t       sec_tick = 0;
         uint16_t      sec_cntr = 0;

         float         lpf_pres = 0.0;
         float         lpf_temp = 0.0;    
         
void setup(void) 
{
//  Serial.begin(115200);
 // mpl115a2.begin();
  lcd.begin(16, 2);      

  for (uint8_t j = 0; j < 8; j++)  
  {
    for (uint8_t i = 0; i < 8; i++)
    {
      if ( i <= j )  prs_bars[j][7-i] = B11111;
      else           prs_bars[j][7-i] = B00000;
    }
  }  
  for ( uint8_t i = 0; i < 8; i++)
  {
    lcd.createChar(i, prs_bars[i]);
  }

  for ( uint8_t j = 0; j < 16; j++)          // Taking time for sensor to settle
  {
    print_Bars( j, j );
    delay(500);
  }

  lcd.clear();

    lcd.setCursor( 3, 0);
    lcd.print("*Magician*");
    
    lcd.setCursor( 5, 1);
    lcd.print("ver. 2a");

  delay(2000);

  lcd.clear();

  for ( uint8_t i = 0; i < 8; i++)
  {
    print_Bars( i, prs_hist[i]);             // Show nice picture
  } 

 // lpf_pres = mpl115a2.getPressure();  
 // lpf_temp = mpl115a2.getTemperature();  

 /* Set up TIMER 1 - 1 seconds tick-er */
  TIMSK1 = 0x00;
  TCCR1A = 0;
  TCCR1B = 0;
  TCCR1C = 0;

  TCCR1A =  ((1<<WGM11) | (1<<WGM10));       // Mode 15, Fast PWM
  TCCR1B =  ((1<<WGM13) | (1<<WGM12));       // Mode 15, Fast PWM

  TCCR1B |=  ((1<<CS10) | (1<<CS12));        // clk/1024 prescaling.
  OCR1A  = 15625;                            // 1 sec.

  TCNT1  = 0;
  TIFR1   |= (1<<TOV1); 
  TIMSK1  |= (1<<TOIE1);
}
 
void loop(void) 
{
 float    pressureKPA = 0, temperatureC = 0;    
 uint16_t temp;

  if (sec_tick) { 
    //pressureKPA = mpl115a2.getPressure();  
//    Serial.print("Pressure (kPa): "); Serial.print(pressureKPA, 4); Serial.println(" kPa");
  //  temperatureC = mpl115a2.getTemperature();  
//    Serial.print("Temp (*C): "); Serial.print(temperatureC, 1); Serial.println(" *C");
    lpf_pres = 0.99 * lpf_pres + 0.01 * pressureKPA;
    lpf_temp = 0.99 * lpf_temp + 0.01 * temperatureC;

    lcd.setCursor( 9, 1);
    lcd.print( lpf_temp, 2);
    lcd.print("*C");
    
    lcd.setCursor( 9, 0);
    lcd.print( lpf_pres, 1);
    lcd.print("kP");
   
    if (sec_cntr > UPD_HISTR)
    {
      lcd.clear();
      for ( uint8_t i = 0; i < 7; i++)
      {
        prs_hist[i] = prs_hist[i+1];
        print_Bars( i, prs_hist[i]);
      } 
    temp = 2 *(lpf_pres - ABS_MINIM);
    prs_hist[7] = temp;
    print_Bars( 7, prs_hist[7]);

    sec_cntr = 0;
    }
  sec_tick = 0;
  }
}

ISR(TIMER1_OVF_vect)
{
  sec_tick = 1;
  sec_cntr++;
}

void print_Bars( uint8_t location, uint8_t value )
{
  if ( value < 8 )
  {
    lcd.setCursor( location, 1);  
    lcd.write(value);
  }
  else
  {
    lcd.setCursor(location, 1);
    lcd.write(7);
    lcd.setCursor(location, 0);
    lcd.write(value - 8);
  }        
}
Can You help me to resolve this problem? :'(
Many Thanks