Hi sir
I got 1570 hpa from gy-65.
But the real value should be about 1018.
Thanks for your suggestion .. .
PS:I can get the temperature correctly.
Hi sir
I got 1570 hpa from gy-65.
But the real value should be about 1018.
Thanks for your suggestion .. .
PS:I can get the temperature correctly.
Post your code, a link to the data sheet and describe (or even better, photograph) how you have it set up.
thanks for your help
I wrote the keil c code for 8051,not arduino ... .
I search hte question on the internet.
I also saw many people had the question.
Could I post keil-c code here?
Yes
//大氣壓力感測器程式模組
//int Multiple_Read_I2C short??
//#include <REGX51.H>
#include"PIO.h"
#include"lcd.h"
#define SCL P2_0
#define SDA P2_1
void Delay5us();
void Delay_1mX(tim); //讀取前需要的緩衝時間
void I2C_Start();
void I2C_Stop();
void I2C_SendACK(bit sack);
bit I2C_GetACK();
void I2C_SendByte(unsigned char dat);
unsigned char I2C_RecvByte();
void Single_Write_I2C(unsigned char SlaveAddress,unsigned char REG_Address,unsigned char REG_Data);
//unsigned char Single_Read_I2C(unsigned char SlaveAddress,unsigned char REG_Address);
int Multiple_Read_I2C(unsigned char SlaveAddress,unsigned char REG_Address);
unsigned char Dev_ID=0xee; //大氣壓力IC=BMP085
void Dev_init();
unsigned char I2C_ReadBuf[2]; //陣列大小為連續讀取資料Byte數
unsigned int led;
//----for BMP085----
#define OSS 0 // Oversampling Setting (別設其它值)
short ac1,ac2,ac3,b1,b2,mb,mc,md; //暫存器
unsigned short ac4,ac5,ac6; //暫存器
long temperature; //轉換後的溫度
long pressure; //轉換後的壓力
void Dev_init();
long ReadTemperature(void);
long ReadPressure(void);
void bmp085Convert();
main(){
Delay_1mX(200); //電源穩定
Dev_init();
lcd_initial();
while(1){
if(!led++){
//Dev_init();
bmp085Convert();
//pressure=193456;
WORD[0]=((pressure%1000000)/100000)+0x30;
WORD[1]=((pressure%100000)/10000)+0x30;
WORD[2]=((pressure%10000)/1000)+0x30;
WORD[3]=((pressure%1000)/100)+0x30;
WORD[4]=((pressure%100)/10)+0x30; //初步看
WORD[5]=(pressure%10)+0x30;
WORD[13]=((temperature%1000)/100)+0x30;
WORD[14]=((temperature%100)/10)+0x30; //初步看
WORD[15]=(temperature%10)+0x30;
disp_lcd();
}
}
}
void Delay5us(){
unsigned char i;
i=5;
while(i>0)i--;
}
void Delay_1mX(tim){
unsigned char i,j;
i=tim;
while(i>0){
i--;
j=240;
while(j>0)j--;
}
}
void I2C_Start(){
SDA = 1;
SCL = 1;
Delay5us();
SDA = 0;
Delay5us();
SCL = 0;
}
void I2C_Stop(){
SDA = 0;
SCL = 1;
Delay5us();
SDA = 1;
Delay5us();
}
void I2C_SendACK(bit sack){
//9th bit--- send ack
SDA=sack;
SCL = 1;
Delay5us();
SCL = 0;
Delay5us();
}
bit I2C_GetACK(){
bit getack;
//9th bit---get ack
SDA=1;
Delay5us();
SCL=1;
Delay5us();
getack=SDA; // get ack
SCL = 0;
Delay5us();
return getack;
}
void I2C_SendByte(unsigned char dat){
unsigned char i;
bit gack;
for (i=0; i<8; i++){//1-8 bits
SDA= (bit) (dat & 0x80);
dat <<= 1;
SCL = 1;
Delay5us();
SCL = 0;
Delay5us();
}
gack=I2C_GetACK();
}
unsigned char I2C_RecvByte(){
unsigned char i;
unsigned char dat = 0;
SDA = 1; //讀取前要先拉High,1-8 bits
for (i=0; i<8; i++){
dat <<= 1;
SCL = 1;
Delay5us();
dat |= SDA;
SCL = 0;
Delay5us();
}
return dat;
}
void Single_Write_I2C(unsigned char SlaveAddress,unsigned char REG_Address,unsigned char REG_Data){
I2C_Start();
I2C_SendByte(SlaveAddress);
I2C_SendByte(REG_Address);
I2C_SendByte(REG_Data);
I2C_Stop();
}
/*
unsigned char Single_Read_I2C(unsigned char SlaveAddress,unsigned char REG_Address){
unsigned char REG_data;
I2C_Start();
I2C_SendByte(SlaveAddress);
I2C_SendByte(REG_Address);
I2C_Start();
I2C_SendByte(SlaveAddress+1);
REG_data=I2C_RecvByte();
I2C_SendACK(1); // ack=1...NACK
I2C_Stop();
return REG_data;
}
*/
int Multiple_Read_I2C(unsigned char SlaveAddress,unsigned char REG_Address){
unsigned char HB, LB;
short _data;
I2C_Start(); //起始信號
I2C_SendByte(SlaveAddress); //發送設備位址+寫信號
I2C_SendByte(REG_Address); //發送存儲單元位址
I2C_Start();
I2C_SendByte(SlaveAddress+1); //發送設備位址+讀信號
HB=I2C_RecvByte(); //存儲連續讀回的資料
I2C_SendACK(0); //回應ACK
LB=I2C_RecvByte();
I2C_SendACK(1); //依據資料手冊的格式P7 or P10 /ACK
I2C_Stop(); //停止信號
Delay_1mX(5); //5ms
_data = HB << 8;
_data |= LB;
return _data;
}
void Dev_init(){
ac1 = Multiple_Read_I2C(Dev_ID,0xAA); //Dec_ID=0xee,初始化暫存器位址
ac2 = Multiple_Read_I2C(Dev_ID,0xAC);
ac3 = Multiple_Read_I2C(Dev_ID,0xAE);
ac4 = Multiple_Read_I2C(Dev_ID,0xB0);
ac5 = Multiple_Read_I2C(Dev_ID,0xB2);
ac6 = Multiple_Read_I2C(Dev_ID,0xB4);
b1 = Multiple_Read_I2C(Dev_ID,0xB6);
b2 = Multiple_Read_I2C(Dev_ID,0xB8);
mb = Multiple_Read_I2C(Dev_ID,0xBA);
mc = Multiple_Read_I2C(Dev_ID,0xBC);
md = Multiple_Read_I2C(Dev_ID,0xBE);
}
//--讀取溫度值--
long ReadTemperature(void){
Single_Write_I2C(Dev_ID,0xF4,0x2E); //發送設備位址+寫信號
Delay_1mX(5); // 最大轉換時間 4.5ms
return (long)Multiple_Read_I2C(Dev_ID,0xF6);
}
//--讀取壓力值--
long ReadPressure(void){
Single_Write_I2C(Dev_ID,0xF4,0x34); //發送設備位址+寫信號
Delay_1mX(5); // 最大轉換時間 4.5ms
return (long)Multiple_Read_I2C(Dev_ID,0xF6);
}
//***********************************************************************
void bmp085Convert(){
long ut;
long up;
long x1, x2, b5, b6, x3, b3, p;
unsigned long b4, b7;
ut = ReadTemperature();
//ut =27898; //ReadTemperature(); // 讀取溫度
up = ReadPressure();
//up =23843; //ReadPressure(); // 讀取壓強
x1 = ((long)ut - ac6) * ac5 >> 15;
x2 = ((long) mc << 11) / (x1 + md);
b5 = x1 + x2;
temperature = (b5+8) >> 4;
//*************
b6 = b5 - 4000;
x1 = (b2 * (b6 * b6 >> 12)) >> 11;
x2 = ac2 * b6 >> 11;
x3 = x1 + x2;
b3 = (((long)ac1 * 4 + x3) + 2)/4;
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 >> OSS);
if( b7 < 0x80000000){
p = (b7 * 2) / b4 ;
}else{
p = (b7 / b4) * 2;
}
x1 = (p >>8 ) * (p >>8 );
x1 = (x1 * 3038) >> 16;
x2 = (-7357 * p) >> 16;
pressure = p + ((x1 + x2 + 3791) >> 4);
}
If you know what the reading should be, why do you need a sensor? ![]()
But that's a semi-serious question: how do you know it's wrong? Is the 1018 from a reliable source?
Thanks for your help..
I must check does the reading value coeecet or not.
I search the information about atmosphere pressure.
When I am on the groung, it's about 1018 hpa...
If the pressure is about 1500hpa, I must be underground..
So .. I thought it was wrong.. .
Well you didn't say where you were: you might have been testing the pressure in a diving decompression chamber. Yep 1018 or so is normal in free air.
What voltage are you supplying it. I notice in the datasheet that it has a MAXIMUM supply voltage of 3.6 volts.
it had regulator in gy-65,so it can be work in 5V.
I test it in the normal free air.
Thanks for your help
Are you actually running this connected to an Arduino, or an 8051, or have I just misunderstood something?
I really run it on 89S52, I post my code on older article.
I see the pressure data is 15575 pa...
thanks a lot