Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Scan I2C: Locates I2C addresses of connected devices (Oshonsoft).

DogFlu66

Member
Library: I2C_Scan.bas – I2C Device Scanner for PIC18 (Oshonsoft)

This library scans the I2C bus for connected devices using a PIC18 microcontroller and the Oshonsoft Basic compiler. It requires the I2CLib.bas library (which provides START_I2C, STOP_I2C, WRITE_I2C) and a properly initialized serial output (UART by default) to display results.

How it works:
  • The I2C_Ping function sends a write request to a given 7-bit I2C address. If the device responds with ACK, it's considered present.
  • The I2C_Scan function loops through valid I2C addresses (0x03 to 0x77), calls I2C_Ping for each, and prints the detected addresses via UART1. It also returns the total number of detected devices.
Useful for debugging I2C setups or identifying connected sensors and EEPROMs automatically.

I2C_Scan.jpg
 

Attachments

Latest threads

New Articles From Microcontroller Tips

Back
Top