login

online now

We have 96 guests and no members online

search

 
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: GinSing works, MIDI works, GinSing + MIDI does not

GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #232

So I setup the MIDI library from the Arduino playground, and also the GinSing library. I was able to receive/interpret MIDI notes in one sketch. In a DIFFERENT sketch, I was able to get GinSing to play nice with my Arduino and make noises.

When I tried to combine the two, however, something strange happened.

I hooked up the MIDI to the MIDI breakout I made, and played notes through it. Sure enough, the little GinSing LED lit up when the note was supposed to be on, and went out when the note was supposed to be off.

HOWEVER, when I actually connected the unit to speakers, no noise came out! What's more, the GinSing LED stopped turning on and off (it just always stays off).

Now, if I unplug the audio cable from the GinSing, once again it appears (from the LED indicator) to work. But as soon as I plug it in—no sound!

p.s. yes I realize the jumpers need to be set for the configuration I have; they are set—getting the GinSing to work isn't the problem, getting it to play nice is

Here is my code:

#include <MIDI.h>
#include <GinSing.h>

/********************************* MIDI DEFINES ************************************************/
#define COMPILE_MIDI_IN 1 // Set this setting to 1 to use the MIDI input.
#define COMPILE_MIDI_OUT 0 // Set this setting to 1 to use the MIDI output.
#define COMPILE_MIDI_THRU 0 // Set this setting to 1 to use the MIDI Soft Thru feature

/********************************** GINSING DEFINES *******************************************/
#define rcvPin 12 // this is the pin used for receiving ( can be either 4 or 12 )
#define sndPin 11 // this is the pin used for transmitting ( can be either 3 or 11 )
#define ovfPin 10 // this is the pin used for overflow control ( can be either 2 or 10 )

GinSing GS; // create the class library from which all methods and data are accessed
GinSingSynth *my_synth; // our global pointer to the synth mode interface ( set up after initialization )

// This function will be automatically called when a NoteOn is received.
// It must be a void-returning function with the correct parameters,
// see documentation here:
// arduinomidilib.sourceforge.net/class_m_i_d_i___class.html

void HandleNoteOn(byte channel, byte pitch, byte velocity) {
if ((pitch > 20) && (pitch < 106)){ // within the A0 - A7 MIDI boundry

// Do whatever you want when you receive a Note On.
// if (velocity == 0) {} // was supposed to turn the note off

my_synth->selectBank (BANK_A);
my_synth->setNote( OSC_1, (GSNote)pitch );
my_synth->trigger( OSC_1 );

my_synth->selectBank (BANK_B);
my_synth->setNote( OSC_2, (GSNote)pitch );
my_synth->trigger( OSC_2 );

// Try to keep your callbacks short (no delays ect) as the contrary would slow down the loop()
// and have a bad impact on real-time performance.

} // end if pitch
} // end HandleNoteOn

void HandleNoteOff(byte channel, byte pitch, byte velocity) {

my_synth->selectBank (BANK_A);
my_synth->release( OSC_1 );
my_synth->selectBank (BANK_B);
my_synth->release( OSC_2 );

} // end HandleNoteOff

void setup() {

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

// Connect the HandleNoteOn function to the library, so it is called upon reception of a NoteOn.
MIDI.setHandleNoteOn(HandleNoteOn); // Put only the name of the function
MIDI.setHandleNoteOff(HandleNoteOff);

/***************************************** GINSING SETUP ************************/

GS.begin ( rcvPin , sndPin , ovfPin ); // start the device (required)

my_synth = GS.getSynth(); // get the synth mode interface
my_synth->begin (); // enter synth mode

// SETUP NOISEMAKING OSCs ON BANK A

my_synth->selectBank (BANK_A);
my_synth->setWaveform ( OSC_1, SINE );
my_synth->setPatch ( OSC_1_TO_MIXER );

my_synth->selectBank (BANK_B);
my_synth->setWaveform ( OSC_2, RAMP );
my_synth->setPatch ( OSC_2_TO_MIXER );

// GS.end(); // commented out because THE FUN NEVER ENDS

}


void loop() {
// Call MIDI.read the fastest you can for real-time performance.
MIDI.read();

// There is no need to check if there are messages incoming if they are bound to a Callback function.
}
Last Edit: 5 years 2 months ago by administrator.
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #233

I just reloaded the Arduino with some earlier, MIDI-free GinSing code. I kept the MIDI breakout (which I based of the schematic of the SparkFun breakout) hooked up, just to see if that might be the issue.

WITHOUT MIDI code (but still hooked up to the physical breakout) the GinSing still works, so I know that nothing got fried/hosed on the GinSing board; it still works like it did when I first got it a few days ago (it was a present).

