{"id":33860,"date":"2020-06-18T11:02:13","date_gmt":"2020-06-18T03:02:13","guid":{"rendered":"\/blog\/?p=33860"},"modified":"2020-06-18T11:02:15","modified_gmt":"2020-06-18T03:02:15","slug":"arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m","status":"publish","type":"post","link":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/","title":{"rendered":"Arduino Jeston Nano \/ Xavier NX Communication using Python via USB"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>When working on Arduino project with <a rel=\"noreferrer noopener\" aria-label=\"Jetson Nano (opens in a new tab)\" href=\"https:\/\/www.seeedstudio.com\/NVIDIA-Jetson-Nano-Development-Kit-B01-p-4437.html\" target=\"_blank\">Jetson Nano<\/a> or <a href=\"https:\/\/www.seeedstudio.com\/NVIDIA-Jetson-Xavier-NX-Developer-Kit-p-4573.html\">Jetson Xavier NX<\/a>, 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 <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/www.seeedstudio.com\/Wio-Terminal-p-4509.html\" target=\"_blank\">Wio Terminal<\/a> or an <a rel=\"noreferrer noopener\" aria-label=\"ethernet shield (opens in a new tab)\" href=\"https:\/\/www.seeedstudio.com\/W5500-Ethernet-Shield.html\" target=\"_blank\">ethernet shield<\/a> 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. <\/p>\n\n\n\n<p>Firstly, connect your Arduino with Jetson Nano through USB cable. Then open the terminal on Jeston Nano. Type in the following command.<\/p>\n\n\n\n<p><code>ls \/dev\/ttyA*<\/code><\/p>\n\n\n\n<p>If you get <code>\/dev\/ttyACM0<\/code>, 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&#8217;s try to communicate with Arduino. Firstly, install <a rel=\"noreferrer noopener\" aria-label=\"PySerial (opens in a new tab)\" href=\"https:\/\/pythonhosted.org\/pyserial\/\" target=\"_blank\">PySerial<\/a> using the command <code>pip3 install pyserial<\/code>. I&#8217;m using python3, so my command is pip3. You should use pip if you are using python2.<\/p>\n\n\n\n<p>After the installation of PySerial, give it a test first. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"939\" height=\"176\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-46.png\" alt=\"\" class=\"wp-image-33868\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/06\/image-46.png 939w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/06\/image-46-300x56.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/06\/image-46-768x144.png 768w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/06\/image-46-936x176.png 936w\" sizes=\"(max-width: 939px) 100vw, 939px\" \/><\/figure>\n\n\n\n<p>If everything works fine, we can proceed to the next step. Now let&#8217;s start coding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Arduino Side<\/h3>\n\n\n\n<div style=\"background: #f8f8f8;overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em\"><table><tbody><tr><td><pre style=\"margin: 0;line-height: 125%\"> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12<\/pre><\/td><td><pre style=\"margin: 0;line-height: 125%\"><span style=\"color: #00BB00;font-weight: bold\">void<\/span> <span style=\"color: #00A000\">setup<\/span>()\n{\n  Serial.begin(<span style=\"color: #666666\">119200<\/span>);\n}\n\n<span style=\"color: #00BB00;font-weight: bold\">void<\/span> <span style=\"color: #00A000\">loop<\/span>()\n{\n  <span style=\"color: #AA22FF;font-weight: bold\">if<\/span> (Serial.available())\n  {\n    Serial.println(<span style=\"color: #BB4444\">\"Hello Jetson!\"<\/span>);\n  }\n}\n<\/pre><\/td><\/tr><\/tbody><\/table><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Python Side<\/h3>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f8f8f8;overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em\"><table><tr><td><pre style=\"margin: 0;line-height: 125%\"> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12\n13\n14<\/pre><\/td><td><pre style=\"margin: 0;line-height: 125%\"><span style=\"color: #AA22FF;font-weight: bold\">import<\/span> <span style=\"color: #0000FF;font-weight: bold\">serial<\/span> \n<span style=\"color: #AA22FF;font-weight: bold\">import<\/span> <span style=\"color: #0000FF;font-weight: bold\">time<\/span>\n\narduino <span style=\"color: #666666\">=<\/span> serial<span style=\"color: #666666\">.<\/span>Serial(<span style=\"color: #BB4444\">&#039;\/dev\/ttyACM0&#039;<\/span>, <span style=\"color: #666666\">115200<\/span>, timeout<span style=\"color: #666666\">=1<\/span>)\n\n\n<span style=\"color: #AA22FF;font-weight: bold\">while<\/span> <span style=\"color: #AA22FF;font-weight: bold\">True<\/span>:\n    <span style=\"color: #AA22FF;font-weight: bold\">try<\/span>:\n        data <span style=\"color: #666666\">=<\/span> arduino<span style=\"color: #666666\">.<\/span>readline()\n        <span style=\"color: #AA22FF;font-weight: bold\">if<\/span> data:\n            <span style=\"color: #AA22FF\">print<\/span>(data)\n            <span style=\"color: #AA22FF\">print<\/span>(<span style=\"color: #BB4444\">&#039;Hi Arduino&#039;<\/span>)\n    <span style=\"color: #AA22FF;font-weight: bold\">except<\/span>:\n        arduino<span style=\"color: #666666\">.<\/span>close() \n<\/pre><\/td><\/tr><\/table><\/div>\n\n\n\n\n<p>Remember to set the baud rate as the same as Arduino. Name the python file as <code>test.py<\/code>. Then use <code>sudo<\/code> to run the code, otherwise, you&#8217;ll be denied permission. Now you can make Jetson and Arduino talk to each other!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"885\" height=\"344\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-47.png\" alt=\"\" class=\"wp-image-33880\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/06\/image-47.png 885w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/06\/image-47-300x117.png 300w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/06\/image-47-768x299.png 768w\" sizes=\"(max-width: 885px) 100vw, 885px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When working on Arduino project with Jetson Nano or Jetson Xavier NX, sometimes we need<\/p>\n","protected":false},"author":3485,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","_price":"","_stock":"","_tribe_ticket_header":"","_tribe_default_ticket_provider":"","_tribe_ticket_capacity":"0","_ticket_start_date":"","_ticket_end_date":"","_tribe_ticket_show_description":"","_tribe_ticket_show_not_going":false,"_tribe_ticket_use_global_stock":"","_tribe_ticket_global_stock_level":"","_global_stock_mode":"","_global_stock_cap":"","_tribe_rsvp_for_event":"","_tribe_ticket_going_count":"","_tribe_ticket_not_going_count":"","_tribe_tickets_list":"[]","_tribe_ticket_has_attendee_info_fields":false,"iawp_total_views":0,"footnotes":""},"categories":[1],"tags":[6,1825,3198,1339],"class_list":["post-33860","post","type-post","status-publish","format-standard","hentry","category-news","tag-arduino","tag-jetson-nano-developer-kit","tag-nvidia-jetson-xavier-nx","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Arduino Jeston Nano \/ Xavier NX Communication using Python via USB - Latest News from Seeed Studio<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arduino Jeston Nano \/ Xavier NX Communication using Python via USB - Latest News from Seeed Studio\" \/>\n<meta property=\"og:description\" content=\"When working on Arduino project with Jetson Nano or Jetson Xavier NX, sometimes we need\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/\" \/>\n<meta property=\"og:site_name\" content=\"Latest News from Seeed Studio\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-18T03:02:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-06-18T03:02:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-46.png\" \/>\n<meta name=\"author\" content=\"ericyu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ericyu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/\",\"url\":\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/\",\"name\":\"Arduino Jeston Nano \/ Xavier NX Communication using Python via USB - Latest News from Seeed Studio\",\"isPartOf\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-46.png\",\"datePublished\":\"2020-06-18T03:02:13+00:00\",\"dateModified\":\"2020-06-18T03:02:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/c1f0264a6ad9ba995b2367e06fd70ec9\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#primaryimage\",\"url\":\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-46.png\",\"contentUrl\":\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-46.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.seeedstudio.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arduino Jeston Nano \/ Xavier NX Communication using Python via USB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#website\",\"url\":\"https:\/\/www.seeedstudio.com\/blog\/\",\"name\":\"Latest News from Seeed Studio\",\"description\":\"Emerging IoT, AI and Autonomous Applications on the Edge\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.seeedstudio.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/c1f0264a6ad9ba995b2367e06fd70ec9\",\"name\":\"ericyu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eb22f677db332dc286108258a6b7f324?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eb22f677db332dc286108258a6b7f324?s=96&r=g\",\"caption\":\"ericyu\"},\"url\":\"https:\/\/www.seeedstudio.com\/blog\/author\/ericyu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Arduino Jeston Nano \/ Xavier NX Communication using Python via USB - Latest News from Seeed Studio","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/","og_locale":"en_US","og_type":"article","og_title":"Arduino Jeston Nano \/ Xavier NX Communication using Python via USB - Latest News from Seeed Studio","og_description":"When working on Arduino project with Jetson Nano or Jetson Xavier NX, sometimes we need","og_url":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/","og_site_name":"Latest News from Seeed Studio","article_published_time":"2020-06-18T03:02:13+00:00","article_modified_time":"2020-06-18T03:02:15+00:00","og_image":[{"url":"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-46.png","type":"","width":"","height":""}],"author":"ericyu","twitter_card":"summary_large_image","twitter_misc":{"Written by":"ericyu","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/","url":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/","name":"Arduino Jeston Nano \/ Xavier NX Communication using Python via USB - Latest News from Seeed Studio","isPartOf":{"@id":"https:\/\/www.seeedstudio.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#primaryimage"},"image":{"@id":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-46.png","datePublished":"2020-06-18T03:02:13+00:00","dateModified":"2020-06-18T03:02:15+00:00","author":{"@id":"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/c1f0264a6ad9ba995b2367e06fd70ec9"},"breadcrumb":{"@id":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#primaryimage","url":"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-46.png","contentUrl":"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/06\/image-46.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.seeedstudio.com\/blog\/2020\/06\/18\/arduino-jeston-nano-xavier-nx-communication-using-python-via-usb-m\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.seeedstudio.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Arduino Jeston Nano \/ Xavier NX Communication using Python via USB"}]},{"@type":"WebSite","@id":"https:\/\/www.seeedstudio.com\/blog\/#website","url":"https:\/\/www.seeedstudio.com\/blog\/","name":"Latest News from Seeed Studio","description":"Emerging IoT, AI and Autonomous Applications on the Edge","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.seeedstudio.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/c1f0264a6ad9ba995b2367e06fd70ec9","name":"ericyu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eb22f677db332dc286108258a6b7f324?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eb22f677db332dc286108258a6b7f324?s=96&r=g","caption":"ericyu"},"url":"https:\/\/www.seeedstudio.com\/blog\/author\/ericyu\/"}]}},"modified_by":"ericyu","views":18980,"featured_image_urls":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":"","visody_icon":"","magazine-7-slider-full":"","magazine-7-slider-center":"","magazine-7-featured":"","magazine-7-medium":"","magazine-7-medium-square":""},"author_info":{"display_name":"ericyu","author_link":"https:\/\/www.seeedstudio.com\/blog\/author\/ericyu\/"},"category_info":"<a href=\"https:\/\/www.seeedstudio.com\/blog\/category\/news\/\" rel=\"category tag\">News<\/a>","tag_info":"News","comment_count":"0","_links":{"self":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts\/33860","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/users\/3485"}],"replies":[{"embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/comments?post=33860"}],"version-history":[{"count":2,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts\/33860\/revisions"}],"predecessor-version":[{"id":33881,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts\/33860\/revisions\/33881"}],"wp:attachment":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/media?parent=33860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/categories?post=33860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/tags?post=33860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}