5 tips to make sensors simpler

-October 30, 2015

Sensors have proliferated across the surface of our planet and surrounding space, supplying the world with data. These inexpensive sensors are one of the driving forces behind the Internet of Things and the digital revolution our society now faces. Connecting to and acquiring data from sensors is not always straight forward or easy, however. Here are five tips to help ease engineers’ struggle with interfacing to a sensor for the first time.

Tip #1 – Start with a bus tool

The first step any engineer should take when interfacing to a sensor for the first time is to limit the unknowns by using a bus tool. A bus tool connects to a PC and then to the sensor via I2C, SPI, or any other protocol that the sensor might talk on. The PC application associated with the bus tool provides a known and working source for sending and receiving data and NOT an unknown, untested embedded MCU driver. Within the working environment of the bus tool, developers can send and receive messages to get an understanding of how the part works before ever trying to operate it at the embedded level.

Tip #2 – Write the interface code in Python

Once a developer has experimented with the sensor using the bus tool, the next step is to write the application code for the sensor. Instead of jumping straight to the MCU code, though, first write the application code in Python. Many bus tools come with plug-ins and example code for writing scripts. Python is usually one of the available languages along with .Net. Writing the application in Python is quick and easy and provides a way to once again test the sensor in an application environment without the intricacies of the embedded environment getting in the way. Having high level code then makes it easy for non-embedded engineers to dig through the script and experiment with the sensor without the need for an embedded software engineer to babysit.

Tip #3 – Test the sensor with Micro Python

One of the advantages to writing the first cut application code in Python is that the application calls to the bus tool API can easily be replaced by calls to Micro Python. Micro Python operates within the real-time embedded software constraints that many sensor engineers have come to appreciate. Micro Python runs on a Cortex-M4 processor and is a great environment from which to debug the application code. Not only is it simpler, there is no need to write I2C or SPI drivers because they are included as part of the Micro Python library. (Read Using Micro Python for real-time software development and/or 5 Advantages of using Micro Python for Embedded Software Programming for more details)

Tip #4 – Leverage sensor vendor code

Any example code that can be pillaged from the sensor manufacturer can go a long way in understanding how the sensor works. Unfortunately, many sensor suppliers aren’t experts in embedded software design, so don’t expect to find a beautifully architected and elegant example that is production ready. Take the vendor code, learn how the part works, and then refactor the heck out of it until it can be cleanly and neatly integrated into the embedded software. It may start out as spaghetti but utilizing the manufacturer's understanding of how their sensor works will help decrease how many weekends get ruined before the product is launched.

Tip #5 – Use a sensor fusion library

The chances are that the sensor being interfaced to isn’t so new that no one has done it before. Entire libraries known as “sensor fusion libraries” are provided by many chip manufacturers to help developers get up to speed quickly and, even better, to prevent them from reinventing the wheel. Many sensors can be combined into common types and categories which makes driver development, if done properly, nearly universal or at least reusable. Seek out these sensor fusion libraries and learn their strengths and weaknesses.

Final thoughts

There are many ways to help improve the speed and ease at which a sensor is integrated into an embedded system. A developer can never go wrong by starting at a high level abstraction and learning how the sensor works before integrating it into a low level system. Resources exist today that help developers hit the ground running without having to start from scratch.

Jacob Beningo is a Certified Software Development Professional (CSDP) whose expertise is in embedded software. He works with companies to decrease costs and time to market while maintaining a quality and robust product. Feel free to contact him at jacob@beningo.com, at his website www.beningo.com, and sign-up for his monthly Embedded Bytes Newsletter here.

Also see:

Join over 2,000 technical professionals and embedded systems hardware, software, and firmware developers at ESC Minneapolis Sept 21-22, 2016 and learn about the latest techniques and tips for reducing time, cost, and complexity in the embedded development process.

Make sure to follow updates about ESC Minneapolis's talks, programs, and announcements in the ESC Collection and social media accounts Twitter, Facebook, LinkedIn, and Google+.

The Embedded Systems Conference and EDN are owned by UBM.

Loading comments...

Write a Comment

To comment please Log In