Technical Article

# Electronics Design on Linux

July 30, 2015 by Trevor Gamblin

Intermediate

### Introduction

Using Windows for your design needs is easy because you have access to a wide array of options for everything from simulation to IDEs, part footprint generators and full-blown schematic capture/PCB layout tools. You may find however that using Linux --whether it's because of the low/nonexistent cost, system stability, or because you're a big fan of free and open-source software (FOSS)-- is more appealing. This article is intended to make the switch seem a little less daunting, and give you a solid grasp of what's available to you when you've made the move. Let's get started with an overview of some of the available tools. If some of this seems unfamiliar, there is a very brief Ubuntu-based command line tutorial later in the article, or you can find a complete one here.

### Compilers

Getting your code compiled for a specific microcontroller architecture doesn't leave you with many options on Linux, but the ones you have are good. If you've used Cygwin on Windows, their terminal interfaces might look familiar:

1. gcc: As part of the GNU toolchain, gcc is your go-to for compiling for x86, ARM (with the packages gcc-arm-linux-gnueabi and binutils-arm-linux-gnueabi), and Atmel micros (with a toolchain consisting of three main packages: avr-gcc, avr-libc and avrdude). This is very popular and well-documented, making it easy to use from the command line. Below you'll see a screenshot of the man page for avrdude. GDB (the GNU Debugger) also supports AVR and ARM microcontrollers, which provides you with a way to debug your code now that you don't have many of the IDEs common on Windows.
2. sdcc: For command-line PIC development, there is the Small Device C Compiler, which works with PIC as well as other architectures such as Intel-8051 and STMicroelectronics STM8. PIC however does have a couple of IDE options, which we'll see in the next section.
3. mbed: If you're using one of the supported ARM micros, then this website is still a decent option (as long as you're okay with the browser-based environment)

### Text Editors and IDEs

This is where you'll find yourself almost overwhelmed with options, and there are many more than can be listed here. While you won't have access to popular embedded IDEs like AVR Studio or IAR Embedded Workbench, the aforementioned gcc and sdcc suites give you the debugging tools to replace them, and you have the freedom to use a wide variety of editors to write the code you need:

1. vi, nano and emacs: These three text editors have long histories and most developers will have a differing opinion on which is best, but really it comes down to whichever you like the features of more. Vi (also known as Vim or Vi IMproved) is often more intimidating to new users, but it is guaranteed to be installed on pretty much any Unix or Unix-like system. We'll use nano a little later on in the terminal overview.
2. gedit, atom, sublime: These are only a few of the many graphical text editor options (there exists a GUI-based Vim editor called gVim). Of the three, only gedit comes pre-installed on Ubuntu, but it's arguably one of the most popular text editors available. If you're uncomfortable with command line editors you'll probably find yourself using one of these before writing and debugging with the GNU toolchain.
3. Eclipse, mbeddr, MPLab, Piklab, Code::Blocks, Arduino IDE: As mentioned before, you won't find IAR Embedded Workbench or AVR Studio versions for Linux, but you can configure other IDEs to use the toolchains you want for your projects. MPLab and Piklab are also available as options for PIC-based designs, with the latter being cited as lighter and more functional. The FreeRTOS website has an older, but still useful how-to for using Eclipse with FreeRTOS, including a section on using microcontroller programming tools from inside the IDE.

### Simulation

Here's another area with a lot of options available. The best part is that even if you aren't interested in doing any coding of your own, several of these (as well as the Arduino IDE mentioned above) are available in the Ubuntu Software Center:

1. ngspice, Qucs and LTSpice: For simulating analog circuit behavior, there are several choices like ngspice available, but they function either through the command-line (listing nodes and component descriptions), or doing the same through a GUI. However, if you are willing to use the Wine compatibility software, you can run LTSpice IV quite easily, giving you access to one of the better simulation tools out there with little trouble. Qucs is an interesting tool that is still under development, and possesses a lot of features, including VHDL and Verilog for digital simulations. You can check out the GitHub page for more info.
2. Logisim, gLogic, and kLogic (KDE version): Available in the Ubuntu Software Center, these are two graphical programs that you can use to simulate digital circuits. Either one would be a good complement to one of the simulators above.
3. Simulavr and avrsim: The two of these are very handy if you're using Atmel microcontrollers. The latter is particularly cool because you can use it to build more complete simulations that test your code for running things like LCD counters. You can check the project out here.
4. Ksimus: This is another simulator with both digital and analog capabilities, although it seems to be geared more towards the former. The website is currently down, but you can still download it on SourceForge.
5. Icarus Verilog and Verilator: Icarus Verilog is a totally free Verilog implementation including a compiler and virtual machine for simulating, as well as a handful of useful addons. Verilator is a Verilog HDL simulator whose claim to fame is its speed, focused specifically on synthesis. It is not intended to replace commercial simulators, but is very useful if you want a simulator that can generate highly optimized code for C++ and SystemC. Check it out here.

### Schematic Capture and PCB Design

There are not as many choices for Linux-based schematic capture and PCB design as there are for software development. Here are a few alternatives:

1. EAGLE and Upverter: CadSoft's EAGLE offering is available on Linux, and is one of your only options if you are looking for software backed by a large company. Upverter is newer and has an excellent interface, as well as being browser-based, but the license prohibits commercialization of your designs if you are using the Community (free) version.
2. gEDA and Fritzing: gEDA was developed as a response to the lack of free PCB design options out there. It is often compared to KiCAD and offers a similar set of tools for basic design. Fritzing was covered previously on our website, and includes a breadboarding aspect you don't often see elsewhere.
3. KiCAD: This design suite used to receive criticism for not being production-ready, but since CERN recently jumpstarted its development, it's improved drastically and has a variety of great new features and bug-fixes. The next part of this article will cover basic KiCAD use.

