olikraus / u8glib

Arduino Monochrom Graphics Library for LCDs and OLEDs
https://github.com/olikraus/u8glib/wiki
Other
1.25k stars 314 forks source link

Arduino I2C internal pullup enable option - report on my hack #363

Open clowrey opened 9 years ago

clowrey commented 9 years ago

Using SSD1306 based 128x64 I2C display + arduino Uno Worked fine with the Adafruit library and others that use the default Arduino Wire library.

Eventually after pulling my hair out for awhile I figured out it was because the default arduino library turns on the internal pullup resistors in the atmega chip, and my display has no pull-ups on the PCB (I designed it ;)...

Here is the modified file: http://hilo90mhz.com/wp-content/uploads/2015/09/u8g_com_i2c.c Only changes are right here starting at line 96 - I just added in the code from the default arduino library that turns on the pullups, the inclusion of Arduino.h is necessary for the SCL and SDA defintion :

#include "Arduino.h" // for digitalWrite SCL and SDA definitions

void u8g_i2c_init(uint8_t options)
{
   digitalWrite(SDA, 1); // activate internal pullups for twi.
   digitalWrite(SCL, 1);

Perhaps this could be added as one of your setup options like? "U8G_I2C_OPT_DEV_0"

Also it would be great to have a way to set the I2C address of the display with the config options :) I figured out how to edit the u8g_com_arduino_ssd_i2c.c file to change that to 0x3d for my display.

Thanks for the great library!