Skip to content

Commit

Permalink
Merge pull request #15 from UgoesSky/pits-zero-bme280-feature2
Browse files Browse the repository at this point in the history
Pits zero bme280 feature2
  • Loading branch information
jstjst authored Jun 18, 2018
2 parents 7dc32e2 + 566da5b commit 85658e3
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 58 deletions.
87 changes: 53 additions & 34 deletions tracker/bme280.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ struct TBME
void bme280Calibration(struct TBME *bme);
int bme280ReadInt(struct TBME *bme, unsigned char address);
// double bme280ReadUP(short fd);
int BMEAddress;

#define BME280_ADDRESS 0x76 // Possible I2C address of BME280 pressure sensor (could also be on ox77) //maybe needs to be changed
int BMEAddress1;
int BMEAddress2;


int BMEPresent(struct TBME *bme, int Address)
Expand Down Expand Up @@ -401,54 +400,74 @@ int bme280ReadInt(struct TBME *bme, unsigned char address)

void *BME280Loop(void *some_void_ptr)
{
struct TBME bme;
struct TBME bme1;
struct TBME bme2;
struct TGPS *GPS;

GPS = (struct TGPS *)some_void_ptr;

if (BMEPresent(&bme, BME280_ADDRESS))
{
BMEAddress = BME280_ADDRESS;
}
else if (BMEPresent(&bme, BME280_ADDRESS+1))
{
BMEAddress = BME280_ADDRESS+1;
}
if (BMEPresent(&bme1, 0x76))
{BMEAddress1 = 0x76;}
else
{
BMEAddress = 0;
}
{BMEAddress1 = 0;}

if (BMEAddress)
{
printf("BME280 Found At Address %02xh\n", BMEAddress);
}
if (BMEPresent(&bme2, 0x77))
{BMEAddress2 = 0x77;}
else
{
printf("BME280 Not Found (nothing at addresses 76/77h)\n");
}
{BMEAddress2 = 0;}

if (BMEAddress1)
{printf("BME280 1 Found At Address %02xh\n", BMEAddress1);}
else
{printf("BME280 1 Not Found (nothing at addresses 76h)\n");}

while (BMEAddress)
if (BMEAddress2)
{printf("BME280 2 Found At Address %02xh\n", BMEAddress2);}
else
{printf("BME280 2 Not Found (nothing at addresses 77h)\n");}

while (BMEAddress1 + BMEAddress2)
{
if ((bme.fd = open_i2c(BMEAddress)) >= 0)
if ((bme1.fd = open_i2c(BMEAddress1)) >= 0)
{
bme280StartMeasurement(&bme1);

sleep(1); // Wait (ample time) for measurement

bme280ReadDataRegisters(&bme1);

bme280GetRawValues(&bme1);

GPS->BMP180Temperature[0] = bme280Temperature(&bme1);
GPS->Pressure[0] = bme280Pressure(&bme1);
GPS->Humidity[0] = bme280Humidity(&bme1);

//printf("Temperature 1 is %5.2lf\n", GPS->BMP180Temperature[0]);
//printf("Pressure 1 is %5.2lf\n", GPS->Pressure[0]);
//printf("Humidity 1 is %5.2lf\n", GPS->Humidity[0]);

close(bme1.fd);
}

if ((bme2.fd = open_i2c(BMEAddress2)) >= 0)
{
bme280StartMeasurement(&bme);
bme280StartMeasurement(&bme2);

sleep(1); // Wait (ample time) for measurement

bme280ReadDataRegisters(&bme);
bme280ReadDataRegisters(&bme2);

bme280GetRawValues(&bme);
bme280GetRawValues(&bme2);

GPS->BMP180Temperature = bme280Temperature(&bme);
GPS->Pressure = bme280Pressure(&bme);
GPS->Humidity = bme280Humidity(&bme);
GPS->BMP180Temperature[1] = bme280Temperature(&bme2);
GPS->Pressure[1] = bme280Pressure(&bme2);
GPS->Humidity[1] = bme280Humidity(&bme2);

// printf("Temperature is %5.2lf\n", GPS->BMP180Temperature);
// printf("Pressure is %5.2lf\n", GPS->Pressure);
// printf("Humidity is %5.2lf\n", GPS->Humidity);
//printf("Temperature 2 is %5.2lf\n", GPS->BMP180Temperature[1]);
//printf("Pressure 2 is %5.2lf\n", GPS->Pressure[1]);
//printf("Humidity 2 is %5.2lf\n", GPS->Humidity[1]);

close(bme.fd);
close(bme2.fd);
}

sleep(10);
Expand Down
33 changes: 16 additions & 17 deletions tracker/bmp085.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ struct TBMP
{
short fd;
short ac1;
short ac2;
short ac3;
short ac2;
short ac3;
unsigned short ac4;
unsigned short ac5;
unsigned short ac6;
short B1;
short B1;
short B2;
short Mb;
short Mc;
Expand Down Expand Up @@ -52,10 +52,10 @@ void *BMP085Loop(void *some_void_ptr)
if ((bmp.fd = open_i2c(BMP085_ADDRESS)) >= 0)
{
int NoBMP;

NoBMP = bmp085Calibration(&bmp);
close(bmp.fd);

if (NoBMP)
{
return 0;
Expand All @@ -65,13 +65,13 @@ void *BMP085Loop(void *some_void_ptr)
{
return 0;
}

while (1)
{
if ((bmp.fd = open_i2c(BMP085_ADDRESS)) >= 0)
{
GPS->BMP180Temperature = bmp085GetTemperature(&bmp);
GPS->Pressure = bmp085GetPressure(&bmp, GPS->BMP180Temperature);
GPS->BMP180Temperature[0] = bmp085GetTemperature(&bmp);
GPS->Pressure[0] = bmp085GetPressure(&bmp, GPS->BMP180Temperature[0]);

// printf("Temperature is %5.2lf\n", GPS->BMP180Temperature);
// printf("Pressure is %5.2lf\n", GPS->Pressure);
Expand All @@ -91,7 +91,7 @@ int bmp085Calibration(struct TBMP *bmp)
{
return 1;
}

bmp->ac1 = bmp085ReadInt(bmp->fd, 0xAA);
bmp->ac2 = bmp085ReadInt(bmp->fd, 0xAC);
bmp->ac3 = bmp085ReadInt(bmp->fd, 0xAE);
Expand All @@ -103,7 +103,7 @@ int bmp085Calibration(struct TBMP *bmp)
bmp->Mb = bmp085ReadInt(bmp->fd, 0xBA);
bmp->Mc = bmp085ReadInt(bmp->fd, 0xBC);
bmp->Md = bmp085ReadInt(bmp->fd, 0xBE);

return 0;

// printf ("Values are %d %d %d %u %u %u %d %d %d %d %d\n", ac1, ac2, ac3, ac4, ac5, ac6, B1, B2, Mb, Mc, Md);
Expand Down Expand Up @@ -171,11 +171,11 @@ int bmp085ReadInt(short fd, unsigned char address)

buf[0] = address;

if ((write(fd, buf, 1)) != 1) { // Send register we want to read from
if ((write(fd, buf, 1)) != 1) { // Send register we want to read from
printf("Error writing to i2c slave\n");
return -1;
}

if (read(fd, buf, 2) != 2) { // Read back data into buf[]
printf("Unable to read from slave\n");
return -1;
Expand All @@ -189,7 +189,7 @@ unsigned short bmp085ReadUT(short fd)
{
unsigned short ut;
unsigned char buf[10];

// Write 0x2E into Register 0xF4
// This requests a temperature reading

Expand All @@ -203,7 +203,7 @@ unsigned short bmp085ReadUT(short fd)
}

usleep(5000);

ut = bmp085ReadInt(fd, 0xF6);

// printf("ut = %u\n", ut);
Expand All @@ -217,7 +217,7 @@ double bmp085ReadUP(short fd)
unsigned char msb, lsb, xlsb;
double up;
unsigned char buf[10];

// Write 0x34 into register 0xF4
// Request a pressure reading w/ oversampling setting

Expand All @@ -239,7 +239,7 @@ double bmp085ReadUP(short fd)
printf("Error writing to i2c slave\n");
return 0;
}

if (read(fd, buf, 3) != 3)
{
printf("Unable to read from slave\n");
Expand All @@ -257,4 +257,3 @@ double bmp085ReadUP(short fd)

return up;
}

6 changes: 3 additions & 3 deletions tracker/gps.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ struct TGPS
// Sensors
float DS18B20Temperature[10];
float BatteryVoltage;
float BMP180Temperature;
float Humidity;
float Pressure;
float BMP180Temperature[2];
float Humidity[2];
float Pressure[2];
float BoardCurrent;
int DS18B20Count;

Expand Down
8 changes: 4 additions & 4 deletions tracker/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ int BuildSentence(unsigned char *TxLine, int Channel, struct TGPS *GPS)
int LoRaChannel;
int ShowFields;
int TSensor, TLength;
char TimeBuffer[12], ExtraFields1[20], ExtraFields2[20], ExtraFields3[40], ExtraFields4[64], ExtraFields5[32], ExtraFields6[32], *ExtraFields7;
char TimeBuffer[12], ExtraFields1[20], ExtraFields2[40], ExtraFields3[40], ExtraFields4[64], ExtraFields5[32], ExtraFields6[32], *ExtraFields7;

if (FirstTime)
{
Expand Down Expand Up @@ -811,12 +811,12 @@ int BuildSentence(unsigned char *TxLine, int Channel, struct TGPS *GPS)
// BMP Pressure/Temperature/Humidity, if available
if (Config.EnableBME280)
{
sprintf(ExtraFields2, ",%.1f,%.0f,%0.1f", GPS->BMP180Temperature, GPS->Pressure, GPS->Humidity);
if (ShowFields) printf(",BME.Temp,Pressure,Humidity");
sprintf(ExtraFields2, ",%.1f,%.0f,%0.1f,%.1f,%.0f,%0.1f", GPS->BMP180Temperature[0], GPS->Pressure[0], GPS->Humidity[0], GPS->BMP180Temperature[1], GPS->Pressure[1], GPS->Humidity[1]);
if (ShowFields) printf(",BME.Temp1,Pressure1,Humidity1,BME.Temp2,Pressure2,Humidity2");
}
else if (Config.EnableBMP085)
{
sprintf(ExtraFields2, ",%.1f,%.0f", GPS->BMP180Temperature, GPS->Pressure);
sprintf(ExtraFields2, ",%.1f,%.0f", GPS->BMP180Temperature[0], GPS->Pressure[0]);
if (ShowFields) printf(",BMP.Temp,Pressure");
}

Expand Down

0 comments on commit 85658e3

Please sign in to comment.