QT Trinkey with mcp9808 sensor and SSD1306 OLED - No OLED values

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
Gary2
 
Posts: 32
Joined: Wed Apr 06, 2022 1:00 am

QT Trinkey with mcp9808 sensor and SSD1306 OLED - No OLED values

Post by Gary2 »

Many thanks for your attention and support. I feel I am missing something trivial, but after reading through the docs, I cannot place what is wrong with my OLED "display.print" statement in Arduino.

All devices are functional. When running the temp sensor through I2C the serial output is happily logging values. When running the Adafruit SSD1306 demo I have a clear display and snowflakes galore. However when I try to tie these three together via I2C and upload Arduino code, I do see the SSD1306 initialize with Adafruit logo - screen invert, etc., but once the QT Trinkey initializes (Neopixel color cycle starts) the SSD1306 goes black and no values are being written, yet they are still logging away in the Serial Monitor.

I did not find any references to this configuration in the Blog/Forum and couldn't locate the error in the device docs, as the syntax seems to be the same as other OLED writes in the example code, but the output just isn't displaying.

Much appreciated!
G2

Code: Select all

// SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
//
// SPDX-License-Identifier: MIT

/**************************************************************************/
/*!
This is a demo for the Adafruit QT2040 Trinkey and the MCP9808 temperature
sensor.
QT2040 Trinkey - https://www.adafruit.com/product/5056
MCP9808 - https://www.adafruit.com/product/5027
/**************************************************************************/
// Oct. 2022
// Including additional drivers and readout to Stemma QT Monochrome OLED 128x64
// Stemma QTMonochrome OLED 128x64 (SSD1306) - https://www.adafruit.com/product/326 
/**************************************************************************/
    #include <SPI.h>
    #include <Wire.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>
    
    #include "Adafruit_MCP9808.h"
    #include <Adafruit_NeoPixel.h>
  
    #define SCREEN_WIDTH 128 // OLED display width, in pixels
    #define SCREEN_HEIGHT 64 // OLED display height, in pixels
    
    // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
    // The pins for I2C are defined by the Wire-library. 
      // On an arduino UNO:       A4(SDA), A5(SCL)
      // On an arduino MEGA 2560: 20(SDA), 21(SCL)
      // On an arduino LEONARDO:   2(SDA),  3(SCL), ...
    #define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
    #define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
    Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);



// Create the neopixel strip with the built in definitions NUM_NEOPIXEL and
// PIN_NEOPIXEL
Adafruit_NeoPixel pixel =
    Adafruit_NeoPixel(NUM_NEOPIXEL, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);

// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 mcp9808 = Adafruit_MCP9808();

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
  0b00000001, 0b11000000,
  0b00000001, 0b11000000,
  0b00000011, 0b11100000,
  0b11110011, 0b11100000,
  0b11111110, 0b11111000,
  0b01111110, 0b11111111,
  0b00110011, 0b10011111,
  0b00011111, 0b11111100,
  0b00001101, 0b01110000,
  0b00011011, 0b10100000,
  0b00111111, 0b11100000,
  0b00111111, 0b11110000,
  0b01111100, 0b11110000,
  0b01110000, 0b01110000,
  0b00000000, 0b00110000 };

long previousMillis = 0;
long intervalTemp = 2000;
bool last_button = false;

void setup() {
  Serial.begin(115200);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...


    // Invert and restore display, pausing in-between
    display.invertDisplay(true);
    delay(1000);
    display.invertDisplay(false);
    delay(1000);
  

  Serial.begin(115200);
  delay(100);

 // pinMode(PIN_SWITCH, INPUT_PULLUP); // Setup the BOOT button

 pixel.begin();
 pixel.setBrightness(50);
 pixel.show(); // Initialize all pixels to 'off'

  if (!mcp9808.begin(0x18)) {
    Serial.println("Couldn't find MCP9808! Check your connections and verify "
                   "the address is correct.");
    while (1)
      ;
  }

  mcp9808.setResolution(3);
}

uint8_t j = 0;

void loop() {
  bool curr_button = !digitalRead(PIN_SWITCH);

  pixel.setPixelColor(0, Wheel(j++));
  pixel.show();

  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > intervalTemp) {
    previousMillis = currentMillis;
    // Read and print out the temperature.
    float c = mcp9808.readTempC();
    float f = mcp9808.readTempF();
    Serial.print("Temp: ");
    Serial.print(c, 4);
    Serial.print("*C\t and ");
    Serial.print(f, 4);
    Serial.println("*F.");

 //***************************************************************
 //  Everthing above seems to be fully functional until the following block.   Subsequent Button press and color wheel code *is functional.
 //***************************************************************
display.clearDisplay();
    display.setCursor(10, 10);
    display.setTextSize(2);
  display.print("Temp: ");
  display.print(c, 4);
  display.print("*C\t and ");
  display.print(f, 4);
  display.print("*F.");
  display.display();
  delay(2000);
 //***************************************************************
  }

  if (curr_button && !last_button) {
    Serial.println("Button pressed!");
  }
  if (!curr_button && last_button) {
    !Serial.println("Button released!");
  }
  last_button = curr_button;

  delay(10);
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if (WheelPos < 85) {
    return pixel.Color(WheelPos * 30, 255 - WheelPos * 30, 0);
  } else if (WheelPos < 170) {
    WheelPos -= 85;
    return pixel.Color(255 - WheelPos * 30, 0, WheelPos * 30);
  } else {
    WheelPos -= 170;
    return pixel.Color(0, WheelPos * 30, 255 - WheelPos * 30);
  }
}


User avatar
adafruit_support_carter
 
Posts: 29170
Joined: Tue Nov 29, 2016 2:45 pm

Re: QT Trinkey with mcp9808 sensor and SSD1306 OLED - No OLED values

Post by adafruit_support_carter »

Which specific SSD1306 OLED product are you using? Can you link to product page.

Which example code is the one that works?
https://github.com/adafruit/Adafruit_SS ... r/examples

User avatar
Gary2
 
Posts: 32
Joined: Wed Apr 06, 2022 1:00 am

Re: QT Trinkey with mcp9808 sensor and SSD1306 OLED - No OLED values

Post by Gary2 »

Apologies. I had listed the OLED model in the code, but omitted it from my request. The display is the Stemma QT Monochrome OLED 128x64 (SSD1306) - https://www.adafruit.com/product/326.

For this OLED, the test code successfully run was: https://github.com/adafruit/Adafruit_SS ... 128x64_i2c and also works as expected when inline through I2C connection with the QT and the mcp9808.

Connections:
[QT key USB —> mcp9808 —> #326 monochrome OLED 128x64]

Thank you for the prompt response!
- G

User avatar
adafruit_support_carter
 
Posts: 29170
Joined: Tue Nov 29, 2016 2:45 pm

Re: QT Trinkey with mcp9808 sensor and SSD1306 OLED - No OLED values

Post by adafruit_support_carter »

Thanks for the clarification.

Nothing super obvious in the code. As a quick test, try moving the text stuff to setup() and see if it shows up then. Can just leave out the actual variables. Just see if anything can show up.

For example, as last lines of setup():

Code: Select all

display.clearDisplay();
display.setCursor(10, 10)
display.setTextSize(2);
display.print("Temp: ");
display.print("*C\t and ");
display.print("*F.");
display.display();
delay(2000);

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”