SoftwareWire I2C library not recognizing the SN3218 chip

Hi,

I would like to address several SN3218 chips at the same time, and their I2C address is hardwired as 0x54, so I would like to use the SoftwareWire library.

I am using the Pimoroni SN3218 breakout board for initial testing, and a cheap Arduino Nano clone.

When I run the sketch, trying to detect just one chip, it doesn't find any devices. The 2 pins in the sketch are connected to the SCL and SDA pins on the breakout board, there are no other connections (besides GND and VCC of course).

However when I connect the chip to A4 and A5 (hardwire I2C pins on the nano) and run the same sketch using the Wire library, the chip address is detected correctly.

Really grateful for any help,
E.

#include <SoftwareWire.h>


// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
// Modified by Egor Kraev in Nov 2015 to use the SoftwareWire library

//#include <Wire.h>
const int sdaPin = 2;
const int sclPin = 3;
SoftwareWire i2c = SoftwareWire( sclPin, sdaPin);

void setup() {
  Serial.begin (9600);

  // Leonardo: wait for serial port to connect
  // while (!Serial) 
  //  {
  //  }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  i2c.begin();
  for (byte i = 1; i < 120; i++)
  {
    i2c.beginTransmission (i);
    if (i2c.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

for testing you can leave the pin connected to A4/A5 and use the SoftwareWire on this pin also.
So without change pin connection you can test Wire and SoftwareWire only changing the Library define.
In this way you are sure that there is no hardware problem

Whitch Arduino IDE version do you use ?
Are you tried to download the library directly from the integrated Arduino Library Manager ?

You do : SoftwareWire i2c = SoftwareWire ( sclPin , sdaPin ) ;
But it should be : SoftwareWire i2c = SoftwareWire ( sdaPin , sclPin ) ;
It is SDA first.

The SoftwareWire has not proven itself yet. You might bump into a few imperfections.

The fastest way to make your project work is using a I2C multiplexer : TCA9548A I2C Multiplexer : ID 2717 : $6.95 : Adafruit Industries, Unique & fun DIY electronics and kits

Koepel,

thanks! Changing sda and scl around in the constructor fixed it - it's the silly stuff that trips one up, especially in the evening:)

I'm trying to minimize the cost of the overall setup, so will try to do it in software first (same reason I'm not using something like tlc5947, which is designed to be daisy-chained, but is several times more expensive than the sn3218).

With the quality and speed of help I'm getting here, I'm happy to take my chances on the fresh library :wink:

Below is the modified scanner sketch which lets one choose the library via macro, just in case someone finds it useful.

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
// Modified by Egor Kraev in Nov 2015 to choose the wire library via macro

#define _SOFT // comment this line out to use the Wire library, leave it in to use SoftwareWire
#ifdef _SOFT
#define WIRE i2c
#else
#define WIRE Wire
#endif

#include <Wire.h> // Arduino Nano I2C pins are A4 (SDA) and A5 (SCL).
#include <SoftwareWire.h>
const int sdaPin = 2;
const int sclPin = 3;
SoftwareWire i2c = SoftwareWire( sdaPin, sclPin);

void setup() {
  Serial.begin (9600);

  // Leonardo: wait for serial port to connect
  // while (!Serial) 
  //  {
  //  }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  WIRE.begin();
  for (byte i = 1; i < 120; i++)
  {
    WIRE.beginTransmission (i);
    if (WIRE.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

OK, was able to address 2 SN3218 chips via SoftwareWire simultaneously, no problem.

Attached is the wrapper class and sketch for doing that - modified the Pimoroni-supplied code to add the option of using SoftwareWire with user-supplied pins.

Thanks a lot for the help!
E.

arduino_sn3218-soft.zip (3.59 KB)

Thanks for testing the SoftwareWire library.