sending data out to two I2C ports

philip.porhammer

Well-known member
I want to do a test program to change ports. how do I change ports?

#include <Wire.h>
#include <SparkFun_Alphanumeric_Display.h> //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
HT16K33 display;


void setup()
{
Serial.begin(9600);
Wire.begin(); //Join I2C bus
Wire1.begin(); //Join I2C bus
display.begin(0x70, 0x71);}


void loop()
{


// Set port 0
display.print("port 0 ");
//set port 1
display.print("port 1 ");

delay(500);
}
 
Just checking: so you have 2 displays on 2 different I2C busses?
Why don't you connect both displays to the default I2C bus and connect them like Sparkfun's multidisplay example states?

Paul
 
I want to use 12 displays with 4 on each I2C port. first i need to make a test program as google was not helpful.
i would upload a pic of the project but its not working
 
#include <Wire.h>
#include <SparkFun_Alphanumeric_Display.h> //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
HT16K33 display;

int Ai=5;//parsed Int
int Bi=6;
int Ci=7;
int Di=7;
String Ss; //sign flag
String As; // set as char
String Bs;
String Cs;
String Ds;

String Ac;
String AP;

int val=300;
int valA;
int v[8] ; // this is the result. The least significant digit goes in position 0
int i=0 ; // index
int y ;
int ledBit=13;
boolean ledfliper=0;

void setup()
{
Serial.begin(9600);
Wire.begin(); //Join I2C bus
Wire1.begin(); //Join I2C bus
display.begin(0x70, 0x71);

pinMode(ledBit, OUTPUT);digitalWrite(ledBit, LOW);
display.decimalOn();
}

void loop()
{
val=val+1;// this is the temperature
if(val>200){val=-200;}
sendCanTemp ();

delay (150);
digitalWrite(ledBit, ledfliper);if(ledfliper==0){ledfliper=1;}else{ledfliper=0;}
}


void sendCanTemp ()
{

valA=abs(val);

i=0 ;
v[0]=0; v[1]=0;v[2]=0; v[3]=0;
while ( valA > 0 )
{y=valA/10 ; v = valA-(10*y) ; valA=y ; i++ ;}

As=String(v[2]);
Bs=String(v[1]);
Cs=String(v[0]);

valA=abs(val);
Ss='+';if(val<0){Ss='-';}

if (valA<10&&valA>=0) {AP= ' '+Ss+'0'+Cs;}
if (valA<100&&valA>=10) {AP= ' '+Ss+Bs+Cs;}
if (valA<1000&&valA>=100){AP= Ss+As+Bs+Cs;}
AP=AP+AP;
AP='PORT 1 ';
display.print(AP);//display.decimalOn();
AP='PRT2 ';
display.print(AP);//display.decimalOn();

Serial.print(Ss);
if(valA>99){Serial.print(v[2]);}
if(valA>9){Serial.print(v[1]);}else{Serial.print("0");}






}
 
maybe I should have stated first that i am using a Teency 4.0 with 3 I2C ports
defalt on the 4.0 is port 0:
Wire.begin(); //Join I2C bus
then we have
Wire1.begin(); //Join I2C bus
and
Wire.begin2(); //Join I2C bus

how do I change the i2c transitions from port 0 then 1 then 2


#include <Wire.h>
#include <SparkFun_Alphanumeric_Display.h> //Click here to get the library: http://librarymanager/All#SparkFun_Q...umeric_Display by SparkFun
HT16K33 display;


void setup()
{
Serial.begin(9600);
Wire.begin(); //Join I2C bus
Wire1.begin(); //Join I2C bus
display.begin(0x70, 0x71);}


void loop()
{


// Set port 0
display.print("port 0 ");
//set port 1
display.print("port 1 ");

delay(500);
}
 
I understand what you want to accomplish.
Thing is you need to tell the library which I2C port it needs to use: Wire, Wire1 or Wire2. Again, I don't think the library is written such that it supports setting the wanted I2C port (but I hope to be proven wrong).

Paul
 
ok so its time to experiment. I saw some comment somewhere about setting the pin numbers. would know what that may be, and how do I get a list of all the commands for the "Wire.begin()"? programming is not my day job. Thanks
 
Code:
//
//    FILE: demo_dual1.ino
//  AUTHOR: Rob Tillaart
// PURPOSE: demo 2 I2C 4x7segment displays one uint32_t unsigned long
//     URL: http://www.adafruit.com/products/1002
//     URL: https://github.com/RobTillaart/HT16K33


#include "HT16K33.h"

HT16K33 left(0x71);
HT16K33 right(0x70);

uint32_t counter = 0;


void setup()
{
  Serial.begin(115200);
  Serial.println(__FILE__);

  left.begin();
  right.begin();

  Wire.setClock(100000);

  left.displayOn();
  right.displayOn();

  Serial.println("dual displayTest");
}


void loop()
{
  display_ulong(counter);

  delay(1);
  counter++;
}


void display_ulong(uint32_t value)
{
  uint16_t lval = value / 10000;
  uint16_t rval = value % 10000;

  // left show no digit if not needed
  left.setDigits(0);
  // right show at least 1 digit if value < 10000, otherwise leading zero's needed
  right.setDigits(lval > 0 ? 4 : 0);

  left.displayInt(lval);
  right.displayInt(rval);
}


// -- END OF FILE --
The code above shows how to handle TWO displays. You should be able to see how to manage three.
The code above was obtained from the this library for the HT16K33 display.

There is NO NEED to change ports, pins etc. All the HT16K33s are wired to ONE I2C port.
You will NEED to change the address used by the HT16K33 on two of them. (Leave ONE as default, set the second to another address and the third to a third one.)

The Addresses are changed by using the jumpers on A0..A2. You can have up to 8 of these devices on one I2C port.
 
@philip.porhammer stated above "I want to use 12 displays with 4 on each I2C port".
The displays he's using (I assume) have only 2 address jumpers hence only 4 addressable displays on each I2C port.
So we are looking for a display library that supports selectable I2C ports [Wire, Wire1 or Wire2]. I believe RobTillaard's library also does not support that.

Paul
 
I believe RobTillaard's library also does not support that.
I think it does actually. Below is a snippet from his HT16K33.h file.
Code:
public:
  HT16K33(const uint8_t address, TwoWire *wire = &Wire);   //  0x70 .. 0x77
I was confused about all the questions about changing pins on the fly etc. Unless I misread it again!!
 
Code:
public:
  HT16K33(const uint8_t address, TwoWire *wire = &Wire);   //  0x70 .. 0x77

How would the actual lines of code look like then? Something like this?
Code:
HT16K33 display1(0x70, Wire);
HT16K33 display2(0x71, Wire);
HT16K33 display3(0x72, Wire);
HT16K33 display4(0x73, Wire);
HT16K33 display5(0x70, Wire1);
HT16K33 display6(0x71, Wire1);
  |
HT16K33 display12(0x73, Wire2);

void setup(){
  display1.begin();
  display2.begin();
    |
  display12.begin();

  display1.displayOn();
  display2.displayOn();
    |
  display12.displayOn();
 }

Paul

PS: this does not compile [C:\Users\Paul\Documents\Arduino\libraries\HT16K33/HT16K33.h:43:7: note: candidate expects 1 argument, 2 provided]
 
Last edited:
The following compiles just fine:
Code:
#include "HT16K33.h"

HT16K33 left(0x71, &Wire);
HT16K33 right(0x70, &Wire1);
...and your code (slightly modified) compiles as well.
Code:
#include "HT16K33.h"

HT16K33 display1(0x70, &Wire);
HT16K33 display2(0x71, &Wire);
HT16K33 display3(0x72, &Wire);
HT16K33 display4(0x73, &Wire);
HT16K33 display5(0x70, &Wire1);
HT16K33 display6(0x71, &Wire1);
HT16K33 display7(0x72, &Wire1);
HT16K33 display8(0x73, &Wire1);
HT16K33 display9(0x70, &Wire2);
HT16K33 display10(0x71, &Wire2);
HT16K33 display11(0x72, &Wire2);
HT16K33 display12(0x73, &Wire2);

void setup() {
    display1.begin();
    display2.begin();
    display3.begin();
    display4.begin();
    display5.begin();
    display6.begin();
    display7.begin();
    display8.begin();
    display9.begin();
    display10.begin();
    display11.begin();
    display12.begin();

    display1.displayOn();
    display2.displayOn();
    display3.displayOn();
    display4.displayOn();
    display5.displayOn();
    display6.displayOn();
    display7.displayOn();
    display8.displayOn();
    display9.displayOn();
    display10.displayOn();
    display11.displayOn();
    display12.displayOn();
}

void loop() {

}
 
Got it working (well, that is to say, my logic analyzer shows data on all 3 I2C ports of a Teensy 4.1).
Had to add "displayXX.cacheOff();" to the code otherwise no data would be sent out...

Here are the images of the logic analyzer:

LA1.jpg
Zoomed in:
LA2.jpg
Zoomed in again:
LA3.jpg

And here is the code used:
Code:
#include "HT16K33.h"

HT16K33 display1(0x70, &Wire);
HT16K33 display2(0x71, &Wire);
HT16K33 display3(0x72, &Wire);
HT16K33 display4(0x73, &Wire);
HT16K33 display5(0x70, &Wire1);
HT16K33 display6(0x71, &Wire1);
HT16K33 display7(0x72, &Wire1);
HT16K33 display8(0x73, &Wire1);
HT16K33 display9(0x70, &Wire2);
HT16K33 display10(0x71, &Wire2);
HT16K33 display11(0x72, &Wire2);
HT16K33 display12(0x73, &Wire2);

