Arduino MEGA สร้าง MIDI Controller ควบคุม Software ระบบภาพ vMIX

ก่อนอื่นเรามาดูภาพรวมของระบบกันก่อนครับ (พอดีช่วงนี้ผมมีเวลาครับ จึงอยากทำตัวให้มีประโยชน์กับผู้อื่นบ้าง)


Diagram การต่อสาย




CODE

#define USE_ROTARY_ENCODER
#include <MIDI_Controller.h> // Include the library


#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();  //ตั้งค่า MIDI Libraly


//--- ปุ่มกด หลายตัว  ---------------------------------------------------------------------------

int mem[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; //เก็บค่าสถานะปุ่มกดแต่ละตำแหน่งเอาไว้


//---------------------------------------------------------------------------------------------------------------------


//-------------- Rotary Encoder  ใช้ library  MIDI_Controller.h ---------------------------------------------------------
//Rotary Encoder #1
const uint8_t Channel = 1;       // MIDI channel 1
const uint8_t Controller = 0x14; // MIDI Control Change controller number
const int speedMultiply = 1;     // No change in speed of the encoder (number of steps is multiplied by 1)

//Rotary Encoder #2
const uint8_t Channel2 = 2;       // MIDI channel 1
const uint8_t Controller2 = 0x15; // MIDI Control Change controller number
const int speedMultiply2 = 1;     // No change in speed of the encoder (number of steps is multiplied by 1)




// Create a new instance of the class 'RotaryEncoder', called 'enc', on pin 2 and 3, controller number 0x14, on channel1,
// no change in speed (speed is multiplied by 1), it's used as a jog wheel, and the sign mode is set to two's complement.
//TWOS_COMPLEMENT, BINARY_OFFSET or SIGN_MAGNITUDE
//RotaryEncoder encoder(26, 27, Controller, Channel, speedMultiply, JOG, TWOS_COMPLEMENT);


//RotaryEncoder encoder(26, 27, Controller, Channel, speedMultiply, JOG and NORMAL_ENCODER,TWOS_COMPLEMENT&SIGN_MAGNITUDE);
//หลังจากใส่คาปาซิเตอร์  0.1 ไมโครฟารัดลงไปใน Rotary Encoder แล้วถ้าเลือกแบบนี้จังหวะการหมุนในการเลือกภาพเลื่อนไป 1 ช่องเท่ากับเลื่อน 2 ภาพ


//RotaryEncoder encoder(26, 27, Controller, Channel, speedMultiply,  NORMAL_ENCODER, TWOS_COMPLEMENT);
//RotaryEncoder encoder(26, 27, Controller, Channel, speedMultiply,  NORMAL_ENCODER, SIGN_MAGNITUDE)
//หลังจากใส่คาปาซิเตอร์  0.1 ไมโครฟารัดลงไปใน Rotary Encoder แล้วถ้าเลือกแบบนี้จังหวะการหมุนในการเลือกภาพเลื่อนไป 2 ช่องเท่ากับเลื่อน 1 ภาพ



//Rotary Encoder #1
RotaryEncoder encoder(26, 27, Controller, Channel, speedMultiply, NORMAL_ENCODER, TWOS_COMPLEMENT&SIGN_MAGNITUDE);
//หลังจากใส่คาปาซิเตอร์  0.1 ไมโครฟารัดลงไปใน Rotary Encoder แล้วถ้าเลือกแบบนี้จังหวะการหมุนในการเลือกภาพเลื่อนไป 2 ช่องเท่ากับเลื่อน 1 ภาพ
//ให้เข้าไปแก้จำนวนPluse ของ NORMAL_ENCODER จาก 4 Pluse  ต่อ 1 คลิกเป็น 2 Pluse ต่อ 1 คลิก ของไฟล์ RotaryEncoder.h
//ที่อยู่ C:\Users\PUYIOT\Documents\Arduino\libraries\MIDI_controller-master\src\MIDI_Outputs
// จากนั้นให้เปิดปิดโค้ชใหม่เพื่อล้างค่าและรับค่าการเปลี่ยนแปลงของ Pluse ที่เราเปลี่ยนใหม่ด้วย


//Rotary Encoder #2
RotaryEncoder encoder2(37, 38, Controller2, Channel2, speedMultiply2, NORMAL_ENCODER, TWOS_COMPLEMENT&SIGN_MAGNITUDE);
//หลังจากใส่คาปาซิเตอร์  0.1 ไมโครฟารัดลงไปใน Rotary Encoder แล้วถ้าเลือกแบบนี้จังหวะการหมุนในการเลือกภาพเลื่อนไป 2 ช่องเท่ากับเลื่อน 1 ภาพ
//ให้เข้าไปแก้จำนวนPluse ของ NORMAL_ENCODER จาก 4 Pluse  ต่อ 1 คลิกเป็น 2 Pluse ต่อ 1 คลิก ของไฟล์ RotaryEncoder.h
//ที่อยู่ C:\Users\PUYIOT\Documents\Arduino\libraries\MIDI_controller-master\src\MIDI_Outputs
// จากนั้นให้เปิดปิดโค้ชใหม่เพื่อล้างค่าและรับค่าการเปลี่ยนแปลงของ Pluse ที่เราเปลี่ยนใหม่ด้วย


;


//--- ปุ่ม potentiometer1 slide  ตัวที่ 1  ---------------------------------------------------------------------------
int val = 0;
int lastVal = 0;
Analog potentiometer1(A0, MIDI_CC::Channel_Volume, 1);

//---------------------------------------------------------------------------------------------------------------------


Analog potentiometer2(A1, MIDI_CC::Channel_Volume, 7);
Analog potentiometer3(A2, MIDI_CC::Channel_Volume, 8);
Analog potentiometer4(A3, MIDI_CC::Channel_Volume, 9);
Analog potentiometer5(A4, MIDI_CC::Channel_Volume, 10);


//************void setup   ******************
//*******************************************
void setup()

{


  Serial.begin(9600);
  MIDI.begin(MIDI_CHANNEL_OMNI);//ให้ Libraly MIDI เริ่มต้นทำงาน

  //กำหนดขาที่ใช้งานให้เป็นแบบ input pull up โดยใช้ R pull up ภายใน  arduino
  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 ) ;
  pinMode(12, INPUT_PULLUP ) ;
  pinMode(13, INPUT_PULLUP ) ;
  pinMode(14, INPUT_PULLUP ) ;
  pinMode(15, INPUT_PULLUP ) ;
  pinMode(16, INPUT_PULLUP ) ;
  pinMode(17, INPUT_PULLUP ) ;

  pinMode(18, INPUT_PULLUP ) ;
  pinMode(19, INPUT_PULLUP ) ;
  pinMode(20, INPUT_PULLUP ) ;
  pinMode(21, INPUT_PULLUP ) ;
  pinMode(22, INPUT_PULLUP ) ;
  pinMode(23, INPUT_PULLUP ) ;
  pinMode(24, INPUT_PULLUP ) ;
  pinMode(25, INPUT_PULLUP ) ;
  pinMode(28, INPUT_PULLUP ) ;
  pinMode(31, INPUT_PULLUP ) ;
  pinMode(29, INPUT_PULLUP ) ;//ปุ่มกด Encoder#1


  pinMode(30, INPUT_PULLUP ) ;//LOOP IN
  pinMode(32, INPUT_PULLUP ) ;//LOOP OUT
  pinMode(33, INPUT_PULLUP ) ;//PLAY/ II
  pinMode(34, INPUT_PULLUP ) ;//Reset/Play
  pinMode(35, INPUT_PULLUP ) ;//Reset/Stop
  pinMode(36, INPUT_PULLUP ) ;//ปุ่มกด Encoder#2


  pinMode(39, INPUT_PULLUP ) ;//Transition  Effect 1
  pinMode(40, INPUT_PULLUP ) ;//Transition  Effect 1
  pinMode(41, INPUT_PULLUP ) ;//Transition  Effect 1
  pinMode(42, INPUT_PULLUP ) ;//Transition  Effect 1
 // pinMode(43, INPUT_PULLUP ) ;//SET FADE




  pinMode(44, INPUT_PULLUP ) ;//SCREEN ON
  pinMode(45, INPUT_PULLUP ) ;//SCREEN OFF
  pinMode(46, INPUT_PULLUP ) ;//PLAY/ II
  pinMode(47, INPUT_PULLUP ) ;//Reset/Play
  pinMode(48, INPUT_PULLUP ) ;//Reset/Stop



}

