HomePage RecentChanges Instrument1

Instrument One (1)

A MIDI instrument - using a PS2 Trackpad as the primary input. See Arduino for my other projects.

Status

The hardware is complete. Software is one of those things, like any artistic rendition, is never complete. However it now successfully plays MIDI scales (semitone stpes for now).

Eye Candy

Hardware

Components required:

What about the Hardware status

Software

There are many versions - here is a bash and status.

Useful Stuff

MIDI

What most people don't realise about MIDI is that it is not just a connection to an instrument but the full standard right down to the hardware. So building a MIDI device is building a device that speaks roughly RS232 Serial, only at the Baud Rate of 31250.

Programming MIDI only requires basic serial access but at an unusual port. I am using the internal UART, but I assume software serial could also be used.

PS2

I rewrote from scratch the PS2 library for accessing a keyboard without hardware interrupts and completely non-blocking. It worked, but only some times due to Keyboard output being quite fast and often 2 or 3 bytes worth for one key press. In a tight loop it worked fine but not while doing other things. I will need to go back to looking at hardware interrupt.

Unfortunately this PS2 library is blocking, which means you can't do anything else while waiting for a key press from a keyboard.

This is not an issue with a mouse - you just set the mouse into batch mode and only get data once you ask for it. In this way I can use the PS2 driver as is.

Internal Pull up

My experience with other hardware lead me to use pull up resistors on my inputs and then just pull to ground as floating proved to be just that - random high/low.

What I learnt is that Atmel chips have an internal pull up resistor, so you just need to turn that on and then you can wire your inputs to ground.

NOTE: Either way this offers no protection - so use optic isolators for long wires or unreliable inputs.

References

Source

Here is some of the source...

MIDI Control

Taken from XXX

#!C
/* ----------------------------------------------------------------------
 * MIDI - Notes on/off etc
 */

#define midiChannel 1

// Send a MIDI note-on message.  Like pressing a piano key
void noteOn(byte channel, byte note, byte velocity) {
  midiMsg( (0x90 | (channel<<4)), note, velocity);
}

// Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note) {
  midiMsg( (0x90 | (channel<<4)), note, 0);
}

// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
#ifdef DEBUG
  Serial.print("Command = ");
  Serial.print(cmd, HEX);
  Serial.print(", Data1 = ");
  Serial.print(data1, DEC);
  Serial.print(", Data2 = ");
  Serial.print(data2, DEC);
  Serial.println();
#else
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
#endif
}

Read mouse and Set Note

Use this is the main loop to read a mouse and set the note...

#!C

  /* get a reading from the mouse */
  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  mstat = mouse.read();
  mx = mouse.read();
  my = mouse.read();

  // Current values - keep within Maximums (using factors)
  if (mx != 0) {
    currentX += mx;
    if (currentX < 0) { currentX = 0; }
    if (currentX > (maxNote * factorNote)) { currentX = maxNote * factorNote; }
    currentNote = currentX / factorNote;
  }
  if (my != 0) {
    currentY += my;
    if (currentY < 0) { currentY = 0; }
    if (currentY > (maxVol * factorVol)) { currentY = maxVol * factorVol; }
    currentVol = currentY / factorVol;
  }
  
    // Turn off last note (if it has changed)
    if (currentNote != lastNote) {
      infoSet(3);  // XXX Demonstration - 3 flashes each time note change
      noteOff(midiChannel, lastNote + offsetNote);
      lastNote = currentNote;
      lastVol = currentVol;
      // Turn on new note - this may not be required if no change !
      noteOn(midiChannel, currentNote + offsetNote, currentVol + offsetVol);
    }

Software error:

Can't locate object method "endform" via package "CGI" at /data/scott.dd.com.au/wiki/modules/search.pl line 15.

For help, please send mail to the webmaster (webmaster@dd.com.au), giving this error message and the time and date of the error.