Wednesday, March 22, 2017

Low Cost Weather Station

I'm also working on a weather station project, but I greedily put that on Hackaday in hopes to win some fat price (I didn't):

Sunday, January 11, 2015

Reusing your ancient mobile phone: LCD

I have many times looked at my old mobile phones (the ones that were cool because they had pixels instead of numerals) and have been wanting to use some of the parts.

I got inspired looking through my Arduino Basic Connections book, and found an instruction to control a Nokia 5110 LCD with an Arduino board. My phone is the Nokia 5210, so not a absolute match, but since the amount of pixels is the same I was hoping the same control circuit was used.

Opening up the phone, I was positively surprised how easy it was to disassemble. It seems the strategy has been to make tiny modules that fit together without needing screws. What I had in my hand in the end, was the LCD with a flexprint attached to it.

Then I needed to determine if it the control IC was the same, and if so, identify the pads of the flexprint. It took quite some time and advanced deduction (combined with a bunch of googling of course), but my conclusion was that it is indeed possible, and the pinning (padding?) is shuffled compared to basically any other LCD (even the ones that look VERY similar). The pinning turns out to be as follows (counting for left to right in the picture above):

pin 1 - LCD reset (RST)
pin 2 - (VOUT)
pin 3 - Ground (GND)
pin 4 - LCD chip select (CS)
pin 5 - Data/Command select (D/C)
pin 6 - Serial data out (DIN)
pin 7 - Serial clock out (SCLK)
pin 8 - Power in (VDD)

Using the schematic in the Arduino book I connected the LCD to my Arduino Leonardo (I guess any type type of Arduino would work).

Adafruit has made libraries to simply control a Nokia LCD. With them you can specify images pixel by pixel in the code, or even draw shapes like circles or triangles. I forked the git repository, since I needed to make some small changes. Namely, to change the order of the pins in the example code from:

// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);


// pin 3 - Serial clock out (SCLK)
// pin 4 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 6 - LCD chip select (CS)
// pin 7 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 6, 7);

Time to try it out, and indeed it works! The example graphics from Adafruit starts filling the screen.

I fast noticed, however, that the graphics was flipped in the x direction. A small fix in the library code fixes this. You can see a file comparison of the change here.

Now let's display something interesting. I have a vision that sometime in the future I will make a windmill, and for that I would need a regulator, taking care of charging a battery. It would be cool to include a display the regulator, indicating amount of power produced, remaining battery juice and so on. A battery indicator can be simply created using the rectangle drawing functions of the Adafruit library, called drawRect() and fillRect(). I decided to also make a picture of a windmill, that would turn when there was wind, and be still when not. For this I made three pictures, to be displayed after each other, simulating turning of the blades.

To simplify making the bitmaps significantly, you can make the images in Gimp and save in .xbm format. The file can then be opened in notepad and the text simply copied into the Arduino file. For it to work I first changed the Adafruit code to allow this, but then I realized that meanwhile an update had been made to the git repository, to allow exactly that. Behold the result:

My example code and the gimp files can be found here.

Monday, January 20, 2014

Electric Guitar Amplifier Repair - Bad Knobs

So I finally decided to invest in a guitar... or my neighbor happened to leave the country, and wanted to get rid of some stuff. One of the above. In any case, I now have a complete electric guitar set including amplifier.

The amplifier did not work all that well, sadly. A couple of the knobs needed fiddling forever to get some sound out of it. A bit like trying to open a safe without knowing the combination.

The solution was simple though. In fact, it's almost embarrassing to make a blog post about it. The answer is called "contact spray".

The above is the kind you find in the Netherlands, but I'm sure other countries have equivalent types.

The spray improves the contact by dissolving dust and oxidation, in this case between the contact surfaces in the potentiometers. Just pulling off the knobs and spraying might work, but to reach from every angle (and for the fun of it) I opened it up.

Some spraying and knob-turning later, it worked fine! Interesting to note is that the smooth feeling when turning the knobs disappeared, and in one case it became much harder to turn. My guess is that the spray dissolves any oil or fat put there as lubricant.

To fill out an otherwise tiny post, below you can see the part that creates the reverb (a sound affect which sounds a bit like echo). It was a surprise to me that this was a mechanical part, instead of some electronic circuit. It works quite simply by inducing vibrations on one side of the springs with electromagnets, and reading the vibrations on the other side with the same mechanism.

One detail remains. Learning how to play the guitar.

A friend of mine who has worked as a sound guy for a long time pointed out to me that there are better ways to fix the problem. As I suspected, the contact spray I use dissolves the existing lubricant, which removes the smooth feeling, but also risks damaging the carbon when turning, which could decrease the life time of the potentiometer. I've also noticed that, although the knobs work, there is quite some noise while turning.

Apparently there are special lubricants that takes care of those issues. They are quite expensive, but I suppose when a mixer board costs thousands of Euros it's a small price to pay. Here is some advice and information on how to properly clean knobs and faders. Last resort, if it still does not work properly, would of course be to replace the potentiometers.

Wednesday, December 11, 2013

Controlling Oscilloscope with Linux Computer

I know it's not something you would need on an everyday basis (rather lifetime basis), but wouldn't it be cool to be able to control your instruments using a script? Or let's say you want to enjoy the comfort of your desktop chair, while remotely controlling and getting data from your instrument in the workshop? With this mindset I started looking for ways to control my oscilloscope with my small eee pc with linux on it (CrunchBang 11, to be exact).

For a windows user you would install whatever software the oscilloscope manufacturer provides, which would place a "visa32.dll" file in your windows directory. This file would make it possible to communicate to the oscilloscope with the VISA API, and pyVISA could be used to control the scope with the programming language Python. For linux, we cannot rely on the luxury of the manufacturer supplying drivers (one can only have faith for the future). At first I tried to find a visa32.dll equivalent, but that didn't lead anywhere. It turns out that a full-worthy solution DOES exist, thanks to someone called Alex Forencich. He has made a pure Python driver based on USBTMC, and a IVI like wrapper on top of that (also in Python).

Before starting to install his work, PyUSB is needed:
sudo apt-get install python-usb

Unfortunately, for some reason, PyUSB is not installed that easily (see link). You also have to run
sudo apt-get install python-pip
sudo pip install --upgrade pyusb 

Now we're ready to install Python USBTMC (look for "Download ZIP"). Navigate to the folder where you downloaded the zip file and run:
cd python-usbtmc-master
sudo python install

Python USBTMC is now installed. Clean up by removing folder and zip file:
cd ..
sudo rm -r python-usbtmc-master 

Try it out:
ulf@eee:~$ python
Python 2.7.3 (default, Jan  2 2013, 16:53:07)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import usbtmc

All seems fine, but let's not get our hopes up too soon. At this point we need to figure out what the vendor and product ID of the instrument is:
ulf@eee:~$ lsusb
Bus 001 Device 004: ID 0957:179a Agilent Technologies, Inc. 

