Code stuck using sigfox with I2C sensor



  • EDIT: I changed the pin for the clock to another one for my I2C bus (Which i tried earlier but due to a typo i didn't realize it was the source of the problem ^^), and it solved the problem. It's a bit odd that the default I2C pins doesn't work with the boards main functionality, oh well.

    I'm using an ultra sonic range finder that uses I2C to send data back to the micro controller, but i am having trouble making it work together with the sigfox class to upload the data.

    I don't know if it's some sort of conflict with I2C or i simply have a bug but the code simply gets stuck at different locations in the code depending on what i execute first.
    The code for uploading, which i just took from the documentation, and the code for retrieving data from the sensor both works independently, but combined i cannot make it work. Hoping someone can help :)

    import time
    from machine import I2C
    from network import Sigfox
    import socket
    import pycom
    
    pycom.heartbeat(False)
    
    i2c = I2C(0)
    i2c.init(I2C.MASTER, baudrate=9600, pins=("P9", "P10"))    
    sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1)
    s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
    s.setblocking(True)
    s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)
    
    while(True):
        i2c.writeto_mem(112, 0x00, b'\51')     #<< code gets stuck right here.
        time.sleep(0.07) # wait for the sensor to complete its reading
        x = i2c.readfrom_mem(112, 0x02, 2)
        time.sleep(0.01) # wait for sensor to return result
        #range = x[1] | x[0] << 8
        s.send(x[0], x[1])
        time.sleep(60)
    

    This code is blocked right after it enters the While loop, and won't write to the sensor at all.

    I have also tried to init sigfox and create the socket inside the loop which made it actually read the data from the sensor, but that got it stuck when trying to send the data. I didn't like this code as creating a socket and initializing the hardware every time my While loop runs doesn't make sense.

    Hoping someone can see something obvious wrong with my code here ;)


Log in to reply
 

Pycom on Twitter