Serial obj not connecting through to serial COM port to accept data from Arduino

Sam Castle's icon

Hi there,

I am having significant difficulty getting my Arduino code (running on an Arduino Nano 33 BLE Sense) to send the serial data to Max. As per this tutorial (https://www.youtube.com/watch?v=6bT3G4Mep7E&list=PLF5vv_9uIfrAN-xFXCoZ3KSxThFhcGJnf&index=14&ab_channel=ProgrammingforPeople).

I am convinced it is a problem to do with Windows - I have tried on 3 different Windows 10 laptops and none of them will connect to the port to allow data to flow. Unfortunately I don't have access to a Mac to try on that instead. I have tried 2 separate microUSB cables - both which allow the Arduino code to be uploaded so are working data and power cables. I have tried all the possible combinations i can think of for Arduino IDE being completely closed then opening Max. I have tried using serial.write instead of serial.println. I have also tried sending messages 'port COM5' into the serial obj. I have also tried running the tutorial files for Communications Tutorial 2: Serial Communication (https://docs.cycling74.com/max8/tutorials/communicationschapter02) again with no data flowing.

If anyone has had this issue please could you let me know how I might fix this? If I can't get serial to work is there an alternative method for getting sensor data (numbers) from Arduino into Max on Windows?

Thanks for all your help, Sam

Source Audio's icon

go to sysem setup usb devices and check which COM port it gets assigned.
It can change many times.

send print message to max serial object to see the list of available COM ports.
one among them - if more present will be your nano.

One can also assign "static" COM port for a serial device, at least it was possble
on win10

Sam Castle's icon

Do you mean look in device manager at the ports? From this you can see that the USB cable is attached to COM5. This is present when sending print into the serial object. This is the port i've assigned to the obj via replacing the letter with 'e' and 'COM5', sending 'port e' as a message, sending port 'COM5' as a message etc.

I believe I also tried assigning a static port at the start with no success but may need to revisit this.

Source Audio's icon

i have no experience with that nano board,
and also don't know if it needs any drivers or not.
can you receive anything in arduino serial monitor ?
Can you use simplest ever test, printig something every second

Sam Castle's icon

Yes I am receiving everything I need on the Arduino side of things. I also am sure that Max is trying to access the port because when I've gone back to Arduino and not closed the port in Max it doesn't allow me to open the serial monitor.

The board has Mbed OS as its driver and once installed on Arduino you simply have to plug the board in as shown here: https://www.arduino.cc/en/Guide/NANO33BLESense

Source Audio's icon

would you upload your max patch and arduino test code ?

Sam Castle's icon

Arduino Sketch:

// constants
const int buttonPin = 2; // push button
const int ledPin = 3; // board led on pin

//variables
int buttonState = 0; // current state of button
int lastButtonState = 0; // previous button state
int randVal = 0; // random number to be sent

void setup(){
// initialise the button on pin 2
pinMode(buttonPin, INPUT);
// initialise the led
pinMode(ledPin, OUTPUT);
// initialise the serial communication
Serial.begin(9600);
}

void loop(){
// set random number
randVal = random(1000);
// read button state
buttonState = digitalRead(buttonPin);
// compare button state against previous
if(buttonState != lastButtonState){
// if the button state has changed, nothing
if(buttonState == HIGH) {
digitalWrite(ledPin, HIGH); //LED off
//Serial.println("up");
}
else{
// if current state is low, send value
//Serial.println("down");
//Serial.println(" ");
digitalWrite(ledPin, LOW); //turn on LED
Serial.println(randVal);
}
// incase of bounce
delay(50);
}
// save current state as the last state for next time through loop
lastButtonState = buttonState;
}

serial_receive.maxpat
text/plain 13.25 KB

Sam Castle's icon

I have just managed to dig out an old Arduino Mega 2560 and the serial object works fine with this instead. There is a difference also in how the board is recognised by the computer. For the mega the printed statement is "port j: COM10 (Arduino Mega 2560)" whereas for the Nano BLE Sense the statement is "port e: COM5 (USB Serial Device)"

Source Audio's icon

nothing in the code is suspect
some advice using
while(!Serial); in setup for that kind of board,
but I can't imagine that it would cause much difference if omitted.

I would try some freeware serial port sniffing app to see if it's
max serial port that makes problems.
You can also try comport object from jasch package,
serial port alternative to max standard object.

Susanna Payne-Passmore's icon

Hi there, I'm having the exact same problem on my Arduino Nano 33 BLE Sense as well. Found the same tutorials mentioned too, and none of them work. Did you ever figure out what was wrong? I'm actually running on a Mac, so I don't think that was the issue. My baud rates match, my assigned port matches as well . . . I'm not sure what else to troubleshoot.

Source Audio's icon

try this, there were reports about mac serial port needs some delay on init
with that ble sense boards

void setup() {
delay(1000);
Serial.begin(9600);
while(!Serial)
Serial.println("hello");
}

void loop() { Serial.println("again"); delay(500);
}

Sam Castle's icon

Hi Susanna,

The issue is that the serial object in Max only recognises standard serial drivers, and the Nano Sense runs on a none standard type. I got around this issue by reading the serial data in Processing and sending out the data via local OSC messages and reading them in Max using the udpreceive function.

Hope this helps,
Sam

Source Audio's icon

a brief look at :
https://infocenter.nordicsemi.com/topic/ug_nrf52840_dk/UG/dk/vir_com_port.html

it seems one has to send dtr 1 to the board to initiate it.
Can you test that ?

Susanna Payne-Passmore's icon

Sam - Thanks, this is very helpful and clarifying! I'm familiar with OSC, so would be great to use that. By Processing, do you mean this thing https://processing.org/?

Source Audio - I actually don't know very much about coding yet. How do I send a "dtr 1" message to the baord? Somewhere in setup(), maybe before serial.begin()? And would it be something like serial.write() or serial.print() function? This is the short tutorial sketch I'm using. Thanks so much for your help!

long randomvalue = 0; // random value
long countervalue = 0; // counter value
int serialvalue; // value for serial input
int started = 0; // flag for whether we've received serial yet

void setup()
{
  Serial.begin(9600); // open the arduino serial port
}


void loop()
{
  if(Serial.available()) // check to see if there's serial data in the buffer
  {
    serialvalue = Serial.read(); // read a byte of serial data
    started = 1; // set the started flag to on
  }
  if(started) { // loop once serial data has been received
    randomvalue = random(1000); // pick a new random number
    Serial.print(countervalue); // print the counter
    Serial.print(" "); // print a space
    Serial.print(randomvalue); // print the random value
    Serial.print(" "); // print a space
    Serial.print(serialvalue); // echo the received serial value
    Serial.println(); // print a line-feed
    countervalue = (countervalue+1)%1000; // increment the counter
    delay(100); // pause
  }
}

 
Source Audio's icon

you simply send message dtr 1 to serial object in Max.
that sends terminal ready message from max to arduino.


Nothing to do with arduino sketch itself.
It would be really a shame to have to use processing or any other in between app to talk to arduino.
that chip nrf52840 seems to need dtr active.

Can you post your serial port max patch, so that I can see how you initiate it ?
----------
a simpler arduino patch would be better to test if it sends anything, like
one I posted in previous post.
or blinkl a led if you receive anything from max.
I am not sure if that board needs
while(!Serial)
in setup, like some non ftdi & co arduinos,
but it will not take you long to test it with or without..

Susanna Payne-Passmore's icon

Sending "dtr 1" as a message to serial works! Thanks so much for your help finding and interpreting the chip documentation.