Différences entre versions de « Mydin-Class-Pico3Mod »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
 
(2 versions intermédiaires par le même utilisateur non affichées)
Ligne 25 : Ligne 25 :
  
 
[[Fichier:Mydin-Class-Pico3Mod-schematic-03.png]]
 
[[Fichier:Mydin-Class-Pico3Mod-schematic-03.png]]
 +
 +
 +
=== Examples ===
 +
 +
The [https://github.com/mchobby/micropython-mydin/tree/main/examples/din_controlers micropython-mydin repository] contains many useful examples.
 +
 +
Your knowledge will quickly progress by reading and understanding them.
  
 
== Class Header ==
 
== Class Header ==
  
{{prop|Ancestor| PicoControler }}
+
{{prop|Ancestor| [[Mydin-classes-diagram#PicoControler|PicoControler]] }}
 
{{prop|Class | '''Pico3Mod'''}}
 
{{prop|Class | '''Pico3Mod'''}}
 
{{prop|Module | pico }}
 
{{prop|Module | pico }}

Version actuelle datée du 29 avril 2025 à 16:14

Pico3Mod class

Raspberry-Pi Pico based controler for 3 modules DIN case.

 

The implementation of the class is closely tied to the features included into 3 modules DIN.

The features are used to design the PCB... so the board schematic is closely tied to the Pico3Mod class implementation.

Features

 

 

Board schematic

Schematic shows how the hardware (buttons, LEDs, buses, ...) are wired to the Pico.

 

 

 


Examples

The micropython-mydin repository contains many useful examples.

Your knowledge will quickly progress by reading and understanding them.

Class Header

Ancestor PicoControler
Class Pico3Mod
Module pico
DIN Size 3 Modules
Descr Raspberry-Pi Pico based controler for 3 modules DIN case.

Attributes

buzzer : Buzzer

Provides access to the active piezo buzzer.

The class Buzzer is documented into the micropython-pico repository (Github)

 

debounce_ms : int

Deboucing time (in milliseconds) used to avoids multiple bouton press detection. The initial value is 300ms as defined by the constant DEBOUNCE_MS in the module pico.

That value can be tuned by modifying the debounce_ms attribute.

pca : PCA9536

Private instance of the 4 bit GPIO expander controling the 4 LEDs of the Pico3Mod controler board. The PCA9536 is wired on the internal I2C bus.

It is not necessary to manipulate that object, LEDs are manipulated through a special class named PcaPinAdapter!

The PCA9536 class is documented into the esp8266-upy/pca9536 repository (Github)

led0, led1, led2, led3 : PcaPinAdapter

The PcaPinAdapter class allows to use one of the PCA9536 GPIO as a Pin alike class.

Such a way, the LED attached to the PCA9536 GPIO can be controled with on(), off(), value(), toggle() methods... exactly as it would be done for a Pin.

 

ext_rtc : DS3231

The external RTC running on coin battery. So the clock always stays in time even on power outage.

The DS3231 is wired on the internal I2C bus.

The DS3231 class is documented into the esp8266-upy/ds3231 repository (Github)

onewire : OneWire

OneWire bus as documented in MicroPython OneWire documentation.

roms : list

List of ROMs scanned on the OneWire bus at the __init__(). The list contains bytes() objects.

rom_ds18b20 : bytes

The rom bytes() object of the first ds18b20 sensor detect on the OneWire bus. Otherwise it contains None.

leds : list

Property returning a list of all the user LEDs of the controler board.

The result is [led0, led1, led2, led3]

buttons : list

Property returning a list of Pin object.

Each of the Pin instance being attached to one of the controler button. The Pin are configured as INPUT with PULL_UP.

The list is ordered by increasing button number so buttons[0] correspond to the button 1, buttons[1] correspond to the button 2, and so on.

onewire_roms : list

Property that list the onewire roms as string under human friendly format (hexadecimal).

has_ds18b20 : bool

Property returning True when a ds18b20 sensor is detected on the OneWire bus.

temp_ds18b20 : float

Property returning the temperature of the ds18b20 sensor. Temperature is read in Celcius degrees.

This property work in two different ways:

  1. Procedural execution : the temperature reading is executed in blocking mode which requires about a 1 second per read.
  2. Asynchronous execution : an async tasks read ans store the ds18b20 temperature every 10 secs (or so). The property immediately returns the last known temperature.

Methods

__init__()

Constructor of the Pico3Mod class, specialized version of the PicoControler for the 3 modules DIN case.

The __init__() creates all objects made available through the properties.

def __init__( self, BackplaneClass ):
  • BackplaneClass : Class of the backplane to be associated with the controler (eg: TwoRelay3Mod).

The constructor will creates the objects & resources specific to the Pico3Mod board.

As Pico3Mod inherits from PicoControler and DinControler, it then inherits from the methods and properties of the both ancestors.

__init__() is also responsible for:

  • setting up MCU RTC with the external RTC date & time.
  • setting up callbacks for the buttons
  • made the LEDs accessible thanks to the PcaPinAdapter class.
  • scanning the OneWire bus for existing sensors
  • sound the buzzer as last init operation

was_pressed(): bool

Check if a given button has been pressed since the last check. This method also resets the pressed state for the requested button.

was_pressed() is very handy to check if a button was pressed while the userloop or other tasks were processing.

Reminder: the button state change is capture by IRQ event handler.

def was_pressed( self, idx ):
  • idx : index of the the button to check (0..N-1).

task_setup(): bool

The overriden task_setup() is adds the following tasks:

  1. The __coro_ds18b20 task to read the temperature sensor every 10 seconds (if has_ds18b20==True) and store the value.
  2. The __coro_monitor task to check the internal MCU temperature every 60 seconds. Over-temperature will reset the microcontroler.
def tasks_setup( self, async_evloop ):

before_run(): bool

The overriden before_run() checks if the internal MCU temperature is in over-temperature state before allowing the run() to starts the userloop.

That would avoids the DIN software to restart in bad conditions if the MCU have been reset for over-temperature reason.

def before_run( self ):