Components for the Prototyping board arrived!

September 1st, 2011 3 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 1 comment

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:

Fixed Time Loop in Microcontrollers

March 31st, 2011 No comments


Most of the times I am developing a piece of code for my PICs, there is a main loop in the flow. The code repeats it self indefinitely doing its thing and it is only interrupted temporarily by the hardware interrupts of the PIC. Now most of the times a simple while(1) { // code here } will do just fine. However, sometimes your need that loop to start at specific time interval for example every half second. This is pretty useful when somewhere in your maths you need a specific dt. Read more…

Categories: electronics, programming Tags:

Filtering a Sensor with Noise and Spikes

January 5th, 2011 3 comments

Recently I have been working on a robot that required accurate measurement of distance (more on that robot on a later post). I noticed some unpredictable behavior of the robot and so I investigated further to find out what was wrong with it. It turns out that the Sharp GP2D120 sensors I used are pretty noisy! I didn’t do much research about it before adding it on my project. When I needed to know the distance value, I took 10 consecutive readings and averaged them. But that was not such a clever choice for filtering and you will understand why, in a while.

Let me first explain you my testing platform. First of all we have the robot that has the GP2D120 sensor on. The PIC micro (used a PIC18F4520) on the robot is able to transmit wirelessly using an XBEE module. Data is received on my PC using another XBEE module through USB. Finally, data is analysed in MATLAB. So I position my robot to be stable, so that the distance sensor should read the same value constantly. Each value read, is transmitted and captured on my PC.

Experiment 1 – No filtering

No filtering

Notice that the y axis is the ADC value and not the voltage value directly. As you can see there are some pretty nasty spikes over there! They occur quite ofter as well. Converting those values to distance, spikes reach up to 3cm ! So you have a wrong measurement by 3cm. For a project that requires accuracy that is a nightmare! Read more…

Categories: electronics Tags: , , ,

Plans for my first line following robot

November 7th, 2010 No comments

Hi there. Now that some obligations are out of the way I am back to my drawing board 🙂

I am thinking of building a line following robot. Hmmm “simple” you might think. Well, maybe but it depends on what you are aiming for. You see the whole concept of the line following competitions is to keep the task simple. This way, you can concentrate on building the robot doing exactly that, as good as possible. As a result, you have many robots trying to do a “simple” (its not that simple actually) task but each one is programmed differently with smart twists, in an effort to be quicker than the rest.

Moreover, you have to keep in mind that a robot is the unification of different sectors (mechanical, electronics, electrical…) into one functional unit. Every part of the robot should work as expected, in order for the robot to function correctly as a whole. For example, the chassis of the robot. How big it should be? big is heavy, small is light but not much room for your electronics. Where do the motors go on the chassis? How will you mount them? Then you have to think about what kind of motors to use, how much torque, rpm, power, consumption do the have? Then you have to think about your electronics, about motor driver, the MCU and other stuff you might need. Then comes the programming part. How can you tell a robot to follow a line? After you figure that out, how can you do this process efficiently, giving you the best result relative to speed.

Anyway, sorry if I confused you or that didn’t make much sense. I just wanted to say that building a robot (even to do a simple task) is a multi-skill process. Don’t be afraid though, I am not saying you have to be an expert to do it. Just some careful thinking before buying your components. Sit down with a pencil and a piece of paper and write how you would build such a robot. Divide your design to the sectors we mentioned above. Try to learn from the designs that other people have done (but don’t copy them, otherwise the purpose is lost) and try to isolate each problem and deal with it.

For example, I had some hard time figuring out how to build my chassis. After some looking around I decided that for now, the cheapest and quickest solution, is to make my designs on google’s SketchUp and transfer it onto thick PVC.

Sometime soon I will start my construction and I will keep you posted.

Categories: electronics, programming Tags:

Install sun-Java6-bin on Ubuntu 10.04

June 3rd, 2010 No comments

Just a quick tip. If you try to install Java in a fresh Ubuntu 10.04 system you won’t get very far as the Java moved to the Partern repository. To fix this open the command line and write:

sudo add-apt-repository "deb lucid partner"
sudo apt-get update

Then you can install your Java 🙂

Categories: general Tags: ,

wp_insert_post removes style elements

April 29th, 2010 1 comment

Recently I was using the wp_insert_post function of wordpress to make a post through a plugin. The problem is that this function removed the styling element I included. For example I used this:

<div id="myid">Hello</div>

and after posting this through wp_insert_post it got like this:


I search for a solution for a couple of days but I couldn’t find a straight answer. Anyway, as it turned out it’s not such a hard problem. I am not a wordpress wizard (not even close :P) but I believe I solved my problem.

Locate the file /wp-includes/kses.php . This function is called when you make a post to filter out all the bad things that may be a risk for your blog. At line 44 (on my file) you can see an array of allowedPostTags. If you take a look you can see that what I was trying to add i.e. the id it is not conained in the div sub-array. That is the reason why it was removed. So I believe you can do 2 things:

  • You can use an allowed tag instead. This is what I did. I noticed that div class was an allowed tag so I used that instead of div id. Not much difference for me 🙂 and it worked.
  • I believe you can also manually add the id tag in the div sub-array in the same way as the other tags are added and it wont be removed. I have’t tested that but I am pretty sure it would work

Anyway, that’s all. I hope you can solve your problem. Let me know in the comments if you need some help.

See ya.

Categories: web Tags:

Simple Serial User Interface on PIC

March 30th, 2010 No comments

So today I needed to control some stuff on my PIC by using the terminal on my PC through RS-232 serial. I want to control the speed on 2 motors connected to the PIC, either separately or both of them together. To do that I divided the tasks that the User Interface (UI) had to provide. So from the main menu the user should be able to choose to control

  • Motor A
  • Motor B
  • Both Motors

In each of the sub-menus shown above the user should have some choices for acting on the motors. Before complicating this stuff more, I will show you the method I used to create this simple menu on my 18F2525 PIC. It doesn’t matter if you don’t have this PIC or even any other microcontroller. The concept is the same.

If you try to tackle the problem an if-then-else structure may seem like an easy solution but I can tell you it is going to messy pretty soon! We need a more clear, robust solution. But first let’s see what we need to do.

PIC User Interface Layout

The image pretty much explains it all. If we are at Main Menu the only valid keys are 1, 2 or 3. Each leads to a new sub menu. From there, there are again three choices 0 that takes us back to Main Menu and + or that will need to take an action (colored green). So if we implement this menu you will be able to implement more complex ones based on the same concept.

I got this idea based on Finite State Machine concept but its not quite right so we cannot call it like that! Anyway. Each of the menu item (Main Menu, Motor A, Motor B, Both Motors), is a different state in the program let assign them 0,1,2,3 accordingly. So if we are at state 0 we can go to state 1,2 or 3 with the right key pressed in the terminal. However if we are at state 1, we can only go back to state 0 or stay at the same state and complete some actions (forwards, backwards) with the right buttons pressed, once more.

So the way to implement this is by using switch/case. I think it will be much clearer if I show you the code. First let’s see how to we switch between the states. Read more…