Ui Flow support for onewire and ds18x20
-
@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?
-
@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
-
@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.
-
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! :)
-
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. ;) -
U mnie działa bardzo dobrze. Dzięki