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

Thread: Sending data into Teensy 4

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    16

    Sending data into Teensy 4

    I have a Teensy 4 running an application that has some settings that are read at startup. The C++ code contains those setting in the source. I would like to be able to modify the settings without having to recompile/upload the source each time. I have considered storing those settings on the EEPROM, but settled on an external micro-SD card. This allows me to place the micro-SD card into a PC and write the new default to a file, then transplant the micro-SD card to the Teensy/reader for reading. While this works, it is a bit tedious, and requires keeping a compiler/uploader system handy.

    Is there a method from which I could write the settings directly to the Teensy/micro-SD card combination from the PC connected to the Teensy via USB? This would prevent having to move the SD card back and forth between the PC and the Teensy/Reader.....or might there be another method I'm overlooking for sending some data to a Teensy that is running code *while it is running* from a PC via USB without re-uploading the code?

  2. #2
    Junior Member
    Join Date
    Feb 2019
    Posts
    4
    Using the Serial library would be the easiest way.

    https://www.pjrc.com/teensy/td_uart.html

  3. #3
    Senior Member
    Join Date
    Feb 2015
    Posts
    212
    Serial would be the easiest for the transport, but you'll need to establish some kind of protocol for how the PC side and Teensy side will talk to each other. In the past I have used something called Protocol Buffers to do this. It's a bit weird to wrap your head around it, but once it clicks it's incredibly powerful. There's an embedded implementation of Protocol Buffers called Nanopb and it's great: https://github.com/nanopb/nanopb

    I implemented a pattern called Remote Procedure Call (RPC) and really liked it, but there are other patterns as well.

    If you want something that is more of a "batteries included" solution where you're not having to define your own protocols, there are a bunch of Arduino libraries like this: https://github.com/PowerBroker2/SerialTransfer and this: https://github.com/bakercp/PacketSerial which should compile and work on the Teensy.

    Obviously, with this sort of thing, you will be required to implement some kind of application on the PC side to actually build the packets and send them to the Teensy.

  4. #4
    The other route that might be worth considering is MTP RESPONDER.
    I'm not sure how well trodden a path this is on a Teensy 4 yet, it was at an experimental level for Teensy 3.6 some time ago and worked for me.
    I can plug into my T3.6 with USB and drag files from the SD, just using MS Windows Explorer, so my guess is you could drag a text file with your new configuration variables and get your code to check for that file on a regular basis. This route potentially allows a non-technical non-teensy person to update the config assuming they can use a text editor, and it allows you to place the SD card in any location buried inside an enclosure.

  5. #5
    Junior Member
    Join Date
    Jan 2020
    Posts
    16
    Quote Originally Posted by jdriedger View Post
    Using the Serial library would be the easiest way.

    https://www.pjrc.com/teensy/td_uart.html

    Thanks jdriedger. I was unaware that I could communicate with serial over the same USB being used for other things. That does look like the simplest method.

  6. #6
    Junior Member
    Join Date
    Jan 2020
    Posts
    16
    Thank you. The Protocol Buffers material look interesting also, but the simplicity of the serial option might be just what I need for this project.

  7. #7
    Senior Member
    Join Date
    Feb 2015
    Posts
    212
    Well, even using Serial over USB, you'll still need to either establish your own protocol or use a library that handles the protocol aspect for you.

Posting Permissions

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