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

    Code stuck using sigfox with I2C sensor

    Scheduled Pinned Locked Moved SiPy
    sigfoxi2csipy
    1 Posts 1 Posters 937 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.
    • Y Offline
      YoungChul
      last edited by YoungChul

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

      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