Closed orhanapaydin closed 3 weeks ago
You mean this menu?
Connection define command source USB or SERIAL
SERIAL SPEED - USART serial speed
All options stored in config, so use save config after change
Send any shell command, receive answer, parse answer You can use scan command: scan {start(Hz)} {stop(Hz)} [points] [outmask]
Outmask:
0b101 - outmask (receive frequency and S21 data)
scan 10000 20000 101 0b101 Answer example: 10.362 tx: scan 10000 20000 101 0b101 10.365 rx: scan 10000 20000 101 0b101 10.546 rx: 10000 0.000022667 -0.000046399 10.548 rx: 10100 -0.000056518 -0.000155888
I have configured the NanoVNA to use SERIAL mode with a baud rate of 115200 and have created the following code to send commands and display the data on a TFT screen:
// Screen and UART settings
// TFT screen and UART objects TFT_eSPI tft = TFT_eSPI(); // TFT screen object
void send_command(const String& cmd) { Serial.write(cmd.c_str()); // Send the command through the main serial port delay(50); // This delay is adjustable to allow for empty lines to pass }
void display_message(const String& message) { tft.setCursor(10, 10); tft.fillScreen(TFT_BLACK); // Clear the screen tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set text color to white with black background tft.setTextSize(1); // Set text size tft.println(message); // Print the message to the screen }
void setup() { Serial.begin(115200); delay(50); // Allow time for the serial connection to stabilize
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK); // Clear the screen to black
tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set text color to white with black background
tft.setTextSize(1); // Set text size
tft.println("Starting up..."); // Print startup message to the screen
delay(2000); // Wait for 2 seconds
tft.fillScreen(TFT_BLACK); // Clear the screen to black
}
void loop() {
send_command("scan 10000 20000 51 0b00000001");
String message = "";
while (Serial.available() > 0) {
char c = Serial.read(); // Read incoming character
message += c; // Append character to the message
delay(10); // Wait to ensure all data is received
}
if (message.length() > 0) {
display_message(message);
}
delay(2000); // Slow down the loop a bit
}
------------------------------------------------------------- end code section
However, the TFT display does not show any frequency data. The display_message function should clear the screen and print the incoming serial data, but nothing appears on the display. Are there any specific things I should check or adjust to ensure the data is properly received and displayed?
Tx pin on NanoVNA connected to Arduino Rx pin Rx pin on NanoVNA connected to Arduino Tx pin Gnd to Gnd Correct?
Need add carriage return at end command send_command("scan 10000 20000 51 0b00000001\r\n");
This command return only frequency list
I connected the NanoVNA to esp32 like that. I use the USB cable to data communication (so I configured the NanoVNA to use USB mode ).
Fixed my code according to your suggestion ("\r\n"), but result is same.
You connect NanoVNA as host USB? NanoVNA not allow USBH mode, only USBD (usb device)
I also don't understand where you are sending the request, ESP32 acts as a USB bus controller and accesses NanoVNA as a USB CDC device?
I connected the NanoVNA directly to the ESP32 via USB, powered the ESP32 through the circuit using an external 5V source, and ran the setup. The code I wrote at the top sends requests from the ESP32 to the NanoVNA. My expectation is for the NanoVNA to respond as requested and for the ESP32 to display the received response on the screen.
I got it, and I assume you're doing something wrong. NanoVNA is a USB CDC device
Connect it to your computer, use any terminal program (Putty for example)? open NanoVNA COM port, send a request and you'll get a response.
I don't see anything like that in your code
The Serial library is used, I'll just assume that your device is not a controller in this mode, it works the same way as NanoVNA expects someone to control it (work in USBD mode, not host)
I understand. I will try to control the NanoVNA with another device like Arduino (connect Tx pin to Tx, Rx pin to Rx, GNG to GNG). I will share my results.
connect Tx pin to Tx, Rx pin to Rx
NOPE! Tx
-> Rx
and Rx
<- Tx
Just understand what these names mean: Tx
(Transmit) is an output and Rx
(Receive) is an input.
EDIT:
Or familiarise yourself with the communication on the PC, e.g. with the highly commented tool nanovna_communication_template.py. It should work with a minimal python installation on any OS. When the easy USB communication works just switch the NanoVNA to serial and connect a USB to serial interface (FT232 or similar devices 3.3V! - NO RS232!) to the NanoVNA pins and use the same setup until it also works (the device autodetection does not work with serial communication, you must provide the port with option -d, e.g. -d COM3
on Windows or -d /dev/ttyUSB0
on Linux) - try not to run until you can safely stand on your feet!
Command line template to send a serial shell command to NanoVNA:
- Connect via USB serial
- Encode the command string to bytearray
- Send the command + CR
- Get the command echo + CRLF
- Get the response + CRLF + prompt
- Format the response (remove CRLF + prompt)
- Decode the response bytearray to string
- Write the response string to stdout
connect Tx pin to Tx, Rx pin to Rx
NOPE!
Tx
->Rx
andRx
<-Tx
Just understand what these names mean:
Tx
(Transmit) is an output andRx
(Receive) is an input.EDIT: Or familiarise yourself with the communication on the PC, e.g. with the highly commented tool nanovna_communication_template.py. It should work with a minimal python installation on any OS. When the easy USB communication works just switch the NanoVNA to serial and connect a USB to serial interface (FT232 or similar devices 3.3V! - NO RS232!) to the NanoVNA pins and use the same setup until it also works (the device autodetection does not work with serial communication, you must provide the port with option -d, e.g.
-d COM3
on Windows or-d /dev/ttyUSB0
on Linux) - try not to run until you can safely stand on your feet!Command line template to send a serial shell command to NanoVNA: - Connect via USB serial - Encode the command string to bytearray - Send the command + CR - Get the command echo + CRLF - Get the response + CRLF + prompt - Format the response (remove CRLF + prompt) - Decode the response bytearray to string - Write the response string to stdout
I have successfully received and displayed responses from the NanoVNA using Arduino by following the instructions in the code you provided, with the correct connection configuration (Tx -> Rx, Rx -> Tx). I was able to send the 'help' command from the Arduino to the NanoVNA and receive a response. However, I am working on some configuration and limit issues (related to the Arduino). Thank you for your assistance.
Hello,
I am working on a project where I need to establish a reliable serial communication between an Arduino and a NanoVNA. Specifically, I am using the NanoVNA H4 model and attempting to connect it via UART0 at a baud rate of 115200 to obtain S21 measurements and display them on a screen. I have a few questions regarding the connection options available under the Connection menu:
What is the exact purpose of the USB and serial connection options? How can I successfully establish a serial connection with the NanoVNA using an Arduino? Any guidance, sample code, or documentation that could help me achieve this would be greatly appreciated.