Teensy4.1 Ethernet - Not seeing hardware

Dimitri

Well-known member
Hi All,

Recently I hooked up an ethernet kit for my Teensy4.1. I soldered everything in and loaded up the example file UDPSendReceiveString.ino.

When I start the program, I get the message (in the serial window):

Ethernet shield was not found. Sorry, can't run without hardware. :(


So now I am debugging - is the supplied capacitor polar? Does it have to be soldered in a particular way or this will not function?

Does the Ethernet cable have to be plugged in? Does the ethernet cable also have to be plugged into another device before the Teensy recognizes the ethernet hardware?



Thanks!
 
Quick update - in the previous post above, I was using the Ethernet libraries, and not the NativeEthernet. So Now I have attempted to use NativeEthernet examples as my starting point and the processor gets hung up at the line
Code:
 Ethernet.begin(mac,IP_Addr);

You'll see in my code below that I have included Serial.print("A") and other print statements as debug lines. The Serial Window prints out "A" but ends there. The LED never blinks as the program gets hung up somewhere in Ethernet.begin();

Code:
#include "NativeEthernet.h"
#include "NativeEthernetUdp.h"

const byte pinOut_LED = 13;
boolean LED_st = 1;

unsigned long t1,t2,t3,t4;
unsigned long CycleTime_ms = 100;

//Ethernet variables
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress IP_Addr(192, 168, 1, 177);
unsigned int LocalPort = 8888;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged";        // a string to send back

EthernetUDP UDP;

///////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
  pinMode(pinOut_LED,OUTPUT);
  digitalWrite(pinOut_LED,HIGH);
  Serial.begin(115200);
  delay(10);
  
  Serial.println("A");
  
  Ethernet.begin(mac,IP_Addr);

  Serial.println("B");

  if (Ethernet.hardwareStatus() == EthernetNoHardware) 
  {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
  }
  else
  {
    Serial.println("Ethernet shield found.");
  }

  Serial.println("C");
  
  if (Ethernet.linkStatus() == LinkOFF) 
  {
    Serial.println("Ethernet cable is not connected.");
  }

  Serial.println("D");
  
  t1 = millis();
  t2 = t1;
  t3 = t1;
  t4 = t1;
}

///////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
  t1 = millis();
  if(((t1-t2) >= CycleTime_ms) || (t2 > t1)) 
  {
    LED_st = !LED_st;
    digitalWrite(pinOut_LED,LED_st);
    t2 = t1;
  }
}


///////////////////////////////////////////////////////////////////////////////////////////////
 
Another Update:

Within NativeEthernet.cpp, I added a bunch of Serial.println() comments to debug where my program was getting hung up. I found it to be in the function

Code:
void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet)

The very last line(s) of the function is where my program gets hung up. When I comment this line out (below), the program executes.
Code:
 while(!link_status){
    }

Now when I run my program, Ethernet.HardwareStatus() reports that it sees a a shield, however right below it, LinkStatus indicates that there is no cable connected.


Does anyone know why this link_Status is giving me the
 
I'm just learning like you are but what I've figured out is you need to find the actual MAC address of your T4.1. Use Ethernet.MACAddress(mac_address) to get that. (https://www.arduino.cc/reference/en/libraries/ethernet/ethernet.macaddress/)

Once you get the right MAC address you should start to see the led blink when connected to your computer. And no the capacitor from the kit is not polarized. I have the same setup as you.
I think you can find the ip address by using:
Serial.println(Ethernet.localIP());

My problem when trying to run a simple webserver is I get the "your IP address is 0.0.0.0" I think I still don't have the right IP address setup in the setup function.
 
Hi DroneOverLord,

Thanks for your response, I'll try the MAC address route. I assume this function below would also retrieve the MAC address too.

Do you know... can I run this ethernet kit without a ethernet cable connected? Does the kit need to be connected to a valid ethernet server or router, etc??

Thank You!

Code:
static void teensyMAC(uint8_t *mac) {
  uint32_t m1 = HW_OCOTP_MAC1;
  uint32_t m2 = HW_OCOTP_MAC0;
  mac[0] = m1 >> 8;
  mac[1] = m1 >> 0;
  mac[2] = m2 >> 24;
  mac[3] = m2 >> 16;
  mac[4] = m2 >> 8;
  mac[5] = m2 >> 0;
}
 
From my understanding, if you just have the USB programmer/serial line connected and not the Ethernet cable then your T4.1 should still be able to send over serial your MAC address but you won't be able to get your local area IP address as that comes from the DHCP communication with your computer through the Ethernet cable. I'll experiment more later tonight.
 
Hi Drone,

Without having an ethernet cable plugged into anything, I use the teensyMAC function. I can see over serial bus that the teensyMAC function changes the values of my MAC address.

Then I call Ethernet.begin(MAC,IP) and the CPU still gets hung up. If you could try tonight, could you please see what happens when you try to execute Ethernet.begin() when no ethernet cable is connected?

Let's figure this out and i'll buy us beers!
 
Hi DroneOverLord & Everyone else,

I have to apologize, I am not the sharpest tool in the shed...

I plugged the ethernet cable from my Teensy4.1 to an ethernet switch and Ta-Da! the system initializes, etc. It gets passed Ethernet.begin().
 
Dimitri,

Yep, I confirmed last night that if I unplug my Ethernet cable from my computer the program waits on "Ethernet.begin();"

I'm glad you solved your problem, mine is still not resolved. After additional hours of searching I believe my problem is that I have to pass all the parameters to Ethernet.begin not just the mac. If I pass just the mac then the function returns 0.0.0.0 as the IP address of the server...which is wrong.

I've also read the I should be using QNEthernet instead of NativeEthernet as apparently it's better.
 
QNEthernet doesn’t block or wait on any of the begin() functions, even if there’s no cable plugged in. There are a few options for waiting for an address from DHCP. See the examples for more information. Also, you don’t need to specify a MAC address as it gets that internally.
 
Shawn,

Thanks for all your work on QNEthernet. I saw your comments on waiting for an address on GITHUB. I haven't tested it yet but I'm 99% sure my problem is I'm connecting my T4.1 directly into my computer with a straight through cable vise a crossover.
 
If you’re using the Ethernet.begin() form then it will try DHCP. I have a feeling that your computer isn’t running a DHCP server, so by the time the 10-second wait time is over, there’s still no IP address. In your code in that thread, there’s no checks if any of the calls fail or time out. Check out the examples that come with QNEthernet.

You could also assign a static IP address. See QNEthernet.h and the README for more documentation.
 
I'm running windows 10 and it is setup for DHCP. The issue I believe is me using a straight through cable vise cross-over. The problem now I believe is that fried the T4.1's DP83825 PHY layer chip when I was soldering the Ethernet cable to make it a cross-over cable. Like an idiot I didn't unplug the cable from the T4.1 when I was solder... all of people don't know that in addition to getting really hot, soldering irons also have a very high voltage on the tip.

Now I get to wait till Friday before my new T4.1 arrives.
 
Well, then. I stand corrected on the DHCP server. :)

I always thought most modern Ethernet jacks don’t need crossover cables anymore. Is that not the case here?

I did not know that about soldering iron tip voltages. Are we talking volts or millivolts or something?
 
You are right about modern computers being able to automatically switch from needing a cross-over cable using MDIX, but my 5 year old Acer laptop might not have that. It's the only thing I can think of right now as to way my super simple setup is not working.

For the soldering voltage we are talking mVs but I have had experience with frying a pin on my Anet A8 when I left the heat plate connected and I was changing out the temperature sensor by soldering a new one in. The prevailing logic is a few mV should not hurt a microchip but I've witnessed it twice with my Anet and now once with my T4.1 At least that is what I believe happened. I'll update everyone when I get my new board and everything works smoothly....I hope.
 
Well I've tried two different cables, (straight through and crossover) and two different Teensy4.1s... the crossover cable doesn't connect at all "Hardware not found" but the straight through cable gives me "server is at 0.0.0.0 for the following code:

Code:
#include <SPI.h>
#include <QNEthernet.h>
using namespace qindesign::network;// ADD for QNEthernet

// Enter a MAC address and IP address for your controller below.
//byte mac[] = {0x08, 0x97, 0x98, 0x6C, 0x4E, 0x8C};
byte mac[] = {0x04, 0xE9, 0xE5, 0x12, 0x35, 0x16};
byte ip[] = { 169, 254, 240, 149 }; // ip in lan

// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  stdPrint = &Serial; // ADD for QNEthernet
  Serial.println("Ethernet WebServer Example");

  // start the Ethernet connection and the server:
  Ethernet.begin(mac);
  Ethernet.waitForLocalIP(10000);// ADD for QNEthernet

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start the server
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // 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>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(2);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }  
}

when I run ipconfig I get:
Ethernet adapter Ethernet:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::bd4c:d462:cdf:f095%17
Autoconfiguration IPv4 Address. . : 169.254.240.149
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :

How do I ensure my laptop has DHCP on?
 
What does the return value of waitForLocalIP() give? You need to check that to see if an IP address was actually acquired.
 
waitForLocalIP returns 0
Code:
 stdPrint = &Serial; // ADD for QNEthernet
  Serial.println("Ethernet WebServer Example");
  int waitresults;
  // start the Ethernet connection and the server:
  Ethernet.begin(mac);
  waitresults = Ethernet.waitForLocalIP(10000);// ADD for QNEthernet
  Serial.print("waitForLocalIP returns = ");
  Serial.println(waitresults);

What should it return?
 
Ok, in the code above I did not pass the IP address just the MAC address.

I ran ipconfig again and got the autoconfiguration IPv4 Address. I passed that IP address along with the MAC address and BAM! It's all working now....so weird.

What is more weird is I get the "Ethernet cable is not connected" but it still works;

Ethernet WebServer Example

waitForLocalIP returns = 1

Ethernet cable is not connected.

server is at 169.254.3.161
 
Sounds like you’re specifying a static IP and not getting one through DHCP. If waitForLocalIP() returns false then no address was assigned via DHCP. (Using the Ethernet.begin() form.) I don’t think there’s an accessible DHCP server running. It’s important to check all the return values for more robust software behaviour.

See my post above, but I’ll repeat here: “You don’t need to specify a MAC address as it gets that internally.”

See the QNEthernet examples for more information and for non-Arduino-Ethernet-style approaches to do things.
 
Back
Top