
How to use I2C Scanner with Digispark to find I2C address | Robojax
This tutorial demonstrates how to use an I2C scanner with a Digispark development board to identify the I2C addresses of connected devices. Knowing the I2C address is crucial for communicating with various sensors and modules using the I2C protocol. This skill is essential for a wide range of projects. For example, you can use this technique to:
- Integrate multiple I2C sensors into a single project, such as an environmental monitoring station.
- Troubleshoot I2C communication problems by verifying the address of a malfunctioning device.
- Quickly identify the I2C address of newly acquired sensors or modules.
This method is particularly useful for devices that don't have their I2C address clearly labeled.
Hardware/Components
To follow this tutorial, you will need the following components:
- Digispark development board (either USB or Micro USB version)
- I2C devices (sensors, modules, etc.) whose addresses you want to identify
- Connecting wires
Wiring Guide
The wiring process involves connecting the SDA and SCL lines from your Digispark to the corresponding pins on your I2C devices (in video at 00:53). The Digispark's SDA pin is typically digital pin 0, and the SCL pin is digital pin 1 (in video at 01:05). Ensure that the VCC and GND pins of your I2C devices are correctly connected to the 5V and GND pins of the Digispark respectively (in video at 01:34). The wiring is similar for various Digispark models (in video at 01:44).
%%WIRING%%
Code Explanation
The provided Arduino code uses the Wire library to scan for I2C devices. The core logic is within the loop()
function (in video at 02:38). The code iterates through possible I2C addresses (1 to 127) and attempts communication with each address using Wire.beginTransmission(address)
and Wire.endTransmission()
. If communication is successful (error == 0), the code prints the address to the serial monitor. The configurable part is mainly the serial baud rate, which is set to 9600 in the Serial.begin(9600)
line. You can change this value if needed, but ensure it matches the baud rate of your serial monitor.
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600); // This line sets the serial baud rate.
while (!Serial);
Serial.println("\nI2C Scanner");
}
void loop() {
// ... (rest of the code) ...
}
Live Project/Demonstration
The video demonstrates the process of identifying I2C addresses for several devices (in video at 03:46, 04:14, 05:17). The tutorial shows how to upload the code to the Digispark, connect the I2C devices, and observe the addresses printed on the serial monitor (in video at 03:11). The video highlights that the serial output will appear in any active window, such as Notepad or Microsoft Word (in video at 04:47). It emphasizes the importance of connecting the device after the upload process begins, within a 60-second window (in video at 03:27, 04:22, 05:34).
Chapters
- [00:00] Introduction and Project Overview
- [00:24] I2C Address Explanation
- [00:53] Wiring Instructions
- [01:48] Software Setup and Installation
- [02:35] Code Upload Process
- [03:11] First Device Address Discovery
- [04:06] Second Device Address Discovery
- [05:15] Third Device Address Discovery
- [05:58] Conclusion
Comments will be displayed here.