When working on Arduino project with Jetson Nano or Jetson Xavier NX, sometimes we need to retrieve data from the Arduino or send a command to control the MCU. You can surely use Arduino compatible boards with onboard WiFi and BLE, like Wio Terminal or an ethernet shield to communicate with Jetson Nano through the network. But you can also adopt a much easier way, which is to talk to your Arduino simply via USB using Python.
Firstly, connect your Arduino with Jetson Nano through USB cable. Then open the terminal on Jeston Nano. Type in the following command.
If you get
/dev/ttyACM0, it means your Arduino is recognized by your Jetson Nano because ttyACM0 will only show up when 2 USB devices are connected to each other. Now let’s try to communicate with Arduino. Firstly, install PySerial using the command
pip3 install pyserial. I’m using python3, so my command is pip3. You should use pip if you are using python2.
After the installation of PySerial, give it a test first.
If everything works fine, we can proceed to the next step. Now let’s start coding.
Remember to set the baud rate as the same as Arduino. Name the python file as
test.py. Then use
sudo to run the code, otherwise, you’ll be denied permission. Now you can make Jetson and Arduino talk to each other!