Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15317

Can i SerialPort.write(String)?

$
0
0

Hi
I have been trying to send some Strings using rx tx communication.
If I use SerialPort.write i cant send strings unless i write SerialPort.write("something").
I cant use already nominated strings to send.

This is the code of the master(sender):

#include <HardwareSerial.h>

HardwareSerial SerialPort(2);  // use UART2

int numero;
int numero1;
String number;
int number1;

void setup() {
  Serial.begin(115200);
  SerialPort.begin(115200, SERIAL_8N1, 17, 16);
}
void loop() {
  delay(2500);
  number = "143";
  SerialPort.write(number);
  /*
  delay(2500);
  numero = 110;
  numero1 = 165;
  SerialPort.write(numero, numero1);*/
}

And this is the code of the Slave(receiver):

#include <HardwareSerial.h>

HardwareSerial SerialPort(2);  // use UART2

int num;
String number;
String numb1;
String numb2;

void setup() {
  Serial.begin(115200);
  SerialPort.begin(115200, SERIAL_8N1, 17, 16);
}
void loop() {
  if (SerialPort.available()) {
    number = SerialPort.readString();
    Serial.println(number);
    /*
    numb1 = number.substring(0, 3);
    Serial.println(numb1);
    numb2 = number.substring(4, 7);
    Serial.println(numb2);
    */
  }
}

5 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 15317

Trending Articles