Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Are there 'readable' shield Id's?

    Scheduled Pinned Locked Moved Comments & Feedback
    lopypytrackexpansion boardpysense
    9 Posts 4 Posters 1.8k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O Offline
      oldGuyDave
      last edited by

      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?

      “Life is trying things to see if they work.” ~Ray Bradbury

      sebS 1 Reply Last reply Reply Quote 0
      • sebS Offline
        seb @oldGuyDave
        last edited by

        @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

        O 1 Reply Last reply Reply Quote 1
        • O Offline
          oldGuyDave @seb
          last edited by

          @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.

          “Life is trying things to see if they work.” ~Ray Bradbury

          sebS 1 Reply Last reply Reply Quote 0
          • sebS Offline
            seb @oldGuyDave
            last edited by

            @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"
            
            O 1 Reply Last reply Reply Quote 0
            • J Offline
              jcaron
              last edited by

              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?

              1 Reply Last reply Reply Quote 0
              • O Offline
                oldGuyDave @seb
                last edited by

                @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.

                “Life is trying things to see if they work.” ~Ray Bradbury

                sebS 1 Reply Last reply Reply Quote 0
                • sebS Offline
                  seb @oldGuyDave
                  last edited by

                  @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.

                  C O 2 Replies Last reply Reply Quote 0
                  • C Offline
                    crumble @seb
                    last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • O Offline
                      oldGuyDave @seb
                      last edited by

                      @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.

                      “Life is trying things to see if they work.” ~Ray Bradbury

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom