Adafruit_SSD1306, radio.h and RDA5807M.h I2C problem?

Hi all

Please consider I have no education in this matter and I will be a novice for ever :wink:

Having trouble with the combination of a radio module (RDA5807M) and an OLED 0.96" display (SSD1306).

There is apparently more than one usage of Adafruit_SSD1306.h. In the examples Adafruit provides, the SSD1306 is declared as follows:

#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

In another sketch I found this:

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

Problem with the second method is: the OLED display seems to skip every other line(a problem more than once found on fora), lowering the vertical resolution and causing vertical stretching of text and bitmaps.

This can be solved by using the first method, on other sketches I made this way the screen is used correctly, but adding the code for the radio makes the display not starting up and causes the radio module to restart every 2 or so seconds.

This is the code with working radio and wrongly but working display (incomplete project: this is just a test). The lines causing trouble are commented out.

#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <RDA5807M.h>

#define FIX_BAND RADIO_BAND_FM   

int setButton = 5;
int backButton = 6;
int potPin = A7;

/*
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

*/
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);


RDA5807M radio;

int stations[12] = {9110,9190,9270,9350,9570,9830,10010,10280,10400,10480,10640,10710};

void setup() {
  pinMode(backButton, INPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 
  display.display();
  delay(2000);
  display.clearDisplay();
    
  radio.init();
  radio.setBandFrequency(FIX_BAND, 9570);
  radio.setVolume(4);
  radio.setMono(true);
  radio.setMute(false);
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print(" 95,70");
  display.display();
  while(1);
}

void loop() {
  /*if(digitalRead(backButton)==HIGH){
    setFrequency();
  
  }
*/
}

void setFrequency(){
  float displayStation;
  int stationNum, val;
  radio.setMute(true);
  while(digitalRead(setButton) != HIGH){
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.print("Select Station");
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(20,10);
    val = analogRead(potPin);
    stationNum = map(val, 0, 1023, 0, 11);
    displayStation = stations[stationNum]/100.0;
    display.print(displayStation);
    display.display();
    display.clearDisplay();
  }
  delay(500);
  radio.setBandFrequency(FIX_BAND, stations[stationNum]);
  radio.setMute(false);
  display.setCursor(20,10);
  display.print(displayStation);
  display.display();
  display.clearDisplay();
}

/*void adjustVolume(){
  while(digitalRead(setButton) != HIGH){
    val = analogRead(potPin);
    vol = map(val, 0, 1023, 0, 15);
    radio.setVolume(vol);
    display.clearDisplay();
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(20,25);
    display.print(vol);
    display.display();
}
}*/

Uncommenting one method and commenting the second (see code below) prevent both screen and radio module to work at all:

// this is the code causing trouble:

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// this is the code making the radio display work (however wrongly: display only uses half the vertical resolution)
// #define OLED_RESET 4
// Adafruit_SSD1306 display(OLED_RESET);

Setup:

Arduino Pro Mini
SSD1306 0.96" OLED
RDA5807M radio module

OLED and Radio get 3.3V from the Pro Mini. (I2C levels are 3.3V too)
On the picture you see the ‘stretched’ screen resolution.

Thank you for having a look.

Regards
Jan

Hi there,

I am having precisely the same problems as you have. What I found so far is that the constructor

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

has been deprecated and should not be used, check the header file Adafruit_SSD1306.h.

I am using I2C to communicate and therefore should not have to use reset but apparently you have to, still not sure how and why.

I tried to change the port to another port or -1 but it does not seem to work, the only pin it functions on is pin 4.

If you have more clarity please let me know. This reset pin or the library does not make sense at all.