Monthly Archives: December 2011

Detecting motion: DLP-TILT 2-axis accelerometer

Using an accelerometer to assess musculoskeletal stresses

Accelerometers are helpful for characterising device usage and detecting the mode of use. Most of these devices have an internal accelerometer, but it is convenient for our purposes to use an external device (requires less programming and does not require a jailbroken device).

Setup

In order to use this device, you must first set up the serial port with a line like the following:

stty -F /dev/ttyUSB0 raw ispeed 38400 ospeed 38400 cs8 -ignpar -cstopb -echo

Code

The code probably won’t tell you all that much, but here’s one way to make your life much easier: assuming you’re running this on Linux, set your device ID as /dev/dlptilt, then change the line ‘/dev/ttyUSB0’ to read ‘/dev/dlptilt’ in the code before compiling.

#include
#include
#include
#include
#include
#include
#include
#include 

#define BAUDRATE B38400
#define MODEMDEVICE "/dev/ttyS1"
#define _POSIX_SOURCE 1         //POSIX compliant source
#define FALSE 0
#define TRUE 1
#define DEBUG 0

volatile int STOP=FALSE;

void signal_handler_IO (int status);    //definition of signal handler
int wait_flag=TRUE;                     //TRUE while no signal received
char devicename[80];
long Baud_Rate = 38400;         // default Baud Rate (110 through 38400)
long BAUD;                      // derived baud rate from command line
long DATABITS;
long STOPBITS;
long PARITYON;
long PARITY;
int Data_Bits = 8;              // Number of data bits
int Stop_Bits = 1;              // Number of stop bits
int Parity = 0;                 // Parity as follows:
                  // 00 = NONE, 01 = Odd, 02 = Even, 03 = Mark, 04 = Space
int Format = 4;
FILE *input;
FILE *output;
int status;