That covers it for this part of the overview. Now we'll provide you with a very short look at using Ubuntu 15.04, and prepare you to setup and install KiCAD on your system.

### Why Ubuntu?

There are no shortage of Linux variants with their own app suites, package managers, desktop environments and targeted markets - and Ubuntu's Unity interface has been met with mixed response - so why use Ubuntu? Here are a few reasons:

1.  It's easy to get and install (the live USB method of installation is particularly easy-to-use and helps you avoid doing nasty things to your hard drive partitions)
2. It gives you quick access to the terminal (the Linux equivalent of the Windows command prompt)
3. The Ubuntu Software Center (a free application that provides a GUI for use in installing software)
4. It's one of the most popular distributions out there, meaning there's all kinds of support available via a quick web search

The Ubuntu download page has all of the information you'll need to get a USB or DVD set up and installed, so we won't cover that. Instead, let's get to talking very briefly about the desktop you'll see, and some simple commands so you can get going with the programming or design you need to do.

### The Ubuntu Terminal

Below you'll see a screenshot of what your Ubuntu desktop will look like when you've logged in:

You can click the Ubuntu logo button in the top left to search your system (and Amazon) for different programs and files, or use one of the others to launch them directly. Instead of doing that, press CTRL+ALT+T and you should see something like this, but with your account name in the place of mine:

### Commands

This is the interface you'll find yourself using a lot of the time on Ubuntu. If working via terminals and/or command line is unfamiliar to you, think of this like viewing your system in a text-only fashion; instead of clicking on an icon, you typically have to type a program's name, and it may be followed by options (we'll see more of this in a bit). There are numerous commands and programs, and plenty of good tutorials out there on this, so I'll give you a very short overview of the tools you'll need to navigate your system. Here are the ones you'll need to get started right away:

1. man or info
2. ls
3. cd
4. pwd
5. mv
6. rm
7. nano
8. apt-get
9. apt-cache
10. chmod

The first entry is extremely useful when it comes to figuring out what everything does. Using man or info followed by the name of a command or program (try it on the others in the list, or by typing "man firefox", or even "man man") provides you with the documentation for the program, including intended use, available options, authors, and more. This also includes things like C library calls, meaning you've got a reference for code you may find yourself using.

Note that names are case-sensitive. The commands ls, cd and pwd are your general navigational tools - "ls" lists the contents of the directory you are currently in, while "cd" followed by a directory name moves you into that directory, and "pwd" prints out the full filename of the directory you're in. The directory you start in when you open a terminal is the Home directory (labeled with your account name in your file browser). Moving to different parts of your system ("cd .." to move up a level in the directory; "cd " to move into a directory). You may find mv and rm less immediately useful, as they allow you to move and remove files, respectively (there is also a command called rmdir for empty directories). I'll cover nano, apt-get, apt-cache and chmod towards the end of the article.

You'll see examples of the use of "ls", "pwd", "cd" and "man", as well as output in the terminals below, along with the manual output for the C function "snprintf" (you can open multiple instances of the terminal by pressing CTRL+ALT+T again):

Continuing on, "nano" is one of many simple text editors available on Ubuntu, and is the one you'll be using here. Like I stated above, you can use "man nano" to read the documentation for the program. Below is a terminal window showing nano opened in a new file called "test.c". In order to do the same, just type "nano test.c" (make sure you're in your home directory by typing "cd" with no arguments). Download the code after the screenshot, or write your own short Hello World-esque program in nano, then press CTRL+X. You'll be prompted about confirmation.

Ubuntu.zip

After closing the file with nano, you'll find yourself back at the prompt. If you now type the command below, you'll call the compiler gcc to create an executable called "test" from your code:

gcc test.c -o test

The executable will show up bright green in the default color scheme. Finally, by typing "./test" you should have the program run. When running executables or scripts in this manner, you have to type "./" before the file name (you're just telling your system to run a program called "test" in the current directory (represented by a single period). If everything went well you'll see something similar to the image below:

And that is the barebones regarding using the terminal. But what about apt-cache, apt-get and chmod? Turns out that "chmod" may be the most immediately useful of the three if you plan on moving on to the KiCAD tutorial. Using it on a file by typing, for example, "chmod test" will tell you you're missing an operand. Using something like "chmod -x test" or "chmod +x test" will remove or add its executable status. You'll need to enable execution of most scripts in order to run them like we did with the "test" program (and it'll be required in the Intro to KiCad article).

That's pretty much it for this article. This certainly isn't an exhaustive list of what's available out there, so make sure to look around on the web. If you're looking a more complete and very excellent tutorial on the command line (and shell scripting), go here. Be sure to comment below if you have any concerns.

## What's Next

Intro to KiCad on Ubuntu - if you're looking to design a PCB or three, read on!

• Share

### You May Also Like

Why Ubuntu? Nothing wrong with Ubuntu/Unity although I have these comments:
* #1 and #2 could be said about any 2016 Linux distribution (Mint, Fedora, openSuse, Centos, etc.).
* The net value of #3 is debatable since the GUI is unpopular for a variety of reasons.  Most folks wind up using the Synaptics GUI and the APT command line instead.
* Agreed about #4 although if one wishes to use a lightweight member of the Ubuntu family (E.g. on an older PC), then Xubuntu, Lubuntu, or Xubuntu Mate distros might be a better choice.

Like.