Leaky Code…

I had heard lots and lots about leaky code so far, but never actually learned about it or read about it until tonight… so here it is below: a sample of LEAKY CODE (source: Wikipedia)

#include <stdlib.h>
 
void function_which_allocates(void) {
    /* allocate an array of 45 floats */
    float * a = malloc(sizeof(float) * 45);
 
    /* additional code making use of 'a' */
 
    /* return to main, having forgotten to free the memory we malloc'd */
}
 
int main(void) {
    function_which_allocates();
 
    /* the pointer 'a' no longer exists, and therefore cannot be freed,
     but the memory is still allocated. a leak has occurred. */
}

via Wikipedia Memory Leak Article

LED Eid Mubarak - from Ejaad

EiD: Hugs, Eidi and GUNS

First and foremost; EID MUBARAK TO ALL… I have been awfully lazy this Eid and didn’t even send Eid Greetings SMS to anyone except a select few.

LED Eid Mubarak - from Ejaad
LED Eid Mubarak – from Ejaad – http://facebook.com/EjaadTech

If someone looked down on Karachi, PK via satellite on Eid days, he would see

  1. Large gatherings of Muslims
  2. Hugging each other like its the last time they’ll meet
  3. Pakistani Flags and badges and stuff [14th August is also almost here]
  4. Children armed with guns…. YES, GUNS..!!!

Every Eid for the past some years I have been seeing GUNS, lots and lots of guns, Eid day reminds me of the scene in Matrix where Neo asks for Guns and gets em.

I mean why Guns, why not any other toy, why not board games, why not card games, why not sports gear, why not wheel-walay-jootay, why did it had to be guns…. and once the little ones have guns, they start having street wars form into gangs and its not only the little ones I see kids of almost 15 years old wandering around showing off their bad-ass BIGGER guns leading those gangs.

This has got to change. It is already done this year but next year and on next coming Eid (Bakra-Eid) I plan on at least trying in my own family to NOT let the kids buy guns. I will RE-post this before the next Eid too so to remind others and let’s stop this. I can force it upon a few but unless we show these little kids that there are other great things, other toys and play things which open the imagination for the better, which encourage healthy and safe outdoor  activities which encourage sharing rather than killing this trend isn’t going anywhere.

Let’s not even start on the hazards of these Guns and how one wrong aim can put out the light in one’s eye.

I hope that most of you will agree with me and some will share this thought this time and the next time on Eid.

[I should better familiarize myself with the latest toys too, so next time, I can give my kid-bro and little cousins a better choice, hopefully before next Eid, I will post here a list too.]

simple-circuit-for-blinky

Simulating Arduino [Steps for Windows/PC]

This is a STEP-by-STEP post, no-nonsense approach to simulating an Arduino on your PC, for those who don’t have the actual Arduino hardware, but have the following Required Software:

From here on, I will be simply providing the steps of the process, no talk about what and how, just the steps, follow them and you will hopefully be able to see simulation of arduino code within your PC.

  1. Open Arduino Software
    – Select Arduino Uno from Tools(menu)>>Boards
    – Select Preferences from File Menu
    — Check the compilation box after the Show verbose output during:
  2. Write your program in Arduino, anything, or simply open some example program.
  3. Once done with the code, CLICK ON VERIFY,
    the RIGHT/check button on top-left – do not click on Upload, cause you don’t have the Arduino connected.

    verify-not-upload
    verify-not-upload
  4. As the arduino IDE verifies and compiles your code, you will see the output of the compilation process as it happens,
    once done, it will show something like this at the bottom LOG window (black area).
    C:\Users\ZAIDPI~1\AppData\Local\Temp\build3564184540682511069.tmp\Blink.cpp.hex
    Binary sketch size: 1,084 bytes (of a 32,256 byte maximum)

    hex-file-address
    hex-file-address
  5. I have only shown the last few lines,
    Copy the PATH of the hex file, complete path from the drive root to .hex
    C:\Users\ZAIDPI~1\AppData\Local\Temp\build3564184540682511069.tmp\Blink.cpp.hexThe arduino Part is DONE, now we move to Proteus.
  6. Open Proteus (ISIS) and add an ATMega328P into the Editing Window of Proteus.
    [press P for Part, search for ATMega328P and then add it, first to library then to the editing area, place part]
  7. Add Power to the AVCC and AREF by attaching them to 5V/VCC/Power Rail
  8. Now double click on ATMega328P to open the properties page, do the followign changes:
    – Set the CLKDIV8 option to (1) Unprogrammed
    – Set the CKSEL Fuses option to (1111) Ext. Crystal 8.0-MHz
    – in Advanced Properties section, write in 16000000 as the value of Clock Frequency Property
    – PASTE the address of HEX file, previously copied from Arduino software in the Program File option.
    Press OK, to close the properties window

    avr-properties-in-proteus
    avr-properties-in-proteus
  9. ADD any circuit, components etc in Proteus as you would with the actual ARDUINO

    simple-circuit-for-blinky
    simple-circuit-for-blinky
  10. PRESS PLAY
  11. Now, whenever you change code in arduino, just click on VERIFY to re-compile it, the hex file will remain the same and you can simply test the new code by stopping and re-starting the proteus simulation.
the car and the little MAKER

Bottle Cap Runaway Car….!

I have a little cousin, in 7th grade… he has recently been getting more and more interested in hacking and tinkering his toys, taking them apart and playing with the LEDs and motors inside. When I met him last week, he showed me this car that he made, all by himself. he was like kinda over-excited presenting his creation to the only engineer (engineering student) in the family :)

The Runaway Bottle-Cap CAR
The Runaway Bottle-Cap CAR

Rear Wheel Drive, single DC Motor, 3 AA cells, barbecue sticks as wheel axles, bottle caps for wheels, plastic beads to hold the axles and a cardboard for the base/body. Push in the 3rd cell and the car starts going, never to stop unless it hits something.

Am going to give him a couple motors, some jumper wires, LEDs and batteries etc to see what he comes up with, for him, these little tiny electronic things literally are a treasure cause he got all these by breaking/opening his toys and he had very limited jumper wire stock treating it as some rare commodity.

the car and the little MAKER
the car and the little MAKER, thinking

Posted this cause the car made me so proud and took me back in time when I used to do stuff like this with my little brother’s toys (never broke any of mine), maybe after some time, I will show him Arduino…

a couple of VIDEOs of the car in action, the car is all prettified for the video-making..!

MS Electronics (Analog IC Design) + Graduate Teaching Fellow at PAF KIET + Co-Founder and Design Engineer at EjaadTech + all round Computer/Electronics Geek