but it not work. anyone can help me?. sorry my english
here my code #include <USBComposite.h>
#define L PB12
class myMidi : public USBMIDI
{
void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity) {
if ((channel - 1) == 1 && note == 1) digitalWrite(L, 0);
}
void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity) {
if ((channel - 1) == 1 && note == 1) digitalWrite(L, 1);
}
};
myMidi midi;
void setup()
{
USBComposite.setProductId(0x0030);
pinMode(L, OUTPUT);
midi.begin();
delay(1000);
}
void loop()
{
midi.poll();
}
I found this old thread on Arduino forums, have you looked at it?
http://forum.arduino.cc/index.php?topic=22447.0
//loop: wait for serial data, and interpret the message
void loop () {
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// wait for as status-byte, channel 1, note on or off
if (incomingByte== 144){ // note on message starting starting
action=1;
}else if (incomingByte== 128){ // note off message starting
action=0;
https://www.google.com/search?source=hp … 2duino.com
Good luck… also, one of our members has written a MIDI lib… viewtopic.php?f=13&t=2926
Ray
Here some common advice’s for Roger’s Core:
2. If you need USB MIDI: Take the example from “examples” -> “USB Composite for STM32F1” -> “midiin” and “midiout”. Play with them and modify it for your needs. If you are using the search function, you’ll find for sure entries for the older approach for USB MIDI. USB MIDI is now part of the “USB composite” library, so you have to modify the examples. (class….)
This one is the very basic midi in example, it works out of the box with Roger’s core and Win10 & OSX:
Please set SPEAKER_PIN to any LED on your black pill. After uploading, on Win10 & OSX the black pill is recognized as “maple” MIDI device. Go into you sequencer and send a note on/off, so you should see the LED blinking. Keep in mind, using MIDI serial you’ll loose the Serial monitor in the Arduino IDE (cause by the odd MIDI baud rate of 31250 – the Arduino serial monitor cannot handle that, maybe a third party monitor would do the job)
#include <USBComposite.h>
#define SPEAKER_PIN PA0
class myMidi : public USBMIDI {
virtual void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity) {
noTone(SPEAKER_PIN);
}
virtual void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity) {
tone(SPEAKER_PIN, (midiNoteFrequency_10ths[note]+5)/10);
}
};
myMidi midi;
USBCompositeSerial CompositeSerial;
void setup() {
USBComposite.setProductId(0x0030);
pinMode(SPEAKER_PIN, OUTPUT);
midi.registerComponent();
CompositeSerial.registerComponent();
USBComposite.begin();
}
void loop() {
midi.poll();
}
[madias – Sat Oct 20, 2018 8:56 pm] –
#include <USBComposite.h>#define SPEAKER_PIN PA0
class myMidi : public USBMIDI {
virtual void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity) {
noTone(SPEAKER_PIN);
}
virtual void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity) {
tone(SPEAKER_PIN, (midiNoteFrequency_10ths[note]+5)/10);
}};
myMidi midi;
USBCompositeSerial CompositeSerial;void setup() {
USBComposite.setProductId(0x0030);
pinMode(SPEAKER_PIN, OUTPUT);
midi.registerComponent();
CompositeSerial.registerComponent();
USBComposite.begin();
}void loop() {
midi.poll();
}
There are USB host modules you can buy that you could use with the stm32f1 over SPI. But I don’t know if there is library support for MIDI over them.
[arpruss – Wed Oct 24, 2018 1:40 pm] –
You can’t receive over USB. USB traditionally comes in two types: host and device. Computers are USB hosts and things like MIDI devices, mice, cameras, etc. are USB devices. You normally cannot connect two USB devices or two USB hosts together. The stm32f1 is a USB device. To connect to your MIDI device, you need a USB host.
There are USB host modules you can buy that you could use with the stm32f1 over SPI. But I don’t know if there is library support for MIDI over them.
For clarity: if you plug your blue pill (device) into a pc (host) it should be fine to *recieve midi* data, over usb, from the computer (as well as send it to the computer)?
[pareidolialjebus – Wed Oct 24, 2018 2:07 pm] –
For clarity: if you plug your blue pill (device) into a pc (host) it should be fine to *recieve midi* data, over usb, from the computer (as well as send it to the computer)?
Yes, it should. At some point, I expect I tested the midiin example in the USBComposite library precisely for computer-to-stm connectivity. The library has evolved since, so it’s possible something broke.
Here is some discussion of USB host: http://stm32duino.com/viewtopic.php?f=9&t=4172
[madias – Wed Oct 24, 2018 3:50 pm] –
Pardon, but an admin should lock this thread, if the guy does not even give back basic informations about his project, system, whatever…
thank all for support.sorry my english and my project information.
my project : DIY USB Midi DJ Controller for Virtual DJ (Software)(i have been test success with Arduino Uno R3.
i can send / receive midi message with Virtual DJ use Uno R3 “chip atmega16u2 running base USB MIDI Device and Midi library“).
now i want receive midi message with black pill from Virtual DJ
“Example midi out message from Black Pill to Virtual DJ working”
#include <USBComposite.h>
const uint8_t notes[] = {60, 62, 64, 65, 67, 69, 71, 72, 61, 63, 66, 68, 70};
const int numNotes = sizeof(notes)/sizeof(*notes);
USBMIDI midi;
void setup() {
USBComposite.setProductId(0x0031);
midi.begin();
delay(1000);
}
void loop() {
for (int i=0;i<numNotes;i++) {
midi.sendNoteOn(0, notes[i], 127);
delay(200);
midi.sendNoteOff(0, notes[i], 127);
}
}
Check that.



