Uploading code to arduino gives me the error: "avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied"

I had a similar issue when I tried to upload a sketch to Arduino. The issue was connected to the lack of permissions to read/write to the serial port. I was able to fix by using the following command:

To confirm the port exists enter the following from the root directory.

ls /dev/ttyACM0

To set read/write permissions, enter the following

sudo chmod a+rw /dev/ttyACM0

Reinstall your arduino installed from Ubuntu software center:

sudo apt install --reinstall arduino

Reinstalling is necessary since your which avrdude command according to your comment returns nothing, but should be /usr/bin/avrdude. Check again:

which avrdude

Run your Arduino IDE after reinstalling and close it.

Check your arduino configuration. Open /home/sergio/.arduino/preferences.txt file and check there serial.port option. Try to change it to /dev/ttyACM0. Open that file:

sudo nano /home/sergio/.arduino/preferences.txt

and apply corresponding changes, i.e. the option should look

serial.port=/dev/ttyACM0

Restart computer afterwards.


Here's what worked for me:

  • Uninstall the version from Apt, it doesn't work properly (sudo apt uninstall arduino; sudo apt autoremove)
  • Install the version from the Arduino website
  • sudo apt install avrdude since the one from the website doesn't include it
  • sudo usermod -a -G dialout $USER since the one from the website doesn't do this automatically (the dialout group owns the device file; this adds the current user to that group)

And now everything's working again!

Tags:

Arduino

18.04