-
Notifications
You must be signed in to change notification settings - Fork 4
/
I2CScanInternalGrooveHat.ino
51 lines (44 loc) · 1.28 KB
/
I2CScanInternalGrooveHat.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2024 by GWENDESIGN. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <Arduino.h>
#include <Wire.h>
typedef struct {
TwoWire *wire;
int sda;
int scl;
} i2cBus_t;
i2cBus_t i2cBus_Internal = {&Wire, GPIO_NUM_21, GPIO_NUM_22};
i2cBus_t i2cBus_Groove_Port = {&Wire, GPIO_NUM_32, GPIO_NUM_33};
i2cBus_t i2cBus_Hat_Port = {&Wire, GPIO_NUM_0, GPIO_NUM_26};
void setup()
{
Serial.begin(115200);
delay(3000);
Serial.println("Start I2C scan");
}
void scanI2C(TwoWire *wire, int sda, int scl)
{
int address;
int error;
wire->begin(sda, scl);
for(address = 1; address < 127; address++)
{
wire->beginTransmission(address);
error = wire->endTransmission();
if(error == 0) Serial.printf("0x%02x ", address);
else Serial.print(".");
delay(10);
}
Serial.println();
wire->end();
}
void loop()
{
Serial.println("I2C Scan - internal");
scanI2C(i2cBus_Internal.wire, i2cBus_Internal.sda, i2cBus_Internal.scl);
Serial.println("I2C Scan - Groove Port");
scanI2C(i2cBus_Groove_Port.wire, i2cBus_Groove_Port.sda, i2cBus_Groove_Port.scl);
Serial.println("I2C Scan - Hat Port");
scanI2C(i2cBus_Hat_Port.wire, i2cBus_Hat_Port.sda, i2cBus_Hat_Port.scl);
delay(2000);
}