Ableton Live 連線 Arduino 教程
你有沒有想過,用 Arduino 做一個簡單的 MIDI controller,控制 Ableton Live 中的引數?
如果想實現兩者的連線,以前的解決方案比較複雜,需要基於 Max/MSP,用Maxuino 實現,還需要在 Arduino 上安裝對應的韌體。
有沒有更簡單的方法呢?
Connection Kit
好訊息是,Ableton 已經提供了官方的Connection Kit,其中包含了與流行的外接裝置的連線工具如 Arduino、OSC、LEGO Mindstorms 等。

image
介紹視訊真是帥炸了~
<iframe frameborder="0" src="https://v.qq.com/txp/iframe/player.html?vid=h0190wbyt6w" allowFullScreen="true"></iframe>
Max for Live Connection Kit_騰訊視訊
如果你已經購買了 Ableton Live 10 Suit,可以在 官網直接下載這個 Pack 。如果不能直接下載,這個 Pack 的原始檔也可以在 github 找到: Ableton/m4l-connection-kit: Max for Live Connection Kit 。下載後,將資料夾複製到 Documents-Ableton-Third-Party Packs。開啟軟體後,就可以在左側找到 Arduino.amxd:

image
初始化
開始連線之前,讓我們看看 使用說明 。
The Arduino Max4Live device connects an Arduino Uno to Live using its serial port via USB and allows access to its analog inputs as well as its digital GPIOs. The device enables you to receive sensor data like switches, potentiometers or light-dependent resistors as well as sending Live parameter values to LEDs or servo motors. So far you may only connect sensors and other periphals to it directly as we do not yet support I2Cs and other periphals via the Serial Periphal Interface (SPI).
目前應該只支援 Uno 板,由 USB 串列埠連線。
因為 Max4Live 需要特定的韌體支援,所以我們先上傳程式到 Arduino 板。上傳的程式在 Arduino IDE 裡面就有:File->Examples->Firmata->StandardFirmata。開啟檔案後(至少是 2.5 版本),上傳到板子。
接著我們可以在 Ableton 裡面編輯一段 clip,雙擊 Arduino.amxd 加入到 device viewer 裡。

image
連線測試電路
回到 Arduino,接一個最簡單的電路。找一個電位計,正極接 Uno 板的 5V 口,負極接 GND,中間的訊號接 A0 模擬埠。

image
上傳以下程式,然後開啟串列埠監視器,檢視是否可以正常讀取旋鈕的值:
void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(20);// delay in between reads for stability }
成功後,關閉串列埠監視器。
Ableton Mapping
然後到 Ableton 中,選擇 port 為 usbmodemxxxx。切換到 Analog tab,點 A0 右側的 Map 按鈕,選擇已經編輯的那個 track 的 Track Volume。
做好這一步對映後,可以看到 A0 旁邊小小的藍色指示條已經開始跳動。旋轉電位計,會看到 Track 的音量產生了變化。
可是,這裡的變化不太符合我們的預期:扭動旋鈕停止後,音量還是會變化,甚至產生隨機的爆音。
這是因為電位計產生了抖動。再開啟 Arduino 串列埠監視器,可以觀察到 A0 埠接收到的不是平滑的值,而是夾雜著很多不穩定的波動值。

image
消抖處理
最簡單的辦法是在 kit 裡面設定 Smooth 的值:

image
但是這樣做,誤差會較大。我們可以進一步嘗試在程式碼裡消抖,或者在電路中加入電容消抖。可以參考這篇文章 Smooth Potentiometer Input 。
進一步的消抖還需要參考一些資料繼續研究。
- Debouncing a potentiometer
- Writing an analog pot debounce as a function
- Debounce a Potentiometer?
- arduino按鈕感測器常見的幾種消抖方法 - 簡書