Monday 10 June 2013

Controlling GPIO with WebIOPi

Using the http://code.google.com/p/webiopi/ software.

Follow the installation instructions (http://code.google.com/p/webiopi/wiki/INSTALL). This can take a few minutes depending on internet speed and SDCard speed (lots of Python and SSL libs downloaded IIRC).

The instruction page is easy to follow, but to replicate the instructions here:

$ wget http://webiopi.googlecode.com/files/WebIOPi-0.6.0.tar.gz
$ tar xvzf WebIOPi-0.6.0.tar.gz
$ cd WebIOPi-0.6.0
$ sudo ./setup.sh

Once installed, run the sudo webiopi command as follows:

pi@raspberrypi ~/WebIOPi-0.6.0 $ sudo webiopi
2013-06-10 21:33:45 - WebIOPi - INFO - Starting WebIOPi/0.6.0/Python3.2
2013-06-10 21:33:46 - WebIOPi - INFO - GPIO - Native mapped to REST API /GPIO
2013-06-10 21:33:46 - WebIOPi - WARNING - Access unprotected
2013-06-10 21:33:46 - WebIOPi - INFO - HTTP Server binded on http://192.168.1.70:8000/
2013-06-10 21:33:46 - WebIOPi - INFO - CoAP Server binded on coap://224.0.1.123:5683/ (MULTICAST)
2013-06-10 21:33:46 - WebIOPi - INFO - CoAP Server binded on coap://192.168.1.70:5683/

Now you can log in to the web app: http://raspberrypi:8000/app/gpio-header. This page looks like:

Using this site for reference (https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/), connect

GND (Pin 6) -> LED -> 330Ω resistor -> GPIO-17 (Pin 11)

I have connected this up rather flimsily by jabbing the resistor and LED into a ribbon cable.

And here it is in use. Look for the underwhelming LED in centre screen!

(Video roated using the nifty YouTube editing capabilities - http://www.youtube.com/editor).

Saturday 5 January 2013

Component Odds and Sods

PPN13LB10A Brush Motor

Brush motor taken from a CDROM drive.

Specifications

I think my motor must be old/obsolete, because I can't find the exact spec sheet.

Model Operating Voltage
[V]
Rated Voltage
[V]
No Load Speed
[min-1]
No Load Current
[mA]
Rated Load
[gf・cm] [mN・m]
PPN13PB10C 2 to 9 7.4 7014 29 7.5 0.74
PPN13PB11C 2 to 9 7.4 9125 34 7.5 0.74
PPN13PB12C 2 to 9 5.0 7084 34 5.0 0.49

Model Rated Load Speed
[min-1]
Rated Load Current
[mA]
Starting Torque Starting Current
[mA]
Shaft Length a [mm]
[gf・cm] [mN・m]
PPN13PB10C 5677 108 39.6 3.9 442 11.0
PPN13PB11C 7473 137 41.7 4.1 601 11.0
PPN13PB12C 6117 114 36.6 3.6 618 11.0

Thursday 3 January 2013

Syntax Highlighting in Blogger

Because Blogger does not seem to allow you to serve your own separate JS files, I've cloned the Git repo of alexgorbatchev/SyntaxHighlighter and use Github's capability to serve raw files.

E.g., this block of code is at the bottom of my Blogger template.

<!-- GRIMBO JS -->
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js'></script>
<script src='https://raw.github.com/gitgrimbo/SyntaxHighlighter/master/build/output/scripts/shCore.js' type='text/javascript'>
</script>
<script src='https://raw.github.com/gitgrimbo/SyntaxHighlighter/master/build/output/scripts/shLegacy.js' type='text/javascript'>
</script>
<script src='https://raw.github.com/gitgrimbo/SyntaxHighlighter/master/build/output/scripts/shBrushJScript.js' type='text/javascript'></script>
<script src='https://raw.github.com/gitgrimbo/SyntaxHighlighter/master/build/output/scripts/shBrushPlain.js' type='text/javascript'></script>
<script src='https://raw.github.com/gitgrimbo/SyntaxHighlighter/master/build/output/scripts/shBrushXml.js' type='text/javascript'></script>
<script type='text/javascript'>SyntaxHighlighter.all();</script>
<!-- GRIMBO JS -->

It works fairly well, apart from the delays caused by the number of files that Blogger downloads by default (76 requests, 449KB transferred, 15.34s total time, 10.28s onload, 8.89s DOMContentLoaded, from one empty-cache test).

NOTE: Github seems to respond to the script requests over http with "301 Moved Permanently", redirecting to the https protocol; thus adding a HTTP 301 per request and slowing the page load. So I use https in the first place. (Correct as of 04/01/2012)

Useful Links

Monday 27 August 2012

LCD, BBC and JSON

Building on the previous LCD example, I tried to connect to the BBC's JSON API for schedule information, and display some of that data.


The code can be found here - https://github.com/gitgrimbo/raspi-fun/tree/master/c/lcd-bbc-json.

I used Jansson for the JSON parsing, and libcurl for the downloading.

Brain dump of trying to install Jansson [JSON library for c]

https://github.com/akheron/jansson

Instructions are:

$ ./configure
$ make
$ make install

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

This did not work, so I tried the other suggestion, to run "autoreconf -i":

pi@raspberrypi /mnt/nas-backup/apps/raspi/jansson $ sudo autoreconf -i
configure.ac:11: error: possibly undefined macro: AC_PROG_LIBTOOL
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1

Error.

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

No joy, Googling found this:
    http://forum.xbmc.org/showthread.php?tid=63780

"hi try apt-get install libtool an run ./bootstrap ./configure again."

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

So try installing libtool:

pi@raspberrypi /mnt/nas-backup/apps/raspi/jansson $ sudo apt-get install libtool
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libltdl-dev libltdl7
Suggested packages:
  libtool-doc gfortran fortran95-compiler gcj
The following NEW packages will be installed:
  libltdl-dev libltdl7 libtool
0 upgraded, 3 newly installed, 0 to remove and 17 not upgraded.
Need to get 1,170 kB of archives.
After this operation, 2,756 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libltdl7 armhf 2.4.2-1.1 [349 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libltdl-dev armhf 2.4.2-1.1 [203 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libtool armhf 2.4.2-1.1 [618 kB]
Fetched 1,170 kB in 6s (187 kB/s)
Selecting previously unselected package libltdl7:armhf.
(Reading database ... 57093 files and directories currently installed.)
Unpacking libltdl7:armhf (from .../libltdl7_2.4.2-1.1_armhf.deb) ...
Selecting previously unselected package libltdl-dev:armhf.
Unpacking libltdl-dev:armhf (from .../libltdl-dev_2.4.2-1.1_armhf.deb) ...
Selecting previously unselected package libtool.
Unpacking libtool (from .../libtool_2.4.2-1.1_armhf.deb) ...
Processing triggers for man-db ...
Setting up libltdl7:armhf (2.4.2-1.1) ...
Setting up libltdl-dev:armhf (2.4.2-1.1) ...
Setting up libtool (2.4.2-1.1) ...

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

And try "autoreconf -i" again:

pi@raspberrypi /mnt/nas-backup/apps/raspi/jansson $ sudo autoreconf -i
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and
libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
configure.ac:11: installing `./config.guess'
configure.ac:11: installing `./config.sub'
configure.ac:4: installing `./install-sh'
configure.ac:4: installing `./missing'
src/Makefile.am: installing `./depcomp'

pi@raspberrypi /mnt/nas-backup/apps/raspi/jansson $ ll
total 17408
drwxr-xr-x 1 root root      0 Aug 26 20:45 .
drwxr-xr-x 1 root root      0 Aug 26 20:23 ..
-rwxr-xr-x 1 root root 343810 Aug 26 20:43 aclocal.m4
drwxr-xr-x 1 root root      0 Aug 26 20:44 autom4te.cache
-rwxr-xr-x 1 root root  11735 Aug 11 10:45 CHANGES
-rwxr-xr-x 1 root root  44826 Aug 26 20:45 config.guess
-rwxr-xr-x 1 root root   2397 Aug 26 20:45 config.h.in
-rwxr-xr-x 1 root root  35543 Aug 26 20:45 config.sub
-rwxr-xr-x 1 root root 415106 Aug 26 20:45 configure
-rwxr-xr-x 1 root root   1246 Aug 11 10:45 configure.ac
-rwxr-xr-x 1 root root  20899 Aug 26 20:45 depcomp
drwxr-xr-x 1 root root      0 Aug 26 20:45 doc
-rwxr-xr-x 1 root root    253 Aug 11 10:45 .gitignore
-rwxr-xr-x 1 root root  13998 Aug 26 20:45 install-sh
-rwxr-xr-x 1 root root    244 Aug 11 10:45 jansson.pc.in
-rwxr-xr-x 1 root root   1081 Aug 11 10:45 LICENSE
-rwxr-xr-x 1 root root 283670 Aug 26 20:44 ltmain.sh
-rwxr-xr-x 1 root root    273 Aug 11 10:45 Makefile.am
-rwxr-xr-x 1 root root  26456 Aug 26 20:45 Makefile.in
-rwxr-xr-x 1 root root  10346 Aug 26 20:45 missing
-rwxr-xr-x 1 root root   1322 Aug 11 10:45 README.rst
drwxr-xr-x 1 root root      0 Aug 26 20:45 src
drwxr-xr-x 1 root root      0 Aug 26 20:45 test
drwxr-xr-x 1 root root      0 Aug 26 20:22 win32

Worked!

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

Compiling the Jansson example:
    http://www.digip.org/jansson/doc/2.3/tutorial.html
    http://www.digip.org/jansson/doc/2.3/_downloads/github_commits.c

Requires curl/curl.h!

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

So try and install curl dev tools.

pi@raspberrypi ~ $ sudo apt-get install libcurl4-gnutls-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  comerr-dev krb5-multidev libcomerr2 libcurl3-gnutls libgcrypt11-dev libgnutls-dev libgnutls-openssl27 libgnutlsxx27 libgpg-error-dev libgssapi-krb5-2 libgssrpc4
  libidn11-dev libk5crypto3 libkadm5clnt-mit8 libkadm5srv-mit8 libkdb5-6 libkrb5-3 libkrb5-dev libkrb5support0 libldap-2.4-2 libldap2-dev libp11-kit-dev librtmp-dev
  libssh2-1 libssh2-1-dev libtasn1-3-dev
Suggested packages:
  doc-base krb5-doc libgcrypt11-doc gnutls-doc krb5-user
The following NEW packages will be installed:
  comerr-dev krb5-multidev libcurl3-gnutls libcurl4-gnutls-dev libgcrypt11-dev libgnutls-dev libgnutls-openssl27 libgnutlsxx27 libgpg-error-dev libgssrpc4 libidn11-dev
  libkadm5clnt-mit8 libkadm5srv-mit8 libkdb5-6 libkrb5-dev libldap2-dev libp11-kit-dev librtmp-dev libssh2-1-dev libtasn1-3-dev
The following packages will be upgraded:
  libcomerr2 libgssapi-krb5-2 libk5crypto3 libkrb5-3 libkrb5support0 libldap-2.4-2 libssh2-1
7 upgraded, 20 newly installed, 0 to remove and 100 not upgraded.
Need to get 2,375 kB/6,657 kB of archives.
After this operation, 11.8 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y

[installed]

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

Proof:

pi@raspberrypi ~ $ sudo find / -name curl.h
/usr/include/curl/curl.h

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

No idea where the headers and libraries live. This command was the only way I could get it to work.
Specifying the full path to the jansson.h (-I) and libjansson.so (-L) files.

I found this site quite useful:
    http://www.rapidtables.com/code/linux/gcc.htm

pi@raspberrypi /mnt/nas-backup/apps/raspi/jansson $ sudo gcc -o github_commits github_commits.c -lcurl -I/mnt/nas-backup/apps/raspi/jansson/src -L/mnt/nas-backup/apps/raspi/jansson/src/.libs -ljansson

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

Again, running was a pain as I was getting this:

pi@raspberrypi /mnt/nas-backup/apps/raspi/jansson $ ./github_commits https://github.com/akheron/jansson.git
./github_commits: error while loading shared libraries: libjansson.so.4: cannot open shared object file: No such file or directory

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

So I had to revert to a hack documented here:

http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

pi@raspberrypi /mnt/nas-backup/apps/raspi/jansson $ LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH:/mnt/nas-backup/apps/raspi/jansson/src/.libs/ ./github_commits akheron jansson
0dac319b CHANGES entry for #88
0b871a11 Merge branch '2.3'
8176527f fix check-exports test on ppc64
ec7bb71d Add an initial CHANGES entry for v2.4
b6a1d8cf Add json_boolean() macro
52924288 Merge branch '2.3'
7892ecce Fix a small error in tutorial
a501a396 Document the JSON_ESCAPE_SLASH encoding flag
37bc3bbf Tweak slash escaping
2d46ea06 Merge branch 'fix-slash' of git://github.com/jrbasso/jansson
b217cd66 Created flag to dump escaping slash
a0c262d0 Escaping the slash when dump
6ce273e2 Merge branch '2.3'
f62b1f5d Bugfix: must cast void* to do pointer math
2b87fdcb Bugfix: Changed all use of ssize_t to size_t.
c0139681 Update the documentation to mention Visual Studio 2010 support
9d6f9511 Merge pull request #74 from rogerz/contrib
a79f64e1 Fix build warnings under MinGW
7ca783c3 Add vs2010 solution and project
ff0c05b8 Support building on Windows
4601bf71 Merge branch '2.3'
c7f86abf fix slight typo in json_pack apiref example
f309e303 Merge branch '2.3'
233574e8 fix slight typo in json_pack apiref example
4a6939ef Merge branch '2.3'
42bc7a3c Check for missing args and envvars in run-tests.sh
abdb8d99 Merge branch '2.3'
ff6e6ee2 jansson 2.3.1
8b2bfd55 Merge branch '2.3'
e46b912f Fix tutorial to use Github API v3

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

Then I actually did what the instructions said!

http://www.digip.org/jansson/doc/dev/gettingstarted.html

That is, I ran the following commands. All as sudo so that my Pi can write to my NAS share.

./configure
make
make check
make install

Did a check for the library, and found it:

pi@raspberrypi ~ $ sudo find / -name libjansson.so
/mnt/nas-backup/apps/raspi/jansson/src/.libs/libjansson.so
/usr/local/lib/libjansson.so

But still didn't work. Apparently I need to do more.

This SO link mentions "/etc/ld.so.conf", so let's have a look:

http://stackoverflow.com/questions/4743233/is-usr-local-lib-searched-for-shared-libraries

pi@raspberrypi ~ $ cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf

Ok, one include. Let's follow that up:

pi@raspberrypi ~ $ ll /etc/ld.so.conf.d
total 20
drwxr-xr-x  2 root root 4096 Jul 15 20:06 .
drwxr-xr-x 88 root root 4096 Aug 27 17:58 ..
-rw-r--r--  1 root root   12 Jul 15 18:12 00-vmcs.conf
-rw-r--r--  1 root root   74 Jun 10 06:07 arm-linux-gnueabihf.conf
-rw-r--r--  1 root root   44 Jun 10 01:36 libc.conf

And again:

pi@raspberrypi ~ $ cat /etc/ld.so.conf.d/libc.conf
# libc default configuration
/usr/local/lib

Ok, so looks like "libjansson.so" has been copied to the right place. Why isn't it working?

More Googling, and now let's try reloading (?) the libraries:

pi@raspberrypi ~ $ ldconfig
ldconfig: Can't create temporary cache file /etc/ld.so.cache~: Permission denied

Nope, try sudo:

pi@raspberrypi ~ $ sudo ldconfig

And...

pi@raspberrypi /mnt/nas-backup/apps/raspi/raspi-fun/c/lcd-bbc-json/grimbo $ sudo ./bbctests
grimbo_url_url_to_buffer(http://www.bbc.co.uk/tv/programmes/genres/factual/scienceandnature/schedules/upcoming.json)
Using temp file /tmp/grimbo_url_R6v1wk
File descriptor 3
grimbo_url_url_to_file_descriptor(http://www.bbc.co.uk/tv/programmes/genres/factual/scienceandnature/schedules/upcoming.json, 7704584)
grimbo_url_wget(http://www.bbc.co.uk/tv/programmes/genres/factual/scienceandnature/schedules/upcoming.json)
cmd=wget -qO- http://www.bbc.co.uk/tv/programmes/genres/factual/scienceandnature/schedules/upcoming.json
grimbo_url_copy(7704952, 7704584)
read 10239 bytes
read 10239 bytes
read 10239 bytes
read 8768 bytes
written 39485 bytes
written=39485
status=0
Child exit code: 0
buffer=7704952
page=1.000000
total=66.000000
offset=0.000000

Works!

Saturday 25 August 2012

Hacking a GPIO ribbon cable so it fits in an Adafruit case

Short story - I bought one of these cases, but the GPIO ribbon cable I had was too tall to fit. So I had to break off the top piece by hitting it with a hammer and a screwdriver.



Similar cable, plus the piece that comes off when hit with a hammer.


Cable now fits!


Cable working!