Skip to main content
added 1750 characters in body
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

I have the following problem: Since the BH1750 Sensor only supports two different I2C adresses, but i need to use 6 of those sensors, i wanna use 3 arduinos, 2 nanos, 1 uno and send the data from the nanos to the uno. Problem is that the I2C bus is already in use and while trying to send data, it does not work properly. Is this even possible? When trying it out, i can't get anything correctenter image description here


Update:

That's what i tried now:

Results i get are still not correct

enter image description here

#include <Wire.h>
#include <BH1750.h>

// This code will feature the use of 6 gy 30 light sensors

BH1750 active_sensor(0x23); // We will use this adress for stating the active sensor
BH1750 inactive_sensor(0x5C);

void setup(){

  Serial.begin(9600);

  // Setting the input pins for controling the addr pins of the modules
    pinMode(8, OUTPUT); 
    pinMode(9, OUTPUT); 
    pinMode(10, OUTPUT); 
    pinMode(11, OUTPUT); 
    pinMode(12, OUTPUT); 
    pinMode(13, OUTPUT);

    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
    digitalWrite(11, LOW);
    digitalWrite(12, LOW);
    digitalWrite(13, LOW);


  // Initialize the i2c bus
  Wire.begin();

 // Here we will set the mode of the module
  if (active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
    Serial.println(F("BH1750 Advanced begin"));
  }
  else {
    Serial.println(F("Error initialising BH1750"));
    Serial.println("Problem on 1");
  }
}

void loop() {  
  get_values();

}

void get_values(){
  int i;
  Serial.println("----");
  for(i = 8; i<=13;i++){
    digitalWrite(i,HIGH);    
    delay(50);
    int lux = 0;
    lux = active_sensor.readLightLevel();    
    Serial.println(lux);    
    delay(50);
    digitalWrite(i,LOW);
    delay(150);
  }
}
    

I have the following problem: Since the BH1750 Sensor only supports two different I2C adresses, but i need to use 6 of those sensors, i wanna use 3 arduinos, 2 nanos, 1 uno and send the data from the nanos to the uno. Problem is that the I2C bus is already in use and while trying to send data, it does not work properly. Is this even possible? When trying it out, i can't get anything correctenter image description here

I have the following problem: Since the BH1750 Sensor only supports two different I2C adresses, but i need to use 6 of those sensors, i wanna use 3 arduinos, 2 nanos, 1 uno and send the data from the nanos to the uno. Problem is that the I2C bus is already in use and while trying to send data, it does not work properly. Is this even possible? When trying it out, i can't get anything correctenter image description here


Update:

That's what i tried now:

Results i get are still not correct

enter image description here

#include <Wire.h>
#include <BH1750.h>

// This code will feature the use of 6 gy 30 light sensors

BH1750 active_sensor(0x23); // We will use this adress for stating the active sensor
BH1750 inactive_sensor(0x5C);

void setup(){

  Serial.begin(9600);

  // Setting the input pins for controling the addr pins of the modules
    pinMode(8, OUTPUT); 
    pinMode(9, OUTPUT); 
    pinMode(10, OUTPUT); 
    pinMode(11, OUTPUT); 
    pinMode(12, OUTPUT); 
    pinMode(13, OUTPUT);

    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
    digitalWrite(11, LOW);
    digitalWrite(12, LOW);
    digitalWrite(13, LOW);


  // Initialize the i2c bus
  Wire.begin();

 // Here we will set the mode of the module
  if (active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
    Serial.println(F("BH1750 Advanced begin"));
  }
  else {
    Serial.println(F("Error initialising BH1750"));
    Serial.println("Problem on 1");
  }
}

void loop() {  
  get_values();

}

void get_values(){
  int i;
  Serial.println("----");
  for(i = 8; i<=13;i++){
    digitalWrite(i,HIGH);    
    delay(50);
    int lux = 0;
    lux = active_sensor.readLightLevel();    
    Serial.println(lux);    
    delay(50);
    digitalWrite(i,LOW);
    delay(150);
  }
}
    
Source Link

Connecting two Arduinos via I2C while I2C Pins A4/A5 are already in use

I have the following problem: Since the BH1750 Sensor only supports two different I2C adresses, but i need to use 6 of those sensors, i wanna use 3 arduinos, 2 nanos, 1 uno and send the data from the nanos to the uno. Problem is that the I2C bus is already in use and while trying to send data, it does not work properly. Is this even possible? When trying it out, i can't get anything correctenter image description here