About "Ardino serial.print() by ESP32"

NY20200803
Posts: 29
Joined: Sun Aug 09, 2020 2:27 am

About "Ardino serial.print() by ESP32"

Postby NY20200803 » Sun Aug 09, 2020 2:36 am

UART in your ESP32
"U0TXD (PIN NO 41)and U0RXD(PIN NO 40)"
I found "U1TXD(PIN NO 29) and U1RXD(PIN NO 28)".
Please tell me how to transfer each port of UART in Ardino serial print.
Example From two channels Seriarl. I want to exchange communication with Print.
Example 1 First channel. .. I would like to use it for writing Ardino.
Second channel. ..
I want to connect the device to the ESP32 and exchange them by communication.

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: About "Ardino serial.print() by ESP32"

Postby ESP_Sprite » Sun Aug 09, 2020 6:19 pm

Moved to the Arduino subforum

NY20200803
Posts: 29
Joined: Sun Aug 09, 2020 2:27 am

Re: About "Ardino serial.print() by ESP32"

Postby NY20200803 » Tue Aug 11, 2020 11:26 pm

Check various things
U2RX and U2TX
as follows
If you make a program
I know it works, but
The following questions arose.

Q

Communication between ESP32-WROOM-32 and ESP32-WROOM-32D

U2TX IO17
U2RX IO16
Wired each other.
And I wrote the following program.
TX only outputs waveform
It does not come out correctly.

Both speed and waveform voltage are different
Of course, I do not receive it either.


The problem is that you connect it directly to the wiring?
No pull-up resistor or pull-down resistor is connected.

Or is it a program?

program
Both wrote the same thing.

/*
* There are three serial ports on the ESP known as U0UXD, U1UXD and U2UXD.
*
* U0UXD is used to communicate with the ESP32 for programming and during reset/boot.
* U1UXD is unused and can be used for your projects. Some boards use this port for SPI Flash access though
* U2UXD is unused and can be used for your projects.
*
*/

#define RXD2 16
#define TXD2 17

void setup() {
// Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
Serial.begin(115200);
//Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial.println("Serial Txd is on pin: "+String(TX));
Serial.println("Serial Rxd is on pin: "+String(RX));
}

void loop() { //Choose Serial1 or Serial2 as required
Serial2.write("12");
while (Serial2.available()) {
int a=Serial2.read();
Serial.print(a);
}
}

NY20200803
Posts: 29
Joined: Sun Aug 09, 2020 2:27 am

Re: About "Ardino serial.print() by ESP32"

Postby NY20200803 » Sun Aug 16, 2020 2:12 pm

Edit the program you received on the support forum
When I moved it, it worked.
Communication failure has been cured.
Cause
Between devices that communicate
This is because the power supply (3.3V) and GND wiring were not common.

feedback
Besides
It is also necessary to note that you have to wire so that it becomes "Wiring at the intersection like RX-TX TX-RX".

If you think about this and work
I think that the above program can be controlled by UART2.

NY20200803
Posts: 29
Joined: Sun Aug 09, 2020 2:27 am

Re: About "Ardino serial.print() by ESP32" NEW QUESTION about Serial2.write

Postby NY20200803 » Mon Sep 14, 2020 9:41 pm

About  writing from ESP32 【Serial Write】
Mysterious thing
When controlling Serial Write
Finally [Serial2.write(0)]; OR as shown in the control below
It doesn't work properly.
This is because I am sending one character at a time
I think it will be [ Serial2.write(1);]
Duplicate letters or send strange numbers.
why?
PS
We are [ Serial2.write(-);] as the transmission content
I think it specifies the number of bytes to send.
In that case, one character should be sent as one byte.
It's different, so I was curious and asked a question.

Sample program
= =
for (int i = 0; i <sendstr.length (); i ++) {
Serial2.write (sendstr.charAt (i));
Serial.print (sendstr.charAt (i));
delay (500);
}
Serial2.write (0);


Write when Serial2.write (); is set to 0
Sometimes it's strange to set Serial2.write (); to 1.
Transfer is not possible if Serial2.write (); is set to 2.

lbernstone
Posts: 828
Joined: Mon Jul 22, 2019 3:20 pm

Re: About "Ardino serial.print() by ESP32"

Postby lbernstone » Mon Sep 14, 2020 11:47 pm

https://www.arduino.cc/reference/en/lan ... ial/write/
Serial.write(0) sends a single 0x00.

mrburnette
Posts: 22
Joined: Mon Feb 12, 2018 6:50 pm

Re: About "Ardino serial.print() by ESP32"

Postby mrburnette » Sun Sep 20, 2020 9:55 pm

Serial.print(""); of course works, but honors the serial protocol:
https://www.deviceplus.com/arduino/ardu ... -tutorial/

Previous issues have been resolved:
https://github.com/espressif/arduino-esp32/issues/1219

Sample useage:

Code: Select all

void setup() {
 pinMode(25, OUTPUT); //Send success, LED will bright 1 second
 pinMode(16, OUTPUT);
 digitalWrite(16, LOW); // set GPIO16 low to reset OLED
 delay(50);
 digitalWrite(16, HIGH);
 Serial.begin(115200);
 while (!Serial); //If just the the basic function, must connect to a computer
 // Initialising the UI will init the display too.
 display.init();
 display.flipScreenVertically();
 display.setFont(ArialMT_Plain_10);
 display.setTextAlignment(TEXT_ALIGN_LEFT);
 display.drawString(5, 5, "LoRa Sender");
 display.display();
 SPI.begin(5, 19, 27, 18);
 LoRa.setPins(SS, RST, DI0);
 Serial.println("LoRa Sender");
 if (!LoRa.begin(BAND)) {
   Serial.println("Starting LoRa failed!");
   while (1);
 }
 Serial.println("LoRa Initial OK!");
 display.drawString(5, 20, "LoRa Initializing OK!");
 display.display();
 delay(2000);
}

NY20200803
Posts: 29
Joined: Sun Aug 09, 2020 2:27 am

Re: About "Ardino serial.print() by ESP32"

Postby NY20200803 » Wed Sep 30, 2020 11:20 pm

Question 1

Thank you for contacting me.


This is a confirmation.
Look for a sample program on the site,
I didn't really understand it because it was moving and working.


At first
Because the string 0 is not written correctly
It is written as '0'.

Inquired this time
Is it safe to assume that Serial.write (0); had the next role?


The last after sending on the serial writing side

Serial.write (0); sends 0x00 as a single
As
When reading
Character conversion is performed with "Char".

After this
On the reading side
if (data ==' 0') {


as
The character string of 0 is judged and the process ends.

Therefore
Last sent
Serial.write (0);
In the current role
Is it correct to interpret that the transmission was completed?

Program example
Write side

In the void loop () function


for (int i = 0; i <sendstr.length (); i ++) {
Serial2.write (sendstr.charAt (i));
Serial.print (sendstr.charAt (i));
delay (500);
}


Serial2.write (0);

Reading side


if (Serial2.available ()> 0)
{
char inChar = char (Serial2.read ());
buffA [counter] = inChar;
counter ++;
if (inChar ==' 0')
{



Question 2
In Arduino
With UART2
To another device
When sending
Can I use the "SerialPrint" function?

Please tell us about this as well.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 96 guests