[Risolto]BME280 I2C_test

Ciao a tutti! sto cercando di utilizzare il BME280 ed in primis ho svolto il test I2C:

#include <Wire.h>
 
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    Serial.println(error);
    delay(500);
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

L'ho eseguito sia con Arduino Uno che con l'ESP32, ottenendo sempre il medesimo risultato: errore 2. Il collegamento che ho effettuato, ad esempio con Arduino Uno, la Vin-->3.3V, SDA-->A4, SCL-->A5, GND-->GND. L'errore da cosa è dovuto e come faccio a risolverlo? In attesa di un gentile riscontro vi ringrazio anticipatamente

Guarda, ho avuto modo di fare la stessa prova proprio un paio di giorni fa ... avevo dei modulini BME280 presi tempo fa su AliExpress e non sapevo quale indirizzo usassero né se fossero funzionanti ... stesso tuo collegamento con Arduino UNO ed al primo colpo li ha individuati su 0x77 quindi ... ricontrolla i collegamenti e ... se sono giusti i ... moduli sono probabilmente guasti.

Ah ... io uso un multispeed scanner ... provalo:

//
//    FILE: MultiSpeedI2CScanner.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.01
// PURPOSE: I2C scanner @different speeds
//    DATE: 2013-11-05
//     URL:
//
// Released to the public domain
//

#include <Wire.h>
#include <Arduino.h>

#define PRINTALL true

int speed[] = { 
  10, 50, 100, 200, 400 };
const int speeds = sizeof(speed)/sizeof(speed[0]);


void setup() 
{
  Serial.begin(115200);
  Serial.println("Multispeed - I2C Scanner - V0.1 - \n");

  Wire.begin();

  I2Cscan();
}

void loop() 
{
}

void I2Cscan()
{
  // HEADER
  Serial.print("ADDR\tADDR\t");
  for (uint8_t s = 0; s < speeds; s++)
  {
    Serial.print("\t");
    Serial.print(speed[s]);
  }
  Serial.println("\t[KHz]");
  Serial.println("-----------------------------------------------------------------------");


  // TEST
  for (uint8_t address = 0; address < 128; address++)
  {
    bool printLine = PRINTALL;
    bool found[speeds];

    for (uint8_t s = 0; s < speeds ; s++)
    {
      TWBR = (F_CPU/speed[s] - 16)/2;
      Wire.beginTransmission (address);
      found[s] = (Wire.endTransmission () == 0);
      printLine |= found[s];
    }

    if (printLine)
    {
      Serial.print(address, DEC);
      Serial.print("\t0x");
      Serial.print(address, HEX);
      Serial.print("\t");

      for (uint8_t s = 0; s < speeds ; s++)
      {
        Serial.print("\t");
        Serial.print(found[s]? "V":".");
      }

      Serial.println();
    }
  }
  Serial.println("\ndone...");  
}

Guglielmo

Ho testato il tuo sketch e sono riuscito a risolvere il problema, ti ringrazio

Bene ... se riporti quale era il problema, la cosa potrebbe essere utili per altri che, in futuro, dovessero anche loro riscontrarlo :slight_smile:

Guglielmo

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.