On Saturday, August 13, 2022 we will be working on the Adafruit Customer Support Forums. If you visit over the weekend and things are not complete yet, please check back later, https://adafruit.com/forumupdates
0

Multiple Displays with Pico and Multiplexers
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Multiple Displays with Pico and Multiplexers

by steadystate on Mon Jun 27, 2022 10:54 pm

Without getting into specific code, I have a couple of general noob questions. Please forgive my ignorance.

It is my understanding that I can *independently* run multiple ssd1306 OLEDs that share the same address on a common I2C bus using a Pico and a TCA9548A multiplexer when programming in C or Micropython. Is this possible with Circuitpython as well?


If so, another question:

Is it possible to use two TCA9548A boards (each with a different address on the same I2C bus) and independently run ssd1306 OLEDs of the same address on channels of each TCA9548A board?

Would I need multiple display busses to use more than one TCA9548A board, since they each have a unique address? Is this even possible on a single Pico using Circuitpython?

Thanks in advance, and apologies if the post isn't very clear.

steadystate
 
Posts: 8
Joined: Mon Jun 27, 2022 9:21 pm

Re: Multiple Displays with Pico and Multiplexers

by freddyboomboom on Mon Jun 27, 2022 11:52 pm

There's a guy on the Pimoroni forums that has multiple displays working on a Raspberry Pi Pico board for a weather station. He calls himself "alphanumeric".

I believe he's put them on different addresses, though.

He has them in a few different threads: https://forums.pimoroni.com/u/alphanumeric/activity/topics

I believe he's using MicroPython, but you may be able to get some hints from his work.

freddyboomboom
 
Posts: 203
Joined: Wed Feb 16, 2022 7:55 pm

Re: Multiple Displays with Pico and Multiplexers

by adafruit_support_mike on Thu Jun 30, 2022 9:25 pm

steadystate wrote:It is my understanding that I can *independently* run multiple ssd1306 OLEDs that share the same address on a common I2C bus using a Pico and a TCA9548A multiplexer when programming in C or Micropython. Is this possible with Circuitpython as well?

Yes. I2C is pretty much independent of the language you use.

steadystate wrote:Is it possible to use two TCA9548A boards (each with a different address on the same I2C bus) and independently run ssd1306 OLEDs of the same address on channels of each TCA9548A board?

Yes, that will work.

Each TCA9548A has a collection of switches that connect the input SDA/SCL lines to one or more pairs of output SDA/SCL lines. They let you handle multiple devices with the same I2C address by only connecting one to the microcontroller at any given time. If you have multiple TCA9548As, all but one will have all its connections shut off at any given time. They can do that, and you can manage all the switch connections in your code.

steadystate wrote:Would I need multiple display busses to use more than one TCA9548A board

Yes.

steadystate wrote:since they each have a unique address?

Just the opposite: all the displays have the same address, so you need the TCA9548As to manage the connections between the displays and the microcontroller.

steadystate wrote:Is this even possible on a single Pico using Circuitpython?

Yes.

adafruit_support_mike
 
Posts: 64984
Joined: Thu Feb 11, 2010 2:51 pm

Re: Multiple Displays with Pico and Multiplexers

by steadystate on Fri Jul 01, 2022 3:34 pm

Thank you so much for the reply.

steadystate wrote:Would I need multiple display busses to use more than one TCA9548A board

adafruit_support_mike wrote:Yes.


steadystate wrote:since they each have a unique address?

adafruit_support_mike wrote:Just the opposite: all the displays have the same address, so you need the TCA9548As to manage the connections between the displays and the microcontroller.


Sorry, what I meant was "since all of the TCA9548A boards have a unique address, would I need a separate display bus for each TCA9548A?"

So, I should set up a separate display bus for each TCA9548A? I've tried to do so this way:

display_bus1 = displayio.I2CDisplay(i2c, device_address = 0x70) #address of first TCA9548A is 0x70
display_bus2 = displayio.I2CDisplay(i2c, device_address = 0x71) #address of second TCA9548A is 0x71

I always get a traceback error stating "Too many display busses".

How do I set up multiple display busses? Sorry for the newbie questions. I really have scoured the internet for answers, but I have not yet met success.

steadystate
 
Posts: 8
Joined: Mon Jun 27, 2022 9:21 pm

Re: Multiple Displays with Pico and Multiplexers

by adafruit_support_mike on Fri Jul 01, 2022 4:56 pm

steadystate wrote:Sorry, what I meant was "since all of the TCA9548A boards have a unique address, would I need a separate display bus for each TCA9548A?"

No.

From the microcontroller's viewpoint, its SDA and SCL lines are its display bus. All your TCA9548As will have their input sides connected to that.

