UIFlow 2 bugs?
-
Hello,
I'm very new to UIFlow so this could just be a beginner learning but I'm running into some strange issues with UIFlow.-
I have the Ext-Encoder working but I'm unable to reliably reset the counter to 0. I'm not sure what all the related blocks do but I've tried a bunch of options using reset encoder rotary value and set rotary value to 0. It seems to occasionally choose a number which isn't 0 to reset to. This presents as the value "resetting" to a consistent random number when hitting a limit switch. Reset number has varied between resets - I can sometimes get the reset value to be 0 if I don't move the encoder during the first few seconds of program time but even that isn't consistent. The sensor is excellent outside of this issue. I'd prefer not to create some hacky workaround or rewrite in Arduino but I'm getting close.
-
I couldn't for the life of me get a simple limit switch or button to work. Was messing around with ports, pins, etc and ended up just initializing the pin and using it at the pin level, which then worked without issue. Is there a secret I'm missing or does a simple limit switch not work when using the UIFlow gui as designed? Tried both the limit switch sensor module (U145) and the optical switch (U058) and neither worked.
I'm not sure what info to post to help debug this, I could probably create a quick example that illustrates these issues, let me know if that would help.
I'm using a core S3 and arc browser.
Thanks in advance!
-
-
@amulder First question, Are you connecting the units to the correct ports?
The ports are different colours for a reason.
Second question, have you read the documentation and guides on the devices pages of the M5Stack site?
3rd question - can you share your code so that we can see what you are trying to do in UIFlow2? -
@ajb2k3 Sorry for the delay, I didn't receive a notification.
Yes, I'm following the documentation and guidance on ports. Although I'm finding the Ext-Encoder documentation a bit lacking as far as what the functions do / return.
I have the Ext-Encoder working in Port C and started with both the limit and optical switch in Port B as they list the GPIO port on the label, but started trying other options when that failed to work. I haven't been able to get the optical switch to work and the only way I got the limit switch to work was using the pin directly.
Loving the system, just not sure what I'm doing wrong. I appreciate the help!
Here's my current functional (outside of the non-zero reset bug) code. It's really just an encoder (port C), limit switch (port B), ui elements and minor logic.
import os, sys, io import M5 from M5 import * from boot_option import * from hardware import * from unit import ExtEncoderUnit import time import m5utils label0 = None label1 = None charging = None Title = None EncoderValue = None batteryPerc = None rect0 = None buttonState = None image0 = None i2c0 = None pin8 = None Encoder = None encoderposition = None ButtonState = None Located = None SliderPosition = None LocTimer = None displayTimer = None def setup(): global label0, label1, charging, Title, EncoderValue, batteryPerc, rect0, buttonState, image0, i2c0, pin8, Encoder, encoderposition, ButtonState, Located, SliderPosition, LocTimer, displayTimer M5.begin() Widgets.fillScreen(0x222222) label0 = Widgets.Label("Value:", 26, 36, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label1 = Widgets.Label("Limit:", 31, 76, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) charging = Widgets.Circle(252, 34, 4, 0x222222, 0x222222) Title = Widgets.Title("Slider", 5, 0xffffff, 0x285c4d, Widgets.FONTS.DejaVu18) EncoderValue = Widgets.Label("null", 95, 36, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) batteryPerc = Widgets.Label("100%", 263, 25, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) rect0 = Widgets.Rectangle(0, 138, 20, 100, 0x285c4d, 0x285c4d) buttonState = Widgets.Circle(102, 86, 7, 0xffffff, 0x222222) image0 = Widgets.Image("res/img/logo_cropped.png", 177, 64, scale_x=.07, scale_y=.07) set_boot_option(1) i2c0 = I2C(0, scl=Pin(18), sda=Pin(17), freq=100000) Encoder = ExtEncoderUnit(i2c0, 0x59) time.sleep_ms(500) Encoder.reset_rotary_value() Encoder.set_rotary_value(0) Located = False pin8 = Pin(8, mode=Pin.IN) def loop(): global label0, label1, charging, Title, EncoderValue, batteryPerc, rect0, buttonState, image0, i2c0, pin8, Encoder, encoderposition, ButtonState, Located, SliderPosition, LocTimer, displayTimer M5.update() batteryPerc.setText(str((str((Power.getBatteryLevel())) + str('%')))) if Power.isCharging(): charging.setColor(color=0x222222, fill_c=0x33cc00) else: charging.setColor(color=0x222222, fill_c=0x222222) encoderposition = Encoder.get_rotary_value() EncoderValue.setText(str(encoderposition)) ButtonState = (pin8.value() ^ (0x01 << 0)) print(encoderposition) if ButtonState == 1: Located = True buttonState.setColor(color=0xFFFFFF, fill_c=0xFFFFFF) Encoder.reset_rotary_value() Encoder.set_rotary_value(0) else: buttonState.setColor(color=0xFFFFFF, fill_c=0x222222) if Located == False and (time.ticks_diff((time.ticks_ms()), LocTimer)) > 500: print('Location unknown') LocTimer = time.ticks_ms() SliderPosition = min(max(m5utils.remap(encoderposition, 0, 45140, 298, 0), 0), 298) if (time.ticks_diff((time.ticks_ms()), displayTimer)) > 15: rect0.setCursor(x=(int(SliderPosition)), y=138) displayTimer = time.ticks_ms() if __name__ == '__main__': try: setup() while True: loop() except (Exception, KeyboardInterrupt) as e: try: from utility import print_error_msg print_error_msg(e) except ImportError: print("please update to latest firmware")
-
@amulder You cant use more then 1 Port B device on port B (black port) at a time due to the limit of the hardware (1 pin is hard set to output and one is hard set to input.
To use multiple PortB devices you will need to connect them to a PBHub.
EXT-ENC is a port A device (red port) not a port C (blue port)
Port C is for UART devices normally but if you got it working then fine. -
@ajb2k3 That all makes sense to me.
Sorry for the confusion, I'm trying to use either the mechanical limit switch OR the ir photogate as a limit switch. Not trying to use both at the same time. But I was unable to use either module using the corresponding UIFlow module integration. I'll post an example next week which hasn't worked for me so far.
Yea, I originally had it in port A but moved it over after confirming there wasn't a negative impact as it's a bit cleaner with both plugs on the same side of the device. If you said there was an electrical difference that could be causing the non-zero reset bug I could try port A again. Any ideas there? Should I be using a different reset / get function? How can I debug this issue better?
Seems pretty clear cut when I'm setting the rotary_value to 0 but when I get the rotary value, it's not 0. It resets to the initial value, which is often not 0. Today I recall three reboots which all had different reset values, roughly 636, -1035, -1.
-1 was close enough and worked for me, but when I got the other values I just reset the board and basically got it to choose a new "0" value.