Trouble getting Serial Data
Hi,
Is there a fool proof way to get serial data from the serail object in Max?
I have Max 8.5.3, and have Macbook Pro M2, OS is Ventura 13.2.1
I have an Arduino Uno with some sensors connected. I can see in the Arduino software serial monitor that there is data streaming in. When I go to Max and use the serial object and connect a print object to it I don't see anything. I put the correct baud speed (9600).
If I send the serial object a "print" message I get:
serial port a: usbmodem11201
If I want to access that port should my serial object be [serial a usbmodem11201 9600]?
Also, is there a generic way to set this object so it gets everything on every port?
Like [serial 9600] ?
I am also wondering if there is some firewall or setting in Max or in my Mac that is preventing serial data to get to Max. I have been using the serial port with this patch on my previous computer for years and it was never a problem. So I suspect something like this might be happening.
Thank you in advance for your help. This is pretty frustrating
Nick
Have you checked that Arduino IDE app is closed before trying sending data through [serial] ?
Hi Sebastien,
Yes I am not getting anything, if the Arduino app is open or closed.
But it's interesting that the serial monitor LED on the Arduino doesn't blink unless the serial object or the Arduino app is open. I didn't realize that it doesn't send serial data unless something on the computer is asking for it.
When Max is open (and Arduino app is closed) and I create a new patch and put a serial object in it, I see the LED on the Arduino to start blinking, so I can see data is being sent, but I can't access it.
Thanks for the response. Let me know if there is something I should try.
Just send your Arduino and MAX code, maybe I can check if it works here.
[serial a 9600] should work.
Ok thank you Sebastien.
Some how by you asking me these questions I am magically getting serial data in Max now.
Here is the super basic Max patch to see if I am getting data
This Arduino code might not work for you because you probably won't have these sensors, but you can certainly try it out.
#include <Wire.h>
const int GSR = A0;
int sensorValue = 0;
int gsr_average = 0;
void setup() {
Serial.begin(9600);
// Serial.println("heart rate sensor:");
Wire.begin();
}
void loop() {
Wire.requestFrom(0xA0 >> 1, 1); //
while (Wire.available()) { //
unsigned char c = Wire.read(); //
//
sensorValue = analogRead(A0);
long sum = 0;
for (int i = 0; i < 10; i++) //
{
// sensorValue=analogRead(GSR);
sensorValue = analogRead(A0);
sum += sensorValue;
delay(5);
}
gsr_average = sum / 10 + 1000; //
// Formating the data from two sensors
// Serial.print("/");
Serial.println(gsr_average);
Serial.println("a"); // delimiter between values
Serial.println(c, DEC); //
Serial.println("a"); //
// delay(500);
}
}
Some how by you asking me these questions I am magically getting serial data in Max now.
;-)
you have to use serial port with set baud rate and port,
either by arguments, or by messages.
like port c, or port usbmodem11201
Source Audio,
Thank you for that info. I realized yesterday how much there is to learn about the serial object and how it works. It's confusing. I got it working so I probably won't change anything until I'm done with this project. Thanks for the help
If you don't understand how that works, you can get into trouble at any time again.
Source Audio.
I know you are totally right. I get into trouble with this object all the time. I am trying to learn it. Every time I start a new project with the serial object (like once per year) it takes me a lot of time to get it set up, and I have to relearn the same things over.
But I hope I retain some of what I learn, I just don't use this method often enough to feel well versed in serial communication.
Do you need some examples or whatever ?
Just post what troubles you.
Actually it is dead easy.
You init serial object with for example a and preferably correct baud rate,
rate that matches your arduino code.

then you need print, close and port messages.
print outputs list of serial devices to console and to
right outlet

if you know what your device port name is, you can insert match
to select it, and start polling.
if device is conected that will work.

Use close message to close serial port, which allows
arduino to upload code to the board, in case you
have to do some changes.
When upload is done, go back and either click on blue message,
or use print again ...
This works on Mac, on windows COM port naming is not working like that,
but you are on mac anyway , or ?
*********
Sometimes serial devices get named differenly when plugged into different
USB slots.
but one part of the port name will allways remain the same.
see here 2 Arduinos plugged into 2 USB Slots

an now swaped slots

usbmodmMID1 - which is 32u4 set as USB Midi device remains the same, no matter where it is plugged.
Nano with CH340 chip, varies, but wchusbserial remains constant.
with a little help from regexp, one can match that part no matter where arduino gets plugged.

Source Audio,
This is so amazingly helpful. i copied this and will be saving it for my future issues. Thank you so much!!!