SSD1306 and ADS1115 on ATTinyCore ......... SOLVED!!!!

Hello everyone,
I have something which is annoying when I connect an 2.42" OLED (SSD1306) and ADS1115 breakout board to ATTiny84.

I tested them separate, they worked, but together… NO WAY >:( >:( >:(

Here’s my code for the OLED

#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
#define RST_Pin 5


void setup() {
  pinMode( RST_Pin, OUTPUT);
  digitalWrite(RST_Pin, LOW);
  delay (500);
  digitalWrite( RST_Pin, HIGH);
  ssd1306_setFixedFont(ssd1306xled_font6x8);
  ssd1306_128x64_i2c_init();
  ssd1306_clearScreen();
}

void loop() {
  ssd1306_setFixedFont(ssd1306xled_font6x8);
  ssd1306_clearScreen();
  ssd1306_printFixed(0,  0, "TEST", STYLE_NORMAL);
  delay(1000);
}

And here’s the code for ADS1115

#include <Wire.h>
#include <SoftwareSerial.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;

void setup(void) {
  Serial.begin(9600);
  ads.begin();
}

void loop(void) {
  int16_t results = ads.readADC_Differential_0_1();
  float multiplier = 0.1875F;
  int Voltage = results * multiplier;
  Serial.println(Voltage);
  delay(1000);
}

As I said before, both codes works.

But when I combine the two… the OLED display messes up and the ADC stops getting values (or showing results).

#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;
#define RST_Pin 5

void setup(void) {
  Serial.begin(9600);
  ads.begin();
  pinMode( RST_Pin, OUTPUT);
  digitalWrite( RST_Pin, LOW);
  delay (1500);
  digitalWrite( RST_Pin, HIGH);
  ssd1306_setFixedFont(ssd1306xled_font6x8);
  ssd1306_128x64_i2c_init();
  ssd1306_clearScreen();
}

void loop(void) {
  int16_t results = ads.readADC_Differential_0_1();
  float multiplier = 0.1875F;
  int Voltage = results * multiplier;
  ssd1306_clearScreen();
  ssd1306_printFixed(0,  0, Voltage, STYLE_NORMAL);
  Serial.println(Voltage);
  }
  
  
  delay(1000);
}

By the way the OLED I2C address is 0x3C. ADC I2C address is 0x48 as long as ADDR pin is connected to GND. I’m using also as mentioned Dr.Azzy cores GitHub - SpenceKonde/ATTinyCore: Arduino core for ATtiny 1634, 828, x313, x4, x41, x5, x61, x7 and x8

Any help is very welcome!

Regards,
Tommy

sova.cpp (6.3 KB)

sova.h (1.33 KB)

My guess: not enough RAM. As you failed to provide links to the used libraries I have no chance to check that.

pylon:
My guess: not enough RAM. As you failed to provide links to the used libraries I have no chance to check that.

Sketch uses 5658 bytes (69%) of program storage space. Maximum is 8192 bytes.
Global variables use 181 bytes (35%) of dynamic memory, leaving 331 bytes for local variables. Maximum is 512 bytes.

ADS1115 lib GitHub - adafruit/Adafruit_ADS1X15: Driver for TI's ADS1015: 12-bit Differential or Single-Ended ADC with PGA and Comparator
SSD1306 lib GitHub - lexus2k/ssd1306: Driver for SSD1306, SSD1331, SSD1351, IL9163, ILI9341, ST7735, PCD8544, Nokia 5110 displays running on Arduino/ESP32/Linux (Rasperry) platforms

If you read the Key Features in the lib page, it said Needs very little RAM (Attiny85 with Damellis package needs minimum 25 bytes of RAM to communicate with OLED)

Thank u in advance

The addition of the ADC library should only cost a few bytes, so the probability of a memory overrun isn't that high.

Just to check that: all three sketches were run on exactly the same hardware setup, so the LCD and the ADC were always connected.
It this were not the case, post links to the used hardware (not the chips but the actual boards) and it's schematics. Also post a wiring diagram.

pylon:
The addition of the ADC library should only cost a few bytes, so the probability of a memory overrun isn’t that high.

Just to check that: all three sketches were run on exactly the same hardware setup, so the LCD and the ADC were always connected.
It this were not the case, post links to the used hardware (not the chips but the actual boards) and it’s schematics. Also post a wiring diagram.

Thank u for reply. My hardware setup is OK, because I don’t move anything or any wire, without just uploading new cods and see the resualts.

Here’s a little schematic which isn’t perfect but very clear I guess

Which board carries the pull-ups?

With the combined code do you still get serial output or does the Tiny freeze?

pylon:
Which board carries the pull-ups?

What do u mean?

pylon:
With the combined code do you still get serial output or does the Tiny freeze?

I guess the ADC freezes, but the OLED messes up!

The I2C bus needs pull-ups exactly once per bus. If the ADC and the OLED have pull-ups or if both don't have them it might lead to communication problems.

I guess the ADC freezes, but the OLED messes up!

I ask again without an additon: does the combined code still produce serial output? If yes, please post the complete output!

pylon:
The I2C bus needs pull-ups exactly once per bus. If the ADC and the OLED have pull-ups or if both don’t have them it might lead to communication problems.

yaha… now I got what u mean!
Yes, I made a little inspection and as it’s shown in the 2 pics… SCL and SDA pin for the LCD are both pulls up with 4.6K and for the ADC are the both pins also pulls up with 10K

pylon:
I ask again without an additon: does the combined code still produce serial output? If yes, please post the complete output!

OK. I disconnected the OLED LCD and kept the ADC connected and connected the uC to Arduino nano through Software Serial. It works!

Here’s my code for ATTiny84

#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;
#include <SoftwareSerial.h>
#define RxPin   9
#define TxPin   10
#define led1   0
#define led2   1
SoftwareSerial mySerial(RxPin, TxPin);
String Value = "" ;
void setup(void) {
  mySerial.begin(9600);
  ads.begin();
}

void loop(void) {
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  int16_t results;
  results = ads.readADC_Differential_0_1();
  float multiplier = 0.1875F;
  int Voltage = results * multiplier;
  Value = Voltage ;

  if (Voltage < 3000) {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, LOW);
    mySerial.println("V= " + Value);
  }
  if (Voltage > 3000) {
    digitalWrite(led2, HIGH);
    digitalWrite(led1, LOW);
    mySerial.println("V= " + Value);
  }
  delay(1000);
}

I added two leds so I can check if it works without looking at the serial monitor.

Here’s my code for the Arduino nano

#include <SoftwareSerial.h>
const byte RxPin = 2;
const byte TxPin = 3;
SoftwareSerial mySerial (RxPin, TxPin);
String Incomming = "" ;
String Result = "" ;
String Value = "" ;
void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  Serial.setTimeout(100);
  mySerial.setTimeout(100);
}
void loop() {
  if (mySerial.available ()) {
    Incomming = mySerial.readString();
    Incomming.trim();
    Serial.println(Incomming);
  }
}

Here’s the ouput. I tested many voltages between 0 and 5v

V= 4450
V= 4448
V= 4449
V= 4455
V= 4454
V= 4456
V= 591
V= 0
V= 0
V= 0
V= 0
V= 599
V= 2373
V= 2374
V= 2376
V= 2374

Is that what u asked me to do Pylon?

I solved it!

A guy had the same problem but with ATTiny85 and the solution was some definitions which the library guy, lexus2k/ssd1306 fixed it.

I copied and pasted the whole definitions and just changed X5 to X4 so it will be something like this:

#elif defined(ARDUINO_AVR_ATTINYX4)

    /** The macro is defined when software i2c implementation is available */
    #define CONFIG_SOFTWARE_I2C_AVAILABLE
    /** The macro is defined when i2c Wire library is available */
    #define CONFIG_PLATFORM_I2C_AVAILABLE
    /** The macro is defined when USI module is available for use */
    #define CONFIG_USI_SPI_AVAILABLE
    /** The macro is defined when SPI library is available */
    #define CONFIG_PLATFORM_SPI_AVAILABLE
    /** Define lcdint as smallest types to reduce memo usage on tiny controllers. *
     * Remember, that this can cause issues with large lcd displays, i.e. 320x240*/
    #define LCDINT_TYPES_DEFINED
    /** This is for Attiny controllers */
    typedef int8_t lcdint_t;
    /** This is for Attiny controllers */
    typedef uint8_t lcduint_t;
    /** The macro is defined when micro controller doesn't support multiplication operation */
    #define CONFIG_MULTIPLICATION_NOT_SUPPORTED

from line 93 to line 111 in the file io.h

For more, read this please Communication with other I2C devices · Issue #48 · lexus2k/ssd1306 · GitHub

Anyway, thank you Pylon. And hope this topic will help someone with the same problem.
Regards,
Tommy