MIDI pitch bend/Modulation wheel

tl;dr: How to get software serial output to USB-B socket?

My digital keyboard doesn't have a pitch bend wheel, but I know it's able to do it if I send a MIDI message to it (it has a USB-B port which can both send and receive MIDI), so I decided to try to make my own simple module for it. I thought it would consist of some cheap touch screen that would send coordinates of my finger to Arduino Nano for it to count the value of pitch bend and send midi signal through a serial port using Arduino MIDI Library.
Here come the first questions.

  1. I want the output port of my device to be USB-B too. Is it possible to remove Nano's miniUSB and replace with USB-B socket like this?
    The next two questions were supposed to be a bit different, but I guess I answered them myself when tried to explain what I mean, so they are not so important.
  2. If I understand correctly, I can buy this display with Uno, see which pin goes where and connect them to corresponding Nano ports and there won't be any troubles?
  3. Also, can I supply my device from keyboard with same USB (serial) port which the data goes through?

But later I thought "What if I also want to use keyboard's MIDI input/output while also using pitch bend?" So I want my device to have two USB-B sockets (one is hardware serial and the second one is software serial somehow sending it to a new USB-B socket): once one of them gets the MIDI message the Arduino should send the same message to another one or vice versa. I think it should be possible if the program will be a loop processing pitch bend that will be interrupted with callbacks.

4.Is there some way to get the software serial's output to a USB-B port? Do I have to use some adapter (and I will also have to somehow replace it's socket with USB-B?..) Or is there a simpler way to implement what I want?

I think you are misunderstanding something fundamental here. If you have a USB-B socket this means that your USB device is a USB client, that is a slave. The A socket means that your USB device is a USB host, that is a master. You can not just change the socket to convert from client to host the whole software stack is different.

If your keyboard has a USB-B socket on it that means your keyboard is a client, therefore in order to talk to it with an Arduino you need to have something like a USB host shield.

It is not clear from your description what other devices are connected and if your keyboard can act as a sound generator. Nor is it clear if you want to connect it to a computer of some sorts.

  1. I want the output port of my device to be USB-B too. Is it possible to remove Nano's miniUSB and replace with USB-B socket like this?

Why not just get a lead?

4.Is there some way to get the software serial's output to a USB-B port? Do I have to use some adapter (and I will also have to somehow replace it's socket with USB-B?..)

Yes you have to use an adapter to make a software serial signal into a USB client, get one with the socket you want to use or just get a lead with the right ends, but remember it is, and will always be, a client.
You can not connect clients together, you can not connect hosts together, you can only connect one host to one client.

Grumpy_Mike:
I think you are misunderstanding something fundamental here.

Yes, you’re right, thanks for an explanation

Grumpy_Mike:
It is not clear from your description what other devices are connected and if your keyboard can act as a sound generator. Nor is it clear if you want to connect it to a computer of some sorts.

Yes, my keyboard can act as a sound generator.
I wanted to connect it like this: keyboard - arduino device - PC
So, if a computer tries to send a MIDI message, I don’t want it to get lost somewhere, I want my device to catch it and send to my keyboard. And when a keyboard sends a message, I want my device to send it to a computer
A picture

If I plug a host shield into an arduino, can I still use it’s first USB port? Can I connect everything like this?
Or, if I can’t, will I have to make something weird like this?

Also, will I have enough pins to plug a screen after connecting host shield?

An Arduino Nano doesn't support MIDI over USB. I'd recommend a Leonardo for example.

Pieter

If I plug a host shield into an arduino, can I still use it's first USB port?

Yes.

Also, will I have enough pins to plug a screen after connecting host shield?

It depends on the screen interface. Most likely it will be an SPI interface as I think is a host shield. The two devices can both go in the SPI bus.

If you get a Leonardo or a micro then you can go with your first configuration, although it would be much more clear if you showed the connectors rather than the messages. Does your keyboard only have a USB connector? If it had a conventional 5 pin MIDI interface it would be much easier to make as you could use a Leonardo and MIDI shield on the hardware UART and still have a USB connector to connect to your PC. No host shield needed.

