Altimètre Arduino Pro mini


Je viens vers vous car j’ai un souci, j’ai suivi ce tuto :

Mais le problème est que je n’est pas le même capteur de pression moi j’ai un BMP180 et dans le tuto il utilise un MPL3115A2
donc j’ai du modifier le code mais sa ne fonctionne pas.

Voici le code :

#include <SFE_BMP180.h>

#include <SevSeg.h>

#include <Bounce2.h>

#include <Wire.h>

 MPL3115A2 Barometric Pressure Sensor Library Example Code
 By: Nathan Seidle
 SparkFun Electronics
 Date: September 24th, 2013
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
 Uses the MPL3115A2 library to display the current altitude and temperature
 Hardware Connections (Breakoutboard to Arduino):
 -VCC = 3.3V
 -SDA = A4 (use inline 10k resistor if your board is 5V)
 -SCL = A5 (use inline 10k resistor if your board is 5V)
 -INT pins can be left unconnected for this demo
 During testing, GPS with 9 satellites reported 5393ft, sensor reported 5360ft (delta of 33ft). Very close!
 During testing, GPS with 8 satellites reported 1031ft, sensor reported 1021ft (delta of 10ft).

#include <Wire.h>
#include "SFE_BMP180.h"
#include "SevSeg.h"
#include <Bounce2.h>

//#define SERIAL_DEBUG //Used for activating Serial Debugging

#define TITLE_MODE 1
#define VALUE_MODE 0

#define ALT 0
#define TOP 1
#define BOT 2
#define DIFF 3
#define STBY 4

//Create an instance of the object
SFE_BMP180 myPressure;
SevSeg myDisplay;

unsigned long timer;
unsigned long titletimer;
const int buttonPin = 3;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status

Bounce debouncer = Bounce(); 

char tempString[10]; //Used for sprintf

float maxaltitude = -99999;
float minaltitude = 99999;
boolean lastbutton = HIGH;
boolean currentbutton = HIGH;
int mode;
boolean metamode = TITLE_MODE;
char *s;
const int titletimerBeat = 1000; //fiddle away!
const int timerBeat = 500; //shouldn't be changed much

void setup()
  pinMode(buttonPin, INPUT_PULLUP);  
  Wire.begin();        // Join i2c bus
  Serial.begin(9600);  // Start serial for output

  int displayType = COMMON_CATHODE; //Your display is either common cathode or common anode

    //This pinout is for a bubble dispaly
       //Declare what pins are connected to the GND pins (cathodes)
       int digit1 = A1; //Pin 1
       int digit2 = 6; //Pin 10
       int digit3 = 12; //Pin 4
       int digit4 = 10; //Pin 6
       //Declare what pins are connected to the segments (anodes)
       int segA = 4; //Pin 12
       int segB = 5; //Pin 11
       int segC = 13; //Pin 3
       int segD = 8; //Pin 8
       int segE = A0; //Pin 2
       int segF = 7; //Pin 9
       int segG = 9; //Pin 7
       int segDP= 11; //Pin 5
  int numberOfDigits = 4; //Do you have a 1, 2 or 4 digit display?

  myDisplay.Begin(displayType, numberOfDigits, digit1, digit2, digit3, digit4, segA, segB, segC, segD, segE, segF, segG, segDP);
  myDisplay.SetBrightness(100); //Set the display to 100% brightness level

  timer = millis();
  titletimer = timer+titletimerBeat;

  //Configure the sensor
  myPressure.setModeAltimeter(); // Measure altitude above sea level in meters
  //myPressure.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa

  myPressure.setOversampleRate(7); // Set Oversample to the recommended 128
  myPressure.enableEventFlags(); // Enable all three pressure and temp event flags 

