LilyGo-T-Relay change I2C pins
-
Good morning everyone,
I need help with the LilyGo-T-Relay board, I need to use I2C to communicate with the INA219, but I can't define the I2C pins. Can anyone help me? -
@rogeriocpe As you probably know there does not seem to be a dedicated I2C port. Looking at the chip pinout here:
https://www.espressif.com/sites/default/files/documentation/esp32-wrover-b_datasheet_en.pdf
page 9, I would guess that GPIO 26 and 14 would work for I2C.
Maybe define them with wire.begin(26, 14);
I do not have a T-Relay to try this on!
Cheers, Terry -
@teastain Thanks, but I still can't get it to work. I'll put the code here to see if I have something wrong.
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_INA219.h>Adafruit_INA219 ina219;
//#define I2C_SDA 26
//#define I2C_SCL 14void setup(void)
{
Serial.begin(115200);
while (!Serial) {
// will pause Zero, Leonardo, etc until serial console opens
delay(1);
}Serial.println("Hello!");
Wire.begin(26, 14);
if(! ina219.begin()){
Serial.println("Failed to find INA219 chip");
while (1) { delay(10); }
}Serial.println("Measuring voltage and current with INA219 ...");
}void loop(void)
{
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V");
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
Serial.print("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V");
Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA");
Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW");
Serial.println("");delay(2000);
} -
@rogeriocpe said in LilyGo-T-Relay change I2C pins:
INA219
oof, OK. Can you draw out the circuit and post it, or email it to me at:
teastain@me.com -
@teastain @rogeriocpe any progress?
I'm using T-relay 8X and would like to use INA219 too,
somewhere I've found I could use pins 32 and 33 but they are used by relays, so what?I also tried to scan with common I2C scanner code, after connecting to pin 14 and 25, without success, no device found.
-
@supermarioprof
So, you want to add a current sensor to your LilyGO T-Relay (8)?
https://www.lilygo.cc/products/t-relay-5v-8-channel-relay
Yes pins 32 and 33 are used by relays
You should be able to choose any two GPIO pins on that header!https://github.com/Xinyuan-LilyGO/LilyGo-T-Relay/blob/main/Schematic/T_Relay8_ESP32.pdf
I would then try GPIO 14 and 15.
Wire.begin(26, 14); (SDA,SCL)Cheers, Terry
-
@teastain2 Bingo! that worked, changing
Wire.begin();
to
Wire.begin(26, 14);so pinout for I2C on T-relay 8X is
SDA: pin 26
SCL: pin 14thank you!