main(int Parm_Count, char *Parms[])
{

   int fd, tty, c, res, i, error;
   char In1, Key;
   struct termios oldtio, newtio;
   struct termios oldkey, newkey;
   struct sigaction saio;
   char buf[255];
   char message[90];

   // set device name here
   strcpy(devicename,"/dev/ttyUSB0"); 

   newkey.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
   newkey.c_iflag = IGNPAR;
   newkey.c_oflag = 0;
   newkey.c_lflag = 0;
   newkey.c_cc[VMIN]=1;
   newkey.c_cc[VTIME]=0;
   BAUD=38400;
   DATABITS=CS8;
   STOPBITS=CSTOPB;
   PARITYON=0;
   PARITY=0;
   fd = open(devicename, O_RDWR | O_NOCTTY | O_NONBLOCK);
   if (fd < 0)
   {
   	perror(devicename);
   	exit(-1);
   }

   saio.sa_handler = signal_handler_IO;
   sigemptyset(&saio.sa_mask);
   saio.sa_flags = 0;
   saio.sa_restorer = NULL;
   sigaction(SIGIO,&saio,NULL);

   fcntl(fd, F_SETOWN, getpid());
   fcntl(fd, F_SETFL, FASYNC);

   tcgetattr(fd,&oldtio);
   newtio.c_cflag = BAUD | CRTSCTS | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD;
   newtio.c_iflag = IGNPAR;
   newtio.c_oflag = 0;
   newtio.c_lflag = 0;
   newtio.c_cc[VMIN]=1;
   newtio.c_cc[VTIME]=0;
   tcflush(fd, TCIFLUSH);
   tcsetattr(fd,TCSANOW,&newtio);
   write(fd,"T",1);
   while (STOP==FALSE) {
       status=1;
       if (status==1) // so redundant...
		{
	if(DEBUG){
   		write(fd,"P",1);
		printf("Printed Pn");
	} else {
		// 7 - single a d conversion to host on current settings
		// z 3 bytes (both channels x and y of accelerometer)
		// s - 7 bytes (all 7 channels)
		// 8 - streaming a/d conversion data using current settings
   		write(fd,"z",1);
	}
	} 

         if (wait_flag==FALSE)  //if output is available
	{
		res = read(fd,buf,255);
		if (res>0)
		{

			// Print serial output
			for (i=0; i

Blink detection and attention evaluation: the NeuroSky MindWave

Hardware for UX evaluation

As part of Project Sunflower, we took various approaches to interface evaluation. Alongside heuristic evaluation, walkthroughs and so forth, we also used various bits of hardware to support trials. This post describes setup and sample code for the NeuroSky MindWave, an inexpensive BCI (brain-computer interface – think ‘electroencephalogram’, or ‘brain wave monitoring’) that uses a single sensor placed on the forehead to measure eye blinks, ‘attention’ and ‘meditation’. These two latter variables shouldn’t be taken at (scuse the pun) face value; according to a report by Travis Ross, they’re based on a proprietary algorithm, with attention reported to relate to beta waves, hence linked to wakefulness/focus, and meditation linked to alpha waves – level of calm. Vague, admittedly, but then these devices are priced for and in large part targeted at the consumer market. If you’ve ever seen those Mattel Jedi force-trainer toys, those are based around the same technology.

Setup

Having installed the software prerequisites and drivers, the next thing is to run the Thinkgear Connector. This is an extremely helpful little piece of kit, which listens to the USB radio link and makes the sensor data available to applications. This reduces the connection step to a couple of lines of code. Since the Thinkgear Connector will return JSON upon request, the data packets are easy to parse.

Code

import sys
import json
import time
from telnetlib import Telnet

tn=Telnet('localhost',13854);
start=time.clock();

i=0;
# app registration step (in this instance unnecessary)
# tn.write('{"appName": "Example", "appKey": "9f54141b4b4c567c558d3a76cb8d715cbde03096"}');
tn.write('{"enableRawOutput": true, "format": "Json"}');

outfile="null";
if len(sys.argv)>1:
        outfile=sys.argv[len(sys.argv)-1];
        outfptr=open(outfile,'w');

# default values
eSenseDict={'attention':0, 'meditation':0};
waveDict={'lowGamma':0, 'highGamma':0, 'highAlpha':0, 'delta':0, 'highBeta':0, 'lowAlpha':0, 'lowBeta':0, 'theta':0};
signalLevel=0;

while i

(Edit: The above code is truncated. See https://github.com/etonkin/neurosky-telnet for full code)

Example output

The code as written above produces very simple CSV output, which has the benefit of being very easy to plot using something like Gnuplot:

plot "test-output.log" using 1:3 with lines, "" using 1:4 with lines, "" using 1:5 with lines

Graph of three variables: working on a language problem.

Some sensor data captured: subject was working on a language problem. Red

Sensor data. Activity: Watching TV

Sensor data captured: individual was watching TV. Red

Note: the number of blinks captured is low enough that the chances are that the MindWave is not picking up all blink events.

Ebook reader basics: file transfer via USB

We covered some of the basics of these devices in an earlier series of posts, but it might be worth taking a few minutes to focus on the most basic behaviour of the lot: getting data onto the devices from a laptop. One might expect that all of these devices would operate as USB mass storage devices (plug it in and copy files on). As anybody who’s ever tried to copy data off an iPod knows, nothing could be further from the truth.

Assumptions used here: the task is to copy non-DRM’d ebook files onto an ebook reader.

Sony PRS-600, Hanvon n510, etc.

Like most of your basic e-Ink devices the Sony and its type are ridiculously straightforward to use, if a little slow, as long as you are familiar with copying files using a file manager. These devices function as USB mass storage devices. Plug it in, copy files, unplug it and (in the case of the Sony) wait for it to reindex pretty much the entire filesystem, including files that have been on the ebook reader for months. Don’t keep too many files on the Sony, or you’ll run out of battery life before you ever read a page – the indexing is the most power-hungry step it takes. The Hanvon doesn’t bother with exhaustive indexing, which saves time and battery life here but means that it doesn’t offer the same search functionality.

Filesystem speed stats were generated using:

rsync -auvh --progress --stats --no-o --no-g --no-p /some/files .

We ran this on Linux in each case, in order to ensure that there weren’t any confounding factors such as Spotlight indexing.

Results:  Hanvon N510: 2.34M bytes/sec

Kindle

The Mac recognises the Kindle as a USB drive, and allows you to copy items directly onto it (.pdf or .mobi – convert using Calibre if required). It’s not all plain sailing, though; the Kindle tends to place items imported in this way into a menu section entitled ‘items not yet indexed’. When this happens, it seems that you may need to reset the Kindle (hold the sleep button for 20 seconds), at which point it will reindex on startup.

File transfer rates: 1.87M bytes/sec
We found the Kindle’s file transfer rates to be unusually slow.

Xoom

The Xoom is a somewhat frustrating device. It’s using a driver called MPT (Motorola Phone Tools). Seems this is standard to Android devices, instead of SCSI-like hard drive/mass storage, so we’ll all have to get used to it… Google’s explanation for this decision may be found on this blog post: in short, MPT is seen as an improvement on USB mass storage because

‘for devices with lots of internal memory, a manufacturer no longer needs to come up with some hard partition between the USB mass storage and internal storage. Instead, they are all in one partition, with MTP providing access to the directory of media files that would normally be available through USB mass storage. This means there is no longer a need for apps on SD card for such devices, because what used to be the ‘internal SD card’ is in the same partition as where applications are stored. The storage on your device can be used for either applications or media, depending on what you want to put on it. You aren’t stuck with how much space the manufacturer decided to leave for the two areas. Also, this means that the media storage doesn’t need to be unmounted from Android when it is being access[ed] through the PC.’

On Windows, once the appropriate drivers are installed, it can be treated like a standard storage device – you can simply drag and drop files. On the Mac you’ll need to download the Android File Transfer software, which will allow you to drag and drop files in either direction, plus or minus the occasional bug.  On Linux, you can mount it through MPT using mptfs, a fusion driver for MPT drives. GNOME users will probably find that this happens automatically. The rest of us just do mptfs -o allow_other mountpoint. Android File Transfer on a Mac feels rather slow, but our test on Linux (see data below) suggests that mptfs is not unreasonably slow.

File transfer rates:
mptfs on Linux (calculated as above): 4.59M bytes/sec
Compare this to a similar test of an HP USB2 16GB USB drive: 7.66M bytes/sec

iPad

The iPad was clear winner of the ‘least cooperative’ award in this category. iDevices don’t show up in the filesystem by default. The traditional mechanism used to get files onto the device involves iTunes. This music software has been adapted after the fact for use as an ebook organiser, and its origins are still clearly visible. The results are indifferent: the right-click context menu in the ‘Books’ pane, for example, invites you to ‘download album artwork’. Using this approach, getting files onto your iPad is a multi-step process; download files, import them into iTunes, sync with iPad.

Right-click context menu for ebooks (iTunes screenshot)

Right-click context menu for ebooks (iTunes)

iTunes is the Vegemite of the tablet user; you either love it or hate it. Unless iTunes is a big part of your ebook-reading life already, it becomes an irritant, dragging out the file copy process unnecessarily. The OPDS approach is simpler, if all you want to do is get your files onto the iPad: just download them directly onto the iPad itself.

File transfer rates:
cannot be compared directly.

OPDS: building an ebook catalogue

This is part of a series wrapping up (belatedly, alas) the findings from Project Sunflower. As the protagonists of the Project have moved on to pastures new, leaving their notes behind, editorial duty has fallen to yours truly.

In this post, we look at OPDS, otherwise known as ‘Open Publication Distribution System’, and why it’s worth a look for anybody intending to integrate ebook platforms into the student experience. For anybody who’d rather skip ahead, version 1.1 of the standard can be found right here.

OPDS is, according to the specification, designed as

a syndication format for electronic publications based on Atom and HTTP

and can

enable the aggregation, distribution, discovery, and acquisition of electronic publications

using

existing or emergent open standards and conventions, with a priority on simplicity.

Now, as we will see from reviewing the performance of typical embedded ebook search/indexing functions and interfaces, most ebook readers aren’t designed to contain huge numbers of ebooks. At 7.99 an ebook, most readers will be cautious in their acquisitions, so perhaps the perception from some manufacturers is that it is pointless to create readers that specialise in navigating across hundreds of thousands of files. Many portable media devices suffer from similar difficulties – the classic ‘clickwheel’ interface on iPods, as applied to a large number of files, became the subject of a 2009 satirical report by The Onion.

The relevance of OPDS is the following: OPDS allows you to search and browse across extensive collections of documents. They don’t need to be books; an OPDS frontend on an institutional repository is perfectly achievable, format conversion notwithstanding. The obvious use case is searching or browsing for a single file, but part of the relevance of OPDS is the fact that it also allows for batch mode: a student downloading the full reading list for the semester, for example. Wouldn’t that be convenient?

An OPDS catalogue is fairly straightforward to set up. For prototyping purposes, the well-known ebook software Calibre can be used to experiment with the concept; it can be found in the Calibre software under Preferences->Network->Sharing over the net, and is referred to as a ‘Content Server’. If you’d rather experiment with a static OPDS catalogue — providing no search function, but with browse functions that make full use of your metadata — consider trying calibre2opds, a Java application that renders your Calibre catalogue as a set of static HTML pages and, being simpler and more secure (by dint of having very few moving parts), may be considered a relatively secure way of deploying a prototype. A comparison of these alternatives may be found here.

Cross-platform compatibility: Limited.

Android and the iPad approach this on a per-application basis, and a good implementation is available for both. iBooks won’t handle the catalogue functionality, but you can manually type the address into Safari; then, when you click on an ePub file, iBooks can handle the download. Alternatively, you can use Stanza, which works well – but when iOS 5 came out, we discovered that Stanza ceased to work until we updated the iPad to the latest version, so be prepared for sudden failures around the time of iOS upgrades.

The Kindle is able to use OPDS catalogues, but requires them to run on port 80 (the usual port for a web server, admittedly, but not Calibre’s preferred choice for practical reasons). Simpler e-Ink devices mostly still do not have any mechanism for connecting to the Web, and therefore this sort of functionality is not available on the platform itself, so desktop software must be used instead.

Ease of setup: Moderate.

Getting a Calibre content-server running on a home network is relatively easy provided that the user is familiar with terms like ‘IP address’. However, practical implementation on a larger scale requires significantly more thought; not only are there security and sustainability issues around the software, but the usability of the resulting catalogue is very dependent on good metadata.

Benefits

Standard, relatively simple to set up, and extremely liberating – a convenient distribution channel, bypassing the need to centralise via a commercial vendor, what’s not to like?

Disadvantages

Support for OPDS is patchy and the standard is still relatively recent. Many popular ebook reader applications do not support it explicitly. Fortunately, it’s so near to popular standards that all you really need is a web browser and an ebook reader to get some benefit from an OPDS.

Sample screenshots

Browse by tag screenshot

Browsing the Calibre content server by tag

 

Browse by author screenshot

Browse by author