Each TCA9548A has a set of internal switches that connect the input SDA and SCL lines to some combination of its eight output SDA/SCL lines. In general, we only connect one output pair at a time so, for instance, the microcontroller thinks TCA9548A.SDA[1] and TCA9548A.SCL[1] are just part of its SDA/SCL bus. Then you can open that pair of switches and close another so the microcontroller thinks TCA9548A.SDA[3] and TCA9548A.SCL[3] are part of its SDA/SCL bus.

If you have multiple TCA9548As connected to the microcontroller's SDA/SCL lines, you have more ways to do the same basic thing. You can set the switches in all the TCA9548As to the microcontroller thinks TCA9548A[1].SDA[1] and TCA9548A[1].SCL[1] are extensions of SDA/SCL, or TCA9548A[4].SDA[3] and TCA9548A[4].SCL[3] are.

You can have up to eight TCA9548As with unique addresses connected to the microcontroller's SDA/SCL lines. Each of those controls connections to eight output SDA/SCL pairs, so you can have a total of 64 OLED displays the microcontroller can use, even if all the displays have the same I2C address. Your code will have to control the TCA9548A switches so the microcontroller only sees one display at any time. The microcontroller always thinks it's talking to a single SDA/SCL bus, while the TCA9548As control which display is part of that bus at any time.

adafruit_support_mike
 
Posts: 64984
Joined: Thu Feb 11, 2010 2:51 pm

Re: Multiple Displays with Pico and Multiplexers

by steadystate on Fri Jul 01, 2022 5:20 pm

adafruit_support_mike wrote:
steadystate wrote:Sorry, what I meant was "since all of the TCA9548A boards have a unique address, would I need a separate display bus for each TCA9548A?"

No.

From the microcontroller's viewpoint, its SDA and SCL lines are its display bus. All your TCA9548As will have their input sides connected to that.

Each TCA9548A has a set of internal switches that connect the input SDA and SCL lines to some combination of its eight output SDA/SCL lines. In general, we only connect one output pair at a time so, for instance, the microcontroller thinks TCA9548A.SDA[1] and TCA9548A.SCL[1] are just part of its SDA/SCL bus. Then you can open that pair of switches and close another so the microcontroller thinks TCA9548A.SDA[3] and TCA9548A.SCL[3] are part of its SDA/SCL bus.

If you have multiple TCA9548As connected to the microcontroller's SDA/SCL lines, you have more ways to do the same basic thing. You can set the switches in all the TCA9548As to the microcontroller thinks TCA9548A[1].SDA[1] and TCA9548A[1].SCL[1] are extensions of SDA/SCL, or TCA9548A[4].SDA[3] and TCA9548A[4].SCL[3] are.

You can have up to eight TCA9548As with unique addresses connected to the microcontroller's SDA/SCL lines. Each of those controls connections to eight output SDA/SCL pairs, so you can have a total of 64 OLED displays the microcontroller can use, even if all the displays have the same I2C address. Your code will have to control the TCA9548A switches so the microcontroller only sees one display at any time. The microcontroller always thinks it's talking to a single SDA/SCL bus, while the TCA9548As control which display is part of that bus at any time.



Thanks for the reply. So, if I understand correctly, I only need one display bus for the Pico to talk to all of the TCA9548A boards (with each TCA9548A set to a unique address). One point of newbie confusion on my part:

To my limited understanding, a display bus definition, e.g.

display_bus = displayio.I2CDisplay(i2c, device_address = whatever address you specify)

requires you to explicitly state the address of a device. If the TCA9548A boards are all set to a different address, then I get a traceback error stating that no device is found at the TCA9548A addresses not specified in the display bus line (since only one address can be specified[?]). If I don't specify an address in the display bus line, then I get an error stating that I must provide an address. What am I missing here? I guess my basic problem is that I don't know how to make a display bus reference more than one address.

Is there any existing example code to show how two TCA9548A boards, each with two OLEDs would be handled in Circuitpython? If so I could extrapolate to more devices.

Thanks again for your help.

steadystate
 
Posts: 8
Joined: Mon Jun 27, 2022 9:21 pm

Re: Multiple Displays with Pico and Multiplexers

by adafruit_support_mike on Fri Jul 01, 2022 7:17 pm

The TCA9548A can be set to addresses from 0x70 to 0x77. Let's assume you have eight of them connected to the microcontroller's SDA/SCL lines, so all eight addresses are visible.

Let's also assume you're using this OLED display, which has I2C address 0x3C. You have 64 of them, one for each of the TCA9548A output channels.

