Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 4 FirstFirst 1 2 3 4 LastLast
Results 26 to 50 of 99

Thread: Teensyduino 1.54 Released

  1. #26
    Quote Originally Posted by PaulStoffregen View Post
    I've added a blog article with a detailed look at the many new features & improvements Teensyduino 1.54 adds.

    https://www.pjrc.com/teensyduino-1-54-released/
    This is great. Thank you. I had not been able to glean this information from the various detailed threads.

  2. #27
    Member
    Join Date
    Jun 2016
    Location
    Rennes France
    Posts
    39
    Thanks too for your blog article. Just 3 questions about serial buffer.
    1) What is the native buffer size of the serial ports?
    2) Is SerialX.flush() have one effect on the buffer create with .addMemoryForWrite() and .addMemoryForRead() or only with native buffer ?
    3) What about interaction with teensyThreads?

  3. #28
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,868
    1) 64 bytes, the hardware has FIFO, thats not included in the standard 64bytes of the driver
    2) inclusive
    3) always use a mutex, should be fine

  4. #29
    Looks like something is broken in this version regarding the SD card.
    I'm going crazy porting a 3.6 project to 4.1 and I was stuck on why my SD stored webpage does not load on 4.1, while the file it's there.
    So I went back to my perfectly working 3.6 and I tried to compile my perfectly working project with both Teensyduino 1.53 and 1.54 (I use portable arduino for easier testing of different versions).

    The following code:
    Code:
      else {       //if no get, show the configuration page
    //  DEBUG_PRINTLN("Got Request:");
        webFile = SD.open("m2q.htm");        // open web page file
        if (webFile) {
    //      DEBUG_PRINTLN("Found File:");
          while(webFile.available()) {
            client.write(webFile.read()); // send web page to client
          }
          webFile.close();
        }
        else {
          DEBUG_PRINTLN("Webpage SD file not found!"); 
          client.println("Can't find webpage! Check SD Card");     
        }
    Works perfectly on 1.53 but the webpage does not load with 1.54. Same board (teensy 3.6), same SD card, same file.
    It must be something in the reading of the file from SD because it does not trigger a missing file error, but the page does not load and keeps spinning.
    Loading an Internal webpage from Json and not a HTTP file from SD card works, so it's not something in the ethernet communication.
    Any idea what to check here?
    thank you

  5. #30
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,026
    Quote Originally Posted by lorenzofattori View Post
    Any idea what to check here?
    Nope, no idea. Looks like it should work.

    I'm tempted to try to fill in the rest of the code to run this here, but usually when I do that I rarely end up managing to reproduce the problem. I also don't know which Ethernet hardware you're using.

    Any chance you could give me a small but complete program to try running here? Any tell me which Ethernet shield you're using, and whether the SD card is in the built in SD socket or on SPI (a detail which should be apparent in the code too...) I'd like to try running it here and see if I can reproduce the problem.

  6. #31
    Quote Originally Posted by PaulStoffregen View Post
    Nope, no idea. Looks like it should work.

    I'm tempted to try to fill in the rest of the code to run this here, but usually when I do that I rarely end up managing to reproduce the problem. I also don't know which Ethernet hardware you're using.

    Any chance you could give me a small but complete program to try running here? Any tell me which Ethernet shield you're using, and whether the SD card is in the built in SD socket or on SPI (a detail which should be apparent in the code too...) I'd like to try running it here and see if I can reproduce the problem.
    While I can't share the entire project (proprietary, big and chaotic) let me try something more tomorrow morning and if I can't get anything out I will prepare something and bring more information.
    I first want to try some examples first, so I can confirm if it's indeed something related with SD (biggest change I can see in the changelog) oe with the Ethernet / Webserver communication.

    Thank you for your offer, I'll keep you posted.

  7. #32
    Quote Originally Posted by PaulStoffregen View Post
    Nope, no idea. Looks like it should work.

    I'm tempted to try to fill in the rest of the code to run this here, but usually when I do that I rarely end up managing to reproduce the problem. I also don't know which Ethernet hardware you're using.

    Any chance you could give me a small but complete program to try running here? Any tell me which Ethernet shield you're using, and whether the SD card is in the built in SD socket or on SPI (a detail which should be apparent in the code too...) I'd like to try running it here and see if I can reproduce the problem.

    Ok, it seems there is a bug somewhere.
    I tried the standard Ethernet Webserver demo and it works with both versions, but the moment I ask to load the file from the SD card it works with TeensyDuino 1.53 but not with 1.54.
    I prepared this basic sketch based on the Ethernet Webserver demo but modified it to load a file from the SD card and a file.htm that needs to be placed in the SD card to be read.

    I loaded the files here: https://github.com/lorenzofattori/TeensySDbug

    If you take this .ino file and compile it with Arduino 1.8.13 with Teensyduino 1.53, then take the file.htm and copy on an SD card and stick it in Teensy 3.6, the webpage loads correctly (see https://github.com/lorenzofattori/Te...g.png?raw=true)
    If you do the same with Arduino 1.8.15 with Teensyduino 1.54, the webpage does not load (see https://github.com/lorenzofattori/Te...g.png?raw=true )


    Some Info:
    - I am using Teensy 3.6 with the configuration seen in the screenshots
    - I am using the WIZ850io Ethernet module, please note in the code I'm using different CS and SCK pins due to my hardware PCB, adjust them as necessary for your board.
    - I am using a direct connection between my PC and the WIZ module, with IP address of the Teensy set to 2.0.0.100, you can change this to meet your needs.
    - I am using a 2GB SanDisk card in the built-in SD connector of Teensy 3.6
    - I am using Windows 10 with Arduino Portable (so I can easily switch and upgrade between versions)
    - The page does NOT load when using Arduino 1.8.15 with Teensyduino 1.54
    - The page does load when using Arduino 1.8.13 with Teensyduino 1.53


    I hope this information is enough for you to try and see if you can find out if it's a user error or what.
    If you need any extra info please let me know.
    Thank you in advance!

  8. #33
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,317
    Code:
      digitalWrite(SS_SD_CARD, LOW);  // SD Card Enabled
      delay(1000);
      if (!SD.begin(SS_SD_CARD)) {
        Serial.println("SD Card initialization failed!");
        return;
      }
      Serial.println("SD Card initialization done.");
      digitalWrite(SS_SD_CARD, HIGH);  // SD Card disabled
    to me this snippet of code does not make sense for
    Code:
    #define SS_SD_CARD   BUILTIN_SDCARD       // using SD card in the main board
    BUITIN_SDCARD is not a valid pin to be set low or high

    maybe it only worked by chance for TD1.53

  9. #34
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,026
    Quote Originally Posted by lorenzofattori View Post
    - The page does NOT load when using Arduino 1.8.15 with Teensyduino 1.54
    - The page does load when using Arduino 1.8.13 with Teensyduino 1.53
    I ran your program here. I could not get it to work on either Arduino 1.8.13 + Teensyduino 1.53 or Arduino 1.8.15 + Teensyduino 1.54.

    The main problem is the "while (client.connected()) {" loop. The browser doesn't disconnect, and it doesn't recognize the response as complete, so it just sits forever waiting.

    Just adding a "break" at the end of transmitting the data makes it work on both versions.

    I also changed the file read & write to this, which can confirm the data really is being read from the SD card if you uncomment 2 lines:

    Code:
                while (webFile.available()) {
                  int n = webFile.read();
                  //Serial.print(".");
                  //Serial.println((char)n);
                  client.write(n); // send web page to client
                }
    Here is a screenshot of it working with Arduino 1.8.15 + Teensyduino 1.54.

    Click image for larger version. 

Name:	screenshot.jpg 
Views:	51 
Size:	88.1 KB 
ID:	25313

    This is the complete program I ran.

    Code:
    #include <SPI.h>
    #include <Ethernet.h>
    #include <SD.h>
    
    
    File webFile;       //webpage
    #define SS_SD_CARD   BUILTIN_SDCARD       // using SD card in the main board
    
    // Enter a MAC address and IP address for your controller below.
    // The IP address will be dependent on your local network:
    byte mac[] = {
      0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    };
    IPAddress ip(192, 168, 194, 72);
    
    // Initialize the Ethernet server library
    // with the IP address and port you want to use
    // (port 80 is default for HTTP):
    EthernetServer server(80);
    
    void setup() {
    
      //digitalWrite(SS_SD_CARD, LOW);  // SD Card Enabled
      delay(1000);
      if (!SD.begin(SS_SD_CARD)) {
        Serial.println("SD Card initialization failed!");
        return;
      }
      Serial.println("SD Card initialization done.");
      //digitalWrite(SS_SD_CARD, HIGH);  // SD Card disabled
    
    
    
      // You can use Ethernet.init(pin) to configure the CS pin
      //Ethernet.init(10);  // Most Arduino shields
      //Ethernet.init(5);   // MKR ETH shield
      //Ethernet.init(0);   // Teensy 2.0
      Ethernet.init(10);  // Teensy++ 2.0
      //SPI.setSCK(14);
      //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
      //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet
    
      // 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
      }
      Serial.println("Ethernet WebServer Example");
    
      // start the Ethernet connection and the server:
      Ethernet.begin(mac, ip);
    
      // 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() {
      Serial.println("main loop");
      delay(200);
      // 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) {
              Serial.println("send http header");
              // 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();
    
              Serial.println("about to open file.htm");
              webFile = SD.open("file.htm");        // open web page file
              Serial.println("about to opened file.htm");
              if (webFile) {
                Serial.println("open successful");
                while (webFile.available()) {
    
                  int n = webFile.read();
                  //Serial.print(".");
                  //Serial.println((char)n);
                  client.write(n); // send web page to client
                }
                webFile.close();
    
    
              }
              else {
                client.println("Can't find webpage! Check SD Card");
              }
    
              //client.println("This is a test...");
              break;  // <----- this is needed because browser does not close connection
            }
            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;
            }
          }
        }
        Serial.println("client no longer available");
        // give the web browser time to receive the data
        delay(1);
        // close the connection:
        client.stop();
        Serial.println("client disconnected");
      }
    }
    I did have to change the IP number, and I commented out "SPI.setSCK(14);" since I tested with a WIZ820 adapter and Wiz850io ethernet module.

    Here's a photo of the hardware I used for this test.

    Click image for larger version. 

