Ciao a tutti ![]()
Ho assemblato su un MEGA2560 un display TFT 480X272 (con relativa shield) e un modulo Ethernet. Il problema sta nel funzionamento della ethernet con il display, vale a dire: appena inizia il programma per un po' funziona la comunicazione LAN, quando il tutto si scalda (dopo qualche minuto), smette di funzionare; se tolgo il display e lascio solo l'Ethernet, essa funziona sempre.
Pensavo a problemi di alimentazione, ma ho dapprima usato switching a 5V per alimentare display e modulo Ethernet, poi ne ho messi 2, uno per il display e uno per il modulo Ethernet; pensavo a un problema di alimentazione, perchè mettendo dei condensatori all'uscita degli switching ho migliorato la comunicazione della LAN.
Non è invece un problema software che io non capisco? Qualche ritardo o non so che?
Vi allego il sorgente, e ringrazio tutti ![]()
#include <EtherCard.h>
#include <UTFT.h>
#include <UTouch.h>
#include <SD.h>
File myFile;Â //per sdcard
static byte mymac[] = {0x74,0x69,0x69,0x2D,0x30,0x31};
static byte myip[] = {192,168,1,100};
byte Ethernet::buffer[1000]; // originale è a 700
const int ledPin = 9;
boolean ledStatus;
char* on = "ATTIVA";
char* off = "DISATTIVA";
char* statusLabel;
char* buttonLabel;
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
// linee collegamento display arduino mega2560
UTFT myGLCD(ITDB43,38,39,40,41);Â
UTouch myTouch( 6, 5, 4, 3, 2);
void setup()
{
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);
 ledStatus = false;
Â
 randomSeed(analogRead(0));
Â
// Setup the LCD
 myGLCD.InitLCD();
 myGLCD.setFont(SmallFont);
 int buf[478];
 int x, x2;
 int y, y2;
 int r;
// cancello lo schermo e creo dei disegni
 myGLCD.clrScr();
 myGLCD.setColor(0, 0, 0);    //colore sfondo rettangolo
 myGLCD.fillRect(0, 0, 479, 271);
Â
 myGLCD.setColor(255, 255, 255);     //colore scritta
 myGLCD.setBackColor(0, 0, 0);     //colore sfondo scritta
 myGLCD.print("* GESTIONE SISTEMA ANTIFURTO *", CENTER, 1);  //scrivo sul display
 delay(2000);              //aspetto 2 secondi
 myGLCD.setBackColor(0, 0, 0);     //colore sfondo scritta
 myGLCD.setColor(255,255,255);      //colore scritta
 myGLCD.print("Test ethernet e SD card.....", CENTER, 30);
Â
 delay(2000);
Â
 Serial.begin(57600);         //attiva e imposta la seriale
 if (!ether.begin(sizeof Ethernet::buffer, mymac, 8)) //pin CS ethernet, + controllo comunicazione
 myGLCD.print( "Accesso Ethernet fallito", CENTER,45); //scrive sul display
else
 myGLCD.print("Accesso Ethernet ok", CENTER, 45);     //scrive sul display
 if (!ether.staticSetup(myip))         //controllo mio IP
 myGLCD.print("Settaggio IP fallito", CENTER, 60);    //scrive sul display
 myGLCD.print("Settaggio IP OK", CENTER, 60); //scrive sul display
Â
 while (!Serial) {
}
 myGLCD.print("Inizializzazione SD Card.....", CENTER, 75); //scrive sul display
 pinMode(10, OUTPUT);
Â
 if (!SD.begin(53)) { //pin CS della SD Card, + controllo comunicazione con sd
 myGLCD.print("Inizializzazione SD Card fallita", CENTER, 90); //scrive sul display
 } else {
 myGLCD.print("Inizializzazione SD Card ok", CENTER, 90);  //scrive sul display
 }
 myGLCD.print("ATTENDERE 6 SECONDI L'AVVIO DEL PROGRAMMA.....", CENTER, 180); //scrive sul display
 delay(6000);
Â
 myGLCD.clrScr();         //cancello lo schermo
 myGLCD.setColor(0, 90, 0);      //colore sfondo rettangolo
 myGLCD.fillRect(0, 0, 479, 271);   //creo un rettangolo
Â
 myGLCD.setFont(BigFont);
 myGLCD.setColor(0, 0, 0);      //colore scritta
 myGLCD.setBackColor(255, 255, 255);  //colore sfondosotto scritta
 myGLCD.print("ANTIFURTO", CENTER, 1); //scrive sul display
 myGLCD.print("NON ATTIVO", CENTER, 16); //scrive sul display
}
//********************************* fine test sd card ***************************************
void loop()Â Â //parte ciclica delprogramma
{
word len = ether.packetReceive();
 word pos = ether.packetLoop(len);
Â
 if(pos) {
 Â
  if(strstr((char *)Ethernet::buffer + pos, "GET /?status=ATTIVA") != 0) {
   Serial.println("Received ON command");
   ledStatus = true;
  }
  if(strstr((char *)Ethernet::buffer + pos, "GET /?status=DISATTIVA") != 0) {
   Serial.println("Received OFF command");
   ledStatus = false;
  }
 Â
  if(ledStatus) {
   digitalWrite(ledPin, HIGH);
   statusLabel = on;
   buttonLabel = off;
  } else {
   digitalWrite(ledPin, LOW);
   statusLabel = off;
   buttonLabel = on;
  }
  Â
  BufferFiller bfill = ether.tcpOffset();
  bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
   "Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
   "<html><head><title>Antifurto</title></head>"
   "<body>Protezione attiva? $S "
   "<a href=\"/?status=$S\"><input type=\"button\" value=\"$S\"></a>"
   "</body></html>"  Â
   ), statusLabel, buttonLabel, buttonLabel);
  ether.httpServerReply(bfill.position());
 }
}