I want to transmit data from ESP32 cam to my PC using serial port. I want to use pyserial to capture data on PC. Right now I am having a very simple loop printing "hello world" from ESP32 cam like this:
#include "Arduino.h"
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print("Hello World!\n");
delay(500);
}
I can see hello world after selecting the port(COM9) at the serial monitor. However, when I am using pyserial in Python like this:
import serial, time
import sys
if __name__ == '__main__':
if len(sys.argv) != 3:
print("python script serial_port baudrate")
print("python -m serial.tools.list_ports")
exit()
port_name = sys.argv[1]
baud = sys.argv[2]
ser = serial.Serial(port_name, baudrate= baud, timeout = 2)
print("serial connected")
while True:
value = ser.readline()
print("serial read")
line = str(value, encoding="UTF-8")
print(line)
I can connect to the port(COM9), but nothing is captured(time out and no bytes read). I tried this python program on serial input from other microcontroller(MSP432P401R), and I can capture data properly. I am setting both end to be default like 8N1 and the same baudrate for UART. Does serial monitor have some special setting with UART?
@elberto I tried your Arduino code with your Python code on a Win 11 desktop.
I loaded the c/c++ code onto the ESP32 (not an ESP32 cam)
I named the Python file "cmd_line.py" and using Command Prompt I navigated to the file location. I then ran the Python file like this python cmd_line.py "COM9" 9600
Do you see any errors or anything different about the way I am doing it?
Thanks for trying it out. Yes, that's pretty much what I did, except I am using ESP32 cam of course. I didn't encounter any error, just no data from the port. Maybe there is something different on the UART pins of the ESP32 cam.