Pysense Expansion Board External Header not working

  • 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)
    chrono = Timer.Chrono()
    while True:
        while echo() == 0:
        while echo() == 1:
        distance = chrono.read_us() / 58.0
        if distance > 400:
            print("Out of range")
            print("Distance {:.0f} cm".format(distance))

  • 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\

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

    Running C:\Users\pmb\Desktop\Wipytest\

    Running C:\Users\pmb\Desktop\Wipytest\

    Distance 45 cm
    Disconnected. Click here to reconnect.

  • 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)

  • 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

  • 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?

Log in to reply

Pycom on Twitter