Skocz do zawartości

ESP8266 - skaner I2C szukający


99teki

Pomocna odpowiedź

- poniżej skaner i2c szukający adresów modułów , portów GPIO podłączonych do magistrali I2C dla esp8266.

- ja skanowałem z pomocą modułu nodeMCU, esp01s ma za mało portów GPIO wyprowadzonych na złącza.

- poniżej wynik skanowania i program pod arduino.

*
* i2c_port_address_scanner and GPIO.
* Scans ports D0 to D7 on an ESP8266 and searches for I2C device. based on the original code
* available on Arduino.cc and later improved by user Krodal and Nick Gammon (www.gammon.com.au/forum/?id=10896)
* D8 throws exceptions thus it has been left out
*
*/

#include <Wire.h>

	// ---------------------------------------------- setup ----------------------------------
void setup() {
  Serial.begin(115200);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\n\nI2C Scanner to scan for devices on each port pair D0 to D7");
  scanPorts();
}

uint8_t portArray[] = {16, 5, 4, 0, 2, 14, 12, 13};
//String portMap[] = {"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7"}; //for Wemos
String portMap[] = {"GPIO16", "GPIO5", "GPIO4", "GPIO0", "GPIO2", "GPIO14", "GPIO12", "GPIO13"};
			
	// ----------------------------		
void scanPorts() { 
  for (uint8_t i = 0; i < sizeof(portArray); i++) {
    for (uint8_t j = 0; j < sizeof(portArray); j++) {
      if (i != j){
        Serial.print("Scanning (SDA : SCL) - " + portMap[i] + " : " + portMap[j] + " - ");
        Wire.begin(portArray[i], portArray[j]);
        check_if_exist_I2C();
      }
    }
  }
}

	// ---------------------------
void check_if_exist_I2C() {
  byte error, address;
  int nDevices;
  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();
			
    if (error == 0){
      Serial.println();
      Serial.print("I2C device found at 7-bit address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
			Serial.print("  8-bit address 0x");
			Serial.print(address<<1, HEX);
      Serial.println("  !");
				
      nDevices++;
    } else if (error == 4) {
      Serial.print("Unknow error at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
    }
  } 	//	------------ for loop -----------
  if (nDevices == 0)
    Serial.println("No I2C devices found");
  else
    Serial.println("  **********************************\n");
  delay(500);           // wait 1 seconds for next scan, did not find it necessary
}

	// ------------------------------------ loop --------------------
void loop() {
}
// ------------------------------ end ----------------------------

 - logi z programu, wycięto dużą cześć logów.


I2C Scanner to scan for devices on each port pair D0 to D7
Scanning (SDA : SCL) - GPIO16 : GPIO5 - No I2C devices found
...
Scanning (SDA : SCL) - GPIO5 : GPIO2 - No I2C devices found
Scanning (SDA : SCL) - GPIO5 : GPIO14 - No I2C devices found
Scanning (SDA : SCL) - GPIO5 : GPIO12 - No I2C devices found
Scanning (SDA : SCL) - GPIO5 : GPIO13 - No I2C devices found
Scanning (SDA : SCL) - GPIO4 : GPIO16 - No I2C devices found
Scanning (SDA : SCL) - GPIO4 : GPIO5 - 
I2C device found at 7-bit address 0x3E  8-bit address 0x7C  !
  **********************************

Scanning (SDA : SCL) - GPIO4 : GPIO0 - No I2C devices found
...
Scanning (SDA : SCL) - GPIO14 : GPIO0 - No I2C devices found
Scanning (SDA : SCL) - GPIO14 : GPIO2 - 
I2C device found at 7-bit address 0x76  8-bit address 0xEC  !
  **********************************

Scanning (SDA : SCL) - GPIO14 : GPIO12 - No I2C devices found
Scanning (SDA : SCL) - GPIO14 : GPIO13 - No I2C devices found
...

 

Edytowano przez 99teki
  • Lubię! 1
Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.