Loading...
Pages: [1]   Go Down
Author Topic: Arduino2Max: read Arduino pins in MAX  (Read 980 times)
0 Members and 1 Guest are viewing this topic.
Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I just posted my primitive but very functional Arduino2Max, package in the Playground. This is a Max patch and associated Arduino code that lets you easily read the Arduino's 12 digital pins and 6 analog pins in Max.

The above works like a charm on a Macbook pro, but it's not tested on anything else. You'll need to download the SimpleMessageSystem-- see the readme file included in the zip archive. Serial writes are possible too, but they're not implemented. Go ahead, implement!

I based Arduino2Max (version .10) on one of the examples in Thomas Ouellet Fredrick's excelent Simple Message Sytem library... thanks Thomas.  The SMS library came along just in time, as they have stopped making and selling the Teleo module...

D
« Last Edit: November 09, 2006, 02:20:11 am by Daniel » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

BRILLIANT!!!  Thanks for this - I have just got the board and have been using Serial object in MAX to get the print statements, however of course I wish to read the pins indipendantly.

So I have been looking at the SimpleMessageSystem and your patch.  I have imported the S.M.S into a basic patch which reads AnaloguePin2 (Piezo attached) and outputs on DigitalPin7 (LED attached).

I am not getting anything in MAX even after sending the 'r d' message.

I am unclear what needs to go into the Arduino Sketch in order to make this work.  The calls in

 // Arduino code
 if (messageBuild()) { // Checks to see if the message is complete
      firstChar = messageGetChar()) { // Gets the first word as a character
      if (firstChar = 'r') { // Checking for the character 'r'
          secondChar = messageGetChar() // Gets the next word as a character
          if (firstChar = 'd') // The next character has to be 'd' to continue
               messageSendChar('d');  // Echo what is being read
               for (char i=2;i<14;i++) {
                     messageSendInt(digitalRead(i)); // Read pins 2 to 13
               }
               messageEnd(); // Terminate the message being sent
          }
       }
  }
 // Arduino code end

I am assuming the various methods such as messageEnd() are in the import, however if I add this code to the Sketch, it does not compile and there are no further notes in the readme about the implementation of these methods or where to set them up.

I am also assuming that such code must go in the loop()

Thanks in advance for your guidance.

Cheers

Garth
Logged

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Garth,

just program the Arduino with the code included in the Arduino2Max zip archive, it should work like a charm... Make sure you have downloaded and installed the SMS library too.

I'd start with that as a reference, and then fiddle with it. If you are only using inputs, you shouldn't need to change anything. The included MAX patch sends the "r d" command automatically.

D

PS: any brilliant kudos should go to Thomas Ouellet Fredericks (TOF), for writing the SMS library.
« Last Edit: November 13, 2006, 11:01:21 pm by Daniel » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Daniel

Sorry for my stupidity earlier in the day - I found the code, moded it to flash a few LED's as a second indication of Piezo input, loaded it, and hey presto - works like a bought one  ;D

Thanks,  Garth
Logged

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

excellent! Can I ask what os you ran it on, and how fast of a computer you're using? I'm wondering what the miimum machine required is.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am running it on a new Intel 2.16GHz 1GBRam under 10.4.8 - not your minimum I would think :-)
Logged

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

At least we know it works on a mac book pro!

D
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Daniel and Garth

I've been having trouble getting Max/MSP to read anything using the "arduino_for Max_input" code.

The code included in the Arduino2Max_v4 compiles correctly, however when I open the arduino_to_Max patch it throws up this error message in the max window:

"itoa:No such object"

Do you know what this means? and any ideas on how to fix it?

Thank you for your help

Gareth

Logged

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

"itoa" a freeware MAX external written by Steve Ellison, and it's included in MAX version 4.5 and higher. It converts integers into ascii characters.

So the solution is to upgrade your copy of MAX, or
download and install itao here, or
write your own little patch to make the conversion from integers to ascii.

"itoa" is used inside the arduinoreader>convertback patch, as written originally by TOF.

Hope this helps

D
« Last Edit: November 19, 2006, 04:07:50 am by Daniel » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Daniel

Thanks for the help. Unfortunatley the hyperlink ( http://ftp://ftp.forumnet.ircam.fr/pub/max ) from the MAX Objects site leads to an empty folder.

Do you have any other links i can try?

Cheers,

Gareth
Logged

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, they really had it hidden away in there. I corrected the link in my post above. that will give you an archive with the itoa external in it. I don't know what platforms it will run on-- I would guess  OS9 and OSX on a Power PC.  

I double-checked the cycling 74 site as well, and versions 4.5, 4.55 and 4.6 of MAX all include "itoa".
« Last Edit: November 19, 2006, 04:23:32 am by Daniel » Logged

Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
I Love Arduino!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Daniel,
nice Max/Msp patch.
I spotted 2 minor errors in your Arduino SimpleMessageSystem code:


You set the value for secondChar(secondChar = messageGetChar()smiley-wink , but you do not use that variable.  In the same section of code, you have a comment that states that the next character has to 'b' to continue, but that is not true as there are no curly braces to indicate the code to execute if the statement is true. It should be something like:

Code:
...snip...
if (secondChar = 'd') {   // The character has to be 'd' to continue and read the sensors

         messageSendChar('d');  // Echo what is being read

          for (int i=0;i<=5;i++) {
            messageSendInt(analogRead(i)); // Read analog pins 0 to 5
          }

          for (int m=2;m<=13;m++) {
            messageSendInt(digitalRead(m)); // Read digital pins 2 to 13
          }

          messageEnd(); // Terminate the message being sent
          delay(9);
}
...snip...

Also, since you are controlling the rate of querying the sensors in Max/Msp there is no real need for the delay(). Simply limit the metro in Max/Msp to 10 ms. Why? You are sending from the Arduino board a list that can contain up to 56 ascii characters and, at 115200 baud rate, that can take about 5.4 ms to transfer (I think), so 10 ms gives a bit of time to settle.

One final comment: since you are querying all sensors simultaneously, you do not need to put headers to your query and answer.
i.e.: To query the sensors you could use only one character. For the answer, you do not need any. Something like this:

Code:
...snip...
if (secondChar = 'r') {   // The next character has to be 'r' to continue and read the sensors

           //(This can be removed with the updated SMS lib, see below) messageSendChar('d');

          for (int i=0;i<=5;i++) {
            messageSendInt(analogRead(i)); // Read analog pins 0 to 5
          }

          for (int m=2;m<=13;m++) {
            messageSendInt(digitalRead(m)); // Read digital pins 2 to 13
          }

          messageEnd(); // Terminate the message being sent
          
}
...snip...

The code above only works with the new SMS lib (and a slightly modified Max/Msp patch where the route is removed), as stefan kersten noticed that I had left some debug statements that would send the size of the buffer through the serial connection. That was corrected and uploaded.

Tom
Logged

Thomas Ouellet Fredericks

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Thomas,

thanks for the excellent comments, and for the excellent SMS library. I'll fix these things and upload anew version after Christmas...

Daniel
Logged

Pages: [1]   Go Up
Print
 
Jump to: