TD send serial data to arduino

i try to send chop data to arduino by serial
but i can’t…

a=int(op(‘merge1’)[‘v1’])
b=int(op(‘merge1’)[‘v2’])
c=int(op(‘merge1’)[‘v3’])

n = op ( ‘serial1’)
def onOffToOn(channel, sampleIndex, val, prev):
n.send(“a b c” , terminator="\n")

and here is arduino code
const int L1 = 5;
const int L2 = 6;
const int L3 = 7;

char buffer[66]; //maximum expected length
int len = 0;
void setup()
{
Serial.begin(9600);

}
void loop()
{
if (Serial.available() > 0)
{
int incomingByte = Serial.read();
buffer[len++] = incomingByte;
//
// check for overflow
//
if (len >= 66)
{
// overflow, resetting
len = 0;
}
//
// check for newline (end of message)
//
if (incomingByte == ‘\n’)
{
int s1, s2, s3;
int n = sscanf(buffer, “%d” “%d” “%d”, &s1, &s2, &s3);
if (n == 3)
{
digitalWrite(L1,s1);
digitalWrite(L2,s2);
digitalWrite(L3,s3);
}
else
{
// parsing error, reject
}
len = 0; // reset buffer counter
}
}
}

toucharduino.toe (4.9 KB)

I’m not in a place where I can open your TOE but currently you are sending the string “a b c” to the serial1 op, rather than the values of tha a,b, and c variables.

And in your Arduino code, add some Serial.print() commands in key places just to validate that the data is even reaching that point. Scale back the scope of your first attempt to just send one number, and once you’re sure that the communication is happening, expand the scope to include the full data and go from there.

i done
when i watch serial print, then i catch my mistake!
thank!

1 Like