For many applications it is vital to have a way of providing instructions and feedback to the user. Many types of display are available including LCD screens and e-paper. OLED technology offers a good compromise between features and power consumption, and units that use the I2C communications interface are very easy to control.
Modules that use the I2C protocol have four pins as shown in the table below.
|VCC||Power input - usually 3.3V|
|SCL||I2C clock pin - used to coordinate communications between the module and the microprocessor|
|SDA||I2C data pin|
The hardware setup is shown in Fig. 2. Please check the pin labels on your particular display module to see whether they are in the same order as those shown in Fig. 1.
The OLED display requires some complex data handling routines in order to work correctly. There are several libraries available that implement the detailed code and provide you with a simple API. The ADAFRUIT_SSD1306 library is recommended and Fig. 3 shows its information in the Particle Web IDE. You should choose the I2C example labelled (1) in the figure and then click Use this example, labelled (2), to load it into the code area ready for flashing to the Argon.
When it runs, the example code runs through a series of demonstrations which use
text of different sizes, graphics and dynamic effects. To make use of these features
in your own code, make a copy of the example, locate the section(s) of the code you want
to keep and remove the parts you are not interested in. For example, the code below
uses an adaptation of the
testscrolltext() function to display the number of
seconds that have passed since startup in intervals of 10s. The displayed text
start at the top-left of the display and scrolls to the right for 2s.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
Things to note
Line 1: The
SPI.hheader file is not required
Lines 69-72: Add variables as needed for your particular application
Line 89: Divide the value returned by
millis()by 10,000 to get ten-second intervals
Line 90: Use the serial monitor for debugging if needed
Line 99: Convert numerical values to text before displaying them