Particle AF OLED display

Includes 3 buttons next to the display that has a diagonal dimension of about 1 inch.   Cost is $15 / ea.   Uses I2C.   Purchase from Particle or Adafruit

Use the AF OLED Wing library The display connects by I2C on pins D0 and D1.   Note that the OLED display uses D2, D3, and D4.   Button A, D4, No pull-up.   Button B, D3, 100k pull-up.   Button C, D2, no pull-up.  


/*
 * Project      af_128x32_oled
 * Description: Template for using Adafruit 128x32 OLED
 * Author:      Mark W Kiehl / Mechatronic Solutions LLC
 * Date:        June 2020
 */

#include "Particle.h"

#if (PLATFORM_ID == PLATFORM_XENON)
SYSTEM_MODE(MANUAL);
#endif

/////////////////////////////////////////////////////////////////////////
// AF 128x32 mono OLED   
// https://github.com/rickkas7/oled-wing-adafruit
// particle library install oled-wing-adafruit
#include "oled-wing-adafruit.h"
OledWingAdafruit display;
// Timer for updating the OLED
const unsigned long TIMER_OLED_INTERVAL_MS = 10000; 
unsigned long timerLastOLED = millis();  
/////////////////////////////////////////////////////////////////////////


void setup() {
 
  pinMode(D7, OUTPUT);
  digitalWrite(D7, LOW);

  Serial.begin(9600);
  //waitFor(Serial.isConnected, 30000);
  delay(1000);
  Serial.printlnf("System version: %s", System.version().c_str());
  Serial.printlnf("Free RAM %d", System.freeMemory());

   /* START AF FeatherWing OLED 128x32 mono */
  display.setup();
  display.clearDisplay();
  display.setTextColor(1);  // 1 = WHITE
  display.setTextWrap(false);
  display.clearDisplay();
  display.setTextSize(2);   
  display.setCursor(0,0);   // rows @ 0,19
  //display.print("[12345678]"); 10x2 chars
  display.print("Boron_A");
  display.setCursor(0,19);   // rows @ 0,19
  display.print("v0");
  display.display();
  /* END AF FeatherWing OLED 128x32 mono */

  Serial.println("Setup complete");
} // setup()


void loop() {

  updateOLED();

} // loop()


void updateOLED() {
  // Check if OLED button A, B, or C has been pressed.
  // Update display if button not pressed.
  display.loop(); // call this on every call to loop() to keep the button debouncer running.
  if (display.pressedA()) {
    // OLED button A on D2 pressed
    display.clearDisplay();
    display.setTextSize(2);   // 10 chars wide x 2 tall; each character is 12 pixels wide x 16 tall
    display.setCursor(0,0);   // rows @ 0,19
    display.print("[_BTN A _]");
    display.setCursor(0,19);   // rows @ 0,19
    display.print("[12345678]");
    display.display();
    timerLastOLED = millis();
  } else if (display.pressedB()) { 
    // OLED button B on D3 pressed
    display.clearDisplay();
    display.setTextSize(1);   // 21 characters wide x 4 characters tall w/ character spacing
    display.setCursor(0,0);   // rows are: 0, 8, 16, 25
    //display.print("012345678901234567890");
    display.print("[ Button B pressed  ]");

    display.setCursor(0,8);   // rows are: 0, 8, 16, 25
    display.print("[ Row 8             ]");

    display.setCursor(0,16);   // rows are: 0, 8, 16, 25
    display.print("[ Row 16");
    display.setCursor(60,16);   // rows are: 0, 8, 16, 25
    display.print("[<- Col 60]");

    display.setCursor(0,25);   // rows are: 0, 8, 16, 25
    display.print("[ Row 25            ]");

    display.display();
    timerLastOLED = millis();
  } else if (display.pressedC()) { 
    // OLED button C on D4 pressed
    display.clearDisplay();
    display.setTextSize(2);   // 10 chars wide x 2 rows tall; each character is 12 pixels wide x 16 tall
    display.setCursor(0,0);   // rows @ 0,19
    display.print("[ BTN C  ]");
    display.setCursor(0,19);   // rows @ 0,19
    display.print("[12345678]");
    display.display();
    timerLastOLED = millis();
  }
  if (timerLastOLED > millis())  timerLastOLED = millis();
  if ((millis() - timerLastOLED) > TIMER_OLED_INTERVAL_MS) {
    display.clearDisplay();    
    display.setTextSize(2);   // 10 characters x 2 rows
    display.setCursor(0,0);   // rows 0, 19
    //display.print("0123456789");
    display.print("Boron_A");
    
    display.setTextSize(1);   // 21 characters wide x 4 characters tall w/ character spacing
    display.setCursor(0,16);   // rows are: 0, 8, 16, 25
    display.print("BATT ");
    // (2000.0 + 806.0)/2000.0 *3.3/4096.0 = 0.00115 (my calc) or 0.0011224
    float battV = float(analogRead(BATT)) * (2000.0 + 806.0)/2000.0 *3.3/4096.0;
    display.print(battV);
    display.print(" V");
    if (PLATFORM_ID == PLATFORM_ARGON || PLATFORM_ID == PLATFORM_XENON) {
      display.setCursor(0,25);   // rows are: 0, 8, 16, 25
      pinMode(PWR, INPUT);
      byte pwr = digitalRead(PWR);    // PWR: 0=no USB power, 1=USB powered
      if (pwr == 0)
        display.print("Battery pwr (no USB)");
      else {
        pinMode(CHG, INPUT);
        byte chrg = digitalRead(CHG);  // CHG: 0=charging, 1=not charging
        if (chrg == 0)
          display.print("USB pwr, charging");
        else
          display.print("USB pwr, not charging");
      }
    } else if (PLATFORM_ID == PLATFORM_BORON) {
      // Boron requires that you query the PMIC 
    } // PLATFORM_ID

    display.display();
    timerLastOLED = millis();
  } // if
} // updateOLED()

More AF FeatherWing products from Adafruit and from Particle

 


Do you need help developing or customizing a IoT product for your needs?   Send me an email requesting a free one hour phone / web share consultation.  

 

The information presented on this website is for the author's use only.   Use of this information by anyone other than the author is offered as guidelines and non-professional advice only.   No liability is assumed by the author or this web site.