USBMIDI CONTROL CHANGE ERROR

I've been trying to make a MIDI controller for a school project, just a simple 4 button 4 knob controller but I've stumbled into some problems with the code.

I had to add the bounce and midi libraries to my project, but know I'm getting an error saying:

Arduino: 1.8.7 (Windows Store 1.8.15.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\KVON\AppData\Local\Temp\Temp2_DJTT_DIY_MIDI.ino_.zip\DJTT_DIY_MIDI\DJTT_DIY_MIDI.ino: In function 'void loop()':

DJTT_DIY_MIDI:63:15: error: 'class USBMIDI_' has no member named 'sendControlChange'

USBMIDI.sendControlChange(i, ccValue*, 3);*
I get this error for each line including "USBMIDI.sendControlChange. I've been trying to figure out how to fix this but I'm pretty stumped.
I've attached the rest of my code below, if anyone has any ideas I'd really appreciate it if you could leave a reply
Thanks Loads
```
*#include <Bounce2.h>
#include <usbmidi.h>

// define how many pots are active up to number of available analog inputs
#define analogInputs 4
// make arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// make array of cc values
int ccValue[analogInputs];
// index variable for loop
int i;

// cc values for buttons
int cc_off = 0;
int cc_on = 65;
int cc_super = 127;

// map buttons to cc for button
int cc0 = 51;
int cc1 = 52;
int cc2 = 53;
int cc3 = 54;

Bounce button0 = Bounce(0, 3);
Bounce button1 = Bounce(1, 3);
Bounce button2 = Bounce(2, 3);
Bounce button3 = Bounce(3, 3);

void setup() {
  // MIDI rate
  Serial.begin(31250);
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
}

void loop() {
  // loop trough active inputs for knobs
  for (i=0;i<analogInputs;i++){
    // read current value at i-th input
    inputAnalog[i] = analogRead(i);
    // if magnitude of difference is 8 or more...
    if (abs(inputAnalog[i] - iAlag[i]) > 7){
      // calc the CC value based on the raw value
      ccValue[i] = inputAnalog[i]/8;
      // send the MIDI
      USBMIDI.sendControlChange(i, ccValue[i], 3);
      // set raw reading to lagged array for next comparison
      iAlag[i] = inputAnalog[i];

}
  delay(5); // limits MIDI messages to reasonable number
  }
 
  // Push Button code
  button0.update();
  button1.update();
  button2.update();
  button3.update();

if (button0.fallingEdge())
  {
    USBMIDI.sendControlChange(cc0, cc_on, 3);
  }
  if (button1.fallingEdge())
  {
    USBMIDI.sendControlChange(cc1, cc_on, 3);
  }
  if (button2.fallingEdge())
  {
    USBMIDI.sendControlChange(cc2, cc_on, 3);
  }
  if (button3.fallingEdge())
  {
    USBMIDI.sendControlChange(cc3, cc_on, 3);
  }

if (button0.risingEdge())
  {
    USBMIDI.sendControlChange(cc0, cc_off, 3);
  }
  if (button1.risingEdge())
  {
    USBMIDI.sendControlChange(cc1, cc_off, 3);
  }
  if (button2.risingEdge())
  {
    USBMIDI.sendControlChange(cc2, cc_off, 3);
  }
  if (button3.risingEdge())
  {
  USBMIDI.sendControlChange(cc3, cc_off, 3);
  }
 
}*
```

Post a link to where you got the usbmidi library from. Please use the chain links icon on the toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

I downloaded the MIDI library from here GitHub - BlokasLabs/USBMIDI: USB MIDI library for Arduino.

I just unzipped the file and dragged the folder into the libraries folder, was i supposed to do it another way?

That's the problem with getting ready made projects from the web. (src)

I have a feeling that you are trying to use this usb midi library. (which is the wrong one to use!)
If you have a look at this example in his repository you will notice that he has written additional code to send CCs and Notes. Those are not included in the library itself.

If you look at the Article from djtechtools, this project is for a Teensy. I have a feeling that the Teensy library has the midiusb functionality that you're missing

Which means, that you're either going to have to write your own code for the methods, or try to adapt the Teensy library to run on the Arduino.

Alright, so do you think if i were to use that second example and changed the button pin count to 4 would that work for my project?

Should be okay.

You will have to ensure that your hardware reflects the changes you make to the code (and vice versa)

alright thanks so much for the help, I'll post back on here weather or not it works!

I used the code from the example that you linked and moved the src folder with the libraries into the libraries folder as well, it came up with this error.

I feel like I'm getting closer but not sure what this is from.

In file included from C:\Users\KVON\Documents\Arduino\libraries\src\usbmidi_vusb.cpp:20:0:

C:\Users\KVON\Documents\Arduino\libraries\src\usbdrv.h:21:35: fatal error: ../vusb/usbdrv/usbdrv.h: No such file or directory

compilation terminated.

Using library src in folder: C:\Users\KVON\Documents\Arduino\libraries\src (legacy)
exit status 1
Error compiling for board Arduino/Genuino Uno.

Here is the new code

#include <midi_serialization.h>
#include <usbmidi.h>

// See midictrl.png in the example folder for the wiring diagram,
// as well as README.md.

void sendCC(uint8_t channel, uint8_t control, uint8_t value) {
 USBMIDI.write(0xB0 | (channel & 0xf));
 USBMIDI.write(control & 0x7f);
 USBMIDI.write(value & 0x7f);
}

void sendNote(uint8_t channel, uint8_t note, uint8_t velocity) {
 USBMIDI.write((velocity != 0 ? 0x90 : 0x80) | (channel & 0xf));
 USBMIDI.write(note & 0x7f);
 USBMIDI.write(velocity &0x7f);
}

const int ANALOG_PIN_COUNT = 4;
const int BUTTON_PIN_COUNT = 4;

// Change the order of the pins to change the ctrl or note order.
int analogPins[ANALOG_PIN_COUNT] = { A3, A2, A1, A0 };
int buttonPins[BUTTON_PIN_COUNT] = { 9, 8 };

int ccValues[ANALOG_PIN_COUNT];
int buttonDown[BUTTON_PIN_COUNT];

int readCC(int pin) {
 // Convert from 10bit value to 7bit.
 return analogRead(pin) >> 3;
}

int isButtonDown(int pin) {
 return digitalRead(pin) == 0;
}

void setup() {
 // Initialize initial values.
 for (int i=0; i<ANALOG_PIN_COUNT; ++i) {
 pinMode(analogPins[i], INPUT);
 ccValues[i] = readCC(analogPins[i]);
 }

 for (int i=0; i<BUTTON_PIN_COUNT; ++i) {
 pinMode(buttonPins[i], INPUT);
 digitalWrite(buttonPins[i], HIGH);
 buttonDown[i] = isButtonDown(buttonPins[i]);
 }
}

void loop() {
 while (USBMIDI.available()) {
 // We must read entire available data, so in case we receive incoming
 // MIDI data, the host wouldn't get stuck.
 u8 b = USBMIDI.read();
 }

 for (int i=0; i<ANALOG_PIN_COUNT; ++i) {
 int value = readCC(analogPins[i]);

 // Send CC only if th has changed.
 if (ccValues[i] != value) {
 sendCC(0, i, value);
 ccValues[i] = value;
 }
 }

 for (int i=0; i<BUTTON_PIN_COUNT; ++i) {
 int down = isButtonDown(buttonPins[i]);

 if (down != buttonDown[i]) {
 sendNote(0, 64 + i, down ? 127 : 0);
 buttonDown[i] = down;
 }
 }

 // Flush the output.
 USBMIDI.flush();
}

If you installed the library correctly, then vusb.h should be there.

You should also take the time to read the description on the github page, specifically the bit about supported devices

Note. The UNO is a ATmega328P device.

Using an UNO to send MIDI data via the USB port is not really viable. You would have to redefine the USB port as a HID device and that takes a lot of extra work.

More feasible is to have the UNO send out data from a couple of spare digital output pins and use softwareserial to define the port.

Have a look at This Article which sets up something close to what you're after.

You will have to create a standard MIDI Din plug and get a midi-USB interface similar to this.

The additional hardware (plug and cable) should cost around $10-$15

You will also need to download and install this library. (Remember to follow the guide I pointed you to at the top of this post)

The article gets you to connect to pin 1 of the arduino (A hardware Serial port), but it's better to use a different pin (such as pin 3)

At the top of your code, add the lines

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

In the code, when they set up the serial port

void setup() {
  Serial.begin(31250); // setup serial for MIDI
}

change that to

void setup() {
  Serial.begin(9600); //Terminal output for debugging etc
  mySerial.begin(31250); // setup serial for MIDI
}

and where they set up the actual MIDI interface:

MIDI_CREATE_INSTANCE(HardwareSerial,Serial, midiOut); // create a MIDI object

change that to

MIDI_CREATE_INSTANCE(SoftwareSerial,mySerial, midiOut); // create a MIDI object

Once you get the example that they describe working, it will be very easy to then adapt it to handle the two extra buttons and four knobs that you want, You have two examples that show you how to handle the input and the MIDI library has a lot of documentation for different types of midi events.

Well in the libraries folder there isn't a vusb.h file but there is a vusb.c file and vsub.s file.

I was hoping i could just get this project working via the usb, do you have any idea how i could get that to work?

I've attached my library folder below so you can take a look if anything is missing.

Image 1

Image 2

You installed the library incorrectly. If the library was installed correctly, the folder structure would look something like this:

Documents/Arduino/libraries
|_USBMIDI
|_examples
|_src
|_usbdrv
|_etc...

Instead, your folder structure looks like this:

Documents/Arduino/libraries
|_src
|_usbdrv

If you read the library installation instructions at the link darrob provided, you will learn how to install Arduino libraries. Any of the three installation methods may be used to install the USBMIDI library, but you should delete your previous failed attempt at installing the library first.

The usbmidi library has not been installed correctly.
I suggest that you exit the IDE, remove the src folder and follow the Libraries installation guide.

Also, did you read the supported hardware section of the github page?

Using the USB port of the UNO to send MIDI is not a trivial thing to do. It will require a lot of work.

Regarding the library not building successfully, if you have all the files on your computer as on GitHub, then you may have to update your Arduino IDE to a newer version.

To use USBMIDI with an ATmega328 based Arduino board, you actually have to hook up another USB-B port to two configured pins, with a schematic similar to the ones on V-USB page:

V-USB - A Firmware-Only USB Driver for Atmel AVR Microcontrollers (Hardware section)

Together with pin mapping, you can figure out which places to hook the USB port to. USBMIDI by default uses PD2 for D+, and PD7 for D-, so that would be Digital Pin 2 and 7 respectively. You can edit the usbconfig.h locally to remap the pins to be closer together, keep in mind that they must be on the same port letter. Changing the interrupt source used by the lib may be necessary, best is to start with default values and get something working.