{"id":2613,"date":"2020-04-17T12:16:07","date_gmt":"2020-04-17T10:16:07","guid":{"rendered":"http:\/\/www.ardpylab.fr\/?page_id=2613"},"modified":"2020-05-10T16:45:04","modified_gmt":"2020-05-10T14:45:04","slug":"communication-arduino-python-via-le-port-serie","status":"publish","type":"page","link":"https:\/\/www.ardpylab.fr\/?page_id=2613","title":{"rendered":"Communication via le port s\u00e9rie"},"content":{"rendered":"\n<h6><span style=\"color: #999999;\"><br \/>(<em>Cliquez pour afficher la version PDF)<\/em><\/span><\/h6>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pyserial.pdf\">Le port s\u00e9rie<\/a><a href=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pyserial.pdf\" class=\"wp-block-file__button\" download>T\u00e9l\u00e9charger<\/a><\/div>\n\n\n\n<p>\u00a0<\/p>\n<p>Python dispose d\u2019une biblioth\u00e8que appel\u00e9e, <strong>pyserial<\/strong>, qui permet d\u2019acc\u00e9der au port s\u00e9rie. Un programme en python, <strong>en remplacement du moniteur s\u00e9rie<\/strong>, pourra alors lui aussi lire ou \u00e9crire des donn\u00e9es via le port s\u00e9rie en utilisant cette biblioth\u00e8que.<\/p>\n<p>La biblioth\u00e8que <strong>\u201d<\/strong><strong>pyserial\u201d<\/strong> peut \u00eatre install\u00e9e via <strong>\u201d<\/strong><strong>pip\u201d <\/strong>(<a href=\"https:\/\/www.ardpylab.fr\/?page_id=2201\" data-wplink-url-error=\"true\">voir installation des modules<\/a>), \u00e0 l\u2019aide de la ligne de commande\u00a0:<\/p>\n<p style=\"padding-left: 40px;\"><strong>pip install pyserial<br \/><br \/><\/strong><\/p>\n<p>Pour utiliser la biblioth\u00e8que <strong>\u201d<\/strong><strong>pyserial\u201d <\/strong>dans un programme python, il faut\u00a0:<\/p>\n<p>&#8211; importer le module <strong>\u201d<\/strong><strong>serial\u201d<\/strong>, \u00e0 l\u2019aide de l\u2019instruction\u00a0: <strong>import serial<\/strong><\/p>\n<p><strong>&#8211; <\/strong>cr\u00e9er un objet <strong>\u201d<\/strong><strong>port s\u00e9rie\u201d<\/strong> et ouvrir le port avec la fonction <strong>\u201d<\/strong><strong>Serial\u201d <\/strong>en pr\u00e9cisant le port COM sur lequel l\u2019Arduino est connect\u00e9, la vitesse de transmission des donn\u00e9es (par exemple, 9600 baups) et \u00e9ventuellement le temps d\u2019attente en s pour la r\u00e9ception des donn\u00e9es (par exemple, timeout=1) :<\/p>\n<p style=\"padding-left: 40px;\"><strong>SerialPort = serial.Serial(\u201dCOM 5\u201d, baudrate=9600, timeout=1)<br \/><\/strong><\/p>\n<p><br \/>Une fois\u00a0 le port s\u00e9rie de l&rsquo;Arduino ouvert, il sera possible:<\/p>\n\n\n\n<p style=\"padding-left: 40px;\"><strong><span style=\"color: #000000;\">. <a style=\"color: #000000;\" href=\"https:\/\/www.ardpylab.fr\/?page_id=2674\" data-wplink-url-error=\"true\">de r\u00e9ceptionner des donn\u00e9es envoy\u00e9es depuis l\u2019Arduino par un programme Python,<\/a><\/span><\/strong><\/p>\n<p style=\"padding-left: 40px;\">. <span style=\"color: #000000;\"><a style=\"color: #000000;\" href=\"https:\/\/www.ardpylab.fr\/?page_id=2678\" data-wplink-url-error=\"true\"><strong>d&rsquo;<\/strong><strong>envoyer des donn\u00e9es par un programme Python vers l\u2019Arduino,<\/strong><\/a><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #000000;\"><strong>. <span style=\"color: #000000;\"><a style=\"color: #000000;\" href=\"https:\/\/www.ardpylab.fr\/?page_id=2683\" data-wplink-url-error=\"true\">de r\u00e9ceptionner et d&rsquo;envoyer des donn\u00e9es simultan\u00e9ment par un programme Python.<\/a><\/span><\/strong><\/span><\/p>\n<p>\u00a0<\/p>\n\n\n<div  class=\"grids-section grids-is-stretch\" style=\"--_gs-gap-desktop:0px 0px;--_gs-m-desktop:0 0 0 0;--_gs-p-desktop:0 0 0 0;--_gs-bg-desktop:transparent none;--_gs-bg-xp-desktop:0px;--_gs-zi-desktop:auto;--_gs-d-desktop:block;--_gs-mw-desktop:calc(100% - 0 - 0);--_gs-gap-tablet:0px 0px;--_gs-m-tablet:0 0 0 0;--_gs-p-tablet:0 0 0 0;--_gs-bg-tablet:transparent none;--_gs-bg-xp-tablet:0px;--_gs-zi-tablet:auto;--_gs-d-tablet:block;--_gs-mw-tablet:calc(100% - 0 - 0);--_gs-gap-mobile:0px 0px;--_gs-m-mobile:0 0 0 0;--_gs-p-mobile:0 0 0 0;--_gs-bg-mobile:transparent none;--_gs-bg-xp-mobile:0px;--_gs-zi-mobile:auto;--_gs-d-mobile:block;--_gs-mw-mobile:calc(100% - 0 - 0);--_gs-columns:2;--_gs-rows:1\"><div class=\"grids-s-w_i\">\n<div class=\"grids-area\" style=\"--_ga-column:1\/2;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=2587\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"28\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/moins.jpg\" alt=\"\" class=\"wp-image-107\"\/><\/a><\/figure><\/div>\n\n<\/div>\n\n<div class=\"grids-area\" style=\"--_ga-column:2\/3;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=2674\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"28\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/plus.jpg\" alt=\"\" class=\"wp-image-106\"\/><\/a><\/figure><\/div>\n\n<\/div>\n<\/div><\/div>\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>(Cliquez pour afficher la version PDF) \u00a0 Python dispose d\u2019une biblioth\u00e8que appel\u00e9e, pyserial, qui permet d\u2019acc\u00e9der au port s\u00e9rie. Un programme en python, en remplacement du moniteur s\u00e9rie, pourra alors lui aussi lire ou \u00e9crire des donn\u00e9es via le port s\u00e9rie en utilisant cette biblioth\u00e8que. La biblioth\u00e8que \u201dpyserial\u201d peut \u00eatre install\u00e9e via \u201dpip\u201d (voir installation [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2613","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/2613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2613"}],"version-history":[{"count":0,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/2613\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}