It is a modular programing language from Cycling 74. I use it in Ableton Live ( digital audio workstation) to comunicate with hardware.
Im biulding a cotroller with Adafruits Neotrellis led/button boards with a Teensy 4.0 controller board.
To make my question clearer.
I need to send integers from 0 to 600 to teensy. And sending directly the int to serial (in max/msp) I could only do 0-255.
Using a different code, with end marker, and playing around with " atoi" and "itoa" I managed to solve that obstacle.
But since I dont understand the different data types and convertions I have a, hopefully, last and more concrete obstacle.
On max/msp , I convert a number (lets say 512) to asccii, append a 10 (endline) at the end and send it to serial module.
On teensy I think I get an array but I need to use integers and cant do the convertion.
Nuevito: In function 'void showNewData()':
C:\Users\Moris\Desktop\Nuevito\Nuevito.ino:104:26: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]
if (receivedChars == 512 ) {
^
C:\Users\Moris\Desktop\Nuevito\Nuevito.ino:108:31: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]
else if (receivedChars == 513 ) {
^
C:\Users\Moris\Desktop\Nuevito\Nuevito.ino:112:31: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]
else if (receivedChars == 514 ) {
^
C:\Users\Moris\Desktop\Nuevito\Nuevito.ino:117:44: warning: invalid conversion from 'char*' to 'uint16_t {aka short unsigned int}' [-fpermissive]
trellis.setPixelColor(receivedChars , a);
^
In file included from C:\Users\Moris\Desktop\Nuevito\Nuevito.ino:1:0:
C:\Users\Moris\Documents\Arduino\libraries\Adafruit_seesaw_Library/Adafruit_NeoTrellis.h:82:8: note: initializing argument 1 of 'void Adafruit_MultiTrellis::setPixelColor(uint16_t, uint32_t)'
void setPixelColor(uint16_t num, uint32_t color);
^
you could send a value of 600 as 2 bytes. but now you need a way to delimit those bytes from others being sent
another approach is to simply send the value as an ascii string with a recognizable line termination such as '\n' using readBytesUntil(), for example. the teensy then needs to translate the string to an integer using atoi(), for example
consider
bear in mind, an integer variable is being printed, not the received c-string
char s [80];
int val;
void loop() {
if (Serial.available()) {
int n = Serial.readBytesUntil ('\n', s, sizeof(s));
s [n] = 0;
val = atoi (s);
Serial.println (val);
}
}
void setup() {
Serial.begin(9600);
}
This will work as long as the message itself never contains newlines. A more robust choice could be 0x03 (end of text) or 0x04 (end of transmission), to stick with the ASCII standard.
I am not sure what you mean by this. Which 2 bytes? Just the number itself in binary (MSB then LSB)?
Receiving 2 bytes will always be faster than receiving 4 bytes [e.g."512\n"] but you then have the issue of figuring out if you get out of sync and start receiving LSB then MSB which means you need some sort of marker again and since you are receiving binary, you could theoretically receive any value 0x00 - 0xFF so there is no safe marker to use.
IF speed is really an issue, you can always bump your baud rate to 115200 or higher
the 3rd argument is the size of the array to insure that it doesn't overflow.
if you're receiving a ascii string, you want to receive the complete string using the terminator, 1st argument, to know when it is complete
if you're receiving an ascii string representing an integer, such as 600, there are 3 ascii bytes. a 16-bit integer can represent a value of 65535, which is 5 ascii characters. atoi() will translate the c-string to a 2 byte integer
it's returning the # of characters received. the received string in the array passed as the 2nd argument.
maybe there's a misunderstanding about sending the data as an ascii c-string. is there?