I am trying to run I2C devices off of two separate circuits (** See below if you care why, as I realize this is atypical)
I'm using an EnviroDIY Mayfly datalogger's I2C connector, and this one is working with no problem.
I've also added pull up resistors (2K) to D4 and D5 on the Mayfly so these can work as I2C connections.
I'm using the SoftWire library which uses bit-banging to mimic I2C on other ports.
I've got a temperature/humidity sensor (SHT31) (s1 in my code) connected to the bitbanged connection D4/D5. And I'm trying to use the Adafruit SHT31 library to read from the sensor (works fine when I connect to regular I2C, but haven't yet gotten it to work for the bit-bang I2C).
On the regular I2C circuit, I've connected an I2C Soil Moisture sensor (s2 in my code) which appears to be working fine. It's using the I2CSoilMoistureSensor. No problems with this one.
The problem I'm having is that the SHT31 library commands don't really seem to work when I'm using the bit-bang I2C. Any suggestions on how to modify the code below to get this s2 sensor to read correctly? The code here is an I2C scanner that picks up both the normal and the bit-banged sensors--Just not getting readings from the 0x44 address.
#include <SoftWire.h>
#include <AsyncDelay.h>
#include <Wire.h>
#include <Adafruit_SHT31.h> // connected to bitbanng I2C port
#include <I2CSoilMoistureSensor.h> // connected to regular I2C port
#define SDA_PIN 5
#define SCL_PIN 4
SoftWire sw(SDA_PIN, SCL_PIN);
Adafruit_SHT31 s1 = Adafruit_SHT31();
I2CSoilMoistureSensor s2 = I2CSoilMoistureSensor();
void setup(void)
{
Wire.begin();
Serial.begin(9600);
sw.begin();
delay(1000);
s1.begin(0x44);
s2.begin(0x20);
// Set how long we are willing to wait for a device to respond
sw.setTimeout_ms(40);
const uint8_t firstAddr = 1;
const uint8_t lastAddr = 0x7F;
Serial.println();
Serial.print("Interrogating all addresses in range 0x");
Serial.print(firstAddr, HEX);
Serial.print(" - 0x");
Serial.print(lastAddr, HEX);
Serial.println(" (inclusive) ...");
for (uint8_t addr = firstAddr; addr <= lastAddr; addr++) {
uint8_t startResult = sw.llStart((addr << 1) + 1); // Signal a read
sw.stop();
if (startResult == 0) {
Serial.print("\nBITBANG Device found at 0x");
Serial.println(addr, HEX);
Serial.flush();
}
Wire.beginTransmission(addr);
byte error = Wire.endTransmission();
if (error == 0)
{
Serial.print("REAL I2C device found at address 0x");
if (addr < 16)
Serial.print("0");
Serial.print(addr, HEX);
Serial.println(" !");
}
}
Serial.println("Finished Scanning");
//Read humidty from sensor s1
float a = s1.readHumidity();
//Read temperature from sensor s2
float b = s2.getTemperature() / (float)10;
// Print readings to serial
Serial.print("Humidty = ");
Serial.println(a);
Serial.print("Soil Temp = ");
Serial.println(b);
}
void loop(void)
{
;
}
** The reason I'm using 2 separate I2C cirucits is because the mayfly has convenient 4-pin plugs. For quick deployment of my sensors, I'd like to simply be able to plug in my different sensors, and change/replace as necessary. I realize I2C is really designed to run multiple, but it makes since to have two of them in my situation--at least it seems to make sense to me.