//************ จบ void setup   **************


//************void loop   ********************************************************************************************
//********************************************************************************************************************
void loop() {

 MIDI.read();


  //------------------  สวิสทซ์ ปุ่มกด  16 ตัว แสดง ON OFF ใน โปรแกรม MIDI  -------------------------------------------------
  //อ่านปุ่มทุกปุ่มออกมา
  int sensorVal[] = {
    !digitalRead(2), !digitalRead(3),
    !digitalRead(4), !digitalRead(5),
    !digitalRead(6), !digitalRead(7),
    !digitalRead(8), !digitalRead(9),
    !digitalRead(10), !digitalRead(11),
    !digitalRead(12), !digitalRead(13),
    !digitalRead(14), !digitalRead(15),
    !digitalRead(16), !digitalRead(17),

    !digitalRead(18), !digitalRead(19),
    !digitalRead(20), !digitalRead(21),
    !digitalRead(22), !digitalRead(23),
    !digitalRead(24), !digitalRead(25),
    !digitalRead(28), !digitalRead(31),
    !digitalRead(29),

    !digitalRead(30), !digitalRead(32),
    !digitalRead(33), !digitalRead(34),
    !digitalRead(35), !digitalRead(36),


    !digitalRead(39), !digitalRead(40),
    !digitalRead(41), !digitalRead(42),
    


    !digitalRead(44), !digitalRead(45),
    !digitalRead(46), !digitalRead(47),
    !digitalRead(48)


  };

  //ถ้าสถานะปุ่มมีการเปลี่ยนแปลง
  for (int j = 0; j < 42; j++) {
    if (sensorVal[j]  != mem[j]) {
      mem[j] = sensorVal[j];
      // จะมีการส่ง MIDI Even ออกไป
      if (mem[j]) {
        MIDI.sendNoteOn(j + 51, 64, 1);
      } else {
        MIDI.sendNoteOff(j + 1, 64, 1);

      }
    }


    MIDI_Controller.refresh(); //ฟังก์ชันของ Rotary Encoder


  }

  //---------------------------------------------------------------------------------------------------------------------


}

//************************************************ จบ void loop   ********************************************************
//************************************************************************************************************************

ผมอธิบายไม่เก่งนะครับ แต่อยากจะนำเสนอให้ทุกท่านที่ สนใจ ได้ดูรายละเอียดกัน

1 Likes

Hi, can you send me the library of this project? Thank you
My email is
ircsaberi@gmail.com

1 Likes

https://drive.google.com/file/d/1q6mZ83oAmnKgVgE8YwlKscynyocSlii4/view?usp=sharing

1 Likes

Thanks for download link; But I have a question.
How to open PCB file?
please told me the neme of software.
best regards

โอ้โห ไฟล์เป็น G เลย งานระเอียดมากเลยครับ ข้อมูลอย่างแน่น

image

I don’t have a PCB File but it’s a wiring diagram I wrote in SketchUp layout ok I will convert it to PDF wfile for you

1

DrawingMIDI.pdf (119.9 KB)

1 Likes

Tomorrow if i have time I will be photographing my work in this post.

1 Likes

รายละเอียดเพิ่มเติมครับ (สำหรับผู้สนใจ) โปรเจคนี้ทำนานแล้ว นานจน ผมลืมๆ ไปแล้ว 555…



1 Likes

Thanks for the explanation. I mean the software with which you designed the PCB. What software did you use to design the PCB? (drawingMIDI.layout)
Another question is, what did you do for the Tali circuit in this project?
I hope I can diy this device

  1. I use Sketchup program. This program is divided into 3 sub-programs. I only use Diagram which you may find other programs to write Diagram. no different
    1

  2. I need more details from your question.

Hi
Is it possible told me, How to made VMIX Controller Step by Step?
I try made it, But I don’t work Properly!!!

My step by step:

  1. MIDI_Arduino_MEGA_R3.ino open, compile, and programed arduino mega 2560 R3.

  2. change USB to MIDI by arduino_midi.hex and Flip 3.4.7 application; then reset arduino.

  3. when the connect Arduino bord, Detected " Arduino_MIDI " in "sound,video and game controller " section on My Device Manager. Is it corrected?

  4. Open Vmix app , Setting, shortcuts ; detected " Arduino_MIDI " and then OK.

  5. Press “add” , then press “Find” key; But When the press any key on the board, Vmix App can not find key!!!

Please help me.

thanks

Hi
Is it possible told me, How to made VMIX Controller Step by Step?
I try made it, But I don’t work Properly!!!

My step by step:

  1. MIDI_Arduino_MEGA_R3.ino open, compile, and programed arduino mega 2560 R3.

  2. change USB to MIDI by arduino_midi.hex and Flip 3.4.7 application; then reset arduino.

  3. when the connect Arduino bord, Detected " Arduino_MIDI " in "sound,video and game controller " section on My Device Manager. Is it corrected?

  4. Open Vmix app , Setting, shortcuts ; detected " Arduino_MIDI " and then OK.

  5. Press “add” , then press “Find” key; But When the press any key on the board, Vmix App can not find key!!!

Please help me.

thanks

Ask to see your work

  1. What equipment do you use? and what does it do
  2. The code that you use in Arduino Mega

Hi

  1. MIDI_Arduino_MEGA_R3.ino open, compile, and programed arduino mega 2560 R3.

  2. change USB to MIDI by arduino_midi.hex and Flip 3.4.7 application; then reset arduino.

  3. when the connect Arduino bord, Detected " Arduino_MIDI " in "sound,video and game controller " section on My Device Manager. Is it corrected?

  4. Open Vmix app , Setting, shortcuts ; detected " Arduino_MIDI " and then OK.

  5. Press “add” , then press “Find” key; But When the press any key on the board, Vmix App can not find key!!!

Please help me.

thanks

Untitled Project

That’s why I have to look at your code.

You have to start testing 1 button first to see if it works.

Thanks for your response.
I do corresponding the film but any key doesn’t work
Please guide me more
Thanks

สำหรับโค้ดชุดนี้เป็นโค้ดที่ใช้งานได้โดยฉันทำเป็นตัวอย่างโดยใช้ปุ่ม Push button 1 ปุ่มและใส่โค้ดชุดนี้เข้าไปก็สามารถที่จะเพิ่มปุ่มของวีมิกซ์ได้ คุณควรตรวจสอบโค้ดของคุณว่าผิดพลาดตรงไหน ถ้าคุณแสดงโพสต์ให้ฉันเห็นฉันจะเป็นไกด์ไลน์ให้คุณได้ แต่คุณไม่แสดง Code มันเป็นสิ่งที่ผิดพลาด สำหรับการแบ่งปัน
คุณควรเปิดใจในเรื่องนี้กับฉัน ถ้าคุณไม่เปิด โค้ดนี้อีก ฉันจะแนะนำคุณครั้งนี้เป็นครั้งสุดท้าย

For this code here is the working code, I made an example by using 1 push button and inserting this code can add Vmix button. You should check your code for any errors. If you show me the post I can guide you. But you don’t show the code, it’s something wrong. for sharing
You should open up to me about this. If you don’t open this code again, I will introduce you this one last time.


#define USE_ROTARY_ENCODER
#include <MIDI_Controller.h> // Include the library


#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();  //ตั้งค่า MIDI Libraly



//--- ปุ่มกด หลายตัว  ---------------------------------------------------------------------------

int mem[] = { 0}; //เก็บค่าสถานะปุ่มกดแต่ละตำแหน่งเอาไว้


//---------------------------------------------------------------------------------------------------------------------




//************void setup   ******************
//*******************************************
void setup()

{


  Serial.begin(9600);
  MIDI.begin(MIDI_CHANNEL_OMNI);//ให้ Libraly MIDI เริ่มต้นทำงาน

  //กำหนดขาที่ใช้งานให้เป็นแบบ input pull up โดยใช้ R pull up ภายใน  arduino
  pinMode(2, INPUT_PULLUP ) ;


}

//************ จบ void setup   **************




//************void loop   ********************************************************************************************
//********************************************************************************************************************
void loop() {

  MIDI.read();


  //------------------  สวิสทซ์ ปุ่มกด  ตัว แสดง ON OFF ใน โปรแกรม MIDI ของ vMIX  -----------------------------------------
  //อ่านปุ่มทุกปุ่มออกมา
  int sensorVal[] = {
    !digitalRead(2)

  };

  //ถ้าสถานะปุ่มมีการเปลี่ยนแปลง
  for (int j = 0; j < 1; j++) {
    if (sensorVal[j]  != mem[j]) {
      mem[j] = sensorVal[j];
      // จะมีการส่ง MIDI Even ออกไป
      if (mem[j]) {
        MIDI.sendNoteOn(j + 51, 64, 1);
      } else {
        MIDI.sendNoteOff(j + 1, 64, 1);

      }
    }

    MIDI_Controller.refresh();
  }

  //---------------------------------------------------------------------------------------------------------------------

}



//************************************************ จบ void loop   ********************************************************
//************************************************************************************************************************