Upload files to "src/i2c/esp32c3_master_i2c"
This commit is contained in:
parent
9a7677a857
commit
36185974eb
51
src/i2c/esp32c3_master_i2c/functions.ino
Normal file
51
src/i2c/esp32c3_master_i2c/functions.ino
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// Question
|
||||||
|
String Question(String Message) {
|
||||||
|
|
||||||
|
Serial.print(Message + " : ");
|
||||||
|
while(!Serial.available());
|
||||||
|
|
||||||
|
Message = Serial.readStringUntil('\n');
|
||||||
|
while(Serial.available()) Serial.read();
|
||||||
|
Message.trim();
|
||||||
|
Serial.println(Message);
|
||||||
|
return Message;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLED Display
|
||||||
|
void oled_write(String message) {
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println(message);
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
// I2C Scanner
|
||||||
|
void scanI2C() {
|
||||||
|
|
||||||
|
byte error, address;
|
||||||
|
int 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("Unknown error at address 0x");
|
||||||
|
if (address<16) Serial.print("0");
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nDevices == 0)
|
||||||
|
Serial.println("No I2C devices found");
|
||||||
|
else
|
||||||
|
Serial.println("Scan complete");
|
||||||
|
|
||||||
|
}
|
22
src/i2c/esp32c3_master_i2c/i2c_functions.ino
Normal file
22
src/i2c/esp32c3_master_i2c/i2c_functions.ino
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
// This Function If Called Sends A Text Message Via I2C
|
||||||
|
void i2c_send_string(uint8_t Slave, String message) {
|
||||||
|
|
||||||
|
// Sending Data
|
||||||
|
Wire.beginTransmission(Slave);
|
||||||
|
|
||||||
|
// First Data Byte Is Length
|
||||||
|
Wire.write(message.length());
|
||||||
|
|
||||||
|
// Second Send Data One Byte At A Time
|
||||||
|
for(int i=0; i<message.length(); i++) {
|
||||||
|
|
||||||
|
// Send String Bits
|
||||||
|
Wire.write(message[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally Closing Transmission
|
||||||
|
Wire.endTransmission();
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user