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

So I made a simple app that reads notifications (extension made by Taifun), and sends the info to an arduino via Bluetooth. Let's say I get a notification like this on my phone:
Youtube
You got a like

The display would print:
Youtube
You got a likeYoutube
You got a like

The Arduino code is perfectly fine, I tried testing with the app called Serial Bluetooth and the display shows one message as it should. I probably just need a way to format the notification contents better in App Inventor.

Hello, I tried sending a message on Discord, it works, only prints on the display once. With SMS it prints twice. With LINE it prints twice. Other apps like Youtube too.

EDIT: Google Chat also prints correctly.

Messages are from LINE. Prints twice.

Where does the Notification come from? It may be that is received twice, thus sent twice.

You can prevent the sending of an identical text by comparing the current text with the previous text, like so (I don't have the extension):

blocks

1 Like

When it prints any notification into Label1, there is no duplicate and it prints fine. It only happens in the Arduino serial monitor and the OLED display I'm using.

In the app:
Matthew: Hello there, testing 123.

In the Arduino serial monitor:
Matthew: Hello there, testing 123.Matthew: Hello there, testing123.

Sometimes the notifications are cut off in the serial monitor and OLED display. I have resistors between the HC-05 bluetooth module and the Arduino Pro Micro, and the code and bluetooth module work fine when testing with the Serial Bluetooth app.

Maybe you could give everything a try. If you could, then I'll gladly give you some guides on how to replicate my exact setup.

I'll try this.

By the way, I changed the app so that there is a ": " between the title and text variables.

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.