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

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

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Location
    Atlanta, GA
    Posts
    7

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

    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?

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,043
    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

  3. #3
    Junior Member
    Join Date
    Dec 2021
    Location
    Atlanta, GA
    Posts
    7
    Quote Originally Posted by KurtE View Post
    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!

    Quote Originally Posted by KurtE View Post
    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?

    Quote Originally Posted by KurtE View Post
    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.

    Quote Originally Posted by KurtE View Post
    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.

  4. #4
    Senior Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    394
    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.

Posting Permissions

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