简体   繁体   English

使用 Arduino mega 2560 与 max 进行 Arduino2max 数字引脚通信

[英]Arduino2max digital pin communication to max using an Arduino mega 2560

Im working on connecting an Arduino Mega 2560 into max msp, I have adapted the Arduino2max arduino code and max patch.我正在努力将 Arduino Mega 2560 连接到 max msp,我已经调整了 Arduino2max arduino 代码和 max 补丁。

I have adapted the max patch and succeeded with all 16 analog inputs from arduino into max but cannot get any digital pins over number 13 into max msp.我已经调整了 max 补丁,并成功地将来自 arduino 的所有 16 个模拟输入都转换为 max,但无法将超过 13 的任何数字引脚转换为 max msp。 I was wondering if anyone had had any sucsess with this?我想知道是否有人对此有任何成功?

Any help and comments would be greatly appreciated!任何帮助和意见将不胜感激!

Many thanks非常感谢

Joe

here is the arduino code adapted from Arduino2max v.5 which can be found here http://www.arduino.cc/playground/Interfacing/MaxMSP这是改编自 Arduino2max v.5 的 arduino 代码,可在此处找到http://www.arduino.cc/playground/Interfacing/MaxMSP

int x = 0;              
int ledpin = 13;

void setup ()
{
// 115200 is the default Arduino Bluetooth speed
Serial.begin(115200);
///startup blink
digitalWrite(13,HIGH);              
delay(600);
digitalWrite(13,LOW);
pinMode(13,INPUT);
}



void loop()
{ 
// Check serial buffer for characters
if (Serial.available() > 0){  
if (1){     //Serial.read() == 'r') { // If an 'r' is received then read the pins 
// Read and send analog pins 0-15
for (int pin= 0; pin<=15; pin++)
{ 
 x = analogRead(pin);
 sendValue (x);
}

// Read and send digital pins 2-53
for (int pin= 2; pin<=53; pin++)

{         
 x = digitalRead(pin);
 sendValue (x);
}

 // Send a carriage return to mark end of pin data.
    Serial.println(); 
 // add a delay to prevent crashing/overloading of the serial port
delay (5);                        
 }
}
}
// function to send the pin value followed by a "space".
void sendValue (int x){ 
 Serial.print(x);
 Serial.print(32, BYTE);
 }

Thanks again!再次感谢!

I suggest you to use the OSC Protocol to communicate between the Arduino Mega and Max.我建议您使用 OSC 协议在 Arduino Mega 和 Max 之间进行通信。 I use the library ardosc.我使用图书馆 ardosc。 There is no documentation on it but its not really hard to use it and it is a good library.它没有文档,但使用起来并不难,而且它是一个很好的库。

If you cannot use it do not hesitate to ask me some explanations如果你不能使用它,请不要犹豫,问我一些解释

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM