Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP8266: I2C transmission rate stays at 100kHz #80

Closed
KarateBrot opened this issue Apr 22, 2017 · 3 comments
Closed

ESP8266: I2C transmission rate stays at 100kHz #80

KarateBrot opened this issue Apr 22, 2017 · 3 comments

Comments

@KarateBrot
Copy link

KarateBrot commented Apr 22, 2017

Adafruit_SSD1306.cpp, line 461 - 464

#ifdef TWBR
  uint8_t twbrbackup = TWBR;
  TWBR = 12; // upgrade to 400KHz!
#endif

When using ESP boards these lines seem to get ignored so the I2C rate stays at 100 kHz.

The problem here is that Adafruit_SSD1306::display takes way too long to transmit data with 100 kHz and therefore yielding only ~10 fps on my display which is way too slow. You can actually see every frame building up. 🐌

I tried this on a WeMos D1 Mini (4MB) and on a NodeMCU.


  • How I fixed it

In void setup(){} I inserted Wire.setClock(400000L); to successfully get 400 kHz on my ESP boards and ~30 fps on my display.

void setup()
{
  Wire.setClock(400000L);
}
  • Possible solution

Add code to Adafruit_SSD1306.cpp, line 465:

#ifdef TWBR
  uint8_t twbrbackup = TWBR;
  TWBR = 12; // upgrade to 400KHz!
#endif
 
#ifdef ESP8266
  Wire.setClock(400000L);
#endif

Additionally:

In this case an 800 kHz transmission rate seems to be the maximum. By calling Wire.setClock(800000L); ~60 fps can be achieved on SSD1306 OLEDs using an ESP8266. That's nearly a sixfold increase in drawing speed! compared to what's possible out of the box right now.

@KarateBrot KarateBrot changed the title I2C transmission rate stays at 100kHz on ESP8266 ESP8266: I2C transmission rate stays at 100kHz Apr 22, 2017
@guru-florida
Copy link

guru-florida commented Sep 28, 2018

As suggested above, adding this to Adafruit_SSD1306 worked for me. My drawing went from 112ms to 30ms...9fps to 30fps! Thanks @KarateBrot !! Now my ECG heart monitor is graphing my heartbeat smoothly!

#ifdef ESP8266
  Wire.setClock(800000L);
#endif

Trying to set in setup() didnt work. The Adafruit lib (or Wire) resets it back to 100k.

@KarateBrot
Copy link
Author

Trying to set in setup() didnt work. The Adafruit lib (or Wire) resets it back to 100k.

It only worked for me if I put the function call at the end of the Setup() routine.
This way Wire.setClock() ultimately overrides the Wire settings no matter what.

@PaintYourDragon
Copy link
Contributor

Library v1.2 incorporates faster I2C transfers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants