Hi, i am new to this and trying to make my Bluetooth module(HC_05) to receive any data it get from my phone through BLE using the app called "Serial bluetooth terminal " and display it onto my 2 16x32 which is in series. Whenever i sent out data from my phone the BLE module receive it but it doesn't display it onto the matrix ,even if it did it will displayed the weird character like this one �. Hope that you could help me out .
this is the matrix code i am using
#include <RGBmatrixPanel.h>
#define CLK 11 // USE THIS ON ARDUINO MEGA
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);
// Function to limit brightness
uint16_t limitBrightness(uint8_t red, uint8_t green, uint8_t blue) {
// Calculate total current from colors
uint8_t totalCurrent = red + green + blue;
// If total exceeds the limit, scale down
if (totalCurrent > 63) { // 63 for 7 on each color channel (max 7)
float scaleFactor = 63.0 / totalCurrent;
red = red * scaleFactor;
green = green * scaleFactor;
blue = blue * scaleFactor;
}
return matrix.Color333(red, green, blue);
}
void setup() {
matrix.begin();
matrix.fillScreen(matrix.Color333(0, 0, 0)); // Clear screen
// Set the text size and wrap
matrix.setTextSize(1); // Set text size to 1 (8 pixels high)
matrix.setTextWrap(false); // Don't wrap text
}
void loop() {
// Clear the screen
matrix.fillScreen(matrix.Color333(0, 0, 0));
// Set the text color using the limitBrightness function
matrix.setTextColor(limitBrightness(7, 7, 0)); // Bright Yellow
// Display the message "HELLO WORLD"
const char *message = "Hi guys";
// Loop until the text completely scrolls off the screen
int messageWidth = strlen(message) * 8; // Calculate the total width of the message
int startPos = matrix.width(); // Start position for scrolling
// Scroll from right to left
for (int offset = startPos; offset >= -messageWidth; offset--) {
matrix.fillScreen(matrix.Color333(0, 0, 0)); // Clear screen for each frame
matrix.setCursor(offset, 0); // Set the cursor with the offset
matrix.print(message); // Print the message
delay(100); // Control speed of the scrolling
}
}
This code below is the code i use to test out my BLE module.
<CODE>
// code by Martyn Currie.
// To enable AT mode connect the EN pin of the HC05
// to 3.3V before powering the HC05.
// Caution, do not connect EN to 5V.
#include <SoftwareSerial.h>
SoftwareSerial BTserial(50, 49); // RX | TX
const long baudRate = 9600;
char c = ' ';
boolean NL = true;
void setup()
{
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);
Serial.println(" ");
BTserial.begin(baudRate);
Serial.print("BTserial started at ");
Serial.println(baudRate);
//BTserial.print("BTserial started at ");
//BTserial.println(baudRate);
Serial.println(" ");
}
void loop()
{
// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);
String command = ""; // Create a string to hold the incoming command
}
// Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available())
{
c = Serial.read();
BTserial.write(c);
// Echo the user input to the main window. The ">" character indicates the user entered text.
if (NL)
{
Serial.print(">");
NL = false;
}
Serial.write(c);
if (c == 10)
{
NL = true;
}
}
}
And finally this code below is the one i need help with
#include <RGBmatrixPanel.h>
#include <SoftwareSerial.h>
SoftwareSerial BTserial(50, 49); // RX | TX
#define CLK 11 // USE THIS ON ARDUINO MEGA
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);
// Global variables
String message = ""; // To store the received message
const long baudRate = 9600;
void setup() {
Serial.begin(9600);
BTserial.begin(baudRate);
Serial.println("Bluetooth started");
matrix.begin();
matrix.fillScreen(matrix.Color333(0, 0, 0)); // Clear screen
matrix.setTextSize(1); // Set text size to 1 (8 pixels high)
matrix.setTextWrap(false); // Don't wrap text
}
void loop() {
// Read from Bluetooth module
while (BTserial.available()) {
char c = BTserial.read();
// Debug print to see received characters
Serial.print("Received: ");
Serial.println(c);
if (c == '\n') { // Newline indicates end of message
displayMessage(message); // Display the complete message
message = ""; // Clear the message for the next input
} else {
message += c; // Append character to message
}
}
}
// Function to display the message on the matrix
void displayMessage(String msg) {
matrix.fillScreen(matrix.Color333(0, 0, 0)); // Clear screen
matrix.setTextColor(matrix.Color333(0, 0, 7)); // Set text color to blue
int x = (matrix.width() - msg.length() * 8) / 2; // Center the text
matrix.setCursor(x, 0); // Set cursor to centered position
matrix.print(msg); // Display the message
delay(2000); // Display for 2 seconds before clearing
}
Power supply : Arduino Mega(USB),Solar panel without battery(5V) with battery (7V)
RX1 TX (Mega Pin 50)
TX1 RX (Mega Pin 49 - but run through a voltage divider using 2 resistors)