KiCAD Howto – Library and the text editor

I was asked by one of my blog followers about using KiCAD libraries and how to make a library and add parts to it.  So I’ve written this blog entry to help all KiCAD users.

One of the very cool things about KiCAD is all the libraries are just text files, so a good editor is all you’ll need.

On a Linux install of KiCAD the default libraries are tricky for a regular user to edit as they are all owned by root, so they are really read only (unless you want to do all that sudo stuff!).

What I have done on my system is create my own library and saved it on a shared directory on my server so any machine that I login from can see the same library.

Start your text editor and create a new library that has no parts in it, it’s just a “shell” like this:

EESchema-LIBRARY Version 2.3  Date: Wed 07 Nov 2012 01:16:37 PM GMT
#encoding utf-8
#End Library

Save this somewhere and call it something like “MyKiCADLib.lib”

Now when you start a new schematic go to “Preferences -> Library”

KiCAD: Select Library from the Preferences Menu

KiCAD: Select Library from the Preferences Menu

In the Library window:

KiCAD: Add a new library

KiCAD: Add a new library

Click on the “Add” button on the right top (near the “Component library files”) and find and select the MyKiCADLib.lib.  The press the “OK” button on the Library preferences window to finish.

Now when you add a component select the “Select by Browser” and you can search for it in your new library… It the moment this library has no parts in it, but it should show up in the left most panel.

KiCAD: New Library is empty...

KiCAD: New Library is empty…

So now it is time to add a part to the new library.  You have two options, you can go ahead and use KiCAD library editor.  This is nice, and I’ve used it a few times when I can’t find a part on the net.  But like most things on-line, someone has probably done the work already!

I’ve found that the part I’m interested in is somewhere in a existing library that may have a few hundred parts in it and I’m only looking for the one part.  So rather than adding yet another library to KiCAD I extract the part from the library and add it to my library.  As the libraries are all text this is easy to do.

For example the DS18B20 is defined like this:

# DS1820
DEF DS1820 IC 0 40 Y Y 1 F N
F0 "IC" -100 400 60 H V C CNN
F1 "DS1820" 0 300 60 H V C CNN
F2 "~" 0 0 60 H V C CNN
F3 "~" 0 0 60 H V C CNN
S 150 -100 -150 250 0 1 0 N
X GND 1 100 -400 300 U 50 50 1 1 W
X DQ 2 0 -400 300 U 50 50 1 1 W
X Vdd 3 -100 -400 300 U 50 50 1 1 W

Parts always start with a DEF and end with an ENDDEF. Look out for these if you are taking a part from an existing library.

Paste the text into you new shell library:

EESchema-LIBRARY Version 2.3  Date: Wed 07 Nov 2012 01:16:37 PM GMT
#encoding utf-8
<insert component text here>
#End Library

Save your modified library and exit out of the schematic editor and restart it (required to pick up changes to libraries!).

Now when you add a component you should see your library has two parts in it: “DS1820” and “DS18B20”.  Go ahead and add this to your schematic.

KiCAD: Part added to library

KiCAD: Part added to library

It as easy as that.. Hope you found this a help!

The EthNode – Hardware build

A quick update on the EthNode: I developed and etched a double side PCB for the EthNode last night and have just finished assembling the components. It’s a tricky build as I can’t plate the through holes with my home setup. If it works, I’ll be getting a few PCB’s professionally made!

The PCB developed with good clean traces.  I was trying to make a JeeNode too, put my inkjet printer ran out of ink and the laser version of the artwork was not dark enough.. so I guess I now know that inkjet is the way to go for printing artwork for PCB production!

Here is the top side of the PCB with a few parts added:

Ethnode - Build start

Ethnode – Build start

The back side is good a clean too, and the hole alignment is much better for this PCB.  I converted an old scanner to a light box which made alignment of the artwork quick and easy to do.

Below is a photo of the assembled PCB, you can see more on my Flickr page if that is your thing!

Ethnoe - Fully assembled

Ethnoe – Fully assembled

Another view.. from the MagJack end:

Ethnoe - Fully assembled (MagJack side)

Ethnoe – Fully assembled (MagJack side)

A close up of the only SMD part on the board (the 25LC512 serial EEPROM):

25L512 serial EEPROM memory

25L512 serial EEPROM memory

All the rails (+5 an 3.3V) are good and a quick electrical check with a multimeter didn’t show up and shorts as I guess it’s coding time..


The EthNode – ATMega based Ethernet board

Taking inspiration from the good folks at Nanode and an Instructable I saw recently, I’ve come up with “another” AVR based Ethernet board that can be programmed and used like an Arduino.

It’s a simple design based on the ATMega and Microchip’s ENC28J60 Ethernet controller with SPI.  Running MQTT on one of these will open up a few options for home automation and remote sensor monitoring.

It’s not as complex as the Nanode.  It doesn’t have the Arduino header locations, but all the major pins are available at headers. There is a 25L512 chip providing 512 Kbit Serial EEPROM for MAC addresses and logged data if one needs it. The PCB is only 80x50mm in size!

Here is the schematic:

EthNode Schematic

EthNode Schematic

Here is the PCB layout:

EthNode PCB Layout

EthNode PCB Layout

All the resources (KiCAD files, libraries, etc) can be downloaded here:Ethnode-V0.9.tar

This morning I got a delivery from Farnell with all the parts.. Busy weekend ahead!

Arduino RGB LEDs and MQTT

Yesterday I took my RGB LED strip project and upgraded it to use MQTT instead of the simple terminal server I was using before. I couldn’t get it working using my WiFly shield, the system would work fine for five minutes or so and then crash. I did a little digging around, thinking it may be a memory issue, put came up blank.  So ditch the WiFly shield and dig out an Ethernet shield…

Arduino Ethernet RGB Lights

Arduino Ethernet RGB Lights

Then installed the Nick O’Leary’s Arduino MQTT library, and got coding:

 * Ethernet RGB LEDS with MQTT 
 * (c) Mark McKillen

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

#define MQTT_SERVER "<Mosquitto Server IP>"

byte MAC_ADDRESS[] = { 0x91, 0xA3, 0xAA, 0x00, 0x01, 0x03 };
char message_buff[30];

int redPin   = 3;   // Red LED,   connected to digital pin 9
int greenPin = 5;   // Green LED, connected to digital pin 10
int bluePin  = 6;   // Blue LED,  connected to digital pin 11

EthernetClient ethClient;  // Ethernet object
PubSubClient client( MQTT_SERVER, 1883, callback, ethClient); // MQTT object

void setup() {
  Serial.println("Net begin");

  if (Ethernet.begin(MAC_ADDRESS) == 0)       // Get connected!
      Serial.println("Failed to configure Ethernet using DHCP");

  Serial.print("IP: ");                       // A little debug.. show IP address

  if (client.connect("arduinoClient")) {      // connect to MQTT server
    client.subscribe("rgblight");             // subscribe to topic "rgblight"
    Serial.println("Connected to MQTT");      // let us know this has happened

void loop()
  client.loop();                              // loop for ever waiting for MQTT event

// handles message arrived on subscribed topic
void callback(char* topic, byte* payload, unsigned int length) {
  int i = 0;

  // create character buffer with ending null terminator (string)
  for(i=0; i<length; i++) {
    message_buff[i] = payload[i];
  message_buff[i] = '\0';

  long colorVal = strtol( message_buff, NULL, 16);

  analogWrite(redPin, (colorVal&0xff0000)>>16 );
  analogWrite(greenPin, (colorVal&0x00ff00)>>8 );
  analogWrite(bluePin, (colorVal&0x0000ff)>>0 );

Really simple, that is the cool thing about MQTT, it’s so easy and powerful.

To light the lights all I need to do is:

mosquitto_pub -h <mqtt server> -t rgblight -m "ff0000"  # All red
mosquitto_pub -h <mqtt server> -t rgblight -m "00ff00"  # All green
mosquitto_pub -h <mqtt server> -t rgblight -m "0000ff"  # All blue

The lights respond quickly, much faster than my last version. Success!