Hi, I am seeking for help related to data communication with a uart module. The module was connected via RX0 and TX1 pins, however when I am trying to send data with Serial.write(...), the program just cannot upload to the board at all. Was it because of code uploading also need to use Serial via USB? Or something else?
This is the code:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600, SERIAL_5E1);
delay(1000);
Serial.write(0xFE);
Serial.write(0xFD);
Serial.write(0x01);
Serial.write(0x01);
}
Thank you for your reply. I am just playing with a serial VFD display. But have no idea what board to use. Maybe it is better to choose a board with extra serial pins?
If you are using UNO or NANO, then you can use Software UART Port (SUART Port) to communicate with your VFD Display Unit leaving the UART Port (RX0/TX1) for IDE/SM. You must know the following parameters of your VFD Display Unit in order to initialie the SUART Port accordingly.
SoftwareSerial only supports 8N1. There are no constructors or methods to use 5E1.
So you will need a board with a processor that gives additional UARTs. With (kind of) the same form factor as the classic Nano, you can use the Arduino Micro, Arduino Nano Every or SparkFun Pro Micro.
If form factor is not important, you can use an Arduino Mega.
There are more boards but they are 3.3V boards instead of 5V boards.
Alternatively you can check the other libraries mentioned by @jremington and check if they support the needed serial format.
I have expected that the OP will confirm explicity that the Serial frame structure of his target devicee is the following. Hope that the OP will confirm it this time.
Bd = 9600
Character Lenghth = 5
Parity Option = Even
Stop Bit = 1
Got it, I will try to find the right config info from the manufacturer. And I think another problem is I did not give enough power to the module (in which case I connect the vcc directly to arduino board)
#include <HardwareSerial.h>
#define TX2 17 // TX Pin on ESP32
#define RX2 16 // RX Pin on ESP32
HardwareSerial UART(1);
void setup() {
// put your setup code here, to run once:
// This Serial is to log essential information
Serial.begin(115200);
Serial.println("Program started");
//Serial2.begin(9600, SERIAL_8E1, RX2, TX2);
// This is to control the VFD Display through UART port (RX2 & TX2) on ESP32
UART.begin(9600, SERIAL_8E1, RX2, TX2); // baud, config (8bit data + Even parity + 1 stop bit), rx_pin, tx_pin
// hour data (display 10 here)
UART.write(0xFE);
UART.write(0xFD);
UART.write(0x02);
UART.write(0x0A);
// minute data (display 56 here)
UART.write(0xFE);
UART.write(0xFD);
UART.write(0x03);
UART.write(0x38);
// : on
UART.write(0xFE);
UART.write(0xFD);
UART.write(0x04);
UART.write(0x01);
}
void loop() {
// put your main code here, to run repeatedly:
if (UART.available() > 0) {
char c = UART.read();
Serial.print(c);
}
}