Hi there,
I am trying to send 3 pieces of information from Max/MSP using the serial object into Arduino using Serial.read. At the moment I am sending from Max just the numbers 1, 2, and 3 in a single message.
The 3 bytes appear to send from Max (pop-up says write 3) but then serial.read (of which I have 3) seems to be returning -1 for 2 out of every 3 readings as follows.
Reading 1 = 1
Reading 2 = -1
Reading 3 = -1
Reading 1 = 2
Reading 2 = -1
Reading 3 = -1
Reading 1 = 3
Reading 2 = -1
Reading 3 = -1
Here is a copy of the Arduino code
int settings[3];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
// put your main code here, to run repeatedly:
settings [0] = Serial.read();
settings [1] = Serial.read();
settings [2] = Serial.read();
Serial.print("Reading 1 = ");
Serial.println(settings [0]);
Serial.print("Reading 2 = ");
Serial.println(settings [1]);
Serial.print("Reading 3 = ");
Serial.println(settings [2]);
}
}
And of the Max patch
{
"boxes" : [ {
"box" : {
"maxclass" : "message",
"text" : "1 2 3",
"numoutlets" : 1,
"patching_rect" : [ 194.0, 78.0, 37.0, 22.0 ],
"id" : "obj-26",
"outlettype" : [ "" ],
"style" : "",
"numinlets" : 2
}
}
, {
"box" : {
"maxclass" : "message",
"text" : "print",
"numoutlets" : 1,
"patching_rect" : [ 115.0, 115.0, 34.0, 22.0 ],
"id" : "obj-10",
"outlettype" : [ "" ],
"style" : "",
"numinlets" : 2
}
}
, {
"box" : {
"maxclass" : "newobj",
"text" : "print status @popup 1",
"numoutlets" : 0,
"patching_rect" : [ 254.0, 218.0, 138.0, 23.0 ],
"id" : "obj-28",
"fontname" : "Arial",
"style" : "",
"fontsize" : 13.0,
"numinlets" : 1
}
}
, {
"box" : {
"maxclass" : "newobj",
"text" : "serial d 9600",
"numoutlets" : 2,
"patching_rect" : [ 194.0, 144.0, 79.0, 22.0 ],
"id" : "obj-1",
"outlettype" : [ "int", "" ],
"style" : "",
"numinlets" : 1
}
}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-26", 0 ],
"destination" : [ "obj-1", 0 ],
"hidden" : 0,
"disabled" : 0
}
}
, {
"patchline" : {
"source" : [ "obj-10", 0 ],
"destination" : [ "obj-1", 0 ],
"hidden" : 0,
"disabled" : 0
}
}
, {
"patchline" : {
"source" : [ "obj-1", 1 ],
"destination" : [ "obj-28", 0 ],
"hidden" : 0,
"disabled" : 0
}
}
],
"appversion" : {
"major" : 7,
"minor" : 3,
"revision" : 3,
"architecture" : "x86",
"modernui" : 1
}
}
Can anybody help me to get the readings in order?
Thanks in advance!
Asha