Just to let you know, buffering was the problem and not the start bit and stop bit.
Setting it to low before sending each byte and hi afterwards made the MIDI signal garbage. So, it looks like the Arduino is already taking care of the necessary serial start/stop bits.
Everything works perfectly now - sending to the LCD display and MIDI out at the same time.
Ingo
-----Original Message----- From: Ingo [mailto:ingo@miamiwave.com] Sent: Monday, March 22, 2021 6:45 PM To: 'Martin Peach' Subject: RE: [PD] Sending Startbit and Stopbit with comport for MIDI with Arduino
I'll have to go through the whole chain and monitor at which point it starts getting messy.
First include the message directly in the Arduino program, then read on the Arduino serial monitor what come into the Arduino, then see if I get both right if it works.
I think I need to set up an array first that will hold he bytes coming from Pd. Pd is sending with a baud rate of 115200 while the serial midi is running at 31250 baud.
Serial.begin(115200); // send from Pd to display, MIDI and read buttons to Pd Serial1.begin(31250); // Start MIDI
Most likely something gets lost there if it's not the start and stopbits.
Thanks! Ingo
-----Original Message----- From: Martin Peach [mailto:chakekatzil@gmail.com] Sent: Monday, March 22, 2021 4:29 PM To: Ingo Subject: Re: [PD] Sending Startbit and Stopbit with comport for MIDI with Arduino
Well I'm sure the start ans stop bits are fine, if the serial connections are working at all. You can only change that in Serial.begin() anyway. Writing LOW will just send the value 0 as serial.
https://www.arduino.cc/reference/tr/language/functions/communication/s
erial/begin/ It sounds like your message parsing or buffering is messed up. If you just send 144,60, 127 through Serial1, does it work?
Martin
On Mon, Mar 22, 2021 at 11:07 AM Ingo ingo@miamiwave.com wrote:
Hi Martin,
I have been using Arduinos for years for MIDI without any issues.
Serial (USB) is connecting to Pd and Serial1 (Pin 0 and1, TX and RX) are sending and receiving MIDI at a Baud Rate of 31250. I had been able to send and receive before as long as my Arduino was doing only MIDI.
Now I am sending from Pd both LCD display text data as well as MIDI and Arduino command data for turning pins on and off, etc. There are headers (253 - 255) that change only when the message type changes (from display text to MIDI or commands). So when I send to the display I send 253 followed by the ascii numbers for the text. When I send MIDI I send 254 followed by the raw MIDI data -like [144(, [60(, [100( . When I need to switch on a pin I send 255 followed by the number that executes turning on a certain pin.
This works perfectly except for some reason a connected MIDI device or interface does not recognize the MIDI signal anymore. So I'm troubleshooting now.
The missing startbit and stopbit were one thing that I'm suspecting. Amother thing is that Pd sends much faster to the Arduino than the MIDI Baud rate - so I'll have to create an array inside of the Arduino for reading the complete data. To slow this down for testing I
used [drip 1].
I tried to add the startbit and stopbit like this in the Arduino sketch but without any success. The " tempSerialMidiInValue1" is coming in over USB (Baud Rate 115200) from Pd. Receiving MIDI data from Pd is activated at this point.
if ((tempSerialMidiInValue1 >= 0) && (tempSerialMidiInValue1 <
253)) {
Serial1.write(LOW);
// MIDI Out Startbit Serial1.write(tempSerialMidiInValue1); // MIDI data byte Serial1.write(HIGH); // MIDI Out Stopbit tempSerialMidiInValue1 = -1; }
Unfortunately the MIDI interface does not signal that it got a message. While reading from the serial (RX pin) MIDI input on the Arduino has no problem sending the received MIDI input data directly to the output like
this:
if (Serial1.available() > 0) { tempSerialMidiInValue1 = Serial1.read(); } if ((tempSerialMidiInValue1 >= 0) && (tempSerialMidiInValue1 <
253))
{
Serial.write(tempSerialMidiInValue1); Serial1.write(tempSerialMidiInValue1);
// MIDI Thru tempSerialMidiInValue1 = -1; }
However, seinding a note on with [144(, [60(, [100( and forwarding it to Serial1.write is not being recognized.
Whether this has anything to do with the startbit and stopbit required by the MIDI format is just a guess . . .
Ingo
-----Original Message----- From: Martin Peach [mailto:chakekatzil@gmail.com] Sent: Monday, March 22, 2021 3:16 PM To: Ingo Cc: Pd-List Subject: Re: [PD] Sending Startbit and Stopbit with comport for MIDI with Arduino
Hi Ingo, It's not clear to me which parts of your setup are hardware MIDI and which are hardware serial, so this may be not relevant: MIDI uses the same serial protocol as regular serial, the difference is the baud rate (31250 is not a standard baud rate) At the hardware level, MIDI is optoisolated and works as a current loop. At the Pd end, MIDI messages are handled completely separately from whatever [comport] is doing, so you have to 'manually' reconstruct MIDI from a serial stream (as with [midifile], which also doesn't integrate with Pd's MIDI sytsem, as MIDI is being handled at the driver level, and uses a different software interface).
So if your baud rate on the Arduino is 31250, at the minimum you need [comport] to be running at 31250 s well, which is not usually
possible.
It's easier to use a MIDI interface on the computer and send MIDI from the arduino directly. This can be done using 2 220 Ohm resistors and a DIN-5 connector.
Martin
On Mon, Mar 22, 2021 at 4:13 AM Ingo ingo@miamiwave.com wrote:
Hi,
I would like to send MIDI with [comport] from Pd by using an Arduino.
Reading into Pd is no problem. It also works fine as a MIDI Thru by simply forwarding the Serial1 RX input (MIDI input) to the Serial1 TX output (MIDI Thru). Something like this:
if (Serial1.available() > 0) { Serial1.write(Serial1.read()); }
(The loop duration is only about 250 ? so there is no timing problem in this case. For data coming in faster than the loop duration I would probably have to read into an arry first.)
However, if I'm sending a MIDI message from Pd it's not recognized by the connected MIDI interface. I'm assuming that's probably because there is no startbit and stopbit that the MIDI interface is looking for.
According to the helpfile I can send a stopbit with [comport] but I didn't find anything about a startbit.
Is there a possibility within Pd and [comport] to send a startbit or would it make more sense to add the startbit and stopbit within the Arduino programming?
Thanks! Ingo
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list