Using two Oled with the same address on a teensy 3.5

Status
Not open for further replies.

dakman

New member
I've successfully connected two optical encoders to my teensy 3.5, as well as a oLED, 32x128 display, all is working great.
That said, the font size I have to use is quite small, for these 65 year old eye.

The simple fix is use a single display for my x and y data output, but alas, it seems that the two oleds, I'm using, have the same address, so the adafruit library that I'm using can't distinguish between the two.

I see teensy has a number of the SCL and SCA pins. Is there a library that allows me to use these same addressed displays, but have date sent to the SCA1 and SCL1 pins.

seems like a pretty simple thing to do, but not sure how to go about it.

Below is my current code, that is working quite well, but again, the x and y data is being displayed on a single oled... if somw code give me some example code for the new method, I would be most grateful.

be gentle boy and girls....:eek:


/* Encoder Library - TwoKnobs Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/

#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

double myX, myY;

#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>

Encoder xEncoder(5,6);
Encoder yEncoder(2,3);

void setup() {
// Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
//Serial.println("Two Encoder Test:");
display.clearDisplay();
// text display tests
display.setTextSize(2);
display.setTextColor(WHITE);

}

long xposition;
long yposition;
long newx, newy;


void loop() {

newx= xEncoder.read();
newy = yEncoder.read();

if (newx !=xposition || newy != yposition) {
display.setCursor(10,0);
display.print("X=");
display.println(newx/5.08/2400.0*25.4, 2);
display.setCursor(10,19);
display.print("Y=");
display.println(newy/5.08/2400.0*25.4, 2);
display.display();
display.clearDisplay();

xposition = newx;
yposition = newy;

}

}
 
This thread talks about using multiple i2c buses:

The simplest thing is to hook one display to pins 17/16 and the other to pins 19/18 (putting 4 pull-up resistors between each of the pins 16-19 and 3.3v), and switch in software whether you are talking to the standard i2c setup (pins 19/18) or the alternative setup (pins 17/16). See Paul's response in that thread about how to do it.

A second suggestion is to get an i2c multiplexer and use it to switch i2c bus is being connected.

You can use multiple i2c buses, but there you typically have to clone the library code and change Wire references to Wire1 (and don't forget the extra pull-up resistors).

Going to a larger screen like a 320x240 screen might allow you to put the information in separate areas.

Finally, since the OLED displays have SPI variants, you can switch one or more displays to SPI. For SPI, you typically need pins 11, 13 for MOSI0 and SCK, and you need 3 pins for CS, DC, and reset. With some displays, CS and DC might need to come from the set of hardware optimized CS pins (9, 10, 15, 20, and 21). Note some of us have discovered that at higher clock speeds, you might need to slow down the OLED bus speed.
 
Michael,

I think I'll just take the least painful path here and go with the slightly larger screen.

Thanks to everyone for chiming in .... great support for us folks with the lower level of understanding. :(
 
Status
Not open for further replies.
Back
Top