Ui Flow support for onewire and ds18x20
-
@fb24 Hi. A few days ago I made a custom block for ds18b20 support. Maybe you're interested
https://github.com/stonatm/UiFlow-custom-blocks/tree/master/ds18b20
-
@fb24
I'm working on using the DS2482 (I2C to onewire) as an interface to the ds18x20.There are existing libraries using arduino. I want to use UIFlow/Blockly . Today I just made a commit using UIFlow/Blockly addressing different sensors/devices like the EXT.IO unit communicating with an M5Stack master as slaves on the I2C bus.
-
@lukasmaximus said in Ui Flow support for onewire and ds18x20:
hey @fb24 onewire and ds18x20 are only supported in micropython version 1.12 uiflow micropython is based on version 1.11 if you are familiar with micropython I suggest you flash your M5Stack device with the latest micropython, I did a short video series on how to use M5Atom with micropython 1.12 and I will be doing some videos shortly on how to use other M5Stack devices with micropython 1.12
I am now using Micropython 1.12 BUT not on M5, but other ESP (bare) development boards. I managed to use the M5 Units and Hats connected to the ESP development board. My question is If I flash my M5Stack Fire or other M5 cores with the latest Micropython is there any python libraries for accessing the internal functionalities of the cores? For example the LCD, AXP? Another assumption is that we could not program the core with UIFLOW, isn't it?
-
Hey @liemph it is possible to use micropython on m5stack fire and core, once you've flashed the firmware you just use a program like upyloader to transfer all the libraries to the flash. Here is an example of M5Stack Fire using pure micropython https://www.hackster.io/andreas-motzek/execute-logo-on-m5stack-esp32-basic-with-micropython-3713fd core can be programmed no problem with the uiflow interface, when using units, you must attach the unit by jumper wires to the same pin numbers as the port you selected which can be found in the documentation
-
@robalstona
Hi! I was unable to get your uiflow blocks from github to work,
the m5b files would not load into uiflow. (nothing happens)
Are they compatible with uiflow 1.4.5?
Secondly, I uploaded ds18x20.py using uPyloader and used "import ds18x20" in custom execute command. What steps do I take after to get the data from the sensor?
If possible, could you paste the python code? Need it for my project.
Thanks a lot! -
@akshaypatil
The code on github is shown as 1 line, hence the confusion in understanding it even a slight bit. I'm new to programming, have just figured out the basic functions in uiflow, therefore I might be pretty ignorant. -
@akshaypatil Hi, you must find in uiflow field named Custom (Beta) in a row with other groups of blocks. Click on it and on right side will appears three new blue color buttons. One of them was called *open .m5b file click it and select ds18b20.m5b. You see loading notification, after this operatiin you see new block group appears below Custom (Beta) when you click it
-
@robalstona Yes, that's exactly what I've been trying, without any success. :/
I had made my own blocks for toggling GPIO pins in blynk with uiflow that would show a loading screen as soon as I clicked it, but with your blocks, it didn't work. (there is no loading notification)If possible, it would be really helpful to see the code in normal python format. So that I could make my own blocks and cross-check if it's not just my computer?
Cheers!
-
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.pythere 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.
-
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)
:) -
@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)
-
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!
-
Nevermind!
I got it to work!! Yahoo!!!Thanks a million for the help! :))
-
@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