Sending data into Teensy 4

Status
Not open for further replies.

smarrocco

Member
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?
 
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.
 
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.
 
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.
 
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.
 
Status
Not open for further replies.
Back
Top