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

    Lopy with a hc-sr04 endless loop

    Scheduled Pinned Locked Moved LoPy
    lopyexpansionboardhc-sr04
    4 Posts 2 Posters 858 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.
    • R Offline
      rootmi
      last edited by

      ****0_1526567392015_WhatsApp Image 2018-05-17 at 16.28.54.jpeg

      Hi everybody,

      like you see in the picture, i made it like that and i wrote this programm, i have a sensor hc-sr04 and Lopy with an expansionboard 2.0.
      The source:

      from machine import Pin
      echo = Pin('P19', mode=Pin.IN) #on the expansionboard G6
      trig = Pin('P20', mode=Pin.OUT) #on the expansionboard G7
      while True:
          trig.value(0)
          time.sleep(2)
          trig.value(1)
          time.sleep(0.00001)
          trig.value(0)    
          while echo()== 0:
              pulse_start = time.time()
              print("echoValue=0")
          while echo()== 1:
              pulse_end = time.time()
              print("echoValue=1")
          pulse_duration = pulse_end - pulse_start
          distance = pulse_duration * 17150
          distance = round(distance, 2)
          print ("hello am i here?")
          if distance > 2 and distance < 400:
              print ("Entfernung: ",distance - 0.5,"cm")
          else:
              print ("Zu weit")
          print ("ENDE")
      

      Hardware: I give small V to echo of course, and VCC goes to VIN on the expansionboard. GND to GND.
      And with this Code i am coming everytime in a endless loop for echo = 0. I dont understand why. I read already other post about it but i think it should be one year later better :))

      Thanks a lot for your help.
      Ciao.****

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @rootmi
        last edited by

        @mdalmis the HC SR04 has an operating voltage of 5V while the Pycom devices use 3.3V. Not sure what the input tolerance and actual output are, you may want to check...

        1 Reply Last reply Reply Quote 1
        • R Offline
          rootmi
          last edited by

          @jcaron Thanks for your answer.
          I think it should be enough that i use 2 resistance for the 3.3V. You can see them in the picture :)

          J 1 Reply Last reply Reply Quote 0
          • J Offline
            jcaron @rootmi
            last edited by

            @rootmi I’m no electronics expert and I don’t know the full specs of the sensor, but I’m not sure I understand how those two resistors would be enough. You are still powering a 5V device with 3.3V and sending it a 3.3V signal, aren’t you?

            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