Are there 'readable' shield Id's?



  • When my lopy powers up I'd like to know if it is connected through a pytrack or some other shield (pytrack is the key). I want to be able to configure the lopy to gather gps info only if the pytrack is connected at run-time. I have it working if I put a flag in the config.py file but I would rather know autonomously at run-time.

    Is there a register (SPI or I2C) that might hold some type of Id to indicate the connected shield?



  • @seb First I want to thank you for your help - you have helped me resolve the board detection issue. I understand try/except is the "python way" but as a developer with a much more structured background I was hoping for a solution that might be more robust so as not to encounter issues in the future as the interface or hardware might change.
    I really do appreciate your time and effort and I understand this is likely the best solution for now.



  • @seb
    I think it is more about reading/guessing the product from the version number.



  • @oldguydave

    I wouldn't say that this is a dirty solution, in python exceptions are not as "expensive" as in other languages, as it is design for this kind of flow. I've heard people say that in python "it is better to ask for forgiveness than to ask for permission". Depending on what you are trying to do (for example will you be using custom base boards?) it might be better to take @jcaron 's approach and scan the i2c bus for specific sensors.



  • @seb Thank you. That is the "little dirty" work around I was thinking about. That's why I asked it ther was a better 'clean' solution, but I can work with that.

    Thanks for your help.



  • You can probably try a scan on the I2C bus(es) and see if anything responds. Not sure if you are trying to detect the Pysense/Pytrack/Expansion board specifically, or if you want to detect specific components on each?



  • @oldguydave

    Just wrap the call like so:

    kind = None
    try:
        v = py.read_hw_version()
        if v == 2:
            kind = "Pysense"
        if v == 3:
            kind = "Pytrack"
    except OSError:
        kind = "Expansion Board"
    


  • @seb Thank you for the prompt response. The solution works perfectly for the pytrack shield, unfortunately one of the shields that may deployed is the expansion board. When this shield is deployed the call to read_hw_version() fails:
    File "/flash/lib/pycoproc.py", line 137, in read_hw_version
    File "/flash/lib/pycoproc.py", line 134, in _send_cmd
    File "/flash/lib/pycoproc.py", line 117, in _write
    OSError: I2C bus error

    Is it fair to assume I2C has not been implemented on the expansion board - I do not see SDL/SDA on the pdf drawing?

    Is there another solution that might work for both? If not I think I can still work with this - although a little dirty.

    Thanks again.



  • @oldguydave

    In the pycoproc class there is a function called read_hw_version, this will return 2 for a Pysense and 3 for a Pytrack



Pycom on Twitter