1-Wire (OneWire) C18 library

November 17th, 2011 No 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 (0×44)
  • 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…

Categories: electronics Tags: , ,

Path Optimizer for pcb-gcode

November 13th, 2011 No 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 cncopt.py 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 https://github.com/demestav/PCB-GCode-Path-Optimizer

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 CNCzone.com 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:

Serial Interface Between PIC and PC – PR4

October 4th, 2011 No comments

This one is really useful.

Most of the times you are developing a project, you will need some sort of monitoring or visual output to understand the status of your program. Sure some LEDs blinking are great but some times you need more. This is where the good old serial communication comes in. Through this communication you will be able to send information in the form of data or text, to and from your computer. You can use it as a debugging tool to monitor what is going on in your microcontroller during execution time. Or you can use this communication to send data to the PIC for processing and then receive the result back. I am sure you will appreciate the usefulness of this as soon as you implement it.

And all this happens by sending a sequence of zeros and ones… Read more…

Categories: electronics, projects Tags: , ,

PIC and 5110 Interface with SPI hardware – PR3

September 26th, 2011 No comments

This is the first “official” project I am doing with my PIC prototyping board. This project is about interfacing and using a simple Graphic LCD. So to follow this project you need a PIC to have SPI hardware, in order to communicate with the device. The GLCD (Nokia 5110) I am using is well known in the community and it is a cheap device. I bought it off ebay for about 5 Euros. Read more…

Categories: electronics, projects Tags: , , , ,

PIC Prototyping Platform – PR2

September 7th, 2011 No comments

Hey,

In PR1 project, I talked about creating a stable prototyping platform that would save me from the trouble of setting up the microcontroller and all its required components. However, since then, I worked on tidying up this design into a more usable design (I wanted to play around with creating PCB actually :D ). So I designed the board sent it for fabrication and finally put it together. Read more…

Categories: electronics, projects Tags: , ,

Components for the Prototyping board arrived!

September 1st, 2011 2 comments

Hey guys,

A couple of days ago, the components for my new PCB arrived so I was able to test my design. The result was successful! Personally this was a simple board carries a lot of “firsts” for me. To begin with, it was the first time I ever designed a board on EAGLE that became an actual PCB. This might sound stupid but its different to make a design for home production (using chemicals) and a design that includes 2 layers, vias, solder masks, silkscreens, correct drill holes etc. I am not saying its hard, I am just saying its different so there are new things to consider.

Another “first” was the soldering of a TQFP package which as it turns out its not that hard (actually its like magic ;) )! I had to buy some solder paste and a tweezers to make my life easier. I am suggesting to check out Surface Mount Soldering guide if you are interested.

Anyway, for a first attempt, I believe the results are pretty good. I made a simple blinking LED program which works, the power switch and reset button work, so I am assuming the design is OK.

I will make another post soon to include the schematics and stuff if anyone is interested and hopefully start producing some projects on this proto board. Finally here are a couple of pictures of the board:

Looking good!

Dimensions are 5cm x 5cm

Low Cost PCB Fabrication

August 13th, 2011 2 comments

Hey guys. I am really excited today because my first ever PCBs arrived from the fabrication house! I always wanted to have my own PCB printed but I was deterred by the price. So I used other methods such as developing my own board which can get quite messy or just sticking with the traditional prototyping boards. Few weeks back, I read a post from Kenneth, which led me to this fabrication house. They actually offer 10 PCBs maximum sized 5cm*5cm, for only $9.90 and $4 for delivery! This is really really cheap! Read more…

Categories: electronics Tags: ,

XBee Dropping Bytes – My Solution

April 29th, 2011 No comments

Hey guys a quick post here.

Since the first time I used XBees (2 years back?) I noticed that they were dropping bytes. This is quite annoying as it disturbs the normal flow of your device. What I did fixed it for good and I never had a single bit dropped from XBees ever again, and let me tell you I sent many thousands bytes so far :)

Anyway, what you need to do is really simple. You need to assign a destination to your transmission. You do that by first  entering the command mode (when using the AT firmware). To do that you need to enter the “command sequence character” three times in a row i.e. for the default settings enter “+++” (without the quotes) to the terminal. The XBee should reply with “OK” and you have a short period of time to enter an AT command. Next you need to send the destination XBee by entering “ATDN<DESTINATION ADDRESS HERE>”. And that’s it :)

Let’s do an example. You have two XBees, one is called BASE and the other one is called HELI. Oh make sure you name your XBees by changing the Node Identifier in the settings. If HELI wants to talk to BASE it will

  1. Enter “+++”
  2. Wait for “OK”
  3. Enter ATDNBASE

Now you can send as much data as you want and you wont loose a byte. This is so simple. Do the opposite i.e. BASE->HELI and you will have a pretty good two way communication.

Let me know if you need any help

Categories: electronics Tags:

Total Beginner’s PIC Platform – PR1

April 27th, 2011 No comments

So I was thinking its time to start posting some complete projects. I am starting with some really basic projects to help the people just starting with PICs. However, before doing that we need to have a common platform to develop on, so we don’t need to discuss about it every time. In this first project (see how I codenamed it PR1!) we will create a minimal PIC platform which we will use in future projects. I will list everything you will need to buy to get you started.

As the brains of this platform I am choosing the PIC18F4520 which I believe it is a pretty nice PIC to work with, having enough peripherals, memory and speed for any beginner project. Let’s see the components you will need:

  1. Breadboard – if you don’t have one, you really need to buy one!
  2. PIC18F4520
  3. 10MHz oscillator
  4. 2 x 22pF capacitors
  5. 10kOhm resistor
  6. 7805 Voltage regulator
  7. PICKit 2 (or 3)

Using the above components will allow to build a functional board even though more components are needed to be “perfect” (smoothing capacitors on the regulator, a couple of diodes between the programmer and the supply and more). Of course it would be nice to add a switch, a reset button, LEDs, and the list goes on, but this would increase the cost of the board. Consider this as a quick-and-dirty solution just to get you started. Maybe on a future post we create a more complete board. For now I believe this is a good starting PIC testing board.

Using the schematic below, hook up the board. I am also attaching a photograph of my own testing board for reference. You also need some sort of power. I find it convinient to use the 9V battery holder and connect it either with a 9V battery or a power supply. Feel free to use any kind of power supply as long as it is between 6V and 12V. If you are (somehow) using a 5V supply, take the 7805 regulator out.

After connecting everything it would be a good idea to write a simple program to check the functionality of the board. I have a simple LED blinking program already compiled. So, using your programmer, transfer the HEX file (attached at the end of this post) to your PIC. To test this out you will need an LED and an 1kOhm resistor connected to the A0 pin as shown in the figure. Turn on the PIC and the LED should be blinking every 1 sec. If not then something is wrong :) . But don’t worry. The board is simple enough to figure out where the mistake is and if you have trouble you can always ask me.

So now you have a board to play with :)

Categories: electronics, projects Tags: