Search found 5956 matches

by pythoncoder
Wed Jul 27, 2022 10:00 am
Forum: General Discussion and Questions
Topic: Using local time with Pico W
Replies: 17
Views: 47319

Re: Using local time with Pico W

Updated version here. This adds portability by using select.poll rather than deprecated socket timeouts (see docs).
by pythoncoder
Tue Jul 26, 2022 9:07 am
Forum: General Discussion and Questions
Topic: A threading.Event() like concept in MicroPython?
Replies: 2
Views: 2461

Re: A threading.Event() like concept in MicroPython?

I suggest you explain more fully what you're trying to achieve. The Pi Pico has two cores and it's possible to use both via the _thread library. Otherwise concurrency is handled by uasyncio see also this doc.
by pythoncoder
Mon Jul 25, 2022 10:42 am
Forum: ESP8266 boards
Topic: time.ticks_ms overflow
Replies: 5
Views: 22577

Re: time.ticks_ms overflow

Unless you do some special arithmetic it's 298/2 hours. If you perform a modular arithmetic subtraction of t2 - t1 the result may be positive or negative, depending on whether t2 follows or precedes t1. So the result from ticks_diff(t2, t1) may be +- 298/2 hours. This is explained in the docs.
by pythoncoder
Sun Jul 24, 2022 10:58 am
Forum: General Discussion and Questions
Topic: Traffic lights with a button interrupt - how would you have done it?
Replies: 12
Views: 8925

Re: Traffic lights with a button interrupt - how would you have done it?

To give a simple example of where uasyncio trumps the alternative, consider a requirement to flash an LED at a rate which can be varied. Then extend it to say four LED's, all flashing at different rates and with each rate subject to variability. Try to code that using a state machine or otherwise an...
by pythoncoder
Sun Jul 24, 2022 10:39 am
Forum: ESP32 boards
Topic: int() Anomaly
Replies: 19
Views: 8690

Re: int() Anomaly

I believe this is correct, but I haven't actually tried it.
by pythoncoder
Sat Jul 23, 2022 8:31 am
Forum: ESP32 boards
Topic: int() Anomaly
Replies: 19
Views: 8690

Re: int() Anomaly

TheSilverBullet wrote:
Sat Jul 23, 2022 7:46 am
If you work with float on MicroPython, that's the precision you can expect:
...
This is not strictly correct. Most MP targets support 32 bit floats, but some support 64 bits, notably the Pyboard D SF6W. Other targets can support 64 bits with a compile option.
by pythoncoder
Sat Jul 23, 2022 7:58 am
Forum: General Discussion and Questions
Topic: Traffic lights with a button interrupt - how would you have done it?
Replies: 12
Views: 8925

uasyncio every time.

Each to their own. As someone who has been doing asynchronous programming since the days of Intel 8080 assembler, cooperative multi-tasking is the natural way to write firmware. Once you have a handle on the concept it is as much part of programming as OOP. And, in my view, it is as important to lea...
by pythoncoder
Fri Jul 22, 2022 2:43 pm
Forum: Raspberry Pi microcontroller boards
Topic: Measure RPM with a Hall Sensor
Replies: 9
Views: 5462

Re: Measure RPM with a Hall Sensor

The two considerations are accuracy and response time. Counting pulses in a given interval is subject to one pulse of uncertainty. So if you count over 30s you have a 2rpm uncertainty. The shorter the interval, the greater the uncertainty but the less time to achieve a reading. Timing the interval b...
by pythoncoder
Fri Jul 22, 2022 2:30 pm
Forum: General Discussion and Questions
Topic: Traffic lights with a button interrupt - how would you have done it?
Replies: 12
Views: 8925

Asynchronous programming

As @DeaD_EyE says, the best way to do this kind of thing is with asynchronous programming: asyncio in CPython and uasyncio in MicroPython. It allows a more scalable object oriented approach: if you write an asynchronous TrafficLight class, you can implement N of them simply by creating N instances. ...
by pythoncoder
Wed Jul 20, 2022 9:17 am
Forum: ESP32 boards
Topic: Callback based driver for touchpads
Replies: 0
Views: 8431

Callback based driver for touchpads

I have extended my uasyncio-based Pushbutton class to support ESP32 touchpads. See this doc.

This enables callbacks to run on any or all of these conditions:
  • Touch event.
  • Release event.
  • Double-touch.
  • Long press.
Rather to my surprise these touch pads seem to be reliable and effective.