BT05 Bluetooth Module

I am using BLExAR along with a BT05 Bluetooth module and I am trying to send a message to an 8 x 32 LED matrix. I can connect to the BT05 but nothing appears on the LED matrix. Here is the sketch I am using, am I missing something or do I need to enter anything else before or after my message? Any help would be much appreciated.

################################################################################
  # File Name:             MikroMatrix
  # Board:                 Arduino UNO
  # Programming Language:  C & C++  / Arduino IDE
  #
  # Objective:             Scrolling LED dot Matrix  &  Seven Segment
  #
  # Operation:             Scrolls a message over a LED dot matrix Change its scrolling speed 
                           intensity and message text during scroll
  #
  # Author:                MUHAMMAD KASHIF
  # Date:                  December 14, 2020
  # Place:                 Lahore - Pakistan
  #
  ################################################################################
 
 This code is a public example.
*/
#include <SoftwareSerial.h>
#include <MikroMatrix.h> // download library from https://github.com/Kashif2812/MikroMatrix
#include <TimerOne.h>   // include timer library for software interrupt




#define CLOCK_PIN 13       // CLK pin of MAX7219 module on arduino UNO Pin no 13
#define CHIP_SELECT 10     // CHIP_SELECT of MAX7219 module on arduino UNO Pin no 10
#define DATA_PIN 11        // DATA_PIN pin of MAX7219 module on arduino UNO Pin no 11
#define NUM_OF_DEVICES 4   // change this variable to set how many MAX7219's you'll use
#define RX       0         // connect arduino pin no 0 to HM10's TX pin
#define TX       1         // connect arduino pin no 1 to HM10's RX pin



char message[100];

SoftwareSerial BT05(RX, TX); //RX|TX

//MAX_7219 class for LED_Matrix and Seven Segment driver:
MAX_7219 MAX_7219_MODULE(DATA_PIN, CHIP_SELECT, CLOCK_PIN, NUM_OF_DEVICES );

//MikroMatrixapp class for Seven Segment applications
MikroMatrixapp Matrix(&MAX_7219_MODULE);

void setup() {

  BT05.begin(9600);                    // begin serial and set buad rate 
  MAX_7219_MODULE.init();              // initializing hardware
  Timer1.initialize(200000);           // initialize timer with 200 milli seconds 
  Timer1.attachInterrupt(call_back);   // attach interupt with call back function 

}

 void call_back()     // This is a function called during interruption
{
int brightness;      // variable to hold the value of brightness
int Speed;           // variable to hold the value of speed

    if (BT05.available())   // condition to check if any value avail on seril buffer
          {
      char C=BT05.read();   // read identifier character 

        if (C=='B')        // check that if identifier character is equal to "B"
            {
              brightness=BT05.parseInt();                 // then incoming value will be equal to brightness
              MAX_7219_MODULE.set_intensity(brightness);  // write the value of brightness in brightness register
            }


        if (C=='S')     // check that if identifier character is equal to "S"
            {
              Speed=BT05.parseInt();     // then incoming value will be equal to Speed
              MAX_7219_MODULE.set_speed(Speed);   // write the value of Speed in speed setting function
            }
      

       // note: For message identifier, use that character you are not using in your message
       
        if (C=='t')      // check that if identifier character is equal to "t"
            {
              memset(message , 0 , 100);      // function to clear message array for new message 
              BT05.readBytesUntil('\r' , message , 100);    // function to recive new message from Serial and store in message array

            }
        }
}

void loop() { 

Matrix. scroll_left(message);

}

I put a Serial.begin(9600) and a Serial.println(message) and nothing appears so it looks like no message is being saved!

I suggest that you have a look at the Robin2's serial input basics tutorial. It shows how to receive and parse serial data.

Why look for available serial data every 200ms? Why us an interrupt? Why not just handle the serial data when it arrives?

In an ISR, interrupts are disabled so I wonder if SoftwareSerial will work in the ISR since SoftwareSerial uses interrupts.

Thanks fro your reply, I will have a look at that.

Thanks for your reply, this is someone else's sketch I came across in a YouTube video which seemed to work fine, so I thought I would try it.

I think that BLExAR is a Bluetooth Low Energy App. The HC05 is a classic bluetooth device and is incompatible with BLE.

You can try to use a CC2541 (HM-10, AT-09, JDY-08, SH-M08) BLE module on the Arduino.

This guy is actually referring to the BT05, which is indeed a BLE device. I understand it is a bastardised CC2541 and looks identical, but maybe best avoided.