The first ID is the vendor (0957), and the one after the semicolon, the product ID (179a). Note that you need the "0x" in front of the number to indicate that it's hexadecimal (hate to admit it, but this caused me quite some hair loss). Alternatively you can convert it to decimal and use that directly.
ulf@eee:~$ python
Python 2.7.3 (default, Jan  2 2013, 16:53:07) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import usbtmc
>>> instr = usbtmc.Instrument(0x0957, 0x179a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/usbtmc/", line 165, in __init__
    if self.device.is_kernel_driver_active(0)
  File "/usr/local/lib/python2.7/dist-packages/usb/", line 719, in is_kernel_driver_active
  File "/usr/local/lib/python2.7/dist-packages/usb/", line 70, in managed_open
    self.handle = self.backend.open_device(
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/", line 733, in open_device
    return _DeviceHandle(dev)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/", line 618, in __init__
    _check(_lib.libusb_open(self.devid, byref(self.handle)))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/", line 571, in _check
    raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

Darn... What to do now? Luckily Alex knew about this and had some pointers in his readme file. As indicated by the error message, we're dealing with a permission problem. The instrument has to be added to the usbtmc group. Create a file called usbtmc.rules in the correct folder:
sudo nano /etc/udev/rules.d/usbtmc.rules

Add the following lines to it:
# USBTMC instruments

# Agilent DSO-X 2004A
SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="0957", ATTRS{idProduct}=="179a", GROUP="usbtmc", MODE="0660" 

Create group:
sudo groupadd usbtmc

Add your user to the group (change "ulf" to your own user name):
sudo usermod -a -G usbtmc ulf

Restart the computer and try again:
ulf@eee:~$ python
Python 2.7.3 (default, Jan  2 2013, 16:53:07) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import usbtmc
>>> instr =  usbtmc.Instrument(0x0957, 0x179a)
>>> print(instr.ask("*IDN?"))
AGILENT TECHNOLOGIES,DSO-X 2004A,MY********,02.35.2013061800

It works! In fact, you can stop here and be satisfied if you want. At this point you can fully control your instrument. For example, if I want to stop my scope and then invert channel 1, I will write:
instr.write(":CHAN1:INV ON")

It's, however, not a very convenient way to control your instrument. The IVI foundation has standardized how to use the C, COM and .NET programming languages to simplify the control (as described here), but does not say anything about Python. Therefore Alex has written his own Python interpretation of the standard, called "Python IVI". There are drivers for quite a few instruments, and luckily my oscilloscope is one of them.

To install, as before, download the zip file, extract, install and clean up:
cd python-ivi-master
sudo python install
cd ..
sudo rm -r python-ivi-master

Now, try it out (replace ******** with the serial number of your instrument):
ulf@eee:~$ python
Python 2.7.3 (default, Jan  2 2013, 16:53:07)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ivi
>>> mso = ivi.agilent.agilentDSOX2004A("USB0::0x0957::0x179a::MY********::INSTR")

If there are no error messages, you're in control! Now, if you want to for example retrieve all data points from on measurement on channel 1, write:
waveform = mso.channels[0].measurement.fetch_waveform()

Or if you simply want to enable channel 4:
mso.channels['channel4'].enabled = True

Coolness achieved.

Sunday, October 20, 2013

AC Dimmer Repair

Ever been annoyed by flickering lights of one of your light bulbs at home? It's likely to be caused by your dimmer. In my case, besides constantly checking if I'm suffering from epilepsy (so far I'm safe), it was also making an annoying sound.

First step in trying to repair anything is to open it up and check for obvious problems, like burst capacitor or visibly over-heated components.

Nothing obviously wrong there. At this stage I decided to go all the way and find out exactly how such a dimmer works. If I succeeded, I thought, I should be able to find the broken component.

For this, I found a very good link with a lot of information. In addition, I decided to simulate the circuit with LTspice (You can find the LTspice files here).

For details on how such circuits works you can check the link, but in general, part of every half-period of the 50 Hz sine wave from the socket is cut off. In other words (actually, pixels), like this:

TRIAC dimmer

In that way the amount of power that is sent to the lamp can be regulated, which is seen as changing brightness.

All of this is achieved by having a capacitor being charged up (C2) at different speeds. When a specific voltage has been reached, the circuit is suddenly opened (with U2) and current flows through the light bulb. The speed of which the capacitor is charged, is varied by increasing or decreasing the resistance of the current that flows to it (R4).

The DIAC seen in the schematic (U1) is not strictly necessary; the TRIAC (U2) does the actual work of releasing the current to the light bulb. The DIAC is there to make the point in time when conducting starts more predictable. To test if any of the two was broken, I simply bridged over the DIAC by soldering a small wire. Except noticing that the transition from zero to full brightness was less smooth (could be expected when no DIAC is present), the flickering still existed. Therefore my conclusion was that the TRIAC was to blame.

I de-soldered the TRIAC and went to the local electronic shop to buy a new one. Viola! It worked. No flickering, no sound, no epilepsy.

Monday, July 29, 2013

Box for Pandaboard

You might think making a box is simple...

I'm using an ARM board called the Pandaboard as a media station which works fine, but it doesn't look that good in a living room (despite the fact that I partly share Benders excitement of naked electronics). I thought I would just make my own box, since at the time nothing was available to buy. I did not quite realize the amount of effort needed. However, after putting my sweat and blood into it (literally, as we shall see), in the end I can say that I'm pretty satisfied.

I wanted the following features for my box:
- As small as possible
- Have space for a hard drive
- Have all buttons, LEDs and connectors available
- Look like something you want to put in a living room

I decided to make the box out of wood, partly because it lets through the wireless interfaces and partly because it's easy to work with ('easier' that is). I must admit that the nice look of wood also made a difference.

I knew I needed to be very exact in measurements (sub mm) to get a decent result. Therefore I decided to make a complete model in Sketchup. At the same time I could play with different solutions and see if it looked ok.

Anybody who also has a Pandaboard and wants to do something similar, or simply want to use the model of the board to know exact positions of all the connectors, can find the drawing here.

The sides of the box are made out of solid wood, and the top of film faced plywood. I chose it because I liked the contrast of the dark brown and the beige wood. To make precise cuts I borrowed a Japanese saw from my father. I must say that it's a huge difference compared to conventional saws. Your eyes and steady hands are the limits rather than the tool.  For most of the holes I used a drill press (also owned by my father).

There are two LEDs on the Pandaboard, and with the software build I'm using, one is showing the processor activity in a heart-beat fashion, and the other, usage of the SD-card. Obviously I want to see them also after encapsulating the board, so I made two small holes in the front panel. To lead the light I needed some transparent glass or plastic. I looked around to see if that was something you can buy of the shelf, but found nothing. Instead I got a piece of thick plastic from one of my girlfriend's makeup jars and started making one myself.

The light should be directed in 90° so I made an angle of 45° in the plastic, and made it as shiny as possible with a fine file and some leather. 45° will be enough to give total internal reflection, assuming a refraction index of 1.5 of the plastic. To fit the pieces in the front panel holes, I filed them round at one end, and made them small enough to just barely fit in the holes (that way they will stay in place without glue). I also made sure to matte the visible surface with sand paper. My idea is that the light then will get diffused at the surface, and be equally visible from any angle.

I noticed that a lot of light leaked over from the LED close by, so I put some electric tape on the sides. Works quite well! (see the last picture of this blog post to get an idea).

I put the hard drive under the board, and to make the box as small as possible I needed to modify the usb cable to be angled. The first one I made didn't work because the cable was for usb 1.1 only (doh!).

Since I permanently use the hard drive and need one USB slot for a wireless keyboard, it felt like a good idea to add some slots. Fortunately the Pandaboard has two slots on the PCB which just needs a connector. Even more fortunately, the double slot connector I bought could be placed directly on the PCB! Might be of interest to anybody else who simply wants to add two USB slots. Make sure the pinning of the board (find the manual here) corresponds with the pinning of the USB connector. In my case, the pitch was slightly different for the holes and the pins, but not enough to be a problem. Also make sure to isolate the bottom of the connector! Otherwise you're likely to cause a shortcut somewhere. I used electrical tape and pressed the pins through.

Perhaps the most delicate part was to put all the wooden pieces together. Even though I made an effort to be precise when cutting them, there were small variations. In the end the best way was to fasten all four sides in a position that looked good (as seen in the picture below), and glue them on one by one.

I extended the buttons of the board in the simplest way I could come up with: two holes, two screws. To make it look better I polished away the slots on the heads of the screws, and made a thin indent in the wood. I wouldn't say it's impossible to do it with a normal drill, but it's a huge help to use a drill press.

After using the box for a while I noticed that it became pretty hot inside, despite the air holes on the lid and on the bottom. I had a small computer fan laying around which I thought would work. It was rated at 12 Volts, and the Pandaboard works with 5 Volts. That turned out to be only good, however. The air flow doesn't need to be immense, and by running it at the lower voltage it's much quieter.

I used two of the holes in expansion connector A for ground and 5 Volts.

As a final touch, I decided to give the box a name. I first experimented with using the brown top layer of the film faced plywood. This is where the blood comes in... I used a Stanley knife to try to peel off the top layer of a piece of the plywood. It slipped, and ended up in my hand.

I had apparently cut one of the tendons in my thumb, so the doctor had to find both ends of it and attach them together. Months of rehabilitation waited. You could at least have hoped that the idea was good, but when I some weeks later took courage to try again, it turned out the wood was too brittle for letters of the size I wanted. Instead I used a piece of fake leather from a sweater label. I used my friend the Stanley knife to cut the letters out, and a belt hole puncher to make the holes.

And here it is, in its rightful place:

Monday, May 13, 2013

Hard drive magnets

Do you have some broken hard drives laying around? Don't throw them away! You can extract and use the very powerful magnets inside. It's usually no problem getting them out, providing that you have the right tool (usually a small torx screwdriver). If you insist on some instructions, look at this link. Personally, though, I prefer to figure things out myself as I go along if I know there is no risk damaging something. It's your choice of course... I'm just saying... you probably learn more without....... I'll shut up now.

A warning is in place here. The magnets are very strong!!! If your finger get stuck in between two magnets, it will hurt. Even worse is a piece of your skin (Yes, it happened to me).

You can probably think of other ways of using them, but I decided to use them as hanging devices for tools.

In that way you don't have to buy hooks; just make the device yourself by screwing the magnets in place (provided that you kept the metal part that the magnet was mounted on). It's also much easier to attach the tool, since you only have to get close for it to snap into place.

Another, related, application is to hang jars from the magnets (metal caps required, obviously). My experience was that 3.5 inch hard drive magnets work perfectly for this purpose, while the 2.5 inch ones (left in the picture below) are a bit too weak.

You might wonder why two of the magnets are blue... That's because I intended to use them for the bicycle dynamo I already blogged about here. The blue part is shrink tube, which I closed with electrical tape to protect the magnets from getting rusty. There! Everyone's curiosity satisfied (expect perhaps those who wonder why Star Wars LEGO is hinted in the picture of a grown man's apartment...).