<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Azzamjiul</title>
    <description>The latest articles on DEV Community by Azzamjiul (@azzamjiul).</description>
    <link>https://dev.to/azzamjiul</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F426543%2F434e5c77-f50a-43d5-a6bc-4a01321c5322.png</url>
      <title>DEV Community: Azzamjiul</title>
      <link>https://dev.to/azzamjiul</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/azzamjiul"/>
    <language>en</language>
    <item>
      <title>How to automatically connecting Arduino  using serial-port in NodeJS</title>
      <dc:creator>Azzamjiul</dc:creator>
      <pubDate>Sat, 12 Sep 2020 00:49:46 +0000</pubDate>
      <link>https://dev.to/azzamjiul/how-to-connect-to-arduino-automatically-using-serial-port-in-nodejs-plh</link>
      <guid>https://dev.to/azzamjiul/how-to-connect-to-arduino-automatically-using-serial-port-in-nodejs-plh</guid>
      <description>&lt;p&gt;&lt;a href="https://serialport.io"&gt;serial-port package&lt;/a&gt; in NodeJS is an awesome tool. You can communicate with hardware like Arduino only with JavaScript. Here, i will show you how to automatically connected with plugged Arduino without specify the port that used. All you need is node installed application with serial-port package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const SerialPort = require('serialport')

let path = ''
let ArduinoPort = ''

// Promise approach
SerialPort.list().then(ports =&amp;gt; {
  let done = false
  let count = 0
  let allports = ports.length
  ports.forEach(function(port) {
    count = count+1
    pm  = port.manufacturer

    if (typeof pm !== 'undefined' &amp;amp;&amp;amp; pm.includes('arduino')) {
      path = port.path
      ArduinoPort = new SerialPort(path, { baudRate: 115200 })
      ArduinoPort.on('open', function(){
        console.log(`connected! arduino is now connected at port ${path}`)
      })
      done = true
    }

    if(count === allports &amp;amp;&amp;amp; done === false){
      console.log(`can't find any arduino`)
    }
  })
})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;i wrote the code in portList.js file in enose-desktop-application node application directory. So, if i want to run it i typed commad&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node portList.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Here the result
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SjwOOot8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8wtcw3d5rstfbk0ezwv0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SjwOOot8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8wtcw3d5rstfbk0ezwv0.png" alt="Results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all. I hope it will help you to solve the problem. any suggestion are welcome :)&lt;/p&gt;

</description>
      <category>serailport</category>
      <category>arduino</category>
      <category>node</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
