Archive

Archive for the ‘electronics’ Category

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 🙂

Incoming search terms:

  • pic projects for beginners (36)
  • pic platform (15)
Categories: electronics, projects Tags:

Fixed Time Loop in Microcontrollers

March 31st, 2011 No comments

Hey.

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…

Incoming search terms:

  • median filter (22)
  • spike filter (22)
  • sensor noise filter (20)
  • how to filter spikes sensor (16)
  • median filter adc (13)
  • c code simple spike filter (10)
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:

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…

Lego Mindstorms – Interesting Advanced Projects

March 27th, 2010 No comments

When I was a kid I remember building small houses and castles using my Lego pieces collection. Even back then you could tell that people creating that stuff had a really creative thinking and ideas. Looking at todays Lego robotic products you can safely assume that they still have that flare of creativity 🙂

Few years back I also bought my first Mindstorms kit. I was quite amazed by the possibilities of this kit. However, me as a person, I have short imagination 🙂 therefore I quickly run out of ideas and moved on to other stuff.

Recently I came across some interesting projects done using the newest NXT mindstorms by Lego and I was truly amazed BIG TIME! Some people have really clever ideas and they implement them beautifully. Not only they are able to put together a working body frame but also there is some clever programming too! Read more…

Incoming search terms:

  • lego mindstorms projects ideas (32)
  • lego mindstorms advanced projects (26)
  • lego mindstorm project ideas (23)
  • advanced lego projects (19)
  • mindstorm projects (16)
  • lego mindstorm advanced projects (16)
  • Advanced NXT Projects (15)
  • lego mindstorms project ideas (13)
  • advanced lego mindstorm projects (13)
  • lego mindstorm projects ideas (12)
Categories: electronics, general Tags:

ZigBee Switch with no batteries!

July 17th, 2009 No comments

I read this today and I think it is pretty interesting.

Schneider Electric company have developed a new prototype switch for ZigBee networks that operates completely green! That means no batteries at all! This self-powered switch could be real useful in housing applications. Convenient, wireless and total green. What else could you ask for?

See more info here. It’s their press release.

Categories: electronics, general Tags: ,

Need motors for your robot? – Servo Motor Hack

April 13th, 2009 No comments

Another quick post. If you are just starting on small scale robots you may wondering what motors to use for movement. A quick google search may scare you actually 🙂

I am telling you this because I had a similar experience when I was starting out. You see, if you look for ‘robot motors’ you are most probably be taken to a DC motors website. First of all a decent DC motor would probably cost more than a newcomer wants to spend just to test it out. And most important it is quite complicated as you need to mess around with DC motor controllers and other stuff like gearing. Read more…

Incoming search terms:

  • servo motor hack (12)
Categories: electronics Tags: , ,

Zigbee Networks – PIC Xbee project

April 1st, 2009 13 comments

Hello again,
Long time no see huh! Well I was pretty busy with many many things. I hope I can find more time to write more posts here. Today we are going to talk about PIC Zigbee projects.

Last year I was working on a PIC project that needed wireless communication and I made a little research on the internet where I came across ZigBee networks. Zigbee specification is ideal for low power applications. It is actually an offspring of the IEEE 802.15.4-2003 standard which is aiming low power wireless communications. Read more…

Incoming search terms:

  • pic zigbee project (14)
  • zigbee interfacing with pic16f877a (14)
  • pic zigbee (12)
  • pic16f877a interface with zigbee (10)
Categories: electronics Tags: ,