Hello All,
I'm kinda new to the Arduino world. I have an Arduino Uno R3. I have kinda figured out the I2C communication thing. My current problem is how do I connect multiple I2c sensors to the one controller?
I have a RTC module, and a BMP085. Do I need to set my uno as the master, and the devices as slaves? Any help would be great!!
Thank you All
// REV 1.1.0
// 02-19-2013
// Date and time functions using just software, based on millis() & timer
#include <Wire.h>
#include <RTClib.h>
#include <SimpleTimer.h>
#include <Adafruit_BMP085.h>
const int temp = 0;
const int LED = 13;
const float wind = 1;
RTC_Millis RTC;
Adafruit_BMP085 bmp;
void setup ()
{
Serial.begin(9600);
pinMode(LED,OUTPUT);
RTC.begin(DateTime(__DATE__, __TIME__)); //sets the RTC to the date & time this sketch was compiled
bmp.begin();
}
void loop ()
{
/* noInterrupts();
if(millis() % 1200000 == 0)
RTC.adjust(DateTime(__DATE__, __TIME__));
interrupts();
*/
float volt, degC, MPH;
int room, deadband, setpoint, degF, dispHour, dispDOW, F, Pressure;
MPH = getVoltage(wind);
volt = getVoltage(temp);
degC = (volt - .5) * 100.0;
degF = degC * (9.0/5.0) + 32.0;
room = 72;
deadband = 3;
setpoint = room - deadband;
F = bmp.readTemperature() * (9.0/5.0) + 32.0;
Pressure = bmp.readPressure() * 0.000295;
DateTime now = RTC.now();
dispHour = now.hour();
dispDOW = now.dayOfWeek();
// print readings every 5 min.
if (millis() % 6000 == 0)
{
// RTD Day Of the Week
if(dispDOW == 0)
Serial.print("SUN: ");
if(dispDOW == 1)
Serial.print("MON: ");
if(dispDOW == 2)
Serial.print("TUE: ");
if(dispDOW == 3)
Serial.print("WED: ");
if(dispDOW == 4)
Serial.print("THU: ");
if(dispDOW == 5)
Serial.print("FRI: ");
if(dispDOW == 6)
Serial.print("SAT: ");
// RTD Date format D/M/TYYY
Serial.print(now.month());
Serial.print('/');
Serial.print(now.day());
Serial.print('/');
Serial.print(now.year() - 2000);
Serial.print(' ');
// RTC Time in 12 hour format with AM/PM
Serial.print((dispHour > 12) ? dispHour - 12 : ((dispHour == 12) ? 12 : dispHour));
Serial.print(":");
if (now.minute() < 10)
Serial.print("0");
Serial.print(now.minute());
Serial.print(':');
if (now.second() < 10)
Serial.print ("0");
Serial.print(now.second());
Serial.print((dispHour<12) ? " AM" : " PM");
Serial.println();
// Temp Display in Deg F
Serial.print(" Temp: "); // Temp will be in a format of
Serial.println(degF); // ##.#
// BMP Temp Display in Deg F
Serial.print(" BMP_Temp: ");
Serial.println(F);
// Pressure Displayed in inHG
Serial.print(" ATM Pressure: ");
Serial.println(Pressure);
// Wind Speed
Serial.print( "MPH: ");
Serial.println(MPH);
}
delay(100); // next step try to use the RTC to take readings every 5 min.
if (degF <= setpoint)
{
digitalWrite(LED,HIGH);
}
if (degF > room)
{
digitalWrite(LED,LOW);
}
}
float getVoltage(int pin1)
{
return (analogRead(pin1) * 0.004882814);
}
float getVoltage(float pin2)
{
return (analogRead(pin2));
}
Above is my current code for the weather station I am working on. No advice is bad advice!!