Wednesday, November 8, 2017

Rumination of Uselessness


Let us return to the Useless Machine topic one more time.

Classical useless machine usually made out of four electrical components, namely:
  • Electrical battery.
  • Gear motor.
  • DPDT switch (usually toggle, sometimes rocker).
  • Micro-switch.
This is probably minimal set: it is hard to imagine anything more efficient. But once an idea came to my mind: maybe such a machine  is not absolutely perfect. Useless machine must cut itself out of power as soon as it returns to the original state. That achieved with help of the micro-switch.  Machine arm,while returning back, pushes switch, its normally closed contact becomes open,  machine fully stops and looks dead. But if tester tries to move an arm manually, micro-switch is released again, its closing contact provides power to the motor. That case is visible on the clip of Rocker Switch Useless Machine starting at second 19. So machine here actually is not dead, it just plays dead! That's  good opportunity for the new design : make the machine, which will allow manual rotation of the arm, when machine is turned off. In other words make the machine really dead at the end of its working cycle. To achieve that I decided to get rid of micro-switch and  use for backward movement an energy stored in the capacitor, charged while machine arm moves forward, . Below you can see circuit diagram of such a machine:
When switch connects motor to the battery and motor moves the arm forward, electrical current is flowing through  the circuit of diode and relay, mounted in parallel to the motor. Relay  is forced to close its normally opened contact. Through that contact (and small resistor) capacitor is connected to battery and receives some charge. 

When arm turns the switch back, motor is disconnected from battery, but connected to the capacitor in the opposite polarity. Motor rotates backward and returns arm to its original state.  Diode now stays in the opposite direction on the way of electrical current,  so relay contact stays open and capacitor is disconnected from the battery. Capacitor mostly is discharged providing the movement of the motor, the rest  will be discharged through the stopped motor winding. You see, in theory it looks simple. But I must tell you that this design is much more demanding on the spec of components, compare to classical schematic. After some trial and error iteration I came up to the next set component:
  • Solarobotics gear-motor GM17  ( I could not make it working reliably with GM2 or other motors with similar spec).    
  • Super capacitor 0.1 F. (I used NEC 5.5 V capacitor). Bigger capacitor would be fine but smaller probably not.
  • 5V relay. Here type is not that important. 
  • Schottky diode. Here type is not that important. 
  • Resistor 5 Ohm. It is optional but it keeps electrical current trough the battery under 1 Amp at the beginning, when the capacitor is fully discharged. Type does not matter here, but better to have 0.5 W.
  • Four 1.2 V rechargeable batteries. Type does not matter. 
As you can see on the video tester may manually  rotate the arm when machine is turned off.  Done!
I published more detailed description on instrcuctables site

Update 11/12/2017. fixed bug in diagrams: missing wire between switch terminals.



Saturday, December 31, 2016

In the Moonlight

This is the moon simulator with bat silhouette which I made as a decor for this  Halloween.


The core part of the project is twelve backlight white LED modules ( I bought them from the adafruit). LEDs are controlled by Atmega328 micro controller. The schematic of the project is fairly simple:




Adm here you can see project assembly with some internals visible:




Twelve LED modules put in the middle of sandwich made out of two Plexiglas  sheets attached with the help of Velcro strips.  Paper Bat attached to the front of the moon with Velcro as well as front and back cardboard shields .

 Program to control the device is short enough to be present entirely in this blog:

/*
 * moon.c
 * Created: 10/22/2016 1:14:19 PM
 *  Author: jumbleview
 */ 
#include <avr/io.h>
#include <avr/interrupt.h>
#include "./pt-1.4/pt.h" // http://dunkels.com/adam/pt/

typedef enum {OUT_LOW, OUT_HIGH} OutputLevel;
volatile uint16_t pulses;

