Raspberry Pi – Finally arrived

 Raspberry Pi  Comments Off on Raspberry Pi – Finally arrived
Jun 282012

Found a parcel in the mail yesterday when I got home from work.
The first text I read was T-shirt, and I wondered what this was. I had not ordered any T-shirt.
But then I read the complete sentence, 'dev-kit and T-shirt'.
At last, my Raspberry Pi had arrived!

It was some time ago since I signed up as interested to get one, and I haven't thought much about it since.
But now I need to get the peripherals needed, keyboard, mouse, SD card.
With that all taken care of today after work, I downloaded the Debian squeeze distro and put it on the card.
Hooking up the board to the TV, it was just to add power and it booted up nicely.

Entering login and password without any problem, and I was all set. Starting gui with startx, and I got this nice desktop!

That's it. All set to go...

VIM with GIT

 VIM  Comments Off on VIM with GIT
Jun 032012

As the source control system I use daily at work and in most of my home projects is GIT, and my favorite editor is VIM it was not far fetched that I wanted a easy way to use GIT from within VIM. After doing some searching and reading, I found this http://www.osnews.com/story/21556/Using_Git_with_Vim, which in turn points to https://github.com/amjith/git-vim.

Here is the information from the readme.rdoc file,


:GitAdd <file>
git-add <file> or current file if not specified.
:GitCommit <args>
Show git-status of current file or repository.
Show git-log of current file or repository.
:GitCheckout <args>
git-checkout. Completes git commits.
:GitDiff <args>
git-diff. Completes git commits.
:GitPull <args>
git-pull –rebase.
:GitPush <args>
git-push. Defaults to +git push origin <current-branch>+.
:GitCatFile <args>
:Git <args>
Does any git command.
Experimental. Call this command on unmerged file to enter vimdiff mode.
Call this command after merging.



:GitDiff –cached
:GitAdd <cfile>


In git-status buffer

:GitAdd <cfile>

Arduino – Home Automation Project, part 2.

 Arduino, DIY, Home Automation  Comments Off on Arduino – Home Automation Project, part 2.
Apr 242012

Well, at last I have made a simple Arduino library of the previous Tx433_Proove sketch. I have pushed the complete code up on GitHub.

Here is the public class interfaces.

class Tx433_Proove
@digitalpin - the digitalpin to send data on to transmitter
@transmittercode - the unique code of the transmitter (52 bits)
@channelcode - the channel code (4 bits)
Tx433_Proove(int digitalpin, char *transmittercode, char *channelcode);

@unit - the device to turn on.
0,1,2 are the three separate devices.
3 is the complete group.
void Device_On(int unit);

@unit - the device to turn off.
0,1,2 are the three separate devices.
3 is the complete group.
void Device_Off(int unit);

Made a new page at http://elektronikforumet.syntaxis.se/wiki/index.php/RF_Protokoll_-_Proove_self_learning to give something back to a great site.

Also added a new link at http://arduino.cc/playground/Main/LibraryList pointing at the Github upload.

Android touch events script

 Android, Python  Comments Off on Android touch events script
Apr 242012

When I have been working with touch drivers on Android devices, I usually end up using the getevent tool in adb.
But the output takes some time to understand. In order to make it easier for me and my colleagues, I made a small python script called touchevents.py.
It is a brute force implementation, but it gets the job done. I uploaded it to github here.

This is how it is used.

adb shell getevent | python touchevents.py event9
adb shell getevent -t | python touchevents.py event9

Arduino – Home Automation project

 Arduino, DIY, Home Automation  Comments Off on Arduino – Home Automation project
Apr 152012

Something I have thought about, on and off, for a long long time is to setup some remote controlled lamps at home.
I have read about the Tellstick from Telldus, but that requires a computer for controlling it. Also I have read and heard that the RF performance/reach is somewhat restricted.
Another solution is of course to use the Arduino together with a RF transmitter.
The different devices available in the stores are all using the same RF frequency, 433.92 MHz, with ASK modulation.

As this is the true DIY solution, I got both a transmitter and a receiver for this frequency 🙂

The transmitter, http://www.kjell.com/sortiment/el/elektronik/fjarrstyrning/433-mhz-sandarmodul-p88901
Data sheet, http://www.kjell.com/.mvc/Document/File?id=6d308334-d5c5-4ef1-8060-9fb700fc0f01

|       |
|   O   |
|       |
 | | | |
 | | | |
 1 2 3 4

pin    name
1      GND
2      Data In
3      Vcc
4      ANT

The receiver, http://www.kjell.com/sortiment/el/elektronik/fjarrstyrning/433-mhz-mottagarmodul-p88900
Data sheet, http://www.kjell.com/.mvc/Document/File?id=18c020a8-2364-4ee9-a99e-9fb700fc0d73

|                    |
|             O []   |
|                    |
 | | | |      | | | |
 | | | |      | | | |
 1 2 3 4      5 6 7 8
pin    name
1      GND
2      Data Out
3      Linear out
4      Vcc
5      Vcc
6      GND
7      GND
8      ANT

I bought the receiver to be able to sniff the data from the remote controller.

Initially I was going to get some Nexa devices. Something like these, http://www.nexa.se/PB3Ny3packsjalvlarande.htm.
But when I got to the store they didn't have these. Instead they had , http://www.kjell.com/sortiment/el/el-produkter/starkstrom/fjarrstrombrytare/sjalvlarande/fjarrstrombrytare-p50207, which is of the brand Proove. They told me it was the same thing(TM), but of course it would turn out it wasn't.

The reason for me to get Nexa was my research done prior to the purchase.
Well, well, they said it was the same in the store.

At home I fired up the Arduino IDE, and made a first attempt on controlling some lights, by just importing the HomeEasyCtrl library into a sketch as the example showed.
But of course that didn't work. It didn't even compile!
Some quick searching on the net, and I found out that old libraries, using #include "WProgram.h", needs to be updated with the following.

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "WProgram.h"
#include <pins_arduino.h>

With this change it compiles, but it does nothing with my remote controlled light.

Time for some extended research. Found out that Nexa has, at least, two different protocols. The old simple protocol, and the new self learning protocol.
A very good web site describing these protocols are http://elektronikforumet.syntaxis.se/wiki/index.php/Huvudsida, at least if you understand swedish.
I took this information, translated it, at put it on a single page here, http://tech.jolowe.se/home-automation-rf-protocols/.

My next approach, after reading up on the protocol, is to use the receiver to get the data from the remote, without needing to open it up.
After some tries, I got some result which I think is the code sent for turning on device number one.

? 1010100101101001010101100101011001010101010101010110 10 01 0101 0101 ?
? = seems like the start bit and stop bit described in the protocol does not exist.

But when I try to send this myself from the Arduino setup, nothing happens. Frustrating!
I tried this approach several times for several days, with modifications, but without any success.
As I ran out of new ideas on how to proceed, I open up the remote.
This is what it looked like.

The Xtal says 'ND13.560'.
The IC says 'Holtek HT48(or 46)R01T3 ...". Web here, http://www.holtek.com/english/.
Holtek IC pinout:
(by measurement, visual inspection and looking in the datasheet)

Dout -|1   16|- SW5
SW1  -|2   15|- Sw6
SW2  -|3   14|- SW7
SW3  -|4   13|- SW8
SW4  -|5   12|- Vcc?
?    -|6   11|- ?
?    -|7   10|- ?
Vcc? -|8    9|- Vcc?
SWx, is the buttons on the remote.

Web: http://www.holtek.com/english/docum/consumer/4xr01t3.htm
Datasheet: http://www.holtek.com/pdf/consumer/4xR01T3v130.pdf
Pin #1, Dout, is the actual data sent via RF!! This is what we want!
Time to decode (by probing Dout):
Pressing button #1 On switch and capture data with oscilloscope.
A Pause is, approx. 10 ms low.
A Sync is, high 240 us, low approx. 2.5 ms.
Data sent is: 10101001011010010101011001010110010101010101010101101001010101010
Pressing button #1 Off switch.
Data sent is: 10101001011010010101011001010110010101010101010101101010010101010
Zero = high 300 us, low 1.3 ms
One = high 280 us, low 250 us

