I2C Teensy 4.1 using pins SDA1 and SCL1

Status
Not open for further replies.

Tinbum

Member
Hi,

I have a 20x4 LCD display using I2C that I have working fine using SCL0 and SDA0 (pins 19 and 18) but for my next application those pins are not easily accessible.

I therefor want to use pins 16 and 17 (SDA1 and SCL1)

I've tried;

Wire.setSCL(16);
Wire.setSDA(17);

but that doesn't work. Any ideas?

I'm using this library;

#include <LiquidCrystal_I2C.h>
and
#include <Wire.h>
 
Perhaps post your complete (not working) code for us to assist you in debugging? See the Forum Rule on top of this page.

Paul
 
I hadn't posted the code as it is very large and would just complicate matters.

Here is some code that doesn't work on SDA1 and SCL1. (If I connect using pins SDA0 and SCL0 it will still work on that).

Code:
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:  
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

void setup()

{
 Wire1.setSCL(16);
 Wire1.setSDA(17);
 Wire1.begin();

 lcd.begin(20, 4);

}

void loop()
{
  
  lcd.setCursor(0, 0);                                      //Start at character  on line 0
  lcd.print("TEST TEST TEST");
  delay (1000);
  lcd.setCursor(0, 1);
  lcd.print("TEST TEST TEST");
  delay (2000);
  lcd.clear();
  delay (2000);

}
 
You're not telling LiquidCrystal_I2C to use Wire1, so it's almost certainly using Wire. Using Wire1.begin() before you use that library doesn't have any effect on what the library actually does.

LiquidCrystal_I2C may not even have any way to tell it which I2C port to use. Generally only newer libraries provide that sort of configuration. If it does not have a way to specify which port, the only way to make it use Wire1 would be to edit its code and replace ALL "Wire" with "Wire1". We've seen this sort of problem many times where older libraries need to be edited and it's easy to miss some of the places where "Wire" is used. If you're facing this situation (I'm guessing LiquidCrystal_I2C is an older style lib with "Wire" hard-coded), know that leaving even 1 place within the library with "Wire" not changed to "Wire1" could cause it to not work.
 
LiquicCrystal_I2C is hard coded to use Wire. You will have to change LiquidCrystal_I2C to use Wire1. There is on entry to change in the .h and about 6 in the .cpp.
 
If you installed this library using Arduino's library manager, the files are probably located on your computer at {Documents}/Arduino/libraries/LiquidCrystal_I2C.

If you still can't find the location, click File > Preferences and turn on verbose output during compilation. Then click Verify. Arduino will print tons of info in its console panel. Drag the window divider to make the normally-too-small black console section larger. Near the end will be a list of all the libraries it used with the full pathname on your computer for each.

When you start editing the code, as a first quick check, just add any sort of syntax error and save. Then click Verify in Arduino. If Arduino complains about the error, then you know you're editing the correct file.

You can edit the .cpp and .h file with any text editor. Windows Notepad will do. Just make sure you use a text search to find every "Wire" within the file. If you miss changing even one Wire to Wire1, this won't work. They all have to be changed.
 
Thank you to both of you. I'm still struggling. I did a search on the computer for all .h and .cpp named files and removed all except the ones from the link above. I changed all wire to wire1 and it still wouldn't work.

I since noticed, by looking at the circuit diagram for the pcb the Teensy is mounted on, that there is in fact a jumper for SCL0 and SDA0 connections but for some unknown reason they don't populate it with the connector. I've now ordered some connectors and hopefully I can solder one on. I may have to get a very fine soldering iron tip and a magnifying glass.

Can bridge.jpg

Still it would be nice to get it working on SCL1 and SDA1.
 
It's not a place for a jumper but a location for an I2C QWIIC connector.
What I2C Address are you using?
Are you sure that it is the correct address?
You can use the code following to scan your system for I2C devices. It will report any I2C devices found with their I2C Address.
This code can also be found in C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3\examples\advanced_scanner
EDIT: Oops you said it worked fine on I2C0. It will still be useful to run the scanner, it will indicate if your wiring is correct.
Code:
// -------------------------------------------------------------------------------------------
// I2C Advanced Bus Scanner
// -------------------------------------------------------------------------------------------
//
// This creates an I2C master device which will scan the address space and report all
// devices which ACK.  It does not attempt to transfer data, it only reports which devices
// ACK their address.
//
// This version will sweep all existing I2C buses (eg. Wire, Wire1, Wire2, Wire3).
//
// Pull the control pin low to initiate the scan.  Result will output to Serial.
//
// This example code is in the public domain.
// -------------------------------------------------------------------------------------------

#include <i2c_t3.h>

// -------------------------------------------------------------------------------------------
// Defines - modify as needed for sweep range and bus pin config
//
#define TARGET_START 0x01
#define TARGET_END   0x7F

#define WIRE_PINS   I2C_PINS_18_19
#if defined(__MKL26Z64__)               // LC
#define WIRE1_PINS   I2C_PINS_22_23
#endif
#if defined(__MK20DX256__)              // 3.1-3.2
#define WIRE1_PINS   I2C_PINS_29_30
#endif
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)  // 3.5/3.6
#define WIRE1_PINS   I2C_PINS_37_38
#define WIRE2_PINS   I2C_PINS_3_4
#endif
#if defined(__MK66FX1M0__)              // 3.6
#define WIRE3_PINS   I2C_PINS_56_57
#endif

// -------------------------------------------------------------------------------------------
// Function prototypes
void scan_bus(i2c_t3& Wire, uint8_t all);
void print_bus_status(i2c_t3& Wire);
void print_scan_status(struct i2cStruct* i2c, uint8_t target, uint8_t& found, uint8_t all);

// -------------------------------------------------------------------------------------------
void setup()
{
    pinMode(LED_BUILTIN,OUTPUT);    // LED
    pinMode(12,INPUT_PULLUP);       // pull pin 12 low to show ACK only results
    pinMode(11,INPUT_PULLUP);       // pull pin 11 low for a more verbose result (shows both ACK and NACK)

    // Setup for Master mode, all buses, external pullups, 400kHz, 10ms default timeout
    //
    Wire.begin(I2C_MASTER, 0x00, WIRE_PINS, I2C_PULLUP_EXT, 400000);
    Wire.setDefaultTimeout(10000); // 10ms
    #if I2C_BUS_NUM >= 2
    Wire1.begin(I2C_MASTER, 0x00, WIRE1_PINS, I2C_PULLUP_EXT, 400000);
    Wire1.setDefaultTimeout(10000); // 10ms
    #endif
    #if I2C_BUS_NUM >= 3
    Wire2.begin(I2C_MASTER, 0x00, WIRE2_PINS, I2C_PULLUP_EXT, 400000);
    Wire2.setDefaultTimeout(10000); // 10ms
    #endif
    #if I2C_BUS_NUM >= 4
    Wire3.begin(I2C_MASTER, 0x00, WIRE3_PINS, I2C_PULLUP_EXT, 400000);
    Wire3.setDefaultTimeout(10000); // 10ms
    #endif

    Serial.begin(115200);
}

// -------------------------------------------------------------------------------------------
void loop()
{
    // Scan I2C addresses
    //
    if(digitalRead(12) == LOW || digitalRead(11) == LOW)
    {
        uint8_t all = (digitalRead(11) == LOW);

        Serial.print("---------------------------------------------------\n");
        Serial.print("Bus Status Summary\n");
        Serial.print("==================\n");
        Serial.print(" Bus    Mode   SCL  SDA   Pullup   Clock\n");
        print_bus_status(Wire);
        #if I2C_BUS_NUM >= 2
        print_bus_status(Wire1);
        #endif
        #if I2C_BUS_NUM >= 3
        print_bus_status(Wire2);
        #endif
        #if I2C_BUS_NUM >= 4
        print_bus_status(Wire3);
        #endif

        scan_bus(Wire, all);
        #if I2C_BUS_NUM >= 2
        scan_bus(Wire1, all);
        #endif
        #if I2C_BUS_NUM >= 3
        scan_bus(Wire2, all);
        #endif
        #if I2C_BUS_NUM >= 4
        scan_bus(Wire3, all);
        #endif

        Serial.print("---------------------------------------------------\n\n\n");

        delay(500); // delay to space out tests
    }
}

// -------------------------------------------------------------------------------------------
// scan bus
//
void scan_bus(i2c_t3& Wire, uint8_t all)
{
    uint8_t target, found = 0;
    
    Serial.print("---------------------------------------------------\n");
    if(Wire.bus == 0)
        Serial.print("Starting scan: Wire\n");
    else
        Serial.printf("Starting scan: Wire%d\n",Wire.bus);
    
    digitalWrite(LED_BUILTIN,HIGH); // LED on
    for(target = TARGET_START; target <= TARGET_END; target++) // sweep addr, skip general call
    {
        Wire.beginTransmission(target);       // slave addr
        Wire.endTransmission();               // no data, just addr
        print_scan_status(Wire.i2c, target, found, all);
    }    
    digitalWrite(LED_BUILTIN,LOW); // LED off
    
    if(!found) Serial.print("No devices found.\n");
}

