Best way to expand the number of Digital Outputs on Teensy 3.6

Status
Not open for further replies.

nicnut

Well-known member
Hi,

I am planning on making a Midi Controller that uses a Teensy 3.6. I will be using a lot of Analog inputs and Digital inputs.
I also have a lot of RGB Leds, with each color, Red, Green and Blue, requiring it's own Digital output pin, and the Teensy 3.6 doesn't have enough.

Is there a way to network another Teensy 3.6 so I can use that 2nd board's Digital Pins? Or a way to expand the digital pins on a board?

What would be a sturdy, safe way to achieve increasing the digital pins on a Teensy 3.6 board?

Thanks,

Nick
 
For the LEDs I'd use a driver like the TLC5947 (24 PWM channels, SPI) here a breakout board: https://www.adafruit.com/product/1429 There are lot of others as well, just look for multichannel led driver. If you don't need the PWM capability you can also use something like a TLC59025, which is very easy to use.
 
Hi luni,

Great. Thank you. That adafruit breakout board might be the way to go. I'll study up on it.
 
If you just want digital input or output, and don't need things like PWM support, you can get i2c boards like the MCP23017, which allows you to have 16 digital inputs or outputs per board. You can combine up to 8 of the boards together on the same i2c bus, for a total of 128 digital inputs/outputs.

For just LED output, another solution is to use either WS2812B (which Adafruit calls neopixels) or APA102 (which Adafruit calls dotstars) LED strings. They come in a variety of form factors (individual pixels, rings, sticks, matrix, strings).

Adafruit also has the PWM driver in i2c form factor:

There are different technologies involved in moving LEDs off from direct Teensy pins:
  • I2C -- This is a common bus that allows one master and one or more slave boards. Each slave board has an address, and typically the master sends out a packet with a specific address encoded in it, and the board with that address then responds. On the Teensy you have to use fixed pins to control the i2c bus, typically pin 18 (A4) and pin 19 (A5).
  • SPI -- This is another common bus that often can be somewhat faster than i2c, but it doesn't allow as many slave boards. On SPI buses, you use three fixed pins to control the bus (on the Teensy normally pins 13, 12, and 11), plus 1 extra pin per slave board, plus usually 2 other pins that can be shared among the slave boards. Instead of having an address, each board has the one pin that controls whether the board is active or not.
  • WS2812B -- These are strings of pixels. Each pixel has its own microprocessor that controls the PWM of the 3 or 4 LED colors of the chip. You need one pin to control a LED string on the Teensy. Each pixel has 3 inputs (power, ground, data in) and 3 outputs (power, ground, data out), and the pixels are daisy chained together (i.e. if you have 4 pixels, when you send the commands out, you have to send out the command for pixel #1, then pixel #2, pixel #3, and then pixel #4). Because there is no timing control, the Teensy has to put out the commands in a rather precise timing window. This often times means the Teensy has to turn off interrupts while it is communicating to the LED string, but there are ways to improve upon this.
  • APA102 -- These are strings of pixels like the WS2812B pixels. Unlike the WS2812B pixels, there are two pins (data and clock) which means the timing from the Teensy doesn't have to be as exact.

As you get more LEDs, you will have to spend sometime figuring out how to power the LEDs, as you will run into limitations of how much power the Teensy can provide.

There are various issues for each different technology that you will need to look at.

As a start, you might want to figure out how many pixels you want, whether you want them in fixed form factors or just random pixels, whether you need to control the color and brightness (via turning them on/off rapidly, via PWM), what other things the Teensy is going to be doing at the time, and what kind of power envelope you will need.

You also mentioned lots of analog inputs. You can also move some analog inputs to separate boards:

But there it might be better to just use a second Teensy to handle the analog inputs, and talk to the master Teensy. Perhaps using one or more Teensy LC's. But there you get into complexity that you have to design a protocol for the Teensys to talk to each other.
 
Last edited:
Why not, for all the bells and whistles (LEDs, switches and potentiometers) go for a semi autonomous touch screen like the Nextion HMI?
 
For me these types of questions are always difficult to answer, as the usual answer is it depends...

Things like you could use level shifters to add Input or Output registers, example is 595 for outputs. Not sure if any are compatible with 3.3v...

Or Input/Output Mux. There are several of them out there that also allow for Analog.

Or for adding lots of buttons without needing as many inputs as buttons. You can wire them up like a how many of the keypads do it... Example:
https://www.sparkfun.com/products/14881 If you look at the wiring the 16 buttons take 8 IO pins... You can easily expand this by adding another logical ROW or COL
So you could handle a 20 button setup with 9 pins... But by default these only work if only one button is pressed. There are ways to make it so you can see more than one...

Likewise you can handle multiple buttons on one Analog pin, by using a resistor ladder hookup. So each button pressed with create a different analog voltage, which you can then deduce in the code)....

So again lots of possibilities...

What will work best for you? It depends...
 
Also, MCP23S17 port expanders. These are SPI based, and work on a single chain, with each of the MCP chips having a separate hardware address. The chain length is limited to 8 chips. there are so many options for increasing digital pin number, but like said above, it depends on what you really need.
 
OMG. This is one of the best forums ever. SO much good information here. Thank you all.

I have 16 RGB illuminated button switches and I want the extra digital outputs for all those LEDs, so 48 digital outputs. I'll start researching these options.

THe TLC5947 (24 PWM channels, SPI) breakout board looks nice and I've worked with similar products so I might go that route. Also the MCP23017 - i2c 16 input/output port expander looks good, but I think I will need to research how to program it. And I've never used I2c with a teensy yet. I have used it with Raspberry Pi so I am familiar with the concept. I will figure this out and post my results. So far I have a great prototype with all my analog ins, digital ins, LED displays working. I need to figure out this LED issue but it seems I have some options to figure this out.

Thank You all again.

Nick
 
Maybe the little I/O expander boards we made for the Monolith Synth project might also help? It was basically a hybrid of 2 I/O expander chips (both available as separate boards from Adafruit) plus mosfets to drive 12V lights.

https://www.pjrc.com/monolith-synth/

https://oshpark.com/shared_projects/jiW2r6f5

ledbuttons.jpg
 
Hi everyone,

Sorry to resurrect an old thread. I'm curious regarding the Neopixels MichaelMeissner recommended (https://www.adafruit.com/product/1734) as I'd like to use them in a MIDI pedal I'm trying to build.

The pins read
Data In
+5v
Ground
Data Out

If run from a Teensy 4.0 or 4.1, how would you guys go about powering them?

Cheers! Simon
 
I would connect Vin from the Teensy to the 5V and ground from Teensy to ground on the LED. I think you connect SCA and SDA from the Teensy to to two other pins. You can chain all of those LEDs together. I hope that helps, but that's the general gist of it.
 
Hi everyone,

Sorry to resurrect an old thread. I'm curious regarding the Neopixels MichaelMeissner recommended (https://www.adafruit.com/product/1734) as I'd like to use them in a MIDI pedal I'm trying to build.

The pins read
Data In
+5v
Ground
Data Out

If run from a Teensy 4.0 or 4.1, how would you guys go about powering them?

Cheers! Simon

The answer is it depends on how many lights you want to light up and how bright you want the lights. And as you get to more and more lights, things become more complex.

Some of the newer WS2812B lights can actually be run at 3.3v (which means you don't have to translate the data signal from 3.3v to 5v), but you ultimately only have 250mA available from the Teensy processor, and it needs power as well. So perhaps you can run 10-16 LEDs this way, assuming you don't use high power for the LEDs (I tend to use a maximum of 30 for any one LED, where the 30 is the sum of the R, G, and B power levels). IIRC, a 16 LED ring would draw about 75mA. But note, a random LED might not work at 3.3v. The data in pin would be connected to a random Teensy pin (the data out pin connects to the next light in the chain).

However for real time stuff, you likely want to switch from using the basic Adafruit neopixel library to using the WS2812Serial library. The Adafruit neopixel library disables interrupts while the whole chain is being written (due to the critical timing based on the WS2812 specification, where you need to produce the next set of bits in a fixed period of time). The WS2812Serial library on the other hand restricts your data pin to one of the serial port TX pins. But it operates in a non-blocking fashion, so that other things that need interrupts are not blocked.

For a bit more LEDs (maybe 100 or so), the way to do this is use a fast 3.3v to 5v converter. Note, the random voltage converters are not fast enough (it the converter mentions I2C, SPI, or dual direction, it generally will not be fast enough). The simplest converter to use is the 74AHCT125, which is one of the few fast converters that are available in through hole format rather than surface mount (which you need to solder to a breakout board). Here is Adafruit's entry for it (you can get it from other suppliers):

In this configuration, you hook you the VIN (5v) pin from your Teensy to the VCC pin on the 74AHCT125 and to the VCC on the first light in the strand. Connect Teensy ground to the ground amd 1OE pins on the chip and and to the ground pin on the LED strip. Connect your data pin to the 1A pin on the chip. Connect the 1Y pin to the Data in pin of the strip. For successive strips, connect the VCC, and Ground pins to both strips, and connect the Data Out pin of the first strip to the Data In pin of the next strip.

However, you are limited by the power going through the VIN pin (500mA?), and ultimately the USB cable powering the Teensy. If you hook up the VUSB pin, you should be able to get access to the entire USB power going into the Teensy. But note many USB connections will only give you 500mA.

Beyond 100 LEDs or so, you probably can't power the LEDs from the USB power that powers the Teensy, but you have to have multiple power sources, to power a set of LED strips, interconnecting the grounds, but not the power. It is also at that point you may need to switch to the OctoWS2811 adapter and the OctoWS2811 library:

The Adafruit neopixel uberguide tries to document many of the pitfalls (but it is written from an Adafruit background, so it doesn't mention Teensy specific things like WS2812Serial):

I would connect Vin from the Teensy to the 5V and ground from Teensy to ground on the LED. I think you connect SCA and SDA from the Teensy to to two other pins. You can chain all of those LEDs together. I hope that helps, but that's the general gist of it.
This won't work. See the above posting for the reasons.
 
Status
Not open for further replies.
Back
Top