Arduino 2 PD Help

Hey Im trying to get an Arduino to read multiple Sensor Values for use over Serial in Pure Data.

Arduino Code:

#include <SimpleMessageSystem.h>

/* Analog/Digital inputs to PD trigger
 * ------------
 * send serial values to PD to trigger something
 */

char firstChar; 
char secondChar;

void setup()
{
  Serial.begin(9600);
}


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<=12;m++) { 
       messageSendInt(digitalRead(m)); // Read digital pins 2 to 12, 13 is onboard LED on Arduino NG
          }
            
       messageEnd(); // Terminate the message being sent 
       
          
                    } 
      }
   }
}

Compiling works fine.

Pure Data PAtch:

Yes I changed to the right Port and the Baud rate is set to 9600.

The Problem is i still dont see any numbers changing if i turn the potis. I did turn on the 'start polling' btw
Any help would be greatly appreciated.

Flitschi

Why not start with a much simpler project. Send ONE value from one analog pin. Verify that that is working, and then expand the project.

There is only one ADC on the Arduino. When switching between analog pins, the first reading from the new pin is suspect, and should be discarded.

Yeah I did that and it was relatively easy. I need to read multiple sensors at once unfortunately though. That's where I have problems.
I also had an implementation where I would send the sensor values in different ranges and then split them up in PD but this approach is limited and not very precise:

Sensorvalue 1: 0-64
Sensorvalue 2: 65-130
Sensorvalue 3: 131-194
Sensorvalue 4: 195-255
for example

I need to read multiple sensors at once

Well, you can't. Get over it.

What you CAN do is read multiple sensors, one after another, so that all area read in some reasonable period of time. You will have issues when switching analog pins, if you don't read the pin twice.

Forget about the SimpleMessageSystem class for now. Send data from all the sensors to the serial port. See that THAT works, before using the SimpleMessageSystem class.

You need to determine where the breakdown is occurring.

yeah that worked already, I sent over the values one by one and it worked. but my approach so far is limited. I want to do it with a list like in the simple message system.

I want to do it with a list like in the simple message system.

Then, obviously, you'll need to implement, in PD, an algorithm to unpack the data from the list. It would appear that the data in the "list" is NOT a comma-delimited string of characters. I'd guess that you are sending binary data using the SimpleMessageSystem class, while PD is expecting ASCII data.

== not =

Mark