Showing posts with label USB. Show all posts
Showing posts with label USB. Show all posts

Sunday, August 26, 2012

Now with added Beagle Bone

After the last couple of days my workshop in London on the 8th of October, at the Hoxton Hotel, now has added BeagleBone and Raspberry Pi.

Blinking the BeagleBone's heartbeat LED using the iPhone

We're going top go hands on in a small class setting, deep diving into the iOS internal sensors and how to connect your iPhone or iPad to external hardware. Everyone will get their hands dirty, and everyone will come away knowing more about both the iPhone hardware and how to work with external accessories. So come along and get your hands dirty playing with iPhone, Arduino and now the BeagleBone and Raspberry Pi and get 10% off the Early Bird ticket price today only with code BEAGLE10.


Register
Monday 8th October 2012
Hoxton Hotel, London
Early Bird Price: £499 (until 1st Sept.)
Normal Price: £699
Save 10% with code BEAGLE10

Saturday, August 25, 2012

Blinking the BeagleBone's heartbeat LED from the iPhone

Following up on the work I was doing last night connecting the iPhone to the BeagleBone using PeerTalk. I've now reached the blinking LED stage, which is more-or-less the "Hello World" stage of any bit of hardware hack.

Blinking the BeagleBone's heartbeat LED using the iPhone

I've been having a great back-and-forth on Twitter with David House while hacking away with this project, who is working away as I type to get this working on the Raspberry Pi. It's been a lot of fun.

If you want to replicate this on the BeagleBone you should first download and build the PeerTalk library, and then build and deploy the iOS and OSX example applications and get that up and running.

Then connect up and boot your BeagleBone. You'll need to power the board using a mains adapter as when you're compiling things it's possible you'll be drawing enough amperage that you're computer will turn off the USB port to protect itself, and as a result power down your BeagleBone. I had this happen to me a couple of times before I finally dug a mains adapter out of my office drawer. However since you're powering the board from the mains you'll also have to connect an Ethernet cable so that you can ssh root@beaglebone.local and log into the board over the network.

1. Go ahead and login to your BeagleBone as root.

2. Download, build and install libusb. Version 1.0.9 builds, links and installs okay.

3. Download, build and install cmake, which you'll need to build usbmuxd later. You'll need to grab the latest Git nightly checkout as older release versions don't build, having problems with the stock libbz2 compression on the BeagleBone.

4. We also need libplist, however this is available as part of the package management system on Ångström Linux, so all you need to do to install this is type opkg install libplist-dev at the prompt.


5. Download, build and install usbmuxd. Version 1.0.8 builds, links and installs okay, although you may beed to use ccmake and configure by hand, rather than using cmake, as it can't seem to find the libusb include files that got installed into /usr/local.


6. Create a usbmux user

   groupadd -r usbmux -g 114
   useradd -r -g usbmux -d / -s /sbin/nologin -c "usbmux user" -u 114 usbmux


7. As the BeagleBoard doesn't have syslog turned on by default, and you'll need it for debugging, turn on syslogd from the relevant script in /etc/init.d.


8. Run up the usbmux deamon, by typing usbmuxd -v -v at the prompt.


9. Plug your iPhone into the (host side) USB on your BeagleBoard, you should see some debug scrolling by in /var/log/messages.


10. Download David House's peertalk-python and its dependances.


11. On your iPhone start the PeerTalk client for iOS.


12. Start the python client on the BeagleBone by typing python ./peertalk.py at the prompt.


Type in a message at the prompt, and you should see something like this...


Bi-directional communication between the iPhone and the BeagleBone via USB
From there it's pretty trivial to replicate my "Hello World" example, just by hacking around with David's code and toggling the heartbeat LED when the BeagleBone receives any messages.

    def run(self):
        framestructure = struct.Struct("! I I I I")
        ledOn ='echo 1 > /sys/class/leds/beaglebone::usr0/brightness'
        ledOff ='echo 0 > /sys/class/leds/beaglebone::usr0/brightness'
        i = 0
        while self._running:
            try:
                msg = self._psock.recv(16)
                if len(msg) > 0:
                    frame = framestructure.unpack(msg)
                    size = frame[3]
                    msgdata = self._psock.recv(size)
                    print "Received: %s" % msgdata
                    if i == 0:
                       os.system(ledOn)
                       i = 1
                    else:
                       os.system(ledOff)
                       i = 0
            except:
                pass

Which gets you to this point...

Toggling the BeagleBone heartbeat LED with my iPhone over USB.
Which is pretty much where I've reached right now. Next steps is a proper application on the iOS end of things with more generic control of the BeagleBone's header pins, and a more flexible Python backend on the BeagleBone itself...

Update: David House has managed to get everything up and working on the Raspberry Pi. The only changes from the above is that you should grab libplist using apt-get rather than opkg, and since you won't be logged in as root you should remember to sudo usbmuxd -v -v when you start the USB daemon. Apart from that, you should be good to go...

David House (@davidahouse)
25/08/2012 20:22
Video of iPhone controlling LED on Raspberry Pi.


Controlling a LED connected to a GPIO pin on the Raspberry Pi with an iPhone

Update: Come along to my workshop in London on the 8th of October and get your hands dirty playing with iPhone, Arduino and now the BeagleBone and Raspberry Pi. Get 10% off the Early Bird ticket price today only with code BEAGLE10.

Register
Monday 8th October 2012
Hoxton Hotel, London
Early Bird Price: £499 (until 1st Sept.)
Normal Price: £699
Save 10% with code BEAGLE10

Update: David House has just updated his Github repository with a better description of what he did to get the iPhone to control the Raspberry Pi's GPIO pins.
David House (@davidahouse)
26/08/2012 13:40
@aallan I just updated my github repo with a better description with attributions. Had a blast working with you...


Controlling a LED connected to a GPIO pin on the Raspberry Pi with an iPhone

PeerTalk and the BeagleBone

Earlier today I came across an excellent bit of wizardry by Rasmus Andersson called PeerTalk. It's a Objective-C library allowing you to communicate between your iPhone and your Mac over the USB dock cable using TCP sockets.

PeerTalk Demo

My immediate thought was that if this really only depended on having USB host mode capability at the far end, the same mechanism should be able to be used to talk to something like the BeagleBone, or the Raspberry Pi, not just your Mac. This would allow you connect your phone directly to the micro controller board and to drive hardware directly, a lot like the Redpark cable but bypassing Apple's External Accessory framework. 

Yup, this is going to be useful...
So I started digging around inside the source code to see if it depended on anything that was going to be specific to OS X, it became apparent that PeerTalk was mostly some really nice socket code sitting on top of the USB Multiplex Daemon (usbmuxd). This bit of software is in charge of talking to your iPhone over USB and coordinating access to its services by other applications. Effectively this is what iTunes and Xcode use to talk to your phone when you plug it into your Mac's USB port.

So any device that wants to talk to the iPhone using this method needs usbmuxd. Fortunately  for me there are a number of people that have worked oout how to talk to the iPhone from Linux, and there is a working usbmuxd for Linux.

The BeagleBone
As well as a few other dependences which aren't present on the stock Ångström Linux distribution on my BeagleBone, or even packages via opkg, building usbmuxd on my BeagleBone requires libusb and cmake. So before building usbmuxd, I had to build cmake, which meant resolving some problems with the stock compression libraries that shipped with Ångström.

However several hours later. after enough waiting around for software to build to convince me that before doing any serious development on the BeagleBone I really had to build an ARMv7 toolchain on my Mac to cross-compile things instead of building them directly on the board....

 The iPhone talking directly to my BeagleBone  using PeerTalk
...I managed to get a simple "hello" from my iPhone to the BeagleBone and then via screen to my Mac using port forwarding and that old stand by, telnet.

