Problem with HM-10 Bluetooth Module communication with Arduino UNO

Hey guys, I'm working with an Arduino Uno and the HM-10 BLE module, but my transmission connection is acting weird. It connects properly and I get a quick TX RX blinks on my Uno board and the correct info on my serial monitor, but after a second or so it starts to blink really slowly and the info transmitted comes a second at a time even if I stopped sending info a while ago. Any ideas on why that's happening?

#include <Arduino.h>

int  x = 0;
int  y = 0;

void setup()
{ 
Serial.begin(9600);
}
void loop()
{
while (Serial.available() > 0) {
    x = Serial.read();
    y = Serial.read();
    Serial.print("x: ");
    Serial.println(x);
    Serial.print("y: ");
    Serial.println(y);
  }
}

Two devices (HM-10 and serial monitor) on the same serial port can cause problems. May I suggest that you use a software serial port (several libraries available) for the Bluetooth module and save the hardware Serial (USB) for upload and program output and debug?

Shat What is the Bluetooth sender?

Shat is the Bluetooth sender?

I didn't understand this question, sorry.

As for the two devices on the serial port, that might be it, I was already looking for the SoftwareSerial library to try and solve this, they are probably using the same lanes and causing trouble on the comms.

Ty for the answer!!!

Shat is the Bluetooth sender?
I didn't understand this question, sorry.

I meant what is the Bluetooth sender. Fat fingers and poor proofreading, sorry.

What is sending data to the HM-10?

Oh, ok hahah

I'm sending data from an MIT App Inventor app via an Android phone

in your loop() code you are reading 2 bytes if at least one byte is available. That is not the most reliable way to do it.

What is the app sending? Can you provide a sample?

What is printed with this simple test code? Copy and paste the serial monitor results to a new post, please. You will need to wire the Blutooth module to the Uno as shown in the test program to use Software serial.

#include <SoftwareSerial.h>

// connect bt TX to Uno pin 4 and BT RX to Uno pin 5
SoftwareSerial BTserial(4, 5); // RX | TX

void setup()
{
   Serial.begin(9600);
   BTserial.begin(9600);  // **** change for your module if necessary

}

void loop()
{
   if (Serial.available())
   {
      BTserial.write(Serial.read());
   }
   if (BTserial.available())
   {
      Serial.print(char(BTserial.read()));
   }
}

Martyn Currey has a vey good tutorial on the HM-10.
http://www.martyncurrey.com/hm-10-bluetooth-4ble-modules/#arduinoToHM-10

It connects properly and I get a quick TX RX blinks on my Uno board and the correct info on my serial monitor, but after a second or so it starts to blink really slowly and the info transmitted comes a second at a time even if I stopped sending info a while ago. Any ideas on why that's happening?

I would recommend that you get things working with a standard ble terminal app before using a custom App Inventor program.

The serial input basics tutorial may give you some good ideas for more reliable reading of serial input data.

groundFungus:
in your loop() code you are reading 2 bytes if at least one byte is available. That is not the most reliable way to do it.

What is the app sending? Can you provide a sample?

What is printed with this simple test code? Copy and paste the serial monitor results to a new post, please. You will need to wire the Blutooth module to the Uno as shown in the test program to use Software serial.

#include <SoftwareSerial.h>

// connect bt TX to Uno pin 4 and BT RX to Uno pin 5
SoftwareSerial BTserial(4, 5); // RX | TX

void setup()
{
  Serial.begin(9600);
  BTserial.begin(9600);  // **** change for your module if necessary

}

void loop()
{
  if (Serial.available())
  {
     BTserial.write(Serial.read());
  }
  if (BTserial.available())
  {
     Serial.print(char(BTserial.read()));
  }
}

Will try to answer you later, sorry to take so long, I'm really busy! I'll reply in some time.
Thanks for taking your time to answer me!

No problem. We are here all week.

groundFungus:
in your loop() code you are reading 2 bytes if at least one byte is available. That is not the most reliable way to do it.

What is the app sending? Can you provide a sample?

What is printed with this simple test code? Copy and paste the serial monitor results to a new post, please. You will need to wire the Blutooth module to the Uno as shown in the test program to use Software serial.

#include <SoftwareSerial.h>

// connect bt TX to Uno pin 4 and BT RX to Uno pin 5
SoftwareSerial BTserial(4, 5); // RX | TX

void setup()
{
  Serial.begin(9600);
  BTserial.begin(9600);  // **** change for your module if necessary

}

void loop()
{
  if (Serial.available())
  {
     BTserial.write(Serial.read());
  }
  if (BTserial.available())
  {
     Serial.print(char(BTserial.read()));
  }
}

Already fixed the two byte readings asking for only one byte available. I was a mistake I made while not paying attention!
The app I have sends The X and Y values for a "joystick" that is on screen, just like this one.
The blocks on App Inventor are basically the same, just adapted for BLE.
The sample code prints random things, can't see anything useful from it