Alright , let's do it ...
Summary:
- Arduino Leonardo
- LED Max 7219 - 12 modules
- HC 05 Bluetooth module - interfaced SPI
- Using Serial1 due to Leonardo serial(default) reserved.
- Using MD_Parola and MD_MAX_XXX libraries
- Lazarus IDE with TLazserial component.
Main funcionality:
Sending messages to the display from the application made in Lazarus using serial communication via bluetooth.
Arduino code so far:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define MAX_DEVICES 12
#define CLK_PIN 15 //sck
#define DATA_PIN 16 // mosi
#define CS_PIN 17 //ss
MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);
char data = 0;
void setup(void)
{
P.begin();
P.setInvert(false);
Serial1.begin(9600);
}
void loop(void){
if(Serial1.available() > 0)
{
data = Serial1.read();
if(data == '1') {
P.displayText("Empty totes down !" ,PA_CENTER,2,4,PA_OPENING_CURSOR, PA_NO_EFFECT);
while (!P.displayAnimate());
}
if(data == '2'){
P.displayText("Empty totes up !",PA_CENTER,2,4,PA_OPENING_CURSOR, PA_NO_EFFECT);
while (!P.displayAnimate());
}
if(data =='3'){
P.displayText("Stop packing !",PA_CENTER,2,4,PA_OPENING_CURSOR, PA_NO_EFFECT);
while (!P.displayAnimate());
}
if(data =='4'){
P.displayText("Continue packing.",PA_CENTER,2,4,PA_OPENING_CURSOR, PA_NO_EFFECT);
while (!P.displayAnimate());
}
if(data =='5'){
P.displayClear();
while (!P.displayAnimate());
}
if(data =='6'){
P.displayText("Packages down !",PA_CENTER,2,4,PA_OPENING_CURSOR, PA_NO_EFFECT);
while (!P.displayAnimate());
}
if(data =='7'){
P.displayText("Packages up !",PA_CENTER,2,4,PA_OPENING_CURSOR, PA_NO_EFFECT);
while (!P.displayAnimate());
}
if(data =='/'){
P.displayText(data,PA_CENTER,2,4,PA_OPENING_CURSOR, PA_NO_EFFECT);
while (!P.displayAnimate()) ;
}
} // end of serial input
} // end of void loop
So that works perfect. In the attachment you can find screen from my app made in Delphi.
Basically when you chose one of the radioboxes and press "send" app is sending byte through serial on certain com port and baud rate which is equivalent of bluetooth setup.
This is the part of the Delphi code I have used:
procedure TForm1.Button5Click(Sender: TObject);
begin
if form1.RadioButton2.Checked =true then
begin
form1.LazSerial1.WriteData('1');
end;
if form1.RadioButton3.Checked =true then
begin
form1.LazSerial1.WriteData('2');
end;
if form1.RadioButton4.Checked =true then
begin
form1.LazSerial1.WriteData('3');
end;
if form1.RadioButton5.Checked =true then
begin
form1.LazSerial1.WriteData('4');
end;
if form1.RadioButton6.Checked =true then
begin
form1.LazSerial1.WriteData('6');
end;
if form1.RadioButton7.Checked =true then
begin
form1.LazSerial1.WriteData('7');
end;
end;
When the byte is send , same byte represents some chars in arduino code and that's how I display messages on LED Matrix.
As you can see on screen there is toogle box named "Manual Messages" where I would like to send message I want , but without scrolling , I had some examples on internet but I doesn't make the thing I would like to achieve.
So as I can assume we have to serial1.readString() from the Delphi application then we need to change that string into char that can be read in :
P.displayText(textfromdelphi ,PA_CENTER,2,4,PA_OPENING_CURSOR, PA_NO_EFFECT);
while (!P.displayAnimate());
Also , as to be prepared for text input in delphi I would like to preface the procedure like :
char textfromdelphi;
...
...
...
if(data == '/') {
texfromdelphi= serial1.read();
P.displayText(textfromdelphi ,PA_CENTER,2,4,PA_OPENING_CURSOR, PA_NO_EFFECT);
while (!P.displayAnimate());
}
Btw. actually the component in Lazarus gives you quite nice tool to control things via serial and bluetooth. If I can help you making something for you in thanks for your help , just let me know.
Best Regards
Jakub