Name:	DSC_1539_web.jpg 
Views:	47 
Size:	144.8 KB 
ID:	25312

  10. #35
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    821
    On a related note, because of this line: client.println("Connection: close"); the browser will not close the connection on its own. I discovered this when making my version of the library, what this means is that immediately after the server sends its data then it is supposed to close the transmitting side of its socket but its still able to receive data. The browser is expecting this so it will not close first, I ended up having to add a separate client.close() command for my version of the library in order to support that properly.

  11. #36
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,026
    Yeah, I fiddled with the http header and other stuff when first starting to investigate this. Really should have put that back as it was. But I'll admit, most of my effort was looking at whether we had a bug with the SD & SdFat libraries or something wrong with SPI. When it because clear SD was working fine, I wrapped this up quickly without doing the thorough look into the real the reason the http session was stalling. Once a quick hack was working in both versions, cut this short and move on to other stuff. Somewhat sloppy on my part, but I do have a huge backlog of stuff I want to do that's growing longer every day while I try to get the flash encryption project to a usable point.

  12. #37
    Quote Originally Posted by PaulStoffregen View Post
    I ran your program here. I could not get it to work on either Arduino 1.8.13 + Teensyduino 1.53 or Arduino 1.8.15 + Teensyduino 1.54.

    The main problem is the "while (client.connected()) {" loop. The browser doesn't disconnect, and it doesn't recognize the response as complete, so it just sits forever waiting.

    Just adding a "break" at the end of transmitting the data makes it work on both versions.

    I also changed the file read & write to this, which can confirm the data really is being read from the SD card if you uncomment 2 lines:

    Code:
                while (webFile.available()) {
                  int n = webFile.read();
                  //Serial.print(".");
                  //Serial.println((char)n);
                  client.write(n); // send web page to client
                }
    Here is a screenshot of it working with Arduino 1.8.15 + Teensyduino 1.54.

    Click image for larger version. 

Name:	screenshot.jpg 
Views:	51 
Size:	88.1 KB 
ID:	25313

    This is the complete program I ran.

    Code:
    #include <SPI.h>
    #include <Ethernet.h>
    #include <SD.h>
    
    
    File webFile;       //webpage
    #define SS_SD_CARD   BUILTIN_SDCARD       // using SD card in the main board
    
    // Enter a MAC address and IP address for your controller below.
    // The IP address will be dependent on your local network:
    byte mac[] = {
      0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    };
    IPAddress ip(192, 168, 194, 72);
    
    // Initialize the Ethernet server library
    // with the IP address and port you want to use
    // (port 80 is default for HTTP):
    EthernetServer server(80);
    
    void setup() {
    
      //digitalWrite(SS_SD_CARD, LOW);  // SD Card Enabled
      delay(1000);
      if (!SD.begin(SS_SD_CARD)) {
        Serial.println("SD Card initialization failed!");
        return;
      }
      Serial.println("SD Card initialization done.");
      //digitalWrite(SS_SD_CARD, HIGH);  // SD Card disabled
    
    
    
      // You can use Ethernet.init(pin) to configure the CS pin
      //Ethernet.init(10);  // Most Arduino shields
      //Ethernet.init(5);   // MKR ETH shield
      //Ethernet.init(0);   // Teensy 2.0
      Ethernet.init(10);  // Teensy++ 2.0
      //SPI.setSCK(14);
      //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
      //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet
    
      // 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
      }
      Serial.println("Ethernet WebServer Example");
    
      // start the Ethernet connection and the server:
      Ethernet.begin(mac, ip);
    
      // 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() {
      Serial.println("main loop");
      delay(200);
      // 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) {
              Serial.println("send http header");
              // 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();
    
              Serial.println("about to open file.htm");
              webFile = SD.open("file.htm");        // open web page file
              Serial.println("about to opened file.htm");
              if (webFile) {
                Serial.println("open successful");
                while (webFile.available()) {
    
                  int n = webFile.read();
                  //Serial.print(".");
                  //Serial.println((char)n);
                  client.write(n); // send web page to client
                }
                webFile.close();
    
    
              }
              else {
                client.println("Can't find webpage! Check SD Card");
              }
    
              //client.println("This is a test...");
              break;  // <----- this is needed because browser does not close connection
            }
            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;
            }
          }
        }
        Serial.println("client no longer available");
        // give the web browser time to receive the data
        delay(1);
        // close the connection:
        client.stop();
        Serial.println("client disconnected");
      }
    }
    I did have to change the IP number, and I commented out "SPI.setSCK(14);" since I tested with a WIZ820 adapter and Wiz850io ethernet module.

    Here's a photo of the hardware I used for this test.

    Click image for larger version. 

Name:	DSC_1539_web.jpg 
Views:	47 
Size:	144.8 KB 
ID:	25312

    Thank you so much for all your effort in troubleshooting this. This is extremely valuable for me.
    However the situation here is still different, I copied/pasted your code, changed only IP address and SCK pin and the page is stuck on loading.
    I commented out the Serial print on the SD reading and it seems stuck on SD reading as I still see dots being printed and not going back to the main loop.

    Click image for larger version. 

Name:	still-not-working.jpg 
Views:	45 
Size:	54.7 KB 
ID:	25321

    I will continue troubleshooting it now that I know it works on your side and I will try some basic things first, changing SD, cables see if I have another Teensy or WIZ module at home, etc.
    I'll keep you posted.

  13. #38
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,026
    I see the contents of file.htm printing to the serial monitor in your screenshot, so I'm pretty sure the SD library is correctly reading that file.

    Which browser are you using? What version? I could start up Windows 10 here and give it another quick try...

  14. #39
    Member DIYLAB's Avatar
    Join Date
    Jun 2020
    Location
    Germany
    Posts
    64
    Hi,

    I need to download the latest version 1.53 again for testing.
    Where can I find it?

    Since version 1.54 my projects cannot communicate with the desktop program in C# because TeensySharp throws errors and Teensy-ID returns wrong values from the controller.

  15. #40
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,255

  16. #41
    Quote Originally Posted by PaulStoffregen View Post
    I see the contents of file.htm printing to the serial monitor in your screenshot, so I'm pretty sure the SD library is correctly reading that file.

    Which browser are you using? What version? I could start up Windows 10 here and give it another quick try...
    Thank you Paul for your offer and dedication.
    While testing around I saw that the page was sometimes loading, sometimes was stuck in the middle of the HTML file.
    I just swapped the SD card and now the page loads perfectly every single time (*facepalm)
    previous SD is now in the trash bin.

    I will now go on implementing the good changes in your code which are still extremely valuable for me, my code was based on copy-pasting of various tutorials so a peer check is always appreciated.
    If for any reason I will see the behavior again with other SD cards I will be back here, but I think it can be easily pinpointed to defective hardware.

    I'm so sorry for wasting your time.
    Thank you for everyone helping here.

  17. #42
    Member DIYLAB's Avatar
    Join Date
    Jun 2020
    Location
    Germany
    Posts
    64
    Hi,

    I have now created my current project for testing with version 1.53 and 1.54.

    With version 1.53 this is delivered:
    mgmtObj = {\\DELL\root\CIMV2:Win32_PnPEntity.DeviceID="USB\\VID_16C0&PID_0483\\7731230"}

    With version 1.54 this comes:
    mgmtObj = {\\DELL\root\CIMV2:Win32_PnPEntity.DeviceID="USB\\VID_16C0&PID_0483&MI_00\\6&15BF7C7&0&0000"}

    This completely messes up "TeensySharp" and thereby the whole project.
    Before I contact the author of "TeensySharp", I would like to know if something has changed in version 1.54 in this regard. Where do the different device IDs come from?

    Kind regards
    Bruno

  18. #43
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,026
    Quote Originally Posted by DIYLAB View Post
    This completely messes up "TeensySharp" and thereby the whole project.
    Before I contact the author of "TeensySharp", I would like to know if something has changed in version 1.54 in this regard. Where do the different device IDs come from?
    Yes, the USB descriptors changed to use IAD. TeensySharp will need to be updated.

  19. #44
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,618
    TeensySharp was written some 6 years ago and has a rather small user base (<300 downloads at nuget). So, I have to admit that it was not very well maintained over the years. However, ~two years ago I spent some time to upgrade it to the then new multiple Serial ports which also required supporting the IAD descriptors. This upgraded version works but was never really finished and not much tested. It lives in the development branch of the repo. I recently got a request to support the new MicroMode versions so, I started to work on it again (at least whenever I find some time...). I would be glad if you could give it a try and identify open bugs.

    It might be better to move this discussion to the TeensySharp thread https://forum.pjrc.com/threads/29063...r-Applications or to the gitHub repo: https://github.com/luni64/TeensySharp/discussions

  20. #45
    Quote Originally Posted by PaulStoffregen View Post
    I ran your program here. I could not get it to work on either Arduino 1.8.13 + Teensyduino 1.53 or Arduino 1.8.15 + Teensyduino 1.54.

    The main problem is the "while (client.connected()) {" loop. The browser doesn't disconnect, and it doesn't recognize the response as complete, so it just sits forever waiting.

    Just adding a "break" at the end of transmitting the data makes it work on both versions.

    I also changed the file read & write to this, which can confirm the data really is being read from the SD card if you uncomment 2 lines:

    Code:
                while (webFile.available()) {
                  int n = webFile.read();
                  //Serial.print(".");
                  //Serial.println((char)n);
                  client.write(n); // send web page to client
                }
    Here is a screenshot of it working with Arduino 1.8.15 + Teensyduino 1.54.

    Click image for larger version. 

