This project demonstrates how to use the Parallax FLiP with a Memsic 2125 accelerometer to visually display two-axis incline using a moving bubble on the 0.95” OLED display. When you change the incline of the accelerometer you will see the yellow bubble indicator move on the OLED. The positive or negative degrees incline will also be shown on the OLED. Incline measurement has useful applications including physical therapy feedback, heavy equipment anti-rollover detection, robotics, digital level, and a slope indicator.
The programming concepts in this project show how a sensor may be continuously monitored in its own processor and how to use the OLED to show simple graphic images, precisely-positioned text and data values, and incline values without showing remnant characters.
The FLiP was chosen for this project because of its small size and lower cost. The Propeller Activity Board (regular or WX) will also work fine.
These items are available individually:
- (1) FLiP Module (or Propeller Activity Board)
- (1) 0.95” OLED (#28087)
- (1) Memsic 2125 Dual-Axis Accelerometer (#28017)
- (2) 220 ohm resistors
- (misc) jumper wires
Propeller I/O Pin Connections
- P0: OLED DIN
- P1: OLED CLK
- P2: OLED CS
- P3: OLED D/C
- P4: OLED RES
- P5: M2125 Y-axis, via 220 ohm resistor
- P6: M2125 X-axis, via 220 ohm resistor
Use the schematics and pictures below to build the Tilt Bubble Display.
The source code is available for download from the link below:
The Blockly program has several key sections. The program starts by configuring the OLED and filling it with a blue background. The function “MX2125 Accelerometer” starts in its own processor and runs continuously. The X and Y-axis incline values are stored in variables which are used to draw the yellow bubble on the OLED.
The repeat loop simply cycles through the following three functions:
- Draw circles and lines on OLED
- Write text labels and values to OLED
- Draw accelerometer bubble on OLED
To understand how the OLED is updated we graphed the project on a 64x96 pixel space. Normal horizontal (x) and vertical (y) cartesian coordinate systems would place the (0,0) origin in the OLED’s lower left-hand corner. However, computer terminals and OLEDs are designed to place the origin in the upper left corner. The positive x increases to the right and y is downward.
The coordinates used in the Blockly code were plotted, pixel by pixel. The use of the OLED space worked out like this:
Two more considerations relative to coordinates are helpful to understand:
- Cursor positioning is in the upper left corner of the text. This project uses the small font, which requires 5x7 pixels for each character but in a 6x8 space for space around the character.
- Numeric incline values (x-axis and y-axis variables) are written to the display, then erased by writing a rectangle block of color. This prevents remnant values from showing up. For example, suppose you wrote X=-12 to the display and the next sensor value was X=-9. Simply writing the new value would appear as X=-92 [because the remnant 2 was persistent].