On a PC I set up an Arduino Mega 2560 R3 to send out serial data. I verified it was working using PUTTY on the laptop.
From a terminal on the Nano I run dmesg --follow and when I plug in the USB cable it prints ttyACM): USB ACM device
I run this code on the Nano. It runs but prints out Serial incoming data: b’’ (or if I use readlines).
The Nano seems to see the device correctly. I tried all 4 USB ports with no luck and they all work with cameras and keyboard. Any suggestions are greatly appreciated. Seems like a simple problem but I haven’t seen the cause and solution after a lot of searching.
import serial, sys
from serial import SerialException
Install using pip3 install --user pyserial
if name == “main”:
serial_comm = serial.Serial()
# Configure the baud rate and it should be equal to the Arduino code serial communication baud rate
serial_comm.baudrate = 9600
# Configure the COM port as needed ‘/dev/ttyXXXX’ is applicable for Linux systems
serial_comm.port = ‘/dev/ttyACM0’
#Configure timeout seconds
serial_comm.timeout = 10
try:
serial_comm.open()
except serial.SerialException:
# Print an error when the serial communication isn’t available
print (“Could not open port”)
while (True):
if serial_comm.isOpen():
print (“Serial Incoming Data: {}”.format(serial_comm.readline()))
else:
print (“Exiting”)
break
sys.exit()