Report
1 week, 1 day ago.

Print on serial monitor string and char var.

Good morning programmers! Can you help me on how I can correct this code? I am trying to send that string of characters but the result is not what I expect, I think it is because of the conflict of variables when using the printf command, I'm not sure and I do not know how to correct that error. Please help!!!

Annex the code in which I am working:

#include "mbed.h"
#include <string

Serial USB(USBTX, USBRX);

void enviaDato(int id, int canal, int dato) {
  string comando = "add ";
  comando += id;
  comando += ",";
  comando += canal;
  comando += ",";
  comando += dato;
  comando += "\xFF\xFF\xFF";
  USB.printf(comando.c_str());
}

int main(){
 
 USB.baud(115200);

    for (int i=0; i<50; i++) {
      enviaDato(1,0,i);
     //Serial.println(i);
      enviaDato(1,1,i+100);
      wait(0.020);
    }
}

P.d: I am working on a program that communicates a stm32F446re card with a nextion display.

Comment on this question

1 Answer

5 days, 20 hours ago.

Hello Alexander,

The following might help get started

#include "mbed.h"

Serial usb(USBTX, USBRX);

void enviaDato(int id, int canal, int dato) {
  usb.printf("add %d,%d,%d\\xFF\\xFF\\xFF\r\n", id, canal, dato);
}

int main(){
 
 usb.baud(115200);

    for (int i=0; i<50; i++) {
      enviaDato(1,0,i);
      enviaDato(1,1,i+100);
      wait(0.020);
    }
}

Hello Zoltan, thanks for your help!!!

posted by Alexander Sacaquirin 05 Dec 2018

To post an answer, please log in.