Skip to content

todd-herbert/vusb-arduino

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

V-USB Arduino port (20121206)

Allows an Arduino to act as midi device through 2nd (firmware-only) usb port.

V-USB

V-USB by Objective Development Software GmbH

http://www.obdev.at/products/vusb/index.html

Circuit

Arduino & V-USB Arduino & V-USB

Default config:

  • D- = Pin 7
  • D+ = Pin 2

You can change default values in src/usbconfig.h file. For more information please visit V-USB website.

Midi sample

#include <TFUsbMidi.h>
unsigned long ms = 0;

void setup() {
	Serial.begin(115200);
	//setup midi msg callback
	VUsbMidi.OnMsg(OnMidiMessage);
    VUsbMidi.begin(false);
}

void loop() {
	//watch for new midi messages
	VUsbMidi.refresh();
  
	//send some midi messages at every 5sec
	if (ms < millis()) {
		Serial.println("SendNoteOn");
		//NoteOn message: channel, note, velocity
		VUsbMidi.NoteOn(1, 60, 100);
		delay(200);
		//NoteOff message: channel, note
		VUsbMidi.NoteOff(1, 60);
		
		//ControlChange message: channel, ctrlid, value
		VUsbMidi.ControlChange(2, 10, 54);
		
		//Send raw message v1:
		TFMidiMessage midimsg;
		midimsg.type = TFMidiType.NoteOn;
		midimsg.channel = 1;
		midimsg.data1  = 60; //note
		midimsg.data2  = 50; //velocity
		VUsbMidi.write(midimsg);
		
		//send raw message v2
		byte buffer[4];
		buffer[0] = 0x09;
		buffer[1] = 0x90 | 1; // message type | channel
		buffer[2] = 0x7f & 60; //note
		buffer[3] = 0x7f & 50; //velocity
		VUsbMidi.write(buffer,4);
		
		ms = millis() + 5000; 
	}
}

//this function will be called on every midi message
void OnMidiMessage(TFMidiMessage msg) {
    Serial.print(msg.type);
    Serial.print("\t");
    Serial.print(msg.channel);
    Serial.print("\t");
    Serial.print(msg.data1);
    Serial.print("\t");
    Serial.println(msg.data2);
}

TFMidiUsb wrapper

Wrapper class based on:

About

Obdev's V-USB arduino port

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Assembly 46.3%
  • C 37.1%
  • PHP 10.3%
  • C++ 6.3%