Sunday, April 05, 2009

Computer and micro-controller communication

After my digital thermometer, I thought it is worthwhile to integrate my micro controller (uC) projects to my computer. There are tonnes of advantages that I see by doing this. While working uCs, specially as being a computer programmer, I found it difficult to achieve a number of stuff. Most basic things like input / output aren't readily available (note that I'm not blaming the uCs here; after all we are not writing software here, but building hardware) -- this makes it very difficult to debug or build prototypes. These days I use LEDs (and different blink rates) to debug various scenarios. But imagine how I would have debugged my first LED blink project :) -- there was simply no way. Not just debugging, allowing uC to talk to the computer (when required) opens up a whole new world of communication. There are so many features that become readily available, like
  • keyboard - I can configure my uC parameters at runtime from my keyboard?
  • monitor - I can send some debug output or runtime logs to my comp and record it?, you know much work I did to show just 2 digits in hardware.
  • processing power - not sure how useful it is but if I need I can make use of the huge processing power a comp has.
  • internet - this is very interesting. maybe my uC doesn't need internet but how about controlling my uC from the internet ?? maybe, controlling my room's lights from office ? office -> internet -> webserver on my home comp -> uC -> light; I think this opens up a lot of new opportunities.
Let's see how it evolves :) I have no idea about how I'm going to utilize, but I'm convinced that given my programming knowledge on computers, it is quite a useful thing to have. Technologies becomes more and more powerful only when they interact.

Now that we are convinced that a computer interface is useful, it is time think about the choices. The possible options are serial port, parallel port, USB, bluetooth, infra-red. Bluetooth and infra-red need hardware counterpart on both sides (on the computer and uC hardware), so that isn't practical for me now. USB seems a option, but that also requires a USB protocol handler on the uC side (there are some free open source USB drivers available for AVR uC's but they would occupy considerable code space -- and with just 8KB available for programming, I would rethink). Serial and parallel ports are the simplest options. Over these two I prefer serial port for two reasons.
  1. Serial port requires fewer number of lines for transmission/reception (technically only 2 lines for data(tx/rx), but additional lines for vcc,gnd etc., add up to 4-5 lines, still much better than parallel port).
  2. ATMega8 has builtin support for handling USART - the standard serial transmission protocol. This makes it handy for us to talk over serial port between the computer and the uC.
So I chose serial port as the preferred communication interface. This does not mean that I can just connect a few wires from serial port of the computer to my uC -- because the logic levels are different between the serial port and the uC. I need a convertor for these logic levels before I can communicate. How? stay tuned.

2 comments:

  1. Hi Dude,

    Was just going through your blog and encountered this loverly post.
    I had done such a project in my college days where i used a philips 89c51RD2 uC for controllin home appliances like TV, Room lights, sterio system, etc,
    I used paralle port for the communication and hence was ristricted to control only 8 devices at a time.
    I had planned to port my project to USB or Serial port which eventually never happned.

    While looking at your post it agiain striked to my mind and will be giving it a secound thought,

    Let me know whats on your mind and progress .. may be i can learn from it..

    Keep it up man

    ReplyDelete
  2. thanks.

    In case you are interested: there is an open source usb implementation on AVR along with the corresponding schematics using an AtMega8. I didn't search for the link now, but that should be easy enough for you to find. I was analyzing that last some months back, but never got back to implementing it.

    ReplyDelete