🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Ui Flow support for onewire and ds18x20

    UIFlow
    8
    26
    82.1k
    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.
    • R
      robalstona
      last edited by

      its weird to me, i use online wersiin of uiflow, its shows 1.4.5. Newer mind.

      I based custom block on this file:
      https://github.com/stonatm/M5Atom_matrix_library/blob/master/lib/dallas.py

      there in a two class which diffirents in one line near return temperature dependent of sensor type

      usage:
      #run once
      import time
      from dallas import ds18b20 as sensor
      sensor.init( pin )

      #reading procedure
      sensor.convert ( pin )
      time.sleep_ms(750)
      print ( sensor.read( pin ) )

      This library is simple and have small amount of code but its sacrified to using only one sensor by pin. I don't implemented search rom procedures.

      A 1 Reply Last reply Reply Quote 1
      • A
        akshaypatil @robalstona
        last edited by akshaypatil

        @robalstona

        from m5ui import *
        from uiflow import *
        
        setScreenColor(0x111111)
        
        
        import time
        import onewire
        from dallas import ds18b20 as sensor
        
        sensor.init( pin )
        
        
        
        while True:
          sensor.convert ( pin )
          time.sleep_ms(750)
          print ( sensor.read( pin ) )
          wait_ms(2)
        

        Is this the basic code to display the temperature?
        Don't hesitate from thinking of me as a complete newbie, I have only been able to figure out basic logic/programming in python.
        The plan is to make a battery-heated lunchbox (my design thesis) that will be activated through blynk (or the button mstickC) and use the temperature reading to create a closed looped-feedback and switch it off.
        As simple as that sounds in my head. (but not really, as I have learned with time)
        :)

        R 1 Reply Last reply Reply Quote 0
        • R
          robalstona @akshaypatil
          last edited by

          @akshaypatil yes it is simplest form, but in this loop you display temperature every 0.75s on the console via print function. A function sensor.read ( pin ) return a value of readed temperature. You could store this value in variable to use for compare or other things.

          for example:

          temperature = sensor.read( pin )
          if temperature > 25:
              lcd.print('Too Hoot', 0, 0, 0xffffff)
          
          
          A 1 Reply Last reply Reply Quote 0
          • A
            akshaypatil @robalstona
            last edited by

            @robalstona

            from m5stack import *
            from m5ui import *
            from uiflow import *
            
            import machine
            import time
            import onewire
            from dallas import ds18b20 as sensor
            
            setScreenColor(0x111111)
            
            sensor.init(26)
            
            
            while True:
              sensor.convert (26)
              time.sleep_ms(750)
              lcd.print((sensor.read(26)), 0, 0, 0xffffff)
              wait_ms(2)
            
            

            I'm getting "cannot import name ds18b20" error, how do I get around this?

            Thank you for helping me out!

            1 Reply Last reply Reply Quote 0
            • A
              akshaypatil
              last edited by

              Nevermind!
              I got it to work!! Yahoo!!!

              Thanks a million for the help! :))

              R 1 Reply Last reply Reply Quote 0
              • liemphL
                liemph @robalstona
                last edited by

                @robalstona said in Ui Flow support for onewire and ds18x20:

                here you have the library to support ds18b20. You would have to copy these files to your device and from UiFlow call the appropriate micropython commands using the blocks Advanced -> Execute -> Execute code:

                https://github.com/micropython/micropython/tree/master/drivers/onewire

                Dear Roblastona, I realized that the feature to make and implement our own piece of phyton code into the UiFlow can solve many problems at hand. Could you lead me to URL or documentation on how to make the m5b files and implement it into the UiFlow?

                R 1 Reply Last reply Reply Quote 0
                • R
                  robalstona @akshaypatil
                  last edited by

                  @akshaypatil I probably made a mistake in the file location. I "manually" start my programs from the main.py file, but uiflow saves program files in the /apps folder by default and also automatically saves this file with the sent program in the / as the main.py file. The app selector on the device works on a similar principle. So you can try to save the dallas.py file in the same place as the main.py file. The second option is that you copy and paste all the code in the class section into your program. I have firmware version 1.4.2 in my stickc and I have a built-in _onewire module that I import in the dallas.py file. It is possible that in other versions it may have a different name

                  1 Reply Last reply Reply Quote 0
                  • R
                    robalstona @liemph
                    last edited by

                    @liemph In uiflow after pressing the field / Custom button (Beta), buttons appear with a link to the wizard, the other to help, the third to load.

                    https://docs.m5stack.com/#/en/uiflow/blockly_custom

                    I don't know if there are any other tutorials. I just wasn't looking. I combined myself by trial and error. This editor practically generates only two types of blocks. Does not check syntax compatibility. And there is no option to load previously saved files. So you write the code blind, save later, load in uiflow and then it turns out whether it loads and it will work. For the sake of simplicity, I figured out that I am making the first block called init / initialize and in it I put code that imports the modules I need and defines all my functions. The next blocks contain only the code that calls only the previously defined functions with the appropriate parameters if it uses them.

                    A 1 Reply Last reply Reply Quote 0
                    • A
                      akshaypatil @robalstona
                      last edited by

                      @robalstona

                      from m5stack import *
                      from m5ui import *
                      from uiflow import *
                      
                      setScreenColor(0x111111)
                      
                      import BlynkLib
                      BLYNK_AUTH = 'YOUR AUTH'
                      blynk = BlynkLib.Blynk(BLYNK_AUTH)
                      
                      from machine import Pin
                      import _onewire
                      
                      def init(pin):
                        Pin(pin, Pin.OPEN_DRAIN, Pin.PULL_UP)
                      
                      def convert(pin):
                        _onewire.reset(Pin(pin))
                        _onewire.writebyte(Pin(pin), 0xcc)
                        _onewire.writebyte(Pin(pin), 0x44)
                      
                      def read(pin):
                        _onewire.reset(Pin(pin))
                        _onewire.writebyte(Pin(pin), 0xcc)
                        _onewire.writebyte(Pin(pin), 0xbe)
                        tlo = _onewire.readbyte(Pin(pin))
                        thi = _onewire.readbyte(Pin(pin))
                        _onewire.reset(Pin(pin))
                        temp = tlo + thi * 256
                        if temp > 32767:
                          temp = temp - 65536
                        temp = temp * 0.0625
                        return(temp)
                      
                      init(0)
                      
                      @blynk.VIRTUAL_READ(6)
                      def v6_read_handler():
                          blynk.virtual_write(6, "%.2f"%((read(0))))
                      
                      
                      while True:
                        blynk.run()
                        convert(0)
                        lcd.clear()
                        lcd.font(lcd.FONT_DejaVu18)
                        lcd.print(("%.2f"%((read(0)))), 15, 50, 0xff0000)
                        wait_ms(2)
                      
                      

                      This will push the ds18b20 temperature to value display widget "Value Display/Labeled Value" on Blynk.
                      Don't forget to change the reading rate on this widget from "PUSH" to "1 sec".

                      Let me know if it works! :)

                      A 1 Reply Last reply Reply Quote 0
                      • A
                        akshaypatil @akshaypatil
                        last edited by

                        @akshaypatil

                        from m5stack import *
                        from m5ui import *
                        from uiflow import *
                        from easyIO import *
                        
                        setScreenColor(0x111111)
                        
                        
                        import BlynkLib
                        BLYNK_AUTH = 'YOUR AUTH'
                        blynk = BlynkLib.Blynk(BLYNK_AUTH)
                        
                        
                        from machine import Pin
                        import _onewire
                        
                        def init(pin):
                          Pin(pin, Pin.OPEN_DRAIN, Pin.PULL_UP)
                        
                        def convert(pin):
                          _onewire.reset(Pin(pin))
                          _onewire.writebyte(Pin(pin), 0xcc)
                          _onewire.writebyte(Pin(pin), 0x44)
                        
                        def read(pin):
                          _onewire.reset(Pin(pin))
                          _onewire.writebyte(Pin(pin), 0xcc)
                          _onewire.writebyte(Pin(pin), 0xbe)
                          tlo = _onewire.readbyte(Pin(pin))
                          thi = _onewire.readbyte(Pin(pin))
                          _onewire.reset(Pin(pin))
                          temp = tlo + thi * 256
                          if temp > 32767:
                            temp = temp - 65536
                          temp = temp * 0.0625
                          return(temp)
                        
                        init(0)
                        
                        @blynk.VIRTUAL_READ(6)
                        def v6_read_handler():
                          blynk.virtual_write(6, "%.2f"%((read(0))))
                        
                        @blynk.VIRTUAL_WRITE(9) # Button Widget VPIN 9 at GPIO 26
                        def my_write_handler(value):
                          blynk.virtual_write(1, toggleIO(26))
                        
                        while True:
                          blynk.run()
                          convert(0)
                          lcd.clear()
                          lcd.font(lcd.FONT_DejaVu18)
                          lcd.print(("%.2f"%((read(0)))), 15, 50, 0xff0000)
                          lcd.print(digitalRead(26), 35, 90, 0xffffff)
                          wait_ms(2)
                        

                        And this will toggle GPIO 26.
                        Now with the Blynk "Eventor" widget, you can have a summer fan that switches on when the temperature is higher than 28. ;)

                        1 Reply Last reply Reply Quote 0
                        • K
                          Kris
                          last edited by

                          U mnie działa bardzo dobrze. Dzięki

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post