OLED Display with RSSI values and shape

Good day everyone ^^, we are trying to display the circle on the OLED once the received RSSI is greater than 0 however both the OLED and the serial monitor stops functionig together.. is OLED incompatible working with softwareSerial? I am getting RSSI value from HC-05 bluetooth module. Here is our codes. and thank you in advance for the replies

#include <SoftwareSerial.h>
SoftwareSerial bt(10,11);

#include <SPI.h>
#include <Wire.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     13
#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
Adafruit_SSD1306 display( OLED_MOSI,OLED_CLK,OLED_DC,OLED_RESET,OLED_CS);

//Define for delay
//unsigned long previousMillis = 0;
//const long interval = 100;
const int buttonPin1 = 2;
int buttonState1 = 0;

//Define for Data
char btData;
String splitString(String str, String devider, int arrayNumber);
String deviceAddress;
String deviceClass;
String deviceRSSI;
String message;

bool ATCommandsVisible = true;
bool RSSIVisible = true;
String atQuestEnd = "?\r\n";
String atSetEnd = "\r\n";
String atStart = "AT+";
String Version = "VERSION";
String Address = "ADDR";
String Name = "NAME";
String Role = "ROLE";
String UART = "UART";
//String State = "STATE";
//String Password = "PSWD";
//String Reset = "ORGL";
//String Initialize = "INIT";
//String accesCode = "IAC=9E8B33";
//String deviceType = "CLASS=0";
//String searchRSSI = "INQM=1,2,48";
//RSSI, limit of devices receivable(will find more of the same), max time spend searching *1.28
//String receiveRSSI = "INQ";
//String roleIsMaster = "ROLE=1";
//String roleIsSlave = "ROLE=0";
//String magnitude = " ";

void setup() {
  Serial.begin(9600);
  bt.begin(38400);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 
  display.clearDisplay();
  display.display();
  pinMode(buttonPin1, INPUT);
  
}
void loop() {
  buttonState1=digitalRead(buttonPin1);
  //unsigned long currentMillis = millis();
  bt.listen();
  if (bt.available()) {

    btData = bt.read();
    message.concat(btData);
    if (btData == '\n') {
      filterCode();
    }
    if (ATCommandsVisible) {
      Serial.write(btData);
    }
  }
 // if (currentMillis - previousMillis > interval) {
   // previousMillis = currentMillis;
    //}
  int receivedRSSI = pow((-(int(hexToDec(deviceRSSI)) - int(hexToDec("D666")))),0.45);

if (receivedRSSI > 0){
 drawcircle();
}
 
}
void drawcircle(){
  display.clearDisplay();

  for(int16_t i=max(display.width(),display.height())/2; i>0; i-=3) {
    // The INVERSE color is used so circles alternate white/black
    display.fillCircle(display.width() / 2, display.height() / 2, i, INVERSE);
    display.display(); // Update screen with each newly-drawn circle
    //delay(1);
  }

  //delay(2000);
}

void filterCode() {
  if (message.substring(0, 5) == "+INQ:") {
    deviceAddress = splitString(message, ",", 0).substring(5);
    deviceClass = splitString(message, ",", 1);
    deviceRSSI = splitString(message, ",", 2);
    if (RSSIVisible) {
      Serial.println(sqrt(-(int(hexToDec(deviceRSSI))-int(hexToDec("D666")))));
    }
  }
  message = "";
}

String splitString(String str, String devider, int arrayNumber) {
  int previousDevider = 0;
  int deviders = 1;
  for (int i = 0; i < str.length(); i++) {
    if (str.substring(i, i + devider.length()) == devider) {
      deviders++;
    }
  }
  int devideCounter = 0;
  String devidedString[deviders + 1];
  for (int i = 0; i < str.length(); i++) {
    if (str.substring(i, i + devider.length()) == devider) {
      if (devideCounter) {
        devidedString[devideCounter] = str.substring(devidedString[devideCounter - 1].length() + 1, i);
      } else {
        devidedString[0] = str.substring(0, i);
      }
      devideCounter++;
      previousDevider = i + devider.length();
    }
  }
  devidedString[devideCounter] = str.substring(previousDevider, str.length());
  if (arrayNumber > deviders) {
    return "ERROR; array number not found. Array number is to big.";
  } else {
    return devidedString[arrayNumber];
  }
}

unsigned int hexToDec(String hexString) { //converts HEX to DEC
  unsigned int decValue = 0;
  int nextInt;
  for (int i = 0; i < hexString.length(); i++) {
    nextInt = int(hexString.charAt(i));
    if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
    if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
    if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
    nextInt = constrain(nextInt, 0, 15);
    decValue = (decValue * 16) + nextInt;
  }
  return decValue;
}

ShadowSilver:
once the received RSSI is greater than 0

What device are you using that reports a positive RSSI ?

RSSI values are normally reported as negative dBm.

hi, sorry for the incomplete information. RSSI values are from HC-05 Bluetooth module

  bt.listen();

You only need to call listen() if you have more than one instance of the SoftwareSerial class.

char btData;

Why is this a global variable?

    if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);

Stupid.

    if (nextInt >= '0' && nextInt <= '9') nextInt -= '0';

Smart.

    nextInt = constrain(nextInt, 0, 15);

You should NOT be forcing an invalid value to be in some range. If the value is NOT in the proper range, there is an error. Do not try to resolve the error by pretending that the character was OK.

Your hexToDec() function is an attempt to write a better strtol() that is NOT better than the professionally written one. For one thing, it assumes that the input values are unsigned.

ShadowSilver:
hi, sorry for the incomplete information. RSSI values are from HC-05 Bluetooth module

Are the values actually positive?

Yes there where actually positive values ^^ . our only problem is on the "OLED Display" why it is not having a dispaly :slight_smile: thank you ^^

ShadowSilver:
is OLED incompatible working with softwareSerial?

No they will work together.

However you cannot run the softwareserial for the Bluetooth on the same pins that the display is using for its SPI connection.

we are using I2C OLED with pins of SCL and SDA

ShadowSilver:
we are using I2C OLED with pins of SCL and SDA

No your not. Check the code you posted.

can you please specify which part of the OLED codes are erroneous, the code for OLED is from the library of adafruit ssd1306 from arduino itself.

SoftwareSerial bt(10,11);
...
...
#define OLED_RESET     13
#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
Adafruit_SSD1306 display( OLED_MOSI,OLED_CLK,OLED_DC,OLED_RESET,OLED_CS);

You're trying to use OLED_CLK and OLED_DC for two different purposes.

ShadowSilver:
we are using I2C OLED with pins of SCL and SDA

Looks at the code you are using;

#define OLED_RESET     13
#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
Adafruit_SSD1306 display( OLED_MOSI,OLED_CLK,OLED_DC,OLED_RESET,OLED_CS);

Does any of that point to the SCL and SDA pins (of the I2C bus) being used to drive the OLED ?