PieterP:
An Arduino Nano doesn't support MIDI over USB.

Are you sure? This page says "Compatible with all Arduino boards (and clones with an AVR processor)."

Grumpy_Mike:
Does your keyboard only have a USB connector?

Yes, unfortunately

Grumpy_Mike:
it would be much more clear if you showed the connectors rather than the messages

Yes, that picture was supposed to show just the logic of what I want. That's how I think it should look now, I hope I understood what you said correctly.

slawagn:
Are you sure? This page says "Compatible with all Arduino boards (and clones with an AVR processor)."

That is a hardware MIDI library, it just needs a UART that can operate at 31250 baud.
For MIDI over USB, you need an Arduino with a native USB connection.
Read more here: MIDI over USB · tttapa/MIDI_controller Wiki · GitHub

You need two MIDI USB connections here: one between the synth and the Arduino, where the Arduino acts as a host, and the synth as a slave, and a second one between the Arduino and the computer, where the Arduino is the slave, and the computer the host.

This library claims to support MIDI over USB using a USB host shield (for the connection between the Arduino and the synth).

If you use an Arduino with native USB support (Leonardo, Micro, Zero, Due ...), you can use the MIDIUSB library for the connection between the Arduino and the computer.

Personally, I wouldn't go through the USB Host hassle, and just connect both devices (synth + Arduino as USB MIDI slave) to the computer, and then route the MIDI events from the Arduino to the synth. On Linux, I use QJackCtl for MIDI routing, but you can probably find similar tools for Windows and OSX. Maybe it's even built into your DAW.

Pieter

Sorry, maybe it's because English is not my native language, but I can't find a contradiction here. I don't understand what exactly is wrong with the scheme from my previous message. Can't I exchange data between computer and Uno through its UART with a FortySevenEffects' Arduino MIDI Library and use Felis' USB Host Shield Library (it includes the YuuichiAkagawa's USB Host MIDI driver from your message) to transfer data through Host Shield between synth and Uno?
Or did you want to say that an Arduino with a native USB support would be just easier to use?

PieterP:
Personally, I wouldn't go through the USB Host hassle, and just connect both devices to the computer, and then route the MIDI events from the Arduino to the synth.

I thought about this, but I want to make this project exactly because I want to also be able to connect only synth with arduino without a computer

You seem to contradict yourself here:

slawagn:
I thought about this, but I want to make this project exactly because I want to also be able to connect only synth with arduino without a computer

slawagn:
Yes, my keyboard can act as a sound generator.
I wanted to connect it like this: keyboard - arduino device - PC
So, if a computer tries to send a MIDI message, I don't want it to get lost somewhere, I want my device to catch it and send to my keyboard. And when a keyboard sends a message, I want my device to send it to a computer

slawagn:
Sorry, maybe it's because English is not my native language, but I can't find a contradiction here. I don't understand what exactly is wrong with the scheme from my previous message. Can't I exchange data between computer and Uno through its UART with a FortySevenEffects' Arduino MIDI Library and use Felis' USB Host Shield Library (it includes the YuuichiAkagawa's USB Host MIDI driver from your message) to transfer data through Host Shield between synth and Uno?
Or did you want to say that an Arduino with a native USB support would be just easier to use?

Of course you could use the hardware UART to send and receive MIDI, but the computer won't recognize it as a MIDI device, just as a virtual serial port, so it's useless to any audio software you have running on your computer.
You could use a USB MIDI interface, or a software tool like Hairless MIDI, but that's just really cumbersome, so why not get a suitable microcontroller in the first place.

Pieter

PieterP:
You seem to contradict yourself here

Yes, I guess it sounds weird. I wanted to say, when I started thinking about this project I didn't think about connection to a computer, the original idea was a pitch bend controller working without it. Just synth and this device. I just decided later that I sometimes may want to both use pitch bend and work with a computer, so I've come up with this

Anyway, thank you both for your help