A packet consist of:
Data 64 bits
The same packet is sent four times.

The above data is THE SAME(!) as I managed to sniff out of the air with my RX433 sketch!
Still, when I send this data, the receiver does nothing.
But if I look at the data I am sending, it doesn't look as nice as the one the remote is sending.
Especially the 'ones' are kind of distorted. The low part is not as 'distinct'. Wonder what the reason could be? Faulty HW?

Continued to probe all data patterns of the remote, while I still had it opened.

#                10        20        30        40        50           60
#       1234567890123456789012345678901234567890123456789012 34 56 7890 1234
#1 On:  1010100101101001010101100101011001010101010101010110 10 01 0101 0101
#1 Off: 1010100101101001010101100101011001010101010101010110 10 10 0101 0101
#2 On:  1010100101101001010101100101011001010101010101010110 10 01 0101 0110
#2 Off: 1010100101101001010101100101011001010101010101010110 10 10 0101 0110
#3 On:  1010100101101001010101100101011001010101010101010110 10 01 0101 1001
#3 Off: 1010100101101001010101100101011001010101010101010110 10 10 0101 1001
Gr On:  1010100101101001010101100101011001010101010101010110 01 01 0101 0101
Gr Off: 1010100101101001010101100101011001010101010101010110 01 10 0101 0101

Here is oscilloscope pictures of a data packet.

Now when I know I have the correct data from the remote, I try and change the HomeEasyCtrl lib accordingly.
But still, nothing happens when I try to send the data.
Just to rule out HW failure, I bought a second TX433 transmitter. But the result was the same. Conclusion, not a HW issue.
Start looking over my TX433 sketch again, and ... ARGHH!!!..., I found an error in my sendZero function.
Correcting that, and moving the Pause bit to after data instead of before Sync - IT WORKS!
Somehow, at least. Every fourth try fails, could it be a timing issue?
Changing the timing of the pulses, and now it works 100%!!!
The timing used now is:
Zero = 250 high, 1250 low
One = 250 high, 250 low
Sync = 250 high, 2500 low
Pause = 250 high, 10000 low.
A packet is sent as Sync + Data + Pause.

Here is my sketch for TX433 Proove,

TX433 - a 433.92 MHz ASK transmitter
Joakim Wesslen

This program handles the 'Proove' devices, not Nexa.

Found the 'Nexa Self learning' protocol description here (in swedish),
From which I started out.

But as it turns out, the Proove protocol is somewhat different.

Here is a brief description.

A packet is 64 bits in toatal (without dimming bits, whichI do not know if it handles).

Packet structure:
Bit nbr:    Name:
01-52       Transmitter code. 26 bits, but sent as 52 as every other bit is the inverse of the previous.
53-54       Group On(01), Off(10)
55-56       On(01), Off(10) (or Dim(11)?)
57-60       Channel. 1=1010, 2=1001, 3=0110, 4=0101
61-64       Switch.  1=1010, 2=1001, 3=0110, 4=0101
(65-73       Dimmer value, 16 steps. (optional))

Every message is started by a Sync (high pulse followed by a 2.5 ms low)
Every mesage is ended by a Pause (high pulse followed by a 10 ms low)
Every message is sent four (4) times.


#define DBGpin  13

#define TXpin  4
#define RETRANSMIT  4

int tOneHigh = 250; //275;
int tOneLow = 250; //170;

int tZeroHigh = 250;
int tZeroLow = 1250;

int tSyncHigh = 250;
int tSyncLow = 2500;

int tPauseHigh = 250;
int tPauseLow = 10000;

char *dim[15] = {

char *On1   = "1010100101101001010101100101011001010101010101010110100101010101";
char *Off1  = "1010100101101001010101100101011001010101010101010110101001010101";

char *On2   = "1010100101101001010101100101011001010101010101010110100101010110";
char *Off2  = "1010100101101001010101100101011001010101010101010110101001010110";

char *On3   = "1010100101101001010101100101011001010101010101010110100101011001";
char *Off3  = "1010100101101001010101100101011001010101010101010110101001011001";

char *GrOn  = "1010100101101001010101100101011001010101010101010110010101010101";
char *GrOff = "1010100101101001010101100101011001010101010101010110011001010101";

void setup() {
pinMode(TXpin, OUTPUT);
pinMode(DBGpin, OUTPUT);
//  dimtest();

void loop() {
//  group(on);

void group(boolean on) {

if (on) {
Serial.println("Group on");
} else {
Serial.println("Group off");

void test() {
Serial.println("Turn on #1");
Serial.println("Turn on #2");
Serial.println("Turn on #3");
Serial.println("Turn off #1");
Serial.println("Turn off #2");
Serial.println("Turn off #3");

void dimtest() {
for (int d = 15; d >= 0; d--) {
for (int i = 0; i < RETRANSMIT; i++) {
sendCode(On1, strlen(On1));
sendCode(dim[d], strlen(dim[d]));

void sendPackets(char *pkt) {
for (int i = 0; i < RETRANSMIT; i++) {

void sendPacket(char *pkt) {
sendCode(pkt, strlen(pkt));

void sendCode(char *str, int len) {
char *p = str;
int i = 0;
while (i <= len) {
if (*p == '0') {
if (*p == '1') {

void sendZero() {
digitalWrite(TXpin, HIGH);
digitalWrite(TXpin, LOW);

void sendOne() {
digitalWrite(TXpin, HIGH);
digitalWrite(TXpin, LOW);

// Sync
void sendSync() {
digitalWrite(TXpin, HIGH);
digitalWrite(TXpin, LOW);

// Pause
void sendPause() {
digitalWrite(TXpin, HIGH);
digitalWrite(TXpin, LOW);

Something I haven't mentioned so far, but as you might have seen in the code above, is the dimming levels.
The devices I have does not seem to use the dimming levels. But when I added it, it still worked, but without dimming.
It justed continued to turn on and off. Other Proove device though, might be able to handle this. I just don't know, as I havent tried it myself.

A small side note of information is that I found out that it is ArcTech that does the HW for Proove and Nexa et al, http://www.arctech.com.tw/html/profile.htm.

A note on the antenna. As the frequency is 433.92 MHz, I used an antenna (just a piece of wire) with a length of 690 millimeters. Also tried a quarter wave antenna, length 170 millimeters, with same result as the longer one.

As I now have a working sketch for the TX433 transmitter, the next step is to make it a library, to make it easier to re-use in other projects. Something new to learn, great!

Arduino – Display project

 Arduino, DIY  Comments Off on Arduino – Display project
Mar 192012

Some time ago I got myself a display, which I was thinking of hooking up to my Arduino Uno.
After having read some examples and reference stuff on arduino.cc and on ladyada.net about the 16 x 2 displays with the HD44780 chip, I was thinking about getting me one of those.
Unfortunately, what I got hold of was a ATM1602B Display, which also is a 16 x 2, but a completely different pin out.
And this is where the problem with this module is, the pin out. The documentation is everything, but clear.
This is a link to its manual and the datasheet.
As can be seen in the provided documentation, they do not number their pins as it is usually done. Starting from 1 (or zero) in one end and increasing it as you move along. No, that seems too easy, doesn't it.
After some trial and error, and measurements, I can conclude that the physical marking on the board is the correct one. Pin number one, is the third pin from the right when looking at the display from the front! The first two pins are the A (anode) and K (cathode) for the backlight.

This is the pin list I used to get it to work.

Arduino         LCD  Name
2               6    Enable
3               7    Data Bit 0 (DB0)
4               8    (DB1)
5               9    (DB2)
6               10   (DB3)
7               11   (DB4)
8               12   (DB5)
9               13   (DB6)
10              14   (DB7)
11              5    Read/Write (RW)
12              4    Register Select (RS)
pot.-out        3    Vo
+5V             2    VDD
GND             1    VSS

Please note, that the pin #1 is actually the third pin from the right when you are facing the display (as stated above).
Here is a link to a page that really help me on the way, http://www.arduino.cc/en/Tutorial/LCDLibrary.
Here is what my final setup looks like.

The potentiometer is 10kohm, and connected between Vdd and Vss, with its output connected to pin 3 (Vo) on the LCD.

Using the LiquidCrystalDisplay library does work well, and is a real time saver to get started quickly.
And here are some simple code to get something up on the display.

/* LCD fun
   Joakim Wesslen
   LCD = ATM1602B
#include <LiquidCrystal.h>
// 4 bit setup
LiquidCrystal lcd = LiquidCrystal(12, 11, 2, 7, 8, 9, 10);
// 8 bit setup
//LiquidCrystal lcd = LiquidCrystal(12, 11, 2, 3 ,4, 5, 6, 7, 8, 9, 10);
void setup(void){
  pinMode(13, OUTPUT);  // dbg
  lcd.begin(16, 2);  // columns, rows

void loop(void){
  digitalWrite(13, HIGH); // dbg

Now when I have the basics up and running, it is time to get into the more interesting stuff to utilize the full potential of the display.

Let's see what we learn in the future!

Mar 112012

Made some running LEDs to have something quick and fun to show my kids.
This is what it looked like. I am using the even numbered digital outputs, connected to a LED with a 220 ohm resistor to ground.

They really liked it. When I first set it up, I only used red LEDs, but they wanted me to switch to what is shown in the picture.

Here is a short video of the live action :-), FunWithLEDs

The programming was intense, not! It is a really easy thing to use Arduino with its IDE and all help and examples available.

This is what the coding ended up in.

  Fun with LEDs

int pin;

void setup() {                
  // initialize the digital pins as output.
  for (pin=0; pin < 13; pin++) {
    pinMode(pin, OUTPUT);     

void loop() {
  for (pin=0; pin < 13; pin++) {
    digitalWrite(pin, HIGH);   // set the LED on
    delay(30);              // wait
    digitalWrite(pin, LOW);    // set the LED off
    delay(30);              // wait

That's it! I am not sure what the next project will be. Either a Display project, or a HomeAutomation project controlling some Nexa power outlet switches.


VIM – revisited

 VIM  Comments Off on VIM – revisited
Mar 112012

Made some refactoring of my VIM settings the other day.

The current plugins used are:

  • colorsamplepack
  • cscope_maps
  • highlight_current_line
  • matchit
  • NERD_tree
  • SearchComplete
  • taglist

This is the current settings file, or .vimrc as it's called.

" Joakim Wesslen
" The inspiration for the below setup was found at these places
" http://www.derekwyatt.org/vim/
" http://www.swaroopch.com/notes/Vim_en:Programmers_Editor
" http://spf13.com/post/perfect-vimrc-vim-config-file
" http://www.catonmat.net/blog/vim-plugins-surround-vim/
" among others...
set nocompatible " not compatible with original vi
let mapleader="," " set mapleader to , instead of \
nmap <silent> <leader>ev :e $MYVIMRC<CR> " edit .vimrc
nmap <silent> <leader>sv :so $MYVIMRC<CR> " source .vimrc
" Status bar --------------------------------------------------------------
set ch=2 " Make command line two lines high
set showmode " show current mode in status bar
set stl=%f\ %m\ %r\ Line:\ %l/%L[%p%%]\ Col:\ %c\ Buf:\ #%n\ [%b][0x%B] " Set the status line the way I like it
set laststatus=2 " Show statusline in single window
" Color, layout etc  ------------------------------------------------------
set background=dark " background color
colorscheme darkgreen " color scheme
syntax on " Enable syntax highlightning
set tw=120 " text width
set cc=+1 " highlight column after textwidth
set nowrap " wrap text
"set smarttab " tab/backspace are smart
"set expandtab " insert spaces as tabs
set tabstop=8 " Tab length, nbr spaces
set cindent " indent according to tabstop
set smartindent " help me with indenting
set autoindent " autoindent
set sw=2 " scrollbar width
set number " show line numbers
set autoread " watch for file changes
set undolevels=1000 " nbr undo levels
set history=1000 " command history levels
set list " Show trailing spaces and tabs
set listchars=trail:+,tab:>- " Show trailing spaces and tabs
set foldminlines=5 " Folding lines shown
set foldnestmax=3 " Folding level
" Search ------------------------------------------------------------------
set ignorecase " ignore case in pattern
set smartcase " override ignorecase
set incsearch " show pattern in text as it is written
set hlsearch " highlight all matches
set wrapscan " Set the search scan to wrap around the file
set path+=** " search directories
" Copy --------------------------------------------------------------------
set cpoptions+=$ " add a $ at end of 'copy/change'
" Buffer ------------------------------------------------------------------
set hidden " change buffer without saving
noremap <C-Left> :bfirst<cr> " Switch to first buffer
noremap <C-Down> :bnext<cr> " Switch to next buffer
noremap <C-Up> :bprevious<cr> " Switch to previous buffer
noremap <C-Right> :blast<cr> " Switch to last buffer
" Windows -----------------------------------------------------------------
noremap <silent> <C-h> :wincmd h<cr> " Move the cursor to the window left of the current one
noremap <silent> <C-j> :wincmd j<cr> " Move the cursor to the window below the current one
noremap <silent> <C-k> :wincmd k<cr> " Move the cursor to the window above the current one
noremap <silent> <C-l> :wincmd l<cr> " Move the cursor to the window right of the current one
" Specials ----------------------------------------------------------------
map <C-s> :w<CR> " 'Ctrl s' to save file in command mode.
imap <C-s> <Esc>:w<CR>i " 'Ctrl s' to save file in insert mode.
" Plugins -----------------------------------------------------------------
:filetype plugin on "
" Function keys -----------------------------------------------------------------
map <F2> :TlistToggle<cr> " Taglist, need ctags
map <F3> :NERDTreeToggle<cr> " NERDtree
"map <F4> <cr> " Buflist (buflist.vim defines F4 as toggle window
map <F5> :b#<cr> " switch buffer
" file type detection
:filetype on "
autocmd FileType make set noexpandtab set sw=4
autocmd FileType c set tw=80
autocmd FileType h set tw=80
autocmd FileType patch set tw=80



 Arduino  Comments Off on Arduino
Feb 122012

After having read about it for a _very_ long time, I finally got around and bought an Arduino Uno the other day.
If you do not know what it is, all I can tell you is that it is an open source hardware for learning and experimenting with electronics and software in an easy way. It has a very big supporting community, and a very good website for all levels of users. Check out http://arduino.cc/en/ for more information.

To setup the Arduino IDE on my Dell laptop running Ubuntu 10.10, I followed this guide, http://www.pluggy.me.uk/arduino-ubuntu/, and it worked straight away.

The Arduino IDE comes with many examples, which are quite nice to use in order to quickly learn how to use a certain feature. Doing the standard 'Hello world' of electronics, making a LED blink, was done within minutes, thanks to the examples and guides.

Next up will be to use it with Python...

No mouse needed

 Linux  Comments Off on No mouse needed
Feb 092012

In my quest for using the computer mouse as little as possible, I thought I had come up with a great idea.
Why not implement a keyboard mouse, using the windows key and arrow keys for navigation.
But then my second thought was, this must already exist.
Sure enough, after some searching on the net, I found this link

Here is the essence of the link in short.

Shift + NumLock to activate numpad as keyboard mouse.
1,2,3,4,6,7,8,9 to navigate
”5” left mouse button
-” & ”5” right mouse button
”*” & ”5” middle mouse button

It will take some time to get use to, but at least it exists as an alternative.