void setup() {
  Wire.setClock(100000);
  display1.begin();
  display2.begin();
  display3.begin();
  display4.begin();
  display5.begin();
  display6.begin();
  display7.begin();
  display8.begin();
  display9.begin();
  display10.begin();
  display11.begin();
  display12.begin();

  display1.displayOn();
  display2.displayOn();
  display3.displayOn();
  display4.displayOn();
  display5.displayOn();
  display6.displayOn();
  display7.displayOn();
  display8.displayOn();
  display9.displayOn();
  display10.displayOn();
  display11.displayOn();
  display12.displayOn();

  display1.cacheOff();
  display2.cacheOff();
  display3.cacheOff();
  display4.cacheOff();
  display5.cacheOff();
  display6.cacheOff();
  display7.cacheOff();
  display8.cacheOff();
  display9.cacheOff();
  display10.cacheOff();
  display11.cacheOff();
  display12.cacheOff();
}

void loop() {
  display1.displayInt(1);
  display2.displayInt(2);
  display3.displayInt(3);
  display4.displayInt(4);
  display5.displayInt(5);
  display6.displayInt(6);
  display7.displayInt(7);
  display8.displayInt(8);
  display9.displayInt(9);
  display10.displayInt(10);
  display11.displayInt(11);
  display12.displayInt(12);

  delay(10);
}

Hope Philip can test with the real displays.
Paul
 
wow, i did not see all the replies. my SW friend helped me with this:



#include <Wire.h>
#include <SparkFun_Alphanumeric_Display.h> //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun

HT16K33 display1;
HT16K33 display2;
//HT16K33 display3;

void setup()
{
Serial.begin(9600);
// while(!Serial) { // Wait until serial port is initialized
// } // Comment this out, when standalone! Otherwise you sketch won't work.

Wire.begin(); //Join I2C bus
Wire1.begin(); //Join I2C bus
//Wire2.begin();
if (display1.begin(0x70, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, Wire) == false) {
// Serial.println("Wire wasn't found");
}
if (display2.begin(0x70, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, Wire1) == false) {
// Serial.println("Wire1 wasn't found");
}
// display3.begin(0x70, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, Wire2);

}

void loop()
{
display1.print("Milk");
delay(500);
display2.print("SUGR");
delay(500);
}
 
wow, i did not see all the replies. my SW friend helped me with this:



#include <Wire.h>
#include <SparkFun_Alphanumeric_Display.h> //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun

HT16K33 display1;
HT16K33 display2;
//HT16K33 display3;

void setup()
{
Serial.begin(9600);
// while(!Serial) { // Wait until serial port is initialized
// } // Comment this out, when standalone! Otherwise you sketch won't work.

Wire.begin(); //Join I2C bus
Wire1.begin(); //Join I2C bus
//Wire2.begin();
if (display1.begin(0x70, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, Wire) == false) {
// Serial.println("Wire wasn't found");
}
if (display2.begin(0x70, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, Wire1) == false) {
// Serial.println("Wire1 wasn't found");
}
// display3.begin(0x70, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, Wire2);

}

void loop()
{
display1.print("Milk");
delay(500);
display2.print("SUGR");
delay(500);
}

Did this work with the Sparkfun library?

Paul
 
yes, i now have expanded it to 6 display, 3 on each port.


#include <Wire.h>
#include <SparkFun_Alphanumeric_Display.h> //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun

HT16K33 display1;
HT16K33 display2;
//HT16K33 display3;
String TOP1="COOl";
String TOP2="-10.2";
String TOP3="FAST";
String top;
String Bot1="SODA";
String Bot2=" +1.0";
String Bot3="COLD";
String bot;




void setup()
{
Serial.begin(9600);
// while(!Serial) { // Wait until serial port is initialized
// } // Comment this out, when standalone! Otherwise you sketch won't work.

Wire.begin(); //Join I2C bus
Wire1.begin(); //Join I2C bus
//Wire2.begin();
if (display1.begin(0x70,0x71, 0x72, DEFAULT_NOTHING_ATTACHED, Wire) == false) {
// Serial.println("Wire wasn't found");
}
if (display2.begin(0x70, 0x71,0x72, DEFAULT_NOTHING_ATTACHED, Wire1) == false) {
// Serial.println("Wire1 wasn't found");
}
// display3.begin(0x70, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, DEFAULT_NOTHING_ATTACHED, Wire2);

}

void loop()
{
top=TOP1+TOP2+TOP3;
bot=Bot1+Bot2+Bot3;
display1.print(top);display2.print(bot);
delay(500);
display1.print(" "); display2.print(" ");
delay(10);



}
 
Back
Top