Usage fault with i2c bus wire and wire1 endTransmission

I am having problems using a humidity sensor SHT31-D with wire and wire1. I stripped out code from the Adafruit_SHT31 library and to find the issue and it works great with arduino. Whenever endTransmission is called, it puts the Electron into a usage fault (5 flashes). Problem on both wire and wire1 pins.

I want to use wire1 (pins C4 & c5) so I set SLC pin to INPUT as discussed.

I checked for DIV/0 by printing all the wite() commands.

I have the pull-up resistors as discussed.

Code -

void writeCommand(uint16_t cmd) {
  Serial.println("writeCommand input cmd = ");
  Serial.println("writeCommand cmd >> 8");
  Serial.println(cmd >> 8);
  Wire1.write(cmd >> 8);
  Serial.println("writeCommand cmd & 0xFF");
  Serial.println(cmd & 0xFF);
  Wire1.write(cmd & 0xFF);
  Serial.println("writeCommand end Transmission");
  Serial.println("writeCommand Done");
void setup(){
  Serial.begin(9600); // connect serial
  pinMode(C5, INPUT); 
  delay(10000); //so I have time to start serial monitor
  writeCommand(0x30A2); ///SHT31_SOFTRESET);

bool CheckHumidity(float &hum){
  Serial.println("Here 1");
  writeCommand(0x2400); ///SHT31_MEAS_HIGHREP
  uint8_t readbuffer[6];
  Serial.println("Here 2");
  Wire1.requestFrom(0x44, (uint8_t)6); //(_i2caddr, 
  if (Wire1.available() != 6) 
    return false;
  for (uint8_t i=0; i<6; i++) {
    readbuffer[i] =;
  uint16_t SRH;
  SRH = readbuffer[3];
  SRH <<= 8;
  SRH |= readbuffer[4];
  Serial.println("Here 3");
  uint8_t *data = readbuffer+3;
  int len = 2;
  const uint8_t POLYNOMIAL(0x31);
  uint8_t crc(0xFF);  
  for ( int j = len; j; --j ) {
      crc ^= *data++;

  for ( int i = 8; i; --i ) {
    crc = ( crc & 0x80 )
      ? (crc << 1) ^ POLYNOMIAL
      : (crc << 1);
  Serial.println("Here 4");

  if (readbuffer[5] != crc) return false; 
  double shum = SRH;
  shum *= 100;
  shum /= 0xFFFF;
  hum = shum;
  Serial.print("humidity = ");
  return true;

void loop(){  
  float curHum = 0.0;
  Serial.print("humidity = ");

I might be blind, but where are your Wire.begin() or `Wire1.begin() calls?

Also what system version are you targeting?

Here is a working library for the SHT31D sensor.

1 Like

Why are you putting these huge delays between the .write()'s? .write() just caches bytes until the endTransmission() call, which is what sends the message.

Thanks, that was it I was missing the lost the Wire.begin when I stripped the code. I was missing the pinMode(C5, INPUT); before I stripped it all.

1 Like

The delays are because on one of them aruino or particle, I have had the last serial.print not show up if it something goes wrong really fast after it.