• Alarm callback function not executing

    Discussion timer alarm
    5
    1
    0 Votes
    5 Posts
    971 Views
    J
    @robert-hh It turns out the "periodic=False" attribute is all it needed. Works fine now.
  • Timer.Alarm question

    Discussion timer alarm
    3
    0 Votes
    3 Posts
    767 Views
    J
    @robert-hh Got it! Many thanks!
  • Using an IO pin interrupt + Alarm

    MicroPython lopy pytrack pin interrupt alarm
    3
    0 Votes
    3 Posts
    2k Views
    K
    @gregcope Wondering if it might be useful to simply start a thread for everything. If I spawn an alarm in one thread, an interrupt in another and so on, I may be able to avoid the issue of blocking. The major issue is that since some of the functions I need to run can take 20 seconds or so, I don't want one to block another from running and have to wait a whole other interval for the respective functions to be run. Especially since there are multiple interrupts and one or two alarms. So would simply running a function that spawns an alarm within a separate thread make it so that the alarm itself is contained in that thread indefinitely?
  • 0 Votes
    3 Posts
    1k Views
    N
    @robert-hh Thanks for that insight. My issue was that (unlike my example) the callback would trigger a separate function that included an additional but non-related alarm call back that would get 'stalled' from the original callback. Having worked out that as long as an alarm is created from the 'main' thread it will not be blocked by work from the caller I have adjusted my program to use a mix of sensor alarms and secondary "worker" threads which are triggered by not run from the alarm callback. Not sure if it is the best way but seems to allow things to run smoothly without blocking.
  • 0 Votes
    4 Posts
    2k Views
    N
    @robert-hh Thanks for that (and your assistance on my other question). I would be interested in your thoughts on how the "main" thread would check these flags as that goes back into using some kind of event/interrupt to know the timer/sensor readings have read something in. My first thoughts would be a while loop with a sleep count and checking periodically but feels like that is not the correct way to go about it. At this stage I am currently working with two or three period alarms executed from the "main" thread and a single secondary thread that is in a while loop and constantly sleeping looking for values at certain intervals which it then does the "heavy" processing and sending. @crumble - Yes I must admit I need to get out of some of my older habits to focus more on efficiency than simplicity/readability. However, I must admit I have been struggling to find material on how Micropython, specifically, works with allocation of memory for objects/variables/functions and what is the most efficient practice. Most examples go back to pure Python requiring multiple libraries to do memory statistics, even then not actually demonstrating what is the best way. Simple questions as to how the GC works, if I need to set variables to 'None' at the end of a function, or the use of a list over three distinct variables. The only way I am really finding it is by doing it both ways and testing it with gc.mem_free() which is time consuming and feels more like guess work. Would be interested on your point 4 about modules and compiling at boot time.
  • LoPy and Time-based Events

    LoPy timer alarm
    20
    0 Votes
    20 Posts
    5k Views
    robert-hhR
    @fuzzy OK. here is a variant of the fist version which counts down the total duration every second: from machine import Pin, Timer, idle DEFAULT_HIGH = const(2) DEFAULT_LOW = const(4) DEFAULT_DURATION = const(10) class BLINK: def __init__(self, pin, high = DEFAULT_HIGH, low = DEFAULT_LOW, duration = DEFAULT_DURATION): self.start(pin, high, low, duration) def start(self, pin, high, low, duration): self.pin = pin self.times = [high, low] self.duration = duration self.state = 0 self.count = self.times[self.state] self.pin(self.state) self.timer = Timer.Alarm(self.timerCallback, 1.0, periodic=True) def timerCallback(self, timer): self.duration -= 1 if self.duration <= 0: self.pin(0) # or whatever final state you like self.stop() else: self.count -= 1 if self.count <= 0: self.state = 1 - self.state self.count = self.times[self.state] self.pin(self.state) def stop(self): self.timer.cancel() def run(): pin = Pin("P5", mode=Pin.OUT) blink = BLINK(pin, 1, 1, 10) while blink.duration > 0: idle() run()
  • Example Alarm fail

    SiPy alarm sipy example 1.8.6
    4
    1 Votes
    4 Posts
    1k Views
    robert-hhR
    @VST-Admin The actual example in the in the examples section documentation mentions alarm.callback(None). The recent firmware supports the cancel method. So I recommend updating the firmware.