Sunday, 24 June 2012

Raspberry Pi Wireless Display Using a Cheap Parrot LCD Photo Frame

One of the first things I've tried with my Raspberry Pi is to get it to use the low cost Parrot DF3120 320x240 picture frame as a wireless display over Bluetooth. These little frames are available on Amazon for under £15!

video

This builds on the sterling work done here https://sites.google.com/site/repurposelinux/df3120 to hack Linux onto the DF3120. When I first saw this post, I bought a few of the frames as they looked like they might come in handy for something.

The basic idea is to set up Bluetooth networking with the Pi, and use SDL VNC viewer to display the X screen on the Parrot. 

Bluetooth Network Setup 

The first thing we need to do is get Bluetooth networking set up between the two devices.

To start off with, on the Pi side, I'm using the standard Debian squeeze image and an Atheros Communications, Inc. AR3011 Bluetooth USB dongle. Install the bluetooth package, and for my atheros dongle, I installed the firmware-atheros package:

apt-get install bluetooth firmware-atheros

On the Pi, you will also need to run bluetooth-agent to allow pairing of the parrot. For testing I just ran this at the command line with no PIN specified. This will allow the Pi to pair with anything that attempts to connect.

bluetooth-agent hci0 

On the Parrot, flash the firmware update using the PFS file and minifs image using the instructions at https://sites.google.com/site/repurposelinux/df3120. Hold down the left and center buttons while powering on to boot into Linux. Once booted, connect the Parrot to a Linux machine and set up the USB networking using 

ifconfig usb0 172.16.61.3 netmask 255.255.255.0 up
telnet 172.16.61.1 

More details on connecting to the Parrot over the USB network are here https://sites.google.com/site/repurposelinux/df3120/connecting-to-the-usb-device

To bring the network up and connect to the Pi over bluetooth, issue these commands on the Parrot:

pand --connect AA:AA:AA:AA:AA:AA
ifconfig bnep0 192.168.4.10

where AA:AA:AA:AA:AA:AA is the BD Address of the Pi. You can find this out by running hciconfig on the pi. 

On the Pi in the terminal where you have bluetooth-agent running, you should see something like:

Authorizing request for /org/bluez/1274/hci0/dev_BB_BB_BB_BB_BB_BB

There should now be a virtual network interface created by bluez on the pi, bnep0. You can give this an IP address on the Pi by issuing: (We will automate this process later)

ifconfig bnep0 192.168.4.1

You should then be able to ping or telnet to the Parrot on 192.168.4.10 from the Pi. To bring Bluetooth networking up automatically on the parrot, I added this to /etc/init.d/rcS, so mine looks like:

#echo "* Starting Bluetooth"
hciattach -s 115200 /dev/ttySAC0 bcm2035 921600 flow 00:00:00:00:00:00 >/dev/null 2>&1
hciconfig hci0 up

bdaddr 84:59:04:04:02:05                                                              
hciconfig hci0 reset                                                                  
                            
#echo "* Starting DUN connection"
#rfcomm bind /dev/rfcomm0 08:00:06:5E:8D:F5 2
#pppd /dev/rfcomm0 noauth defaultroute lcp-echo-interval 10 lcp-echo-failure 12

#echo "* Starting PAN connection"
pand --listen --role NAP
pand --connect 00:02:72:B2:E8:12
sleep 5
ifconfig bnep0 192.168.4.10

A couple of things to note - I'm using static IPs, but you could run dhcp on the Pi and assign IP addresses like that. The other thing is that for some reason on the Parrot, I was getting a different bd address every time I rebooted. To solve this I use the bdaddr command that is in the bluez test suite to set the bd address every time. 

The bdaddr utility is not included in the pre-built image for the parrot, but you can download a copy I built here - bdaddr.tar.gz

To build a copy of bdaddr, I had to rebuild the bluez package in minifs for the Parrot to include the test apps. To get this to work, you need to follow the instructions on building the DF3120 toolchain/rootfs here https://sites.google.com/site/repurposelinux/df3120 using this patch to bring a few package versions up to date where the linked versions are no longer available, and add the dependancies and config option to build the test apps (including bdaddr) in bluez:

diff -rupN minifs.orig/conf/packages/10common_base.sh minifs/conf/packages/10common_base.sh
--- minifs.orig/conf/packages/10common_base.sh 2012-06-24 20:26:02.714490989 +0100
+++ minifs/conf/packages/10common_base.sh 2012-06-24 02:10:36.030728699 +0100
@@ -3,7 +3,7 @@
 ## zlib - http://www.zlib.net/
 #######################################################################
 PACKAGES+=" zlib"
