Saturday, November 1, 2014

Business Card Holder with $805 Price Tag



No, I did not pay that many for this cardholder. I am not even sure I ever will pay $5 for any  cardholder. I got mine completely free. It was taken  out of computer, which was prepared to be utilized by E-waste service. Processor passive cooler  grabbed my attention and pretty soon I have found some use in it. That was an easiest project I ever made. Out of curiosity I did the online search to find out the pedigree of this beast.   And here you can see the result.

Indeed it has a spectacular specification and outstanding price. That money may buy you Apple MakBook Air nowadays. Why people complain about an inflation?

Friday, July 4, 2014

Useless Machines, Atmel Controllers & Protothreads



This is the project I made in 2010 as a response to the publication about useless machines in Make Magazine1. In overall excellent article there was one statement which looked controversial to me. Author stated that a machine with a microprocessor does not cut itself completely off power and from that point of view cannot be fully qualified as useless machine. This is not true. Sure you can build a machine with microprocessor which at the end of cycle cuts itself off power. And here is its wiring diagram of the machine from the clip above.

As central component this project utilizes Pololu B-168 controller 2 with Atmel ATmega168 as a brain. In addition controller has two H-bridges for bi-polar load. One bridge in this project controls the motor, another controls the reed relay which keep the machine on power disregarding of the control switch state. To eliminate toggle switch (the reason for that you can read here) I designed the push button custom made out of two micro-switches. To justify presence of the controller more complicated task assigned to the machine. This task could be described in in these statements:
  • The Machine waits till tester hits the button. With first hit turn itself on.
  • Thew Machine waits some time if there is no hits anymore.
  • The Machine calculates the number of hits.
  • If pause after last hit is big enough working cycle begins and the machine arm hits button as many time as tester did.
  • At the end machine cuts itself off power.
While preparing this post I decided to rewrite program having in mind to try one well known but new to me technique, namely Protothreads 3. This is the framework based on C language trick which allows operator switch to be embedded inside C code blocks like if, while or for. Such obscure language feature allows to use case statements as breakpoints where the task may yield execution to other tasks and from where it can resume execution when it gets the control next time. For the detail explanation I would reference you to author website. After reading it you will understand why not everyone in programming community accepts these ideas and why there is no known company which includes it into the corporate coding standards. But for hobby project I can use whatever I like, right? Fragment of the code below contains protothread routine which implements machine working cycle 4.

// script routine
int protothread(struct pt* upt)
{  // called each timer interrupt 
 static int count=0, ix;
 static u_time timer;
 PT_BEGIN(upt); // PT_INIT is called form the main function
 // just in case to avoid race condition at the end
 PT_YIELD_UNTIL(upt,isButtonPressed());
  
 turnRelay(DeviceON); // keep device powered 
 turnMotor(DeviceOFF);
 turnLED(DeviceOFF);
 do { // counting cycle
  PT_WAIT_UNTIL(upt,isButtonReleased());
  timer = schedule(750);
  count++;
  PT_WAIT_UNTIL(upt,isExpired(timer)||
    isButtonPressed());
 } while(!isExpired(timer));
 
 for(ix = 0; ix != count; ++ix) { // working cycle
  turnLED(DeviceON);
  turnMotor(DeviceON);
  PT_WAIT_UNTIL(upt,isButtonPressed());
  turnMotor(DeviceOFF);
  timer = schedule(20);
  PT_WAIT_UNTIL(upt,isExpired(timer));
  turnMotor(DeviceBACKWARD);
  turnLED(DeviceOFF);
  PT_WAIT_UNTIL(upt,isArmDown());
  turnMotor(DeviceOFF);
  timer = schedule(20);
  PT_WAIT_UNTIL(upt,isExpired(timer));
 }
 turnRelay(DeviceOFF); // kill the machine
 timer = schedule( 20);
 PT_WAIT_UNTIL(upt,isExpired(timer));
 PT_END(upt);
 return PT_EXITED;
}

See for yourself but to me it looks like good pseudo code which expresses program logic in clear and conscious way.
And at the end some observations from my limited experience with protothreads:
  • All yields/resumings of particular protothread have to be in the same protothread routine, in other words you cannot spread switch case statements across more then one function.
  • Protothread states must not be stored inside local auto variables, only static or global variables have to be used.
  • When working with Microsoft Visual Studio projects you must change default project setting of Debug Information Format field from Program Database For Edit and Continue (/ZI),to Program Database(/Zi). Otherwise your program will not compile.

