Utft in combinatie met W5500

Arduino specifieke Software
Gebruikers-avatar
Berichten: 43
Geregistreerd: 09 Jan 2015, 15:09

Utft in combinatie met W5500

Berichtdoor hv0805 » 23 Mrt 2018, 15:31

Hallo,
Ben met een nieuw projectje gestart en zit al in de problemen.
Ik maak gebruik van een Ethernet module W5500, een UTFT scherm (TFT_320QVT) en een Mega.
Als ik de Ethernetmodule gebruik zonder UTFT werkt het en print de NTP time af op de Serial monitor.
Als ik de TFT module gebruik zie ik iets op het scherm.
Als ik beide modules gebruik zie ik enkel iets op het scherm.
De setup print nog wel "Serial.println("voor Ethernet begin");" maar verder komt die niet. (staat daar enkel als debug)

Ethernet is aangesloten op de ICSP connector net boven de resetknop (dus midden het board).
Wat kan hier de oorzaak van het niet samenwerken van beide modules zijn?

Dank u

Herman

Code: Alles selecteren
#include <SPI.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h>
#include <UTFT.h>
#include <URTouch.h>
#include <UTFT_Geometry.h>

// Initialize display
// Standard Arduino Mega/Due shield            : <display model>,38,39,40,41

UTFT    tft(ILI9341_16,38,39,40,41);
// Initialize touchscreen
// Standard Arduino Mega/Due shield            :  6, 5, 4, 3, 2

URTouch  myTouch( 6, 5, 4, 3, 2);

// Geo
UTFT_Geometry geo(&tft);

// Declare which fonts we will be using
extern uint8_t BigFont[];
extern uint8_t SmallFont[];

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
// Ethernet.begin(mac, ip, DNSserver, gateway, subnet);
/*byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};*/

byte mac[] = { 0x84, 0x42, 0x8B, 0xBA, 0xB2, 0x31 };
IPAddress ip(192, 168, 0, 136);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
IPAddress DNSserver(192,168,0,1);
EthernetServer server(80);


unsigned int localPort = 8888;       // local port to listen for UDP packets
unsigned long epoch,prvmillis;

char timeServer[] = "3.be.pool.ntp.org"; // time.nist.gov NTP server

const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message

byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

// A UDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  tft.InitLCD();
  tft.clrScr();
  tft.setFont(BigFont);
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  // volgen lijnen zijn test op werking van TFT
  tft.setColor(255, 255, 255);
  tft.setBackColor(0, 0, 0);
  tft.print("TFT Working*", 0, 0);
   tft.setColor(0, 0, 255);
  tft.fillRect(0, 15, 319, 16);
 
  // start the Ethernet connection:
  Serial.println("voor Ethernet begin");
   if (Ethernet.begin(mac) == 0)
       {
         Serial.println("Failed to configure Ethernet using DHCP");
         for (;;)
           ;
       }
   //  Ethernet.begin(mac, ip, DNSserver, gateway, subnet);
   Ethernet.begin(mac);
  Serial.print("My IP address: ");
     for (byte thisByte = 0; thisByte < 4; thisByte++)
        {
          // print the value of each byte of the IP address:
          Serial.print(Ethernet.localIP()[thisByte], DEC);
          Serial.print(".");
        }
  Serial.println();
  Serial.println("NA Ethernet begin");
  Udp.begin(localPort);
  prvmillis=millis();
}

unsigned long sendNTPpacket(char* address) // send an NTP request to the time server at the given address
{
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;

  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer, NTP_PACKET_SIZE);
  Udp.endPacket();
}


void ntptime()
   {
      sendNTPpacket(timeServer); // send an NTP packet to a time server
     // wait to see if a reply is available
  //   delay(1000);
     if ( Udp.parsePacket() )
        {
          // We've received a packet, read the data from it
          Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
          
          //the timestamp starts at byte 40 of the received packet and is four bytes,
          // or two words, long. First, esxtract the two words:
          
          unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
          unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
          // combine the four bytes (two words) into a long integer
          // this is NTP time (seconds since Jan 1 1900):
          unsigned long secsSince1900 = highWord << 16 | lowWord;
       //   Serial.print("Seconds since Jan 1 1900 = " );
       //   Serial.println(secsSince1900);
          
          // now convert NTP time into everyday time:
       //   Serial.print("Unix time = ");
          // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
          const unsigned long seventyYears = 2208988800UL;
          // subtract seventy years:
          epoch = secsSince1900 - seventyYears;
          // print Unix time:
       //   Serial.println(epoch);
         }
   }
   
void printtime()  // Print Uren, min, seconden  xx:yy:zz
{
    Serial.print("Huidige tijd: ");
    Serial.print(((epoch  % 86400L) / 3600)+1); // uren, +1 voor wintertijd
    Serial.print(':');
    if ( ((epoch % 3600) / 60) < 10 ) // kleiner dan 10, leading 0
       {
      Serial.print('0');
       }
    Serial.print((epoch  % 3600) / 60); // minuten
    Serial.print(':');
    if ( (epoch % 60) < 10 ) // kleiner dan 10, leading 0
       {
        Serial.print('0');
       }
    Serial.println(epoch % 60); // seconden
}   
   
   
void loop()
{
   ntptime();
   if ((millis()-prvmillis)>=1000)
      {
         prvmillis=millis();
         printtime();
         
      }
}
   

Advertisement

Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: Utft in combinatie met W5500

Berichtdoor Koepel » 23 Mrt 2018, 16:24

Volgens mij zit de hardware en de libraries elkaar niet in de weg.
Het display kan wel flink wat geheugen gebruiken.

Ik zou eerst eens naar het stroomverbruik kijken. De Arduino Mega 2560 heeft de ATmega2560 microcontroller, die is wat ouder en heeft meer dan 4.5V nodig om te werken.
Meet de 5V pin, en als die even in de buurt van de 4.5V komt, dan is dat misschien het probleem.

Er bestaan ook Nextion displays en WeMos ESP8266 modules met wifi.

Gebruikers-avatar
Berichten: 43
Geregistreerd: 09 Jan 2015, 15:09

Re: Utft in combinatie met W5500

Berichtdoor hv0805 » 23 Mrt 2018, 17:05

Koepel, Had ik al aan gedacht. Ik meet de spanning op de W5500 module (die gebruikt 3,3v) en deze is ook 3,1 - 3,3v. De TFT module blijft gewoon werken, de Ethernet module niet.
Kan het dan toch aan het stroomverbruik liggen van de 3,3 v. Hoeveel mag de spanning afwijken?

Herman

Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: Utft in combinatie met W5500

Berichtdoor Koepel » 23 Mrt 2018, 17:12

Zo eenvoudig is dat niet, je kunt niet zeggen dat als het Ethernet Shield voldoende spanning heeft, dat het dan wel zal werken. Het werkt met elkaar samen.

Je kunt zelf de datasheet nalezen: http://www.wiznet.io/product-item/w5500/.
De spanning voor de W5500 mag 2.97 V tot 3.63 V zijn.

Wat doet de 5V ? Ik maak me meer zorgen over de ATmega2560.

Gebruikers-avatar
Berichten: 43
Geregistreerd: 09 Jan 2015, 15:09

Re: Utft in combinatie met W5500

Berichtdoor hv0805 » 23 Mrt 2018, 20:01

Ik weet al iets meer, ik zoek het volgende week uit en laat iets weten.

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 18 gasten