// -------------------------------------------------------------------------------------------
// print bus status
//
void print_bus_status(i2c_t3& Wire)
{
    struct i2cStruct* i2c = Wire.i2c;
    if(Wire.bus == 0)
        Serial.print("Wire   ");
    else
        Serial.printf("Wire%d  ",Wire.bus);
    switch(i2c->currentMode)
    {
    case I2C_MASTER: Serial.print("MASTER  "); break;
    case I2C_SLAVE:  Serial.print(" SLAVE  "); break;
    }
    Serial.printf(" %2d   %2d  ", Wire.i2c->currentSCL, Wire.i2c->currentSDA);
    switch(i2c->currentPullup)
    {
    case I2C_PULLUP_EXT: Serial.print("External  "); break;
    case I2C_PULLUP_INT: Serial.print("Internal  "); break;
    }
    Serial.printf("%d Hz\n",i2c->currentRate);
}

// -------------------------------------------------------------------------------------------
// print scan status
//
void print_scan_status(struct i2cStruct* i2c, uint8_t target, uint8_t& found, uint8_t all)
{
    switch(i2c->currentStatus)
    {
    case I2C_WAITING:  Serial.printf("Addr: 0x%02X ACK\n",target); found=1; break;
    case I2C_ADDR_NAK: if(all) { Serial.printf("Addr: 0x%02X\n",target); } break;
    case I2C_TIMEOUT:  if(all) { Serial.printf("Addr: 0x%02X Timeout\n",target); } break;
    default: break;
    }
}
 
I'm sorry, I thought that you were asking for help in getting a 20x4 LCD display working on (SDA1 and SCL1)?
 
The display seen in the photo is one supplied with the board. He wanted to add another 20X4 I2C display, which is what he was having problems with.
At least that is how I see it.
Here is a link to the board schematic.
 
I'm sorry, I thought that you were asking for help in getting a 20x4 LCD display working on (SDA1 and SCL1)?

Yes I am. The display on the pcb, as supplied, isn't really ideal for a display when mounting it all in an enclosure, hence the need for another display to mount on the enclosure. To get the triple CAN and the Ethernet you had to buy a pcb with the display on which is double sided taped so won't come off without destroying it!!
 
I can't get the scanner to compile with the 4.1. i2c_t3.h isn't compatible with Teensy 4.0 or 4.1
Ok, try this one below, I just compiled it ok for a T4.1, so should be OK. It ought to be included with Teensyduino instead of the one that is there. @PaulStoffregen
Code:
// --------------------------------------
// i2c_scanner
// http://playground.arduino.cc/Main/I2cScanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

// BUGBUG::Should put this in WireIMXRT.h
#if defined(__IMXRT1062__)
#define WIRE_IMPLEMENT_WIRE
#define WIRE_IMPLEMENT_WIRE1
#define WIRE_IMPLEMENT_WIRE2
#endif
typedef struct {
  TwoWire *_wire;
  const char * wire_name;
  IMXRT_LPI2C_t * const port;
} wire_list_t;

wire_list_t wireList[] = {
  {&Wire, "Wire", &IMXRT_LPI2C1}
#if defined(WIRE_IMPLEMENT_WIRE1)
  , {&Wire1, "Wire1", &IMXRT_LPI2C3}
#endif  
#if defined(WIRE_IMPLEMENT_WIRE2)
  , {&Wire2, "Wire2", &IMXRT_LPI2C4}
#endif
#if defined(WIRE_IMPLEMENT_WIRE3)
  , {&Wire3, "Wire3"}
#endif
};
const uint8_t wirelist_count = sizeof(wireList) / sizeof(wireList[0]);


void setup() {
  // uncomment these to use alternate pins
  //Wire.setSCL(16);
  //Wire.setSDA(17);
  for (uint8_t wirelist_index = 0; wirelist_index < wirelist_count; wirelist_index++) {
    wireList[wirelist_index]._wire->begin();
  }
  Serial.begin(9600);
  while (!Serial);        // Leonardo: wait for serial monitor
  Serial.println(F("\nI2C Scanner"));
}


void loop() {
  byte error, address;
  int nDevices;

  for (uint8_t wirelist_index = 0; wirelist_index < wirelist_count; wirelist_index++) {
    IMXRT_LPI2C_t * const port = wireList[wirelist_index].port;
    Serial.print(F("Scanning("));
    Serial.print(wireList[wirelist_index].wire_name);
    Serial.println(F(")..."));
    nDevices = 0;
    for (address = 1; address < 127; address++) {
      // The i2c_scanner uses the return value of
      // the Write.endTransmisstion to see if
      // a device did acknowledge to the address.
      wireList[wirelist_index]._wire->beginTransmission(address);
      error = wireList[wirelist_index]._wire->endTransmission();

      if (error == 0) {
        Serial.print(F("Device found at address 0x"));
        if (address < 16) {
          Serial.print("0");
        }
        Serial.print(address, HEX);
        Serial.print("  (");
        printKnownChips(address);
        Serial.println(")");

        nDevices++;
      } else if (error == 4) {
        Serial.print(F("Unknown error at address 0x"));
        if (address < 16) {
          Serial.print("0");
        }
        Serial.print(address, HEX);
        Serial.printf("MCR:%x MSR:%x, MIER:%x MDER:%x MCFGR0:%x MDMR:%x MCCR0:%x\n",
          port->MCR, port->MSR, port->MIER, port->MDER, port->MCFGR0, port->MDMR, port->MCCR0);
      }
    }
    if (nDevices == 0) {
      Serial.println(F("No I2C devices found\n"));
    } else {
      Serial.println(F("done\n"));
    }
  }
  delay(5000);           // wait 5 seconds for next scan
}