1 Brett Coulthard. '"The most useless machine" (Issue 23 of Make Magazine). 2010
2 You cannot buy it anymore but there is the substitution with a better functionality in the same package but with slightly different wiring.
3Protothread Home Page.
4 The whole source code is available at this storage.

Sunday, June 15, 2014

From the Garage to the Kitchen

People use pegboards as garage tool organizers. This is well-known fact. Sometimes pegboards are used inside kitchen to arrange cooking spoons, knifes etc. This is not so well-known but still an old trick. In this project I put pegboard inside the picture frame. Picture frame serves here two purposes: it strips pegboard off its garage-like look and it makes process of installation easy.
Project is very simple. First you need to choose the proper frame. Be sure that it has two hangers (if not you have to install them yourself as I did). Then cut the proper size pegboard, put it into the frame and hang the organizer on the kitchen wall.

Now you can invite the chef to arrange cooking tools in a convenient and aesthetic way.

Thursday, May 8, 2014

Wall Clock with Atmel Microcontroller

Time measuring devices always look special to me.  I admire the royal nobility of a tower clock,the steady pace of a pendulum mechanism, the instant obedience of a stop watch. Eventually I decided to build one such device myself. While making a mechanical device is out of my ability, building an electronic clock is a relatively easy task. All that you need nowadays is a few inexpensive  components, rudimentary soldering skills and some programming experience.  







The clock above is what I made for our bedroom (thanks to my wife who allowed me to put this creature on the wall).
What is special about this clock: 
  •  It is a twenty four hours clock with accuracy up to one minute.
  • It uses a single active component: Atmega328 controller, which keeps the time and controls LEDs without help of any external microchip.
  • Time accuracy is provided  by an external oscillator while internal oscillator provides processor working frequency. 
  • Technique known as charlieplexing is used to handle the number of  LEDs exceeding number of controller's  I/O pins. 
  • This bedroom clock  possess an important feature: it can turns light OFF  and ON according to the schedule. This way it's light does not distract us during sleep time but allows easy time reading at dawn.
Let us describe the clock interface. This clock has two dials: inner (yellow) dial for hours and outer (green) dial for minutes. These two dials provide time reading with accuracy up to three minutes. Three correction  LEDs in the middle improve accuracy up to one minute.

Rules to read the time are simple:
  •   During AM hours single LED is turned ON  showing current hour. LED which points to XII hour  is always OFF.
  • During PM hours group of LEDs are ON staring from the LED which points to XII LED and ending with the current hour. 
  • Next LED is switched ON when there are two minutes left till the start of new hour.
  •  Each green LED of outer dial represents 5 minutes interval. LED which point to 60 minutes is always ON  as well as LED next to the current minute and all LEDs in between. This way the clock provides at least three minutes accuracy.
  • Three LEDs in the middle allow time correction:


Pictures below illustrate time reading rules.

Clock contains this set of components:
  • Atmel controller. I have used Atmega 328 but less powerful controller could be used as well.
  • Clock oscillator 32768 Hz.
  • Thirty LEDs (5 mm size).
  • 15 resistors 51 Ohm each (0.25 or 0.125 does not matter).
  • Radio Shack protopype board (catalog number 276-170)
  • Two three pins  headers (to build ISP connection between controller and PC)
  • Capacitor 0.047 micro farad 
  • Encoder to set up clock time. I have used Panasonic EVQ-WTEF2515B
  • Hookup wire and old IDE cable.
  • Power supply 5 V. It must provide at least 300 mA of current. I have used supply from old Sharp  handheld computer.
These components are connected according to the circuit diagram below:
To make soldering of  four LEDs to the single resistor I  prepared the board by making some cuts with a knife.

Here is how the board looks after soldering of all components.

I decided to use as a clock plate the wooden board from Michael's. As you can see I did not try hard to make it strictly symmetrical, having in mind the asymmetrical shape of the board. 

The clock was programmed with help of Atmel  studio 6.1 in C language. Source code and project file are  available here https://bitbucket.org/jumbleview/clock30/src.

Setting the time is not hard. For that three LEDs at the back of clock are used:

To set the time there is the need to follow next steps:


  1. Push the encoder: reserved LED is turned on
  2. Rotate the encoder to choose value you want to set (hour or minute).
  3. Push the encoder  again, now clock are ready to set the value.
  4. Rotate the encoder to set the proper value.
  5. Push the encoder again: the value is set.

To set the other value you  may repeat steps 1-5.

And here is the movie, which shows process of setting clock minutes.

video