Hello,
I am working on a project that involves an Atmega32u4 connected to an I2C display. The 32u4 has the Arduino Leonardo bootloader installed, and is attached to a bare breakout board, as shown here.
Uploading over USB and running various code on it works just as expected so far, as well as USB CDC Serial. Trying to communicate with the display over I2C has led to a problem, however.
Running the following code,
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 0, 22, "Hello World!");
}
void setup(void) {
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(50);
}
...results in the device locking up and other unexpected results. Windows will then complain that the USB device has failed/has been disconnected. However, when using the same code on an Arduino Uno, everything works as expected. This problem is not limited to this display either. I have also tested a DS1307, and experienced the same problem.
After lots of experimentation, I found that not connecting the device to USB results in I2C working as expected. (the device was connected to power only, no USB data lines) I have also attempted installing Adafruit's Atmega32u4 breakout bootloader on the device. Unfortunately, it still resulted with the same exact situation. Since USB communications is one of the requirements of this project, I am unable to simply do away with it.
So basically, I2C and USB do not work at the same time on my Atmega32u4. Any help with solving this or any ideas would be greatly appreciated.