
In this article, we will delve into the common issue faced by many Arduino enthusiasts – the “Permission Denied” error when uploading code to Arduino on Ubuntu 18.04. We will provide detailed solutions with step-by-step instructions to help you troubleshoot this problem.
Understanding the Issue
The error, which typically reads as “avrdude: ser_open(): can’t open device “/dev/ttyACM0″: Permission denied”, usually occurs when the Arduino Integrated Development Environment (IDE) doesn’t have the necessary permissions to access the serial port.
Solution 1: Checking User Group Membership
The first step towards resolving this issue is to ensure that your username is part of both the “tty” and “dialout” groups. This can be done by running the command groups
in the terminal. If your username is not part of these groups, you can add it using the following commands:
sudo usermod -a -G tty $USER
sudo usermod -a -G dialout $USER
The usermod
command modifies the system account files to reflect the changes that are specified on the command line. The -a
option is used to add the user to the supplementary group(s) and -G
option is used to specify the group(s).
After executing these commands, log out and log back in to apply the group changes. Verify that the Arduino IDE configurations are correct, with the board set to Arduino UNO and the port set to ttyACM0. Try uploading the code again.
Solution 2: Creating UDEV Rules
Another approach is to create UDEV rules that allow your user to access the Arduino device. Here’s how you can do it:
- Create a new file in the
/etc/udev/rules.d/
directory, for example,99-arduino.rules
. You can do this using the command:
sudo nano /etc/udev/rules.d/99-arduino.rules
- Open the file and add the following line:
SUBSYSTEM=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0043", MODE="0666"
The idVendor
and idProduct
values correspond to the USB Vendor ID and Product ID of your Arduino board. You can find these values by running the command lsusb
in the terminal.
- Save the file and exit (Ctrl+X, then Y, then Enter).
- Restart your computer and try uploading the code again.
Solution 3: Updating Arduino IDE
Sometimes, the issue might be with the Arduino IDE itself. In this case, updating the IDE might help:
- Download the latest version of Arduino IDE from the official Arduino website.
- Install the IDE by running the command
sudo ./install.sh
in the extracted directory. - Run the script
arduino-linux-setup.sh
with your username as an argument, for example,./arduino-linux-setup.sh sergio
. - Follow any instructions provided by the script, restart your computer, and check if the issue is resolved.
Solution 4: Reinstalling Arduino IDE and avrdude
Reinstalling the Arduino IDE and avrdude might also resolve the issue:
- Uninstall the Arduino IDE installed from the Ubuntu Software Center using the command
sudo apt uninstall arduino
followed bysudo apt autoremove
. - Download the latest version of Arduino IDE from the official Arduino website and follow the installation instructions provided.
- Install the
avrdude
package using the commandsudo apt install avrdude
. - Add your username to the “dialout” group by running the command
sudo usermod -a -G dialout $USER
. - Restart your computer and check if the issue is resolved.
Solution 5: Adjusting Permissions in Ubuntu Software Center
If the above solutions don’t work, you can try adjusting the permissions in the Ubuntu Software Center:
- Install the Arduino IDE from the Ubuntu Software Center.
- Open the Ubuntu Software Center and go to the Arduino IDE page.
- Click on “Permissions” and enable “Access usb hardware directly”.
- Try uploading the code again.
Conclusion
The “Permission Denied” error when uploading code to Arduino on Ubuntu 18.04 can be frustrating, but it is typically due to a permissions issue and can be resolved by following the steps outlined in this article. If none of the above solutions work for you, you can try the script created by sergiomafra, which can be found at https://github.com/sergiomafra/iniarduino. This script automates the process of setting the correct permissions and reloading UDEV rules.
Remember to follow the instructions carefully and make sure you have the necessary permissions to perform the actions mentioned in the solutions. Happy coding!
Arduino IDE (Integrated Development Environment) is a software application that allows you to write, compile, and upload code to Arduino boards. It provides a user-friendly interface for programming and interacting with Arduino microcontrollers.
You can check your group membership in Ubuntu 18.04 by running the command groups
in the terminal. This will display a list of groups that your username belongs to.
You can find the USB Vendor ID and Product ID of your Arduino board by running the command lsusb
in the terminal. Look for the line that corresponds to your Arduino board and note the values under the "ID" field.
To uninstall the Arduino IDE in Ubuntu, you can use the command sudo apt uninstall arduino
followed by sudo apt autoremove
. This will remove the Arduino IDE and any associated packages from your system.
If none of the solutions mentioned in this article work for you, you can try using the script created by sergiomafra, which can be found at https://github.com/sergiomafra/iniarduino. This script automates the process of setting the correct permissions and reloading UDEV rules. Be sure to carefully follow the instructions provided by the script.