In this project, there is a 7-Segment display, 8x8 LED matrix, proximity sensor (to determine the home position), and a BlinkM RGB LED that communicates via the I2C interface. We will discuss the application of each component in this project.
Prepare for lift off
The main requirement for this section is the necessary I2C device required to interface with the weather clock.
Engage thrusters
Let us review about the 7-Segment display.
The 7-Segment display
The Adafruit 7-Segment display backpack (reference: the tutorial available at https://learn.adafruit.com/adafruit-led-backpack/0-dot-56-seven-segment-backpack provides instructions on setting up the backpack and testing the backpack with a code sample), which is used to display the current atmospheric temperature obtained via the Raspberry Pi.
Adafruit provides libraries to write to the 7-Segment display. In order to write to the 7-Segment display, we declare a 7-Segment object:
If the current weather condition is fair, a smile is displayed and a frown is displayed for impending danger.
The write process is similar to the 7-Segment display. The 7-Segment display and the 8x8 display matrix use the MAX7219 chip. Hence, it is necessary to use a different address for the LED matrix. The Adafruit tutorial (https://learn.adafruit.com/adafruit-led-backpack/connecting-multiple-backpacks) clearly explains how to change I2C port addresses on the LED backpack. You are welcome to switch the address if both the 7-Segment display and the LED matrix are being used in the project.
It is also possible to write strings to the 8x8 matrix and scroll like a marquee. Similar to the 7-Segment display, we will initialize the object to communicate with the LED matrix:
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
We initialize the I2C port address of the device in the Arduino setup() function:
matrix_7segment.begin(0x73);
Adafruit tutorials also explain the creation of bitmaps for the smileys to be displayed:
The bitmap is used to determine the LEDs that would have to be turned on to create the smiley. For example, 0x3C (binary value: 00111100) turns on the LEDs except for the first and last two on either ends:
The setRotation function is used to rotate the display image by 90 degrees. The drawBitmap function is used to draw the bitmap on the display. In the drawBitmap function, the first two arguments specify the x and y of the starting position followed by the bitmap, width, height of the bitmap, and its color.
BlinkM
We discussed the BlinkM RGB LED in Project 2, A Raspberry WebIDE Example. The BlinkM is used to indicate impending danger by flashing a red color in the event of impending danger. We use the BlinkM libraries to play a flashing red script in such scenarios:
BlinkM_playScript(script_no,0,0 );
The BlinkM_playScript function takes the script number of the RGB LED. The second argument is the number of repeats for the script. When the third argument is zero, the script is played in an infinite loop.
Proximity sensor
The proximity sensor is used to determine the home position of the arrow that is used to point to the weather position. The proximity sensor used in this project is the OSEPP Proximity Sensor Module from Parallax. The proximity sensor detects the presence of objects and communicates this via the I2C communication port.
Similar to the other I2C devices, we set the sensor address as follows:
const uint8_t sensorAddr = 0x20;
We turn on the sensor in the Arduino setup() method:
WriteByte(sensorAddr, 0x3, 0xFE);
The sensor's reading is read by:
ReadByte(sensorAddr, 0x0, &val)
Objective complete – mini debriefing
We discussed the interfacing of different I2C devices that could be used in this project. In the next section, we will work on controlling these devices using an individual control signal.