You are not logged in.

#1 2011-07-06 19:27:22

tirezo
Member
Registered: 2011-07-06
Posts: 4

Accessing USB device (Arduino) while not root

Hello all,
I use an Arduino, an open-source microcontroller platform, which sits on /dev/ttyUSB0 and spits out data over the serial port. It would be very useful to me to be able to access the arduino without having to be root or to sudo. As it is, here's what happens:

[user@computer ~]$ minicom -D /dev/ttyUSB0 -b 57600
minicom: cannot open /dev/ttyUSB0: Permission denied
[user@computer ~]$ sudo minicom -D /dev/ttyUSB0 -b 57600


Welcome to minicom 2.5

OPTIONS: I18n
Compiled on Feb  2 2011, 18:45:31.
Port /dev/ttyUSB0

Press CTRL-A Z for help on special keys             
                                                     
GO,1023,353,352,255,0,1,,377,0,505,ST               
GO,1023,297,295,255,0,1,,204,0,505,ST               
GO,1023,387,386,255,0,1,,417,0,506,ST               
..... and so on.

How can I fix this?
Thanks!

Last edited by tirezo (2011-07-07 19:43:59)

Offline

#2 2011-07-06 19:31:25

tirezo
Member
Registered: 2011-07-06
Posts: 4

Re: Accessing USB device (Arduino) while not root

By the way, here's ls -l for the device:

[user@computer ~]$ ls -l /dev/ | grep ttyUSB
crw-rw---- 1 root uucp  188,   0 Jul  6 15:22 ttyUSB0

I tried adding myself to the uucp group and it still didn't work:

[user@computer ~]$ groups user
lp wheel uucp games video audio optical storage scanner power users

Offline

#3 2011-07-06 19:40:45

tirezo
Member
Registered: 2011-07-06
Posts: 4

Re: Accessing USB device (Arduino) while not root

okay, this worked:
sudo chmod 666 /dev/ttyUSB0

But how can I have arch do this automatically for all USB devices?

Last edited by tirezo (2011-07-06 19:40:59)

Offline

#4 2011-07-07 01:42:57

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,230

Re: Accessing USB device (Arduino) while not root

I think you want to create a udev rule.

https://wiki.archlinux.org/index.php/Ud … mm_Devices


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2011-07-07 18:04:57

tirezo
Member
Registered: 2011-07-06
Posts: 4

Re: Accessing USB device (Arduino) while not root

Thanks ewaller! I had no idea what udev rules were.
For anyone having trouble with arduino permissions on arch, add the following 2 lines to this file:
/etc/udev/rules.d/50-embedded_devices.rules

SUBSYSTEMS="usb", ATTRS{product}== "Arduino Uno", GROUP="users", MODE="0666"
SUBSYSTEMS="usb", ATTRS{product}== "FT232R USB UART", GROUP="users", MODE="0666"