The TCA9548A command interface is simple: you write one byte to the TCA9548A's address. The TCA9548A treats that byte as a row of 8 bits, each of which sets the on/off status for one of its switches.

To select the OLED display connected to the first TCA9548A's channel 0, you'd send the byte 0b00000001 to I2C address 0x70, and 0b00000000 to I2C addresses 0x71 through 0x77.

After sending those messages to the TCA9548As, the microcontroller will see an I2C bus with devices at addresses 0x70 through 0x77, and one device at address 0x3C.

If you want to switch to the OLED connected to TCA9548A 0x70's third output channel, you'd send the byte 0b00000100 to address 0x70. After doing so, the microcontroller will still see an I2C bus with devices at addresses 0x70 and one device at address 0x3C. The device at address 0x3C will be different from the one the microcontroller was talking to before, but the list of I2C addresses visible to the microcontroller will always look the same.

adafruit_support_mike
 
Posts: 64984
Joined: Thu Feb 11, 2010 2:51 pm

Re: Multiple Displays with Pico and Multiplexers

by steadystate on Fri Jul 01, 2022 8:26 pm

Again, thanks for the reply. I'm starting to wrap my head around it. Unfortunately, the only TC9548A w/OLED examples I can find are in C++ or Arduino, which I don't know. I have yet to find Circuitpython or even Micropython examples of the TCA9548A with OLEDs.

steadystate
 
Posts: 8
Joined: Mon Jun 27, 2022 9:21 pm

Re: Multiple Displays with Pico and Multiplexers

by steadystate on Sat Jul 02, 2022 9:52 pm

I'm going to have to concede defeat on this one. Without example code in Circuitpython, I'm just spinning my wheels in unsuccessful trial and error. I know it's simple once you understand it. But my pea brain just can't make it work from examples in C++ or by looking at the module descriptions.

The official adafruit Circuitpython webpage has a link to compatible adafruit boards, including the TC95848A. But the examples and tutorials for the TC9548A are not in Circuitpython, but rather in C++. :(

If anyone can direct me to example code in Circuitpython, I would be most appreciative.

steadystate
 
Posts: 8
Joined: Mon Jun 27, 2022 9:21 pm

Re: Multiple Displays with Pico and Multiplexers

by freddyboomboom on Sat Jul 02, 2022 11:41 pm

I don't have one, but I would try either of these two for hints:

https://learn.adafruit.com/working-with-multiple-i2c-devices/circuitpython-3

https://learn.adafruit.com/midi-laser-harp-time-of-flight-sensors/coding-the-laser-harp

Found them by going to learn.adafruit.com and searching for "TC95848A".

freddyboomboom
 
Posts: 203
Joined: Wed Feb 16, 2022 7:55 pm

Re: Multiple Displays with Pico and Multiplexers

by steadystate on Tue Jul 05, 2022 9:49 pm

I've spent a week on this with no success. I can find no applicable example code in Circuitpython. Does anyone know of someone I can pay who will write a simple script using a Pico and two TCA9548A boards, each with two i2C ssd1306 OLEDs attached (one to channel 0 and another to channel 1) each displaying independent text? I could use this example to extrapolate to additional multiplexers and displays.

I stripped the sketch to the bare bones (using one display and one TCA9548A):


import board
import busio
import time

# Create I2C bus as normal
i2c = busio.I2C(scl=board.GP21, sda=board.GP20)

while not i2c.try_lock():
pass

# change buffer value to: 0b00000000, 0b00000001, 0b00000100 and connect a display to each TCA9548A channel one by one to test
# enable channel 0 (SD0,SC0) or channel 1 or channel 3 by using buffer values above

i2c.writeto(0x70, b'0b00000001')

try:
while True:
print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()],)
time.sleep(2)

finally: # unlock the i2c bus when ctrl-c'ing out of the loop
i2c.unlock()


The results:
Writing 0b00000000 shows a device at 0x3c on channels 4 and 5 when the display is connected to those channels
Writing 0b00000001 shows a device at 0x3c on channels 0, 4, and 5 when the display is connected to those channels
Writing 0b00000100 shows a device at 0x3c on channels 0, 1, 4, and 5 when the display is connected to those channels

I don't know what I'm doing wrong. I generally like to do things on my own, but despite the help I've already received (which I appreciate), I'm just plain stuck. Thanks.

steadystate
 
Posts: 8
Joined: Mon Jun 27, 2022 9:21 pm

Re: Multiple Displays with Pico and Multiplexers

by adafruit_support_mike on Wed Jul 06, 2022 5:46 pm

Post a photo showing your hardware and connections and we'll take a look. 800x600 images usually work best.

adafruit_support_mike
 
Posts: 64984
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.