M265 I2C_SCANNER (#28117)

This commit is contained in:
ellensp 2025-10-19 12:18:02 +13:00 committed by GitHub
parent fb95e66652
commit 9f0fa5a040
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 87 additions and 3 deletions

View file

@ -4718,6 +4718,11 @@
//
//#define PINS_DEBUGGING
//
// M265 - I2C Scanner
//
//#define I2C_SCANNER
// Enable Tests that will run at startup and produce a report
//#define MARLIN_TEST_BUILD

View file

@ -0,0 +1,69 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2025 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "../../../inc/MarlinConfig.h"
#if ENABLED(I2C_SCANNER)
#include "../../../libs/hex_print.h"
#include "../../gcode.h"
#include <Wire.h> // Include Wire library for I2C communication
/**
* M265: I2C Scanner - Scan for I2C devices on DOGLCD I2C pins
*
* Usage: M265
*
* Scans I2C addresses 0x08 to 0x77 and reports any responding devices.
*/
void GcodeSuite::M265() {
Wire.begin();
int device_count = 0;
SERIAL_ECHOLNPGM("Scanning I2C (0x08-0x77)...");
for (uint8_t address = 0x08; address <= 0x77; address++) {
Wire.beginTransmission(address);
const uint8_t error = Wire.endTransmission();
if (error == 0) {
// Device found
device_count++;
SERIAL_ECHOLNPGM("I2C device found at address 0x", hex_byte(address));
}
else if (error == 4)
SERIAL_ECHOLNPGM("Unknown error at address 0x", hex_byte(address));
safe_delay(5); // Small delay between scans
}
SERIAL_ECHOPGM("I2C scan complete. ");
if (device_count == 0)
SERIAL_ECHOLNPGM("No I2C devices found");
else {
SERIAL_ECHOLN("Found ", device_count, " device");
if (device_count > 1) SERIAL_CHAR('s');
SERIAL_EOL();
}
}
#endif // I2C_SCANNER

View file

@ -826,6 +826,10 @@ void GcodeSuite::process_parsed_command(bool no_ok/*=false*/) {
case 261: M261(); break; // M261: Request data from an i2c slave
#endif
#if ENABLED(I2C_SCANNER)
case 265: M265(); break; // M265: I2C Scanner
#endif
#if ENABLED(PREVENT_COLD_EXTRUSION)
case 302: M302(); break; // M302: Allow cold extrudes (set the minimum extrude temperature)
#endif

View file

@ -211,6 +211,7 @@
* M256 - Set LCD brightness: 'M256 B<brightness>' (0-255). (Requires an LCD with brightness control)
* M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
* M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
* M265 - i2c Scanner - Scan for I2C devices. (Requires I2C_SCANNER)
* M280 - Set servo position absolute: 'M280 P<index> S<angle|µs>'. (Requires servos)
* M281 - Set servo min|max position: 'M281 P<index> L<min> U<max>'. (Requires EDITABLE_SERVO_ANGLES)
* M282 - Detach servo: 'M282 P<index>'. (Requires SERVO_DETACH_GCODE)
@ -965,6 +966,10 @@ private:
static void M261();
#endif
#if ENABLED(I2C_SCANNER)
static void M265();
#endif
#if HAS_SERVOS
static void M280();
#if ENABLED(EDITABLE_SERVO_ANGLES)

View file

@ -3651,7 +3651,7 @@
#endif
// Flag whether hex_print.cpp is needed
#if ANY(AUTO_BED_LEVELING_UBL, M100_FREE_MEMORY_WATCHER, DEBUG_GCODE_PARSER, TMC_DEBUG, MARLIN_DEV_MODE, DEBUG_CARDREADER, M20_TIMESTAMP_SUPPORT, HAS_STM32_UID)
#if ANY(AUTO_BED_LEVELING_UBL, M100_FREE_MEMORY_WATCHER, DEBUG_GCODE_PARSER, TMC_DEBUG, MARLIN_DEV_MODE, DEBUG_CARDREADER, M20_TIMESTAMP_SUPPORT, HAS_STM32_UID, I2C_SCANNER)
#define NEED_HEX_PRINT 1
#endif

View file

@ -39,7 +39,7 @@ exec_test $1 $2 "RAMPS4DUE_EFB with ABL (Bilinear), ExtUI, S-Curve, many options
restore_configs
opt_set MOTHERBOARD BOARD_RADDS Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z3_DRIVER_TYPE A4988 \
X_MAX_PIN -1 Y_MAX_PIN -1
opt_enable ENDSTOPPULLUPS BLTOUCH AUTO_BED_LEVELING_BILINEAR \
opt_enable ENDSTOPPULLUPS BLTOUCH AUTO_BED_LEVELING_BILINEAR I2C_SCANNER \
Z_STEPPER_AUTO_ALIGN Z_STEPPER_ALIGN_STEPPER_XY Z_SAFE_HOMING
exec_test $1 $2 "RADDS with ABL (Bilinear), Triple Z Axis, Z_STEPPER_AUTO_ALIGN, E_DUAL_STEPPER_DRIVERS" "$3"

View file

@ -268,7 +268,8 @@ HAS_FILAMENT_SENSOR = build_src_filter=+<src/feature/runout.c
MK2_MULTIPLEXER = build_src_filter=+<src/feature/snmm.cpp>
HAS_CUTTER = build_src_filter=+<src/feature/spindle_laser.cpp> +<src/gcode/control/M3-M5.cpp>
HAS_DRIVER_SAFE_POWER_PROTECT = build_src_filter=+<src/feature/stepper_driver_safety.cpp>
EXPERIMENTAL_I2CBUS = build_src_filter=+<src/feature/twibus.cpp> +<src/gcode/feature/i2c>
EXPERIMENTAL_I2CBUS = build_src_filter=+<src/feature/twibus.cpp> +<src/gcode/feature/i2c/M260_M261.cpp>
I2C_SCANNER = build_src_filter=+<src/gcode/feature/i2c/M265.cpp>
G26_MESH_VALIDATION = build_src_filter=+<src/gcode/bedlevel/G26.cpp>
ASSISTED_TRAMMING = build_src_filter=+<src/feature/tramming.cpp> +<src/gcode/bedlevel/G35.cpp>
HAS_MESH = build_src_filter=+<src/gcode/bedlevel/G42.cpp>