Sunday, November 9, 2008

The heights of geekiness

Geek noun \ˈgēk\: Geek  Used in a nice way it is someone who seems to know everything there is to know about computers.

If I were to define myself as a geek, I would say:

   1:    -----BEGIN GEEK CODE BLOCK-----
   2:    Version: 3.12
   3:    GED/J d-- s:++>: a-- C+++(++++) 
   4:    ULU++ P+ L++ E---- W+(-) N+++ 
   5:    o+ K+++ w---  O- M+ V-- PS++>
   6:    $ PE++>$ Y++ PGP++ t- 5+++ 
   7:    X++ R+++>$ tv+ b+ DI+++ D+++
   8:    G+++++ e++ h r-- y++**
   9:    ------END GEEK CODE BLOCK------



(don't understand the above? refer to The Geek Code v3.12, Yup, we have one) smile_nerd


Even as a geek, there comes a point, where you need to draw the line. One such point came today. I found myself facing a dilemma, unable to decide, "How to get bored today". After much deliberation I found that I simply could not decide between five things to do. Under these circumstances I decided a coin toss would be ideal. This of course brought up another question how best to decide between 5 choices using a coin. At that time a brilliant geeky idea came to me, and I decided to whip together a "Random Choice Maker"


Screenshot


Took me 20 minutes to whip together this simple utility, I wrote a simple RNG function it went like:



   1: class myRandomizerClass
   2: {
   3:     public int generateRandomValue(int uValue)
   4:     {
   5:         int millisecondsNow = DateTime.Now.Millisecond, breakIndex = 1000/uValue;
   6:         return millisecondsNow/breakIndex;
   7:     }
   8: }



It uses a simple uValue for checking quantile density.


So, that's it. Once again I ended up prooving that "Once a geek, always a Geek"


Cheerio. smile_tongue

Sunday, September 28, 2008

Digital Thermometer

 

Thermometer

Not too long ago, I took the plunge into the world of Linux. Only to find myself constantly requiring to skip down to the command line to perform even some of the simplest of tasks. So when I learned about KontrollerLab, I was itching to get creative with it, and the "Digital Thermometer Project" is born.

Well to be quite honest, building a digital thermometer is a no-brainer. But I really had to do some building, or die of dull boredom.

Those of us familiar with Unix/Linux (and other Posix based OSes) would understand why I felt frustrated when I had to keep getting down to the command line to do a simple $avr-gcc -mmcu=atxxxx -O0 -c /Projects/xxxxx/xxx.c. I wrote a few scripts to automate a few tasks, but that wasn't sufficient. When I learned of KontrollerLab IDE I wasn't too hopeful, I tried it not expecting much. Frankly, I was blown out of my mind. It was excellent! It is comparable to almost any good commercial Microcontroller Development IDE. Since it works with avr-gcc, it would be compatable with most of your existing code for the AVR.

Screenshot

Though it may seem that way, but this post is not about the development tool I have been emphasizing about so far! So lets discuss what we this post is really about. This weekend I'm building a Digital Thermometer.

Here is what we need.

dsc00032

* Soldering Iron - Check.
* Random Wiring - Check.
* Some Discreets (Resistors, LED's etc.) - Check
* Headers and Sockets - Check.
* Microcontroller (ATMega32) - Check.
* LCD - Check.
* LM35 - Check.

* Geeky Brain - Check. ;)

OK, Good to go :D.

 LM35

Now, Some may be wondering why I preferred the National Semiconductor LM35 over the much easier to use Dallas DS18x20. Well, for starters, I have a huge load of LM35's lying with me (remnants of an old project :P), and the second reason is, the LM35 is analogue, and pre-calibrated (yes, so is the DS18x, I know). And lastly since the LM35 is linear (10.0 mV/°C) it makes for easy calculation of the temperature from the sensor voltage. The sensor voltage is sampled using the ADC of the ATMega32. I wrote a C function to sample the ADC, it goes like:

void readAdcValue(int channel)
{
ADMUX=channel|0x40;
ADCSRA|=0x40;
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
adcVal = ADCW;
}


For those not in the know, basically the function is using the ADMUX register to select the ADC channel that we are using, then we trigger the ADC Conversion using the ADSC (ADC Start Conversion) bit (bit 6) of the ADC Control and Status register (ADCSRA, we OR it with 0x40 i.e 0b 0100 0000). We then wait for the ADIF (ADC Interrupt Flag) to get set, then we sample the ADC value using the ADCW (ADC Word). ADCW is *not* a register. It is basically a combination of the ADCH and ADCL register. Remember the ATMega32 is an 8-bit processor, so all registers are 8-bit, and since the ADC is 10-bit, the ADCH (ADC High Value) and ADCL (ADC Low Value) registers are used.



Ok, Now we have an ADC reading, we have to convert that into a Sensor Voltage value and then convert that into a temperature.



void showSensorVoltage(void)
{
char* buff;
lcd_gotoxy(0,0);
lcd_puts("Sensor Voltage:");
sensorVoltage = (adcVal * 1024)/5;
buff = intToString(sensorVoltage);
lcd_gotoxy(0,1);
lcd_puts(buff);
}

void showSensorTemp(void)
{
char* buff;
lcd_gotoxy(0,0);
lcd_puts("Temperature:");
sensorTemp = (sensorVoltage * 500)/1024;
buff = intToString(sensorTemp);
lcd_gotoxy(0,1);
lcd_puts(buff);
}


I use the equation,

sensorVoltage = (adcVal * 1024)/5;


and,


sensorTemp = (sensorVoltage * 500)/1024;



Ok, the code is divided into the following functions:



void init(void);
void showWelcome(void);
void showAdcValue(void);
void showSensorVoltage(void);
void showSensorTemp(void);
void readAdcValue(int);
char* intToString(int);
int main(void);


You can get a more detailed Idea by looking at the attached code.



Ok, Time for the hardware assembly. I designed a schematic for the whole system:



Schematic



After hours of assembly and debugging:



dsc00026


dsc00022



And it works!!!dsc00027


dsc00029




Case Modding:



Ok, so now I need to make a case for this thing. I got a standard SMPS casing (again, leftovers from an older project) lying around.



dsc00037



The size is more or less right, but the insides are a bit messy



dsc00040



Anyhow, after some work, I managed to fit it all.... Not too neat. But not unacceptable either.



dsc00015  



dsc00017



dsc00020



 



Thats all folks!!



Stay Tuned! :)

Non-Geek: My Friends Blog

 

 

Well Guys long time since I posted anything around here, Its time to clean out the cobwebs and move in again. :)

To start out, my Friend, and Clan member the one and only Mr. Riteek "VoLdEmOrT" Arora is on Blogger now, I'm sure all the Geeks and even the Non-Geeks (do we get that kind around here? ;) ) would enjoy his blog. His interests involve around F1, Linux (apparently Harry Potter Characters ;) ), well....You read his blog.

DSC01153    
Pictured above: Mr. Riteek "VoLdEmOrT" Arora

Visit his blog: RiTeEk "VoLdEmOrT" aRoRa'S Blog

 

Cheerio!! PS. A geeky entry is coming soon....Stay tuned!

Sunday, April 20, 2008

TicTacToe Bot (Part 2)

PART-2 : The TicTacToe Robot Controller

IMG_0140

Now, that we have an algorithm working, what's next? Good question. Lets take a look again at the block diagram of our electronics:

 block-diagram

Roughly based on the above I whipped together a Schematic:

Schematic

Basically a Atmel (AVR) ATMega32, with a 2x16 Character LCD,  a Keypad Matrix,  and A set of headers for interfacing with the motion driving circuitry and sensors.

Step 1: Preparing the firmware.

This was main part, apparently porting the windows 'C#' code to plain 'C' wasn't all that simple, after all. Well it would have been , except:

Error_mem

So, I did a bit of optimization, and then some more, and then a LOT more. A poem would explain better:

"Till I had reduced each int to byte,

and byte to bit,

Till each hardware register was consumed,

Till each register could be used,

or Re-Used no more,

and Lo... I present to you the 'Optimized Code-Size'" smile_shades

new_mem

This I'm particularly proud of. clap

Anyway, the code is divided into 5 Files:

  • main.c
  • game.h
  • game.c
  • UserInterface.h
  • UserInterface.c

Program Structure

Step 2: Preparing the hardware.

After getting the code "Out of the way", it was time to do what I really wanted to do this weekend. Time to get some Solder Iron Burns and some spit, wire and breadboards, together!!

Lets See what we need first. Hmmm....

IMG_0120

-Solder Iron. Check.

-Bread Board. Check.

-LCD. Check.

-Microcontroller. Check

r step -Random Headers and Stuff. Check.

-Some Discreets. Check.

-Lots-a-Buttons. Check.

All clear. Lets go....thumbs_up

One Hour Later:

IMG_0121

Everything assembled to my satisfaction, and ready for testing. fingerscrossed

IMG_0122

It Works!!! It Works!!!

Some random screens:

IMG_0128

IMG_0130

Scrolling Up and Down the Menu:

IMG_0123

IMG_0124

IMG_0125

IMG_0126 IMG_0127

IMG_0131 IMG_0133 IMG_0134

Preparing the Outer Box: (I wish I had taken my art and crafts class in High school seriously smile_thinking

IMG_0135

Ooohhh the guts and wires.....IMG_0136

The Front Panel: (Before I got creative with a felt pen smile_wink)

IMG_0137  AAaahhh Finished.... clapthumbs_upbeer

IMG_0139

 

IMG_0140

Still Works....

IMG_0142

Under the hood: Easy Access to the Microcontroller, and I/O Headers. I know, I'm a genius. smile_teeth

IMG_0138  So, Thats it for now. What about the rest of the bot? Well the main part is over, I mean, the Code works on the Mega32, is now optimized, quite a bit, and I spent an entire long weekend (Long Weekend = Friday + Saturday + Sunday) on it, so it may be atleast another 3-4 weekends that this project will be on hold, so that I can work on other interesting projects. Nothing to be sad about... Next week, I'm working on Panasonic Servo based gantry (Ball Screw), with a Xilinx Spartan XC3S400. Nice....

 

If you like this post, leave a message, it always makes my day.smile_regular