Using OLED and rotary encoder on Micro

I am working on a project using the Arduino Micro. I have an OLED display and a rotary encoder to integrate as well as a number of LEDs. I have previously used a Nano for this project, but needed more digital I/O pins.

The challenge is that the Micro uses D2 & D3 to communicate to the OLED via I2C, but those pins are also used as pins for external hardware interrupts. On the Nano, these two functions are on different pins. Reading some posts here indicates that I should be able to use D0 & D1 as external interrupts without affecting the ability to connect with the Micro via USB for uploading and debugging.

But when I use D0 & D1 for interrupts, the sketch initially runs, but at some point hangs. So is the guidance on using D0 and D1 for interrupts not correct?

Is my only option to use Pin Change Interrupts?

Thanks in advance

Pin 0 and 1 on the Arduino Micro (or on the clone Pro Micro) are normal pins. It can be Serial1 port, it can be digital pins, they both have normal interrupts that attachInterrupt() can use.

There could be a bug in the sketch, or a library that does nasty things with pin 0 and 1, but that is not likely. I think that something else is going on.

How good is your I2C bus ? What is connected to it ? How long are the wires ? How much pullup do you have ? Do you use a flat ribbon cable with SDA next to SCL ? Are there 3.3V sensors connected to a 5V I2C bus ? Did you know that a OLED display can disturb the I2C bus for others ? That is what OLED displays do, unless you bought one from Adafruit.

Please read and use the advice in this link: How to get the best out of this forum - Using Arduino / IDE 1.x - Arduino Forum

All technical information needs to be provided. Words are not the way.

Koepel,

Thanks for the response. You asked a number of questions regarding the I2C bus. Here are my responses:

How good is my I2C bus? I currently have this circuit implemented using a solderless breadboard, with jumper wires, so it's probably not great.

What is connected to the I2C bus? Just one device - a 128x32 OLED display (not from Adafruit)

How long are the wires? The jumpers are about 6"

How much pullup do you have? When I wrote the email I had none (explanation below)

Do I use flat ribbon cable with SDA next to SCL? No, not at this point. Eventually, this circuit will be done as a PCB.

Are there 3.3V sensors connected to the bus? No, just the OLED

Did I know that an OLED display can disturb the I2C bus for others? No, I wasn't aware of this.

I did some reading and put 4.7k resistors from both SDA and SCL lines to 5V, and this so far seems to have resolved this issue. I had implemented the circuit based on the Nano using a design I found online which did not provide any pullups for the OLED. Prior to switching to the Micro, I breadboarded the circuit with a Nano (no pullups) and it worked fine. Then I removed the Nano and wired the Micro in making the needed connection changes.

I gather that the internal pullups on the Nano are different enough from those in the Micro to make a difference in the way the I2C bus operates. Lesson learned.

Thank you for the help.

Rick

The OLED displays work internally at 3.3V and it has a 3.3V I2C bus.
If you add pullup resistors to 5V, then it gets a little better for the 5V Arduino board and a little worse for the OLED display (but that is okay).

Adafruit adds a I2C level shifter for SDA and SCL to be compatible with both 3.3V and 5V Arduino boards. That is much better for the noise margin, but a level shifter also makes the I2C bus a little weaker.
It is a good idea if you add a I2C level shifter for the OLED, especially if you want to add more I2C devices later on.

The most important wire of the I2C bus is the GND wire. Once everything is on a PCB board, that problem is luckily gone.

I still have a feeling that you have not a good GND connection and too much noise. Do you use extra pullup resistors for the rotary encoder ? Don't rely on the internal pullup resistors.

In case the I2C bus has a problem, there is a timeout: setWireTimeout() - Arduino Reference
I suggest to add that as shown on that page.
If a I2C bus is so bad that the timeout is needed, then the timeout might not be enough to keep the project going, but using the timeout makes things better.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.