Sending data from two analog input sensors out of the serial port...

HI,

I have an analog sensor that I am reading and sending the data out of the serial port to MaxMSP softare, where I am analyzing the code.

Is it possible to add another analog sensor to this and send the data from both sensors through the serial port? Is there a way to ID the data streams so that I can separate them in Max? I have been looking and haven't been able to see any solution.

I will put the code I have below. Thank you in advance for any suggestions.

#define Version 11 // version, 1.0 or 1.1, which depands on your board you use as it is
const int pinO2 = A0; // Connect Grove – Gas Sensor(O2) to A0.   GSR sensor

#if Version==11
const int AMP = 121;
#elif Version==10
const int AMP = 201;
#endif

float sensorValue;
float sensorVoltage;


const float K_O2 = 7.43;
float Value;
float previousValue = 10;



void setup()
{
  Serial.begin(115200); //Start the Serial connection
}

void loop()
{

  sensorValue = analogRead(A0);
  sensorVoltage = (sensorValue / 1024.0) * 3.3;
  sensorVoltage = sensorVoltage / (float)AMP * 10000.0;
  Value = sensorVoltage / K_O2;

  // only transmit Value_02 if the input has changed

  if ( Value != previousValue) {
    previousValue = Value;
    Serial.println(Value, 3);
  }

}

Is it possible to add another analog sensor to this and send the data from both sensors through the serial port? Is there a way to ID the data streams so that I can separate them in Max?

Of course you can

What sort of ID would you like to use ? You can tag each value with an ID of your choosing by simply sending the ID via serial. It would be a good idea to use start and end markers for each ID/data pair to make it easier to parse at the other end

The serial input basics tutorial should give you some ideas.

Get the value from the second sensor and send the 2 readings (float data type) in a packet like:

Serial.print("<");  // start marker
Serial.print(fiirstValue, 3);
Serial.print(",");  // delimiter between values
Serial.print(secondValue, 3)
Serial.println(">");  end marker and \r\n

Hey GroundFungus,

Ok I'm looking at your code. That looks interesting. I guess on the receiving end I'll get:

< sensor value 1, sensor value 2 >

right? Then in Max I can take that list and separate it into two different numbers that I can work with. And I can probably remove the <,>.

Thank you very much for the help I'll try this out.

I did look in the tutorial and didn't see much about sending numbers, only receiving them, but I just did a quick scan, as there is a lot of stuff there. Anyway I'll try this. Thank you again.

Nick

Nick

I did look in the tutorial and didn't see much about sending numbers, only receiving them, but I just did a quick scan, as there is a lot of stuff there. Anyway I'll try this. Thank you again.

Yes. the tutorial is about receiving strings and numbers, but I think that it also give insight into how to send data packets for reliable reception. Framing the data with start and end markers, for instance.