OLED display connected to Arduino and HC-05 prints notification info from phone twice instead of once

It works! It displays one message in both the serial monitor and the OLED display! Now that's not the end of it. Long messages are cut off short. I copied this from the serial monitor:

Matthew: Yes

Matthew: Just kidding I can get it to you tomorrow broo(the forum doesn't like the word meaning brother) I wa

Matthew: Hi

Matthew: Just kidding I can get it to you tomorrow broo(the forum doesn't like the word meaning brother) I wa

Matthew: Hi I just got your message me when you get a chanc

Matthew: Just kidding I can get it to you tomorrow broo(the forum doesn't like the word meaning brother) I wa

It's getting cut off at exactly 58 characters, and not just in the serial monitor or display, but also in the app!

This is just some gibberish by the way, here's the full message for the last message that's cut off:

Just kidding I can get it to you tomorrow broo I want to see if I could get expelled from the thumbnail on YouTube and I will be there in about you.

Dear @MasterfulMatthew ,
the length of the notifications could probably depend on this ?
What Are Push Notification Character Limits? [Cheat Sheet].
Otherwise, if the label on the App shows the complete text, while on Arduino the text is shown shorter, you need to dig the Arduino side. (I agree, it's trivial, but) I believe the first thing to verify is to individuate in which half (App or Arduino) the issue arises.

That could be a Bluetooth limitation between the Arduino and the App, you only have approx 20 to 23 bytes available for your data per packet, but I don't know of a Serial Monitor limit. Can you upload your Sketch file?

From Arduino:

"There is no limitation in serial monitor. It displays what it receives, character by character. There is however a limitation in the software buffer used by the Arduino hardware serial implementation (used by Serial.println) and that is indeed around 60 characters; "

So the easiest solution would be to feed the messages in short lengths.

On the app, it used to display the entire notification, but now it gets cut off on all 3 sides: the app, serial monitor, and display. Although there are no more duplicate notifications, only one, which I'm happy about.

CryptaGlassBluetoothWORKING.ino (1.5 KB)

Here you go man.

We're getting close to solving the issue.

Could you guide me on that?

Alright so here's my setup right now:
App has changes @ChrisWard suggested.
Arduino code is the same as the file shared.
I'm using an alt Discord account to send a message to my phone which the notification listener picks up and displays into the label and sends it over Bluetooth.

AT THIS MOMENT IN TIME:
For Discord at least, Label1 in the app displays the entire notification regardless of how long it is, here's the message I sent from my alt account on Discord:

You know, I'm coming for you, and when I do find you, there will be nothing left. You'll just be ashes. No one will find you. Mark my words, mark my words. You know, I'm coming for you, and when I do find you, there will be nothing left. You'll just be ashes. No one will find you. Mark my words, mark my words. You know, I'm coming for you, and when I do find you, there will be nothing left. You'll just be ashes. No one will find you. Mark my words, mark my words.

What gets displayed in Label1 on the app:

ilikeminecraft: You know, I'm coming for you, and when I do find you, there will be nothing left. You'll just be ashes. No one will find you. Mark my words, mark my words. You know, I'm coming for you, and when I do find you, there will be nothing left. You'll just be ashes. No one will find you. Mark my words, mark my words. You know, I'm coming for you, and when I do find you, there will be nothing left. You'll just be ashes. No one will find you. Mark my words, mark my words.

What I see on both the serial monitor and OLED display:

ilikeminecraft: You know, I'm coming for you, and when I do fin

That's 63 characters.

EDIT: With "\n" wouldn't that be exactly 65 characters? Keep in mind the app is displaying the complete notification, at this moment in time, and it's only the serial monitor and OLED that's getting cut off.

EDIT 2: I've been testing for 10 minutes, results are staying constant.

I think that the readstring() in your Arduino code could be foolished by some \n embedded into the notification.
I would rather suggest the following:
image
Please be aware that the UART running @9600 means 1 ms for each byte, therefore the delayMicroseconds(nnn) can be useless or, on the opposite side, mandatory depending on the BT buffer refilling. Anyway you can trim accordingly the value (if you see that there is an improvement or a worsening).

Another clue is about the use of RAM memory by the display: the whole display map is contained in the Arduino board RAM, therefore if the available quantity is not enough, and you use Strings (that normally use a lot of RAM on their side) you could fall into unpredictable behaviours because of memory overlap (I've got crazy before understanding this issue in an application of mine a time ago with an UNO board).

I got a bunch of numbers:
105108105107101109105110101991149710211658321121081019711510132119111114107

This is the message that got sent from the app to the Bluetooth module:
ilikeminecraft: please work

EDIT: My huge brain tells me that these numbers are ASCII.

Message: jk
Serial monitor: 106107
ASCII for j: 106
ASCII for k: 107

EDIT 2:

I'm smort.

1 Like

This code... works... finally...
It displays the full message in all 3 places!

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

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

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

SoftwareSerial BTserial(9, 8); // RX | TX

void setup() {
  BTserial.begin(9600);
  Serial.begin(9600);

  // Initialize the display with 128x32 pixels
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("System Ready");
  display.display();
}

void loop() {
  String val = "";
  // Keep reading from HC-06 and display on OLED
  if (BTserial.available()) {
    while (BTserial.available()) {
      val += BTserial.readString();
      //delayMicroseconds(500);
    }

    Serial.println(val);

    display.clearDisplay();
    display.setTextSize(1);             // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);        // Draw white text
    display.setCursor(0,0);             // Start at top-left corner
    display.println(val);
    display.display();
  }
}
1 Like

I will make sure everything works on all chatting platforms before marking this post as solved.

Dear @MasterfulMatthew,
nice to see that you have used (approx.) my algorithm.
Most probably the notification contains the \n (ASCII Linefeed: 0x0A or 10 decimal) character that stops the receiving when encountered by the readstring(). But the modified algorithm retries to get new data as they are still incoming, so, by repeating the readstring() until BTserial.avaialble is true, deosn't interrupt the received sentence. And in this case you don't need the delayMicroseconds.
Good job !

That's a point. Char[x] string uses less memory than String. Also, 'val' could be populated by Serial.readStringUntil(), with an imposed end of string character. The target though should be to update the Serial Monitor with short strings, so I'm thinking that would be easiest to achieve if the App sent short strings.

Isn't this pretty much the same as before?

val += BTserial.readString();

val becomes one long string that could exceed the Serial Monitor buffer limit?

Another thing of interest, about which I know nothing, is the OLED display - is there a maximum number of characters it can display or does the first part of a message roll off, to be replaced by the next part, like a typewriter?

using BTserial.read() gave me ASCII numbers, that's why I altered your suggested code. But hey, you were to spark to solving it.

1 Like

I'm already almost done making a scroll function. I'm going to make a full Youtube tutorial and blogpost somewhere (not sure what platform yet), but I'm going to share all my experiences, issues, solutions and workarounds.

1 Like

Dear @MasterfulMatthew,
thanks for sharing this detail ! Honestly I didn't try my hypotesis of solution on a real HW, but the way to receive long messages on the BT that I've suggested you is the same that I've used many times. The weird thing is that the issue of receiving numbers (the ASCII codes) instead of true characters does never happened to me. :thinking:
Anyway, I'm happy that it works for you with the readstrng !!! :grimacing:
Cheers.

Everything works on all chatting platforms! This setup will work with ANY notification. If anyone has this problem or wants to display phone notifications on an OLED display via a Bluetooth module and Arduino Pro Micro, simply follow this forum. You could use this for say, a pair of smart glasses or a smart watch. If anything is unclear, please contact me directly!

4 Likes

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