And well you might but, on the Internet, innocence can be quite shortlived, and the clown from Lahore hasn't a clue. He clearly states that he is using a Uno, but then declares software serial on the hardware serial pins 0,1 - a certain recipe for disaster and a clear indication of the author's competence.

I have no idea of what you are really trying to do, but you may find that this is actually your only problem (!), and you have two options:

  1. Move Bluetooth and software serial to another pair of pins. I believe any pair of pins are OK for software serial on a Uno, except pins 0,1!

  2. Leave Bluetooth where it is and delete all reference to software serial, i.e change "BT05" to simply "Serial". No need to define the pins, Arduino already knows that.

I would suggest the latter, but disconnect Bluetooth while uploading the code.

Thanks for your replies guys, I haven't done much with bluetooth to date. All I was trying to do was to use the terminal of the app to send a message to the LED Matrix which would then scroll across. I will try your suggestions Nick and see how it goes.

To be fair to the author, he had pins 1 & 2 in one file and pins 4 & 5 in another. It ws a message from someone else who stated it must be pins 0 & 1.

I have tried both of your options with no joy! I have discovered that my Bluetooth module is an HM-10 and can connect my phone to it no problem. when I send to it, I can see the led flashing but I have tried to write to the serial port but nothing appears. I did use a Serial.begin so it looks like something else is amiss.

Please post the latest version of code you are using and your connections. Thanks.

Here is the latest code that I have tried

/*
  ################################################################################
  # File Name:             MikroMatrix
  # Board:                 Arduino UNO
  # Programming Language:  C & C++  / Arduino IDE
  #
  # Objective:             Scrolling LED dot Matrix  &  Seven Segment
  #
  # Operation:             Scrolls a message over a LED dot matrix Change its scrolling speed 
                           intensity and message text during scroll
  #
  # Author:                MUHAMMAD KASHIF
  # Date:                  December 14, 2020
  # Place:                 Lahore - Pakistan
  #
  ################################################################################
 
 This code is a public example.
*/
#include <SoftwareSerial.h>
#include <MikroMatrix.h> // download library from https://github.com/Kashif2812/MikroMatrix
#include <TimerOne.h>   // include timer library for software interrupt




#define CLOCK_PIN 13       // CLK pin of MAX7219 module on arduino UNO Pin no 13
#define CHIP_SELECT 3     // CHIP_SELECT of MAX7219 module on arduino UNO Pin no 10
#define DATA_PIN 11        // DATA_PIN pin of MAX7219 module on arduino UNO Pin no 11
#define NUM_OF_DEVICES 4   // change this variable to set how many MAX7219's you'll use
#define RX       6        // connect arduino pin no 0 to HM10's TX pin
#define TX       7         // connect arduino pin no 1 to HM10's RX pin



char message[100];

SoftwareSerial BT05(RX, TX); //RX|TX

//MAX_7219 class for LED_Matrix and Seven Segment driver:
MAX_7219 MAX_7219_MODULE(DATA_PIN, CHIP_SELECT, CLOCK_PIN, NUM_OF_DEVICES );

//MikroMatrixapp class for Seven Segment applications
MikroMatrixapp Matrix(&MAX_7219_MODULE);

void setup() {

  Serial.begin(9600);                  // Added
  BT05.begin(9600);                    // begin serial and set buad rate 
  MAX_7219_MODULE.init();              // initializing hardware
  Timer1.initialize(200000);           // initialize timer with 200 milli seconds 
  Timer1.attachInterrupt(call_back);   // attach interupt with call back function 

}

 void call_back()     // This is a function called during interruption
{
int brightness;      // variable to hold the value of brightness
int Speed;           // variable to hold the value of speed

    if (BT05.available())   // condition to check if any value avail on seril buffer
          {
      char C=BT05.read();   // read identifier character 

        if (C=='B')        // check that if identifier character is equal to "B"
            {
              brightness=BT05.parseInt();                 // then incoming value will be equal to brightness
              MAX_7219_MODULE.set_intensity(brightness);  // write the value of brightness in brightness register
              Serial.println(brightness);  //added
            }


        if (C=='S')     // check that if identifier character is equal to "S"
            {
              Speed=BT05.parseInt();     // then incoming value will be equal to Speed
              MAX_7219_MODULE.set_speed(Speed);   // write the value of Speed in speed setting function
              Serial.println(Speed);  //added
            }
      

       // note: For message identifier, use that character you are not using in your message
       
        if (C=='t')      // check that if identifier character is equal to "t"
            {
              memset(message , 0 , 100);      // function to clear message array for new message 
              BT05.readBytesUntil('\r' , message , 100);    // function to recive new message from Serial and store in message array
              Serial.println(message); //added
              
            }
        }
}

