Overview

This is to show how to set up your Arduino and vscode for arduino projects.

I converted to:

  • not using Cmake, using pyalamake and Makefiles instead, see pyalamake for the section "Convert Arduino from cmake"
  • converted to using vscode, not CLion

These instructions are for installation on Ubuntu 20.04. Other Operating Systems and Ubuntu versions may need changes or additional steps.

Install Tools

Everything in this section needs to be done only once.

  • Install project devino-app-template
  • run ./do_install full to install all necessary packages
  • run ./do_check to check all packages are installed and tool versions are acceptable

Other Tasks

  • I put everything into a "projects" subdirectory off of $HOME.
mkdir -p ~/projects
  • add your userid to the dialout group. Normally in Ubuntu you must have root access to access a serial port. This command gives your_userid access to the serial port devices in /dev/tty_USB*.
  sudo adduser $USER dialout
  # logout (or reboot) and log back in

  # this tells you all the groups your userid belongs to:
  groups

  # the output should contain "dialout":
  arrizza adm lp dialout cdrom sudo dip plugdev lpadmin

Install CLion

  • Note: CLion is a paid IDE. See Jetbrains CLion for a personal version. I installed the Perpetual License (best deal in my opinion)
  • See CLion Quick Start
  • Create a C and/or C++ project to printf "hello world". This tests the CLion installation is correct.

Get LED blinker project source

  • get the source code for Arduino LED Blink. This is the "hello world" of embedded projects.
     cd ~/projects
     git clone git@bitbucket.org:arrizza-public/arduino-led-blink.git
     cd arduino-led-blink

finish the installation of necessary packages.

     ./do_subm_update full  # do install of submodule
     ./do_install full      # do install of python, compilers, arduino library
     ./do_check             # check all is installed

For more, see:

Determine the Board ID

Ensure the board id is correct:

print_board_list()

You'll see a list of boards. Choose the name for the one you are using.

 --  1]  -- ARDUINO Boards:
 --  2]  --              uno: Arduino Uno
 --  3]  --        atmega328: Arduino Duemilanove w/ ATmega328
 --  4]  --        diecimila: Arduino Diecimila or Duemilanove w/ ATmega168
 --  5]  --          nano328: Arduino Nano w/ ATmega328
 --  6]  --             nano: Arduino Nano w/ ATmega168
 --  7]  --         mega2560: Arduino Mega 2560 or Mega ADK
 --  8]  --             mega: Arduino Mega (ATmega1280)
 --  9]  --         leonardo: Arduino Leonardo
 -- 10]  --          esplora: Arduino Esplora
 -- 11]  --            micro: Arduino Micro
 -- 12]  --          mini328: Arduino Mini w/ ATmega328
 -- 13]  --             mini: Arduino Mini w/ ATmega168
 -- 14]  --         ethernet: Arduino Ethernet
 -- 15]  --              fio: Arduino Fio
 -- 16]  --            bt328: Arduino BT w/ ATmega328
 -- 17]  --               bt: Arduino BT w/ ATmega168
 -- 18]  --       LilyPadUSB: LilyPad Arduino USB
 -- 19]  --       lilypad328: LilyPad Arduino w/ ATmega328
 -- 20]  --          lilypad: LilyPad Arduino w/ ATmega168
 -- 21]  --         pro5v328: Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
 -- 22]  --            pro5v: Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168
 -- 23]  --           pro328: Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328
 -- 24]  --              pro: Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168
 -- 25]  --        atmega168: Arduino NG or older w/ ATmega168
 -- 26]  --          atmega8: Arduino NG or older w/ ATmega8
 -- 27]  --     robotControl: Arduino Robot Control
 -- 28]  --       robotMotor: Arduino Robot Motor
 -- 29]  --

Determine the Port ID

Find out which USB port your Arduino is attached to. This is a special file in the Ubuntu directory structure under "/dev".

To find the correct device id, do this:

  • unplug the Arduino and any other USB device (excluding your mouse)
  • enter ls /dev/ttyU* - you should see none
  • enter ls /dev/ttyA* - you should see none
  • plug in the Arduino; the LED should light up
  • enter ls /dev/tty* - you should see a single entry /dev/ttyUSB0.
  • If not, enter ls /dev/ttyA* - you should see a single entry /dev/ttyACM0
  • if you see more than one entry, you have some other USB device plugged in
  • If you change which USB port the Arduino is plugged into, the device id may change.

Check other settings

uncomment this line and run ./do_build

print_board_settings(${MY_BOARD})

Check that the settings are correct for your board:

 --  1]  -- Arduino nano328 Board:
 --  2]  --    nano328.name=Arduino Nano w/ ATmega328
 --  3]  --
 --  4]  --    nano328.upload.protocol=arduino
 --  5]  --    nano328.upload.maximum_size=30720
 --  6]  --    nano328.upload.speed=57600
 --  7]  --
 --  8]  --    nano328.bootloader.low_fuses=0xFF
 --  9]  --    nano328.bootloader.high_fuses=0xDA
 -- 10]  --    nano328.bootloader.extended_fuses=0xfd
 -- 11]  --    nano328.bootloader.path=atmega
 -- 12]  --    nano328.bootloader.file=ATmegaBOOT_168_atmega328.hex
 -- 13]  --    nano328.bootloader.unlock_bits=0xff
 -- 14]  --    nano328.bootloader.lock_bits=0xcf
 -- 15]  --
 -- 16]  --    nano328.build.mcu=atmega328p
 -- 17]  --    nano328.build.f_cpu=16000000L
 -- 18]  --    nano328.build.core=arduino
 -- 19]  --    nano328.build.variant=eightanaloginputs

Note: if one of them are wrong you can set that value manually:

# just an example, the default value 57600 is correct
nano328.upload.speed=115200

Upload to arduino

At this point, the build is complete.

  • run ./do_upload to upload the image to your arduino.

The LED should be off for 1 second, then turn on and blink quickly for about a second, and repeat indefinitely.

devino-app-template

Another project to check out is devino-app-template. This one is template. It is a starting point for creating an arduino project.

This one is similar to arduino-led-blink except the blinking is done based on random values. When you ./do_upload multiple times the LED will blink at different rates each time.

- John Arrizza