【问题标题】:Serial communication between python, arduino and hairless MIDIpython、arduino和无毛MIDI之间的串行通信
【发布时间】:2019-10-20 14:45:52
【问题描述】:

我想通过串口从 python 发送一条消息到 arduino uno,然后从 arduino 到无毛 MIDI 来控制 LMMS 软件。问题是这两种情况下的通信都通过端口 COM4。是否有可能通过不同的端口从 python 获取数据?

Python 代码:

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 代码:

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);
    }
  }
}

【问题讨论】:

  • 所以您想通过 Arduino 在两个软件之间进行通信?为什么? Arduino在这里的目的是什么?
  • 带有连接传感器的 arduino 用作 MIDI 控制器。 python 代码将提供一个用户界面来打开 MIDI 控制器,它会分析歌曲的播放精度

标签: python arduino serial-port midi


【解决方案1】:

Python 和 Hairless MIDI 无法同时通过同一个 COM 端口与 Arduino 通信。

您必须在每个软件中交替打开和关闭连接。

我建议您使用 Python MIDI 库来替代 Hairless MIDI 功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    相关资源
    最近更新 更多