void loop() { 

Matrix.scroll_left(message);

}

Connections are as follows:

LED Matrix

Data Pin - Pin 11
CS Pin - Pin 3
CLK Pin - Pin 13

HM10 - Bluetooth Module

TX Pin - Pin 6
RX Pin - Pin 7
GND - GND
VCC - 5V

I did try just using Serial.begin and dropping the SoftwareSerial but to no avail. I put the serial.println lines in to see if it would show up on the serial monitor, but nothing appears.

Thanks.

You were previously warned about having all the software serial reading within an interrupt context.

I would recraft the program without the timer interrupt, eliminate the callback, and just place that block of code in loop().

/*
  ################################################################################
  # File Name:             MikroMatrix
  # Board:                 Arduino UNO
  # Programming Language:  C & C++  / Arduino IDE
  #
  # Objective:             Scrolling LED dot Matrix  &  Seven Segment
  #
  # Operation:             Scrolls a message over a LED dot matrix Change its scrolling speed
                           intensity and message text during scroll
  #
  # Author:                MUHAMMAD KASHIF
  # Date:                  December 14, 2020
  # Place:                 Lahore - Pakistan
  #
  ################################################################################

  This code is a public example.
*/
#include <SoftwareSerial.h>
#include <MikroMatrix.h> // download library from https://github.com/Kashif2812/MikroMatrix
//#include <TimerOne.h>   // include timer library for software interrupt




#define CLOCK_PIN 13       // CLK pin of MAX7219 module on arduino UNO Pin no 13
#define CHIP_SELECT 3     // CHIP_SELECT of MAX7219 module on arduino UNO Pin no 10
#define DATA_PIN 11        // DATA_PIN pin of MAX7219 module on arduino UNO Pin no 11
#define NUM_OF_DEVICES 4   // change this variable to set how many MAX7219's you'll use
#define RX       6        // connect arduino pin no 0 to HM10's TX pin
#define TX       7         // connect arduino pin no 1 to HM10's RX pin



char message[100];
int brightness;      // variable to hold the value of brightness
int Speed;           // variable to hold the value of speed


SoftwareSerial BT05(RX, TX); //RX|TX

//MAX_7219 class for LED_Matrix and Seven Segment driver:
MAX_7219 MAX_7219_MODULE(DATA_PIN, CHIP_SELECT, CLOCK_PIN, NUM_OF_DEVICES );

//MikroMatrixapp class for Seven Segment applications
MikroMatrixapp Matrix(&MAX_7219_MODULE);

void setup() {

  Serial.begin(9600);                  // Added
  BT05.begin(9600);                    // begin serial and set buad rate
  MAX_7219_MODULE.init();              // initializing hardware
  //Timer1.initialize(200000);           // initialize timer with 200 milli seconds
  //Timer1.attachInterrupt(call_back);   // attach interupt with call back function

}

// void call_back()     // This is a function called during interruption
//{
//int brightness;      // variable to hold the value of brightness
//int Speed;           // variable to hold the value of speed

void loop() {

  Matrix.scroll_left(message);

  if (BT05.available())   // condition to check if any value avail on seril buffer
  {
    char C = BT05.read(); // read identifier character

    if (C == 'B')      // check that if identifier character is equal to "B"
    {
      brightness = BT05.parseInt();               // then incoming value will be equal to brightness
      MAX_7219_MODULE.set_intensity(brightness);  // write the value of brightness in brightness register
      Serial.println(brightness);  //added
    }


    if (C == 'S')   // check that if identifier character is equal to "S"
    {
      Speed = BT05.parseInt();   // then incoming value will be equal to Speed
      MAX_7219_MODULE.set_speed(Speed);   // write the value of Speed in speed setting function
      Serial.println(Speed);  //added
    }


    // note: For message identifier, use that character you are not using in your message

    if (C == 't')    // check that if identifier character is equal to "t"
    {
      memset(message , 0 , 100);      // function to clear message array for new message
      BT05.readBytesUntil('\r' , message , 100);    // function to recive new message from Serial and store in message array
      Serial.println(message); //added

    }
  }
}

Serial also uses interrupts. Interrupts are disabled in the ISR.

Here is a demonstration code using the receive with end marker example from the serial input basics tutorial along with the strtok function to parse the data. For testing enter data from the serial monitor. This is just do demo the use of the serial input basics methods. Use what you want.

const byte NUM_CHARS = 110;  // message length + 10
char receivedChars[NUM_CHARS];   // an array to store the received data
boolean newData = false;

char message[100];

