Press "Enter" to skip to content

Smart sniffer I2C zbernice

MiroRi 0

I2C smart sniffer

 

Je to skener I2C zbernice s databázov najpoužívanejších I2C zariadení (preto smart).

Ako hardwér som použil môj ESP-01 progtest.

 

 

 

 

 

 

 

 

 

 

Je to vlastne kombinácia programátoru ESP8266 na doske ESP-01 s vývodmi GPIO 0 a GPIO 2, ktoré používam v tomto prípade ako I2C zbernicu.

 

 

Základný kód ​​ i2c_smartsniffer.ino:

 

/*

​​ * Toto vyhľadá všetky zariadenia s I2C zbernicou, prečíta ich adresu v HEX

​​ * a vypíše všetky typy zariadení, ktoré bežne používajú túto adresu.

​​ * Názvy a ich adresy sú uložené v i2c.h (ak niektoré chýba, treba ho dpoísať).

​​ * Ak na sériový port pošleš typ zariadenia s I2C zbernicou, vráti sa ti jeho HEX adresa

​​ * aj s možnými variantmi.

​​ * Napr. pošleš BMP28 a vráti sa BMP280 Temp/Barometric (0x76 or 0x77) používa adresu 0x76

​​ * Ešte poznámočka! Používam ESP8266 (bez využitia WiFi), lebo dostatok pamäte.

​​ * Kód funguje aj na Arduino UNO a Nano, len i2c.h sa musí podstatne skrátiť lebo zaberá 376%  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ 

​​ * dynamickej pamäti Arduino Nano

​​ *  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ 5.11.2024 MiroR

​​ */

 

#include "i2c_list.h"

#include <Wire.h>

 

void setup() {

 ​​​​ Serial.begin (115200);

 ​​​​ Serial.println ();

 ​​​​ Serial.println ("i2c_smartsniffer.ino");

 ​​​​ Serial.println ("POZOR! Ak maju dve zariadenia rovnaku adresu, najde len jedno zariadenie z nich.");

 ​​​​ Serial.println ("Vzdy porovnaj fyzicky pocet zariadeni z poctom uvedenom na konci vypisu.");

 ​​​​ Serial.println ("Pre opakovany test stlac RESET, alebo posli enter na seriovy port.");

 ​​​​ Serial.println ("Ak chceš vedieť standardne pouzivanu I2C adreu isteho zaraidenia,\nposli jeho nazov na na seriovy port.");

 ​​​​ Serial.print ("Napr. posli BMP280, ");

 ​​​​ Serial.println ("vrati sa Ti Temp/Barometric (0x76 or 0x77) používa adresu 0x76\na este dalsie, ktore s nim moze mat koliziu.\n");

 ​​​​ Wire.begin(2,0);//pre ESP

 ​​​​ //Wire.begin();//pre Arduino s prídavnou RAM-kou

 ​​​​ sniffing();

}

 

void sniffing(){

 ​​​​ byte count = 0; ​​ 

 ​​​​ for (byte i = 8; i < 120; i++){

 ​​ ​​ ​​​​ Wire.beginTransmission (i);

 ​​ ​​ ​​​​ if (Wire.endTransmission () == 0)

 ​​ ​​ ​​ ​​ ​​​​ {

 ​​ ​​ ​​ ​​ ​​​​ Serial.print ("I2C HEX address: ");

 ​​ ​​ ​​ ​​ ​​​​ //Serial.print (i, DEC);

 ​​ ​​ ​​ ​​ ​​​​ Serial.print (">>>0x");

 ​​ ​​ ​​ ​​ ​​​​ Serial.print (i, HEX);

 ​​ ​​ ​​ ​​ ​​​​ Serial.println("<<< Mozne zaraidenia:");

 ​​ ​​ ​​ ​​ ​​​​ 

 ​​ ​​ ​​ ​​ ​​​​ //Serial.println (")");

 ​​ ​​ ​​ ​​ ​​​​ uint8_t uintValue = (uint8_t)i;

 ​​ ​​ ​​ ​​ ​​​​ printDeviceName(uintValue);

 ​​ ​​ ​​ ​​ ​​​​ Serial.println ();

 ​​ ​​ ​​ ​​ ​​​​ count++;

 ​​ ​​ ​​ ​​ ​​​​ delay (1); ​​ // maybe unneeded?

 ​​ ​​ ​​ ​​ ​​​​ }

 ​​​​ }

 ​​​​ Serial.println("\nPocet zariadeni: "+String(count)+"\n"); ​​ 

}

 

