Hello!
I'm trying to get serial data from LED matrix controlled by MAX7219 and Arduino Uno but it does not read anything,like there's no data to read... I use LedControl library-first i turn on few diodes with setRow and i need to know what data is sent to MAX/Arduino. I've tried different delay times,different rates in Serial.begin(), nothing works.
#include "LedControl.h"
LedControl lc=LedControl(12,11,10,1);
int c=0;
void setup() {
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,3);
/* and clear the display */
lc.clearDisplay(0);
Serial.begin(9600);
}
void loop() {
lc.setRow(0,0,B11111001);
if (Serial.available()) { //without this "if" program returns "-1"
c = Serial.read();
Serial.println(c);
}
delay(10);
}
I'm trying to get serial data from LED matrix controlled by MAX7219 and Arduino Uno
Nowhere in your code do you even attempt to read anything from the MAX7219. All your code is doing is reading characters from the serial monitor.
Are you saying it displays nothing from the serial monitor when you send it characters?
If by "sending" you mean Serial.print() then yes,it does displays strings or chars if i tell him to do it. Just doesn't display anything from Serial.read().
Is there any way i can get to this data from MAX7219?
If by "sending" you mean Serial.print() then yes,it does displays strings or chars if i tell him to do it. Just doesn't display anything from Serial.read().
I don't understand what this means at all. It seems to be self contradicting.
The MAX7219 is not connected in any way with the serial system. Why would the serial system know anything about the data from the MAX7219.
The MAX7219 is connected to the Arduino with SPI, have you wired the SPI system so that the serial output of the MAX7219 is connected to the MISO of the SPI system? Until this is done there is no hope of reading anything from it.
Now does the libiary you are using support actually returning data from the SPI system? I don't know look at the documentation for it.
If it does support it and you have wired it correctly then something like:-
last = lc.setRow(0,0,B11111001);
and the variable "last" will contain not this value but the last one you sent.
Anyway why do you want to read the data in the first place? You just have an array that matches the registers. You then change the value in the array and send it to the appropriate register. You simply look at the array to see what value you last sent to that register. The MAX7219 will not change its data at all, from than that you wrote to it.
So apparently there's no MISO pin in MAX7219 and there's no informations in LedControl documentation about reading SPI data. Let's leave MAX then.
LedControl is working great but i need to know what specific data(in what format/unit,maybe an array) Ardunio gets in serial so it turns on each LED. I need to write a program in Matlab to control this LED matrix but to do that it seems like i need something more than just simple 8-bit/16-bit values. They just don't work with it at all.
And using Serial.read() should return something right? When i apply Serial.read() and Serial.println(c) right after declaration of variable "int c=0" the program returns "0" just like it should,but it doesn't return anything after i turn on LEDs. This is my main concern.
So apparently there's no MISO pin in MAX7219
Yes it is called serial out. It is used to chain multiple chips together. Or to feed the last two bytes back into the Arduino.
They just don't work with it at all.
Yes they do if you do it right.
And using Serial.read() should return something right?
Only if you send it something from the serial monitor, otherwise no. Have you not been paying attention to what I have been telling you?
need to write a program in Matlab to control this LED matrix but to do that it seems like i need something more than just simple 8-bit/16-bit values
No you don’t. It is all in bytes. Have you actually read the data sheet of this chip?
Ok,can you suggest any other way to control this matrix in Matlab than ShiftRegister or using Arduino as a USB port +function "fwrite"? My LED matrix doesn't respond in both methods...
You are very difficult to understand. Is this going through some sort of translation.
Post the code where you try to do the control, the code you posted at first made no attempt to control anything. Also post a schematic of your wiring.
I'm sorry,English isn't my first language...
About my first code-this is my whole code. There's nothing more. I'm using lc.setRow(0,0,B11111001) to light some LEDs and that's all. That's why i use LedControl library. If there's other way i can turn on LEDs AND control them(and pass data),please tell me.
This is my wiring.
In my last post i was trying to say that i've tried to program this matrix in Matlab using functions such as "ShiftRegister/read/write" and "fwrite/fread(serial)" with binary values and none of those works.
About my first code-this is my whole code. There's nothing more.
I think you are missing something very fundamental here.
Your code makes no attempt to take the data received and do anything with it. This data will be sent from MatLab if you have set it up correctly.
Now does the libiary you are using support actually returning data from the SPI system? I don't know look at the documentation for it.
Did you? Well looking at the code in the LedControl libiary shows that no call returns any value so that using this libiary you can never read anything back from the MAX7219 chip. You also failed to say that you were using a MAX7219 board with built in matrix. That makes a big difference in that you can not easily wire the board to read the data sent back even if that libiary could cope with it.
So the first thing you want to do is to set things up so MatLab can talk to the Arduino and send it data.
This code will read the serial port and if it sees any data it sees any data it will blink the onboard LED.
void setup() {
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
c = Serial.read();
digitalWrite(13,HIGH );
delay(10);
}
else {
digitalWrite(13,LOW);
}
}
When that works MatLab will be communicating with your Arduino, and then you can go on to the next step.
The next step is to get the data from MatLab and use it for the parameters in the lc.setRow call.
Unfortunately onboard LED doesn't blink.
Grumpy_Mike:
Did you? Well looking at the code in the LedControl libiary shows that no call returns any value so that using this libiary you can never read anything back from the MAX7219 chip. You also failed to say that you were using a MAX7219 board with built in matrix. That makes a big difference in that you can not easily wire the board to read the data sent back even if that libiary could cope with it.
Yes,I wrote earlier that there's no informations in LedControl documentation about reading SPI data.
Grumpy_Mike:
The next step is to get the data from MatLab and use it for the parameters in the lc.setRow call.
No, I wanted it the other way. I wanted to collect data from Serial.read() first and then use it in MatLab. My goal is to control this LED matrix through MatLab,but because I wasn't able to communicate with Arduino and matrix that way(using simple 8/16 bits) I thought data collected straight from Arduino(Arduino code) might be useful.
No, I wanted it the other way. I wanted to collect data from Serial.read() first and then use it in MatLab.
That does not make a lot of sense. What is feeding the serial port with data? It will be connected to MatLab both the TX and RX.
This comes down to the problem that you have never answered. Exactly what do you want to do?
Unfortunately onboard LED doesn't blink.
Then you have not set up MatLab correctly to communicate with the Arduino. It is a waste of time going any further until you have.