Un saluto a tutti ![]()
Sto realizzando un progettino con un mega2560, un display TFT 480X272 e una ethernet shield, il progetto serve come antifurto, devo visualizzare sul display i vari sensori e barriere e da remoto, se scatta un allarme, vorrei vedere quale sensore o barriera è stato.
Il problema mi sorge per far lavorare insieme ethernet e display, in quanto i pin MOSI, MISO, SCK sono a comune, se uso solo il display, funziona, e se uso solo l'ethernet funziona, come inserisco fisicamente la shield di adattamento per il display (anche senza display) smette di funzionare l'ethernet. Nel mega i pin sono 50: MISO, 51: MOSI, 52: SCK, usati dalla shield per il display. A voi chiedo: ci sono altri pin utilizzabili dalla ethernet per la comunicazione? Mi pareva di aver letto da qualche parte che questa porta sulla 2560 è l'unica.
Spero di essere stato abbastanza chiaro, grazie a tutti per l'aiuto ![]()
Ho fatto alcune prove, non pare un problema fisico della porta SPI, dopo aver creato qualche immagine nel display, se rifaccio un test della shield ethernet, mi da esito positivo, quindi la comunicazione c'è; solo che da remoto non trovo la lan, se invece tolgo fisicamente display e shield relativa, l'ethernet funziona regolarmente.
Ho controllato l'alimentazione, ed è ok, anche perchè ho usato uno switching a 5V per alimentare il display... Non so più cosa fare, aiutatemi >:(
Vi allego il codice
#include <EtherCard.h>
#include <UTFT.h>
#include <UTouch.h>
#include <SD.h>
#include <tinyFAT.h>
File myFile;Â //per sdcard
static byte mymac[] = {0x74,0x69,0x69,0x2D,0x30,0x31};
static byte myip[] = {192,168,1,100};
byte Ethernet::buffer[700]; // originale è a 700
const int ledPin = 9;
boolean ledStatus;
char* on = "ON";
char* off = "OFF";
char* statusLabel;
char* buttonLabel;
// Declare which fonts we will be using
extern uint8_t SmallFont[];
// linee collegamento display arduino mega2560
UTFT myGLCD(ITDB43,38,39,40,41);Â
UTouch myTouch( 6, 5, 4, 3, 2);
void setup()
{
 Serial.begin(57600);         //attiva e imposta la seriale
 Serial.println("Sistema Antifurto"); //scrive sulla seriale
 if (!ether.begin(sizeof Ethernet::buffer, mymac, 8)) //pin CS ethernet, + controllo comunicazione
 Serial.println( "Accesso Ethernet fallito"); //scrive sulla seriale con ln dopo print, va a capo
else
 Serial.println("Accesso Ethernet ok");     //scrive sulla seriale
 if (!ether.staticSetup(myip))         //controllo mio IP
 Serial.println("Settaggio IP fallito");    //scrive sulla seriale
 Serial.println(); //scrive sulla seriale, niente
Â
 while (!Serial) { //
}
 Serial.println("Inizializzazione SD Card........"); //scrive sulla seriale
 pinMode(10, OUTPUT);
Â
 if (!SD.begin(53)) {  //pin CS della SD Card, + controllo comunicazione con sd
 Serial.println("Inizializzazione SD Card fallita"); //scrive sulla seriale
 return;
 }
 Serial.println("Inizializzazione SD Card ok");  //scrive sulla seriale
Â
 // open the file. note that only one file can be open at a time,
 // so you have to close this one before opening another.
 myFile = SD.open("test.txt", FILE_WRITE);
Â
 // if the file opened okay, write to it:
 if (myFile) {
 Serial.println("Scrittura di test.txt");    //scrive sulla seriale
 myFile.println("Sto scrivendo nella SD Card"); //scrive nella sd card
 myFile.close();                 // chiusura del file nella sd card
 Serial.println("Scrittura di test.txt riuscita"); //scrive sulla seriale
 } else {
 Serial.println("Errore lettura test.txt");    //scrive sulla seriale
 }
 myFile = SD.open("test.txt");      //apertura del file test.txt nella sd card
 if (myFile) {
 Serial.println("test.txt:");       //scrive sulla seriale
 Â
 while (myFile.available()) {      //lettura dei dati dentro il file
 Serial.write(myFile.read());
  }
  myFile.close();            // chiusura del file nella sd card
 } else {
  Serial.println("Errore lettura test.txt"); //scrive errore perchè il file non è stato letto
}
//********************************* fine test sd card ***************************************
Â
 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(255, 0, 0);
 myGLCD.fillRect(0, 0, 479, 13);
 myGLCD.setColor(64, 64, 64);
 myGLCD.fillRect(0, 258, 479, 271);
 myGLCD.setColor(255, 255, 255);
 myGLCD.setBackColor(255, 0, 0);
 myGLCD.print("* Test Display*", CENTER, 1);
 myGLCD.setBackColor(64, 64, 64);
 myGLCD.setColor(255,255,0);
 myGLCD.print("ethernet e Sd card", CENTER, 259);
}
void loop()Â Â //parte ciclica delprogramma
{
word len = ether.packetReceive();
 word pos = ether.packetLoop(len);
Â
 if(pos) {
 Â
  if(strstr((char *)Ethernet::buffer + pos, "GET /?status=ON") != 0) {
   Serial.println("Received ON command");
   ledStatus = true;
  }
  if(strstr((char *)Ethernet::buffer + pos, "GET /?status=OFF") != 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>WebLed</title></head>"
   "<body>LED Status: $S "
   "<a href=\"/?status=$S\"><input type=\"button\" value=\"$S\"></a>"
   "</body></html>"  Â
   ), statusLabel, buttonLabel, buttonLabel);
  ether.httpServerReply(bfill.position());
 }
}