Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 45

Thread: One Teensy 4.1 to send/receive information to six Teensy 4.1s

  1. #1
    Junior Member
    Join Date
    Oct 2021
    Posts
    17

    One Teensy 4.1 to send/receive information to six Teensy 4.1s

    My goal is to have one Teensy 4.1 send and receive information from each of the seven other Teensy 4.1. How would I go about this? I've been research on using I2C by using multiple Arduinos as an example, but I can also take advantage of Teensy 4.1's 8 serial ports. Thus, I was thinking I could multiple serial#.read/write(). However, I'm not sure how feasible that is. Is there a guide I can follow to accomplish my goal?

  2. #2
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    It depend what your requirements are

    If you need all teensy to be able to communicate at the same time then the 8 port serial is to prefer, the downside is the many required pins of the "master" teensy.

    I2C is a better approach if you for example want to expand it in the future.

    There is also the CAN interface.

    If you want you can use RS-422/RS-458 together with the UART (serial port)
    that approach is good when you have long distances between the diffferent teensy.

  3. #3
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    I need all teensys to communicate at the same time. I don't plan on expanding it in the future.

    I don't think I need a CAN interface.

    The length of wire between each Teensy is at most three meters.

    Therefore, I want to use the 8 serial ports or use the RS-422/RS-458. I'm not sure which is better. I have minimal experience with using serial ports and none with RS-422/RS-458.

  4. #4
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    You use RS-422/RS-458 together with the serial ports,

    there is also RS-232 but that often require external capacitors to work and it's also slower and support shorter cables.

    At three meters I believe it's safest to use any kind of the above standards,


    taken from wiki:
    RS-422/RS-458 is twisted pair wire and support 1200 meters of wire
    RS-232 is single wire but with +- voltage levels

    RS-422 is full duplex
    RS-458 is half duplex but can be full duplex using two transceivers

    so with full duplex RS-422/RS-458 you will need four wires + GND for each teensy that you connect, note that the wires need to be twisted pair, for example you can use the wires from a old ethernet cable, I have recently done that with around 10 meters of cable where two pairs are used for GND and power, one pair is unused and the last pair is for half duplex data.

    I have used MAX487 which is a half duplex transceiver

    in your case you could use MAX488 which is a full duplex RS-422/RS-458 transceiver available in a 8pin PDIP

  5. #5
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    I'm looking into RS-458 and MAX488. I have only found an Arduino-based tutorial below.

    https://create.arduino.cc/projecthub...-rs-485-36888f

    https://www.amazon.com/Max485-Chip-R...ustrial&sr=1-3

    What would be the equivalent code and wiring, at least for an example using three Teensy 4.1 with one master and two slaves, but using Full Duplex communication.

  6. #6
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    The downside with that example is that it uses a master <-> slave configuration half duplex
    (Which is normal? for rs-422/rs-458 networks)

    And it's always the master that initiates a data request, and each slave have a unique adress.

    The master can have the adress 0x00.

    In simple terms it works this way:
    1. All slaves are in receive mode
    2. The master gets into transmit mode and then sends a message: "slave address >0" + "data request CMD" + \n (line feed)
    3. The master gets into receive mode
    4. The slave that matches the adress parses the data, then gets into transmit mode to send a response to the master, this response should use the adress 0x00 (so that only the master "gets" the data.


    Another simpler option using max3232 (full duplex modules) could be used,
    Then you can use the serial ports just like if you did connect them directly between the teensy:s.
    You will then need 12 of those modules to connect 6 teensy:s to the "master".
    In that case you can send commands to all teensy:s at the same time or if you have it the other way and the 6 teensy can simultaneously send data to the "master".

    while at amazon i found these
    https://www.amazon.com/HiLetgo-Level.../dp/B00LUDCAXQ
    Which is rs-232 boards
    They should also work in your case
    And they offer full duplex out of the box
    With the capacitors already mounted.
    And are cheaper.

    Sorry if I confuse you with all the different options.

    Btw. If you use the bare max3232 ic +caps then you have access to two senders and two receivers in one ic, which means in your application you only need 3 max3232 ic:s at the "master" side and one max3232 at each "slave"
    Totally 9 max3232 ic:s.

  7. #7
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    If you want the simpler full duplex approach using the rs-458 modules then you need 24 of those

  8. #8
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    As i feared the max485 based modules are only 5v which means they may not operate well with 3v3 teensy voltage.
    Instead there are the max3485 which are 3v3
    https://www.amazon.com/IndustrialMak.../dp/B085RG84HM

  9. #9
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    I'm interested in using max3485 full duplex mode. Should I buy the module like https://www.amazon.com/Max485-Chip-R...ustrial&sr=1-3 or just the independent IC? I'm not sure if there is a functional difference but would it easier to use a max3485 module: https://www.amazon.com/DollaTek-Deve.../dp/B08HQMDKGR? From what I've research 3485 modules are substantially more expensive per piece though I would be still willing to buy 7 of them.

  10. #10
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    Ok,
    the first amazon link is the 5v half duplex variant
    the second is by the looks of the ic on the board a MAX13487 which is still a half duplex 5V variant,
    I would not trust that one.


    but on mouser.com there is this one
    https://www.mouser.se/ProductDetail/...JvmhZfXA%3D%3D
    which is the full duplex 10Mbps 3v3 variant.
    it cost $4.66 at >10
    so that will be $55.92 @ 12pcs

    you will also need 12 "termination" resistors
    https://www.mouser.se/ProductDetail/...EkkWQXsAvxs%3D

    then you can do it like this:
    Click image for larger version. 

Name:	RS488_multiple.jpg 
Views:	22 
Size:	89.4 KB 
ID:	26540



    But if I understand, you want to do it master/slave with only 7 MAX3490 (10Mbps variant):s
    then you will need the MAX3491:s at the slave teensy:s which have transmit enable (a collision will otherwise occur when two or more transmitters is activated)
    Click image for larger version. 

Name:	RS488_multiple_variant.jpg 
Views:	22 
Size:	67.4 KB 
ID:	26542
    I this mode the master can send some data to all slaves simultaneous, but only one slave can send data back at any given time.

    So if you compare it with the half duplex mode it's the same,
    as all slaves are always listening for commands from the master
    and if the master in half duplex mode want to send something to all slaves
    it can do so by a special message.


    The conclusion:
    it's either the full duplex 12x MAX3490 "master"/"slave" variant or the 7x MAX3485 half duplex master/slave variant


    edit.
    don't forget the decoupling caps at each transceiver ic they are not in the schematic (because it takes too much time adding them)

    edit.
    also don't trust the datasheet at mouser as it contains errors
    here is the newest one from Maxim
    https://datasheets.maximintegrated.c...83-MAX3491.pdf

  11. #11
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,926
    at least with CAN you have a star network, where they all talk to each other at same time, even if one or more go offline, and you can definately go way beyond 3 meters easily

  12. #12
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    I have 6 slave teensy 4.1 and one master teensy 4.1. Each slave needs to be able to receive commands from the master and be able to send information to the master if requested. However, each slave needs to be able to send information to the master when there is an issue without the master requesting it. This means I need to prevent collisions if multiple slaves detect issues. From how I understand each proposal so far, I will need each teensy to communicate equivalently and not as a master/slave configuration. I could be wrong so correct me here, I need a full-duplex RS485 configuration with what @manicksan suggested or a CAN network as both mentioned before. Which would be more appropriate for my application?

    For context, the only other pins for now that I would need are SCL, SCL1, SDA, SDA1, and 1 digital pin. Therefore, using multiple pins should not be an issue. However, it is best if I don't need that many pins. Furthermore, I have limited experience with Serial Ports and I2C protocols. None with RS-based or CAN based ones and would need help with those if implemented.

  13. #13
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,926
    3 wires (CANH,CANL,GND) from each teensy transceiver

    Vehicles use this network because of it's reliability and guarenteed data transmission accross the network, especially in noisy environments. Should one node fail, all your nodes will know (if they have keep alive messages or data setup of your choice). You can use regular UTP cable between the teensies.

    Each frame is capable of sending 8 bytes payloads at a time in CAN2.0 mode, but if you were to use CANFD, you could send up to 64 bytes payload in a single transmission

    So while you can handle the 8/64 data easily as an array, if you use SPI/I2C/UART etc you will need to manage the data one byte at a time or use a library that handles the reassembly for you

  14. #14
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    512
    Another solution might be to use some Ebyte E32 Lora radios.
    They communicate with the Teensy using Serial Uart.
    The radios can be addressed from a master broadcasting to all or individual slaves. The slaves can reply in a similar manner.
    I am using a number of them in a building energy management system. One master and many slaves.
    Seems to work quite well.
    Details here.
    You have to be prepared to have some lost packets. I have experienced when I have stood right in front of the transmitter and blocked the signal.
    I have found that this can be cured quite easily with some simple handshaking.
    Slave sends a message and Master replies to the Slave effectively saying thanks for your message. I include a checksum in the handshake reply to overcome any corruption but have not found any yet.
    A good Teensy library already exists here.
    Here is a YouTube video from the Author of the Library.

  15. #15
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    @BriComp
    I am not going to be using wireless, since there might be electrical interference with the equipment I am using. I should've clarified.

    @toton81
    What modules or example wiring of a Teensy 4.1 can be used with a CAN network? For instance, I find the MAX3490 by @manicksan to be helpful if I were to implement it in a RS485 method.

    Speaking of RS485, @manicksan does the MAX3490 module support full duplex two way communication? I also want to clarify for full duplex, would there be conflict in communication if a Teensy 1 receives information from multiple Teensies while also sending? Otherwise, I'm assuming that I have to switch the Teensy from receiving to sending with a small delay in between unless this is the standard for all code.

  16. #16
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    The MAX3490 is a full duplex 10Mbps 3-3.3V RS-485 transceiver ic
    it's fully transparent to the serial data (you can use it for any kind of digital data)
    Click image for larger version. 

Name:	RS488_one.png 
Views:	17 
Size:	9.6 KB 
ID:	26556

    to use the CAN interface you will need a CAN transceiver (the physical layer)
    https://forum.pjrc.com/threads/64321...-1-4-0-and-3-2

    edit.
    https://www.amazon.com/HiLetgo-SN65H.../dp/B07ZT7LLSK

  17. #17
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    @manicksan

    For the max3490 diagram I just want to confirm that it is indeed the max3490 and not the max3488 as it described per each IC. I am assuming each decoupling capacitor is used to reduce the noise generated from the transfer of data. These decoupling capacitors you mentioned are placed in parallel with the IC chip from VCC to ground, where the VCC is coming from the 3.3 V of the Teensy 4.1, right? Do the GND and VCC for all Teensy 4.1 and max3490 module have the to be the same? Also what is the purpose of the resistors between the twisted wires and where do I place these resistors? I am assuming from the diagram that these are placed right before the twisted wires separate to go into the inputs.

    Lastly, is there a library and an example code I could use with the max3490?

    For the CAN transceiver, I am reading that the Teensy 4.1 already has a CAN controller, meaning that I only need to buy the CAN transceivers you linked. Can you confirm these connections?
    For each Teensy 4.1: CTX1 connects to CRX, CRX1 connects to CTX.
    For each module to make sure all Teensys can communicate with each other: All CANL connects to the same node. All CANH connects to the same node.

    Also, does the FlexCAN_T4 library work with Teensy 4.1?

  18. #18
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,926
    yes to everything except CRX/CTX... For CAN it's TX to TX and RX to RX, same for all, all in parallel
    Also CANH to CANH, CANL to CANL, all parallel

    Best part is if you use CANFD to transfer large 64 byte array payloads (or CAN2.0 to handle small 8 byte payloads), you don't need to add your own CRC stuff with CAN data, the data is guarenteed to be correct/intact once received

    software CRC is only needed if you want to assemble 2 of more payloads together and make sure it's valid. You could also use isotp plugin that is part of the FlexCAN_T4 to send larger payloads over CAN2.0 (8 bytes). It does all the reassembly and gives you the full payload in the callback, even if it is 100 bytes or more so long as the buffer is set to support the highest payload you'll receive over isotp

    My current project uses a CAN2.0 frame request to another node to send back a payload as isotp format. once the data is reassembled the callback is fired and your data is available.
    The payload size is around 112 bytes, where isotp reassembles all the 8 byte frames to rebuild and supply your payload array

    Also, CAN is broadcasted, so all your teensies see the same data, obviously you tell a specific teensy what ID to work with. Each teensy could have it's own CANID, so while they can see all traffic, you decide how you want them to react
    Last edited by tonton81; 11-17-2021 at 05:26 AM.

  19. #19
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    CAN looks very nice indeed as every teensy can talk to one and another. I guess that if the Line is busy and one teensy want to send data that is taken care of by the CAN hardware/software?
    And the data is automatically sent when the line go free again.

    In my big schematic they should be max3490 instead of the max3488 mentioned.

    MAX3490 MAX3488 don't need any special examples except the standard serial port ones,
    as the configuration is a "point to point" network.

  20. #20
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    The downside with CAN is that it needs a special controller, so if one (Including myself) need to connect to a small easy to solder MCU 8pin there is not so many options.
    I'm using the RS-422/RS-485 together with a PIC micro that measures airline pressure for a deep well.

  21. #21
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,926
    yes it is done in hardware, priority is lower CANIDs but in any case you wouldn't notice them taking turns it happens too fast for a human to perceive it. In a car for example, my bus has about 60 IDs all streaming at same time, you can print the traffic to serial monitor but you will see it scrolling non stop with all the traffic from multiple modules

    In essense, hardware takes care of the transmits, you only need to handle the receptions

  22. #22
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    @manicksan
    Is the SN65HVD230 CAN Bus Transceiver compliant with 3.3V? edit: I just checked, it can.

    @tonton81
    Do you have an example code for Teensy 4.1 to Teensy 4.1 communication with the FlexCan_T4 library?

  23. #23
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,926
    The FIFO with interrupt example has send and receive capability. The code is very minimal and it can send and receive 8 bytes payload from all teensies attached

  24. #24
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    520
    did just find these
    https://www.mouser.se/ProductDetail/...J7%2FzzK3JU%3D
    it's a "new" 8-bit pic micro with a CAN FD controller for only $2.30
    looks good to use for small devices/sensors

  25. #25
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    What's the difference between SN65HVD230 CAN Bus Transceiver and PIC18F26Q84-I/SP? Is this a controller that I attached between the Teensy 4.1 and the SN65HVD230 CAN Bus Transceiver to enable CAN FD?

Posting Permissions

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