Name:	screenshot.jpg 
Views:	51 
Size:	88.1 KB 
ID:	25313

    This is the complete program I ran.

    Code:
    #include <SPI.h>
    #include <Ethernet.h>
    #include <SD.h>
    
    
    File webFile;       //webpage
    #define SS_SD_CARD   BUILTIN_SDCARD       // using SD card in the main board
    
    // Enter a MAC address and IP address for your controller below.
    // The IP address will be dependent on your local network:
    byte mac[] = {
      0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    };
    IPAddress ip(192, 168, 194, 72);
    
    // Initialize the Ethernet server library
    // with the IP address and port you want to use
    // (port 80 is default for HTTP):
    EthernetServer server(80);
    
    void setup() {
    
      //digitalWrite(SS_SD_CARD, LOW);  // SD Card Enabled
      delay(1000);
      if (!SD.begin(SS_SD_CARD)) {
        Serial.println("SD Card initialization failed!");
        return;
      }
      Serial.println("SD Card initialization done.");
      //digitalWrite(SS_SD_CARD, HIGH);  // SD Card disabled
    
    
    
      // You can use Ethernet.init(pin) to configure the CS pin
      //Ethernet.init(10);  // Most Arduino shields
      //Ethernet.init(5);   // MKR ETH shield
      //Ethernet.init(0);   // Teensy 2.0
      Ethernet.init(10);  // Teensy++ 2.0
      //SPI.setSCK(14);
      //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
      //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet
    
      // 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
      }
      Serial.println("Ethernet WebServer Example");
    
      // start the Ethernet connection and the server:
      Ethernet.begin(mac, ip);
    
      // 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() {
      Serial.println("main loop");
      delay(200);
      // 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) {
              Serial.println("send http header");
              // 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();
    
              Serial.println("about to open file.htm");
              webFile = SD.open("file.htm");        // open web page file
              Serial.println("about to opened file.htm");
              if (webFile) {
                Serial.println("open successful");
                while (webFile.available()) {
    
                  int n = webFile.read();
                  //Serial.print(".");
                  //Serial.println((char)n);
                  client.write(n); // send web page to client
                }
                webFile.close();
    
    
              }
              else {
                client.println("Can't find webpage! Check SD Card");
              }
    
              //client.println("This is a test...");
              break;  // <----- this is needed because browser does not close connection
            }
            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;
            }
          }
        }
        Serial.println("client no longer available");
        // give the web browser time to receive the data
        delay(1);
        // close the connection:
        client.stop();
        Serial.println("client disconnected");
      }
    }
    I did have to change the IP number, and I commented out "SPI.setSCK(14);" since I tested with a WIZ820 adapter and Wiz850io ethernet module.

    Here's a photo of the hardware I used for this test.

    Click image for larger version. 

Name:	DSC_1539_web.jpg 
Views:	47 
Size:	144.8 KB 
ID:	25312


    Just a followup on this since someone might find this while going through the forum and struggling to make it work on Teensy 4.1
    Since all of this started from porting the code back to Teensy 4.1, I went back trying to run it on Teensy 4.1 using the NativeEthernet library.
    Unfortunately the same code does not run on 4.1, while page gets loaded properly (I can see that in the serial console) the browser is stuck in loading and mentions that the connections is reset while loading the page.
    Adding a small delay in the load of the page makes it work correctly.

    Code:
                while (webFile.available()) {
    
                  int n = webFile.read();
                  Serial.print(".");
                  Serial.println((char)n);
                  delay(1);  //<--- had to add this in order to make it work on Teensy 4.1
                  client.write(n); // send web page to client
                }
                webFile.close();
    I don't know why, (4.1 is too fast?) but I thought it was worth mentioning it here if someone else is struggling with the same.

  21. #46
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    821
    Quote Originally Posted by lorenzofattori View Post
    Just a followup on this since someone might find this while going through the forum and struggling to make it work on Teensy 4.1
    Since all of this started from porting the code back to Teensy 4.1, I went back trying to run it on Teensy 4.1 using the NativeEthernet library.
    Unfortunately the same code does not run on 4.1, while page gets loaded properly (I can see that in the serial console) the browser is stuck in loading and mentions that the connections is reset while loading the page.
    Adding a small delay in the load of the page makes it work correctly.

    Code:
                while (webFile.available()) {
    
                  int n = webFile.read();
                  Serial.print(".");
                  Serial.println((char)n);
                  delay(1);  //<--- had to add this in order to make it work on Teensy 4.1
                  client.write(n); // send web page to client
                }
                webFile.close();
    I don't know why, (4.1 is too fast?) but I thought it was worth mentioning it here if someone else is struggling with the same.
    This is what I meant about adding the client.close() command in my library, remove the delay, and put a client.close() command before the break that Paul added. I didnít document this change too well since it wasnít discovered until after I initially made the library, it was only added into the WebServerMDNS example here and not the regular WebServer example.

  22. #47
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,255
    @Paul, for the new wavePlayer:

    - Do we still need AudioStartUsingSPI() or is this handled by the SdFat?
    - Is there a way to know if it a file is from BULITIN_SDCARD, SPI, LittleFs? Maybe this is useful.. perhaps we can use smaller buffers for faster interfaces (or larger for SPI)

  23. #48
    Junior Member
    Join Date
    Jul 2021
    Posts
    19
    W.r.t. TeensyDebug:
    The debugger does not work for me using Arduino 1.8.15 and Teensyduino 1.54.
    See posts #93 and onwards of https://forum.pjrc.com/threads/61373...rst-Beta/page4

    But if I revert to Arduino 1.8.13 and Teensyduino 1.53 it works!

  24. #49
    Quote Originally Posted by Frank B View Post
    There was an update of Platformio, for Teensy, but they still use the old size tool
    Do you use the latest Teensy dev-platform for PlatformIO? See https://forum.pjrc.com/threads/67885...tformIO-is-out!

  25. #50
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,255
    Quote Originally Posted by ikravets View Post
    Do you use the latest Teensy dev-platform for PlatformIO? See https://forum.pjrc.com/threads/67885...tformIO-is-out!
    Yes.
    PACKAGES:
    - framework-arduinoteensy 1.154.0 (1.54)
    The size print looks like this:
    Code:
    RAM:   [===       ]  26.6% (used 139616 bytes from 524288 bytes)
    Flash: [          ]   0.9% (used 75736 bytes from 8126464 bytes)
    Building .pio\build\teensy41\firmware.hex
    ..which is not as good as the one Teensy has for T4/4.1/MM
    which looks like this (more or less (I use a slightly modified version))

    Code:
    (FB) Memory Usage on Teensy 4.1:
      FLASH: code:26884, data:3784, headers:8240   free for files:8087556
       RAM1: code:24264, variables:17088   free for local variables:474432
       RAM2: variables:12384  free for malloc/new:511904

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •