Wednesday, June 4, 2014

3wire SPI temperature sensor and relay control boards (suitable for Raspberry Pi)

I've been using this LM95071 temperature sensor breakout for quite a while.


Low-power, high-resolution (13-Bit plus sign) digital temperature sensor with an SPI/MICROWIRE compatible interface. 5-pin SOT-23. From Texas Instruments.
Works just fine with the RPi :)

And here is the relay control board:




Coil is 5V DC. Controlled with digital transistor. All you need is 1 GPIO pin from any MCU.
-----------------------------------------------------------------------------------------------------------------

Friday, May 30, 2014

Raspberry Pi camera case and lens

(It's been a while since my last post...)

The RPi camera in a 3D printed case and some wide screen lens attached to it:




I bought the lens from ebay.com. Just search for "Fish Eye Lens for iPhone" or something.

As for the case: www.thingiverse.com/thing:92208
I used these exact files: front | back
-----------------------------------------------------------------------------------------------------------------

Monday, January 14, 2013

Wireless temperature sensor with Raspberry Pi

Finally got some time to play with the Raspberry. Behold the wireless temperature sensor :D




The sensor itself is LM95071. Temperature is read through SPI. The only problem was that after the first read the sensor was put in shutdown mode... I guess this is because the SPI is full duplex and the SI/O pin was left dangling during WR to the sensor (even though I was only reading from it...). The solution was to add pull-down resistor to the SI/O pin (the additional resistor on the picture).

I have Apache web server on the RPi and I'm using WUSB54GC wifi dongle to transmit the temperature over the internet :)


-----------------------------------------------------------------------------------------------------------------

Monday, August 6, 2012

WiFi dongle on Raspberry Pi


A little guide how to use Linksys WUSB54GC WiFi dongle on Raspberry Pi (Raspbian “wheezy” images). The dongle is pretty old but I used it just for the test :)

(1) You need self-powered USB hub!
(2) Plug the dongle in the hub:

pi@raspberrypi:~$ dmesg
[  111.915950] usb 1-1.3.2: new high speed USB device number 5 using dwc_otg
[  112.216207] usb 1-1.3.2: New USB device found, idVendor=13b1, idProduct=0020
[  112.216240] usb 1-1.3.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  112.216261] usb 1-1.3.2: Product: Compact Wireless-G USB Adapter
[  112.216290] usb 1-1.3.2: Manufacturer: Cisco-Linksys
[  112.311511] cfg80211: Calling CRDA to update world regulatory domain
[  112.495964] usb 1-1.3.2: reset high speed USB device number 5 using dwc_otg
[  112.978042] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[  112.981551] Registered led device: rt73usb-phy0::radio
[  112.982146] Registered led device: rt73usb-phy0::assoc
[  112.982727] Registered led device: rt73usb-phy0::quality
[  112.987435] usbcore: registered new interface driver rt73usb

We can also see the drivers are loaded:

pi@raspberrypi:~$ lsmod
Module                  Size  Used by
...
rt73usb                 23490  0
rt2x00usb              12077  1 rt73usb
rt2x00lib              43890  2 rt2x00usb,rt73usb
mac80211              253889  2 rt2x00lib,rt2x00usb
cfg80211              180459  2 mac80211,rt2x00lib


(3) wlan0 interface is automatically created:

pi@raspberrypi:~$ ifconfig
wlan0     Link encap:Ethernet  HWaddr 00:1d:7e:11:c4:56
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


(4) To connect automatically to WiFi AP add this to /etc/network/interfaces:

auto wlan0
iface wlan0 inet dhcp
  wpa-ssid <AP-SSID>
  wpa-psk <KEY>


(5) Restart networking:

pi@raspberrypi:~$ sudo /etc/init.d/networking restart
Running /etc/init.d/networking restart is deprecated because it may not re-enable some interfaces ... (warning).
Reconfiguring network interfaces...Internet Systems Consortium DHCP Client 4.2.2
Copyright 2004-2011 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/00:1d:7e:11:c4:56
Sending on   LPF/wlan0/00:1d:7e:11:c4:56
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 9
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 12
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPOFFER from 192.168.32.1
DHCPACK from 192.168.32.1
bound to 192.168.32.104 -- renewal in 32936 seconds.
done.


Done!

pi@raspberrypi:~$ dmesg
[  374.243090] wlan0: authenticate with 00:b0:0c:4f:25:10 (try 1)
[  374.244913] wlan0: authenticated
[  374.307729] wlan0: associate with 00:b0:0c:4f:25:10 (try 1)
[  374.312512] wlan0: RX AssocResp from 00:b0:0c:4f:25:10 (capab=0x411 status=0 aid=1)
[  374.312540] wlan0: associated

pi@raspberrypi:~$ ifconfig
wlan0     Link encap:Ethernet  HWaddr 00:1d:7e:11:c4:56
          inet addr:192.168.32.104  Bcast:192.168.32.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:51 errors:0 dropped:0 overruns:0 frame:0
          TX packets:37 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:10652 (10.4 KiB)  TX bytes:4726 (4.6 KiB)


Try some ping:

pi@raspberrypi:~$ ping google.com
PING google.com (209.85.148.101) 56(84) bytes of data.
64 bytes from fra07s07-in-f101.1e100.net (209.85.148.101): icmp_req=1 ttl=56 time=34.7 ms
64 bytes from fra07s07-in-f101.1e100.net (209.85.148.101): icmp_req=2 ttl=56 time=46.4 ms
64 bytes from fra07s07-in-f101.1e100.net (209.85.148.101): icmp_req=3 ttl=56 time=45.8 ms
...

So for the test I left it pinging for some time. Haven't seen any issues till now :)

Next step: To avoid using self-powered hub find WiFi dongle with lower power consumption... :/
-----------------------------------------------------------------------------------------------------------------

Friday, August 3, 2012

Raspberry Pi

My long awaited Raspberry Pi finally arrived:


I tried it with Raspbian (wheezy) images:


One of the first impressions is that apparently there is absolutelly no power management (PM) - the board generates a lot of heat :(
Should search for images with some PM optimization (hope they exist).

Hmm... now must think of a good project :D
-----------------------------------------------------------------------------------------------------------------

Wednesday, August 31, 2011

Touchscreen calibration in Android

Another how-to. This time about touchscreen calibration for Android.

We assume you already have your touchscreen driver for your dev board and you've tested it with Android getevent (or the evtest tool) and you're sure it's giving the right coordinates to user space.

Next step before really using it is calibration ... which is real pain in the a** because Android doesn't provide a calibration tool. For the purpose we are going to use ts_lib.

To clone ts_lib package ported for Android use:
$ git clone git://tslibonandroid.git.sourceforge.net/gitroot/tslibonandroid/tslibonandroid

Then build it as normal Android package with "mm" (I assume you already know how to build Android... If no checkout this link for basics).
Copy all output files from the build to their corresponding places in the target dev board.

To create calibration file for the touchscreen boot the board, export the following environment variables

export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CONFFILE=/system/etc/ts.conf
export TSLIB_CALIBFILE=/system/etc/pointercal
export TSLIB_PLUGINDIR=/system/lib
export TSLIB_CONSOLEDEVICE=/dev/tty
export TSLIB_FBDEVICE=/dev/graphics/fb0
 (see also Android.mk in ts_lib sources)

and then run the newly built ts_calibrate tool.

Now we must apply this patch to make Android use the calibration file we created.

Rebuild Android services and you custom touchscreen must now work properly :) Hope it was useful!

P.S. the above was tested on Android Eclair with resistive touchscreen.
-----------------------------------------------------------------------------------------------------------------

Thursday, June 23, 2011

Java attempt


Today I made my first java application using NetBeans IDE. Hurray! :)
It converts Celsius to Fahrenheit and the opposite ... *quite* n00b-ish :D

How it looks:


The jar file: CelsiusConverter.jar

-----------------------------------------------------------------------------------------------------------------

Friday, April 29, 2011

Git cheat sheet

Yet another git help :)
This time cheat sheet (mostly for beginners):


-----------------------------------------------------------------------------------------------------------------

Thursday, April 28, 2011

Dropbear sshd on Android device

Recently I needed to have SSH connection with Android development board but since no SSH daemon is included in the official Android release I had some troubles finding the right way to do it.

The following guide was tested on OMAP3 development board with Android Eclair but should be working on any (rooted/unlocked) phone with Android.

Instructions how to run dropbear sshd on Android device:

First you fetch the latest Dropbear sources:
git clone git://android.git.kernel.org/platform/external/dropbear.git

Since the Android has different paths, no password support, etc. we must fix this in the original sources by applying the patch found here: http://pastebin.com/f3dedc5e7
...the only problem is that it's for older version of Dropbear so we must try to apply it manually :(

After patch was applied build with:
./configure --host=arm-none-linux-gnueabi --disable-zlib
make CC=arm-none-linux-gnueabi-gcc

In case you're unable to apply the patch correctly or something went wrong with the build here is a archive with prebuilt binaries (dropbear, dropbearkey, dropbearconvert):

(Another guide how to build Dropbear for Android can be found @ http://teslacoilsw.com/dropbear)

Install:

To install dropbear on the desired gadget copy the binaries to some custom dir, e.g. /dropbear.


Setup the Server (Android):

Generate a RSA server key using dropbearkey:
dropbearkey -t rsa -f dropbear_rsa_host_key

Then create a dir /data/dropbear and copy dropbear_rsa_host_key there.

Test dropbear:
/dropbear/dropbear -r dropbear_rsa_host_key -F -E -v -s

This should show you the debuglog (the (-F) option means non-daemon mode).

Now we need to generate a key-pair for the client to connect with (Dropbear is run with the option -s (no-password) because there is no password support in Android):

//generates a private key
dropbearkey -t rsa -f /dropbear/id_rsa

//extract the public-key:
dropbearkey -f /dropbear/id_rsa -y > /dropbear/id_rsa.pub

We need to create /data/dropbear/.ssh and cat the public-key to authorized_keys:
mkdir /data/dropbear/.ssh
cat /dropbear/id_rsa.pub > /data/dropbear/.ssh/authorized_keys

IMPORTATNT: Check the perms of /data/dropbear and make sure they are *only* readable/writable by root!


Setup the Client (Ubuntu):

As dropbear and openssh use different key formats we first need to convert id_rsa (private key) to openssh-format:
./dropbearconvert dropbear openssh /dropbear/id_rsa /dropbear/id_rsa_openssh

Now move id_rsa and id_rsa_openssh to your desktop (e.g. to your home dir).

Before establishing connection gadget's USB interface should be UP:
busybox ifconfig usb0 up 192.168.1.2
(yes, busybox must be installed on the Android device...)

Finally connect to the device:
ssh -i id_rsa_openssh <device-ip>

You can use -vv for both the client and the server to see debug info and fix whatever is wrong.


Setup the Client (Windows XP):

The only difference is that we use different SSH client. I used PuTTY.
So...
- boot the board/phone
- connect PC with board with USB cable and wait for auto install
- set IP address (TCP/IP settings) in the automatically created USB Ethernet connection
- copy auth. keys generated with dropbear
- convert OpenSSH key to "PuTTY" key (ppk) using PuTTYGen
- open PuTTY and set remote IP/Port to connect to
- use SSH key generated with PuttyGen: Connection -> SSH -> Auth -> select key
- connect!

NOTE: The above is extended/edited version of the original guide @ http://cri.ch/sven/doku.php/blog/running-dropbear-on-android

-----------------------------------------------------------------------------------------------------------------

Tuesday, April 19, 2011

Useful git commands


Some git commands that I found useful...

To remove all untracked files and dirs (aka "uber clean"):
$ git clean -f -d -X

For more useful/clear git log ouput:
$ git log --oneline --decorate

or  better use the following command:
$ git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

You can add it as alias in ~/.gitconfig :

[alias]
        lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative


More @ http://cheat.errtheblog.com/s/git

-----------------------------------------------------------------------------------------------------------------

Monday, April 18, 2011

Eee PC 901 paint job

At laaast! The 2-year warranty on my Eee PC 901 netbook has expired. Since I bought it its pearl white color was torture to my eyes (there were only white ones left at the store) but now I can finally pain it BLACK >:]

The disembowelment was kind of hard but here is the result:


Actually I was a bit surprised by of the assembly quality. Asus did a good job :)

Next I took all parts of the case, mask all necessary holes with duct tape (the mic, all the LED holes, etc.) and sand the parts a little. Then I removed any grease left and applied three layers of paint (with 2h for drying before applying the next  layer).

I left it for 24h to dry and here is it (I spent two hours assembling the damn thing):



Maybe not quite as I expected but it looks nice. :) Though I *should* have bought more expensive paint.
I left the battery white but maybe (someday) I'll paint it too. And maybe order some black keyboard & pad from ebay .... :)
-----------------------------------------------------------------------------------------------------------------

Wednesday, April 13, 2011

Encode/Scale video with MEncoder


The only thing I don't like about my old Canon S3 IS camera is that it records video without compression. Meaning that 4min 640x480/30fps vid is about 512MB...
I spend some time playing with MEncoder ("...a free command line video decoding, encoding and filtering tool released under the GNU General Public License" and a really *great* tool) and found a way to encode (or scale) my videos from Linux command line:

Encode from Canon RAW (acceptable quality):
$ mencoder INPUT.mpeg -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1800:mbd=2:trell=yes:v4mv=yes -o output.avi
Scale video:
$ mencoder INPUT.mpeg -vf scale=320:240 -oac copy -ovc lavc -lavcopts vcodec=mpeg4 -o OUTPUT.mpeg

-----------------------------------------------------------------------------------------------------------------

Create swap file in Linux

Some time ago when I was working with a BeableBoard-like dev board I had troubles creating Linux swap file. After reading some guides over the internet I'd like to share this simple how-to (Ubuntu):

1) Create "empty" file (~537 MB):
$ dd if=/dev/zero of=/swapfile1 bs=1024 count=524288

2) Setup Linux swap area:
$ mkswap /swapfile1

3) Activate swap space immediately:
$ swapon /swapfile1

4) Add to fstab (optional):
/swapfile1 swap swap defaults 0 0

To test:
$ free -m

To deactivate:
$ swapoff /swapfile1


Hope that someone would find it useful :)
-----------------------------------------------------------------------------------------------------------------

Tuesday, April 12, 2011

Different look for the Linux console

// lol...first "official" post


If you're bored of the default color your Linux console or want to change the look of it checkout the following example (Ubuntu):

Edit ~/.bash.rc with:

PS1="\n\[\e[32;40m\]| \[\e[31;40m\]\H \[\e[32;20m\]\d \[\e[32;1m\]\t \[\e[1;33m\]\w\[\e[0m\]\[\e[32;40m\]\n| \[\e[37;40m\]\u\[\e[1;37m\] \\$ \[\e[32;1m\]\[\e[0m\]"

and

force_color_prompt=yes


Output:


Feel free to modify :)
-----------------------------------------------------------------------------------------------------------------

Creation!

Blog created.
Purpose yet unknown :)
Will post random stuff...