Archive for November, 2011

1-Wire (OneWire) C18 library

November 17th, 2011 6 comments

So yesterday I wanted to get some temperature measurements from a DS18S20 thermometer to my PIC prototyping board. This thermometer uses the 1-Wire communication protocol so I searched around to find a 1-Wire library for the C18 compiler I am using. Maybe I am wrong but I couldn’t find any. So I created one, hence this post.

I had a post about the 1-Wire protocol a while back so you can read that if you are not familiar with it. To implement this protocol we need to work with precision timing. Ideally this could be written in asm. However, for convenience reasons I wrote this in C. I don’t really mind the minor performance penalty ūüôā

Just to be clear, this is a library for the 1-Wire protocol, not for any of the supported devices. The library contains 3 main functions:

  • 1-Wire Reset
  • 1-Wire Write
  • 1-Wire Read

Using these three operations we can have full communication with any 1-Wire device. Let me demonstrate first and then I will write about how you can use it in your project.

A brief demonstration

To demonstrate this operation, I connected a DS18S20 thermometer and connected the DQ line on my PIC’s Port C Pin 1. The procedure I will follow is:

  • Issue a Reset pulse and observe the Presence of the thermometer
  • Issue the Skip Rom command (0xCC)
  • Issue the Convert T command (0x44)
  • Wait for 1+ second
  • Issue a Reset pulse and observe the Presence of the thermometer
  • Issue the Skip Rom command (0xCC)
  • Issue the Read Scratchpad command (0xBE)
  • And read the next two bytes which represent the temperature

Lets see the C code I loaded on my board Read more…

Incoming search terms:

  • ds18b20 c18 (18)
  • 1 wire xc8 pic18f library (1)
Categories: electronics Tags: , ,

Path Optimizer for pcb-gcode

November 13th, 2011 8 comments

The last couple of days I used the CNC machine to create a PCB for a project I am working on. As the CNC was etching away the copper, I noticed that between paths (i.e. while the spindle was not cutting) there was a lot of¬†unnecessary¬†travel. This happened quite a few times during my 35 minute job. Because I am using slow feedrate, about 10in/min, that¬†unnecessary¬†travel must have added 2-3 minutes. So if you are here looking how to optimize gcode you are at the right place ūüôā

So to solve this, we need some optimization. What a better thing to spend your afternoon than firing up python, calling a friend and colleague over your PC, and solve this problem. So me and Mike, decided to solve this the easiest and quickest way possible, just by using brute force method to combine the different paths together. The goal is of course to minimize the unnecessary travel of the spindle.

Since this is a python script, it is multi platform. I personally tested it on my Ubuntu and Windows XP.

Some results

Let me just show you a couple of screen shots of a job, run on a simulator. This is the PCB of my last project. First let’s see the screenshot before optimizing the code

Spindle path before optimization

The white line represents the travelling between two paths. As you can see there are a lot of those white lines! ūüôā Now let’s see the second screenshot which is the same PCB job, but this time with optimized gcode

The path after optimization

As you can see the white lines are reduced. Also notice the clock (below the STOP sign)  of the simulator. We just saved a few minutes!

The program

First of all we assume that you already installed python on your system. Download the optimizer script. There is no GUI yet (feel free to expand the code, use git) so we need to run it from command line. Just write

python your_file_here

The script will run and give you some stats on the performance of the optimization.

Screenshot from my terminal

As shown, in my PCB gcode, the optimized code reduced the travel time from 33 inches to 14. That is a decrease of about 60%. The optimized file will have the same filename with an additional .optimized at the end.

Please note that this was a one-afternoon project just for the fun of it. All comments and feedback are welcome. I hope you find it useful.

I would like to thank Mike as we developed this together.

You can find the project on GitHub

Incoming search terms:

  • cncopt py (78)
  • g code optimizer (34)
  • gcode optimizer (33)
Categories: CNC Tags:

How to flatten the CNC table

November 3rd, 2011 No comments

Hey guys, recently we got a medium-low end CNC machine in the lab I am working. We got it mainly for prototyping PCBs of our projects. I am still in the process of fine-tuning the machine. The learning curve was (is!) pretty steep and makes it even worst if you have little time to spend working the machine.

Anyway, when I printed my first PCB using 15 mils for copper width, I noticed some inconsistencies on the final result. One factor of this problem is the fact that the cutting table is not flat in relation to the XY axis of the machine. In other words, the distance between the table and the spindle is not constant along the plane.

This could happen for many reasons, your table may not be flat, the machine may not be exactly horizontally fixed to place etc. After asking around the web, the good fellas at the¬†forum, suggested to flatten the table surface by milling into it. So what that means is that you pass the cutting tool up and down, cutting out a square area on your table. Since the cutting tool is always at the same depth, the square are should be completely flat with relation to your cutting tool. Genius isn’t?

A nice and flat square on the wooden table!

In order to do that, you need the appropriate g-code of course. I search around a bit and found a software for that, but for some reason (bugs?) it wasn’t working well for me. For that reason and also because I wanted to learn Java Applet programming in a day :), I created a simple tool to create that square area for you.

Head over to CNC Tools page to find my online tool for for a flattening the CNC table. The tool will load into your browser and after you input your data it will give you the g-code and the estimated time to finish the job. You can test the generated g-code on a CNC simulator.

Let me know if you have any questions, suggestions or bug to report.

Categories: CNC Tags: