First time poster so I apologize in advance for not including something I should. I am trying to create a simple counter using 2 Quad 0.54" AlphaNum feather and TCA9548A multiplexer. The goal is to have an input, like a button, that will increment on the displays but keep track of the counts individually. I don't think this is particularly hard but I am having trouble getting the displays to work at the same time (so problems with the multiplexer). If anyone has any advice I would be very appreciative. Thank you
// trying to get two displays to work at the same time using I2C multiplexer
// Include Wire Library for I2C
#include <Wire.h>
// include other stuff for displays
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_AlphaNum4 alpha1 = Adafruit_AlphaNum4(); // create objects for each display
Adafruit_AlphaNum4 alpha2 = Adafruit_AlphaNum4();
void TCA9548A(uint8_t bus) // this is a switch for the channel
{
Wire.beginTransmission(0x70); // TCA9548A address is 0x70
Wire.write(1 << bus); // send byte to select bus
Wire.endTransmission();
}
void setup() {
Wire.begin();
// set up for display 1
TCA9548A(1);
// put your setup code here, to run once:
alpha1.writeDigitRaw(3, 0x0);
alpha1.writeDigitRaw(0, 0xFFFF);
alpha1.writeDisplay();
delay(200);
alpha1.writeDigitRaw(0, 0x0);
alpha1.writeDigitRaw(1, 0xFFFF);
alpha1.writeDisplay();
delay(200);
alpha1.writeDigitRaw(1, 0x0);
alpha1.writeDigitRaw(2, 0xFFFF);
alpha1.writeDisplay();
delay(200);
alpha1.writeDigitRaw(2, 0x0);
alpha1.writeDigitRaw(3, 0xFFFF);
alpha1.writeDisplay();
delay(200);
alpha1.clear();
alpha1.writeDisplay();
// display every character,
for (uint8_t i='!'; i<='z'; i++) {
alpha1.writeDigitAscii(0, i);
alpha1.writeDigitAscii(1, i+1);
alpha1.writeDigitAscii(2, i+2);
alpha1.writeDigitAscii(3, i+3);
alpha1.writeDisplay();
delay(300);
}
// set up for display 2
TCA9548A(2);
alpha2.writeDigitRaw(3, 0x0);
alpha2.writeDigitRaw(0, 0xFFFF);
alpha2.writeDisplay();
delay(200);
alpha2.writeDigitRaw(0, 0x0);
alpha2.writeDigitRaw(1, 0xFFFF);
alpha2.writeDisplay();
delay(200);
alpha2.writeDigitRaw(1, 0x0);
alpha2.writeDigitRaw(2, 0xFFFF);
alpha2.writeDisplay();
delay(200);
alpha2.writeDigitRaw(2, 0x0);
alpha2.writeDigitRaw(3, 0xFFFF);
alpha2.writeDisplay();
delay(200);
alpha2.clear();
alpha2.writeDisplay();
// display every character,
for (uint8_t i='!'; i<='z'; i++) {
alpha2.writeDigitAscii(0, i);
alpha2.writeDigitAscii(1, i+1);
alpha2.writeDigitAscii(2, i+2);
alpha2.writeDigitAscii(3, i+3);
alpha2.writeDisplay();
// Serial.println("Start typing to display!");
}
}
char displaybuffer[4] = {' ', ' ', ' ', ' '};
void loop() {
while (! Serial.available()) return;
char c = Serial.read();
if (! isprint(c)) return; // only printable!
// scroll down display
displaybuffer[0] = displaybuffer[1];
displaybuffer[1] = displaybuffer[2];
displaybuffer[2] = displaybuffer[3];
displaybuffer[3] = c;
// set every digit to the buffer
alpha1.writeDigitAscii(0, displaybuffer[0]);
alpha1.writeDigitAscii(1, displaybuffer[1]);
alpha1.writeDigitAscii(2, displaybuffer[2]);
alpha1.writeDigitAscii(3, displaybuffer[3]);
// write it out!
alpha1.writeDisplay();
delay(200);
while (! Serial.available()) return;
char d = Serial.read();
if (! isprint(d)) return; // only printable!
// scroll down display
displaybuffer[0] = displaybuffer[1];
displaybuffer[1] = displaybuffer[2];
displaybuffer[2] = displaybuffer[3];
displaybuffer[3] = d;
// set every digit to the buffer
alpha2.writeDigitAscii(0, displaybuffer[0]);
alpha2.writeDigitAscii(1, displaybuffer[1]);
alpha2.writeDigitAscii(2, displaybuffer[2]);
alpha2.writeDigitAscii(3, displaybuffer[3]);
// write it out!
alpha2.writeDisplay();
delay(200);
}
The second instance needs a different i2c address.
The first is 0x70. That's the default.
The second display will need A0 shorted to make it address 0x71
Then Use this:
Adafruit_AlphaNum4 alpha1 = Adafruit_AlphaNum4(); // create objects for each display
Adafruit_AlphaNum4 alpha2 = Adafruit_AlphaNum4(0x71);
If you need to use the multiplexor and it is set at address 0x70, then short A0 an the first board, and short A1 on the second, then use this:
Adafruit_AlphaNum4 alpha1 = Adafruit_AlphaNum4(0x71);
Adafruit_AlphaNum4 alpha2 = Adafruit_AlphaNum4(0x72);
If you are going to use a multiplexer, then you need to properly set the multiplexer channel before communicating with each display. You have done this in setup(), but not in loop().
Much easier to do as @SurferTim suggests and set different addresses for the display, that completely eliminates the multiplexer.
You forgot the Serial.begin() in setup, and the 200mS delays in loop() may cause the Serial receive buffer to overflow if you send more than an average of 5 characters per second over Serial.
The HT16K33 chips on the display backpacks have a default address of 0x70.
The TCA9548 also has a default address of 0x70.
So if you were hoping to use the multiplexer in order to avoid having to change the address of one of the display backpacks, you are out of luck!
Given that you will have to change the address of one of the 3 modules, you might as well change one of the display backpacks, and not need to use the multiplexer.
That is correct. The default is 0x70.
with pads:
A0 shorted = 0x71
A1 shorted = 0x72
A0 & A1 shorted = 0x73
A2 shorted = 0x74
A2 & A0 shorted = 0x75.
..and on
Edit: I can't spell "shorted"? My fingers are sometimes faster than my brain.
I shorted the backpack and it works like a charm without the multiplexer. I was just over complicating my project. Thank you so much!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.