void loop() {

/* ​​ 

 ​​​​ if (Serial.available()) {

 ​​ ​​ ​​​​ char cr = Serial.read();

 ​​ ​​ ​​​​ if (cr == '\r') {

 ​​ ​​ ​​ ​​ ​​​​ sniffing();

 ​​ ​​ ​​​​ }

 ​​​​ }

*/

 ​​​​ if (Serial.available() > 0) {

 ​​ ​​ ​​​​ String input = Serial.readStringUntil('\n'); // Prečítaj vstup do konca riadku

 ​​ ​​ ​​​​ if(input.length()>2)printDeviceAddress(input);

 ​​ ​​ ​​​​ else sniffing();

 ​​​​ }  ​​ ​​​​ 

}

void printDeviceName(uint8_t detectedAddress) {

 ​​​​ for (int i = 0; i < sizeof(devices) / sizeof(devices[0]); i++) {

 ​​ ​​ ​​​​ if (devices[i].address == detectedAddress) {

 ​​ ​​ ​​ ​​ ​​​​ Serial.println(devices[i].name);

 ​​ ​​ ​​​​ }

 ​​​​ }

}

 

void printDeviceAddress(String deviceName) {

 ​​​​ for (int i = 0; i < sizeof(devices) / sizeof(devices[0]); i++) {

 ​​ ​​ ​​ ​​ ​​​​ String testString=devices[i].name;

 ​​ ​​ ​​​​  ​​​​ testString.trim();

 ​​ ​​ ​​ ​​ ​​​​ deviceName.trim();

 ​​ ​​ ​​ ​​ ​​​​ if(testString.indexOf(deviceName)>-1){

 ​​ ​​ ​​ ​​ ​​​​ Serial.print(devices[i].name);

 ​​ ​​ ​​ ​​ ​​​​ Serial.print(" používa adresu 0x");

 ​​ ​​ ​​ ​​ ​​​​ Serial.println(devices[i].address, HEX); // Vypíš adresu v hexa formáte

 ​​ ​​ ​​ ​​ ​​​​ return;

 ​​ ​​ ​​​​ }

 ​​​​ }

 ​​​​ // Ak zariadenie neexistuje

 ​​​​ if(deviceName=="test"){

 ​​ ​​ ​​​​ sniffing();

 ​​ ​​ ​​​​ return;

 ​​ ​​ ​​​​ }

 ​​​​ Serial.println("Zariadenie "+deviceName+" nebolo nájdené.");

}

 

Databáza I2C zaraidení i2c_list.h (skrátená, ak napíšeš pošlem celú :)) ):

struct DeviceInfo {

 ​​​​ uint8_t address;

 ​​​​ const char* name;

};

 

DeviceInfo devices[] = {

{0x3C,"SSD1305 monochrome OLED (0x3C or 0x3D, hardware selectable on some displays with a solder connection)"},

{0x3C,"SSD1306 monochrome OLED (0x3C or 0x3D, hardware selectable on some displays with a solder connection)"},

{0x3D,"SSD1305 monochrome OLED (0x3C or 0x3D, hardware selectable on some displays with a solder connection)"},

{0x3D,"SSD1306 monochrome OLED (0x3C or 0x3D, hardware selectable on some displays with a solder connection)"},

{0x40,"PCA9685 16-channel PWM driver default address (0x40 – 0x7F)"},

{0x40,"INA219 High-Side DC Current/Voltage sensor (0x40 – 0x4F)"},

{0x40,"INA260 Precision DC Current/Power Sensor (0x40 – 0x4F)"},

{0x41,"INA219 High-Side DC Current/Voltage sensor (0x40 – 0x4F)"},

{0x41,"INA260 Precision DC Current/Power Sensor (0x40 – 0x4F)"},

{0x48,"ADS1115 4-channel 16-bit ADC (0x48 0x49 0x4A or 0x4B)"},

{0x4A,"PCF8591 Quad 8-bit ADC + 8-bit DAC (0x48 – 0x4F)"},

{0x71,"PCT2075 Temperature Sensor (0x28-0x2E, 0x48-0x4F, 0x70-0x77)"},

{0x71,"TCA9548 1-to-8 I2C Multiplexer (0x70 – 0x77)"},

{0x72,"HT16K33 LED Matrix Driver (0x70 – 0x77)"},

{0x72,"PCT2075 Temperature Sensor (0x28-0x2E, 0x48-0x4F, 0x70-0x77)"},

{0x72,"TCA9548 1-to-8 I2C Multiplexer (0x70 – 0x77)"},

{0x73,"HT16K33 LED Matrix Driver (0x70 – 0x77)"},

{0x73,"PCT2075 Temperature Sensor (0x28-0x2E, 0x48-0x4F, 0x70-0x77)"},

{0x73,"TCA9548 1-to-8 I2C Multiplexer (0x70 – 0x77)"},

{0x74,"HT16K33 LED Matrix Driver (0x70 – 0x77)"},

{0x74,"IS31FL3731 144-LED CharliePlex driver (0x74 0x75 0x66 or 0x77)"},

{0x74,"PCT2075 Temperature Sensor (0x28-0x2E, 0x48-0x4F, 0x70-0x77)"},

{0x74,"TCA9548 1-to-8 I2C Multiplexer (0x70 – 0x77)"},

{0x75,"HT16K33 LED Matrix Driver (0x70 – 0x77)"},

{0x75,"IS31FL3731 144-LED CharliePlex driver (0x74 0x75 0x66 or 0x77)"},

{0x75,"PCT2075 Temperature Sensor (0x28-0x2E, 0x48-0x4F, 0x70-0x77)"},

{0x75,"TCA9548 1-to-8 I2C Multiplexer (0x70 – 0x77)"},

{0x76,"BME280 Temp/Barometric/Humidity (0x76 or 0x77)"},

{0x76,"BME680 Temp/Barometric/Humidity/Gas (0x76 or 0x77)"},

{0x76,"BMP280 Temp/Barometric (0x76 or 0x77)"}, ​​ 

 ​​​​ // ... ostatné zariadenia

};

 

Výstup na serial monitore:

 

POZOR! Ak maju dve zariadenia rovnaku adresu, najde len jedno zariadenie z nich.

Vzdy porovnaj fyzicky pocet zariadeni z poctom uvedenom na konci vypisu.

Pre opakovany test stlac RESET, alebo posli enter na seriovy port.

Ak chceš vedieť standardne pouzivanu I2C adreu isteho zaraidenia,

posli jeho nazov na na seriovy port.

Napr. posli BMP280, vrati sa Ti Temp/Barometric (0x76 or 0x77) používa adresu 0x76

a este dalsie, ktore s nim moze mat koliziu.

 

I2C HEX address: >>>0x3C<<< Mozne zaraidenia:

SSD1305 monochrome OLED (0x3C or 0x3D, hardware selectable on some displays with a solder connection)

SSD1306 monochrome OLED (0x3C or 0x3D, hardware selectable on some displays with a solder connection)

 

I2C HEX address: >>>0x48<<< Mozne zaraidenia:

ADS1115 4-channel 16-bit ADC (0x48 0x49 0x4A or 0x4B)

ADT7410 Temp sensor (0x48 0x49 0x4A or 0x4B)

INA219 High-Side DC Current/Voltage sensor (0x40 – 0x4F)

INA260 Precision DC Current/Power Sensor (0x40 – 0x4F)

PCF8591 Quad 8-bit ADC + 8-bit DAC (0x48 – 0x4F)

PCT2075 Temperature Sensor (0x28-0x2E, 0x48-0x4F, 0x70-0x77)

PN532 NFC/RFID reader (0x48 only)

TMP102 Temperature sensor (0x48 0x49 0x4A or 0x4B)

TMP117 Temperature sensor (0x48 0x49 0x4A or 0x4B)


ESP-01 progtest

<< Translate