I'm doing a project on arduino uno where's ethernet server based on Ethernet library and shield W5100 and led matrix rgb based on Adafruit RGB panel library RGB-matrix-panel.
Separately server and panel rgb works ok but together i can't manage that.
Some draft code below for testing:
// put y#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#include <Fonts/font7.h>
#include <ArduinoJson.h>
#include <avr/wdt.h>
#include <SPI.h>
#include <Ethernet.h>
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Similar to F(), but for PROGMEM string pointers rather than literals
#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr
#define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE 9
#define A A0
#define B A1
#define C A2
String readString;
int suma_kontrolna;
int loop_on_off;
// ethernet mac address - must be unique on your network
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
IPAddress myIP(192,168,1,177);
EthernetServer server(80);
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation. Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers(). This is normal.
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true,1);
// Double-buffered mode consumes nearly all the RAM available on the
// Arduino Uno -- only a handful of free bytes remain. Even the
// following string needs to go in PROGMEM:
char test[] = "";
//const char str[] PROGMEM = "";
const char str[] PROGMEM = "Test";
const unsigned char arrow [] PROGMEM = {
// 'arrow, 16x16px
0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,0x80, 0x01, 0x80,
0x01, 0x80, 0x0d, 0xb0, 0x07, 0xe0, 0x03, 0xc0, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00,
};
int Red = 50;
int Green = 0;
int Blue = 0;
int textX = 1,
textMinX = sizeof(str) * -12,
textY = -1,
textMinY = 25;
void setup() {
//wdt_enable(WDTO_8S);
Serial.begin(9600); // serial / USB port
// Serial1.begin(9600, SERIAL_8E1); // serial / USB port
Serial.println("Starting");
Ethernet.begin(mac, myIP);
server.begin();
Serial.println(Ethernet.localIP());
matrix.begin();
}
void render_text(){
Serial.println("mtrix");
// Clear background
matrix.fillScreen(0);
matrix.setTextWrap(true); // Allow text to run off right edge
matrix.setFont(NULL);
matrix.setTextColor(matrix.Color888(Red,Green,Blue));
matrix.setCursor(textX+7, 1);
matrix.setTextSize(2);
matrix.print(F2(str));
matrix.swapBuffers(false);
}
void server_work(){
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("test");
}
client.println("</html>");
break;
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
void loop() {
server_work();
render_text();
}
If I comment out
//matrix.begin()
//render_text();
server works ok.
if I comment out part with server led matrix works ok but i have to comment out
//#include <Ethernet.h>;
too, to work with matrix led.
Both use pin 4 matrix for blue color and wiznet W5100 for sd card(with i don't use/need) but when I remove this connection (hardware) matrix won't show blue but works and ethernet works too so I don't think that's the problem.
How can I menage this to work together?