Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: How does Teensyduino know it's coding for a non-teensy?

  1. #1
    Member
    Join Date
    Jan 2016
    Location
    USA
    Posts
    62

    How does Teensyduino know it's coding for a non-teensy?

    I am having a terrible time writing code to copy a Teensy SD file to a Nano (with SoftSerial connection) SD file. It occurs to me that the Nano compilation may be seeing the Teensy SD library file whose SD.cpp I had to modify by reducing write speed.

    How does the compiler know to use the Teensy SD code instead of the generic Arduino code? Is it by board select or Programmer choice?

    I don't want yet to get into asking for help diagnosing my code because I haven't tried everything. could be SoftwareSerial and I'll find out by copying to a second teensy I have or maybe a mega where I'd have hardware serial.

    it is funny, that I thought this would be easy.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,008
    Quote Originally Posted by jferguson View Post
    How does the compiler know to use the Teensy SD code instead of the generic Arduino code?
    The Arduino IDE searches for libraries in many places, which match the #include lines in your sketch. How it matches them has changed somewhat over the many Arduino versions.

    In recent Arduino, if you turn on Verbose Info in File > Prefs, Arduino will show you a list of the locations where it actually found the libraries.

    If it found more than 1 for each .h file you included, it will also show a message that a conflict was found, with the location of the one it used and other others it ignored. This conflict message is supposed to always appear (but only if a conflict is detected). The non-conflict info only appears in verbose mode.

    So how does it know. Well, first Arduino looks in your sketchbook libraries folder, which is usually Documents/Arduino/libraries (but may be configured elsewhere in File > Prefs). If a matching library is found there, it always overrides all others. This is a powerful feature that lets you always be in control, since the library you put there always overrides others. The location is separate from Arduino's folder, so it persists long-term. It's also a real liability if you forget you put a library there, and months or years later it gets used instead of a newer one elsewhere.

    Next, Arduino looks in the platform libraries folder. This location is determined by which board you selected in Tools > Boards. Actually, which architecture. All the ones grouped in the same arch share a common location. Traditionally these are in hardware/(platformname)/(archname)/libraries. Recent versions of Arduino also allow these to be installed inside your preferences folder, which varies depending on the operating system. Teensyduino puts a customized copy of SD into its own platform folder, which is always hardware/teensy/avr within Arduino's folder. When a platform lib overrides the global ones, it's not considered a conflict for printing a warning, since platforms need to override global libs.

    The global libs folder is the last place Arduino searches. It's the libraries folder you see in Arduino's folder (or inside the app bundle, if using a Mac and you know how to drill down inside it).

    it is funny, that I thought this would be easy.
    Well, it's supposed to be normally be easy.

    As you can infer from those messages and warnings about library locations and conflicts, sometimes it's not so easy. Hopefully those messages can help you understand what Arduino's really doing.

  3. #3
    Member
    Join Date
    Jan 2016
    Location
    USA
    Posts
    62
    thanks for this comprehensive dissertation. It looks like what I need to do is rename the teensy-modified SD files to something like TSD so that i get them when i want them, but not otherwise. four years ago, I needed to modify tinygps to such a degree that the iterations wound up to tinygps8. they were not improvements per-se but more tuning to do only what I needed and nothing else. I think there should be an implicit responsibility to change names in library files where content changes affect how the thing works, even if the change files are unlikely to escape your system.

    it looks like your answer is that if i modified the SD in the teensy subdirectory, this is the one that a teensy compile will see but not if it isn't a teensy.

    thanks again. john

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,008
    Correct. When you have any non-Teensy board selected, Arduino should never look for libraries in hardware/teensy/avr/libraries.

Posting Permissions

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