Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] arduino, BMP180, I2C.

Status
Not open for further replies.

crazy-igzp

Member level 1
Joined
Feb 3, 2014
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
Settat, Morocco
Activity points
255
hello.
I want to read data from BMP180 barometric sensor in I2C communication protocol using arduino digital pins Instead of using A4 and A5. "the analog pins"
is it possible? any tips if it is?
thank you.
 

I have no idea how to read this sensor with analog pins.
You can use this code:
Code:
#include "BMP180.h"
#include "I2c.h"
#include "math.h"
//#include "delays.h"

#define BMP180_I2c_Address		0xEE 									//I2c address. Don't change this value!
#define Resolution			3 										//0,1,2,3 [0 - lowest, 3 - highest]

short AC1;
short AC2;
short AC3;
unsigned short AC4;
unsigned short AC5;
unsigned short AC6;
short B1;
short B2;
short MB;
short MC;
short MD;
long UT;
long UP;

void BMP180_Read_UT_Value (void);	
void BMP180_Read_UP_Value (void);

void BMP180_Init (void)
{
	unsigned char inbuff[22];
	I2c_Read_Page_1(BMP180_I2c_Address, AC1_Reg, inbuff, 22);
	AC1=(inbuff[0]<<8)|inbuff[1];
	AC2=(inbuff[2]<<8)|inbuff[3];
	AC3=(inbuff[4]<<8)|inbuff[5];
	AC4=(inbuff[6]<<8)|inbuff[7];
	AC5=(inbuff[8]<<8)|inbuff[9];
	AC6=(inbuff[10]<<8)|inbuff[11];
	B1 =(inbuff[12]<<8)|inbuff[13];
	B2 =(inbuff[14]<<8)|inbuff[15];
	MB =(inbuff[16]<<8)|inbuff[17];
	MC =(inbuff[18]<<8)|inbuff[19];
	MD =(inbuff[20]<<8)|inbuff[21];
}

void BMP180_Read_UT_Value (void)
{
	unsigned char inbuff[2];
        unsigned long delay_10ms = 1000000;
	I2c_Write_Register(BMP180_I2c_Address, 0xF4, 0x2E);
	while(delay_10ms--);
	I2c_Read_Page_1(BMP180_I2c_Address, 0xF6, inbuff, 2);
	UT=(inbuff[0]<<8)+inbuff[1];
}

void BMP180_Read_UP_Value (void)
{
	unsigned char inbuff[3];
        unsigned long delay_30ms = 3000000;
	I2c_Write_Register(BMP180_I2c_Address, 0xF4, 0x34+(Resolution<<6));
	while(delay_30ms--);
	I2c_Read_Page_1(BMP180_I2c_Address, 0xF6, inbuff, 3);
	UP=(((long)inbuff[0]<<16)+(inbuff[1]<<8)+inbuff[2])>>(8-Resolution);
}

void BMP180_Get_Result (float * Temperature, long * Pressure)
{
	long X1, X2, B5, T;
	long B6, X3, B3;
	unsigned long B4, B7;
	BMP180_Read_UT_Value();
	BMP180_Read_UP_Value();
	
	/*Calculate temperature*/
	X1=((UT-AC6)*AC5)>>15;//2^15;
	X2=(MC<<11)/(X1+MD);
	B5=X1+X2;
	T=(B5+8)>>4;
	* Temperature = T/10;
	
	/*Calculate pressure*/
	B6=B5-4000;
	X1=(B2*((B6*B6)>>12))>>11;
	X2=(AC2*B6)>>11;
	X3=X1+X2;
	B3=(((AC1*4+X3)<<Resolution)+2)>>2;
	X1=(AC3*B6)>>13;
	X2=(B1*((B6*B6)>>12))>>16;
	X3=((X1+X2)+2)>>2;
	B4=(AC4*(unsigned long)(X3+32768))>>15;
	B7=((unsigned long)UP-B3)*(50000>>Resolution);
	if (B7<0x80000000) * Pressure = (B7*2)/B4;
		else * Pressure = (B7/B4)*2;
	X1=(* Pressure>>8)*(* Pressure>>8);
	X1=(X1*3038)>>16;
	X2=(-7357*(* Pressure))>>16;
	* Pressure = * Pressure + ((X1 + X2 + 3791)>>4);
}

/* Returns absolute altitude */
float Altitude (long Pressure)
{
	const float p0 = 101325;     // Pressure at sea level (Pa)
	return (float)44330 * (1 - pow(((float) Pressure/p0), 0.190295));
}

/* Converts pressure to mm Hg */
unsigned short Pa_To_Hg (long Pressure_In_Pascals)
{
	return (unsigned long)(Pressure_In_Pascals*760)/101325;
}

unsigned char BMP180_Check_ID (void)
{
	unsigned char inbuff;
	I2c_Read_Page_1(BMP180_I2c_Address, 0xD0, &inbuff, 1);
	if (inbuff!=0x55) return 1;
	return 0;
}
 



hello.
I want to read data from BMP180 barometric sensor in I2C communication protocol using arduino digital pins Instead of using A4 and A5. "the analog pins"
is it possible? any tips if it is?

To read with the digital pins, you need to have a digital value, which means, for Arduino, HIGH or LOW. Your BMP180 sends analog values...
 

Maybe I explained myself wrong. BMP sends analog values but they are digitalized in the ADC of the Arduino. Those are values from 0 to 5 V, but not either 0 or 5 V.

To read with the digitals pins, which means, using the "digitalRead" function, you need to place in that pin 0 to less than 3V=LOW, more than 3V=HIGH, which is the value that function returns.
 
Last edited:
Sorry, but getting data from BMP180 not related to ADC anyhow. It is I2c based data tranfer. Reading datasheets still not forbiten. No analog pins being used.
A gave you a C code. There are no any arduino specific language. C or C++ only.
 
I'll have to use the analog pins after all.


Depends on application. If you want to control something with ON/OFF (boolean sense, TRUE/FALSE) it is possible because if the voltage is less than 3V, the function will return LOW, if is more than 3V, the function will return HIGH.
 
Pins A4 and A5 of Arduino are Analog pins and also I2C pins (SCL and SDA). He is not using Analog function but hardware I2C function to read the sensor. If he is indeed using Adafruit BMP180 Library then it uses I2C (Wire) Library. What I said it edit the BMP180 Library and change all hardware I2C functions with Software I2C functions.

I already provided the SoftI2C Library and BMP180 Library links.


You can then use any 2 digital pins to read the Sensor.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top