Saturday, December 8, 2012

Raspberry Pi - Dallas Semiconductor Temperature Sensors

Today I set out to follow Edward O'regan's procedure for connecting a Dallas Semiconductor DS18B20 temperature sensor to the Raspberry Pi development board.

The first problem I ran into was with the sort of IDE cable I was using. If you look close you can see it's an 80-pin IDE connector. 

The problem with an 80-pin IDE connector as it turns out, is that it not only interleaves a ground between each pin on the ribbon cable, it also grounds specific pins within the socket. In the picture above we can see the ground plane that I pulled out of the socket for illustration purposes. we can see that at various points along the plane there are sharp protuding pins that make contact with the various pins in the socket. this is BAD for the raspberry pi as I found out (GPIO 4 worked but when I rebooted the pi, it locked up).

But, this wasn't all for nothing. Since I opened up the socket while troubleshooting, I noticed that the pins stick out far enough to be soldered to. Next I had to check to see if the plastic could take the high temperatures incurred during soldering. They did, very nicely. I heated them all at the same time for about 20 seconds and the plastic didn't give way whatsoever.

So I took a 6-foot hunk of cat-5e and soldered Brown, Orange, and Green to socket pins corresponding to Ground, +3.3v, and GPIO-4 (these are the pins needed to interface with a 1-wire device such as the DS18b20 temperature sensor).

Everything worked great on the first try. I added a second DS18B20 in parallel with the first and the second one was detected within a few seconds. I pulled temperature readings from both sensors. The fastest I could poll the sensors was bout 1-second per check. Not too fast, but not bad all things considering.

Next I tried configuring the sensor for "1-wire" or "parasitic" operation by shorting pins 1-3 to ground and leaving GPIO-4 connected to pin2 for data.

At first  it seemed to work, but upon closer inspection, both sensors returned 85-degrees-celcius every time regardless of the actual temperature. The strange thing is that the checksum was correct each time.

Since I don't mind stringing a third wire to each temp sensor I went forward with the 3-wire configuration.

Next I made a more permanent cable.

At the base of the wire I have the first of two sensors. And at the end of the cable is the second sensor.

close-up of both sensors along with the header.

1-liner used for testing

root@raspberrypi:/sys/bus/w1/devices# while : ; do for I in 28-* ; do echo $I ; cat $I/w1_slave ; done; done

Sample output

59 01 4b 46 7f ff 07 10 a2 : crc=a2 YES
59 01 4b 46 7f ff 07 10 a2 t=21562
50 05 4b 46 7f ff 0c 10 1c : crc=1c YES
50 05 4b 46 7f ff 0c 10 1c t=85000

Remaining Tasks

All that remains is to write a script to integrate the temperature readings with snmp, and write some scripts to collect and store the information. 

Saturday, September 8, 2012

Compiling GNURadio on the Raspberry Pi (Raspi)

I've been meaning to post this for a few weeks so today I'm going to jot down just the most pertinent information, in hopes that someone may benefit from what I learned.

So a few weeks ago I set out to compile Gnuradio on my Raspberry Pi. It took a lot of digging (googling) but thanks to many users who encountered similar challenges, I was able to piece together the recipe below, that should result in a compiled gnu radio installation.

Although Patch VonBraun's GNURadio build script didn't do the trick, I used it for reference when coming up with the following steps.

In the following section, lines starting with "#" should be executed as the root user. Lines starting with "$" may be executed as your favorite raspberry pi user.

build and activate an 800MB swap

(Credit to for posting these steps on the forum - thank you)

  # swapoff
  # swapoff -a
  # sudo dd if=/dev/zero of=/myswap bs=1024 count=800k
  # mkswap /myswap
  # free -m
  # swapon /myswap
  # free -m



* Raspberry pi wheezy/sid (make sure to get a suitable image)    *** Image (Wheezy 7.5) is too new, not supported by build script yet.
    *** Image (Wheezy 7.2) should work perfectly with this procedure :)
    *** Raspian images prior to January 2014 should work as long as the version is listed: "*6.0*|*wheezy*|*sid*|*7.1*|*7.0*|*7.2*|*7.3*|*7.4*)"

Option-1: build-gnuradio script (recommended) 

As the pi user (or another user with sudo access) run the following commands

$ cd; mkdir gnuradio; cd gnuradio
$ wget
$ chmod 755 ./build-gnuradio
$ ./build-gnuradio -v

Monitor the screen for the first 20 minutes and make it doesn't exit with an error. If it does, try running it a second time. Otherwise if it seems to be running, let it run, and come back in 24 hours :)

Big thanks to patchvonbraun for building and maintaining the build-gnuradio script!

Option-2: build from source manually

Install prerequisite packages

  # apt-get install python-cheetah libboost-all-dev python-lxml python-wxgtk2.8 python-numpy python-lxml libfftw3-dev libsdl1.2-dev python-scipy python-matplotlib python-tk octave liboctave-dev libgsl0-dev python-sphinx libcppunit-dev libuhd-dev swig python-qt4-dev libqwt-dev git

Check-out the latest copy of the gnuradio source tree

  $ cd ; mkdir gnuradio; cd gnuradio
  $ time git clone

cd into the build directory and run cmake.

  $ cmake -Dhave_mfpu_neon=0 -DCMAKE_CXX_FLAGS:STRING="-march=armv6 -mfpu=vfp -mfloat-abi=hard" -DCMAKE_C_FLAGS:STRING="-march=armv6 -mfpu=vfp -mfloat-abi=hard" ../

Compile (Takes about 24 hours!)

  $ make


  $ sudo make install

Remaining Tasks
  • Get osmosdr, gr-baz, and any other extras to compile.

