teensy mtp - windows explorer shows teensy - how can i change the name?

Fluxanode

Well-known member
I think my question has already been answered but I can't find it, how can i change the name MTP shows from teensy?
 
I think my question has already been answered but I can't find it, how can i change the name MTP shows from teensy?
If memory serves me correctly "Teensy" is hardcoded into the library. If you look in MTP_Teensy.h (assuming you are using @KurtE's github version) you will see:

Code:
#include "MTP_Storage.h"
// modify strings if needed (see MTP.cpp how they are used)
#define MTP_MANUF "PJRC"
#define MTP_MODEL "Teensy"
#define MTP_VERS "1.0"
#define MTP_SERNR "1234"
#define MTP_NAME "Teensy"

You would have to change MTP_NAME to want you want - no programmatical way to change it.
 
If memory serves me correctly "Teensy" is hardcoded into the library. If you look in MTP_Teensy.h (assuming you are using @KurtE's github version) you will see:
Paul's version will take over. https://github.com/PaulStoffregen/MTP_Teensy


However I am not sure what his current plans are. That is at one point he was going to integrate MTP probably
directly into the core project, like all of the other USB types. At that point hopefully there will be settings in the header files
to make it easier to customize.

Although not sure if it is any easier/harder to change places like usbdesc.h or MTP_Teensy.h...
 
I was messing around with MTP and made the above changes to MTP_Teensy.h with one of the example programs and now the teensy 4.1 won't show up as a usb device in Arduino. The comm port (com4) shows but not the HID. I can't program it any longer. Did i break something?

Error is
Teensy should be selected from "teensy ports" rather
than "Serial ports" in Arduino's Tools > Port menu
No Teensy boards were found on any USB ports of your computer.
Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.

program:

Code:
 SD datalogger

  This example shows how to log data from three analog sensors
  to a storage device such as a microSD card.

  This example code is in the public domain.
*/

#include <SD.h>
#include <MTP_Teensy.h>

File dataFile; // Specifies that dataFile is of File type

int record_count = 0;
bool write_data = false;

/////////////////////////////////////////////Setup/////////////////////////
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    // wait for serial port to connect.
  }
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);

  Serial.print("Initializing SD card ...");
  if (!SD.begin(BUILTIN_SDCARD)) {
    Serial.println("Error mounting SD card!");
    while (1) {
      // Error, so don't do anything more - stay stuck here
    }
  }

  MTP.begin();
  MTP.addFilesystem(SD, "SD");

  Serial.println("SD card initialized.");

  menu();
}

/////////////////////////////////////////////main loop//////////////////////
void loop() {
  MTP.loop();

  if (write_data) {
    logData();
  }

  if (Serial.available()) {
    char rr = Serial.read();
    switch (rr) {
      case 'l':
        listFiles();
        break;
      case 'e':
        eraseFiles();
        break;
      case 's':
        Serial.println("\nLogging Data!!!");
        write_data = true; // continue writing data until stopped
        dataFile = SD.open("datalog.txt", FILE_WRITE);
        logData();
        break;
      case 'x':
        stopLogging();
        break;
      case 'd':
        dumpLog();
        break;
      case '\r':
      case '\n':
      case 'h':
        menu();
        break;
    }
    while (Serial.read() != -1);
  }
}
///////////////////////////////////////////////////////////////////////END OF main

void logData() {
  // assemble the data to log:
  String dataString;

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) dataString += ",";
  }

  if (dataFile) {
    dataFile.println(dataString);
    Serial.println(dataString);
    record_count++;
  } else {
    Serial.println("error opening datalog.txt");
  }
  delay(100);
}

void stopLogging() {
  Serial.println("\nStopped Logging Data!!!");
  write_data = false;
  dataFile.close();
  Serial.printf("Records written = %d\n", record_count);
  MTP.reset();
}

void dumpLog() {
  Serial.println("\nDumping Log!!!");
  dataFile = SD.open("datalog.txt");
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
  } else {
    Serial.println("error opening datalog.txt");
  }
}

void menu() {
  Serial.println();
  Serial.println("Menu Options:");
  Serial.println("\tl - List files on disk");
  Serial.println("\te - Erase log file");
  Serial.println("\ts - Start Logging data");
  Serial.println("\tx - Stop Logging data");
  Serial.println("\td - Dump Log");
  Serial.println("\th - Menu");
  Serial.println();
}

void listFiles() {
  Serial.println("\nDirectory\n---------");
  printDirectory(SD.open("/"), 0);
}

void eraseFiles() {
  if (SD.exists("datalog.txt")) {
    SD.remove("datalog.txt");
  }
  Serial.println("\nLog erased!");
  MTP.reset();
}

void printDirectory(File dir, int numSpaces) {
  while (true) {
    File entry = dir.openNextFile();
    if (!entry) break;
    for (int i = 0; i < numSpaces; i++) Serial.print(" ");
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numSpaces + 2);
    } else {
      for (int i = 0; i < (36 - numSpaces - strlen(entry.name())); i++) Serial.print(" ");
      Serial.print("  ");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}
 
I tested with a new teensy by plugging it into the usb and it behaves as it should but i have not attempted to program it as i don't need it broken too
 
ok got it back after several resets...

Can someone look over my example program and see if there is anything that could have screwed it up?
 
Back
Top