Hi,
to get a possibly faster sampling rate (although I haven't tried this) you can delete the lines of code that read the pins you aren't using in the Arduino.
Right now, the Arduino reads all the digital and analog pins:
void loop()
{
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 (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(100);
}
}
}
}
To potentially speed things up, you can try to just read the pins you need.
Here's an example that would just read two analog and two digital pins:
void loop()
{
[color=#cc0000] 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 (int i=0;i<=1;i++) {
messageSendInt(analogRead(i)); // Read analog pins 0 and 1
}
for (int m=2;m<=4;m++) {
messageSendInt(digitalRead(m)); // Read digital pins 2, 3 and 4
}
messageEnd(); // Terminate the message being sent
delay(100);
}
}
}
}
Other than this, you can adjust the settings in MAX:
A: "Change how often MAX asks the Arduino for serial data: 10 miliseconds is the default."
this is how often MAX asks the Arduino to perform read its pins.
B: "Change how often MAX reads the computer's serial port for incoming data. Making this too slow will cause crashes! 2 milliseconds is the default." This is how often MAX checks the serial buffer for data. If it's too high of a number, the serial port buffer won't get checked often enough, and it will overflow.
You might try:
- eliminating the MAX> Arduino requests altogether, and just having the Arduino send data continuously, but this will probably crash the serial port.
- adjusting and tweaking the settings above for the best compromise.
Ultimately I think you are going to be limited by the serial port speed, but you can probably do a lot better than it is now. If you get an improved verion, can you take hte time to post it in the playgorund with a higher version number?
Thanks
D