Sunday, July 22, 2012

Compiling rtl-sdr on the nslu2

Many thanks to embrtlsdr's blog for many helpful hints!

I found that autoreconf -i didn't work in my case (due to m4 errors and associated bug) so rather than updating my autoconf packages I opted to go with cmake - which is working like a champ (After installing libusb from source, and ln -s /usr/local/include/libusb-1.0/libusb.h /usr/local/include/).

# /usr/local/include/libusb-1.0/libusb.h /usr/local/include/
# make
Scanning dependencies of target rtlsdr_shared
[  7%] Building C object src/CMakeFiles/rtlsdr_shared.dir/librtlsdr.c.o
[ 14%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_e4k.c.o
[ 21%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0012.c.o
[ 28%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0013.c.o
[ 35%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc2580.c.o
Linking C shared library
[ 35%] Built target rtlsdr_shared
Scanning dependencies of target rtl_fm
[ 42%] Building C object src/CMakeFiles/rtl_fm.dir/rtl_fm.c.o
Linking C executable rtl_fm
[ 42%] Built target rtl_fm
Scanning dependencies of target rtl_sdr
[ 50%] Building C object src/CMakeFiles/rtl_sdr.dir/rtl_sdr.c.o
Linking C executable rtl_sdr
[ 50%] Built target rtl_sdr
Scanning dependencies of target rtl_tcp
[ 57%] Building C object src/CMakeFiles/rtl_tcp.dir/rtl_tcp.c.o
Linking C executable rtl_tcp
[ 57%] Built target rtl_tcp
Scanning dependencies of target rtl_test
[ 64%] Building C object src/CMakeFiles/rtl_test.dir/rtl_test.c.o
Linking C executable rtl_test
[ 64%] Built target rtl_test
Scanning dependencies of target rtlsdr_static
[ 71%] Building C object src/CMakeFiles/rtlsdr_static.dir/librtlsdr.c.o
[ 78%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_e4k.c.o
[ 85%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_fc0012.c.o
[ 92%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_fc0013.c.o
[100%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_fc2580.c.o
Linking C static library librtlsdr.a
[100%] Built target rtlsdr_static

# make install
Linking C shared library
[ 35%] Built target rtlsdr_shared
Linking C executable rtl_fm
[ 42%] Built target rtl_fm
Linking C executable rtl_sdr
[ 50%] Built target rtl_sdr
Linking C executable rtl_tcp
[ 57%] Built target rtl_tcp
Linking C executable rtl_test
[ 64%] Built target rtl_test
[100%] Built target rtlsdr_static
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/pkgconfig/librtlsdr.pc
-- Installing: /usr/local/include/rtl-sdr.h
-- Installing: /usr/local/include/rtl-sdr_export.h
-- Installing: /usr/local/lib/
-- Installing: /usr/local/lib/
-- Installing: /usr/local/lib/
-- Installing: /usr/local/lib/librtlsdr.a
-- Installing: /usr/local/bin/rtl_sdr
-- Installing: /usr/local/bin/rtl_tcp
-- Installing: /usr/local/bin/rtl_test
-- Installing: /usr/local/bin/rtl_fm

# rtl_test
Found 1 device(s):
  0:  ezcap USB 2.0 DVB-T/DAB/FM dongle

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Elonics E4000 tuner
Supported gain values (18): -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0 43.0 45.0 47.0 49.0
Reading samples in async mode...
lost at least 180 bytes
lost at least 188 bytes
lost at least 48 bytes
lost at least 336 bytes
lost at least 148 bytes
lost at least 148 bytes
lost at least 196 bytes
lost at least 120 bytes
lost at least 148 bytes
lost at least 128 bytes
lost at least 44 bytes
lost at least 12 bytes
lost at least 816 bytes
lost at least 336 bytes
lost at least 364 bytes
lost at least 364 bytes
lost at least 484 bytes
lost at least 80 bytes
lost at least 244 bytes
lost at least 188 bytes
lost at least 156 bytes
lost at least 16 bytes
lost at least 816 bytes
lost at least 184 bytes
lost at least 176 bytes
^CSignal caught, exiting!

OK Results aren't perfect, but it's a great start!

Now time to see if I can stream 2.048Ms/s over Ethernet using nslu2.

Saturday, May 12, 2012

GFSK Crash Course

Z-Wave Is a wireless protocol used to connect devices in the home wirelessly. For example remote lighting, remote outlets, dimmers, and more. It uses a sort of FSK modulation to transfer data between nodes.

I've chosen Z-wave as a starting point in familiarizing myself with GNU Radio, FSK, and Manchester encoding.

Thus far I have been able to capture a signal from my Z-wave transmitter, convert it down to base band, and "hear it". At this point I'm trying to come up with A GNU Radio flow graph that can splice the bits into an ASCII stream.

 GNU Radio flow graph so far... Only using a quadrature demod.
GRC File: link

GNU Radio FFT plot showing a few peaks.

Scope plot, showing the preamble, data, and what may be a post-amble 

Now I just need to figure out what flow graph I need to decode the bits!

Tuesday, April 24, 2012

187f:0202 not realtek!

EzTV ISDB-T: Just got this one in the mail, it's not a realtek/e4k: Bus 002 Device 011: ID 187f:0202 Siano Mobile Silicon Nice

Sunday, April 22, 2012

Saturday, April 21, 2012

New adapter - in hand!

Today I received my first RTL2832u+e4k adapter. I've been testing it and so far I'm pretty impressed. It grabs a 2 Mhz wide slice of spectrum and passes it all to the PC over USB for decoding. I've chosen GNU Radio as my SDR software.

Here's my first GNU Radio app (not counting the tutorials that I also completed today).