54. I2C Scanner

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

 

Code

/*Paste your code here*/
// can use this i2cdetect -y 1//
import smbus2
import time

def scan_reg(bus_number=1):
    print(f"scanning i2c buses{bus_number}")
    detect_device=0

    with smbus2.SMBus(bus_number) as bus:
        for address in range(0x03,0x78):
            try:
                bus.write_quick(address)

                print(f"device founded at address: 0x{address:02X}")
                detect_device+=1

            except OSError:
                continue
    print("-"*30)
    print(f"scan complete. Total device found:{detect_device}")
if __name__=="__main__":
    scan_reg()

 

Output

Raspberry Pi Dht11 Interfacing With Raspberry Pi | Raspberry Pi

Video

Add a video of the output (know more)

 

 

 

Screenshot of Serial Terminal 

Add a Screenshot of the serial terminal showing the output.

 


 

Was this helpful?
Upvote
Downvote