Sunday, December 27, 2015

Running LCDProc on Digispark

The project I was working on recently was to get the Digispark module to act as a Linux I2C-to-USB driver. It wasn't all so straight forward so I decided to put a little put a little tutorial on how to do it.

That's how the breadboard version of it looks like

Let's get to hacking!

Requirements

You will obviously need a Digispark or a clone of it. I used one I bought from aliexpress.com and it does the trick quite nicely

Let's assume you don't have the micronucleus bootloader installed and let's build one from scratch. You'll need a AVR programmer like USBasp (cheap and does the job very well)

Done. In case you're missing any libraries or tools that's the list of packages that is required

build-essential, avrdude, avr-libc, binutils-avr gcc-avr

You'll also need an LCD with PCF8547A or PCF8547T extender. I used one with T which required me to apply a patch to the LCDProc sources. More on that soon

The project

First we need the littlewire version of the firmware for our Digispark. You can get it form github

git clone https://github.com/nopdotcom/i2c_tiny_usb-on-Little-Wire

Buinding it and installing onto your Digispark is very straight-forward and described in details here.

Let's get to the hacky part of it!

Patching LittleWire firmware

As it turns out the original driver for i2c-tiny-usb was reluctant to recognize the hardware as proper I2C adapter. I needed to update the vendor and device IDs to make it work

After building it and installing again on the Digispark and loading the i2c-tiny-usb and i2c-dev modules using modprobe the command i2cdetect -l finally started spitting out some good news :)

padcom@aphrodite:~$ sudo i2cdetect -l
i2c-0 i2c        i915 gmbus ssc                   I2C adapter
i2c-1 i2c        i915 gmbus vga                   I2C adapter
i2c-2 i2c        i915 gmbus panel                 I2C adapter
i2c-3 i2c        i915 gmbus dpc                   I2C adapter
i2c-4 i2c        i915 gmbus dpb                   I2C adapter
i2c-5 i2c        i915 gmbus dpd                   I2C adapter
i2c-6 i2c        DPDDC-B                          I2C adapter
i2c-7 i2c        DPDDC-C                          I2C adapter
i2c-8 i2c        i2c-tiny-usb at bus 001 device 057 I2C adapter

After hooking up the LCD to pins 0 (SDA) and 2 (SCL) and adding 2 4.7k pull-up resistors the LCD has been properly recognized as well :)

padcom@aphrodite:~$ sudo i2cdetect 8
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-8.
I will probe address range 0x03-0x77.
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

Success! Well, actually to get to this point took me over 2 days to figure out all the moving parts but the joy of having it actually working was just great :)

Now it's time to do some serious work with that new piece of hardware we have. Let's use LCDProc to display some system statistics!. Download, extract... and if you're using the PCF8547T version of the extender apply the following patch before building:

All that is left is to configure and build and configure the LCDProc package. Tested also on Raspberry Pi 2 and works flawlessly.

./configure --enable-drivers=hd44780 && make && sudo make install

Now edit the /usr/local/etc/LCDd.conf file as follows

DriverPath=/usr/local/lib/lcdproc/
Driver=hd44780
ServerScreen=off

And under the section [hd44780] make sure you have the following values

ConnectionType=i2c
Device=/dev/i2c-8 # that is the I2C bus id you have from i2cdetect -l
Port=0x27         # that is the I2C device id you have from i2cdetect 8
Check out also other options - they are all properly commented so it should be easy to figure out what they mean

Starting it all up

First start the LCDd daemon. You might want to start it initially with the -f (foreground) parameter to check if it works ok.

LCDd -f

Next you need to run the client. Yes! It is a client-server architecture! Use lcdproc --help for the list of all available options. I use the SMP-CPU version the most

lcdproc -f P

That's it! I admit this is more hassle that I generally like but getting it working is worth every late night minute I spent on it :)

Happy hacking!

No comments: