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

    Pysense Expansion Board External Header not working

    Scheduled Pinned Locked Moved Firmware
    wipyotherbug
    5 Posts 2 Posters 1.2k Views 2 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.
    • A Offline
      ambropete
      last edited by jmarcelino

      Hi there,
      I got two Pysense expansion boards together with a Wipy. The Wipy works just fine but I have a hard time getting sensor readings from a hc-sr04 sensor to it. The sensor gets 5V and its output signal is level shifted to 3V3. The sensor works well but the connection to the Pysense works just very intermittently. Do you have any suggestions? How can I make this work? Does anyone else have an issue with the Pysense? This is the code I use in Atom:

      import pycom
      import time
      from machine import Pin, Timer
      
      echo = Pin(Pin.exp_board.G7, mode=Pin.IN)
      trigger = Pin(Pin.exp_board.G8, mode=Pin.OUT)
      trigger(0)
      chrono = Timer.Chrono()
      while True:
          chrono.reset()
      
          trigger(1)
          time.sleep_us(10)
          trigger(0)
      
          while echo() == 0:
              pass
      
          chrono.start()
      
          while echo() == 1:
              pass
      
          chrono.stop()
      
          distance = chrono.read_us() / 58.0
      
          if distance > 400:
              print("Out of range")
          else:
              print("Distance {:.0f} cm".format(distance))
      
          time.sleep(500)
      
      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @ambropete
        last edited by

        Hi @ambropete

        How have you connected the sensor to the Pysense?

        Looking at the Pysense pinout G8 is used internally for I2C to the the other sensors on board so you'll have a problem sharing it with your stuff.

        Can you use another pin?

        1 Reply Last reply Reply Quote 0
        • A Offline
          ambropete
          last edited by

          Hi @jmarcelino thank you for your reply.
          The Hc-sr04 is connected via a logic level shifter to the Pysense. Trigger and signal are connected to HV1 and HV2. the ground from the sensor goes to the ground on the HV side. The LV1 trigger signal goes to PIN8 on the Pysense expansion board and the LV2 echo signal to PIN7 on the Pysense, ground goes to Ground which is PIN 1 on the external header of the Pysense.

          Well when you connect the Pysense to the Wipy all PINs G1 until G31 are occupied by the Wipy. So you just have the External IO header PINs 1 until 10 and I don't see a reason there why a connection to PIN 7 or 8 should not work, see the Pysense Pinout for reference. Do you have any other suggestions on how I can get the sensor readings? Like I said, the Wipy works well. - Thanks in advance...
          Here is the Link to the Logic Level Shifter I use

          J 1 Reply Last reply Reply Quote 0
          • J Offline
            jmarcelino @ambropete
            last edited by

            Thanks @ambropete

            Pin 8 - your trigger - on the Pysense is G22 and Pin 7 your echo pin is G17
            so I'm not sure how your code even works?

            It should be

            echo = Pin(Pin.exp_board.G17, mode=Pin.IN)
            trigger = Pin(Pin.exp_board.G22, mode=Pin.OUT)
            
            1 Reply Last reply Reply Quote 0
            • A Offline
              ambropete
              last edited by ambropete

              Hi @jmarcelino, wow you're right a reminder to always read exactly!! Thanks so far! Now I ran the program with the corrected PINs several times but I still have the issue that I get sensor readings just at a maximum one time per run. I am sure the Hc-sr04 has 5V as needed and the logic level converter should also not be an issue as both trigger, echo and ground are correctly connected to it. I annexed the Atom Output to this post after uploading the new program:
              Running C:\Users\pmb\Desktop\Wipytest\wipysensortest.py

              Distance 1 cm
              Disconnected. Click here to reconnect.
              Connecting on COM5...
              Running C:\Users\pmb\Desktop\Wipytest\wipysensortest.py
              Disconnected. Click here to reconnect.
              Connecting on COM5...
              Running C:\Users\pmb\Desktop\Wipytest\wipysensortest.py
              Traceback (most recent call last):
              File "<stdin>", line 34, in <module>
              KeyboardInterrupt:
              raw REPL; CTRL-B to exit
              Disconnected. Click here to reconnect.
              Connecting on COM5...

              Running C:\Users\pmb\Desktop\Wipytest\wipysensortest.py

              Running C:\Users\pmb\Desktop\Wipytest\wipysensortest.py

              Distance 45 cm
              Disconnected. Click here to reconnect.

              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