Using SSD1306Ascii on Wire1, Wire2

This is an extract from SSD1306AsciiWire.h in the SSD1306Ascii library:

#include "SSD1306Ascii.h"
/**
 * @class SSD1306AsciiWire
 * @brief Class for I2C displays using Wire.
 */
class SSD1306AsciiWire : public SSD1306Ascii {
 public:
#if MULTIPLE_I2C_PORTS
  /**
   * @brief Initialize object on specific I2C bus.
   *
   * @param[in] bus The I2C bus to be used.
   */
  explicit SSD1306AsciiWire(decltype(Wire)& bus = Wire) : m_oledWire(bus) {}
#else  // MULTIPLE_I2C_PORTS
#define m_oledWire Wire
#endif  // MULTIPLE_I2C_PORTS

I think this means I can tell the library to use Wire1, Wire2 etc if MULTIPLE_I2C_PORTS has been defined.

I'm trying to use this on Teensy 3.6 where MULTIPLE_I2C_PORTS is defined, but I can't figure out the correct syntax.
For example this compiles and uses the default I2C bus on Wire no problems:

SSD1306AsciiWire oled;

but this won't even compile:

SSD1306AsciiWire(&Wire2) oled;

suggestions? :slight_smile:

The constructor takes a reference to an object of the same type as the Wire object. Get rid of the '&' and put the argument in the correct place:

SSD1306AsciiWire oled(Wire2);
1 Like

If you mention something, please give a reference.
It is the "SSD1306Ascii" library from the Library Manager.
That is this library: https://github.com/greiman/SSD1306Ascii

I don't know where the documentation is located, so I downloaded a zip file from that repository and read the doc files.

I think it uses "by reference", which is default "Wire".
Can you try:

SSD1306AsciiWire(Wire2) oled;

[EDIT] Oops, it took me some time to figure it out, meanwhile gfvalvo already solved it

that works a treat, thank you sir.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.