void printKnownChips(byte address)
{
  // Is this list missing part numbers for chips you use?
  // Please suggest additions here:
  // https://github.com/PaulStoffregen/Wire/issues/new
  switch (address) {
    case 0x00: Serial.print(F("AS3935")); break;
    case 0x01: Serial.print(F("AS3935")); break;
    case 0x02: Serial.print(F("AS3935")); break;
    case 0x03: Serial.print(F("AS3935")); break;
    case 0x0A: Serial.print(F("SGTL5000")); break; // MCLK required
    case 0x0B: Serial.print(F("SMBusBattery?")); break;
    case 0x0C: Serial.print(F("AK8963")); break;
    case 0x10: Serial.print(F("CS4272")); break;
    case 0x11: Serial.print(F("Si4713")); break;
    case 0x13: Serial.print(F("VCNL4000,AK4558")); break;
    case 0x18: Serial.print(F("LIS331DLH")); break;
    case 0x19: Serial.print(F("LSM303,LIS331DLH")); break;
    case 0x1A: Serial.print(F("WM8731")); break;
    case 0x1C: Serial.print(F("LIS3MDL")); break;
    case 0x1D: Serial.print(F("LSM303D,LSM9DS0,ADXL345,MMA7455L,LSM9DS1,LIS3DSH")); break;
    case 0x1E: Serial.print(F("LSM303D,HMC5883L,FXOS8700,LIS3DSH")); break;
    case 0x20: Serial.print(F("MCP23017,MCP23008,PCF8574,FXAS21002,SoilMoisture")); break;
    case 0x21: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x22: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x23: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x24: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x25: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x26: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x27: Serial.print(F("MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay")); break;
    case 0x28: Serial.print(F("BNO055,EM7180,CAP1188")); break;
    case 0x29: Serial.print(F("TSL2561,VL6180,TSL2561,TSL2591,BNO055,CAP1188")); break;
    case 0x2A: Serial.print(F("SGTL5000,CAP1188")); break;
    case 0x2B: Serial.print(F("CAP1188")); break;
    case 0x2C: Serial.print(F("MCP44XX ePot")); break;
    case 0x2D: Serial.print(F("MCP44XX ePot")); break;
    case 0x2E: Serial.print(F("MCP44XX ePot")); break;
    case 0x2F: Serial.print(F("MCP44XX ePot")); break;
    case 0x33: Serial.print(F("MAX11614,MAX11615")); break;
    case 0x34: Serial.print(F("MAX11612,MAX11613")); break;
    case 0x35: Serial.print(F("MAX11616,MAX11617")); break;
    case 0x38: Serial.print(F("RA8875,FT6206,MAX98390")); break;
    case 0x39: Serial.print(F("TSL2561, APDS9960")); break;
    case 0x3C: Serial.print(F("SSD1306,DigisparkOLED")); break;
    case 0x3D: Serial.print(F("SSD1306")); break;
    case 0x40: Serial.print(F("PCA9685,Si7021")); break;
    case 0x41: Serial.print(F("STMPE610,PCA9685")); break;
    case 0x42: Serial.print(F("PCA9685")); break;
    case 0x43: Serial.print(F("PCA9685")); break;
    case 0x44: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x45: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x46: Serial.print(F("PCA9685")); break;
    case 0x47: Serial.print(F("PCA9685")); break;
    case 0x48: Serial.print(F("ADS1115,PN532,TMP102,LM75,PCF8591")); break;
    case 0x49: Serial.print(F("ADS1115,TSL2561,PCF8591")); break;
    case 0x4A: Serial.print(F("ADS1115")); break;
    case 0x4B: Serial.print(F("ADS1115,TMP102,BNO080")); break;
    case 0x50: Serial.print(F("EEPROM,FRAM")); break;
    case 0x51: Serial.print(F("EEPROM")); break;
    case 0x52: Serial.print(F("Nunchuk,EEPROM")); break;
    case 0x53: Serial.print(F("ADXL345,EEPROM")); break;
    case 0x54: Serial.print(F("EEPROM")); break;
    case 0x55: Serial.print(F("EEPROM")); break;
    case 0x56: Serial.print(F("EEPROM")); break;
    case 0x57: Serial.print(F("EEPROM")); break;
    case 0x58: Serial.print(F("TPA2016,MAX21100")); break;
    case 0x5A: Serial.print(F("MPR121")); break;
    case 0x60: Serial.print(F("MPL3115,MCP4725,MCP4728,TEA5767,Si5351")); break;
    case 0x61: Serial.print(F("MCP4725,AtlasEzoDO")); break;
    case 0x62: Serial.print(F("LidarLite,MCP4725,AtlasEzoORP")); break;
    case 0x63: Serial.print(F("MCP4725,AtlasEzoPH")); break;
    case 0x64: Serial.print(F("AtlasEzoEC")); break;
    case 0x66: Serial.print(F("AtlasEzoRTD")); break;
    case 0x68: Serial.print(F("DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D")); break;
    case 0x69: Serial.print(F("MPU6050,MPU9050,MPU9250,ITG3701,L3G4200D")); break;
    case 0x6A: Serial.print(F("LSM9DS1")); break;
    case 0x6B: Serial.print(F("LSM9DS0")); break;
    case 0x70: Serial.print(F("HT16K33")); break;
    case 0x71: Serial.print(F("SFE7SEG,HT16K33")); break;
    case 0x72: Serial.print(F("HT16K33")); break;
    case 0x73: Serial.print(F("HT16K33")); break;
    case 0x76: Serial.print(F("MS5607,MS5611,MS5637,BMP280")); break;
    case 0x77: Serial.print(F("BMP085,BMA180,BMP280,MS5611")); break;
    case 0x7C: Serial.print(F("FRAM_ID")); break;
    default: Serial.print(F("unknown chip"));
  }
}
 
You're using the wrong scanner. In Arduino, click File > Examples > Wire > Scanner.

Like other programs, to need to edit Wire to Wire1. Scanner.ino has 3 places you must edit. It will not work unless you edit all 3.

Do NOT uncomment the 2 lines to change the pin numbers. Those are for other Teensy models where Wire (not Wire1) can use alternate pins 16 & 17. On Teensy 4.0 & 4.1, those pins are only Wire1 (as the pinout card shows) and can't be used with normal Wire. Refer to the other Teensy model pinouts if you want to more fully understand the difference.
 
Ok, try this one below, I just compiled it ok for a T4.1, so should be OK. It ought to be included with Teensyduino instead of the one that is there. @PaulStoffregen
Code:
// --------------------------------------
// i2c_scanner
// http://playground.arduino.cc/Main/I2cScanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

// BUGBUG::Should put this in WireIMXRT.h
#if defined(__IMXRT1062__)
#define WIRE_IMPLEMENT_WIRE
#define WIRE_IMPLEMENT_WIRE1
#define WIRE_IMPLEMENT_WIRE2
#endif
typedef struct {
  TwoWire *_wire;
  const char * wire_name;
  IMXRT_LPI2C_t * const port;
} wire_list_t;

