Max/MSP + Wiring Micro Controller: Serial Connect Problems
I'm trying to get my Wiring Board and Max/MSP to communicate using serial data. In Max/MSP I'm using the Serial object and sending integers to it. On the Wiring end my code looks like this:
int val;
void setup() {
Serial.begin(9600);
}
void loop() {
if(Serial.available() > 0) {
val = Serial.read();
Serial.print(val);
}
}
When I open the serial monitor I get no data, so it's obviously not getting anything. If anyone has done anything similar to this and can give me some pointers, or even better, a patch, I would be grateful.
Also, is there anything I have to do to configure my comm ports on my win xp machine?
Any help would be greatly appreciated.
Thanks,
Aaron
since this is what I want to do next week, it would also interest me to know more about other people's experiences and problems.
Can you communicate between your board and your computer using other programs?
Is the serial object set to the right baudrate, etc.?
If you cannot communicate with other programs either, you may need a null-modem-cable, in which the wiring is slightly different than a straight serial-cable.
Dayton
Forget serial man.
Use midi
Set the baud rate to 31250
And send serial packets in triples like this:
176, 0, var_0
176 = continuous control message on channel one
0 = continuous controller number zero
Var_0 = variable (make sure this is limited to 7bits...
If you need higher precision, use pitch-bend.
I forget the midi bytes for pitch bend.
...
If you insisnt on using r232. Use hyper terminal to check to see if this
wiring board is playing nice with the com ports...
Btw are you connecting via a dsub9 or usb cable?
If usb, you may need a driver to communicate with the serial com ports in
windows...
Good luck
-lcc
Hmm. I didn't realize using midi was an option. To be honest, this is my first stab at serial communication programming. How would the midi data appear to the wiring board? How would I retrieve it? And how would I send data back to max/msp?
Also, I opened hyper terminal but couldn't figure out how to test anything. My Wiring board is on com1 (and won't workon any other com port), but that port isn't available as one of the com ports when I open Hyper Terminal. How do I use HT to verify that things are working?
Thanks,
Aaron
Hi Aaron.
Im not sure what's the problem with the serial port com stuff.
But you should be able to open HT, create a connection, set the appropriate
baud rates, stop bit, parady, etc, and have a mess of numbers show up in the
text field as your micro controller spits out data.
Midi is totally an option. Probably an easier one, if you are like me and
prefer to address this problem from a musician perspective.(rather than an
electrical engineer prospective.)
Midi is just serial data at a specific baud rate, with a few hardware specs.
For details on how to make this work, check out the Physical Computing pages
here: http://tigoe.net/pcomp/index.shtml
Btw I am assuming you are using a micro controller to connect sensors to
control things in the computer...
-lcc
Are you using the FTDI chip in your serial-to-usb? That might make a difference.
Also, Hans Stein has made an object for PD called Pduino, which might give you some pointers. Find it at
http://at.or.at/hans/pd/objects.html
Hans-Christoph Steiner is the gentlemans name :)
v a d e //
www.vade.info
abstrakt.vade.info
Oops! Pardon me...
Really interesting work, which I find a great inspiration. Even if I can't remember his name properly.
It took me a couple of days but I finally figured out what I was doing wrong. So, for those of you, like me, who are new to serial communications and are trying to use Max/MSP and wiring, here are some tips:
(I am using an Inspiron 600m laptop with Win XP Pro installed)
1: Start off by figureing out which comm port wiring is on. This is easy. It is the port that the wiring app uses to connect to the wiring board. (menu option "Tools/Serial Ports") On My computer this was com port 5. It is probably something different on your computer.
2. Write your program in Wiring and upload it to the board
Here's some basic code that I used:
-------------------
char val; // variable to receive data from the serial port
void setup()
{
Serial.begin(9600); // start serial communication at 9600bps
}
void loop() {
if( Serial.available() ) // if data is available to read
{
val = Serial.read(); // read it and store it in 'val'
Serial.print(val); //Send the value back out to the serial port
delay(100); // wait 100ms for next reading
}
}
-----------------------------
It is important to use the "serial.print(val);" line otherwise Max/Msp will have no way of knowing whether the value was recived or not. This completes the loop. Wiring gets a value from max/MSP and send the value back for verification.
Don't forget to reset your wiring board to activate the program one it is uploaded.
3. Close the wiring app, but leave the wiring board connected.
4. Open Max/MSP and write program. (See attached code snippet)
***When using max/MSP there are a few things you need to be aware of. ***
a) Never leave your Max patch open when editing your Wiring program. You will get port conflicts and won't be able to upload your program.
b) Make sure that the serial port you set in the Serial object is correct. Max uses letters as stand ins for numbers so a=1. b=2, c=3... So in my case I used e because I am on com port 5.
c) Every time I reopen max or unplug my Wiring Board (regardless of whether I reset it or not) I get serial port errors. If this happens, simply open your patch for editing, select the serial object and change the letter to something different, then click off the serial object. (You should see an error message in the Max window indicating that it can't connect to that port.) Now, re-select the Serial Object and set the letter back to the port you really are using.(In my case e.) Switch off editing mode and send some data. You should be able to send and recieve serial data with no problems.
Once the data is being sent correctly over your serial port you can assign the value to an analog out pin in Wiring to control a motor, or get a value from an analog inpin and send it to Max.
Hope that helps.
Aaron
Since I apparently cannot atach files, here's the text version of my max patch from my previous post:
[Slider] {min = 0, Max = 127}
|
[Number]
|
[Int] [Bang] {click Bang to see received data in Max Window}
|/
[Serial e 9600] {port e = com port 5, 9600 is the baud rate}
|
[Print]