├── platformio.ini ├── README.md ├── LICENSE └── src └── main.cpp /platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | 12 | [env:m5stack-stamps3] 13 | platform = espressif32 14 | board = m5stack-stamps3 15 | framework = arduino 16 | lib_deps = 17 | m5stack/M5Cardputer@^1.0.3 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # I2C Scanner for M5Cardputer 2 | 3 | It scans the I2C bus for connected devices and displays their addresses on the built-in screen. The addresses are shown in hexadecimal format. 4 | 5 | 6 | ## Hardware Requirements 7 | 8 | - M5Cardputer 9 | - I2C device to scan on the grove connector 10 | 11 | 12 | ## Usage 13 | 14 | - The M5 Card Computer will start scanning the I2C bus upon startup. 15 | - Detected I2C device addresses will be displayed on the screen in hexadecimal format with the prefix 0x. 16 | - If no I2C devices are found, the message "No I2C devices" will be displayed. 17 | The scan will repeat every 8 seconds. 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include // Include the M5Cardputer library 3 | #include 4 | 5 | std::vector i2cAddresses; // Tableau pour stocker les adresses I2C détectées 6 | 7 | void setup() 8 | { 9 | auto cfg = M5.config(); // Get the M5 configuration 10 | M5.begin(cfg); // Initialize the M5 11 | M5.Power.begin(); // Initialize the M5 power 12 | 13 | M5.Lcd.setTextSize(2); 14 | M5.Lcd.setRotation(1); 15 | M5.Lcd.clear(BLACK); 16 | M5.Lcd.setCursor(55, 60); 17 | M5.Lcd.printf("I2C Scanner\n"); 18 | 19 | delay(1000); // Delay to show the initial message 20 | 21 | Wire.begin(); 22 | } 23 | 24 | void loop() 25 | { 26 | byte error, address; 27 | int nDevices; 28 | 29 | i2cAddresses.clear(); // Erase previous adresses 30 | M5.Lcd.clear(BLACK); 31 | M5.Lcd.setTextSize(2); 32 | M5.Lcd.setCursor(60, 40); 33 | M5.Lcd.println("Loading..."); 34 | 35 | nDevices = 0; 36 | for (address = 1; address < 127; address++) 37 | { 38 | // The i2c_scanner uses the return value of 39 | // the Write.endTransmission to see if 40 | // a device did acknowledge to the address. 41 | Wire.beginTransmission(address); 42 | error = Wire.endTransmission(); 43 | M5.Lcd.clear(); 44 | M5.Lcd.setCursor(100, 80); 45 | M5.Lcd.setTextSize(2); 46 | M5.Lcd.print(address); 47 | 48 | if (error == 0) 49 | { 50 | if (address < 16) 51 | M5.Lcd.print("0"); 52 | 53 | i2cAddresses.push_back(address); // add adsress 54 | nDevices++; 55 | } 56 | else if (error == 4) 57 | { 58 | M5.Lcd.print("Error at address 0x"); 59 | 60 | if (address < 16) 61 | M5.Lcd.print("0"); 62 | 63 | M5.Lcd.println(address, HEX); 64 | } 65 | } 66 | 67 | M5.Lcd.setCursor(35, 10); 68 | if (nDevices == 0) 69 | M5.Lcd.println("No I2C devices\n"); 70 | else 71 | { 72 | M5.Lcd.clear(); 73 | M5.Lcd.printf("%d I2C devices\n", nDevices); 74 | M5.Lcd.println(""); 75 | 76 | for (byte addr : i2cAddresses) 77 | { 78 | M5.Lcd.print("0x"); 79 | if (addr < 16) 80 | M5.Lcd.print("0"); 81 | M5.Lcd.println(addr, HEX); 82 | } 83 | } 84 | delay(8000); // wait 8 seconds for next scan 85 | } 86 | --------------------------------------------------------------------------------