Connecting 2 or more Teensy together

Status
Not open for further replies.

Tejkaran

Well-known member
Hi all

I am using the Teensy 3.2 with APA102 lights and FastLED library for coding the Adruino IDE.

I am looking to drive the LED's as fast as possible and also as accurately too.
The process I am using is to light up a few leds(say 5) and make it look like a moving strip. Initially I was only using 1 LED strip(30LEDs/m - 150LED's) and everything worked fine but when I attach multiple LED strips together the LEDs s flicker as I believe they are not very good with high speeds/computations.

What I have been able to do with the help of the FastLED library is to use 4 SPI pins on the Teensy (7,11,13,14) and drive 4 separate LED strips, and therefore get 20m to work really well(https://github.com/FastLED/FastLED/wiki/SPI-Hardware-or-Bit-banging). The problem though, and I am following this up, is that any distance over 5m per array seems to have the same effect that a long led strip has, which is to cause the LEDs to flicker badly.

Therefore, I began to think of ways around this and arrived at a potential solution of linking up multiple Teensy's for longer chains (60m+/1,750LED's) to work at the speed I would like. Each Teensy can connect 4x5m strips and then if each Teensy connected to each other, I can use 3 Teensy to drive 60m.

However my problem is I do not know how to connect the Teensys together, and in addition, if I am able to connect Teensys together how can I get them to communicate with one another? I read in some forum posts that it is possible using I2C/SDA/SCL but i do not have any idea what that is so even a breakdown would be hugely appreciated

thank you

Tej
 
Hi,

lowering the SPI bus frequency helps with long strips, maybe try that first? Also check if all LEDs have a stable power supply with not to much voltage drop accross the strip.
 
However my problem is I do not know how to connect the Teensys together, and in addition, if I am able to connect Teensys together how can I get them to communicate with one another? I read in some forum posts that it is possible using I2C/SDA/SCL but i do not have any idea what that is so even a breakdown would be hugely appreciated
Well, that's another topic...

The easiest is to use the Hardware-Serial(s). Connect TX of Tennsy #1 to RX of Teensy #2 - RX of Teensy#1 to TX of Teensy#2
But, really, i'd try this way only if nothing else helps.
 
@Ben
I have stable power supply, and I have lowered the frequency and it is more stable, however it becomes too slow for what I want if I do lower it

@Frank B
I will try that, I'm not overly keen on it, I'm just preparing for what to do if I cannot do my ideal plan.
If I was to have three Teensys connected, how would I wire that? Would I do Teensy 1 tx to Teensy 2&3 rx, and vice versa?
 
If I was to have three Teensys connected, how would I wire that? Would I do Teensy 1 tx to Teensy 2&3 rx, and vice versa?
If you only need one Teensy (Master) communicating to several other Teensies(Slaves) you could prefix each Message with an address and daisy-chain the Teensies:
T#1TX->T#2RX
T#2TX->T#3RX

if Teensy #2 receives a messages with an address it does not "know" it just forwards the message to the next slave. You need to check if the lag introduced by those store-and-forward transmissions is acceptable.
 
How about sending a 4 byte message from the master ...

first 2 bytes for teensy 2 = 88 and second 2 byte for teensy 3 = AA.

Teensy 2 gets the message 88AA, stores it, then retransmits it. Teensy 2 just right shifts >> the stored 88AA to 88.

Teensy 3 receives 88AA too, and just bangs off the MSB .. (88AA & FF = AA).

Maybe you could even parallel the teensies, so no need to retransmit in a daisy chain? A teensy 3.2 used as a master has three hardware serial ports available.

Edit: I'm working on a MIDI project so forgive me my asinine Midified suggestions atm.
 
Last edited:
@Ben
I have neevr done a master/slave combo with the Teensy
could you give a very basic sketch that I can work off - for example if you had an LED on pin 13 on Teensy 1(master), Teensy 2(slave) and Teensy 3(slave). so three led's and you wanted to light up no1,2 & 3 with a 1 sec break between each.

@Adrian, that sounds good, and i can follow what you are saying but I do not know how to implement as such - pretty much a layman here :/
 
With your distances, you are way beyond sane cable length limits for logic level I2C, SPI or UART. I don't think bidirectional communication buys you much.

I would use one Teensy as master and connect all other Teensys as slaves to the same UART. Put a RS485 transmitter on the master side and RS485 receivers on the slave side (you can get nice 3.3V versions that don't require any additional components). RS485 is intended for very long cable lengths and will give you noise immunity.

When you send a command to the slaves include a slave ID, so that the wrong slaves can simply ignore it.

Code:
Master Teensy           Teensy slave 1     Teensy slave 2
   UART TX                 UART RX            UART RX
      |                       |                  |
 RS485 transmitter       RS485 receiver     RS485 receiver
      |                       |                  |
      --------------------------------------------------------...
 
hi Tni

I have looked up what the RS485 is, and it makes sense for me to get one, when looking around I relised that they cost about £300/$450, is this right? any chance that you could link me to what I should be looking at?
 
I have looked up what the RS485 is, and it makes sense for me to get one, when looking around I relised that they cost about £300/$450, is this right? any chance that you could link me to what I should be looking at?
You are looking at the wrong thing. You are not supposed to use an actual RS485 interface, only the line transceivers. You will speak the standard UART (like RS232) protocol. You simply translate the normal 3.3V logic levels (referenced against ground) to differential RS422/RS485 levels (use twisted pair wiring for the connection).

You would use a chip like this ($1.35 for a single one):
https://www.digikey.com/product-detail/en/intersil/ISL83490IBZ/ISL83490IBZ-ND/1034856

\\

From I have seen, it should actually be possible to drive strings of a few hundred (maybe thousands) APA102s at more than 12MHz SPI speed. So you should be able to use a single Teensy. You should post a new thread with details of your design.

You are driving the strings with a level shifter, right? You should place the level shifter close to the the first APA102 and if the connection Teensy --> level shifter is long use a RS422/ RS485 transmitter/receiver between Teensy/level shifter.

Teensy --> RS485 transmitter ----twisted pair----> RS485 receiver --> level shifter --> APA102

Actually, you could also replace the level shifter with a 5V RS485 receiver:

Teensy --> 3.3V RS485 transmitter ----twisted pair----> 5V RS485 receiver --> APA102

Edit:

The part I mentioned above is rated for 10Mbps only. You can get RS485 transceivers that can handle 35.
 
Last edited:
Thanks xenomoar and tni, was worried about cost escalating there!

@tni
I thought APA102 should be able to run at 12Mhz for 1 few thousand too, however it does not. I will make a new thread for that, so it does not overlap, but thanks for the heads up on the RS485 wiring which can work over long distances.
My next question would be how to code it, but for now, I will leave that as it may not be necessary and I do not want to be wasting your time.
 
For coordinating among many slaves and one master, consider using the EasyTransfer library from Bill Porter. Define a struct with a slave address and the APA102 information, then have the slaves watch the TX/RX lines for new messages to process.

Unless you select a slew-limited RS485 chip, remember to use a 120Ohm terminating resistor across A-B on either end of the RS485 bus. Slew-limited RS485 chips usually operate below 250kbps, the other kind can operate up to 20Mbit/s. IIRC, Teensy serial buses can operate up to 6Mbit/s. I plan on operating mine at 1Mbit/s, with Rs485 transceivers that are claimed to go 5-10x faster (allowing a margin of error for marketing speak / data sheet vs. reality).
 
RS485 can handle high speed and long distance. But it's designed for a single asynchronous serial signal (eg, start & stop bits).

Using more than one RS485 transmitter & receiver for 2 synchronous signals is a different matter, where you'll also need the total signal delay through both paths to closely match. It may work out well, but then again it may not. These chips don't come with specs for the input to output signal propagation delay, where you need to worry about the total variance, rather than just a worst case maximum.
 
Using more than one RS485 transmitter & receiver for 2 synchronous signals is a different matter, where you'll also need the total signal delay through both paths to closely match. It may work out well, but then again it may not. These chips don't come with specs for the input to output signal propagation delay, where you need to worry about the total variance, rather than just a worst case maximum.
Is that an issue when you have good thermal coupling between transmitter/receiver pairs (same package) and identical cabling (e.g. using 2 twisted pairs from an Ethernet cable)? I would expect the wire delay mismatches to be a much bigger problem than mismatches in single-package transmitters/receivers.

I found some parts with very nice specs and very tightly controlled delay:
http://www.linear.com/product/LTC1518
http://www.linear.com/product/LTC1688
 
Using more than one RS485 transmitter & receiver for 2 synchronous signals is a different matter, where you'll also need the total signal delay through both paths to closely match. It may work out well, but then again it may not. These chips don't come with specs for the input to output signal propagation delay, where you need to worry about the total variance, rather than just a worst case maximum.

Interesting point - is this an example of trying to run SPI or the APA102 signals directly over the RS485 buses?

Also, if sending at high speed, you may need multiple RS485 transmitters / signalling lines to enable RTS/CTS as well? That is, if there is a single master, one pair for serial TX from master to the slaves, then a RTS line from the slaves back to the master? (This would be one-way comm).
 
Last edited:
Hello Tejkaran-
The way we are doing it is to use the CAN bus. Teensys have hardware support for CAN, but they need transceivers and a library. See
https://github.com/teachop/FlexCAN_Library and
http://www.aliexpress.com/item/Free...tion-module-development-board/1902162748.html

You can connect as many Teensys as you want and the CAN bus is robust. We are still wroking out the bugs in the bit-packing protocol, but it definitely works. What's more, you can hot-swap since CAN bus is a spider topology. Just make sure you connect ground before power, or you can fry stuff...
 
hey guys, sorry about disappearing, I went on holiday and was then ill after that, so been MIA

@ xenomoar/tni et al.
You say it should go like this if the distance between my teensy and the first APA102 LED is far?:
That said, the distance between the Teensy and the first APA102 is not far at all, your talking 30-40cm at most.
Teensy --> 3.3V RS485 transmitter ----twisted pair----> 5V RS485 receiver --> APA102

Just to make sure I have the right parts, if i need to go down this road are these the correct parts?:
--> 3.3V RS485 transmitter (any recommendations?)
--> twisted pair cable (how about this?)
--> 5V RS485 receiver (link that xenomoar gave)

So for the first Teensy IE the master, I won't really have to do anything special right? But for subsequent ones, I should follow your layout above?
but then as PaulStoffregen said, the master/slave combo may not work so this is a risk? In which case I have two leads to follow:
1) EasyTransfer from Bill Porter as suggested by constantin or
2) Use a CAN based layout as suggested by ghjmaui ?

