# Problems connecting to USB serialport from container

**URL:** <https://forums.balena.io/t/problems-connecting-to-usb-serialport-from-container/24>\
**Category:** Product support\
**Created:** [March 10, 2015, 10:17am UTC](https://forums.balena.io/t/problems-connecting-to-usb-serialport-from-container/24 "2015-03-10T10:17:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elaval](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/elaval/32/30_2.png) [@elaval](https://forums.balena.io/u/elaval)\
**Post date:** [March 10, 2015, 10:17am UTC](https://forums.balena.io/t/problems-connecting-to-usb-serialport-from-container/24/1 "2015-03-10T10:17:54Z")

</div>

I need my raspberry to connect to an Arduino via the USB serialport. I have managed to do this smoothly in a traditional RPi environment (with Raspbian) with nodejs (using johhny-five or plain firmata/serialport npm modules) BUT I have not been able to connect to the serialport from a Resin container.

For example with this basic node program

```
var five = require("johnny-five"),
  board = new fiveBoard();

board = new five.Board();
board.on("ready", function() {
    (new five.Led(13)).strobe();
});

```

I just get the message:

```
root@raspberrypi:/home/test# node server.js                       
1425982101921 Looking for connected device   

```

(And I have an Arduino with Firmata in one of the USB ports … even tried with 2 Arduinos on each of the USB ports and cannot get the serialport to work).

It seems that the container “sees” the usb ports

```
root@raspberrypi:/dev# ls ttyACM*                                               
ttyACM0 ttyACM1

```

But it is not able to connect/open them

Do you know if there is any restriction for connection to USB serial ports from a Resin container? Is there any way around this issue?

Thanks

---

<div class="post-metadata">

**Author:** ![elaval](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/elaval/32/30_2.png) [@elaval](https://forums.balena.io/u/elaval)\
**Post date:** [March 26, 2015, 5:00pm UTC](https://forums.balena.io/t/problems-connecting-to-usb-serialport-from-container/24/2 "2015-03-26T17:00:08Z")

</div>

I have found that the serial ports (/dev/ttyACM0 & /dev/ttyACM1) are active and work if I connect to them from the container using a serialport terminal such as minicom.

The problem is that the npm package serialport.js expects to get the list of available ports reading the dirs:  
/dev/serial/by-path  
or  
/dev/serial/by-id

BUT the containers does not have those dirs (no /dev/serial in the container).

Other packages that work on top of serialport,js (such as johnny-five) expect the serialport.list() method to work properly in order to identify available ports, but it is failing to find the ports.

Not sure about how resin works … but could it be that when the resin software creates the container, it should map the /dev/serial dirs from the host into the container and it is not doing so?

Any idea on how to solve this is welcomed.

---

<div class="post-metadata">

**Author:** ![anon22468611](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon22468611](https://forums.balena.io/u/anon22468611)\
**Post date:** [April 1, 2015, 4:43pm UTC](https://forums.balena.io/t/problems-connecting-to-usb-serialport-from-container/24/3 "2015-04-01T16:43:06Z")

</div>

Hi elaval,

Sincere apologies for taking so long to respond, we are keeping a much closer eye on this forum now and future responses should be far more rapid!

You can resolve this issue by triggering [udev](http://en.wikipedia.org/wiki/Udev) to detect new devices and place the appropriate files in the `/dev` directory using [udevadm](http://linux.die.net/man/8/udevadm).

To do this for a node project, you can simply update your `package.json` to run `udevadm trigger` on application start by changing the `start` field, e.g.:-

### Before

```auto
{
  ...
  "scripts": {
    "start": "node app.js"
  },
  ...
}

```

### After

```auto
{
  ...
  "scripts": {
    "start": "udevadm trigger && node app.js"
  },
  ...
}

```

Let us know if you have any further issues!

Best, Lorenzo

---

<div class="post-metadata">

**Author:** ![anon22468611](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon22468611](https://forums.balena.io/u/anon22468611)\
**Post date:** [April 1, 2015, 6:56pm UTC](https://forums.balena.io/t/problems-connecting-to-usb-serialport-from-container/24/4 "2015-04-01T18:56:57Z")

</div>

Hi again,

After discussing this with my colleagues I realise I’ve missed an important step - you need to start [udevd](https://www.kernel.org/pub/linux/utils/kernel/hotplug/udev/udevd.html) first before triggering the udev update. At this point it makes sense to use a separate start script, e.g.:-

```auto
{
  ...
  "scripts": {
    "start": "bash start.sh"
  },
  ...
}

```

Where `start.sh` looks like:-

```bash
#!/bin/bash
udevd &
udevadm trigger
node app.js

```

Best, Lorenzo

---

<div class="post-metadata">

**Author:** ![elaval](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/elaval/32/30_2.png) [@elaval](https://forums.balena.io/u/elaval)\
**Post date:** [April 2, 2015, 8:15am UTC](https://forums.balena.io/t/problems-connecting-to-usb-serialport-from-container/24/5 "2015-04-02T08:15:08Z")

</div>

Thanks Lorenzo!

I does work now 😄
