I'm new to programming and the arduino, but I finally got the BMP085 to transfer data using the 433 Mhz RF so that I can print to Serial, LCD or other display. I'm posting my code here because it took me a few frustrating nights to figure out how to transfer the data. If you have any suggestions to the code please feel free to comment. All I ask is to please remember that I am new to this, but I am a fast learner. Thanks for your time and I hope that this will help someone else out.
I used:
Arduino Uno
Seeedstudio Bluetooth Bee (This wouldn't ever be my first choice for debugging but I bought it for a future project. I just have to learn how to program some apps for it. You do need to pay attention to the Virtual Wire library for the TX/RX pins. Thankfully I read about that before I started)
BMP085 Barometric Pressure/Temperature/Altitude Sensor http://www.adafruit.com/products/391
433Mhz RF link kit http://www.seeedstudio.com/depot/433mhz-rf-link-kit-p-127.html?cPath=139
This is the Transmitter Code:
#include <VirtualWire.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
int LED = A0; //LED to blink when transmitting
int numbers[6]; //Number of variables to send out
void setup()
{
Serial.begin(9600);
Serial.println("Setup");
pinMode(LED,OUTPUT);
bmp.begin();
if (!bmp.begin())
{
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1)
{
}
}
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(1000); // Bits per sec
//vw_set_tx_pin(6); // pin 6 is used as the transmit data out into the TX Link module, change this to suit your needs.
}
void loop()
{
//----------------------------Taking Readings from BMP085---------------------------------------------------
/*
float temp = bmp.readTemperature(); //Read Temperature in Celcius
int temp1 = (int)temp; //Read Temperature digits on the left of the decimal place
int temp2 = (int)((temp - temp1) * 100.0); //Read Temperature digits on the right of the decimal place
*/
float temp = (bmp.readTemperature() * 9.0 / 5.0 + 32); //Read Temperature and convert to fahrenheit
int temp1 = (int)temp; //Read Temperature digits on the left of the decimal place
int temp2 = (int)((temp - temp1) * 100.0); //Read Temperature digits on the right of the decimal place
/* Altitude with no correction
// you can get a more precise measurement of altitude
// if you know the current sea level pressure which will
// vary with weather and such. If it is 1015 millibars
// that is equal to 101500 Pascals.
float alt = bmp.readAltitude(); //Read Altitude with no correction
int alt1 = (int)alt; //Read Altitude digits on the left of the decimal place
int alt2 = (int)((alt - alt1) * 100.0); //Read Altitude digits on the right of the decimal place
*/
//Remove the " * 3.280839895" for units in meters
float alt = bmp.readAltitude(103149) * 3.280839895; //Read Altitude with correction
int alt1 = (int)alt; //Read Altitude digits on the left of the decimal place
int alt2 = (int)((alt - alt1) * 100.0); //Read Altitude digits on the right of the decimal place
//Remove the " * 0.0002952998751" fro units in pascal
float bar = bmp.readPressure() * 0.0002952998751; //Read Barometric Pressure
int bar1 = (int)bar; //Read Altitude digits on the left of the decimal place
int bar2 = (int)((bar - bar1) * 100.0); //Read Altitude digits on the right of the decimal place
//-------------------------------End of Readings from BMP085------------------------------------------------
//-------------------------------Debugging---------------------------------------------------
Serial.print ("Temperature= "); //Print Temperature
Serial.print (temp1); //Print Temperature digits on the left of the decimal place
Serial.print ("."); //Print decimal
Serial.print (temp2); //Print Temperature digits on the right of the decimal place
Serial.println (" *F"); //Print degrees in fahrenheit, Change to C for Celcius
/*
Serial.print ("Altitude="); //Print Altitude
Serial.print (alt1); //Print Altitude digits on the left of the decimal place
Serial.print ("."); //Print decimal
Serial.print (alt2); //Print Altitude digits on the right of the decimal place
Serial.println (" meters"); //Print unit of measure
*/
Serial.print ("Altitude= "); //Print Altitude
Serial.print (alt1); //Print Altitude digits on the left of the decimal place
Serial.print ("."); //Print decimal
Serial.print (alt2); //Print Altitude digits on the right of the decimal place
//Serial.println (" meters"); //Print unit of measure
Serial.println (" ft"); //Print unit of measure
Serial.print ("Barometric Pressure= "); //Print Barometric Pressure
Serial.print (bar1); //Print Barometric Pressure digits on the left of the decimal place
Serial.print ("."); //Print decimal
Serial.print (bar2); //Print Barometric Pressure digits on the left of the decimal place
//Serial.println (" Pa"); //Print unit of measure
Serial.println (" inHg"); //Print unit of measure
//----------------------------------End of Debugging-------------------------------------------
digitalWrite(LED, HIGH); //Turn on LED when transmitting
numbers[0] = temp1; //Temperature digits on the left of the decimal place
numbers[1] = temp2; //Temperature digits on the right of the decimal place
numbers[2] = alt1; //Altitude digits on the left of the decimal place
numbers[3] = alt2; //Altitude digits on the right of the decimal place
numbers[4] = bar1; //Barometric Pressure
numbers[5] = bar2; //Barometric Pressure
vw_send( (uint8_t *)numbers, sizeof(numbers));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(LED, LOW); //Turn off LED when transmitting
}
This is the Receiver Code:
#include <VirtualWire.h>
int LED = 13;
int numbers[6];
void setup()
{
Serial.begin(9600);
Serial.println("Setup");
pinMode(LED, OUTPUT);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(1000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
//vw_set_rx_pin(5); //pin 5 is used as the RX pin
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
//------------------Debugging---------------------
Serial.print(buflen, DEC);
Serial.println(" bytes received!");
//------------------Debugging----------------------
for (int i = 0; i < buflen; i++)
{
//-------------------Debugging-------------------
Serial.print("buf[");
Serial.print(i, DEC);
Serial.print("]=");
Serial.print(buf[i], DEC);
Serial.print(" ");
//-------------------Debugging------------------
}
Serial.println(); //For Debugging
//memcpy(buf, numbers, buflen);
for (int i = 0; i < 6; i++) //If you add more integers you have to change the 6 to how many intergers you have.
{
numbers[i] = word(buf[i*2+1], buf[i*2]);
//-------------------Debugging------------------
Serial.print("numbers[");
Serial.print(i, DEC);
Serial.print("]=");
Serial.print(numbers[i], DEC);
Serial.print(" ");
//-------------------Debugging-------------------
}
Serial.println(); //For Debugging
Serial.print("Temperature= ");
Serial.print(numbers[0], DEC);
Serial.print(".");
Serial.print(numbers[1], DEC);
Serial.println(" *F");
Serial.print("Altitude= ");
Serial.print(numbers[2], DEC);
Serial.print(".");
Serial.print(numbers[3], DEC);
//Serial.println(" meters");
Serial.println(" feet");
Serial.print("Barometric Pressure= ");
Serial.print(numbers[4], DEC);
Serial.print(".");
Serial.print(numbers[5], DEC);
//Serial.println(" Pa");
Serial.println(" inHg");
Serial.println();
}
delay(1000);
}