fbpx
  Friday, 10 March 2023
  4 Replies
  2K Visits
21
Votes
Undo
  Subscribe
I'm trying to program the SAM2695 and send it notes that are coming from an organ pedal using a keyboard scan modul PEDSCAN.
The module has a three pin outlet going to the classical DIN plug (2 - GND, 4 and 5 wired). When I connect this module to my MacbookPro I can monitor the codes that are coming out of the module using the PocketMIDI application. The codes coming out there are exclusively:


90 25 40
80 25 40
90 25 40
80 25 40
90 27 40
80 27 40
90 27 40
80 27 40


These come from two test buttons that are connected to the keyboard scanner and simulate the notes 37 and 39 (a D and an E), and they show a note on, note off action, with vv (velocity) constantly set to 40h. All fine.

Now I would like to pass these codes through an Arduino Nanos' SoftwareSerial Port and the codes I'm receiving are being garbled by something I cannot find out at the moment. As said, in the Midi Monitor PocketMIDI all is fine and correct.

As soon as I disconnect (I understand that connecting both, the adapter and my hardware could bend the signal to unwanted levels) and connect the following converter circuit, the trouble begins.

MIDI_to_TTL.jpg

Often the Data bytes are garbled (40 becomes FF etc.). Is the optocoupler circuit wrong?
Christoph set the type of the post as  Technical Question — 2 months ago
2 months ago
·
#17959
0
Votes
Undo
I'm not familiar enough with the hardware side of things to comment on that. But when you mentioned hex FF, that reminded me of another user who recently posted about their Arduino MIDI project sometimes producing a sequence of "-1" values.

The Arduino Serial.read() function returns a -1 value to indicate there is no data available to read. If your code isn't checking if(Serial.available() > 0) before every Serial.read() call, then Serial.read() might sometimes encounter no data available and return a -1. When -1 is converted to an unsigned byte, it will show up as hex FF.
0
Votes
Undo
The optocoupler circuit is fine.

SoftwareSerial is not reliable; it will read wrong bits when its code does not manage to get executed early enough. A hardware serial port would not have this problem.
2 months ago
·
#17969
0
Votes
Undo
@Bavi_H:
I have this read loop:

if(midiSerial.isListening())
if(midiSerial.available() > 0) {
c=midiSerial.read();
midiSerial.write(c);
snprintf(str,5,"\n%02x ",c);
Serial.print(str);
}

@Clemens Ladisch:

Thanks. I'm already in the course of changing to the on chip UART.
1 month ago
·
#18209
0
Votes
Undo
I solved the issue meanwhile. The MCU (Mega128 in the Arduino) was too slow and the software concept was too lazy.
I moved the development to a faster MCU (STM32Fxx) and implemented interrupt handling, UART ringbuffer and multitasking.
This were reading errors from the UART, as Clemens already correctly stated.
  • Page :
  • 1
There are no replies made for this post yet.