-hset zlib url "http://www.zlib.net/zlib-1.2.6.tar.gz"
+hset zlib url "http://www.zlib.net/zlib-1.2.7.tar.gz"
 configure-zlib() {
  configure ./configure \
diff -rupN minifs.orig/conf/packages/11graphical.sh minifs/conf/packages/11graphical.sh
--- minifs.orig/conf/packages/11graphical.sh 2012-06-24 20:26:02.714490989 +0100
+++ minifs/conf/packages/11graphical.sh 2012-06-24 02:14:55.366933145 +0100
@@ -5,7 +5,7 @@ hset libjpeg url "http://www.ijg.org/fil
 # http://www.libpng.org/pub/png/libpng.html
 PACKAGES+=" libpng"
-hset libpng url "ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.4.8.tar.bz2"
+hset libpng url "ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.4.11.tar.bz2"
 hset libpng depends "zlib"
 hset libpng configscript "libpng-config"
diff -rupN minifs.orig/conf/packages/14bluez.sh minifs/conf/packages/14bluez.sh
--- minifs.orig/conf/packages/14bluez.sh 2012-06-24 20:26:02.714490989 +0100
+++ minifs/conf/packages/14bluez.sh 2012-06-24 12:47:30.981169269 +0100
@@ -15,9 +15,22 @@ deploy-dbus() {
  deploy deploy_binaries
 }
+PACKAGES+=" check"
+hset check url "http://downloads.sourceforge.net/project/check/check/0.9.8/check-0.9.8.tar.gz"
+hset check depends ""
+
+configure-check() {
+        configure-generic
+}
+
+deploy-check() {
+        deploy deploy_binaries
+}
+
+
 PACKAGES+=" bluez"
-hset bluez url "http://www.kernel.org/pub/linux/bluetooth/bluez-4.81.tar.gz"
-hset bluez depends "dbus libiconv libgettext libglib"
+hset bluez url "http://www.kernel.org/pub/linux/bluetooth/bluez-4.101.tar.gz"
+hset bluez depends "check dbus libiconv libgettext libglib"
 configure-bluez() {
  configure-generic \
@@ -43,7 +56,8 @@ configure-bluez() {
  --enable-service \
  --enable-tools \
  --disable-udevrules \
- --disable-usb
+ --disable-usb \
+ --enable-test
 }
 deploy-bluez() {

To automate things on the Pi side, I added the following to /etc/network/interfaces

iface bnep0 inet static
address 192.168.4.1
netmask 255.255.255.0

And to automatically start bluetooth-agent for pairing I added this to the bluetooth startup script. Note that this will allow any device to connect with no PIN, so beware!

--- bluetooth.orig 2012-06-24 21:43:17.024405263 +0100
+++ bluetooth 2012-06-24 20:03:45.376014045 +0100
@@ -25,6 +25,7 @@
 DAEMON=/usr/sbin/bluetoothd
 HCIATTACH=/usr/sbin/hciattach
+BLUETOOTH_AGENT=/usr/bin/bluetooth-agent 
 HID2HCI=/usr/sbin/hid2hci
 HID2HCI_ENABLED=1
@@ -164,6 +165,11 @@
  log_progress_msg "compatibily daemons not started, see bluez-compat package"
  fi
+        sleep 3
+        for i in `hciconfig | grep hci | cut -f1 -d:` ; do
+ $BLUETOOTH_AGENT $i & 
+ done
+
  log_end_msg 0
   ;;
   stop)
@@ -180,6 +186,9 @@
  start-stop-daemon --stop $SSD_OPTIONS
  log_progress_msg "bluetoothd"
  stop_uarts || true
+
+ killall $BLUETOOTH_AGENT > /dev/null 2>&1
+
  log_end_msg 0
   ;;
   restart|force-reload)

VNC Setup

The next step is to get VNC up and running. On the Pi, install a the tightVNC server and viewer:

apt-get install tightvncserver xtightvncviewer 

Then run the server on the Pi - it will ask for a password to connect the first time.

vncserver -geometry 320x240 -depth 8 :1

On the Parrot, run the SDL vnc viewer:

SDLvncviewer 192.168.4.1:1 

Enter the password you specified earlier, and you should now see your desktop displayed on the Parrot. Yay!

From an X session on the pi, you can run 

vncviewer :1 

To open a vnc session where you can control the desktop on the Pi. Enjoy.












34 comments:

  1. Despite having my Pi hooked up to a diminutive monochrome CRT (which looks GREAT) you've convinced me to spend a few quid on a Parrot DF3120 at Amazon... Excellent work!

    ReplyDelete
  2. Great job! I already own two DF3120 picture frames, and I was planning to do something similar with mi Guruplug Server+.

    ReplyDelete
  3. I can't find this display in the states.

    KG

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Awsome job. I've been looking through a few methods of connecting a display. This one beats 'em all. One question... Did you upgrade the Parrots' RAM as the good guys at repurpose_linux suggested?

    ReplyDelete
  6. Hi, Thanks! No - I haven't attempted the memory upgrade as I'm just using the picture frames as remote displays, and not doing anything more demanding on the frame itself.

    ReplyDelete
  7. Great job. Unfortunately it was unsuccessful, there is no bnep0. pand seemingly works, maybe not in reality.

    pand --connect AA:AA:AA:AA:AA:AA
    / # ifconfig bnep0 192.168.4.10
    ifconfig: SIOCSIFADDR: No such device

    Any idea what to do?

    Thank you.
    George Fenyvesi

    ReplyDelete
    Replies
    1. AA:AA:AA... is my Mac adress.

      Delete
    2. Hi George,

      There should me messages in /var/log/syslog on the Pi that will let you know if the Parrot is attempting to connect, and what the problem might be. Do you have any messages in there?

      Delete
  8. I am afraid that the problem is on the PI side. The syslog contains:
    Bluetooth: hci0 ACL packet for unknown connection handle 2

    I am using Wheezy version and was not able to set up Bluetooth correctly. What is the content of /var/lib/bluetooth/AA:AA.../config file?
    My version is:

    name raspberrypi-0
    class 0x520100
    onmode discoverable
    mode discoverable
    discovto 0
    pairable yes

    Thank you for your help.

    George

    ReplyDelete
    Replies
    1. I wanted to not having PINs. But I have:
      syslog:

      No agent available for request type 0
      raspberrypi bluetoothd[1548]: PIN code negative reply: Operation not permitted

      Delete
  9. /var/lib/bluetooth/AA:AA.../config is automatically generated, and I don't have the Pi with me here, but I can look later for you. Do you have bluetooth_agent running? - in another console try running

    bluetooth_agent hci0

    do you see the 'Authorizing request..' message, and and do you get the same error in syslog?

    ReplyDelete
    Replies
    1. Dear Chris,

      I am a bit confused because:
      1. I am not really a Linux guy;
      2. I read that in blueZ v4.x the bluetooth-agent is obsolete (simle-agent is the obscurous new one), so I didn't care with it. Anyway it doesn't work.

      $ bluetooth-agent hci0
      Can't get default adapter
      Rejected send message, 2 matched rules; type="method_call", sender=":1.20" (uid=1000 pid=2245 comm="bluetooth-agent hci0 ") interface="org.bluez.Manager" member="DefaultAdapter" error name="(unset)" requested_reply="0" destination="org.bluez" (uid=0 pid=1544 comm="/usr/sbin/bluetoothd ")

      Delete
    2. The bluetooth packages in wheezy may bedifferent from squeeze, although it could be a permissions issue - are you running bluetooth-agent as root?

      Once I get round to trying out the wheezy beta, I'll get it set up and update this post. In the meantime do you have a particular requirement to run wheezy, or could you use the squeeze image as a basis for your project?

      Delete
    3. Chris,

      the situation remained the same. I am not strictly connected to Wheezy, but this version seems to be better and I made a lot of modifications I should start again. So it would be better to have Wheezy, if it is possible.
      If you would be so kind to copy the content of your /var/lib/bluetooth/AA:AA.../config file, maybe it could help. The setup of blueZ is a misery.

      Thanks for your patience.

      George

      The screen copies:

      On the PI side:
      pi@raspberrypi ~ $ sudo bluetooth-agent sci0 0000
      (I suggested being not neccessary, because pand dooesn't seem to require PIN)

      The status of the adapter:
      pi@raspberrypi ~ $ hciconfig -a
      hci0: Type: BR/EDR Bus: USB
      BD Address: 00:15:83:15:A3:10 ACL MTU: 672:4 SCO MTU: 48:1
      UP RUNNING PSCAN ISCAN
      RX bytes:3656 acl:28 sco:0 events:126 errors:0
      TX bytes:1257 acl:34 sco:0 commands:61 errors:0
      Features: 0xff 0x3e 0x85 0x38 0x18 0x18 0x00 0x00
      Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
      Link policy: RSWITCH HOLD SNIFF
      Link mode: SLAVE ACCEPT
      Name: 'raspberrypi-0'
      Class: 0x520100
      Service Classes: Networking, Object Transfer, Telephony
      Device Class: Computer, Uncategorized
      HCI Version: 2.0 (0x3) Revision: 0xc5c
      LMP Version: 2.0 (0x3) Subversion: 0xc5c
      Manufacturer: Cambridge Silicon Radio (10)

      On the Parrot site:

      / # pand --connect 00:15:83:15:A3:10
      / # ifconfig
      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      UP LOOPBACK RUNNING MTU:16436 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:0
      RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

      usb0 Link encap:Ethernet HWaddr 9A:10:7A:D7:7E:FB
      inet addr:172.16.61.1 Bcast:172.16.61.255 Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:98 errors:0 dropped:0 overruns:0 frame:0
      TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:12251 (11.9 KiB) TX bytes:988 (988.0 B)
      / # ifconfig bnep0 192.168.4.10
      ifconfig: SIOCSIFADDR: No such device

      Delete
    4. __________________
      The situation is even stranger. The Parrot can see the PI, but can't connect.

      / # hcitool scan
      Scanning ...
      00:15:83:15:A3:10 raspberrypi-0
      / # pand --connect 00:15:83:15:A3:10
      / # ifconfig bnep0 192.168.4.10
      ifconfig: SIOCSIFADDR: No such device

      A question:
      My minifs for Parrot is not from the original repurposelinux because it seemed not to work (perhaps it is a .bz2 despite of its .img name), but from http://www.martinhubacek.cz/arm/df3120-linux-picture-frame with enabled CHMOD. What version did you use?

      Thanks.
      George

      Delete
  10. I used the original repurposelinux image, works fine when you use dd to copy it to the card. I also built my own from source with the above patch so I could enable the test utilities in bluez.

    Looking at your syslog, I still think that you issues are that you don't have an agent to pair with the parrot, note that your line should not read

    sudo bluetooth-agent sci0 0000

    but

    sudo bluetooth-agent hci0

    to specify pairing with no pin. As the parrot is sending a pairing request to the Pi, you will need to have an agent running on the pi.

    To test if it's a pairing issue, try

    echo "BB:BB:BB:BB:BB:BB [all]" >> /var/lib/bluetooth/AA\:AA\:AA\:AA\:AA\:AA/trusts

    Where AA:... is the bdaddr of the Pi, and BB:... is the bdaddr of the Parrot. This will temporarily establish a pairing

    Then try to connect, then see what the syslog output is.

    ReplyDelete
    Replies
    1. Chris,

      You are right.

      The correct version is:
      sudo bluetooth-agent hci0, but unfortunately it doesn't work either without a passkey:

      agent [--adapter adapter-path] [--path agent-path] []

      I don't understand that in your description there is no pairing at all. What time is it done in your case? Did you set noPIN on PI? How?

      On the other hand you are right because after the Parrot pand --connect the PI syslog is:
      Jul 12 19:55:09 raspberrypi bluetoothd[1448]: No agent available for request type 0
      Jul 12 19:55:09 raspberrypi bluetoothd[1448]: PIN code negative reply: Operation not permitted

      I tried your idea:
      I wrote the Parrot MAC into the /var/lib/bluetooth/AA\:AA\:AA\:AA\:AA\:AA/trusts, connected from Parrot, the result is the same:
      Jul 12 20:22:43 raspberrypi bluetoothd[1448]: No agent available for request type 0
      Jul 12 20:22:43 raspberrypi bluetoothd[1448]: PIN code negative reply: Operation not permitted

      It is strange, that the line I wrote into ...\trusted disappeared. I used sudo mc + nano.


      What is the content of /var/lib/bluetooth/AA:AA.../config file?

      Thanks.

      George

      Delete
  11. Hi - It would seem that things have changed in wheezy, and I won't be able to give you a definite answer until I've had a chance to install it myself, which I'll try to get onto soon.

    my /var/lib/bluetooth/AA.../config just has

    name raspberrypi-0
    class 0x4a0100

    But these files are automatically generated by bluez, which is why your trusts file gets overwritten

    However, in my /etc/bluetooth/network.conf I have,

    [General]

    # Disable link encryption: default=false
    DisableSecurity=true

    but I'm not sure if that will make any difference.

    ReplyDelete
  12. OK - booting wheezy now, will let you know how I get on :-)

    ReplyDelete
  13. Indeed - there does seem to be some issues with wheezy and USB Bluetooth. I'll look into it and update here if I find a solution...

    ReplyDelete
    Replies
    1. You are great, Chris.

      Thanks.
      George

      Delete
    2. Chris,

      I have a strictly stupid but practically not so silly question. In this VNC setup you can control the Pi from another computer (mouse/keyboard), the Parrot is only a hardcopy of the other VNC session's screen. It would be great if the PI's mouse and keyboard could control directly the Parrot. I know that is doesn't have USB host and so on. Is there any solution when only the screen is connected to the "VCN session" but the control remains at the PI side?

      Delete
    3. I tried on the PI side:
      vncserver -viewonly -geometry 320x240 -depth 8 :3

      Using the IP on USB on the Parrot side it is unable to connect, maybe because of the needed password:
      / # SDLvncviewer 172.16.61.3:3
      02/01/2007 19:27:14 ConnectToTcpAddr: connect
      02/01/2007 19:27:14 Unable to connect to VNC server

      If the Xserver wouldn't ask for password, then it might work.
      I'll try it.

      Delete
  14. Should there be any other files than the IMG file on the SD card? The firmware upgrade appeared to work alright but it doesn't appear to apply the USB CDC to my system when booted and connected (not in 'ifconfig'). Anything you could suggest?

    Thanks

    ReplyDelete
  15. Hi.

    Any progress on Gyorgy's problem - I'm in a similar situation?

    I seem to be stuck on a response from the Parrot:

    "root@raspberrypi:/home/pi# bluetooth-agent hci0 &
    [1] 3533
    root@raspberrypi:/home/pi# ifconfig bnep0 192.168.4.1
    SIOCSIFADDR: No such device
    bnep0: ERROR while getting interface flags: No such device"

    Then when I do on the Parrot:

    "pand --connect 00:10:60:D2:C2:C8"

    I get the following response on the Pi:

    "Pincode request for device /org/bluez/2134/hci0/dev_40_38_04_00_14_03"

    BTW - I find I need to do all this stuff as root - "sudo su".
    Also I found the line: bluetooth-agent hci0 needs an & so it runs in the BG.

    I'd be grateful for some help here, please!

    Jim

    ReplyDelete
    Replies
    1. Hi - Yes, I have made some progress, but not quite there yet. The newer versions of Bluetooth that are on the more recent RasPi distributions will not allow bluetooth connections without a PIN, and the agent used to supply the PIN on the Parrot, and acknowledge the PIN on the Pi use D-Bus.

      I have built an image for the Parrot that includes D-Bus and the agent to supply a PIN, and have got it to successfully pair with the Pi, I just need to get the networking up and scripted and package it up, then I'll update the post here.

      I'll try to get some time on it this week if I can!

      Cheers,

      Chris

      Delete
    2. Hi Chris,
      what agent did you include in the Parrot to submit the PIN for the pairing with the RPi?

      I do understand that 'pand' do not allow the transmission of a PIN, right?

      Delete
  16. Thanks for the reply, Chris.

    I know nothing about Bluetooth, but what's the issue with PINs - can't an arbitrary one be issued, like an IP address?

    Incidentally the distro I'm using is Rasbian.

    Jim

    ReplyDelete
  17. Further to the above:

    I find that if I do a hcitool scan with the Pi and the Parrot is in its native picture frame mode, I get a response:

    Scanning ...
    00:12:1C:CA:78:17 Parrot PHOTO

    But I don't get a response with the Parrot running Linux.

    This suggests to me that Bluetooth is working OK on the Pi, but not on the Parrot+Linux.

    Jim

    ReplyDelete
  18. Hi Chris did you ever find the answer?
    Chris E.

    ReplyDelete
  19. Hi got pairing with passkey working, but it is still not perfect though...

    I more or less used this GitHub repository to get dbus on the parrot working: https://github.com/tuopppi/minifs-df3120

    On the RPi side, I added the passkey to /var/lib/bluetooth/-BT-MAC-/pincodes (this file takes on pin per line i.e.: AA:BB:CC:DD:EE:FF 1234). I listen for connections with "pand --listen --role GN". After this I need to restart the bluetooth service (I don't know why...)
    [I although added the Parrot to the trusted devices using "bt-device" - I think this is in the bluez-tools package... this is obviously only once necessary]

    On the Parrot I started the agent from the git repo: "agent 1234 &" and connect with "pand --connect MAC".

    Both sides list the connection with "pand -l" and on the RPi side everything seems to be okay, bnep0 created and configureable. But on the parrot side something is still amiss: The bnep0 interfaces is created but I cannot bring it up, when I assign an IP address I get "SIOCSIFFLAGS: Cannot assign requested address". ifconfig shows the assigned address but the interface is still down.

    Note: I although followed the "Connection refused(111)" solution from this post, but I am not sure if it is really necessary, maybe the bluetooth service restart was sufficient:
    https://bbs.archlinux.org/viewtopic.php?id=145001

    ReplyDelete
    Replies
    1. Would it be possible for you to put your built image somewhere I could download it?

      I'm having no luck building from source...

      Thanks,
      Steve

      Delete