Sunday, October 31, 2010

[FYP] climbing up a ramp

well done boys and girls~! We shall not stop here. There are more to come..... 


Wednesday, October 27, 2010

[FYP] almost there

turning the segway using a pot while maintaing balance

Monday, October 25, 2010

[DSA] pointers stuff

Well done to those that have completed the drill question (well, at least you did the “EASY” one) last week. To those that did my STUN question, KUDOS!!!! By doing this exercise, you have examine the buggy code and correctly identified the syntax errors, logic erros and some went further of discovering the differences of using “cin” and “getline”. The application and synthesis skills, such as isolating the buggy portion of the code, using the debugger, and reading error message from the IDE are particularly important especially in programming. These are the skills that I hope you can exhibit or demonstrate at the future assessments to come.

For those that have yet to attempt, please give it a try. And for those have done, try out the “HERO” question. Everybody loves to be a hero and get "worshiped" (I assumed that is).

Pointer is used for example when sorting a data structure. It is “expensive” to move the data physically, hence, changing the value of the pointer that points to the data is considered “cheaper”.

Below is a chunk of code that demonstrates pointers, the differences when pointers are applied to “char array” and “int array”. YOU are MOST WELCOMED to add more examples of using a pointer in c++.

Pointers come a long history in C and C++, some hate it so much but some really love it. Take it like a durian. Pointers enable the manipulation of the memory directly. PLEASE be EXTRA meticulous when it comes to programming pointers. Commented code really helps a lot for others to look, learn, debug another programmer’s code.

Now Comes the drill question for pointer. Write a program that calculates the volume of a cube (A x A x A), which need to satisfy some "requirement" identified from the "problem analysis" (which is done by me for you)
1. Read in 2 inputs from the user
2. Code a function that takes in this 2 parameter passed by reference and the result is stored in another variable, which is also accessible by the pointer ptrArea. Print out the area for the user.
3. Code another function, which takes in the ptrArea and calculate the volume of the cube.

Now come to the drill question array. Arrays are “containers” that can be used to store data in a structural manner. There are some disadvantages when it comes to using array. First, memory need to be allocated first (static). What happends when there are many copies of the same programme are running? Since memory is allocated, and used up but there are more data to come, array do not have the flexibility to increase like the vector. What are the other cons of using array compare to any other data structure?

Consider using “arrays”. Code a simple 100 seat cinema booking system that will do the following
1. Given (x,y) coordinate set the seat to be occupied.
2. Suggest a scheme/algorithm that detects duplicate seat entry.

Wednesday, October 20, 2010

[DIY] my LED belt buckle bling

I was toying with the idea of controlling rows and rows of LED for display purposes. Why not LCD (monochrome)? some may ask. First of all, LCD doesn't display well under outdoor condition and secondly we can see from afar if compared relatively with an LCD.

So there I go finding different ways of multiplexing LEDs. If no multiplexing method is used, I am limited with N number of LEDs. Where N is the number of digital pins available from my MCU. I am not in the state of getting a MCU with 64 IO pins just to control 64LEDs. What a waste of resources.

There I stumbled on the idea of charlie-plexing on the Internet. After reading about it and getting hook on the idea, I am eager to give it a try. But to my horror, the wiring on the vero-board can be quite nightmarish. Any 1 wire connected wrongly can result in a disaster.

I am looking for a better solution, eg a PCB for my own use. I stumbled upon LOLshield V0.1 and it cost USD$99 excl shipping. It is way out of my reach.

I went around asking our staff about it and luckily, I met Mr.Chong SP which he kind enough to supply me a PCB he designed to use charlieplexing for 56LEDs. The experiment time was cut down drastically, because of the time reduce from making the connection. PHEW... programming was not straightforward but still manageable.

But somewhat 56LEDs I am still not satisfy with it..... The number of text I can scroll is limited. Couple of months later, LOLshield v1.5 is going for USD25. I know i got to get my paws on it.
126LEDs in a 9x14 grid! wow!!! Quickly, I made my order and waited patiently for it to reach SG.

I thought inserting of 126LEDs of 3mm is going to be a breeze...but i was wrong......spent about 1hr + just to insert them all....Make sure you get all the polarity of the LED correct. Any 1 mistake will make the whole board defect.JimmyRodges silk screen the LED polarity on the PCB, so you will not mess up with the + and -. How thoughtful.

 Next, Apply masking tape of the LED side to support when doing the soldering. The spacing are very small (1.5mm apart) and can be quite intimidating to beginners. I got some steady hands and couple shots of coffee to help me stay focus. I have soldered 126x2 = 252 pins in another 1hr + time.
When soldering PCB of this caliber, make sure you have a really good solder tip. Having a good condition tool is to the success of this toy. My newest soldering iron is getting really troublesome. After a few pins, the heat became uneven and it felt very sluggish..... I changed to my old solder iron which I am reluctant to throw away. Same problem..... The soldering tip is worn out badly. I went digging around my pile of junk and discover that I have a spare soldering tip, but for a smaller watt which I bought earlier but did not get to used it. 

On the left is the badly battered soldering tip, on the right is the new one.

Then soldering is really a FASSSTTTTT.... I only spent about 1-3 seconds per pin....I recommend to trim off the excess leads from the LED to as short as possible, roughly 1-2mm above the PCB then solder. I will explain in the next paragraph. My soldering skills are getting rusty, I am getting old and my eye sight is still as good. God knows how many more years I can do such delicate soldering.

Hook up the LOLshield to the Arduino. Note in the previous step. If you do not trim the leads as short as possible, when you fit the LOLshield to the Arduino there might be a gap and caused loose contact. Worst, the exposed leads will come in contact with the USB connector on the arduino. Hence, I covered the metal connector with masking tape to prevent it from shorting my LEDs.

Now, the code part, I am using the basic test from the example. Download to the chip... and....Kept my fingers crossed..........

The moment of seeing all the LEDs light up accordingly, it is really priceless.........all the hours spent did went off.........
Next, I want to scroll some text, but i realised that the library I imported is buggy and doest not support fonts. jimmrodges did release another version of the library. Comparing the modified code is really mentalling taxing. So i used the "diff" function from notepad++ to compare the changes in the 2ver of the lib files.
Life is so much simpler with this small helpers....

Load in the new changes in the lib file... mod the existing sample code to scroll a longer text. Please note that it only supports 22char and capital letters only.

have fun!!! It is going to appear as my belt buckle with customizable text. Anybody wants to shrink the footprint to make it even smaller? LOL

Sunday, October 17, 2010

[DSA] Common Mistakes in Programming

There are few categories of mistakes/error/bug in programming. Suchs as logic erros, syntax errors, core dumpz (run time error)/
I came across many many types of mistakes in programming that student commit. These mitakes fall majorly into the syntax error which is the easiest to troubleshoot. As compared to logic errors, there are formal mathematical way to prove that the logic and the premise it holds.

As the old programming guru’s mantra: “It takes more pairs of eyes to spot the bug”

Below is NAF (Need A Fix) buggy code that I have created (50lines only....easy). Your "TASK" is to "SOLVE IT", "FIX IT", PLS DO NOT EAT IT!!!

PLS POST/SHARE your answers here, add in as comments.


NO KICK???????????!!!!!!!!!!!

try the below (100lines, 5qns), covers strings, STL containers, iterators. Errors such as syntax error, runtime error and a little bit of logic error.



Thursday, October 14, 2010

[DIY] pc based oscilloscope-zelscope

sometimes we need to use oscilloscope to verify our findings, especially with data acquisition. 
But, if you working from home, having the hardware it self is a luxury.

this is pc based. you would need to connect it to the mic input of your laptop/computer.
stereo audio cable, stereo mini 2.5" jack (male and female) both can draw from the store.
if you need to look at a sample. come to my office.

Pls do not, put >5v as input. might damage your sound card.
alternatively, go SLS get those 9bux USB soundcard and use that mic input.
Anything fried, will be at the USB sound. Take it as an insurance, 9bux  10 bux only.

This is how the usb soundcard oscilloscope looks like

for the software, download here the 

there is the free ver, which is not floating from the official website. It is in my laptop

Please note the sampling frequency is only until 44kHz, which is equivalent to the CD quality for the USB sound. Hence, any hi frequency waveform is not able to observe using the software.

Sunday, October 3, 2010

[FYP] Almost there....

Weekends well spent with the students...

Happy Bdae to KKKY too~~!~!

Saturday, October 2, 2010

Congratulations Cisco NetRider Singapore 2010


You made us PROUD!!!!!
Photo Source: sjteo