There is so much info here and i'm trying to digest it all, so bare with me please. Does that sound right to you?

Thanks for the wiring info too, i'm reading my way through that.
 
Well, that's another topic...

The easiest is to use the Hardware-Serial(s). Connect TX of Tennsy #1 to RX of Teensy #2 - RX of Teensy#1 to TX of Teensy#2
But, really, i'd try this way only if nothing else helps.

Can I connect the RX to TX directly with a wire or do we need a chip between them?
 
If it is just between Teensys, then just wires. All Teensy serial ports use "TTL" serial (logic level of 3V3), not standard RS232 voltage level (which can be anywhere from 8 to 12VDC). If you are just going between two T3.x or T4.x, then just wires between them and use the serial library. If you have to go outside to some other serial device, then you need to translate using a MAX232 chip or logic level converter.
 
Can I connect the RX to TX directly with a wire or do we need a chip between them?

Yes. Be sure to connect the ground wire also between the two Teensies. Assuming each is powered separately, don't connect VIN. If you are wanting to power one Teensy and use it to power the other, then connect the two VIN wires.
 
Yes. Be sure to connect the ground wire also between the two Teensies. Assuming each is powered separately, don't connect VIN. If you are wanting to power one Teensy and use it to power the other, then connect the two VIN wires.

How do I connect ground wires if I connect 4 teensies to a teensy 4.1 that only has 3 ground pins?
 
Status
Not open for further replies.
Back
Top