Arduino Mini04 and midi bytes over RX fail

Hello.

My first post here :slight_smile:
For a long time wanted to do this project. Very quickly I've come to a point where help is needed.
I have ENGL guitar amp that has MIDI in and thru. All tubes amp with a digi possibilities. A footswitch communicates through in port, so one can program different presets on the amp. The thu port.. well is throu port. The idea is to take the signal from it, connect it to a DAW, so that the footswitch becomes a controller for both things.
Benefits?

  • Pushing on a footswitch synchronous triggers a stored amp setting and i.e. a drum loop in DAW.
  • Pushing on a footswitch(es) starts/stops/loops a recording of a guitar phrase you just played. Layering music.
  • 16 midi channels each containing 128 values gives possibility to create √ľberpresets that are a mix of amp ones and the presets on your MIDI device(s).
  • For instance, banks 11-14 on channel 2 can all be copies in terms of amp settings, but provide different drum, bass lines on DAW. Background tracks for practice.
  • It can even incoorporate into audiovisual performance. processing.org / openFrameworks and MIDI input ftw.

Why Arduino? The issue is that ENGL sends commands as "program change" (midi status byte 0xC0 - 0xCF). The DAW I 'm using, receives these signals, however they cannot be assigned to control the app remotely. So I needed a converter.

Converter receives from amp
2 byte package:
1st byte wrong
2nd byte ok

It has to send
2 x 3 byte package:
1)
Changed 1st byte in a certain way (A)
2nd byte that was ok
Added 3rd byte X
2)
Changed 1st byte in a certain way (B)
2nd byte that was ok
Added 3rd byte Y

I have built such converter quickly and successfully using Arduino Duemilanove (ATmega328). Works like a charm! :slight_smile:

/*
MidiVader by kroko
Code for Arduino
Tested on Z12  - InVader 100 - Arduino Duemilanove - EDIROL Firewire audio I/O - Mac OSX - Ableton Live 8
*/

#define MIDIBAUD 31250 // 31.25 kbits/sec
// #define CLOSEBAUD 28800 // for serial tty debug

#define PROGRAM 0xC0 // ENGL sends all commands as "program change"

#define NOTE_ON 0x90 // note on root
#define NOTE_OFF 0x80 // note off root

#define LEDPIN 13

unsigned char midiPacket[3] = {0,0,0};

void setup() {
  Serial.begin(MIDIBAUD);
  
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, HIGH);
}

void loop() {
  while (Serial.available() > 1) {
    midiPacket[0] = (unsigned char)Serial.read()^PROGRAM; // mask out which channel is active on footswitch
    midiPacket[1] = (unsigned char)Serial.read(); // detect which program change #
    sendMidi(midiPacket[0],midiPacket[1]); // process it
  }
}

// Formatting packet, sending it as a note on/off message (probably the most foolproof method - DAWs differ, but they all swallow on/offs)
void sendMidi(unsigned char channelNr, unsigned char note) {  
    midiPacket[0] = NOTE_ON|channelNr; // note on with channel mask
    midiPacket[1] = note; // program change # is now used as a note value
    midiPacket[2] = 127; // full volume
    Serial.write(midiPacket,3); // send note on
    midiPacket[0] = NOTE_OFF|channelNr; // note off with channel mask
    midiPacket[1] = note;
    midiPacket[2] = 0; // mute
    Serial.write(midiPacket,3); // send note off
}

And using following shematic:

The problem which I'm trying to solve the whole day:
I want to pack that all into a small blue-leded box using Arduino Mini 04.
Have programmed it with the same code as for duemilanove and connected as shown in the second diagram.
It doesn't work. Pushing on footswitch does nothing as if Mini would not receive anything.
The programming is done through duemilanove with chipset off. Have uploded different test sketches, the Mini itself works.
Checked - it sends TX serial signals, this dummy sketch works:

#define MIDIBAUD 31250 // 31.25 kbits/sec
// #define CLOSEBAUD 28800 // for serial tty debug
#define PROGRAM 0xC0 // ENGL sends all commands as "program change"
#define NOTE_ON 0x90 // note on root
#define NOTE_OFF 0x80 // note off root
#define LEDPIN 13

unsigned char midiPacket[3] = {0,0,0};

void setup() {
  Serial.begin(MIDIBAUD);

  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, HIGH);
}

void loop() {
  sendDummy();
  delay(1000);
}

void sendDummy() {  
  midiPacket[0] = NOTE_ON; // note on with channel mask
  midiPacket[1] = 60; // program change # is now used as a note value
  midiPacket[2] = 127; // full volume
  Serial.write(midiPacket,3); // send note on
  midiPacket[0] = NOTE_OFF; // note off with channel mask
  midiPacket[1] = 60;
  midiPacket[2] = 0; // mute
  Serial.write(midiPacket,3); // send note off
}

And RX physically also works. When the original sketch is running, connecting RX with +5VDC triggers some chaotic action.

What could be the problem with Mini 04 and, more significant, the solution? The code, the shematic, both? Things I could do to track down the problem?

Any help would be greatly appreciated.
Many thanks in advance,
kroko

I checked Midi Pinout again. You're right. Must have looked at this scheme on arduino midi site :). Or did You mean other "output circuits"?

As it worked on Duemilanove - took it for granted.

Now after removing GND:
On Duemilanove everything still works flawlessly.
On Mini it still doesn't. Silence.

Out of options. Trying other mini in the same setup at local resellers place to see if there's a difference? But there's no reason for this mini to be deffective - TX sends, RX receives.

Plus a new problem came around. When connecting - as shown in shematics - +7.5V to +9V on Mini, it "boots" (3 blinks), however never runs the program (led doesn't switch on as coded in setup() ). If using the same power source on Duemilanove everything is ok. Isn't the 9V connector on Mini as the VIN on Duemilanove or am I missing smth here?
When measuring:
+9VDC input to GND = 7.24V
+5VDC to GND = 4.62V
Thus internal voltage regulator works.
Tried with 9V supply (8.59V). Mini regulated it to 4.94V. Still didn't run the program.
Mini RUNS the program if supplied with regulated 5V (from the other arduino) to 5V connector.

Being able to put this so fast together on duemilanove and now... you know the feeling :slight_smile:

Just throw me an idea, I'm desperate to try everything :slight_smile:

Thanks

Despite that you have had something that works this is not the way to wire up a MIDI interface. It is a danger to your arduino and possibly your other equipment. This is the correct way to do it, guaranteed to work:-
http://www.thebox.myzen.co.uk/Hardware/MIDI_Shield.html

Thanks, I'll look into it!

Yep, it works now on mini! :slight_smile:
Changed 1N1418 -> PH4148 and BC212 -> C556B
My fault I trusted arduino midi tutorial and extra example that is linked there. Maybe You should also include link to Mike Cook's shematic - "the right way to do it" ::slight_smile:
Thank you!

Hello, I used the MIDI example that¬īs on the arduino software, but it doesn¬īt work... I don¬īt know what happen...... the code has a mistake and I correct it.... but nothing

void loop() {
// play notes from F#-0 (0x1E) to F#-5 (0x5A):
for (intnote = 0x1E; note < 0x5A; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100);
}
}

Who can help me with that...??

Thaks