Photon i2c issues - ADS1115 influence SSD1306

Dear Community,

in my setup I have a SSD1306 OLED display and an ADS1115 4-channel Analog Digital Converter working on i2c. Each for it self works properly. When I bring both together the display messes up and die ADC values get worse.

For both I’m using the libraries provided by the Particle IDE. They are also on different addresses OLED on 0x3C and ADC on 0x48;

Any idea where to start trouble shooting?

I did some tests and it seams the issue relates to a software timer. The timer is used to measure every second a voltage by the ADS1115.

Any thoughts on that?

@r-morgenstern, software timers are like interrupt service routines. The issue is that the I2C peripheral is unique and if the timer fires during an I2C transaction to the display, it will “clobber” that transaction while doing the ADS1115 transaction. You have two choices:

  1. Set/reset a global “mutex” (mutual exclusivity) flag every time the timer or the display code interacts with the I2C. Check the flag prior to any I2C transaction and skip if the flag is set.

  2. Use a non-blocking timer (using millis()) in loop() or set a flag in the software timer that you can sample in loop(). When it is set, do the ADC sampling.

I suggest the second choice since it is simple and easy to implement. :wink:

3 Likes

@peekay123 Thank you. I did your second suggestions. It works perfect now and timing seams also ok without timer!

1 Like

Hi could be possible to get the code? I met the same issue. Thank you