May 042014
 

To take measurements on railway track (possibly miles from civilisation), it is useful to have a system that doesn’t require mains power or display, keyboard, etc. In this case I used:

  • 5000mAh Li-Ion Rechargeable Power Bank; supplied by RS Online (775-7508)
  • Belkin Cable Transfer Windows 8; supplied by RS Online (779-8827)

Raspberry Pi Type A with Sparkfun Sensor Stick used to monitor railway track

Raspberry Pi Type A and Sparkfun Sensor Stick used to monitor railway track


Power Source

The Power Bank is a rechargeable battery that is powered through a USB connection, and that supplies power to two USB-powered devices. In this case it is used to power only the Raspberry Pi Type A, and was used extensively over a 24-hour period without need for recharge.

Ethernet Communication between Raspberry Pi and Laptop

The Transfer Cable masquerades as an ethernet connection on Linux and was used to connect the Raspberry Pi with a Dell Laptop (with Debian Wheezy 7.4.0 newly installed). Of course, there are other ways to establish a link between the the Raspberry Pi and the outside world, and I plan to get it working via WiFi and radio in the near future, but the hard-wired connection has other potential applications. Also, it can be unplugged and then plugged in again, so is probably the lowest-power option.

To get the Raspberry Pi to recognise and configure the USB connection, add the following settings for usb0 in /etc/network/interfaces:

allow-hotplug usb0
iface usb0 inet static
    address 192.168.99.2
    netmask 255.255.255.0
    gateway 192.168.99.1

Update: Actually, the gateway setting isn’t necessary – I have tested the Belkin cable on a Raspberry Pi Type B*1 without the gateway setting and it works fine. The gateway setting is required if you want to share the laptop’s internet connection – in which case, you will also need to configure iptables on the laptop*2.

*1 I read somewhere that the Belkin cable doesn’t work with the Type B, but it seems to work fine for me.
*2 I used ufw for this, which is easy enough to use, but where things do get complicated is with nameserver configuration on the Raspberry Pi.

Something similar needs to be done on the laptop:

allow-hotplug usb0
iface usb0 inet static
    address 192.168.99.1
    netmask 255.255.255.0

Results

The graphs below are accelerometer and gyro measurements averaged over a period of one second. The sensors were collecting data continuously and most of the time there was no activity. The passing trains appear as a compressed burst of movement, against which long-term changes are apparent.

Gyro on rail web: Deltics and Class 37

Gyro on rail web: Deltics and Class 37

Accelerometer on rail web: Deltics and Class 37

Accelerometer on rail web: Deltics and Class 37

Above: The Deltic arrived at Barrow Hill preceded by a Class 37, and later they left with a second Deltic coupled behind.

Gyro on rail web: 0-3-0, Class 40 and Class 45

Gyro on rail web: 0-3-0, Class 40 and Class 45

Accelerometer on rail web: 0-3-0, Class 40 and Class 45

Accelerometer on rail web: 0-3-0, Class 40 and Class 45

Above: The 0-3-0 passed first, collected the Class 40 and Class 45 for a total of four passes, then uncoupled and returned.

Apr 162014
 

The hardware I’m using here is a Raspberry Pi Type A, described in detail here. My previous post (Part 1: Modules and Packages) configured the Raspberry Pi to use the I2C connection. The aim in this post is to connect to a SparkFun 9DOF Sensor Stick (SEN-10724) which has a 3-axis accelerometer (ADXL345), a 3-axis gyro (ITG-3200) and a 3-axis compass / magnetometer (HMC5883L) all sharing an I2C interface.

Raspberry Pi Type A connected via I2C with a SparkFun 9DOF Sensor Stick (SEN-10724)

Raspberry Pi Type A connected via I2C with a SparkFun 9DOF Sensor Stick (SEN-10724)


There are three separate devices on the sensor stick all hooked up to the same I2C bus. You can see the addresses listed below. The HMC5883L compass / magnetometer uses address 1e. The ADXL345 accelerometer uses address 53. The ITG-3200 gyroscope uses address 68. (The ‘UU’ at address 3b indicates an address reserved by the kernel, but I don’t know for what.)

~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1e -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- 53 -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

2. Connecting to the Sensor Stick

I’m not the first to use this stick, and there is, for example, a project by Peter Bartz which uses the stick:
Attitude and Heading Reference System (AHRS). More useful, perhaps, is Rolfe Schmidt’s muCSense work with it here and here.

All three I2C devices have open source (MIT license) C++ device libraries available from I2Cdevlib:

These rely on the underlying Wire class written for the Arduino, however, so a Raspberry Pi implementation of the Wire class is necessary (and one or two other miscellaneous functions).

I am currently working on this – find the latest source here, and a discussion topic here.