Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

i2c

jeann0526

Recruit
Basic Member
Messages
3
Reaction score
0
Points
16
Patulong nmn po bali sa thesis po kc namin is gagamit kami ng mga sensors/modules na DHT22,Rain Sensor, Anemometer, SI1145(i2C),BMP180(i2C),rtc(i2C),micro sd card

bali nagsearch napo ako ng program each module ang problem ko po is kapag pinagsasama sama ko yung DHT22, SI1145, BMP180 at Rain Sensor is wala pong data na makita sa library may idea po ba kayo kung paano magprogram pag may 2 or more i2c devices include


//BMP180, DHT22, Rain Sensor, SI1145
/*Pin Configuration for each Sensors
*BMP180 0x77 SI1145 0x60
*Vin = 5v Vin = 5v
*Gnd = Gnd Gnd = Gnd
*SCL = 21 SCL = 21
*SDA = 20 SDA = 20

*DHT22 Rain Sensor
*= = 5v Vcc = 5v
*- = Gnd Gnd = Gnd
*out = A0 A0 = A1
*/
//Libraries
//Common
#include "Adafruit_Sensor.h" //BMP180 & DHT22
#include "Wire.h" //BMP180 & SI1145
//BMP180
#include "SFE_BMP180.h"
//DHT22
#include "DHT.h"
#include "DHT_U.h"
//SI1145
#include "Adafruit_SI1145.h"

//Constants
//BMP180
#define BMP_ADD 0x77
SFE_BMP180 pressure;
#define ALTITUDE 5.0//Manila
//#define ALTITUDE //dingalan
//DHT22
#define DHTPIN A0
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);
//Rain Sensor
const int rainMin = 0;
const int rainMax = 1024;
#define rainPIN A1
//SI1145
#define SI1145_ADD 0x60
Adafruit_SI1145 uv = Adafruit_SI1145();
float UVindex = uv.readUV();

//Variables
//Common
double temp;
//BMP180
char status;
double P, p0, a;
//DHT22
int chk;
float hum;

void setup() {
//Common
Wire.begin();
Serial.begin(9600);
Serial.println("REBOOT");
//BMP180
if(Wire.begin(0x77)){
Serial.println("BMP180 Initializattion Succcessful");
}
else{
Serial.println("BMP180 Initialization Failed!");
while(1);
}

//DHT22
dht.begin();
if(isnan(hum)||isnan(temp)){
Serial.println(F("DHT22 Initialization Failed!"));
while(1);
}
else{
Serial.println("DHT22 Initialization Successful");
}
//SI1145
for (Wire.begin(0x60)){
if(!uv.begin()){
Serial.println("SI1145 Initialization Failed!");
while(1);
}
else{
Serial.println("SI1145 Initialization Successful");
}
}
}
void loop() {
Serial.begin(115200);
//BMP180
status = pressure.startPressure(3);
if (status != 0)
{
delay(status);
status = pressure.getPressure(P,temp);
if(status != 0)
{
Serial.print(P*0.0295333727,2);
Serial.println("Hg");
p0 = pressure.sealevel(P, ALTITUDE);
Serial.print("Sea Level Relative Pressure: ");
Serial.print(p0*0.0295333727,2);
Serial.println("Hg");
a = pressure.altitude(P,p0);
Serial.print(a,0);
Serial.print("meters");
}
else
Serial.println("Error retrieving pressure measurement");
}
else
Serial.println("Error starting pressure measrurement");
//DHT22
hum = dht.readHumidity();
temp = dht.readTemperature();
Serial.print("Relative Humidity: ");
Serial.print(hum);
Serial.println("%");
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println("°C");
//Rain Sensor
int rainReading = analogRead(rainPIN);
int rainRange = map(rainReading, rainMin, rainMax, 0, 4);
switch(rainRange){
case 0:
Serial.println("Heavy Rain");
break;
case 1:
Serial.println("Moderate Rain");
break;
case 2:
Serial.println("Light Rain");
break;
case 3:
Serial.println("No Rain");
break;
}
//SI1145

UVindex /= 100.0;
Serial.print("UV: ");
Serial.println(UVindex);
if( UVindex <3.0){
Serial.println("Low");
}
else if ( UVindex >= 3.0 && UVindex <60){
Serial.println("Medium");
}
else if ( UVindex >= 6 && UVindex < 8){
Serial.println("High");
}
else{
Serial.println("Danger");
}
delay(2000);
}


ayan po yung code ko salamat po
 
na-solve mo na ba ito? paano ang connection mo sa i2c devices? ginamitan mo ba ng 1 to 8 I2c multi-channel module?
 
na-solve mo na ba ito? paano ang connection mo sa i2c devices? ginamitan mo ba ng 1 to 8 I2c multi-channel module?


Ok n apo bali ginawa ko nlng is ginamit ko yung dalawang SDA and SCL pins ng arduino mega pero may nahanap kc akong code ng BMP180 nai2c protocol ginamit yun yung code na ginamit ko para sure na gumana :) :) :) sa anemometer nmn ako nag kakaproblema ngayon hehe
 
Ok n apo bali ginawa ko nlng is ginamit ko yung dalawang SDA and SCL pins ng arduino mega pero may nahanap kc akong code ng BMP180 nai2c protocol ginamit yun yung code na ginamit ko para sure na gumana :) :) :) sa anemometer nmn ako nag kakaproblema ngayon hehe

buti naman nasolve mo na. hindi kasi pwedeng 2 or more i2c device na nakakonekta sa isang pares ng SDA/SCL pins unless gamitan mo ng 1 to 8 I2c multi-channel module na merong 8-i2c inputs.
 
ayyy ganun po ba yun akala ko po kc need lng ng resistor yung sa youtube po kc may schematic na need lng ng resistors ihhh tapos i2c protocol yung codes wala nmn po akong idea sa ganun anyway thank you po sa info :) :) :)
 
Back
Top Bottom