Fritzing to design and prototype electronics circuits

I have been playing with Fritzing lately, and I have to say I am impressed. It is seductively easy to create and document electronics designs, and turn them into beautiful working circuits.

Here’s an example of an Arduino project documented using the Breadboard view. The components are all available from the parts library built into the tool. SparkFun is a huge contributor, as is Adafruit.


The Schematic view is automatically produced as you work in the Breadboard view. It has autoroute support, and it is fairly easy to move things around. The color of the wires has to be chosen manually.


The PCB view allows you to quickly produce a PCB design. You can place components on the top and bottom layers, add additional boards, autoroute, and further manipulate wires and components. The tool will even derive the text in the silk screen layers from the labels on the parts. When you’re done, you can export for production in the Gerber RS-274x format. The image below shows the Gerber layers exported by Fritzing, as viewed in Gerbv. This PCB allows an Arduino Pro to be plugged on one side, and several small boards to be plugged on the other side.



Working with multiple git remotes

This post discusses useful git commands when working with multiple git remotes such as to share code with distributed teams.

We are all familiar with the clone command

git clone repository_url

This creates a local working copy of the remote, identified by the short name origin. You can see all the remote repositories in your working copy thus

git remote -v

The following command fetches commits from origin

git pull

The following command pushes local commits to origin

git push

What if you want to share your copy of the repository so that another team can work on it? Maybe to a new remote repository shared with that team?

This can be done as follows

git remote add repo_short_name repository_url
git push repo_short_name master

You can pull changes from the new repository

git pull repo_short_name master

And push them to origin (origin is assumed if not specified)

git push origin

If a remote has conflicting commits that you want to favor

git pull -s recursive -X theirs repo_short_name master

Pull and rebase on top of remote

git pull --rebase repo_short_name master

For more information on working with remote repositories see chapter 2 of the free Git book.

Once you have mastered the command line, you can do all of the same things using a Git client such as the free SourceTree app from the folks at Atlassian.

Install python and pip on Mac OS X

Mac OS X ships with python. You can see its version using

python --version

You can see where it is installed using

which python

You may want the latest version of python, or install python packages using pip. The way I found to get the latest versions of python on Mac is using macports. To install macports download the packaged version from their site and install. Further instructions can be found on their install page.

Once macports is installed, you can install latest version of python 2 thus

sudo port install python27

To learn all python versions available

port list python*

To find out all python packages available

port list py*

To install pip

sudo port install py27-pip

Now that pip is installed you can install python packages. To see installed packages

pip-2.7 list

To search for available packages e.g. all packages with Django in the text

pip-2.7 search Django 

To install django

sudo pip-2.7 install Django==1.4.8

To see more details about a package such as where it is installed

pip-2.7 show Django

To use pip packages with the version of python that ships with OS X, export their path to PYTHONPATH and call python

export PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

Using ping to determine MTU size

ping is a ubiquitous and versatile utility available from the command line of most operating systems. Here’s how it can be used to determine maximum transmission unit (MTU) size i.e. the maximum amount of data the network will forward in a single data packet.

On Ubuntu GNU/Linux

ping -s 50000 -M do localhost

Here, 50000 is the size of the payload in the ICMP echo request. The -M do option prohibits fragmentation. The ICMP message as a whole has 8 more bytes, as that is the size of the header. The command shows that the loopback adapter’s MTU size is 16436, and the ping fails.

On a Mac

ping -s 50000 -D localhost

Does not print the MTU size, so you’ll have to try different payload sizes until you hit the limit. -D prohibits fragmentation by setting the Don’t Fragment (DF) bit in the IP header.

On Windows 8

ping -l 50000 -f localhost

Prints the default MTU size as 65500, so the ping above works.

Learning Python by Mark Lutz; O’Reilly Media

Learning Python

Learning Python, now in its fifth edition, is a humongous tome that covers Python 2 and 3. In covering both versions of Python, it does a tremendous service to the beginner. As a new Python programmer who’s well-versed with other programming languages, I found the book easy to get up to speed with, and its verbosity and thoroughness an asset rather than a liability.

Part 2 of the book has excellent coverage of basic types and data structures. Having read Parts 1 and 2, Parts 3, 4, and 5 seem repetitive sometimes, and are probably most useful as a reference.

Chapter 3 makes a quick reference to pdb and Winpdb, but the coverage of debuggers is otherwise quite sparse. Debugging multithreaded apps without a good debugger is a pain. Not a huge omission as the book does not cover multithreading.

Chapter 9 covers the json module briefly, but the book covers neither socket nor httplib/http.client modules. Network and web programming are required knowledge even for beginners these days. Programming Python, by the same author, does cover these topics in great detail.

Chapter 25 covers advanced topics regarding modules, such as using dual mode code for implementing tests, but that is about the only coverage of unit testing you’ll find in the book. It refers you to the official documentation for modules such as unittest and doctest.

I found Test Your Knowledge Quiz and Answers at the end of each chapter useful. After having read syntax highlighted code in books such as Python Cookbook, I found the code samples in the book rather dull.

I thank O’Reilly Media for providing the book for review.

Python Cookbook by David Beazley, Brian K. Jones; O’Reilly Media

Python Cookbook

Python Cookbook is an extensive tome of recipes for the Python 3 programmer. It is a perfect companion book for those migrating Python 2 code to Python 3. If you are stuck with Python 2, you may still find the second edition of the book for sale, but the recipes may be dated as they cover Python 2.4. It is not a beginners book. If you are looking for a beginners book, I recommend Learning Python by Mark Lutz.

A quick chapter summary follows.

Chapter 1 has recipes involving manipulation of built-in structures such as dictionaries and sequences. Usage of heapq module for implementing priority queues is demonstrated.

Chapter 2 covers string and text manipulation, with extensive use of regular expressions.

Chapter 3 has recipes for working with numbers, dates, and times. Usage of numpy module for matrix and linear algebra calculations is demonstrated.

Chapter 4 provides recipes for implementing iterators and generators.

Chapter 5 covers File and I/O, including recipes for reading and writing compressed files, memory mapping binary files, and communicating with serial ports.

Chapter 6 moves on to more advanced recipes for encoding and processing, such as reading and writing CSV, JSON, XML, Hex digits, and Base64.

Chapter 7 provides recipes for functions and closures.

Chapter 8 provides recipes for classes and objects, such as creating managed attributes, lazily computed properties, and extending classes with mixins. It also covers common patterns such as state, and visitor.

Chapter 9 digs deeper into metaprogramming.

Chapter 10 has recipes for modules and packages, such as for splitting a module into multiple files using packages, and loading modules from another machine using import hooks.

Chapter 11 provides recipes for network and web programming. I didn’t know you could use ip_network objects to generate IP addresses and check for membership. It also covers event-driven I/O but does not introduce any new framework.

Chapter 12 has recipes for concurrency. It discusses implementing concurrency using generators (coroutines), but doesn’t cover frameworks such as gevent, it does mention PEP 3156 that covers those.

Chapter 13 has recipes for writing utility scripts for system administration.

Chapter 14 has recipes for unit testing, debugging, exception handling, and profiling.

Chapter 15 wraps it up with recipes for extending Python using C.

I’ve added this book to my list of references to look into, before heading to Google. Source code listings use syntax highlighting, a nice touch that makes the code easier, and less boring, to read.

I thank O’Reilly media for providing the book for review.