// STM32 Nucleo-C031C6 I2C Example
// Simulation: https://wokwi.com/projects/365421666018061313
#include <Wire.h>
#include "LiquidCrystal_I2C.h"
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
//#define I2C1_SDA D14
//#define I2C1_SCL D15
//I2C1 my_i2c(I2C1_SDA, I2C1_SCL);
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.print("Scanning");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
// La valeur de retour de Wire.endTransmission()
// est false (0) si le peripherique existe a cette adresse
Serial.print(".");
if (error == 0)
{
Serial.println(""); // retour à la ligne
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
break; // commenter cette ligne si vous recherchez plusieurs péripheriques I2C
// sur le bus, sinon le test s'arrête dès le premier trouvé
}
else if (error==4)
{
Serial.println("");
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
delay(50);
}
if (nDevices == 0)
{
Serial.println("");
Serial.println("No I2C devices found\n");
}
else
Serial.println("done\n");
delay(3000); // on attend 3 secondes et on recommence
}
/*
void setup() {
Serial.begin(115200);
Serial.println("Hello, STM32!");
lcd.init();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("Hello, STM32");
lcd.setCursor(5, 2);
lcd.print("Welcome to");
lcd.setCursor(7, 3);
lcd.print("Wokwi!");
}
void loop() {
}
*/