This will let you use the arduino uno and duemilanove without having to worry about permissions (I haven't tested any other versions)


****UPDATE: This doesn't work.

Last edited by tirezo (2011-07-07 19:45:04)

Offline

#6 2015-05-15 19:06:08

bshaya
Member
Registered: 2015-05-15
Posts: 1

Re: Accessing USB device (Arduino) while not root

I had the same problem and after much mucking around in udevadm, found out why this wasn't working; it should be SUBSYSTEMS=="usb", not single =. Udev considered this file unparseable.

SUBSYSTEMS=="usb", ATTRS{product}== "Arduino Uno", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{product}== "FT232R USB UART", GROUP="users", MODE="0666"

I found you can also avoid needing a reboot/replug by running:
$sudo udevadm trigger

(Tested on Mint 17.1)

Offline

#7 2015-05-15 19:08:23

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,406

Re: Accessing USB device (Arduino) while not root

Not sure if you need it for the Arduino, just the USB UART serial adapter.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#8 2015-05-15 20:37:28

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Accessing USB device (Arduino) while not root

Easier than the udev rule would just be to add your user to the uucp group as the device files already have group r/w access.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#9 2015-11-07 02:07:45

ILMostro
Member
Registered: 2013-03-28
Posts: 5

Re: Accessing USB device (Arduino) while not root

Yup, great call Trilby. 

# usermod -a -G uucp yourregusername

Offline

#10 2015-11-07 02:21:45

bstaletic
Member
Registered: 2014-02-02
Posts: 658

Re: Accessing USB device (Arduino) while not root

As to why adding oneself to uucp group failed to solve permission issue for OP is probably because he forgot to relog his user.

Wiki also suggest that if adding a user to uucp is still causing problems, try adding the user to lock group also.

Offline

#11 2016-01-10 04:51:36

NickTouik
Member
Registered: 2014-01-15
Posts: 19

Re: Accessing USB device (Arduino) while not root

None of this works for me. I added myself to

uccp

a long time ago and have been quite happy using my arduino with Arch. All of the sudden (there was a system upgrade) it stopped working.

Now I get the error message:

avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
Problem uploading to board. 

Whenever I try to upload. I added myself to

lock

and re-logged in. Still doesn't work. When running the Arduino IDE as root, however, there is no issue. It works fine.

Other strange fact. I changed the permission mode of

/dev/ttyACM0

to 666, but after trying to upload to the board the permission mode reverts to 660, i.e.

crw-rw----

Any suggestions? I didn't make a udev rule yet, but I don't think it should be necessary.

Offline

#12 2016-01-10 05:03:58

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,230

Re: Accessing USB device (Arduino) while not root

What type of Arduino is it?  Some flavors do a USB disconnect when the Arduino's processor is reset -- Leonardo and others that use the Atmel's intrinsic USB interface do this.  Edit:  When it reconnects, the permissions reset (end edit)
Which version of AVRDUDE are you using?  A recent version had issues with Arduino and needed downgradng.
What is the output of groups

Last edited by ewaller (2016-01-10 05:04:40)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#13 2016-01-10 06:57:58

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,438

Re: Accessing USB device (Arduino) while not root

@ tirezo, can you try changing permission of minicom, so that when it is run by normal user it runs with root previlages,

sudo chmod u+s /usr/bin/minicom

assuming minicom is in /usr/bin, this works with wvdial when I use it for my usb modem.

Offline

#14 2016-01-10 14:39:12

NickTouik
Member
Registered: 2014-01-15
Posts: 19

Re: Accessing USB device (Arduino) while not root

Thanks for the quick reply, ewaller!

ewaller wrote:

What type of Arduino is it?

It's an Arduino Esplora

ewaller wrote:

Some flavors do a USB disconnect when the Arduino's processor is reset -- Leonardo and others that use the Atmel's intrinsic USB interface do this.  Edit:  When it reconnects, the permissions reset (end edit)

Right, the Esplora is based on Leonardo, I believe.

ewaller wrote:

Which version of AVRDUDE are you using?  A recent version had issues with Arduino and needed downgradng.
What is the output of groups

My avrdude version is 1:6.1-1 (Edit: This version was installed on December 9 2015, and uploading worked fine then. I downgraded to avrdude 6.1-1 but there was no imporvement.)

Groups output: tty wheel uucp lock audio vboxusers nick (n.b. my username is nick)

I'm using the latest version (as of January 9th 2016) of the Arduino IDE and also I can upload to my board when running the IDE as root.

Last edited by NickTouik (2016-01-10 14:50:09)

Offline

#15 2016-01-10 16:42:56

bstaletic
Member
Registered: 2014-02-02
Posts: 658

Re: Accessing USB device (Arduino) while not root

What is the output of

ls -l /dev/ttyACM0

Offline

#16 2016-01-10 16:51:03

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,230

Re: Accessing USB device (Arduino) while not root

It works here.... hmm

ewaller@turing ~ 1096 %pacman -Qi arduino         
Name           : arduino
Version        : 1:1.6.7-1
Description    : Arduino prototyping platform SDK
Architecture   : x86_64
URL            : http://arduino.cc/en/Main/Software
Licenses       : GPL  LGPL
Groups         : None
Provides       : None
Depends On     : gtk2  libusb-compat  java-runtime  desktop-file-utils  giflib  avrdude
Optional Deps  : None
Required By    : None
Optional For   : None
Conflicts With : None
Replaces       : None
Installed Size : 402.84 MiB
Packager       : Unknown Packager
Build Date     : Sat 02 Jan 2016 09:58:16 AM PST
Install Date   : Sat 02 Jan 2016 10:00:43 AM PST
Install Reason : Explicitly installed
Install Script : Yes
Validated By   : None

ewaller@turing ~ 1097 %pacman -Qi avrdude
Name           : avrdude
Version        : 1:6.1-1
Description    : Download/upload/manipulate the ROM and EEPROM contents of AVR microcontrollers
Architecture   : x86_64
URL            : http://www.nongnu.org/avrdude/
Licenses       : GPL
Groups         : None
Provides       : None
Depends On     : readline  libftdi  libusb-compat  elfutils
Optional Deps  : None
Required By    : arduino
Optional For   : None
Conflicts With : None
Replaces       : None
Installed Size : 950.00 KiB
Packager       : Anatol Pomozov <anatol.pomozov@gmail.com>
Build Date     : Wed 09 Dec 2015 01:04:02 PM PST
Install Date   : Thu 10 Dec 2015 08:03:58 AM PST
Install Reason : Installed as a dependency for another package
Install Script : No
Validated By   : Signature

ewaller@turing ~ 1098 %ll /dev/ttyACM?            
crw-rw---- 1 root uucp 166, 1 Jan 10 08:33 /dev/ttyACM1
ewaller@turing ~ 1099 %

As a sanity check, is the group of the device node uucp?

Edit:  I just saw bstaletic's post -- I think we are on the same track.

Last edited by ewaller (2016-01-10 16:52:03)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#17 2016-01-11 01:41:10

NickTouik
Member
Registered: 2014-01-15
Posts: 19

Re: Accessing USB device (Arduino) while not root

Everything looks like it checks out:

ls -l ttyACM0 
crw-rw---- 1 root uucp 166, 0 Jan 10 20:32 ttyACM0

and

[nick@TaMereVIII dev]$ pacman -Qi arduino
Name           : arduino
Version        : 1:1.6.7-1
Description    : Arduino prototyping platform SDK
Architecture   : x86_64
URL            : http://arduino.cc/en/Main/Software
Licenses       : GPL  LGPL
Groups         : None
Provides       : None
Depends On     : gtk2  libusb-compat  java-runtime  desktop-file-utils  giflib
                 avrdude
Optional Deps  : None
Required By    : None
Optional For   : None
Conflicts With : None
Replaces       : None
Installed Size : 402.84 MiB
Packager       : Unknown Packager
Build Date     : Sat 09 Jan 2016 11:02:35 PM EST
Install Date   : Sat 09 Jan 2016 11:19:22 PM EST
Install Reason : Explicitly installed
Install Script : Yes
Validated By   : None

[nick@TaMereVIII dev]$ pacman -Qi avrdude
Name           : avrdude
Version        : 1:6.1-1
Description    : Download/upload/manipulate the ROM and EEPROM contents of AVR
                 microcontrollers
Architecture   : x86_64
URL            : http://www.nongnu.org/avrdude/
Licenses       : GPL
Groups         : None
Provides       : None
Depends On     : readline  libftdi  libusb-compat  elfutils
Optional Deps  : None
Required By    : arduino
Optional For   : None
Conflicts With : None
Replaces       : None
Installed Size : 950.00 KiB
Packager       : Anatol Pomozov <anatol.pomozov@gmail.com>
Build Date     : Wed 09 Dec 2015 04:04:02 PM EST
Install Date   : Sun 10 Jan 2016 09:50:40 AM EST
Install Reason : Installed as a dependency for another package
Install Script : No
Validated By   : None

This is really frustrating. Works fine as root, and I think the permission problem is subtle because when I upload, I get the permission error but my Arduino also resets, so something is going through.

Edit: I also rebooted, deleted the ~/Arduino and ~/.arduino15  directories, to remove any options. Still no luck. I also tried chowning ttyACM0 to myself, but it resets to belonging to root.

Last edited by NickTouik (2016-01-11 01:49:12)

Offline

#18 2016-01-12 01:45:19

Kostafun
Member
Registered: 2014-07-02
Posts: 1

Re: Accessing USB device (Arduino) while not root

Exactly the same problem here, I used dirty fix

sudo chmod u+s /usr/bin/avrdude

Offline

#19 2016-01-12 04:20:48

NickTouik
Member
Registered: 2014-01-15
Posts: 19

Re: Accessing USB device (Arduino) while not root

Thanks alot Kostafun. That sure is dirty, but totally works! I didn't know about you could set programs to run that way.

I have two questions:

1) How do I revert avrdude to its original privilege settings?
2) How insecure is this? Is it possible to execute arbitrary code or read/write to the file system via avrdude?

Offline

#20 2016-01-12 04:49:18

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,230

Re: Accessing USB device (Arduino) while not root

What that does is set the SUID bit.  It causes the program to run with the privileges of the files's owner (root) rather than the user's.   Clear the bit with chmod u-s /usr/bin/avrdude   ( I think)
It is not too bad WRT security.  Something still smells fishy as to why it does not work without this hammer.

Last edited by ewaller (2016-01-12 04:50:09)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#21 2016-01-12 04:58:25

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,438

Re: Accessing USB device (Arduino) while not root

@NickTouik, I had posted similar solution in my previous post.

"chmod u+s" adds s to root permission, you can check current permissions with "ls -l /usr/bin/avrdude", this s permission can be removed with below command

sudo chmod u-s /usr/bin/avrdude

Bit more on that bit, 'u' is file owner which is root in this case I believe, with u+s any user can execute file as owner of that file. You can change other permission similarly using u(for owner), g(for group), o(for other), while permissions are w(write),r(read),x(execute). '+' to add and '-' to remove permissions. so 'chmod g+wx' gives write and execute permissions to the group that owns the file.

regarding your second question, with this any user can execute avrdude with root permissions, but anyway that is what you want, isn't it?

-regards

Last edited by Docbroke (2016-01-12 05:11:25)

Offline

#22 2016-01-12 14:08:41

NickTouik
Member
Registered: 2014-01-15
Posts: 19

Re: Accessing USB device (Arduino) while not root

Thank you for your responses and edifying explanations.

@Docbroke: I now understand your previous response smile. As for my second question, generally if some program has this type of elevated privilege there should be a good reason e.g. sudo. To be honest, I'm not sure what avrdude does exactly nor what its scope is; so, as a sensible user, I shouldn't just leave it "u+s". I'll probably write a script to switch the permission for just when I need to use it. Then again if avrdude can only write to attached USB devices, then who cares, right?

@ewaller: I aggree this isn't completely satisfactory. Feel free to propose queries to my system to find the real problem.

Last edited by NickTouik (2016-01-12 14:10:54)

Offline

#23 2016-01-12 14:54:20

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,230

Re: Accessing USB device (Arduino) while not root

NickTouik wrote:

To be honest, I'm not sure what avrdude does exactly nor what its scope is; ...

Thus spake man avrdude tongue

AVRDUDE(1)                BSD General Commands Manual               AVRDUDE(1)

NAME
     avrdude — driver program for ``simple'' Atmel AVR MCU programmer

SYNOPSIS
     avrdude -p partno [-b baudrate] [-B bitclock] [-c programmer-id]
             [-C config-file] [-D] [-e] [-E exitspec[,exitspec]] [-F]
             [-i delay] [-n -logfile] [-n] [-O] [-P port] [-q] [-s] [-t] [-u]
             [-U memtype:op:filename:filefmt] [-v] [-x extended_param] [-V]

DESCRIPTION
     Avrdude is a program for downloading code and data to Atmel AVR microcon‐
     trollers.  Avrdude supports Atmel's STK500 programmer, Atmel's AVRISP and
     AVRISP mkII devices, Atmel's STK600, Atmel's JTAG ICE (mkI, mkII and 3,
     the latter two also in ISP mode), programmers complying to AppNote AVR910
     and AVR109 (including the Butterfly), as well as a simple hard-wired pro‐
     grammer connected directly to a ppi(4) or parport(4) parallel port, or to
     a standard serial port.  In the simplest case, the hardware consists just
     of a cable connecting the respective AVR signal lines to the parallel
     port.
.....8<.................8<...........
     The Arduino (which is very similar to the STK500 1.x) is supported via
     its own programmer type specification ``arduino''.
.....8<.................8<...........

Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#24 2016-09-28 18:46:23

eshahnazi
Member
From: Esfahan, IRAN
Registered: 2016-09-28
Posts: 1

Re: Accessing USB device (Arduino) while not root

hi
i run arduino ide with gksudo. AND  upload code is no error.
in desktop right click icon arduino ide / and open it with gedit / then add "gksudo -k -u root" to first "Exec" line.

[Desktop Entry]
Type=Application
Name=Arduino IDE
GenericName=Arduino IDE
Comment=Open-source electronics prototyping platform
Exec=gksudo -k -u root /media/ProgLinux/arduino64linux/arduino-1.6.9/arduino
Icon=arduino-arduinoide
Terminal=false
Categories=Development;IDE;Electronics;
MimeType=text/x-arduino
Keywords=embedded electronics;electronics;avr;microcontroller;
StartupWMClass=processing-app-Base

Last edited by eshahnazi (2016-09-28 18:48:08)

Offline

#25 2023-06-29 08:24:35

frischwasser
Member
Registered: 2023-06-29
Posts: 2

Re: Accessing USB device (Arduino) while not root

Hi,

I run in the same "time waste hole".
I ask myself is it a bug?

Where:
$ ls -al /dev/ttyACM0
crw-rw---- 1 root uucp 166, 0 Jun 29 09:07 /dev/ttyACM0

As i understand uucp also root do have a write permission. Add I add $USER to group uucp.  But the membership doesn't change the right to write.

chmod a+rw /dev/ttyACM0 does give write pemission until a reconnection.

I also create udev without success.

I also ask myself: Is there a second membership on arch needed?

On debian based distribution, add a $USER to group dialout and everything works fine as expected. 

After 2 days, I realize i can't fix my avrdude write permission issue on arch. Sadly I give up and use a other distribution to program the ATmega32U4 Pro Micro via arduino ide.

Offline

Board footer

Powered by FluxBB