A Digital Compass for the Original Tablet

compass-adafruitBFigure 1: The digital compass has been mounted in the original homemade tablet, next to the powerful Imedion NiMH “C” cell bank.

The next item to be added to the original homemade tablet was a mims/magnetic compass (purchased from Adafruit).  It is an i2c device, so is only a four wire connection (Vcc, Gnd, SCL, and SDA):

Odroid/C1 –  Compass
  • Pin 3 —-  SDAmay need 1.8k – 4.7k ohm pull-up to Vin (see text)
  • Pin 5 —-  SCL may need 1.8k – 4.7k ohm pull-up to Vin (see text)
  • Pin 1  —- Vin
  • Pin25 —- Gnd

Note: Odroid pins are on the left, the compass pins are on the right.  Also note that SDA and SCL may need pullups (something like 1.8k – 4.7 kohms) to Vin/Vcc.  See text, below.

The Odroid documentation that I’ve managed to find is not clear (at least to me) about what value the internal pull-up resistors may have for  SCL and SDA, or if they even exist.  So, I’ve tried the compass with and without pull-ups from SCL to Vin, and from SDA to Vin, and it works equally well either way (seemingly).  This seems to say that there are internal pull-ups, but it would be wise to check on this (somehow).

The value of the pull-up is subject to debate.  To some extent, it depends upon how many I2C devices are hooked onto the bus.   This is because many I2C devices have built-in pull-up resistors, and each additional device that is added has the effect of reducing the total resistance of the pull-ups on the SDA/SCK pins (since the resistances are all in parallel).  As this resistance drops, the current demand increases, and at some point (depending upon the pull-up values chosen or already included in devices) it may be more than the SoC board can deliver.

There is also a consideration for how good the data train looks on a scope.  So – when any values are chosen for the pull-ups, there should probably be a follow-up inspection of the waveform. The default pull-up on the Pi is 1.8k ohms.  However; if connectecting two or more devices, then a higher starting value puts the total closer to 1.8k due to the resistors being in parallel. It’s a case-by-case, and like I said the waveform should be checked to make sure it’s reasonable.  I have two I2C devices on this homemade tablet (the barometric pressure unit and the compass).  I used separate busses, so the resistors are not in parallel.

If I had used the same bus, then my 4.7k ohm resistors would have provided a total of  (4.7 * 4.7) / (4.7 + 4.7) = 2.35 k ohms, which is close to the default Pi internal values of 1.8k ohms.  The Pi can source only 50 mA, so the maximum number of I2C devices may be pretty high.  However; the ability of the individual I2C devices to handle the current must be considered, so it’s a case-by-case situation.  The resistance at which 50 mA occurs on a 3.3 VDC bus is 3.3 V / 0.05  = 66 ohms.  I can’t be bothered to calculate the number of devices that amounts to (R = 1 / ((1/ R1) + (1/ R2)  + (1/R3) … etc)) – but it’s quite a few.  OTOH, the waveform should still be looked at, considering the individual device capabilities and also considering the different frequencies at which the bus may be operated, and the length of the lines.  Note this is a non-expert, hobbyist’s opinion – not advice!

The compass unit (which uses a LSM303DLHC chip) was mounted on standoffs next to the battery bank, because that’s the only place that remained inside of the enclosure, where an easy floor mount could be managed (there’s still some room on the walls and the ceiling!). The compass board has an on-board regulator for 3.3 VDC, so could be fed with 5VDC (Vin) when using a 5 volt system, but I instead supplied the 3.3 V from the Odroid C1 SoC board 40 pin header, since it was available (and why play with fire?)

Anyone who’s had an iPad knows the kinky little trick it uses to orient the screen as the user rotates the device.  I don’t know for sure, but it seems that a compass (or accelerometer) may play a part there.  The LSM303 device contains both!

Some software is needed to interrogate the compass board, and it can be  adapted from the arduino C code at:

git clone https://github.com/adafruit/Adafruit_LSM303

Or, Python can be used to interrogate the board, using:

git clone https://github.com/adafruit/Adafruit_Python_LSM303.git

The OS needs git, build-essential, and python-dev (on Linux).  For the Python tool, I cloned the github repo, and setup the program thusly:

  • cd Adafruit_Python_LSM303
  • sudo python setup.py install

I changed the directory to be the Adafruit…./examples directory, and ran simpletest.py.  My unit’s output is shown in Figure 2 (below).

The constant-current/ constant voltage board behind the compass does not power the tablet!  It is not made to supply as much current as my DC-DC converters do, and is only a small part of the overall (somewhat complicated) charging circuit component scheme. The batteries are contained inside of standard holders, but are held down by rubber extensions on the “ceiling” of the enclosure, which make a snug fit when the two halves are assembled.

I had some reservations about placing the compass so close to the batteries, thinking that the sensors would be affected, so it’ll be interesting to see how this plays out.  I had a real go-round and round with the GPS unit, getting it to work properly.  Hopefully, this board will work with fewer complications.

compass-output1Figure 2: Output of the new compass. (Click to enlarge).

Python auto-loads the modules, but if using the C code version of the tool, one must make sure the module for i2c is loaded:

  • sudo modprobe aml_i2c  (or put into /etc/modules to make persistent)
  • sudo lsmod | grep aml_i2c

Looking into /dev, on the Odroid one should see:

  • /dev/i2c-1
  • /dev/i2c-2
  • /dev/i2c-3
  • /dev/i2c-4

Executing this command should disclose the address(es) of i2c devices:

  • i2cdetect -y 1  (assuming the connection is to the first i2c bus)

Figure 2 shows the output of the example program, but I have yet to verify that the results are correct.  The output is (supposedly) displayed in micro teslas, and I do indeed see the X and Y values move consistently up and down as I rotate the homemade tablet through 360 degrees.  There is a nice little utility for converting the micro-tesla readings to bearing degrees:

https://learn.adafruit.com/lsm303-accelerometer-slash-compass-breakout/coding

So far, I cannot say whether or not the batteries are interfering with the readings in any way, because I don’t do teslas that well in my head.  Some experimentation will be needed, using the degree calculator (from link shown) – to get a feel for what accuracy I’m dealing with …

Read More …

Note: the author does not have a recent, applicable background in circuit building, or battery related issues, so this is presented as the work of a hobbyist, and is not meant for duplication by others. Readers should look elsewhere for design advice and info.

Note: The Odroid site is http://www.hardkernel.com and is not affiliated with this site in any way.  The Adafruit product #1120 Compass is available at adafruit.com.  Adafruit is a trademark of Adafruit Inc.  Imedion and PowerEx are trademarks of Maha (Maha Energy Corp). None of the mentioned companies has any relationship to this author or website.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s