Beginner arduino question, ultrasonic range sensor
Hello all,
Im not very familiar with the serial object. Ive checked the other posts on this but no joy. Im just trying to get my ultrasonic range sensor to read into max. Its reading fine into arduino IDE 2.2,1 (macbook bigsur)
However I am not getting much out the serial object , just trying it with a basic metro set to the same rate as the ide code (50) in serial I have the following arguments in serial "serial b 9600" but I doubt its worth posting my max code its so primitive , can anyone give me an example Max code that will get the data out of the following arduino code (arduino connected by usb) :
Arduino code :
//www.elegoo.com
//2016.12.08
#include "SR04.h"
#define TRIG_PIN 12
#define ECHO_PIN 11
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long a;
void setup() {
Serial.begin(9600);
delay(1000);
}
void loop() {
a=sr04.Distance();
Serial.print(a);
Serial.println("cm");
delay(50);
}
tx!
If you checked "other" posts about serial port, then
I am assuming that you are not making beginner mistakes,
that you know how to select correct port, activate polling etc.
if you println anything from arduino then 13 - ASCII Carriage return
will output collected bytes from zl.group.
If you receive nothing, even not raw bytes
then you have a problem, and with so less infos one can't offer any help about what to do...
Hi thanks
Yes Im getting no data out the left of serial with any port selected,
when I send print message to serial object I get serial:
port a: Bluetooth-Incoming-Port serial:
port b: usbmodem14201 data:
port Bluetooth-Incoming-Port usbmodem14201 (not sure what this means)
I have selected serial: port b: usbmodem14201 but also tried with port a
The right port is printing out "read 0" but only when I change to port a. Port b puts nothing out of either outlet.
The serial monitor in Arduino is receiving data just fine and I have tried the patch with serial monitor closed.
Heres my maxpatch:
and heres the arduino code:
//www.elegoo.com
//2016.12.08
#include "SR04.h"
#define TRIG_PIN 12
#define ECHO_PIN 11
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long a;
void setup() {
Serial.begin(9600);
delay(50);
}
void loop() {
a = sr04.Distance();
Serial.println(a);
delay(5);
}
As far as the MAX code is concerned, you mis-connected the [serial] object :
May not solve 100% of the issues, but this should be corrected first.
Hi ,
Yeah thanks for your help but Ive tried both outlets, as I mentionedthe first outlet is putting out nothing - not even connected to a bang, print raw etc nada... Im wondering if there's something in the inspector for serial I need to change.
Then I don't know. Works here, with a dummy code quickly uploaded in an Arduino nano (port c in my case) :
Dummy code:
a = random(0,100);
Serial.print(a);
Serial.println("cm");
aggghhh it was mind boggling simple - something if you used an arduino before you probably would just assume is obvious - I had the arduino IDE still running !! Turned it off and now its fine - thanks again for your help!!