Category: Hardware
PIC 3
The coolest project I've created. EVAR.
50+ months.
Gardening meets PIC assembly.
Where did it all start...:
Meet the Poinsettia. A photo-periodic plant, native in Mexico. Suitable for home, but it needs 14 hours of continuous darkness (starting from October), so it can "sense" winter is coming and trigger blossom.
And it looks good when it does:
:)
Poinsettia meets the student-programmer day/night cycle:
Don't try to figure out any order or logic — there ain't any.
In result:
Poinsettia stays green, three years in a row. Since we rarely turn off the lighting here before midnight, the biological clock of the poor plant gets totally screwed up.
I've read from several places in the net, that this problem can be alleviated by placing a large box over the flower in the late afternoon, and lifting it up in the morning. It just needs 14 hours of "night".
However, this needs manual intervention and it's not my taste, really. Waking up early is a no-no for me.
Meet the PIC microcontroller:
Capable of running all kinds of peripherals and electronics. I got the PICKit 2 starter kit - a programmer, a PIC16F690 chip, a Low-pin count demo board, and some software to learn&use all this.
Applying some soldering, relays, wiring...:
We can now drive a DC motor back and forth. Yay.
Meccano building kit:
Generic metal building set. Unleash your imagination. For starters, we did one of the models in the book:
Let's build a crane:
.
Programming:
Pure Assembly. Everything else is shit.
A box... using plain wires:
.
Since a cardboard box that large (32х38х38cm) would be too heavy - usually over 500 g - I built a cage using wires, and wrapped it up in black nylon - the whole box is less than 100 g!
Mounting the crane:
.
Works surprisingly well. Designed for up to 7 Richter (like, really!)
So finally, the Thing is completed! Run for your lives!
It:
.
.
.
.
Well. So you are probably a bit confused over here. The idea is like:
The PIC is programmed to run busy loop, counting the time that way. Turns out to be fairly accurate.
At 5pm, the "box" is moved down, so it covers the flower and provides darkness.
At 7am, it is lifted back up.
See this clip of the whole thing in action: Youtube
This son of a bitch is really working. Two weeks now.
On a side thought, I really learned one thing while working on this project: if you set your goals too high, and pursue them by any means that are out of your technical reach, you're going to fail. You really need to keep focused on the important things. It is vital to define your target correctly, and be ready to adjust your standards of success lower and lower as the project wears on. Some ideas aren't really worth pursuing. Consider:
* Being battery-powered (I reviewed all kinds of power sources, 4.5 volts, 9 volts, 4xAA rechargeable, even a LM7805 combo came to my mind...) (didn't need any of that after all. The Thing is inside a fucking house! You can really use a 5V adapter. It's lame. But it works™.
* Detecting the movement endpoints - since I had this current-sensing circuitry anyway, I could've sensed when, e.g., while moving the box up, it comes to halt at the top point, as the current through the motor increases sharply. I had even a more wild idea for the downward movement. Here it is: move the box, in a timed fashion, a bit more than it should be needed. Then start to pick it up. When the slack of the rope is consumed and it starts to pull the box, the current will rise, so stop here. (Of course, got rid of that idea, too. This is far too buggy and fragile. Calibrated timing is all you need.)
* Keeping track of time (throughout the day) - I've came up with all sorts of ideas. For example, I could've used an precise timer, which would trigger interrupts on the PIC. The interrupts would wake the microcontroller from sleep (and sleeping is for... conserving the power from the battery - see point 1).
* Don't use the internal clock of the PIC - use an external quartz resonator instead...
* Various battery efficiency ideas, e.g. - don't run the PIC at 4 MHz; use lower speeds. 32 kHz is sufficient, and the PIC is far more efficient that way.
* All other kinds of crazy ideas, basically avoiding to keep track of the time with the PIC.
(You'd wonder why was all that fear. Well, the datasheet says that the PIC achieves its best clock accuracy, "only" 1% of rated MHz, when we assume room temperature and 5V power supply. But, I thought, even there, the error is huge - we're talking about ~15 minutes per day! Well, with some calibration, the PIC becomes fairly good at tracking time. My current performance is being merely 10 seconds too slow per day, and I can calibrate it better if I want to. Anyway, the plant doesn't care.)
I did implement a few debugging things though. For example, I can trigger the movement, up or down, by holding the button of the demo board for a while - the type of operation being determined by the amount of time I kept it pressed. Another function I coded is that I can ask, "PIC, tell me what time is it", and it would show me. In 4-bit binary. Minutes are displayed like this: first, it prints M div 5, then M mod 5. Another thing that kept me busy for a while was an actual hardware bug that developed out of nothing, some time after I finished my first soldering two years ago. The bug was that the motor refused to turn in one of the directions, and the relays clicked wrong during that. More precisely, one of them wasn't clicking at all. When you touch the pins at some specific place of the board, it suddenly works all right again. Of course, it turned out to be bad soldering. There are no miracles in electrical engineering - only weak joints. But you should've seen what it is like to debug hardware. You still think that text-based gdb debugging is painful, ugly and obsolete? Meh.
P.S. I uploaded the source code of this thing: /code/my_projects/PIC.
Posted in category Hardware -- 18 Nov 2010, 00:54, 0 comments
Using Apple's Aluminium Keyboard on Linux
Here's a mini-HOWTO on the tweaks and hacks to turn the beautiful-but-temperament Apple aluminium keyboard into a PC-compatible one. Having used this gem for about an year now, I can testify: it's, without a doubt, the best keyboard I've ever worked with. It's comfort, quiet, fast, compact, prompts you to keep your fingernails short... you name it :)
The only hitch turns out to be the weird key locations of some symbols, and some Mac-influenced behaviour. You don't have an Insert button, there's a "Fn" button instead (see the picture above); F-keys don't behave as such, but rather do something (e.g., F12 is "volume up"); the numpad keys +, -, *, / are totally different; the key on the left of '1' is strange, it's not a tilde; and, the most painful thing - the Alt and Win keys are swapped (Alt is no more to the left of Space, but one key further left).
Fedora 13 applies the following logic in regard to these PC/Mac mismatches - a key does exactly what is written on it; even if that's different from what all people are used to do. Personally, I find that unacceptable, so here's how I restored a PC-compatible behaviour of the Apple keyboard:
1) Add the following two lines in /etc/rc.local:
echo "2" > /sys/module/hid_apple/parameters/fnmode
echo "0" > /sys/module/hid_apple/parameters/iso_layout
The first line makes the F-keys behave as real F-keys. To access the "action", combine with the "Fn" key. E.g., Fn + F12 turns the volume up.
The second line resolves the tilde issue, among other things.
2) Swapping the Alt and Win keys is best done by modifying the XKB scan-code interpretation file directly:
2.1) In Gnome->Preferences->Keyboard->Layouts, select "Evdev-managed keyboard" as your keyboard device.
2.2) Open /usr/share/X11/xkb/keycodes/evdev in a text editor. Search for any lines of the form "<LALT> = number", "<LWIN> = other number". Now you need to swap the numbers, corresponding to LALT and LWIN, and similarly for RALT and RWIN.
2.3) Restart X.
And that's it! Voilà!
Posted in category Hardware -- 26 Sep 2010, 02:39, 6 comments
Canon 350D battery durability
Amazing! I had the unique chance to test the Canon 350D battery's durability. My baggage (including the Canon charger) got lost by the crafty hands of TAP airlines, so I had to shoot on battery only, from 100% full, to complete discharge:
vesko@lappy:~$ cd photos/Portugal/
vesko@lappy:~/photos/Portugal$ find . | grep -i vesko | wc -l
975
So - almost 1000 shots by a three-years-old body, and an unknown number (probably quite high) of cycles on the original battery. 350D rlz :)
Posted in category Hardware -- 31 Dec 2009, 00:26, 1 comment
PIC 2
The birth of The Thing was delayed a little. I had the intent to design a simple DC motor controller. However, problem one, the PICKit2 programmer died (hail to Microchip who were nice enough to send me a free replacement), then, problem two, I had some trouble finding the right elements. Most of them I finally bought from Pulsator - DC motor (6V), relays, jack, etc. After the soldering iron kicked in, the demo board got a little overcrowded, but this was inevitable anyway:
The demo board is no longer bare...
...with the motor...
The design is a simple H-bridge, using four relays. The huge resistor from picture 1 stands on the way to the ground - it redirects some of the current to the A2D (Analog-to-digital converter), so I can measure how much current does the motor draw, respectively - how heavy it is loaded. I put those results on the LEDs for debugging purposes. You can watch the demo here.
You can see how, when the motor gets some load, the current raises (the LEDs show it in binary; they flicker a bit, but this is normal, since they are updated some 200 times a second. Indeed, I initially tried to average a quarter second worth of measurements, but the result looked quite dull).
Now that I can command the motor, I just need to find some more mechanical parts and learn the power-saving capabilities of my PIC... and The Thing will be ready... watch out.. IT Knows Where You Live (devil)
Posted in category Hardware -- 28 Dec 2008, 02:49, 14 comments
PIC
Week and a half ago I ordered the PICkit 2 Starter Kit. It includes a PIC microcontroller, a demo board, a PIC programmer and two CDs with development software. The embedded programming has been a field I wanted to try in since a long time, and this gadget offers an easy and convenient path to introduce one into the matter.
the demo board...
...with the programmer
It was yesterday when I finally found some free time to open the package and install the software. The processor is really simple - no more than one straight sitting to learn the instruction set, the same goes for the hardware on the board. The "Hello, world!" in the realm of microcontrollers - blinking a LED - seemed far too trivial for a first program, so I came up with something a little more interesting - blinking a LED with pulse-width modulation :)
Here it is in action: youtube
In fact, the whole thing is a little more complex than it looks like. PWM with PIC is easy, however the interesting part is how do you change the width of the pulses. It turns out that if you change them linearly, the end result doesn't look very convincing - the LED feels bright for the most part of the time, dimming abruptly only for a short moment and brightening again immediately. I discovered that an exponential pulse width scheme offers a much better effect. With the help of some 128-element lookup table (since the PIC doesn't have any floating-point hardware) and my first program was ready.
Now I have to buy some more electronics so I can start building The Thing. Beware. It is coming :D
Posted in category Hardware -- 24 Oct 2008, 18:36, 1 comment
A few good uses of a laptop
I must admit that my attitude towards laptops changed quite a lot recently (as I got one myself). It is quite hard to encompass all the uses of this technological gem. Here are a few:
* Mobile storage, that easily takes GBs of photos without any complaint (and the user interface is incredible);
* Mobile disc burner. The UI is, again, unrivalled;
* A great utility for presentations. Especially for the Topology lessons in Sofia University;
* (see previous point) Even a greater utility while other people are doing their Topology presentations. Especially if Quake3 runs smooth enough (well, in my case - not quite. It is only a decade-old game after all);
* A great webcam stand. It is not a problem even if the camera itself doesn't have good view controls - with the folding panel you have at least 4DOF;
* ... and many, many more, which I'm now too tired to write down.
Recently I came up with another, absolutely surprising and useful application of my laptop: a butter softener! You know what the cold butter looks like when you take it out of the fridge - yeah, you can cut it with a knife, but try to spread it on a loaf of bread that isn't harder than your teeth. It kinda sucks, right? Well, now that I have The Laptop, I just put the butter in front of the cooling outlet of the machine and wait for one minute. Voilà - now the butter spreads almost like margarine. For more effective cooling you need to run your favourite CPU stress program (e.g. my Fract Benchmark in "Loop forever" mode) - just do not forget to stop it after the butter melts, 'cause the fan starts to whine in agony. Actually, I now have an effective argument why laptops help for better digestion! Would you dare to challenge such an irrefutable argument? Brave you.
So, I've nothing more to add. Thank you, HP, for this multifunctional machine. I'm deeply impressed.
Posted in category Hardware -- 23 Mar 2008, 01:01, 1 comment