connect it to something
with an I2C interface to
read the data. Most any
SBC or even
do the job, but we’re
going to reach for our
Systems’ TS-7970 high
SBC with Wi-Fi and
Bluetooth, since we
have an Io T-like end
goal in mind.
The MPL3115A2 breakout board requires no more
than 3. 3 VDC and a connection to SDA (I2C Data) and
SCL (I2C Clock). There are two interrupt pins that can be
used for things like events and triggers, but we’re not
going to use those in this article. All of this is brought out
on the header designated as HD3 on our TS-7970 (see
section HD3 of the TS-7970 manual available at
When we’re all hooked up and powered on, the I2C
interface is brought out to the Linux device file /dev/i2c-1
(see section TWI of the TS-7970 manual). This number
might change depending on your system, so be sure to
run i2cdetect -l to get a list of I2C interfaces on your board.
Note: We’re making a couple assumptions at this
point. One is that you already know how to boot and
connect to your board. If you’re following along with a TS-
7970, you may want to take a look at the Getting Started
Guide (available at the same link as the manual). Another
assumption we’re making is that you’re running Linux and
have i2c-tools installed.
Programming the I2C Client
Official documentation for programming an I2C client
in C can be found in the Linux Kernel in /i2c/dev-interface.
(You can find documentation
mentioned in this article at
We don’t have to be stuck
using C though. You can reach for
C++, Python, Java, or others. For
this article, we’re going to work
with C for learning purposes, and
because we know C is uber fast
where hardware is involved.
Pro Tip: When researching how
to interface with the MPL3115A2, I
stumbled upon a fantastically
convenient repository in the
( https://github.com/ControlEverything Community) that
has working example code for Python, C, Java, and more.
Take a look for yourself at the ControlEverything
Community/MPL3115A2 github repository.
Pro Tip: If you are interested in using Python, you’ll
need to install python-smbus first
Once we have a basic understanding of how to
program for I2C from looking at examples and
documentation, we need to dive into the specifics of our
sensor using the MPL3115A2 datasheet.
Luckily, NXP also provided a really nice application
note — Data Manipulation and Basic Settings of the
MPL3115A2 Command Line Interface Driver Code — which
helps further our understanding of how to interface with
this sensor. In section 11 (Quick Start Setup), you’ll find a
flowchart showing necessary steps to read altimeter data.
Pro Tip: Since we don’t plan on using the events to
trigger an interrupt pin, you should be able to skip the
step of enabling data flags in PT_DATA_CFG.
July 2017 37