void setup()
{
   Serial.begin(115200);
   Serial.println("<Arduino is ready>  single letter command separated, with a COMMA");
   Serial.println("    from an integer or a string.  Like t,HelloWorld or S,60");
   Serial.println("make sure that the sender terminates the data with a newLine (\\n)");
   Serial.println('\n');
}

void loop()
{
   checkSerial();
   //Matrix.scroll_left(message);
}

void checkSerial()
{
   recvWithEndMarker();
   //showNewData();
   if (newData)
   {
      parseData();
   }
}

void recvWithEndMarker()
{
   static byte ndx = 0;
   char endMarker = '\n';
   char rc;
   // REPLACE THE Serial in the next 2 lines with BT05 to use
   // your software serial.
   while (Serial.available() > 0 && newData == false)
   {
      rc = Serial.read();
      //Serial.println(rc);
      if (rc == '\r') // ignore carruage return
      {
         return;
      }
      if (rc != endMarker)
      {
         receivedChars[ndx] = rc;
         ndx++;
         if (ndx >= NUM_CHARS)
         {
            ndx = NUM_CHARS - 1;
         }
      }
      else
      {
         receivedChars[ndx] = '\0'; // terminate the string
         ndx = 0;
         newData = true;
      }
   }
}

void showNewData()
{
   if (newData == true)
   {
      Serial.print("This just in ... ");
      Serial.println(receivedChars);
      //newData = false;
   }
}

void parseData()
{
   char *strings[3]; // an array of pointers to the pieces of the above array after strtok()
   char *ptr = NULL; 
   byte index = 0;
   ptr = strtok(receivedChars, ",");  // delimiters, comma
   while (ptr != NULL)
   {
      strings[index] = ptr;
      index++;
      ptr = strtok(NULL, ",");  // delimiters, comma
   }
   /*
      //Serial.println(index);
      // print all the parts
      Serial.println("The Pieces separated by strtok()");
      for (int n = 0; n < index; n++)
      {
         Serial.print("piece ");
         Serial.print(n);
         Serial.print(" = ");
         Serial.println(strings[n]);
      }
   */
   // convert string data to numbers
   char command = char(*strings[0]);
   if (command == 'B') // brightness
   {
      int brightness = atoi(strings[1]); // *** is this the appropriate data type?
      //MAX_7219_MODULE.set_intensity(brightness); // **** commented for testing ****
      Serial.print("\nSet brightness to ");
      Serial.println(brightness);
   }
   else if (command == 'S') // speed
   {
      int Speed = atoi(strings[1]); // *** is this the appropriate data type?
      //MAX_7219_MODULE.set_speed(Speed);   // **** commented for testing ****
      Serial.print("\nSet speed to ");
      Serial.println(Speed);
   }
   else if (command == 't')
   {
      memset(message , 0 , 100);      // function to clear message array for new message
      strcpy(message, strings[1]);
      Serial.print("\nNew message is >> ");
      Serial.println(message);
   }
   else
   {
      Serial.println("******* invalid input *******");
   }
   /*
      Serial.print("command = ");
      Serial.print(command);
      Serial.print("   strings[1] = ");
      Serial.print(strings[1]);
   */
   Serial.println(); // blank line
   newData = false;
}

The HM-10 is a Bluetooth Low Energy (BLE) device. BLE works in a quite different way of BT (take a look at Arduino - ArduinoBLE) and it´s also more complicated.

BLExAR will find your module, but your code has to be completely different in order to exchange information.

@Brazilino
I don't believe you are correct.

The iphone app knows how to communicate with the HM10 (likely using some ble uart protocol) and the HM10 can communicate with the Arduino with serial or software serial.

See this example
https://makersportal.com/blog/2018/10/30/4-pin-rgb-led-control-using-ios-blexar-app-hm-10-bluetooth-module-and-arduino

Cattledog,

Many thanks for your efforts, tried doing as you suggested no joy, then copy and pasted your code, again no joy. In the light of Brazilino's comment, it may be back to the drawing board.

groundFungus,

Many thanks for your efforts, I don't understand all of the code you posted but I will play about with it in the hope of learning something.

Brazilian,

Thank you for the information, I will investigate further. Is it possible to get a BT module that will work with my iPhone and a terminal app?

I appreciate all your replies, and apologise for wasting your time as it appears that it cannot work with that code.

Oh, thanks @cattledog !

I didn´t know the application creates some sort of ble uart protocol in an user transparent way.

@SierraGolfMike, take a look in this example that was given in #17 post. It has a code and may help you.

Unfortunately my experience trying to use Bluetooth and BLE with IOS let me with some traumas :skull_and_crossbones: so, I don´t have an answer for your question regarding your IPhone.

Thanks cattledog, I will give that a go.