PC software to modify "settings" of a Teensy-based device via USB

Status
Not open for further replies.

thoraxe

Member
I'm not really sure what this is called, which is why I'm having trouble searching for answers.

I have a project in mind where I'd like the end-user to be able to hook the device up to their PC and to run software (that I will write) that can communicate to the Teensy via USB to modify the device settings, and not the actual firmware/code installed on the device.

For example, in a pseudocode-type sense:

Code:
int modifyable_value = 7

...

if modifyable_value > 7
  thing

In the scenario above, the PC software would allow the user to change the value of modifyable_value only.

What is doing this kind of thing called and are there any examples out there of the basics?
 
Note: Teensy does not provide any way for self modifying code. So no way for you to update directly int modifyable_value to now be 8.

However you can write code, that takes USB input like Serial.read() and define your own way to know you wish to update the value, and then store the value in some
place that is persistent. Example EEPROM. You could say that position 0 in the EEPRM is your modifyable_value.

As the program starts up, your code could do an EEPROM read for that position and use it. When I have done this in the past and had N values: like lets say 18 two byte values for
servo offsets, my code when updating these values would do a quick and dirty checksum of the data to make sure it was my data... Also I might have another byte with version number.
Which I would verify that the data looked reasonable and if not have a set of defaults I would use.

You can store data like this in several different ways, like instead of EEPROM you may have the option of storing data on a file stored on your teensy. Example SD Card, or if you have some form of flash memory, using LittleFS. If T4.x and latest Teensyduino, you could have a Filesystem using part of the unused program space.

Hope that helps
 
Note: Teensy does not provide any way for self modifying code. So no way for you to update directly int modifyable_value to now be 8.

Makes sense!

However you can write code, that takes USB input like Serial.read() and define your own way to know you wish to update the value, and then store the value in some
place that is persistent. Example EEPROM. You could say that position 0 in the EEPRM is your modifyable_value.

I forgot about EEPROM. This is likely the way. I'd never looked into it, and I don't particularly care (the code will probably be open-source anyway): is there a way to read the code from the Teensy back into the IDE, or is it getting compiled down into machine-code anyway and it's not really reverse-engineer-able that way? Is there a way to "lock" a Teensy to prevent further programming?

As the program starts up, your code could do an EEPROM read for that position and use it. When I have done this in the past and had N values: like lets say 18 two byte values for
servo offsets, my code when updating these values would do a quick and dirty checksum of the data to make sure it was my data... Also I might have another byte with version number.
Which I would verify that the data looked reasonable and if not have a set of defaults I would use.

Sounds perfectly reasonable. I'd think you'd want maybe two checksums:

1) is incoming data really coming from the PC-based application? Or is it just random junk data happening to come in via serial?
2) when the device boots up, is the stored data valid? if not, revert to defaults.

You can store data like this in several different ways, like instead of EEPROM you may have the option of storing data on a file stored on your teensy. Example SD Card, or if you have some form of flash memory, using LittleFS. If T4.x and latest Teensyduino, you could have a Filesystem using part of the unused program space.

Hope that helps

EEPROM is probably the way here. The data is minuscule and the PROM is totally large enough.

These are great tips to get me moving forward. Thank you.
 
I like to use Lua via a web interface, but that’s mostly for behavioral changes. It’s also possible to set variables there. Or, some sort of form via a webpage is also useful. The persistence is in a filesystem of some sort via LittleFS (because I’m using Lua text files). For plain settings, EEPROM.
 
Status
Not open for further replies.
Back
Top