Teensy 3.2 wont compile with SSD1306 program

Status
Not open for further replies.
Recently I purchased an Adafruit SSD1306 128 x 64 Monochrome OLED display and connected it to a Teensy 3.2 to try and get it up and running as a small display for a temperature measurement project.

following the guide for Monochrome OLED breakouts and trying to run in I2C mode I did the following:

Downloaded the latest Adafruit GFX library from Github 1.2.2

And downloaded the Adafruit_SSD1306 library and loaded them into my Arduino library folder by .zip extraction

And then the example program 128 x 64 I2C would not compile so edited the .h file to suit 128 x 64 and ran the i2c scanner and saw the device address was
0x3D so changed the define from 0x3C to 0x3D

Code:
/*********************************************************************
This is a library for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

These displays use SPI to communicate, 4 or 5 pins are required to  
interface

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!

Written by Limor Fried/Ladyada  for Adafruit Industries.  
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#ifdef __SAM3X8E__
 typedef volatile RwReg PortReg;
 typedef uint32_t PortMask;
#else
  typedef volatile uint8_t PortReg;
  typedef uint8_t PortMask;
#endif

#include <SPI.h>
#include <Adafruit_GFX.h>

#define BLACK 0
#define WHITE 1

#define SSD1306_I2C_ADDRESS   0x3D	// 011110+SA0+RW - 0x3C or 0x3D
// Address for 128x32 is 0x3C
// Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)

/*=========================================================================
    SSD1306 Displays
    -----------------------------------------------------------------------
    The driver is used in multiple displays (128x64, 128x32, etc.).
    Select the appropriate display below to create an appropriately
    sized framebuffer, etc.

    SSD1306_128_64  128x64 pixel display

    SSD1306_128_32  128x32 pixel display

    -----------------------------------------------------------------------*/
#define SSD1306_128_64
//   #define SSD1306_128_32
/*=========================================================================*/

#if defined SSD1306_128_64 && defined SSD1306_128_32
  #error "Only one SSD1306 display can be specified at once in SSD1306.h"
#endif
#if !defined SSD1306_128_64 && !defined SSD1306_128_32
  #error "At least one SSD1306 display must be specified in SSD1306.h"
#endif

#if defined SSD1306_128_64
  #define SSD1306_LCDWIDTH                  128
  #define SSD1306_LCDHEIGHT                 64
#endif
#if defined SSD1306_128_32
  #define SSD1306_LCDWIDTH                  128
  #define SSD1306_LCDHEIGHT                 32
#endif

#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6

Tried to compile and got:

Arduino: 1.6.13 (Windows 7), TD: 1.33, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz optimize speed (overclock), US English"

WARNING: Category 'Real-time clock' in library DS3231 is not valid. Setting to 'Uncategorized'
C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp: In member function 'virtual void Adafruit_SSD1306::drawPixel(int16_t, int16_t, uint16_t)':

C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:123:14: error: 'swap' was not declared in this scope

swap(x, y);

^

C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp: At global scope:

C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:402:6: error: prototype for 'void Adafruit_SSD1306::dim(boolean)' does not match any in class 'Adafruit_SSD1306'

void Adafruit_SSD1306::dim(boolean dim) {

^

In file included from C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:28:0:

C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.h:142:8: error: candidate is: void Adafruit_SSD1306::dim(uint8_t)

void dim(uint8_t contrast);

^

C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp: In member function 'virtual void Adafruit_SSD1306::drawFastHLine(int16_t, int16_t, int16_t, uint16_t)':

C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:526:16: error: 'swap' was not declared in this scope

swap(x, y);

^

C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp: In member function 'virtual void Adafruit_SSD1306::drawFastVLine(int16_t, int16_t, int16_t, uint16_t)':

C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:594:16: error: 'swap' was not declared in this scope

swap(x, y);

^

Error compiling for board Teensy 3.2 / 3.1.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Can anyone help?

I did set the addresses on the solder pads and it will scan and show 0x3D

Thanks

Jim the Kiwi
 
Looks like, you have your own version of the Adafruit library C:\Users\Jim V\Documents\Arduino\libraries\Adafruit_SSD1306\Ada fruit_SSD1306.cpp

You might try removing it and see if it builds. That is Teensyduino installs a version of that library, but as you have a version in your Sketch folder / library directories, Arduino chooses to use that one instead.

Looking at the Teensyduino version, I am guessing is they removed the usage of swap, by putting a simple macro at the top of the CPP file:
#define ssd1306_swap(a, b) { int16_t t = a; a = b; b = t; }

And change the references of swap to ssd1306_swap

EDIT: Actually looking at the Adafruit current sources I believe it is using the macro I mentioned, so if you don't wish to use the Teensy specific version, you should update the one in your library folder
 
Status
Not open for further replies.
Back
Top