I also sent some MIDI notes to the unit while it was playing, to make sure the MIDI in wasn't somehow interfering; it isn't—everything still works.

I can only assume the problem is somewhere in the code...
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #234

Okay, so I reassigned the jumpers back to pins 2, 3, and 4 (both in my code and physically).

NOW the whole thing won't even receive MIDI notes at all—the little "Note On" LED won't light up, regardless if there is anything plugged into the audio jack or not...

The odd thing is, the only real pin the MIDI uses (aside from Ground and 5V) is Digital 0—the RX "Serial In" pin.

Is the GinSing serialization somehow getting hosed by the MIDI serialization? I wouldn't know how that could happen, since everything is on separate pins?

Once again, though, the example sketches for GinSing (free of MIDI code, of course) work just fine, and the GinSing board behaves as it did when I first got it...
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #235

Okay the GinSing and the MIDI are definitely interfering with each other.

I loaded my GinSing-free, MIDI-only code; all the code does is light up the Arduino's PIN13 LED when a note comes in, and turns off the LED when the note off comes in.

With the GinSing shield loaded and the original jumper positions set (i.e. 2, 3, and 4) the MIDI code failed to trigger the LED.

Once I removed the GinSing shield, everything worked great. :(

I assume this means I'll have to move the jumpers back to their alternate settings (10, 11, and 12). But even then, the original problem remains—the whole thing mysteriously stops working when I plug in my audio jack.

For what it's worth, my audio jack just goes to the audio in on my computer; I have had no problems with hearing through it while the GinSing was playing in demo mode, etc.
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #236

Thanks for the detailed diagnosis.

It sounds like the two libraries are probably interacting in a way that is not obvious. My suspicion is that the MIDI library and GinSing both use the SoftSerial library, and it is the use of the receive interrupt that is getting reallocated depending on who sets up the interrupt last. You may have confirmed this by switching the jumpers on the GinSing board to see they can be in direct conflict if they share the same serial connection. I would not suspect the audio output would have any effect as the output stage of the GinSing board is active in both cases; the GinSing will send audio output to the amplifier regardless of software configuration.

When the jumpers are configured so that GinSing uses the non-MIDI pins, you should be able to send to both boards without problems, but when data is received via MIDI it could be that the GinSing board interrupt is reading the incoming MIDI data and causing neither board to work properly.

As a simple test, try moving the GinSing initialization code before the MIDI initialization code to ensure that the MIDI handling gets its callbacks set up; this should not effect GinSing as long as you don't attempt to read any data coming from it. If that does not work, you could also try disabling the GinSing read completely by removing the receive jumper ( 4 | 12 ) to physically disconnect anything coming back from the GinSing board. In general you would never need to read any data from the GinSing board unless you are using it via the PC link ( i.e. tweaker program ).

Please let me know if this helps - it would be useful for others who might also be using a MIDI shield along with GinSing.
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #238

I moved the GinSing code in setup() so that the MIDI code (and its callback initializers) are the very last things called/done in setup(). I also removed the 4|12 jumper entirely from the physical GinSing board.

In addition, I edited the MIDI.h file to ENSURE that its outputting code was skipped (i.e., the MIDI code can only receive notes, it does not know how to send them out).

Still no dice.

Here's the weird thing:

If you run MIDI notes to the Arduino+GinSing, and leave the audio cable UNPLUGGED (i.e., nothing plugged into the GinSing jack), then the LED indicates that something is turning on and off when it should.

IF you plug in to the audio jack while a note is supposedly being played, noise WILL come out. MIDI commands to change the note, turn off the note, etc. WILL NOT WORK... until you unplug the cable from audio jack.

I thought this might be some weird grounding issue or something, so I switched the Arduino+Ginsing to battery power. The strange "audio cable disables MIDI" behavior remained, though.

************** UPDATE **************

I tried hooking up the GinSing audiojack to some earbuds (don't worry, I didn't put them in my ears).

The earbuds DO NOT INTERFERE, though they made it plain that when the GinSing "plays" a "note" it just actually makes some random noise—it does not make distinct notes. I.E., it makes random noise through the earbuds when turned on by Arduino, and then stops making random noise when turned off.

Again, loading GinSing-only sketches (even with MIDI-breakout *hardware* still in place) works as it should—distinct/correct notes are played as directed by the Arduino sketch. It's only when I add MIDI code that things stop behaving nicely.

I have a programming/engineering type friend who has some experience with embedded systems looking at the MIDI library; I'll post an update should I manage to get anything working.

************************************
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #239

Well that's certainly a bizarre outcome. It looks like your diagnostic tests indicate that both boards are till functioning correctly, but I am surprised that what you hear is garbage when a note is properly triggered. It would appear from this that the GinSing board is getting the right serial commands.

Could you try calling the note callbacks explicitly in a test loop with the a specific known note value without the midi code? That would at least confirm that the sound generation works with the data you are expecting. the you could try adding the midi lib ( without midi cable plugged in ) to confirm or deny an electrical issue.
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #240

I did what you suggested: I included all the libraries (MIDI and GinSing), but in the loop() I replaced MIDI.read() with explicit calls to the NoteOn and NoteOff routines (with a 1 second delay after each so I can tell what's going on).

Instead of trying to parse-n-pass a MIDI "note," I hard-coded the notes given to the GinSing (I did this last night, actually, and just kept the code the same).

It works! It plays the note(s) it should; when recompiled with different note values, it plays those properly.

So the culprit does seem to be somewhere in the MIDI library's interaction with everything.

Here are snippets from the altered code

void HandleNoteOn(byte channel, byte pitch, byte velocity) {

my_synth->selectBank (BANK_A);
my_synth->setNote( OSC_1, C_5 );
my_synth->trigger( OSC_1 );

my_synth->selectBank (BANK_B);
my_synth->setNote( OSC_2, E_5 );
my_synth->trigger( OSC_2 );

} // end HandleNoteOn


void loop() {

HandleNoteOn(0,0,0);
delay(1000);
HandleNoteOff(0,0,0);
delay(1000);

}
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #241

Did you by chance test the same code using MIDI receive, but not using the actual note assignment that is passed? The reason I ask is that it might be possible that you are using invalid notes, which is the only other thing I can think of that might cause the GinSing to process on/offs but produce noise. The actual note values that are allowed are:
enum GSNote
{
	C_0 =  0 ,  CS_0 =  1 , D_0 =  2 , DS_0 =  3 , E_0 =  4 , F_0 =  5 , FS_0 =  6 , G_0 =  7 , GS_0 =  8 , A_0 =  9 , AS_0 = 10 , B_0 = 11 ,
	C_1 = 16 ,  CS_1 = 17 , D_1 = 18 , DS_1 = 19 , E_1 = 20 , F_1 = 21 , FS_1 = 22 , G_1 = 23 , GS_1 = 24 , A_1 = 25 , AS_1 = 26 , B_1 = 27 ,
	C_2 = 32 ,  CS_2 = 33 , D_2 = 34 , DS_2 = 35 , E_2 = 36 , F_2 = 37 , FS_2 = 38 , G_2 = 39 , GS_2 = 40 , A_2 = 41 , AS_2 = 42 , B_2 = 43 ,
	C_3 = 48 ,  CS_3 = 49 , D_3 = 50 , DS_3 = 51 , E_3 = 52 , F_3 = 53 , FS_3 = 54 , G_3 = 55 , GS_3 = 56 , A_3 = 57 , AS_3 = 58 , B_3 = 59 ,
	C_4 = 64 ,  CS_4 = 65 , D_4 = 66 , DS_4 = 67 , E_4 = 68 , F_4 = 69 , FS_4 = 70 , G_4 = 71 , GS_4 = 72 , A_4 = 73 , AS_4 = 74 , B_4 = 75 ,
	C_5 = 80 ,  CS_5 = 81 , D_5 = 82 , DS_5 = 83 , E_5 = 84 , F_5 = 85 , FS_5 = 86 , G_5 = 87 , GS_5 = 88 , A_5 = 89 , AS_5 = 90 , B_5 = 91 ,
	C_6 = 96 ,  CS_6 = 97 , D_6 = 98 , DS_6 = 99 , E_6 =100 , F_6 =101 , FS_6 =102 , G_6 =103 , GS_6 =104 , A_6 =105 , AS_6 =106 , B_6 =107 ,
	C_7 =112 ,  CS_7 =113 , D_7 =114 , DS_7 =115 , E_7 =116 , F_7 =117 , FS_7 =118 , G_7 =119 , GS_7 =120 , A_7 =121 , AS_7 =122 , B_7 =123 ,
};

So passing a note value of 60, for example would be invalid...
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #242

I think you may be right; in my testing I originally just played C5 (which would be 60). However, in the past day or so I've been running everything with hard-coded GinSing-specific GSNotes; of course, GinSing has been playing those notes.

So the weird "noise" that GinSing was making could indeed be operator error.

That still doesn't explain why MIDI.read() hoses everything, even when the GSNotes are hard-coded with valid values. But of course, the MIDI library issue isn't really a problem with GinSing, so much as it's a problem with the MIDI library.

I'll be sure to update here if I find a solution to the MIDI library issue...
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #243

Thanks for digging into this. I would still suspect there is some kind of issue with interrupts going on. I would be interested to know if the MIDI library is using SoftSerial; that would go a long way to finding out how to make them work together, albeit through minor code changes to the GinSing library.
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #245

I did a little reading through the libraries; MIDI uses the HardwareSerial.h library. But, I am now beginning to suspect a grounding problem. There are two reasons:

Tonight, MIDI mysteriously stopped working, even w/out the GinSing shield hooked in! After freaking out a bit, I thought "what is different?" I had just moved my computer (long story), and instead of plugging both the USB-MIDI cable and the Arduino USB cable into the same powered hub, the USB-MIDI cable was hooked directly into my computer, while the Arduino USB cable remained hooked to the hub.

So, after uploading the MIDI test sketch, I moved the Arduino's power to battery...

...and MIDI started working again!

So I tried my MIDI+GinSing code again...same problem—MIDI gets hosed when I plug in the audio cable that goes to my computer's line in. However, when I plugged in my earbuds (which are, of course, NOT connected to my computer or anything)—it worked!

To verify this behavior, I modified the code a bit; I have been using hard-coded GSNote values, instead of trying to read/parse the incoming MIDI notes. I kept that strategy, but put in a toggle variable to switch between GSNote values for every time that the NoteOn function was called. All of this was running the Arduino off battery...and it worked as it should.

I don't know WHAT to think at this point. Part of me suspects that I've been mucking around in libraries needlessly, that it's a hardware issue.

Furthermore, I have a little secret—I'm using the OSEPP "Arduino compatible" Uno R3, not the official "Arduino" Uno R3. I won't go so far as to blame OSEPP at this point, but it really seems like this isn't a library issue, but a hardware one.

So to recap, with GSNote values hard coded, the OSEPP UNO running off battery, and the "audio in" connection being isolated earbuds, EVERYTHING WORKS!

I have never been so frustrated that something works before. :\

p.s. I just emailed OSEPP; maybe they have some insight as to why switching grounds/power sources "fixes" the problem...
Last Edit: 5 years 3 months ago by midiluv. Reason: Added a p.s.
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #246

Hi all,

I've been refactoring the library lately to include Software Serial support. The code is in beta at the moment, I have to run some more tests before publishing it.

You can access the sources here (I moved from SourceForge to GitHub a while ago).

If you have specific code you'd like to be added to the library for the GinSing, I'd be glad to include the modifications. (And if you have a macro definition to detect a GinSing build as well, that would be wonderful! )
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #248

I think you have already done this test, but if you just use the GinSing board connected to your PC speakers, it works correctly, right? This at least would eliminate the possibility of a ground loop between the GinSing shield and the PC. A further test would be to run off battery under the same connections and code. If both of these work OK, I would consider the GinSing board in the clear.

I took a quick look at the schematics between the OSEPP and Arduino boards, and there is a slight circuit difference w/r to the USB. It may not be significant, but you can see the difference when comparing them.

File Attachment:

File Name: Arduino_Uno_Rev3-schematic.pdf
File Size: 81 KB


File Attachment:

File Name: OSEPP_Uno_Arduino_Compatible-Rev1.1-Schematic.pdf
File Size: 30 KB


I am not sure if it is the case with your MIDI board, but most use an opto-isoloator that should eliminate ground loops between the MIDI connection and the board. It might be worth a look to see if this is actually the case on your board.
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #249

I loaded a GinSing test sketch and played it—even with the MIDI hardware in place, the GinSing operates without any problems when connected to my computer's line-in.

As for the MIDI breakout hardware; I based it off the MIDI-in section of the SparkFun breakout; I am indeed using an opto-isolator.

www.sparkfun.com/datasheets/BreakoutBoar...IDI_Breakout-v11.pdf
Last Edit: 5 years 3 months ago by midiluv. Reason: Clarification
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #250

I thought about your comment about my own hardware. While I thought my MIDI breakout was OK, I had enough parts to make a new one. The new one works, even plugged into my computer's line-in.

Boy is my face red. I'm still not sure why the original one is causing all of these problems—they should be the same circuit. But I guess, I'm just thankful that things are working how they should.

Thank you everyone for your help and attention; you all have been very patient and helpful with this issue. Again, I can only apologize, as it appears the problem was with my own equipment.
The administrator has disabled public write access.

Re: GinSing works, MIDI works, GinSing + MIDI does not 5 years 3 months ago #252

Apologies never needed here. I'm glad that the problem in the end was fixed with a simple hardware swap out; it was worth the effort to make sure that others going down the MIDI path know they have a solution. It should be very interesting to see how the GinSing can be used via MIDI; its been something I'd been considering working on for some time.
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 0.285 seconds