#define pinOut(port, bit, outLevel) \
(DDR##port |= (1 << ( DD##port##bit)));\
switch(outLevel) \
{\
 case OUT_LOW: (PORT##port &= ~(1 << (PORT##port##bit))); break;\
 case OUT_HIGH: (PORT##port |= (1 << (PORT##port##bit))); break;\
}
void clearAll()
{ // set all outputs low
 DDRB = 0xFF; PORTB = 0;
 DDRC = 0xFF; PORTC = 0;
 DDRD = 0xFF; PORTD = 0;
}
void activateTimer0()
{
 cli();
 pulses = 0;
 TCCR0A=0; // Normal operation
 TCCR0B=2; // f divider 64  : about 2 ms for interrupt ...
 TIMSK0 = 1; // for system clock f= 1Mhz (CKDIV8 set)
 sei();
}
struct pt wpt; // protothread descriptor

int moonlight(struct pt* mlpt)
{
 PT_BEGIN(mlpt);  // New Moon 
  PT_YIELD(mlpt); 
   pinOut(C,5,OUT_HIGH); pinOut(B,1,OUT_HIGH);
  PT_YIELD(mlpt);
   pinOut(D,0,OUT_HIGH); pinOut(B,2,OUT_HIGH);
  PT_YIELD(mlpt);
   pinOut(D,1,OUT_HIGH); pinOut(B,0,OUT_HIGH);
  PT_YIELD(mlpt); // First Quarter   
   pinOut(D,2,OUT_HIGH); pinOut(D,7,OUT_HIGH);
  PT_YIELD(mlpt);
   pinOut(D,3,OUT_HIGH); pinOut(D,6,OUT_HIGH);
  PT_YIELD(mlpt);
   pinOut(D,4,OUT_HIGH); pinOut(D,5,OUT_HIGH);
   pinOut(C,0,OUT_HIGH); pinOut(C,1,OUT_HIGH);
  PT_YIELD(mlpt);  // Full Moon + Red Eyes
  PT_YIELD(mlpt); 
   pinOut(C,0,OUT_LOW); pinOut(C,1,OUT_LOW);
   pinOut(C,5,OUT_LOW); pinOut(B,1,OUT_LOW);
  PT_YIELD(mlpt);
   pinOut(D,0,OUT_LOW); pinOut(B,2,OUT_LOW);
  PT_YIELD(mlpt);
   pinOut(D,1,OUT_LOW); pinOut(B,0,OUT_LOW);
  PT_YIELD(mlpt);  // Third Quarter
   pinOut(D,2,OUT_LOW); pinOut(D,7,OUT_LOW);
  PT_YIELD(mlpt);
   pinOut(D,3,OUT_LOW); pinOut(D,6,OUT_LOW);
  PT_YIELD(mlpt);
   pinOut(D,4,OUT_LOW); pinOut(D,5,OUT_LOW);
  PT_RESTART(mlpt); // New Moon
 PT_END(mlpt);
}
ISR(TIMER0_OVF_vect)
{
 pulses++;
 uint16_t mod =pulses%750;
 if (mod == 0){
  moonlight(&wpt);  
 }
}
int main(void)
{
 PT_INIT(&wpt); // initiate protothread structure...
 clearAll();
 activateTimer0();
    while(1) { }
}

To  compile and load program into the controller memory I used Atmel Studio 6.1. Code includes three header files.

  • File "io.h" contains definitions to work with input/output (comes with Studio installation)
  • File "interrupt.h" is defining interrupt vectors (comes with Studio installation)
  • File "pt.h" is Adam Dunkels implementation of protothread library.
Protothred library deserves some additional notes. I included it to my programming  tool box recently and nowadays use it any time I need to program embedded devices in "C ". It provides multitasking framework and allows to code device states efficiently and conveniently.  I highly recommend to try it for any programmer  who works with micro-controllers in "C".

As you can see device is simple to made and program. Some additional details you can find in my "Instructables" project.

The only problem I see is relatively high project price. Mostly it is the price of LED modules ($2.50 for each). Nothing could be done here. To gain some additional benefits I decided to substitute  Bat with Reindeer so the device is quite usable  as winter decor:


Saturday, September 3, 2016

Windows Console on Demand in Go

There are two kinds of Windows programs: Windows GUI or Console Application. There could be third case:  process, which does not have any visual representation at all and needs to be running in the background. For that case program maybe be built as Windows GUI, but it should not have any code, which creates Windows objects.  But what if  you want from application sometimes  to be silent and sometimes  to be verbose and to have a console. Possible use cases are:
  • Printing version of the utility if started with special flag (like -V)
  • Program needs complicated tune up through the  command line arguments or configuration file, but normally is  running on the background. It would be beneficially to have a choice either run it with console or run it quietly.
That could be achieved by compiling application as Windows GUI and allocating  or attaching console to the process during run-time if needed. There are a lot of examples how to do that in C/C++. When I myself looked for the solution several years ago I have found this link  helpful. Fragment of the code, which creates console may look like this.

 // taken from: http://www.codeproject.com/KB/dialog/ConsoleAdapter.aspx

 AllocConsole();
 int fdout = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
 FILE* fout = _fdopen(fdout, "w");
 *stdout = *fout;

 int fdin = _open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT);
 FILE* fin = _fdopen(fdin, "r");
 *stdin = *fin;


Nowadays I found myself  programming more and more in Go. While initially Go compiler was intended for Linux only,  that is not the case anymore. Windows now is the first class citizen in the Go world. Recently I needed to create application, which may open the console if that demanded by  command line argument, but work invisibly  otherwise . To my surprise there were not that many online information how to do that in Go. I did find one answered question in StackOverflow. Alas, proposed solution did not work for me out of the box. But using it as starting point and after some googling I have found workable solution. Here is sample of Go application, which will allocate console, print some prompt, wait for keyboard input and quit.

// go build -ldflags -H=windowsgui
package main

import "fmt"
import "os"
import "syscall"

func main() {
 modkernel32 := syscall.NewLazyDLL("kernel32.dll")
 procAllocConsole := modkernel32.NewProc("AllocConsole")
 r0, r1, err0 := syscall.Syscall(procAllocConsole.Addr(), 0, 0, 0, 0)
 if r0 == 0 { // Allocation failed, probably process already has a console
  fmt.Printf("Could not allocate console: %s. Check build flags..", err0)
  os.Exit(1)
 }
 hout, err1 := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
 hin, err2 := syscall.GetStdHandle(syscall.STD_INPUT_HANDLE)
 if err1 != nil || err2 != nil { // nowhere to print the error
  os.Exit(2)
 }
 os.Stdout = os.NewFile(uintptr(hout), "/dev/stdout")
 os.Stdin = os.NewFile(uintptr(hin), "/dev/stdin")
 fmt.Printf("Hello!\nResult of console allocation: ")
 fmt.Printf("r0=%d,r1=%d,err=%s\nFor Goodbye press Enter..", r0, r1, err0)
 var s string
 fmt.Scanln(&s)
 os.Exit(0)
}
I would like to point some details about syscall.Syscall invocation for AllocConsole :
  • This function  has five arguments. It is different of what you will find in the online Go Doc . Looks like doc references Linux definition, which is not the same as Windows.
  • Second parameter here is number of arguments in dll function. For our case it is 0.
  • Function returns three variables, but only first is really meaningful. It is the result returned by AllocConsole function. Second variables always 0. Third variables  is an  error, but in cannot be analyzed in the regular Go way as far as it is never nil.  Still it could be useful: in case of success its value is different from value on failure (for example if application was build with no windowsgui flag and already has the console ) .


Saturday, April 9, 2016

Not for Insulation Only

Hobbyist and DYI makers very often extend usage of elements and components beyond its usual assignments.  I would like to share with you one such a case. 
Whenever you drill through the wooden or plastic sheet you has to be really careful not to drill through. The common well know method to prevent that is to use tape or scotch wrapped around the drill bit. Once I was out of tape and had to look for substitution. Piece of  heat shrink tube came in handy. It fitted drill bit exactly, I just needed to cut proper length of it. That was very lucky finding. I entirely stopped using tape for this task and switched to heat shrink or straw tubing. Especially convenient it becomes  for projects which  needed drilling with the same drill size but with different depth. Switching between tubes can be done in a second.  
The best result is achieved when tube sits tight  on the drill bit. In case you does not have exact heat shrink size, you may cut tube, which is too narrow,  alone. It will still work.  But you need to be more careful to stop drilling right at the moment when tube touches the surface. Otherwise it may be torn away by drill rotation.

Heat shrink actually suited for various tasks. I even   published blog, picturing some of  them : http://www.instructables.com/id/Not-for-Insulation-Only/,  Here is list from that blog in a short:
  • Controlling depth of drilling (that idea you actually see here).
  • Using heat shrink while hanging picture  on sheet rock wall
  • Protecting awl tip
  • Keeping tweezers tips together. 
  • Making paper clip to work better. 

That topic got some attention and was even featured by one of the site editor.  Author Phil B told me about one more usage of heat shrink:  fixing claps on kindle reader case. I am sure there are many more cases which extends usage of heat shrink tubes.

Updated: 11/28/2017. Today I read about one more very useful usage of heat shrink: as thread locker.
Author Left-filed Designs published this blog https://www.instructables.com/id/DIY-Self-Locking-Nut/ . Very good. Will use myself for sure.

Sunday, January 11, 2015

Computer Desk Hutch with Sit or Stand Option

This project is a remake of the DIY project "Sit-n-Stand monitor station" described in the my old post: How did I join the Uprising. Recently my family moved into the new house and a lot of old stuff including some of DIY things did not survive the moving. I have to make the  station again. This time it  looks less DIY and more furniture like  (I hope). The basic principle is the same: desk with monitor moves up and down within sides sliders. Pulley system with counter weight compensates gravity force making moving easy. But there are some  differences:
  • Instead of single pulley line in the middle of the desk there are two lines on both sides of the desk.
  • I made desk as light as possible (but without any sacrifice of sturdiness).  
  • Light desk allowed me to switch from 3-times advantage pulley system to 2-times advantage system. As a result of that counterweight moves withing the boundaries of the hutch.
  •  I mounted  two shelves in the inner side of the hutch making some use of hutch volume.
Detailed steps of this project is published on the "Instructables" site right here: Sit&Stand Computer Desk Hutch . I even submitted it to couple of "Instructables" contests.  I cannot tell that submission made the big splash but project got some attention. While it does not win first prize it reached one contest final and here is my award: "Instrcutables" robot t-shirt. 


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.



Sunday, July 7, 2013

Atmel Microcontroller Plays the Tic-Tac-Toe Game

A couple of years ago I made an electronic Tic-Tac-Toe game with  Pololu baby Orangutan controller as the central component. Pololu  is an excellent device  but for Tic-Tac-Toe game it was an overkill. Its motor drivers were of no use and  it required  at least 5 V power source, so I had to add an adapter to make device workable on two batteries. Recently I decided to gain some experience with bare bone Atmel controllers and repeated this project with ATmega 168. Setting  this controller to the lowest possible frequency (1 MHz) allowed me to eliminate the power adapter. (Two AAA rechargeable batteries provides 2.4 V, which is more than enough for ATmega 168 at this frequency). Here is the circuit diagram of this toy.



Let us look at the list of components:


1. All electronics were mounted on a RadioShack component PC Board 276-168.
2. Central processor Atmega 168 (do not remember where exactly I bought it, many online providers sell it)
3. Nine Bi-polar bi-color 5mm Green/Red LEDs. (again I did not keep the record of purchase,  some online providers sell it)
4. RadioShack 2 AAA battery holder  270-398
5. Nine resistors 51 Ohm 0.25 W (0.125 W is OK as well)
6. Panasonic  EVQ-WTEF2515B Encoder (goldmine-elec-products.com; alas, looks like they do not sell it anymore)
7. Ceramic capacitor 0.47 uF.
8. RadioShack slide switch 275-409
9. Male headers 2.54 mm to make six contacts ISP header. SItes pololu.com or hobbyengineering.com sells various types of them.
10. RadioShack 2-pack 14-PIN IC socket (optional, just to have the possibility to reuse controller  on other projects).
11.Hook-up 26 gauge wire ( hobbyengineering.com ) and 30 gauge precut wire  (Frys electronic store).





As  an enclosure  I used a box from Johnson&Johnson emergency kit. I had to treat edges of the board with file to make it fit into the enclosure.


As you can see the density of project components on the boards is not high.  Soldering elements  to the board and connecting it with 26 gauge wire was not that hard. To find out how LED was oriented on the board follow the simple rule: top of any LED on my diagram corresponds to the longer LED leg.  Contacts of panasonic encoder are very fragile  so I used 30 Gauge wire here. The PC board layout does not provide the proper place to solder ISP header. So I have to separate  three contact plates with utility knife and solder wire directly to contact plates occupied by headers.




Of course, the main part here is the program. For machine to choose the right move there is a well known algorithm: game tree search.   There are many sources to look for. In particular I have used this Berkeley lecture: http://www.cs.berkeley.edu/~jrs/61bf10/lec/18.pdf and strictly followed the described here game three search with simple pruning algorithm converting pseudo code into the C language. The only deviation from the algorithm  I did during programming  of the first  computer move. If computer starts the game it chooses randomly among central and four corner squares. If computer does not start the game it makes its first move in to the center if the center is  free  or chooses randomly any corner square if center is occupied. There are two reasons for such deviation. Making a move when the board is  empty means too many choosing attempts (hundred thousands) and it will take a lot of time  for a low frequency controller to calculate it. In addition introducing some randomness makes the game on the computer side less predictable and boring.


Source code for the toy is available here https://bitbucket.org/jumbleview/three-in-a-row/src/


After compiling code with free Atmel Studio 6.1, the resulting hex file was written into the controller flash memory with the help of Atmel ISP MKII (I bought  mine at mouser.com )


Let us look at the compiler printing regarding the program memory allocation:

Program Memory Usage : 3548 bytes   21.7 % Full
Data Memory Usage : 57 bytes   5.6 % Full


Based on that we can conclude that  after recompilation the code will work on any of controllers from the line:  Atmega48, ATmega88, ATmega168, ATmega328.


And finally here is how the Atmel controller plays the Tic-Tac-Toe game:



Saturday, June 22, 2013

Competition in Uselessness

It is believed that the idea of the Useless Machine was first formulated by Marvin Minsky and implemented by Claude Shannon more than half a century ago. Nowadays this concept is quite a popular one (1). The Useless machine in one sentence may be defined as automaton with only two possible states: 

  1. It is turned off. 
  2. It is turned on.

Transition from state 1 to state 2 happens as a result of external force, and the transition back from state 2 to state 1 is provided by the machine itself. If this machine is electrical (as Claude Shannon built it) energy for the transition is taken from the battery charge. For a purely mechanical machine it is either gravity or spring tension. In its classical implementation the electrical circuit looks like this:
I first got knowledge about that device from Make Magazine (2). Until the time of publication there were tons of videos on YouTube with various versions of this device. While browsing them I paid attention to the fact that most of the machines use a toggle switch as the machine control element. A rocker switch was never used. But it is absolutely clear that a rocker switch may provide the same effect. Why does nobody use it? Good opportunity to contribute something new to an old concept, right?

Using a rocker switch instead of toggle means that the force applied to the switch by the machine arm should go not in a horizontal direction (from side to side) but rather in a vertical direction (from top to bottom). While playing mentally with kinematics to make it workable one more thought came to my mind: why not eliminate the working arm? Let the box lid do the job. This way the machine will be truly different from other animals in the herd: rocker switch instead of toggle and no arm at all.


It took me some time and several attempts to create a two dimensional cardboard model like this:


As soon as my model proved the concept worked, the actual implementation with wood and wires was not so hard :


And here are some technical details:

  • Motor: Solarbotics GM2 gear motor
  • Rocker switch: Radioshack DPDT Switch ( 275-695 ),
  • Micro switch: Radioshack SPDT Switch with Roller Lever (275-017)
  • Wooden box and other wooden parts from the local Michael’s store.
Among the comments left on this YouTube video was a comment from the user xsolarwindx: “this is f*ing stupid”. For any other occasion such a comment would be insulting but for the useless machine maker that could be considered as highest degree award. I think everybody would agree, right?

Updated 10/27/2015.
I have published more detailed description of this project updated version here: http://www.instructables.com/id/Useless-Machine-in-the-Pumpkin-Mask/



References:

1. Here is the site of the company entirely dedicated to useless machines :


2.  Brett Coulthard. '"The most useless machine" (Issue 23 of Make Magazine). 2010

Sunday, May 5, 2013

How did I Join the Uprising



Updated: 01/12/2015. New version of this project you can see here .

In March 2013 letter from Make magazine there was summary: why people are concerned with DIY. Among reasons economy  was mentioned: “Making is often cheaper than buying”. From my experience it is seldom true. In our highly specialized society making things cheaper than you can buy them is quite a rare case. But it still happens sometimes. Project described here is an example.


People who work in the office or from home spend most of their active time sitting: while working, in the car or in the bus/train during commute. It would be much healthier to switch from sitting to standing position from time to time while working . I looked what kind of furniture can help me to do that. Indeed there are some vendors producing sit-n-stand stations. Especially I liked the advertisement from Ergotron company The Uprising: JustStand! .  The ad  is pretty smart and funny,workstation is doing exactly what’s needed, allowing to change from sitting to standing position without job interruption. While such a  workstation is not cheap (~330$ - 420$) it is still affordable. But when I evaluated  its functionality I came to conclusion that it is possible to  implement it differently with almost the same user experience and for less money. I did  couple of visits to the local hardware stores, revised what I have in the attic, and dedicated two weekends to make adjustable monitor/keyboard station .


These photos show my station at the bottom position and when it moved to the top.



Here is the drawings which reveals details about  inner construction. Monitor desk is integrated with keyboard desk. To the sides of the desk attached inner parts of sliders. Outer parts of sliders attached to the side walls of the tower. The desk can move into vertical direction up and down together with  LCD monitor and keyboard on it. Tower is set on the top of the table and  walls of the tower is tied to the table with metal corners providing the needed stability. When desk is at the bottom position it rests on the table, two hinges attached to the edges of tower walls are turned outside.  While at the top position desk rests on the two hinges which now are turned inside.

 
Important part of the design is counterweight system. Weight of the desk with monitor, keyboard and mouse reaches 17 pounds. It is too heavy to easily move it (especially down). Four pulleys together with rope and 5 pounds weight  creates system which compensates most part of the desk weight. Pulleys 1,2 and 3 creates  3 times mechanical advantage . Pulley 4 changes force direction. As a result 5 pounds weight creates 15 pounds counterweight.  This is not really a high tech but what worked for Archimedes 2300 years ago may work for me as well, right?

And here is how actually pulleys 1 and 3 mounted:


Let us calculate price of the project.

1. Pair of draw sliders: $14.99 (Ace Hardware)
2. Two pairs of metal patio door wheels (to use as  pulleys): $6.99*2=$13.98 (Ace Hardware )
3. Fourteen metal corners: $0.69*14=$9.66
4. Two shelf tablette 35” long to make tower walls: $8.99*2=$17.98 (Eames local hardware store)
5. One shelf tablette 23” long to make  keyboard desk: $5.29 (Eames local hardware store)
6. Pair of hinges: 2.99 (Ace hardware)
7. Two C-clamps to tie the LCD monitor to the monitor desk: $1.99*2=$3.98 (Ace hardware)
8. Pair of wooden knobs for hinges: $1.99 (Ace hardware)  
9. Five pounds training weight (used): $2.99 (Play-It-Again store).

So the whole price of the project would be:

$14.99+$13.98+$9.66+$17.98+$5.29+$3.98+ $2.99 + $1.99 = $72.87

Some stuff I found in my attic (leftover from previous projects),namely:
a) wood for tower roof and monitor desk;
b) metal rods to attach keyboard desk to monitor desk;
c) soft material to wrap up weight so it will not hit room wall while moving (I have used old mouse pads here);
d) some screws and Elmer glue.  
I am not sure what will be the cost of this stuff if I need to buy it,  probably $25-$30.

I would tell that for DIY this project is rather  expensive but anyway the whole price is under $100. Saving compare to Ergotron workstation (which is cheapest among the available on the market)  exceeds $200.


And eventually here is the video which shows the process of bringing the  monitor desk from the top position to the bottom and then back to the top.


I have used this station for more than month and I am quite satisfied with it.  Maybe it does not look so neat as Ergotron but it meets my expectations. Having sit-n-stand station at home give me a reason to telecommute more often (Can do that,  I do not work for Yahoo).