wire_list_t wireList[] = {
  {&Wire, "Wire", &IMXRT_LPI2C1}
#if defined(WIRE_IMPLEMENT_WIRE1)
  , {&Wire1, "Wire1", &IMXRT_LPI2C3}
#endif  
#if defined(WIRE_IMPLEMENT_WIRE2)
  , {&Wire2, "Wire2", &IMXRT_LPI2C4}
#endif
#if defined(WIRE_IMPLEMENT_WIRE3)
  , {&Wire3, "Wire3"}
#endif
};
const uint8_t wirelist_count = sizeof(wireList) / sizeof(wireList[0]);


void setup() {
  // uncomment these to use alternate pins
  //Wire.setSCL(16);
  //Wire.setSDA(17);
  for (uint8_t wirelist_index = 0; wirelist_index < wirelist_count; wirelist_index++) {
    wireList[wirelist_index]._wire->begin();
  }
  Serial.begin(9600);
  while (!Serial);        // Leonardo: wait for serial monitor
  Serial.println(F("\nI2C Scanner"));
}


void loop() {
  byte error, address;
  int nDevices;

  for (uint8_t wirelist_index = 0; wirelist_index < wirelist_count; wirelist_index++) {
    IMXRT_LPI2C_t * const port = wireList[wirelist_index].port;
    Serial.print(F("Scanning("));
    Serial.print(wireList[wirelist_index].wire_name);
    Serial.println(F(")..."));
    nDevices = 0;
    for (address = 1; address < 127; address++) {
      // The i2c_scanner uses the return value of
      // the Write.endTransmisstion to see if
      // a device did acknowledge to the address.
      wireList[wirelist_index]._wire->beginTransmission(address);
      error = wireList[wirelist_index]._wire->endTransmission();

      if (error == 0) {
        Serial.print(F("Device found at address 0x"));
        if (address < 16) {
          Serial.print("0");
        }
        Serial.print(address, HEX);
        Serial.print("  (");
        printKnownChips(address);
        Serial.println(")");

        nDevices++;
      } else if (error == 4) {
        Serial.print(F("Unknown error at address 0x"));
        if (address < 16) {
          Serial.print("0");
        }
        Serial.print(address, HEX);
        Serial.printf("MCR:%x MSR:%x, MIER:%x MDER:%x MCFGR0:%x MDMR:%x MCCR0:%x\n",
          port->MCR, port->MSR, port->MIER, port->MDER, port->MCFGR0, port->MDMR, port->MCCR0);
      }
    }
    if (nDevices == 0) {
      Serial.println(F("No I2C devices found\n"));
    } else {
      Serial.println(F("done\n"));
    }
  }
  delay(5000);           // wait 5 seconds for next scan
}


void printKnownChips(byte address)
{
  // Is this list missing part numbers for chips you use?
  // Please suggest additions here:
  // https://github.com/PaulStoffregen/Wire/issues/new
  switch (address) {
    case 0x00: Serial.print(F("AS3935")); break;
    case 0x01: Serial.print(F("AS3935")); break;
    case 0x02: Serial.print(F("AS3935")); break;
    case 0x03: Serial.print(F("AS3935")); break;
    case 0x0A: Serial.print(F("SGTL5000")); break; // MCLK required
    case 0x0B: Serial.print(F("SMBusBattery?")); break;
    case 0x0C: Serial.print(F("AK8963")); break;
    case 0x10: Serial.print(F("CS4272")); break;
    case 0x11: Serial.print(F("Si4713")); break;
    case 0x13: Serial.print(F("VCNL4000,AK4558")); break;
    case 0x18: Serial.print(F("LIS331DLH")); break;
    case 0x19: Serial.print(F("LSM303,LIS331DLH")); break;
    case 0x1A: Serial.print(F("WM8731")); break;
    case 0x1C: Serial.print(F("LIS3MDL")); break;
    case 0x1D: Serial.print(F("LSM303D,LSM9DS0,ADXL345,MMA7455L,LSM9DS1,LIS3DSH")); break;
    case 0x1E: Serial.print(F("LSM303D,HMC5883L,FXOS8700,LIS3DSH")); break;
    case 0x20: Serial.print(F("MCP23017,MCP23008,PCF8574,FXAS21002,SoilMoisture")); break;
    case 0x21: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x22: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x23: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x24: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x25: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x26: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x27: Serial.print(F("MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay")); break;
    case 0x28: Serial.print(F("BNO055,EM7180,CAP1188")); break;
    case 0x29: Serial.print(F("TSL2561,VL6180,TSL2561,TSL2591,BNO055,CAP1188")); break;
    case 0x2A: Serial.print(F("SGTL5000,CAP1188")); break;
    case 0x2B: Serial.print(F("CAP1188")); break;
    case 0x2C: Serial.print(F("MCP44XX ePot")); break;
    case 0x2D: Serial.print(F("MCP44XX ePot")); break;
    case 0x2E: Serial.print(F("MCP44XX ePot")); break;
    case 0x2F: Serial.print(F("MCP44XX ePot")); break;
    case 0x33: Serial.print(F("MAX11614,MAX11615")); break;
    case 0x34: Serial.print(F("MAX11612,MAX11613")); break;
    case 0x35: Serial.print(F("MAX11616,MAX11617")); break;
    case 0x38: Serial.print(F("RA8875,FT6206,MAX98390")); break;
    case 0x39: Serial.print(F("TSL2561, APDS9960")); break;
    case 0x3C: Serial.print(F("SSD1306,DigisparkOLED")); break;
    case 0x3D: Serial.print(F("SSD1306")); break;
    case 0x40: Serial.print(F("PCA9685,Si7021")); break;
    case 0x41: Serial.print(F("STMPE610,PCA9685")); break;
    case 0x42: Serial.print(F("PCA9685")); break;
    case 0x43: Serial.print(F("PCA9685")); break;
    case 0x44: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x45: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x46: Serial.print(F("PCA9685")); break;
    case 0x47: Serial.print(F("PCA9685")); break;
    case 0x48: Serial.print(F("ADS1115,PN532,TMP102,LM75,PCF8591")); break;
    case 0x49: Serial.print(F("ADS1115,TSL2561,PCF8591")); break;
    case 0x4A: Serial.print(F("ADS1115")); break;
    case 0x4B: Serial.print(F("ADS1115,TMP102,BNO080")); break;
    case 0x50: Serial.print(F("EEPROM,FRAM")); break;
    case 0x51: Serial.print(F("EEPROM")); break;
    case 0x52: Serial.print(F("Nunchuk,EEPROM")); break;
    case 0x53: Serial.print(F("ADXL345,EEPROM")); break;
    case 0x54: Serial.print(F("EEPROM")); break;
    case 0x55: Serial.print(F("EEPROM")); break;
    case 0x56: Serial.print(F("EEPROM")); break;
    case 0x57: Serial.print(F("EEPROM")); break;
    case 0x58: Serial.print(F("TPA2016,MAX21100")); break;
    case 0x5A: Serial.print(F("MPR121")); break;
    case 0x60: Serial.print(F("MPL3115,MCP4725,MCP4728,TEA5767,Si5351")); break;
    case 0x61: Serial.print(F("MCP4725,AtlasEzoDO")); break;
    case 0x62: Serial.print(F("LidarLite,MCP4725,AtlasEzoORP")); break;
    case 0x63: Serial.print(F("MCP4725,AtlasEzoPH")); break;
    case 0x64: Serial.print(F("AtlasEzoEC")); break;
    case 0x66: Serial.print(F("AtlasEzoRTD")); break;
    case 0x68: Serial.print(F("DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D")); break;
    case 0x69: Serial.print(F("MPU6050,MPU9050,MPU9250,ITG3701,L3G4200D")); break;
    case 0x6A: Serial.print(F("LSM9DS1")); break;
    case 0x6B: Serial.print(F("LSM9DS0")); break;
    case 0x70: Serial.print(F("HT16K33")); break;
    case 0x71: Serial.print(F("SFE7SEG,HT16K33")); break;
    case 0x72: Serial.print(F("HT16K33")); break;
    case 0x73: Serial.print(F("HT16K33")); break;
    case 0x76: Serial.print(F("MS5607,MS5611,MS5637,BMP280")); break;
    case 0x77: Serial.print(F("BMP085,BMA180,BMP280,MS5611")); break;
    case 0x7C: Serial.print(F("FRAM_ID")); break;
    default: Serial.print(F("unknown chip"));
  }
}

Thanks, output;

I2C Scanner
Scanning(Wire)...
No I2C devices found

Scanning(Wire1)...
Device found at address 0x27 (MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay)
done

Scanning(Wire2)...
No I2C devices found
 
OK, so wiring would appear correct. That's good.
I just looked at a LiquidCrystal_I2C example, I don't know if it is a solution, but they had the line
Code:
lcd.backlight();
after the lcd.init. It looks like the library defaults to Backlight off.
Might be worth a try.
 
If it were me, I would double check the wiring. And the code.

As I have posted in other threads, that @defragster and myself played with. In cases like this, one of the first things I do is to run simple program, that if I try connecting pin to gnd or 3.3v prints out on the Serial port what pin it is...


Code:
void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000 );
  Serial.println("Compile Time:: " __FILE__ " " __DATE__ " " __TIME__);
  Serial.printf("Num Digital Pins: %d\n", NUM_DIGITAL_PINS);

  testForShorts();
  
}

uint32_t cnt = 0;
void loop() {
  cnt++;
    allPinTest( cnt );
}

uint32_t pinLast[NUM_DIGITAL_PINS];
void allPinTest( uint32_t cnt ) {
  uint32_t ii, SET;
  Serial.print("PULLDOWN Start Vals:\n  ");
  SET = 0;
  Serial.print("PULLDOWN :: TEST to 3.3V\n  ");
  for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
    pinMode( ii, INPUT_PULLDOWN );
    delayMicroseconds( 5 );
    pinLast[ii] = digitalReadFast( ii );
    if (pinLast[ii]) {
      Serial.print("\nd#=");
      Serial.print( ii );
      Serial.print( " val=" );
    }
    Serial.print( pinLast[ii] );
    Serial.print(',');
  }
  Serial.println();
  Serial.println();
  while ( 1 ) {
    uint32_t jj, dd = 0, cc = 0, ee=4;
    cc = 0;
    for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
      jj = digitalReadFast( ii );
      if ( jj != pinLast[ii] ) {
        dd = 1;
        cc++;
        pinLast[ii] = jj;
        Serial.print("d#=");
        Serial.print( ii );
        if ( pinLast[ii] ) Serial.print( "\t" );
        Serial.print( " val=" );
        Serial.print( pinLast[ii] );
        Serial.print(',');
      }
      if ( cc > 1 && ee ) {
        Serial.println(">>> MULTI CHANGE !!");
        ee--;
      }
      if ( Serial.available() ) {
        while ( Serial.available() ) Serial.read();
        if ( 0 == SET ) {
          SET = 1;
          Serial.print("PULLUP :: TEST TO GND\n  ");
        }
        else {
          SET = 0;
          Serial.print("PULLDOWN :: TEST to 3.3V\n  ");
        }
        for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
          if ( 0 == SET )
            pinMode( ii, INPUT_PULLDOWN );
          else
            pinMode( ii, INPUT_PULLUP );
          delayMicroseconds( 20 );
          pinLast[ii] = digitalReadFast( ii );
          if (SET != pinLast[ii]) {
            Serial.print("d#=");
            Serial.print( ii );
            Serial.print( " val=" );
            Serial.println( pinLast[ii] );
          }
        }
      }
    }
    if ( dd ) {
      dd = 0;
      Serial.println();
      delay( 50 );
    }
  }
}

void testForShorts() {
  uint32_t ii;
  Serial.print("Quick Test for Shorts to adjacent pin");
  Serial.println("First pull pins down and see if the next one follows");
  for ( ii = 0; ii < NUM_DIGITAL_PINS-1; ii++) {
    pinMode( ii+1, INPUT_PULLDOWN );
    pinMode( ii, OUTPUT);
    digitalWrite(ii, HIGH);
    delayMicroseconds( 5 );
    if (digitalRead(ii+1)) {
      Serial.printf("%d:%d ", ii, ii+1);
    }
  }
  Serial.println("\n Now try Pull up and see if setting low follow");
  for ( ii = 0; ii < NUM_DIGITAL_PINS-1; ii++) {
    pinMode( ii+1, INPUT_PULLUP );
    pinMode( ii, OUTPUT);
    digitalWrite(ii, LOW);
    delayMicroseconds( 5 );
    if (!digitalRead(ii+1)) {
      Serial.printf("%d:%d ", ii, ii+1);
    }
  }
  Serial.println();  
}

Then for example double check that what you think is pin 16, actually rings out as pin 16, dito for 17.

Also I would double check that those pins are not used for something else on that board. Are there things like PU resistors on the Wire object pins, but not these? Does your display have it's own...

Might also double check things like, make sure if you edited the library, that it is actually using your version when it builds.

Good luck
 
Status
Not open for further replies.
Back
Top