Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. dwarrenku
    D
    • Continue chat with dwarrenku
    • Start new chat with dwarrenku
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    dwarrenku

    @dwarrenku

    0
    Reputation
    5
    Posts
    809
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    dwarrenku Follow

    Posts made by dwarrenku

    • RE: Error 118, doconnect() not connecting

      For anyone interested, I think I found the solution to my problem. The problem wasn't with doConnect.

      First, the 118 error was caused by lightsleep... I think. Since lightsleep allows RAM to persist, when it would wake up it would still think wlan_sta was active, even though it wasn't. Adding wifiCfg.wlan_sta.active(False) at the end turned the network off before going to sleep. That way each time it would connect as it should.

      Next, I kept getting error 23 after a few posts. This was caused by not closing the socket that was opened by the request and stored in response. The memory was filling up with socket objects, and running out of room. Calling request.close() removed the socket and freed up the memory. Now it's working just fine.

      posted in Micropython
      D
      dwarrenku
    • Error 118, doconnect() not connecting

      I'm working on debugging this script. It's been a slow process since I can't run serial in VScode.

      It's collecting moisture readings and then sending them to a Adafruit IO feed through a POST. I found my way around th 113 errors from urequests, but now I'm getting OSerror 118. I guess this indicates the wifi isn't connected.

      I'm using wifiCfg's doConnect function in a while loop in hopes that it will keep trying until it works. This works on an initial run, but it looks like it fails after a lightsleep.

      Does anyone have any idea about how I can get the wifi to connect more reliably? What am I missing?

      while(True):
        gc.collect()
        while not wifiCfg.doConnect('guest', '12345678', lcdShow=True): pass
      
        lcd.clear()
        lcd.setTextColor(0xaaaaaa, lcd.BLACK)
        lcd.font(lcd.FONT_DejaVu18)
        axp.setLcdBrightness(50)
        
        test.display(int(get_moisture()/10))
        wait(2)
      
        moisture = get_moisture() #get moisture
        try:
          response = urequests.request(
            method='POST',
            url='http://io.adafruit.com/api/v2/********/feeds/moisture/data',
            json={'value':moisture},
            headers={'Content-Type':'application/json','X-AIO-Key':'**************************'}
          )
          if response.status_code == 200:
            led.duty(99)
            lcd.clear()
            lcd.print("sent", lcd.CENTER, 5)
            lcd.image(0, 50, 'img/success.jpg')
            wait(1)
            axp.setLDO2Volt(0)
          else:
            lcd.print("request \r\n error", lcd.CENTER, 0, 0xFFFFFF)
            lcd.image(0, 50, 'img/error.jpg')
            led.duty(50)
            wait(10)
        except Exception as e:
          lcd.print("OS error", lcd.CENTER, 0, 0xFFFFFF)
          lcd.image(0, 50, 'img/error.jpg')
          print(e)
        
        gc.collect()
        lightsleep(60*1000)
      
      posted in Micropython
      D
      dwarrenku
    • RE: I2C bus already used error

      Thank you! I switched back to the i2c_bus module and the code you provided and it worked. No more errors.

      All that was missing was converting the struct to a short:

      def get_moisture():
        i2c = i2c_bus.easyI2C(i2c_bus.PORTA, 0x36)
        i2c.write_u8(0x0f, 0x10)
        wait_ms(5)
        val = i2c.read(2)
        val = ustruct.unpack(">H", val)[0]
        return val
      
      posted in Micropython
      D
      dwarrenku
    • RE: I2C bus already used error

      Yes, I'm using the uiflow version of micropython. For now I'm working around this by resetting it each time I rerun. It's kind of annoying but it works.
      From what I can see the stemma modules aren't defining the I2C bus, just saving the I2C object.

      class StemmaSoilSensor(seesaw.Seesaw):
          """Driver for Adafruit STEMMA Soil Sensor - I2C Capacitive Moisture Sensor
             :param I2C i2c: I2C bus the SeeSaw is connected to.
             :param int addr: I2C address of the SeeSaw device. Default is 0x36."""
          def __init__(self, i2c, addr=0x36):
              super().__init__(i2c, addr)
      

      and the seesaw module is the superclass of StemmaSoilSensor:

      class Seesaw:
          """Driver for SeeSaw I2C generic conversion trip.
             :param I2C i2c: I2C bus the SeeSaw is connected to.
             :param int addr: I2C address of the SeeSaw device."""
          def __init__(self, i2c, addr):
              self.i2c = i2c
              self.addr = addr
              self.sw_reset()
      
      posted in Micropython
      D
      dwarrenku
    • I2C bus already used error

      I have gotten the M5StickC up and running with micropython and VSCode. It looks like it's going to work very well, and it's much faster development than compared to the Arduino IDE.

      I continue to hit an error when using I2C that I can't figure out. I can run my code successfull yon the first upload, but then once I change it and rerun it errors with I2C bus already used. The only way around this is to perform a hard reset and reupload each time.

      Its my first go at micropython, and I'm still relativey new to i2c, so I'm not sure what to do. I've tried using deinit from the micropython docs, but that creates more errors. Below is my code. I'm grateful for any help in troubleshooting this.

      from m5stack import *
      from m5ui import *
      from uiflow import *
      from stemma_soil_sensor import *
      
      setScreenColor(0x000000)
      i2c = machine.I2C(sda=machine.Pin(32), scl=machine.Pin(33), freq=100000)
      seesaw = StemmaSoilSensor(i2c)
      
      while(1):
        # get moisture
        moisture = seesaw.get_moisture()
        lcd.print(moisture, 10, 0, 0xFFFFFF)
        wait_ms(10)
      
      posted in Micropython
      D
      dwarrenku