I faced a problem in my graduation project and I hope you can help me to solve it :)
My project is connecting Arduino Uno to 16x32 Dot Matrix Display(DMD) and display messages on it from VB.net program. I wrote my VB.net program to convert the input text into 2D binary array. The number of columns depend on the text width. as we know Arduino Uno SRAM is too small just 2 KBytes, so can't receive all the columns and display it.
I tried to receive 100 columns in the Arduino code and display it, then send star *
to computer to receive the second 100 columns and display it and so on but it didn't work. I see the RX and TX of Arduino LEDs flicker but then nothing gets displayed on the DMD.
Can anyone tell me where is the error part in the code, or if you have another idea to solve this problem :)
VB.net Code for sending the 2D array ar(,)
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
SerialPort2.Open()
Dim la As String
If CheckBox1.Checked Then
la = "arabic"
Else
la = "english"
End If
SerialPort2.Write("#" + cols.ToString + "#" + "*" + la + "*")
Dim INDEX As Integer = 0
While INDEX <= cols
Dim see As String = SerialPort2.ReadLine().ToString()
If see = "*" Then
Dim BUFFER(16) As Byte
For I = INDEX To INDEX + 100
If I < cols Then
For J = 0 To rows - 1
BUFFER(J) = ar(I, J)
Next
SerialPort2.Write(BUFFER, 0, 16)
End If
Next
INDEX += 100
End If
End While
SerialPort2.Close()
End Sub
C++ Code for receiving 100 columns and display them:
#include <SPI.h>
#include <DMD2.h>
SoftDMD dmd(1,1);
void setup() {
Serial.begin(9600);
dmd.setBrightness(255);
dmd.begin();
}
long Wid;
void loop() {
if(Serial.available()){
String st = String(Serial.readString());
Wid = (st.substring(st.indexOf('#')+1, st.lastIndexOf('#'))).toInt();
//String Language = st.substring(st.indexOf('*')+1, st.lastIndexOf('*'));
}
long ind = Wid ;
while(ind >= 0 ){
Serial.println("*");
if(Serial.available()>1 ){
boolean pixls[16][100];
getArray(pixls);
displayArray(pixls);
ind-=100;
}
if(ind >=Wid){
ind = wid ;
}
}
}
void getArray(boolean arr[16][100]){
byte serialData[16];
for(int k = 0 ; k < 100 ; k++){
Serial.readBytes(serialData,16);
for(int i = 0 ; i < 16 ; i++){
arr[i][k]= serialData[i];
}
}
}
void displayArray(boolean arr[16][100]){
for(int h = 0 ; h <= 100-33 ; h++){
for (int i = 0 ,g=h; i < 32 ,g<h+32; i++ ,g++){
for (int j = 0 ; j < 16 ; j++){
dmd.setPixel(i,j,(arr[j][g] == 1) ? GRAPHICS_ON : GRAPHICS_OFF);
}
}
delay(100);
}
}
This VB code works for me when sending just 100 columns of the array:
SerialPort2.Open()
Dim BUFFER(16) As Byte
For J = 0 To 100
For I = 0 To rows - 1
BUFFER(I) = ar(J, I)
Next
SerialPort2.Write(BUFFER, 0, 16)
Next
SerialPort2.Close()
C++ code:
#include <SPI.h>
#include <DMD2.h>
SoftDMD dmd(1,1);
void setup() {
Serial.begin(9600);
dmd.setBrightness(255);
dmd.begin();
}
void loop() {
boolean pixls[16][100];
for(int i=0 ;i<100 ; i++){
for(int j=0 ;j<16 ; j++){
pixls[j][i]=0;
}
}
if(Serial.available()>0){
getArray(pixls);
for(int i=0 ; i<100 ; i++)
{
displayArray(pixls);
}
}
}
void getArray(boolean arr[16][100]){
byte serialData[16];
for(int k = 0 ; k < 100 ; k++){
Serial.readBytes(serialData,16);
for(int i = 0 ; i < 16 ; i++){
arr[i][k]= serialData[i];
}
}
}
void displayArray(boolean arr[16][100]){
for(int h = 0 ; h <= 100-33 ; h++){
for (int i = 0 ,g=h; i < 32 ,g<h+32; i++ ,g++){
for (int j = 0 ; j < 16 ; j++){
dmd.setPixel(i,j,(arr[j][g] == 1) ? GRAPHICS_ON : GRAPHICS_OFF);
}
}
delay(100);
}
}
but it didn't work.
- what happens? Does anything get displayed?