element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Azure Sphere Starter Kit
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Azure Sphere Starter Kit
  • More
  • Cancel
Azure Sphere Starter Kit
Blog Interfacing the BME680 enviromental sensor to Azure Sphere
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Azure Sphere Starter Kit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: tekmeister
  • Date Created: 2 Oct 2019 9:39 AM Date Created
  • Views 2085 views
  • Likes 6 likes
  • Comments 8 comments
Related
Recommended

Interfacing the BME680 enviromental sensor to Azure Sphere

tekmeister
tekmeister
2 Oct 2019

As part of my Sensing the World entry, I purchased an Environment Click https://www.mikroe.com/environment-click

The heart of the Click board is a Bosch BME680 environmental sensor, which can measure temperature, relative humidity, pressure and VOC content.

 

I wanted to share my experience using this Click Board with the Azure Sphere Starter Kit in the hope that others find it useful. Alternatively, perhaps it is some form of therapy....(read on for more information)

 

There is one previous example of this board being used on an Azure Sphere, https://www.hackster.io/gatoninja236/azure-sphere-weather-station-d5a2bc

The approach used there was to to read/write directly to the registers.

 

However Bosch provides a driver written in C to get this sensor going, and I wanted to use that. Partly this was for speed and ease of use, and partly because I also wanted to integrate the BSEC library [https://www.bosch-sensortec.com/bst/products/all_products/BSEC ] which builds on the BME680 driver and provides some additional outputs including an indoor air quality (IAQ) index.

 

I was initially planning to use SPI to talk to the BME680, but since the board is configured for I2C out of the box, I opted instead to use I2C.

 

I started with the I2C example project from the Azure Sphere Samples site [https://github.com/Azure/azure-sphere-samples].

I then added the BME680 driver [https://github.com/BoschSensortec/BME680_driver] to the project and filled in the stub user functions for I2C read/write.

Finally I followed the instructions on the BME680 GitHub page to call the driver API.

 

My initial experience integrating the Azure Sphere I2C example and the BME680 driver was very positive. The Azure I2C API was logical and the BME680 driver provided a high level interface to the sensor, without me needing to consult the details of the various BME680 registers in the datasheet. This was going to straight-forward.

 

Or so I thought.

 

After making the above changes, I built and ran my project to make sure the basic I2C example was working. However the values I was getting from bme680_get_sensor_data() were garbage.

 

And so began a tedious session of debugging, whilst I tried to determine why my simple example wasn't working. I knew that the Azure Sphere I2C libraries and hardware *must* be working, as I had previously worked through some of the tutorials using the onboard I2C sensors. Most likely the BME680 was also functioning, meaning the issue was likely my code.

 

Was there an endian issue? No, I ruled that possibility out.

 

Was I mis-reading the datasheet somewhere? I couldn't see where.

 

My BME680 init routine seemed to be returning all the right values, but the sensor data was definitely wrong.

Another weird behaviour I noticed, was that sometimes (but not always!) the data read from the BME680 was to be offset by one byte.

 

Finally after multiple days of thinking, prodding, and testing I cracked the code: there is an underlying issue with the I2C read functions in Azure Sphere 19.07.

If you read more than 8 bytes at a time, then all subsequent reads will return your requested data from offset 1 of your buffer, and the byte at offset 0 is random or rubbish.

 

I modified my read function to read no more than 8 bytes at a time and suddenly my temperature/humidity values started making sense.

image

Success at last. Hopefully this issue is resolved in later Azure Sphere updates.

 

The next task is to try to integrate the BSEC library to get better compensated readings...

  • Sign in to reply

Top Comments

  • Fred27
    Fred27 over 5 years ago +2
    Yes - there's definitely an issue with the repeated first byte on I2C reads. I raised it back at the beginning of September. There is now an issue raised on the MSDN forum (I assume by tekmeister ) but…
  • tekmeister
    tekmeister over 5 years ago in reply to Fred27 +1
    Yes that issue on the MSDN forums is mine :-) 19.09 is available now, but I'm not sure how to get it on my board https://azure.microsoft.com/en-us/updates/update-19-09-for-azure-sphere-public-preview-now…
  • Fred27
    Fred27 over 5 years ago in reply to tekmeister +1
    I started going through the process of setting my board up for the evaluation OS (linked from that page). However the documentation assumes you have code that is deployed OTA rather than using azsphere…
  • tekmeister
    tekmeister over 5 years ago in reply to koener

    Full code for my integration (including BSEC) is in https://github.com/jkuek/EnvironmentMonitor_AzureSphere/

     

    However the code should be able to be much simpler with the latest Sphere SDK and test build of the BSEC library, as you don't need all my workarounds anymore.

     

    I might get around to updating the code myself at some point.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • koener
    koener over 5 years ago

    That would be nice. Can you tell me what you wrote in the stub user functions for I2C read/write?

     

    Thanks,

    Koen

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • tekmeister
    tekmeister over 5 years ago

    An update: Microsoft have purportedly fixed the I2C issue I lodged with the latest Azure Sphere 19.11 OS. I have not yet tested it though.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Fred27
    Fred27 over 5 years ago in reply to tekmeister

    I started going through the process of setting my board up for the evaluation OS (linked from that page). However the documentation assumes you have code that is deployed OTA rather than using azsphere device prep-debug to have a development device like we have all done. I'm sure it's possible to set a development board up to receive 19.09, but it doesn't seem worth the effort if it's on the way soon.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 5 years ago in reply to tekmeister

    If you wait for public release, it automatically downloads OTA. Otherwise you can request the beta version up to 2 weeks early. Check Microsoft docs with a google for "azure sphere os updates"

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube