Go Down

Topic: Why isn't my circuit reading outputted MIDI signals? (LED triggered by MIDI) (Read 609 times) previous topic - next topic

Pure1108

Hi all - total noob here.

For around 6 months now I've been slowly working on my project to ultimately control LED lights via my digital piano keyboard.

My code was provided by a highly rated seller on Fiverr that specializes in Arduino projects, and initially the code did not work.

They then very kindly provided me with two basic scripts to locate the error: an LED test, which was successful, and a MIDI test, which failed.

The MIDI test consisted of a buzzer being added to Pin 10 on the breadboard, which should trigger when a MIDI signal is received, but after connecting the MIDI OUT port of my digital keyboard to a MIDI jack (5-pin din) on the breadboard, it did not sound upon key press.

Code:
Code: [Select]
#include <MIDI.h>
#include "noteList.h"
#include "pitches.h"

MIDI_CREATE_DEFAULT_INSTANCE();

#ifdef ARDUINO_SAM_DUE // Due has no tone function (yet), overriden to prevent build errors.
#define tone(...)
#define noTone(...)
#endif

// This example shows how to make a simple synth out of an Arduino, using the
// tone() function. It also outputs a gate signal for controlling external
// analog synth components (like envelopes).

static const unsigned sGatePin     = 13;
static const unsigned sAudioOutPin = 10;
static const unsigned sMaxNumNotes = 16;
MidiNoteList<sMaxNumNotes> midiNotes;

// -----------------------------------------------------------------------------

inline void handleGateChanged(bool inGateActive)
{
    digitalWrite(sGatePin, inGateActive ? HIGH : LOW);
}

inline void pulseGate()
{
    handleGateChanged(false);
    delay(1);
    handleGateChanged(true);
}

// -----------------------------------------------------------------------------

void handleNotesChanged(bool isFirstNote = false)
{
    if (midiNotes.empty())
    {
        handleGateChanged(false);
        noTone(sAudioOutPin); // Remove to keep oscillator running during envelope release.
    }
    else
    {
        // Possible playing modes:
        // Mono Low:  use midiNotes.getLow
        // Mono High: use midiNotes.getHigh
        // Mono Last: use midiNotes.getLast

        byte currentNote = 0;
        if (midiNotes.getLast(currentNote))
        {
            tone(sAudioOutPin, sNotePitches[currentNote]);

            if (isFirstNote)
            {
                handleGateChanged(true);
            }
            else
            {
                pulseGate(); // Retrigger envelopes. Remove for legato effect.
            }
        }
    }
}

// -----------------------------------------------------------------------------

void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
{
    const bool firstNote = midiNotes.empty();
    midiNotes.add(MidiNote(inNote, inVelocity));
    handleNotesChanged(firstNote);
}

void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)
{
    midiNotes.remove(inNote);
    handleNotesChanged();
}

// -----------------------------------------------------------------------------

void setup()
{
    pinMode(sGatePin,     OUTPUT);
    pinMode(sAudioOutPin, OUTPUT);
    MIDI.setHandleNoteOn(handleNoteOn);
    MIDI.setHandleNoteOff(handleNoteOff);
    MIDI.begin();
}

void loop()
{
    MIDI.read();
}


My digital piano is a Roland RD2000, which is notorious for being technically overcomplicated. I read the manual and spoke to their support team and I concluded that the keyboard has 8 'zones' which can each be set to either internal sound generator, or external sound generator.

By 'internal' they mean playing the keyboard would be triggering the piano's on-board sounds.
By 'external' they mean playing the keyboard would be triggering MIDI signals through the MIDI ports on the respective channel (i.e. if Zone 1 is set to 'external', MIDI signals would be sent through on Channel 1.

When the support advisor mentioned this, I immediately thought that this could be the root of the problem. From usage of other MIDI devices years ago, I know that the module receiving the MIDI signal often needs to also be set to Channel 1.

I'm no coder but I couldn't see anything in the MIDI test code that referred to a specific channel, so I'm wondering if this is something that needs to be specified? It would explain why the MIDI signals are not being read and may possibly be the final solution to complete my project.

I am honestly praying that this is a plausible explanation, because otherwise, I am at a loss as to why this is not functioning correctly.

I would be beyond grateful for any insight on this, please..!

slipstick

I think the default is channel 1 but if you change the MIDI.begin() to MIDI.begin(MIDI_CHANNEL_OMNI) it will listen on all channels.

But what MIDI input circuit are you using? Please provide a circuit diagram showing what is connected where.

Also what Arduino? Tone doesn't work on everything.

Steve


Pure1108

I think the default is channel 1 but if you change the MIDI.begin() to MIDI.begin(MIDI_CHANNEL_OMNI) it will listen on all channels.

But what MIDI input circuit are you using? Please provide a circuit diagram showing what is connected where.

Also what Arduino? Tone doesn't work on everything.

Steve


Hi Steve, thanks very much for your reply.

Apologies, it's an Arduino UNO that I'm using. Please see the below schematic:

This is a schematic for the final project with the LEDs, but I was told I could keep it the same for the MIDI test, simply adding a buzzer to pin 10 (positive) and the ground rail (negative).


slipstick

That's not a schematic and my eyesight isn't good enough to see details in that picture but at least you seem to have an optoisolator and I'll trust the resistors are the right values.

Have you tried it with MIDI_CHANNEL_OMNI? What does it do, if anything? Have you tried your keyboard with anything else so you're confident it actually is transmitting MIDI?

Steve

Pure1108

That's not a schematic and my eyesight isn't good enough to see details in that picture but at least you seem to have an optoisolator and I'll trust the resistors are the right values.

Have you tried it with MIDI_CHANNEL_OMNI? What does it do, if anything? Have you tried your keyboard with anything else so you're confident it actually is transmitting MIDI?

Steve
Thanks Steve, I've tried this and unfortunately getting the same result of nothing happening -

I did consider checking that the keyboard was transmitting MIDI - I had a look online for something cheap  that could test MIDI signals but I didn't have any luck, is there anything you could recommend?

slipstick

If you have a simple MIDI to USB cable like https://www.ebay.co.uk/i/293124822386 then there are loads of PC programs that will tell you what is being sent. I normally use an old program called MIDIOX from http://www.midiox.com/ but there are many others.

Otherwise try this really simple program. It should just switch the onboard pin 13 LED on when you hold any key down and switch it off when you release the key. If that doesn't work either your wiring is wrong or the keyboard isn't sending any MIDI NoteOn/Off commands.
Code: [Select]

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

// -----------------------------------------------------------------------------

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
  digitalWrite(13, HIGH);  // switch LED on
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
  digitalWrite(13, LOW);  // switch LED off
}

// -----------------------------------------------------------------------------

void setup()
{
  MIDI.setHandleNoteOn(handleNoteOn);  // Put only the name of the function

  MIDI.setHandleNoteOff(handleNoteOff);

  // Initiate MIDI communications, listen to all channels
  MIDI.begin(MIDI_CHANNEL_OMNI);
}

void loop()
{
    MIDI.read();
}


Steve


Pure1108

Thanks Steve, I'll give these a go and see how I get on - thanks so much for your help honestly

MarkT

Some versions of that circuit pull pin 7 of the optoisolator to ground with 4k7 or so, increasing the
speed.

See the schematic here: https://www.notesandvolts.com/2015/02/midi-and-arduino-build-midi-input.html

Quote
I did consider checking that the keyboard was transmitting MIDI - I had a look online for something cheap  that could test MIDI signals but I didn't have any luck, is there anything you could recommend?
Use a 220 ohm resistor and a red LED on the MIDI out to see if there is activity.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up