Activity 2: I2C bus and sensors

Learning objectives

In this second activity, you will learn about a very common aspect of device programming: monitoring, logging and transferring sensor data. It builds up on the skills you learned in the first activity - you will get to use arrays and interrupts again!

This activity will teach you how to interact with a large class of devices communicating with the ubiquitous I2C bus and protocol. You will also have to polish your soldering skills, and learn how to navigate a complex data-sheet to find the information you need.

Task to complete

The data-sheet of your sensor is available here.

Using the sensor and your micro-controller, you will have to:

  • record a temperature value every second in an array that will contain the last minute of data (older data is replaced by new data once the array is full). An timer interrupt must be used to trigger the recording of the value.

  • if the temperature goes above a threshold value of 28 degree Celsius, get the temperature sensor to trigger an interrupt that will get the LEDs on the microcontroller to flash a visual alarm signal (for you to imagine), stop the recording, and transmit the last minute of data to your computer by USB serial communication. Values should be transmitted as text (i.e. printed on the serial port), one value per line. The alarm signal should continue until the micro-controller is rebooted.

  • optional: if you are keen, you may try to capture and plot the temperature data on your computer using a python script.

What you may need to learn

To complete the task, you may need to learn the following elements

  • What are I2C devices and how to communicate with them?

  • Soldering and testing your sensor.

  • Configuring the sensor using its internal registers

  • Responding to hardware interrupts from the sensor

Before getting started with the main task, you are invited to learn about the prerequisites mentioned above. Please take them in the right order. This should give you the background knowledge needed to tackle the activity. It may take you 2-3 hours to go through it.