⚲
Projet
Général
Profil
Connexion
Accueil
Projets
Aide
Recherche
:
Accueil
Tous les projets
Accueil
Aperçu
Activité
Annonces
Documents
Wiki
Fichiers
Télécharger (1,52 ko)
Izabela Grubicka
» uid_nfc_test.ino
Izabela Grubicka
, 17/07/2026 15:46
//https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/
//https://forum.arduino.cc/t/changing-i2c-address-of-sensors/910535
#include
<Wire.h>
void
setup
()
{
Wire
.
begin
();
Serial
.
begin
(
115200
);
Serial
.
println
(
"
\n
I2C Scanner"
);
}
void
loop
()
{
byte
error
,
address
;
int
nDevices
;
Serial
.
println
(
"Scanning..."
);
nDevices
=
0
;
for
(
address
=
1
;
address
<
127
;
address
++
)
{
Wire
.
beginTransmission
(
address
);
error
=
Wire
.
endTransmission
();
if
(
error
==
0
)
{
Serial
.
print
(
"I2C device found at address 0x"
);
if
(
address
<
16
)
{
Serial
.
print
(
"0"
);
}
Serial
.
println
(
address
,
HEX
);
nDevices
++
;
}
else
if
(
error
==
4
)
{
Serial
.
print
(
"Unknow error at address 0x"
);
if
(
address
<
16
)
{
Serial
.
print
(
"0"
);
}
Serial
.
println
(
address
,
HEX
);
}
}
if
(
nDevices
==
0
)
{
Serial
.
println
(
"No I2C devices found
\n
"
);
}
else
{
Serial
.
println
(
"done
\n
"
);
}
delay
(
3000
);
int
error2
=
Wire
.
endTransmission
();
if
(
error2
!=
0
)
{
Serial
.
println
(
"The sensor is not at 0x24"
);
}
else
{
Serial
.
println
(
"The sensor is found, changing I2C address"
);
Wire
.
beginTransmission
(
0x24
);
Wire
.
write
(
0x53
);
// password register
Wire
.
write
(
0xAA
);
// password
Wire
.
endTransmission
();
delay
(
10
);
// not described somewhere, just for safety
Wire
.
beginTransmission
(
0x24
);
Wire
.
write
(
0x00
);
// I2C address register
Wire
.
write
(
0x50
<<
1
);
// new I2C address
Wire
.
endTransmission
();
}
}
« Précédent
1
…
34
35
36
37
38
…
44
Suivant »
(36-36/44)
Chargement...