While I was hacking away on getting this working, I wasn't alone. David House was looking down some of the same back alleyways to get PeerTalk talking to his Raspberry Pi, and we batted the problem back and forth on Twitter while waiting for code to compile well into the night...

The next step is to put together a client on the BeagleBone sitting on top of usbmuxd that'll talk natively to the PeerTalk on iOS. Since I've got the source code of both ends, this isn't going to be too hard. I'll probably put something together in Python.
More soon...

Update: Following on from this I pushed forward till I managed to blink the BeagleBone's heartbeat LED from the iPhone which is, more-or-less, the "Hello World" stage of any hardware hack...

Thursday, September 04, 2008

The 3 HSDPA Dongle Review

I've just dropped the HSDPA dongle I've had on loan into a prepaid envelope to return the hardware to 3, so I thought I'd better write up my experiences with it now while it's still on my mind...

After some initial teething troubles I got the dongle working under OSX on my Intel Macbook, and gave it a fairly thorough work out over the course of the last couple of months.

As can be seen from their rollout map, 3 doesn't yet have any HSDPA coverage down here in the South West. Locally then, I'm suffering under the same sorts of problems I had with 3's Skypephone. The places where there isn't any 3 coverage is rather long; my house, my office, the cities and towns I visit regularly. The list of places where there is coverage is considerably shorter, and that's bad. What this also implies is that the problems seen with HSDPA when on the fringes of coverage are perhaps more significant than you might think.

However, whether a wireless modem works when you're in your own living room isn't, perhaps, as relevant as how well it works when it isn't. I used it extensively when I was out in Italy for the Trieste meeting roaming onto the 3 network there, and if I hadn't had the dongle on loan, I'd have only have been paying UK rates to do so...

I've also made use of it on various trips up and down the country, while stuck in hotel rooms, on trains and in coffee shops. I found it to be a good backup if wireless wasn't available. That said, performance was noticeably more sluggish than wireless, and if wireless access was available I generally still ended up paying for that rather than using the dongle.

Because somewhat unfortunately I found the process of using the dongle klunky and inconvenient. Coverage wasn't always there, and when it was there it wasn't there automatically. If I wanted to make use of it I had to dig the dongle out of my bag, plug it in, wait for it to find the 3 network, then wait for it to connect, wait for authorization. A lot of waiting...

I think I would have found the process a lot less inconvenient if HSPDA was built-in to my laptop, and like WiFi, automatically connected to a network when one was present. I'd like my data connection to seamlessly switching between wired, Wi-Fi and HSDPA when needed, without having to do do any fiddling around. Which I why I found the Dell and Vodafone announcement earlier today so interesting. You have to wonder how well integrated Vodafone's HSDPA card and Dell's mini 9 are going to be?

Three blew the roof off the mobile data market late last year when then started offering flat rate mobile broadband. Except of course it's not unlimited, their biggest plan has a data allowance of 15GB a month for £30. Which by mobile network standards is pretty good going. But despite the fact I wasn't paying for the bandwidth I found myself obsessively checking how much of the data allowance I was using, and the days where that's acceptable to me are long gone...

So the question I'm asking myself is "what's it for"? With a 15GB per month allowance this would never replace my home ADSL connection, I'd blow through that within the first week. So this is strictly for when you're out of the house, and the office, traveling. Perhaps this isn't normal, but most of the traveling I do is to the US. I don't spend much time in Europe, and less time than that traveling around the UK. Which means that I'd be paying £3 per MB when roaming, which clearly is just totally unacceptable.

So perhaps what I'm really saying here is that for me, this isn't the solution. Even when in Europe, and paying 10 pence per MB rather than £3 per MB, it isn't really good enough. However if you do most of your traveling in the UK, or within the coverage of a 3 sister network, perhaps you should take a look. It could be well worth your while.

As always then, your mileage may vary...