"Serial + MIDI" over long distance

Ulfopulfo

Member
Hello forum! First time posting in the forum, have been playing around with Arduino and Teensy for some years. Been luring around in this forum and learned a lot.

So I have an ongoing art project using Teensys which are connected to a computer via long USB cables (he extender kind with power supply).

Each Teensy controls 4 Dotstar LEDstrips and listens to 4 contact microphones. Each LEDstrip and mic

The input of one contact microphone controls one LEDstrip, a "knock" creates a light response. Each knock also sends a MIDI NoteOn message with an individual specified pitch via usbMIDI to my computer.

In Max/MSP I'm receiving the MIDI Messages and can also control the Teensys and LEDStrips via MIDI messages. Controlling brightness, sensitivity and so on.

This is all working well with minimal latency. I started out using Serial messages, tried OSC for a while but decided to go with MIDI. Its robust and fast. The Teensys connect to my computer by themselves and that is a huge upside. No need to create 4 different serial connections and so on.

However, I would like to use even longer cables but it seems like I've reached the limit for USB cable length. up to 20 meters works fine with this brand of cables in series (15m + 5m), but longer cables (for example 15m + 15m) create problems. The midi device/Teensy does not show up on my computer.

I've been testing some USB to Ethernet adaptors and tried with both long and short ethernet cables with the same problem.

WORKS:

- I can connect a Teensy to my computer via this cable setup:
Teensy micro USB Port - Ethernet adaptor - Ethernet Cable - Ethernet adaptor - USB - Computer.
- The Teensy shows up in the Teensyduino IDE and also as a MIDI device (It is programmed as a "Serial + MIDI" type device)
- I can send MIDI CC messages to my Teensy from Max/MSP.
- I can also communicate via Serial from my Teensy to my computer.

DOES NOT WORK:

My MIDI messages get corrupted. I tried this setup with a Teensy which did not have its own power supply (gets its power through the USB port) and all the messages it sent out got corrupted and unreadable. I then tried it with a Teensy which has its own power supply and it managed to send MIDI NoteOn messages to my computer, but the wrong note messages. Somehow the messages still got corrupted. Instead of sending the specified pitches, it just sent the same series of pitches over and over, regardless of which pitch it was supposed to send.

I've been trying to find info about this kind of USB extensions, but all the info leads to using ethernet cables in order to connect to the internet. I just want to use these kinds of cables because they seem to work over longer distances, I don't need my Teensys to connect to e network.

Has anyone used Ethernet/Cat5-6 cables like this in combination with Teensys in "Serial + MIDI" mode and a computer with any luck?

Thanks you guys and sorry for long messy post. If you think it's a bad idea to go the "Ethernet Cable" route, do you have any other suggestions for long distance cables?

This is a short video showing the objects/"drops" in action. The MidiNoteOn messages from the Teensy is sent to Max/MSP and then to Ableton, triggering some samples.
https://www.instagram.com/p/CLJUkR4D141/?utm_source=ig_web_copy_link
 
Which Teensy model are you using?

Teensy 4.0 & 4.1 default to 480 Mbit/sec speed. There is a line inside usb.c you can edit to force use of only 12 Mbit/sec speed, which is usually more tolerant of long cables and their signal propagation delay.
 
I'm using Teensy 4.0.
Ah, I will try that!

BTW, Your replies in other posts have saved me from soo many headaches in the past Paul. You are a powerful and kind demigod.
 
Sadly, it didn't seem to do the trick. I uncommented the line forcing 12 Mbit/sec speed in the usb.c file (....avr/cores/teensy4/usb.c)
I can still send MIDI Messages TO the Teensy and the Teensy is sending Serial data to my Teensyduino IDE, uncorrupted.
Is there something I could/should change in the usb.c file located in the ....avr/cores/usb_midi/usb.c as well?

Thank you so much Paul!
 
You need to provide a link to this adapter you got. Nobody knows exactly what you have. I have this one:

https://www.amazon.com/Monoprice-Extender-CAT5E-Connection-150ft/dp/B003L14ZTC/

This is only good for USB 1.1. If you connect a teensy to this, it will force the teensy into full speed mode:
Screenshot 2022-05-07 003617.jpg

The above diagram shows on its left side the traffic between my PC and the adapter's USB-A male plug. On the right side it shows traffic between the USB-A female socket and a teensy 4.0 (stock firmware).

As you can see across the screen the highlighted event was bus reset. The line below the right side high light was a chirp K, produced by teensy, indicating it is high speed capable. Unfortunately you can't see this chirp K on the left side. The IC inside the adapters must not be fast enough to forward this chirp. You can see as a result teensy enters full speed mode afterwards. The far right panel shows the configuration descriptor teensy provided, which is the full speed version, with all the 64-byte packet sizes. I suspect if at anywhere in your code or teensy sample code or driver there was a 512-byte packet size assumption, there may be issues.

Inside the adapters I found 24MHz crystals and unmarked ICs. I suspect the ICs can only detect 12MHz pulses and forward on the Ethernet socket.
20220506_235139 small.jpg
 
@paul I really wish you would allow a maximal of 1920*1080 image size as most people have this resolution or higher on their monitors and could provide screen shots at this resolution, not the 2000-era 1280 pixels wide. My carefully arranged screens are downsampled into blurry images.
 
I really wish you would allow a maximal of 1920*1080 image size

For many years we've been planning to migrate this forum from vBulletin to XenForo. While we're still on vBulletin, we're keeping all the forum settings fixed. Yeah, it's an early 2000s era limit, for early 2000s era software.

So many other major developments, like Teensy 3.5/3.6, USBHost_t36, Teensy 4.0/4.1, and then a series of crises (surviving the pandemic labor shortage, then navigating the semiconductor shortages) have over and over again pushed the forum upgrade aside. Right now we have a huge software backlog, so forum upgrade definitely will be happen anytime soon.
 
@liudr, thank you for your help!
Yes, I have something similar (page in swedish, sorry):
https://www.kjell.com/se/produkter/...KogwUS2gj_ab3_DCrK8aAsuuEALw_wcB&gclsrc=aw.ds

It seems like it is also USB 1.1 with a transfer speed of 12Mb/s.
With the Teensy 4.0 connected to the computer via the adaptors and a cat6 cable The Teensy and my computer can communicate via Serial through them, and I can send MIDI messages TO the Teensy from the computer, but not from the Teensy to the computer. (Well... I can, but they get corrupted and and are unreadable)

So the issue seems to be limited to the usb.midi commands from Teensy.
Would it be possible possible to change the source code in usb_midi somehow to change the packet size or do I need to find better adaptors? A bit hard to find, maybe there are better solutions for this that I am not aware of.

I thought it could be an easy solution to my problem, the limits of USB cable length. Famous last words as always... ;)
 
So I went into the file /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy4/usb_midi.c

Changed row 79 from:
#define TX_SIZE 512
to:
#define TX_SIZE 64

And my teensy is able to send MIDI messages over cat6 cable!

I will now run cables everywhere. Twice.

Thank you everyone for your input!
 
Great! You definitely went above and beyond of merely asking for an answer. You took the information and went ahead with your own investigation, and you posted back your solution. Thanks! This was also a first clean win for me since I started to try to help others on this forum. I don't know midi but I do know some USB and @paul's code :D
According to the code, this is static and can't be dynamic depending on whether you are using that USB extender or not. In order to by dynamic, there needs to be some sort of malloc_DMAMEM() to allocate dynamic memory in that region when midi is configured. Maybe in the future.
 
For many years we've been planning to migrate this forum from vBulletin to XenForo. While we're still on vBulletin, we're keeping all the forum settings fixed. Yeah, it's an early 2000s era limit, for early 2000s era software.

So many other major developments, like Teensy 3.5/3.6, USBHost_t36, Teensy 4.0/4.1, and then a series of crises (surviving the pandemic labor shortage, then navigating the semiconductor shortages) have over and over again pushed the forum upgrade aside. Right now we have a huge software backlog, so forum upgrade definitely will be happen anytime soon.

It's a very extensive project you're developing and managing @paul and despite of my short time using teensy so far I, see an excellent project, platform, and community, so I'm just going to remind myself to grab windows instead of whole screens until the forum gets its upgrade. ;)
 
Back
Top