void loop() {
  float altitude;
  float pressure;
  int buttonState =;

//  buttonState = digitalRead(buttonPin);
  lastbutton = currentbutton;
  currentbutton = buttonState;
  if (lastbutton == HIGH && currentbutton == LOW) {
    if (mode >= STBY) mode = 0;
    metamode = TITLE_MODE;
    titletimer = millis()+titletimerBeat;
  if (millis() > titletimer) {
    titletimer = millis()+titletimerBeat;
    metamode = VALUE_MODE;

  if (millis() > timer) {
    timer = millis()+timerBeat;
	//things to do every 500 milliseconds
    altitude = myPressure.readAltitudeFt();
    #ifdef SERIAL_DEBUG
    Serial.print(" Altitude(ft):");
    Serial.print(altitude, 2);
    if (buttonState == HIGH) Serial.print("BUTTON PRESSED!");
  if (altitude > maxaltitude) {
    maxaltitude = altitude;
  if (altitude < minaltitude) {
    minaltitude = altitude;

    if (metamode == VALUE_MODE) {
      switch (mode) {
      case ALT:
        sprintf(tempString, "%4d", (int)altitude); //Convert altitude into a string that is right adjusted
      case TOP:
        sprintf(tempString, "%4d", (int)maxaltitude);
      case BOT:
        sprintf(tempString, "%4d", (int)minaltitude);
      case DIFF:
        sprintf(tempString, "%4d", (int)(maxaltitude - minaltitude));
      case STBY:
        sprintf(tempString, "    ");
      s = tempString;
    else if (metamode == TITLE_MODE) {
      switch (mode) {
      case ALT:
        s = "Alt ";
      case TOP:
        s = "HiGH";
      case BOT:
        s = "Lo  ";
      case DIFF:
        s = "diFF";
      case STBY:
        s = "Stby";
    #ifdef SERIAL_DEBUG
    Serial.print(" OUR STR:");
    if(mode != STBY || metamode == TITLE_MODE) myDisplay.DisplayString(s, 0); //MUST STAY OUTSIDE OF "TIMER" IF STATEMENT!!!

Et voici l’erreur:

‘class SFE_BMP180’ has no member named ‘setModeAltimeter’

Ultimate_Altimeter.ino: In function ‘void setup()’:
Ultimate_Altimeter:110: error: ‘class SFE_BMP180’ has no member named ‘setModeAltimeter’
Ultimate_Altimeter:113: error: ‘class SFE_BMP180’ has no member named ‘setOversampleRate’
Ultimate_Altimeter:114: error: ‘class SFE_BMP180’ has no member named ‘enableEventFlags’
Ultimate_Altimeter.ino: In function ‘void loop()’:
Ultimate_Altimeter:147: error: ‘class SFE_BMP180’ has no member named ‘readAltitudeFt’


Lorsque vous utilisez la librairie SFE_BMP180 il faut utiliser les fonctions comprises dans celle-ci. Ici vous faites appel à celles de la librairie MPL3115A2 du tutoriel que vous avez suivi. Il vous faut réécrire le code en trouvant les équivalents entre les deux librairies.

Merci de votre réponse j’ai tenté mais sa ne fonctionne pas il doit y avoir des erreurs !!!
Qu’est-ce qu’il faut modifier ??

Voici le fichier SFE_BMP180.h

	Bosch BMP180 pressure sensor library for the Arduino microcontroller
	Mike Grusin, SparkFun Electronics

	Uses floating-point equations from the Weather Station Data Logger project

	Forked from BMP085 library by M.Grusin

	version 1.0 2013/09/20 initial version
	Our example code uses the "beerware" license. You can do anything
	you like with this code. No really, anything. If you find it useful,
	buy me a (root) beer someday.

#ifndef SFE_BMP180_h
#define SFE_BMP180_h

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "WProgram.h"

class SFE_BMP180
		SFE_BMP180(); // base type

		char begin();
			// call pressure.begin() to initialize BMP180 before use
			// returns 1 if success, 0 if failure (bad component or I2C bus shorted?)
		char startTemperature(void);
			// command BMP180 to start a temperature measurement
			// returns (number of ms to wait) for success, 0 for fail

		char getTemperature(double &T);
			// return temperature measurement from previous startTemperature command
			// places returned value in T variable (deg C)
			// returns 1 for success, 0 for fail

		char startPressure(char oversampling);
			// command BMP180 to start a pressure measurement
			// oversampling: 0 - 3 for oversampling value
			// returns (number of ms to wait) for success, 0 for fail

		char getPressure(double &P, double &T);
			// return absolute pressure measurement from previous startPressure command
			// note: requires previous temperature measurement in variable T
			// places returned value in P variable (mbar)
			// returns 1 for success, 0 for fail

		double sealevel(double P, double A);
			// convert absolute pressure to sea-level pressure (as used in weather data)
			// P: absolute pressure (mbar)
			// A: current altitude (meters)
			// returns sealevel pressure in mbar

		double altitude(double P, double P0);
			// convert absolute pressure to altitude (given baseline pressure; sea-level, runway, etc.)
			// P: absolute pressure (mbar)
			// P0: fixed baseline pressure (mbar)
			// returns signed altitude in meters

		char getError(void);
			// If any library command fails, you can retrieve an extended
			// error code using this command. Errors are from the wire library: 
			// 0 = Success
			// 1 = Data too long to fit in transmit buffer
			// 2 = Received NACK on transmit of address
			// 3 = Received NACK on transmit of data
			// 4 = Other error

		char readInt(char address, int &value);
			// read an signed int (16 bits) from a BMP180 register
			// address: BMP180 register address
			// value: external signed int for returned value (16 bits)
			// returns 1 for success, 0 for fail, with result in value

		char readUInt(char address, unsigned int &value);
			// read an unsigned int (16 bits) from a BMP180 register
			// address: BMP180 register address
			// value: external unsigned int for returned value (16 bits)
			// returns 1 for success, 0 for fail, with result in value

		char readBytes(unsigned char *values, char length);
			// read a number of bytes from a BMP180 register
			// values: array of char with register address in first location [0]
			// length: number of bytes to read back
			// returns 1 for success, 0 for fail, with read bytes in values[] array
		char writeBytes(unsigned char *values, char length);
			// write a number of bytes to a BMP180 register (and consecutive subsequent registers)
			// values: array of char with register address in first location [0]
			// length: number of bytes to write
			// returns 1 for success, 0 for fail
		int AC1,AC2,AC3,VB1,VB2,MB,MC,MD;
		unsigned int AC4,AC5,AC6; 
		double c5,c6,mc,md,x0,x1,x2,y0,y1,y2,p0,p1,p2;
		char _error;

#define BMP180_ADDR 0x77 // 7-bit address

#define	BMP180_REG_CONTROL 0xF4
#define	BMP180_REG_RESULT 0xF6

#define	BMP180_COMMAND_PRESSURE0 0x34
#define	BMP180_COMMAND_PRESSURE1 0x74


Et voici le fichier MPL3115A2.h

#ifndef MPL3115A2_H
#define  MPL3115A2_H

 MPL3115A2 Barometric Pressure Sensor Library
 By: Nathan Seidle
 SparkFun Electronics
 Date: September 24th, 2013
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
 Get pressure, altitude and temperature from the MPL3115A2 sensor.

#if defined(ARDUINO) && ARDUINO >= 100
 #include "Arduino.h"
 #include "WProgram.h"

#include <Wire.h>

#define MPL3115A2_ADDRESS 0x60 // Unshifted 7-bit I2C address for sensor

#define STATUS     0x00
#define OUT_P_MSB  0x01
#define OUT_P_CSB  0x02
#define OUT_P_LSB  0x03
#define OUT_T_MSB  0x04
#define OUT_T_LSB  0x05
#define DR_STATUS  0x06
#define OUT_P_DELTA_MSB  0x07
#define OUT_P_DELTA_CSB  0x08
#define OUT_P_DELTA_LSB  0x09
#define OUT_T_DELTA_MSB  0x0A
#define OUT_T_DELTA_LSB  0x0B
#define WHO_AM_I   0x0C
#define F_STATUS   0x0D
#define F_DATA     0x0E
#define F_SETUP    0x0F
#define TIME_DLY   0x10
#define SYSMOD     0x11
#define INT_SOURCE 0x12
#define PT_DATA_CFG 0x13
#define BAR_IN_MSB 0x14
#define BAR_IN_LSB 0x15
#define P_TGT_MSB  0x16
#define P_TGT_LSB  0x17
#define T_TGT      0x18
#define P_WND_MSB  0x19
#define P_WND_LSB  0x1A
#define T_WND      0x1B
#define P_MIN_MSB  0x1C
#define P_MIN_CSB  0x1D
#define P_MIN_LSB  0x1E
#define T_MIN_MSB  0x1F
#define T_MIN_LSB  0x20
#define P_MAX_MSB  0x21
#define P_MAX_CSB  0x22
#define P_MAX_LSB  0x23
#define T_MAX_MSB  0x24
#define T_MAX_LSB  0x25
#define CTRL_REG1  0x26
#define CTRL_REG2  0x27
#define CTRL_REG3  0x28
#define CTRL_REG4  0x29
#define CTRL_REG5  0x2A
#define OFF_P      0x2B
#define OFF_T      0x2C
#define OFF_H      0x2D

class MPL3115A2 {


  //Public Functions
  bool begin(); // Gets sensor on the I2C bus.
  float readAltitude(); // Returns float with meters above sealevel. Ex: 1638.94
  float readAltitudeFt(); // Returns float with feet above sealevel. Ex: 5376.68
  float readPressure(); // Returns float with barometric pressure in Pa. Ex: 83351.25
  float readTemp(); // Returns float with current temperature in Celsius. Ex: 23.37
  float readTempF(); // Returns float with current temperature in Fahrenheit. Ex: 73.96
  void setModeBarometer(); // Puts the sensor into Pascal measurement mode.
  void setModeAltimeter(); // Puts the sensor into altimetery mode.
  void setModeStandby(); // Puts the sensor into Standby mode. Required when changing CTRL1 register.
  void setModeActive(); // Start taking measurements!
  void setOversampleRate(byte); // Sets the # of samples from 1 to 128. See datasheet.
  void enableEventFlags(); // Sets the fundamental event flags. Required during setup.

  //Public Variables

  //Private Functions

  void toggleOneShot();
  byte IIC_Read(byte regAddr);
  void IIC_Write(byte regAddr, byte value);

  //Private Variables



Le nom des méthodes est quand même assez explicite. Cela ne doit pas demander un effort intellectuel très poussé de passer d'une librairie à l'autre. Et si tu ne comprends pas l'anglais, il suffit de passer les fichiers dans google translate pour avoir une bonne idée de la chose. Fais au moins l'effort d'essayer. Si tu rencontres des difficultés on t'aidera.

Est-ce que quelqu'un pourrait me dire à quoi servent ces lignes ??

# define MPL3115A2_ADDRESS 0x60 / / non décalé adresse I2C 7 bits pour le capteur 

# définir le statut 0x00 
# define OUT_P_MSB 0x01 
# define OUT_P_CSB 0x02 
# define OUT_P_LSB 0x03 
# define OUT_T_MSB 0x04 
# define OUT_T_LSB 0x05 
# define DR_STATUS 0x06 
# define OUT_P_DELTA_MSB 0x07 
# define OUT_P_DELTA_CSB 0x08 
# define OUT_P_DELTA_LSB 0x09 
# define OUT_T_DELTA_MSB 0x0A 
# define OUT_T_DELTA_LSB 0x0B 
# define WHO_AM_I 0x0C 
# define F_STATUS 0x0D 
# define F_DATA 0x0E 
# define F_SETUP 0x0F 
# define TIME_DLY 0x10 
# define SYSMOD 0x11 
# define INT_SOURCE 0x12 
# define PT_DATA_CFG 0x13 
# define BAR_IN_MSB 0x14 
# define BAR_IN_LSB 0x15 
# define P_TGT_MSB 0x16 
# define P_TGT_LSB 0x17 
# define T_TGT 0x18 
# define P_WND_MSB 0x19 
# define P_WND_LSB 0x1A 
# define T_WND 0x1B 
# define P_MIN_MSB 0x1C 
# define P_MIN_CSB 0x1D 
# define P_MIN_LSB 0x1E 
# define T_MIN_MSB 0x1F 
# define T_MIN_LSB 0x20 
# define P_MAX_MSB 0x21 
# define P_MAX_CSB 0x22 
# define P_MAX_LSB 0x23 
# define T_MAX_MSB 0x24 
# define T_MAX_LSB 0x25 
# define CTRL_REG1 0x26 
# define CTRL_REG2 0x27 
# define CTRL_REG3 0x28 
# define CTRL_REG4 0x29 
# define CTRL_REG5 0x2A 
# define OFF_P 0x2B 
# define off_t 0x2C 
# define OFF_H 0x2D

Si tu poses la question c'est que tu n'as pas lu de cours de C :0

Pour faire simple ce sont des trucs qui sont indispensables pour assurer la clarté du code et une relecture facile.

écrire :

define DR_STATUS 0x06

signifie que tu demande au compilateur de remplacer dans le code source DR_STATUS par la valeur 0x06 --> je définie DR_STATUS comme valant 0x06. Maintenant pourquoi DR_STATUS vaut la valeur 0x06 c'est à toi de lire les datasheets de tes matériels pour le savoir.

L'avantage est que le code est bien plus lisible : va te rappeler 1 mois après avoir écrit le programme pourquoi tu as mis 0x06 dans un registre ! Alors que lire DR_STATUS ne pose aucune difficulté de compréhension.

le # et le define devait être collés. comme ça

#define DR_STATUS 0x06 
#define OUT_P_DELTA_MSB 0x07 
#define OUT_P_DELTA_CSB 0x08

Ils servent à définir l'adresse des registres dans le circuit afin de pouvoir les manipuler par leur nom dans le programme plutôt que par un numéro.