pythonarduinoserial-portmidilmms

Serial communication between python, arduino and hairless MIDI


I want to send a message from python via serial to arduino uno and then from arduino to hairless MIDI to control LMMS software. The problem is that the communication in both cases goes through port COM4. Is it somehow possible to get data from python through a different port?

Python code:

import serial

ser = serial.Serial('COM4', baudrate = 9600, timeout = 1)

def getValues(input):
    if(input == 'y'):
        ser.write(b'g')
    else:
        ser.write(b'h')


while(1):
    userInput = input('Get data point?')
    getValues(userInput)

Arduino code:

char userInput;

void setup() {
  Serial.begin(9600);
}

void loop() {
  if(Serial.available()>0){
    userInput = Serial.read();
    if(userInput == 'g'){
      Serial.write(144);
    }
    else if(userInput == 'h'){
      Serial.write(0);
    }
  }
}

Solution

  • Python and Hairless MIDI cannot communitcate with Arduino over the same COM port simultaneously.

    You would have to open and close the connection in each software alternatingly.

    I suggest you use a Python MIDI library that replaces the Hairless MIDI functionality.