Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

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

  1. #1

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

    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

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    465
    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.

  3. #3
    Hi luni,

    Great. Thank you. That adafruit breakout board might be the way to go. I'll study up on it.

  4. #4
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,077
    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 by MichaelMeissner; 07-02-2019 at 12:58 PM.

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,459
    Why not, for all the bells and whistles (LEDs, switches and potentiometers) go for a semi autonomous touch screen like the Nextion HMI?

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,074
    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...

  7. #7
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    899
    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.

  8. #8
    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

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,327
    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


  10. #10
    Thanks @PaulStoffregen. I might not need that much power. The vin pin is working pretty well for me.

    This is the switch I'm using

    https://www.e-switch.com/product-cat...s#.XRw_n3t7l24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •