如何从c ++发送数据(整数)到Arduino?

时间:2017-11-24 10:45:07

标签: c++ arduino serial-port

请帮帮我。这是我的程序和输出。但是有这么多的噪音:

-168< \ 0 GT; ????????????????< \ B个?@ ?????????????????? ??< 15 - ; ???????????? @ ??< \ n> ???????? @ P< \ n> ???????? < \ 0 GT;< \ 0 GT;?℃下\ 0>< \ 0 GT; 13 C ???? LHM ??? O&LT 1个为卤素;?%LT; \ 0 GT; 12 O&LT 1个为卤素;? ??< \ 0 GT;&LT 21';&LT 2 - ;< \ 0 GT;< \ 0 GT; < \ 0 GT;< \ 0 GT;< \ 0 GT; X P&LT 1为卤素; ?????< \ B个;&LT 24每个;< \ 0 GT;< \ 0 GT;&LT 2 - ;&LT ; \ 0 GT;< \ 0 GT;< \ 0 GT;< \ 0 GT;< \ 0 GT;< \ 0 GT;

我的节目:

float yaw, pitch, roll;
quaternion.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&yaw, &pitch, &roll);
wzPrintf(20, 110, "Yaw:%d, Pitch:%d, Roll:%d", yaww, pitchh, rolll);
yaws = (int)RadToDegree(yaw);
pitchs = (int)RadToDegree(pitch);
rolls = (int)RadToDegree(roll);
yaww = (int)RadToDegree(yaw);
pitchh = (int)RadToDegree(pitch);
rolll = (int)RadToDegree(roll);
char out[10];
SerialPort arduino(port_name);
if (arduino.isConnected()) { wzPrintf(20, 130, "Connection established"); }
else wzPrintf(20, 130, "ERROR, check port name");
sprintf_s(out, "%d", yaww);
arduino.writeSerialPort(out, MAX_DATA_LENGTH);

1 个答案:

答案 0 :(得分:0)

不要发送整个缓冲区 我怀疑这应该这样做:

arduino.writeSerialPort(out, strlen(out));