• 0 Votes
    2 Posts
    721 Views
    L
    @rachelsimida this is to fast to read it in this way look at pulses_get https://docs.pycom.io/chapter/firmwareapi/pycom/pycom.html#pycompulsesgetpin-timeout sometimes is also good to dissable irq remember = disable_irq() .... enable_irq(remember)
  • 0 Votes
    17 Posts
    4k Views
    R
    @ambropete import binascii import pycom import socket import time import ujson # put that into the import section from network import LoRa from machine import Pin, Timer echo = Pin(Pin.exp_board.G7, mode=Pin.IN) trigger = Pin(Pin.exp_board.G8, mode=Pin.OUT) # Colors off = 0x000000 red = 0xff0000 green = 0x00ff00 blue = 0x0000ff # Turn off hearbeat LED pycom.heartbeat(False) # Initialize LoRaWAN radio lora = LoRa(mode=LoRa.LORAWAN) # Set network keys app_key = binascii.unhexlify('11 22 33 44 55 66 77 88 99 00 11 22 33 44 55 65'.replace(' ','')) app_eui = binascii.unhexlify('00 00 00 00 00 00 00 00'.replace(' ','')) # Join the network lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0) pycom.rgbled(red) # Loop until joined while not lora.has_joined(): print('Not joined yet...') pycom.rgbled(off) time.sleep(0.1) pycom.rgbled(red) time.sleep(2) print('Joined') pycom.rgbled(blue) s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) s.setblocking(True) 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 s.send(str(distance).encode()) pycom.rgbled(green) time.sleep(0.5) pycom.rgbled(blue) time.sleep(0.5) print("Distance {:.0f} cm".format(distance)) time.sleep(5)
  • 0 Votes
    8 Posts
    2k Views
    J
    @justin-binda the low side is the signal pin on the 3.3V side (the ESP32 / Pycom module), the high side is signal pin on the 5V side (the sensor). I think that sensor actually has two signal pins, one for trigger (MCU -> sensor) and the other for echo (sensor -> MCU) so you would need two level shifters.