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

    I2C communication between sensor and Pysense not working

    Scheduled Pinned Locked Moved Comments & Feedback
    wipy 3.0pysensei2cexternal sensor
    1 Posts 1 Posters 560 Views 1 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

      Hello all together,

      I posted my issue under another topic three weeks ago but it could not be solved and I still got no idea why my setup fails to work. I have a hc-sr04 ultrasonic sensor (5V signal level) level shifted from 5v to 3v3 and connected to the Pysense external I/O header. Echo goes to PIN7, Trigger to Pin8 and Ground to Pin 1. Very sporadically I receive a distance measurement that sometimes seems to be correct and sometimes is 0; 99% of the time, the serial port seems to be dead! Do you have an idea what could be the issue? Is there a mistake in the code? I have two Pysense and the problem with them both. Thank you very much for your time in advance!

      import pycom
      import time
      from machine import Pin, Timer
      from machine import I2C
      import ubinascii
      import micropython
      
      
      echo = Pin(Pin.exp_board.G17, mode=Pin.IN)
      trigger = Pin(Pin.exp_board.G22, 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)
      
      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