How to open Gerber files in AutoCAD with free open source tools

Here is a method for how you can import a Gerber RS-274X file into AutoCAD. There are many commercial software solutions to perform this, but this is how you can do it for free using open source tools!

You’ll need to install and configure (if needed) the following software.

  • gerbv – this is used to view Gerber files, and can also export to a variety of formats (but not DXF or DWG for AutoCAD)
  • pstoedit – converts Postscript files to many different other formats
  • ghostscript – needed by pstoedit

Open your Gerber files in gerbv. This process work for multiple layers as well. You should see your Gerber to make sure it is what it should be.

Export the Gerber set to PostScript. File -> Export -> Postscript…

Optionally, if you don’t need to visually check the Gerber file in gerbv, gerbv supports exporting via the command line, for example:

gerbv -x ps MYGERBER.GTL

Now convert the Postscript (.ps) file to DXF using pstoedit. This is best done on the command line.

pstoedit -f dxf foobar.ps foobar.dxf

Now you should have a .dxf file which you can open in AutoCAD.

Caveats

When working with multiple Gerber files and you export them all at once to one .ps file, and convert them to a single .dxf, all the information comes up in AutoCAD as a single layer, but the original layers can be differentiated by their colours.

However you could manually move different colours to new layers if need be (using QSELECT command in AutoCAD). This probably could be scripted, but that’s a bit beyond my means at the moment.

GLCD Library Support for PIC24H with ST7565R / ST7565P / PCD8544 (Nokia 3310 5510) LCDs

My graphic LCD library (glcd on GitHub) now supports PIC24H with the ST7565R, ST7565P and PCD8544 LCD controllers.

The code has been tested with the Newhaven display NHD-C12864A1Z-FSW-FBW-HTT and NHD-C12832A1Z-FSW-FBW-3V3. I used a Microstick II development board to test these, with demo code available below. I don’t have any PIC24F chips so I wasn’t able to test it with those chips as well (I think I have lost the chip from the Microstick II package). I would think only minor changes would be needed to make it work with PIC24F.

Sample code

Sample code for use with MPLAB X IDE.

Here are some sample projects:

Note that the glcd libraries included with the demos above are not kept up to date as further updates are made to the official glcd library. You can update the library by copying the latest glcd distribution into the existing project files. (take note of custom pin configurations, more details below)

Pin configuration

With the projects above, the pin connections to the LCD’s SPI interface are as follows:

  • SDA (serial data input) => RB14
  • SCK (serial clock) => RB15
  • SS / CS (chip select) => RB2
  • A0 (command / data write selection) => RB3
  • RESET => RA2

To add your own custom pin configuration, you can edit the file ‘devices/PIC24H.h’. You can also make a custom configuration file by creating a `glcd_user_config.h’ file outside of the glcd directory and defining a new compiler symbol ‘GLCD_USER_CONFIG’. Copy the contents of ‘PIC24H.h’ into it. This way, if you need to  update the library, you can simply overwrite the contents of the existing glcd directory without losing your custom pin configuration. Otherwise, you can just keep track yourself of custom changes made to the *.h files in the ‘devices/’ directory.

Videos

Footage of Newhaven Display NHD-C12864A1Z-FSW-FBW-HTT in action, running the sample code:

Footage of Newhaven Display NHD-C12832A1Z-FSW-FBW-3V3 in action, running the sample code:

USB Datalogging on the Turnigy Accucel 6 Hobby Charger

After owning this great little hobby charger for some time, I wanted to use the data logging capabilities of the Turnigy Accucel-6 unit. In particular, the aim is the plot  some discharge curves of some particular batteries.

accucel

A quick search on Google found some articles, but a lot of conflicting information on how to connect the charger to a computer. I decided to perform a few tests on the charger, to see what was really going on, and work out how to connect it to a computer.

Here is what I found out. On the left side of the unit, there is a three pin connector, which doubles up as both a temperature sensor and a serial output. When in serial mode, it sends TTL serial data on the middle pin at 5V levels. The baudrate is 9600 bps, 8 bits, no parity, 1 stop bit (9600-8N1).

To set the charger to send serial data, you’ll need to set it in the menu and make sure USB mode is enabled.

To connect it to a computer, you’ll need a serial TTL to USB connector. There are quite a few options available, some googling shows some advice of the use of cheap Silab chip converters, but personally I prefer to use the more industry standard FTDI chip based adapters. These adapters are pretty cheap, are are based on the FT232 chip, and in some cases,  the newer FT231X part. The one I use is called Foca and it’s under 10 USD from Itead Studios. This unit has a switch that can select between 3.3V and 5V TTL levels. If you use your own adapter, make sure it supports 5V TTL.

foca

accucel_pinout

To connect to the adapter, connect GND pins from the adapter to charger, and the adapters RX pin to the chargers TX pin. I use some of these female to female jumpers, I think they’re more versatile than the recommended fixed configuration adapters I’ve read on a few forums. They’re only about $3 delivered for 40pcs on eBay. Connect the USB cable and plug it into the computer. The charger only sends data while it charging or discharging so set it to do one of these things. The data is sent in bursts around 1.5 seconds apart, 76 bytes in length. If you look on the USB-Serial adapter, if it has a TX and TX LEDs on it, you might see a burst a data every 1.5 seconds.

Using a terminal program, connect it to the appropriate serial port of the adapter, and you should be able to see the actual data being sent. It is binary data, so you won’t be able to read it straight away. On Windows, you can use some free software like Realterm or TeraTerm. On Mac OS X, I like to use CoolTerm. Remember to connect at 9600 8N1.

Here’s a screenshot of a dump in RealTerm when displaying in Hex+ASCII mode.

realterm_screen

You’ll see the data packets are start with a ‘{‘ and end with a ‘}’ char. Here’s a hex dump of a typical packet.

00000000: 7b 9c 84 84 d0 81 80 e4  80 88 85 80 81 8a 85 80 |{...............|
00000010: 81 80 80 8a 81 8c 83 84  81 80 81 81 80 80 8c e4 |................|
00000020: 80 80 8a 86 90 80 80 80  80 8c 92 80 92 80 80 80 |................|
00000030: 80 80 80 80 80 80 80 80  80 80 80 80 80 80 80 80 |................|
00000040: 80 80 80 80 80 80 8a 8f  a4 31 35 7d             |.........15}|

It could take some time to decode this, but Niobos has already spent the time and done most of it on his blog. He has decoded a lot of the data, but I’m only really interested in using the data I need for plotting a discharge curve. This means voltage, current, and capacity. Note that these chargers can only discharge a maximum current of 1A.

I’d like to take this data and save it as a CSV file, so we can plot it and analyse it later on.

On that note, I should mention there is a piece of software called LogView which can read this data. It is a nice piece of software in German, with a somewhat usable English translation. It’s a little old and a bit hard to find the English download, but the site is over here. You’ll need to find the latest version, as I must warn you, if the software detects it has an outdated version and you choose not to update it, it will just close down and not let you use it… bizarre.

To read the serial data, I wrote a Python script, which reads the data through the serial port, and sends CSV data to stdout. You’ll need pyserial installed. Download the script here on GitHub.

To run this program, and view the output on your screen, just pass the serial port as the argument to the script. For example on my Windows machine:

python log.py COM14

You should get an output on the screen similar to this:

Time(s),Minutes,Voltage(V),Current(A),Charge(mAh)
0,45,6.14,0.1,76
1.487,45,6.14,0.1,76
2.974,45,6.14,0.1,76
4.446,45,6.13,0.1,76
5.934,45,6.14,0.1,76
7.405,45,6.14,0.1,76
8.878,45,6.14,0.1,76
10.35,46,6.14,0.1,76
11.837,46,6.14,0.1,76
13.324,46,6.14,0.1,76
14.796,46,6.14,0.1,76
16.283,46,6.14,0.1,76
17.755,46,6.14,0.1,76
19.242,46,6.14,0.1,76

To cancel the running script, press Ctrl+C.

To view the data and save it to a file as well, you can use a program called “tee”. On Windows, this might be part of a Cygwin install, or simply download wintee. For example, on Linux you might want to use use:

python log.py /dev/ttyUSB0 | tee log_file.txt

On Windows, you may have to replace “tee” with “wtee”.

The above should also work with other similar “4 button chargers” like the Imax B6, Bantam e-Station etc, as they all run similar (if not identical) firmware.

Update: It’s been reported by Joe Rosevear who has a HobbyKing Eco Six charger, that the data stream for that unit is a little different from this. He has written a C program to parse the data stream from that particular HobbyKing charger.

Coming soon, I’ll show you how I’ll graph the data using gnuplot.

avr-uart 0.4 released – Atmel AVR UART Serial Library

Please visit the GitHub project page for the most up to date information, and sample code.

https://github.com/andygock/avr-uart

I’ve just updated the avr-uart library to version 0.4. It is designed for use on Atmel AVR microcontrollers. This is free and open source for all to use and is derived from original code by Peter Fluery and Tim Sharpe. Some changes include:
* Supports ring buffers over 256 bytes in size (use the -DUSART1_LARGER_BUFFER in your compiler switches to enable it for USART1 etc). Each USART can have large buffer support turned on or off independently.
* Modified code to use easier to read and understand “uint16_t” type instead of “unsigned int”.
* Some code cleanup You can download

Version 0.4 over here on GitHub. (GitHub project)