T4 with SSD1306 on alternate i2c (SDA1/SCL1)

Status
Not open for further replies.

TeensyWolf

Well-known member
I goofed on my PCB, using SDA1/SCL1 instead of SDA/SCL, but having trouble getting it to work with hardware i2c, when using 2ND_HW_I2C. I tried the HW_I2C also.

The following only works in SW_I2C

Code:
#include <Arduino.h>
#include <U8x8lib.h>

//U8X8_SSD1306_128X64_NONAME_2ND_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);  // does not work
//U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);  // for primary 
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(16, 17, U8X8_PIN_NONE);  // for T4 2nd I2C, this works

void setup() {
    u8x8.begin();
    u8x8.setPowerSave(0);
    u8x8.setFont(u8x8_font_courB18_2x3_f);
    u8x8.setCursor(0,0);
    u8x8.println("hi world");
}

I tried same thing with the u8g2
Code:
#include <Arduino.h>
#include <U8g2lib.h>

// Graphics U8G2
//U8G2_SSD1306_128X64_NONAME_1_2ND_HW_I2C u8g2( U8G2_R0, U8X8_PIN_NONE );  //[page buffer, size = 128 bytes] - not working
U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2( U8G2_R0, 16 , 17 , U8X8_PIN_NONE ); // [page buffer, size = 128 bytes] working

void setup() {
    u8g2.begin();
    u8g2.clearBuffer();	
    u8g2.setFont(u8g2_font_ncenB08_tr);
    u8g2.drawStr(1,8,"Hello World!");
    u8g2.sendBuffer();
}

What can I do to get hardware i2c working here?
 
have you found a solution to your problem? I'm having a similar issue, only I can't get the U8x8 library to display anything on my SSD1306 display. I'm using the 938 OLED from adafruit. I've written to the author of the library, but so far we haven't figured out a solution
 
have you found a solution to your problem? I'm having a similar issue, only I can't get the U8x8 library to display anything on my SSD1306 display. I'm using the 938 OLED from adafruit. I've written to the author of the library, but so far we haven't figured out a solution

I ended up just using software i2c on that board, until I'm able to rev it. I didn't spend too much time digging into it, the Teensy is fast and it worked ok.
 
Have you looked at using the Adafruit library? Adafruit_SSD1306

One of it's constructors:
Code:
  Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi = &Wire,
                   int8_t rst_pin = -1, uint32_t clkDuring = 400000UL,
                   uint32_t clkAfter = 100000UL);
so you should be able to define it like small delta from their example:
Code:
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#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, &Wire1, OLED_RESET);
 
I ended up finding a solution with the help of someone on r/teensy. The solution we found was two fold: first, I needed to manually define the address that the display was using, and then the address had to be bit shifted by 1 position. So the line
Code:
display.setI2CAddress(0x3D<<1);
got the code to work
 
Interesting, are you using SDA1/SCA1 with 2ND_HW_I2C?

I can understand the need to define the address, but curious what's the reason for the bitshift?

I'll try that next time I'm on that project, will report back.
 
Interesting, are you using SDA1/SCA1 with 2ND_HW_I2C?

I can understand the need to define the address, but curious what's the reason for the bitshift?

I'll try that next time I'm on that project, will report back.

IIRC, in the actual I2C protocol, the slave address is 7 bits, and the bottom bit is 0/1 depending on whether this is a read/write request (0 is a write request from the master to the slave, 1 is read request asking the slave for data). Most Arduino libraries do the shift within the library when setting up the I2C request. Evidently the software on the board does not do this shift automatically.
 
Status
Not open for further replies.
Back
Top