espzero 0.0.1__tar.gz → 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: espzero
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Educational tool for physical computing and ESP32/ESP8266 development.
5
5
  Author-email: Neo Neopia-uz <neopia.uz@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/roboticsware/espzero
@@ -13,6 +13,9 @@ Description-Content-Type: text/markdown
13
13
 
14
14
  # espzero
15
15
 
16
+ [![PyPI version](https://badge.fury.io/py/espzero.svg)](https://badge.fury.io/py/espzero)
17
+ [![License](https://img.shields.io/github/license/roboticsware/espzero)](https://github.com/roboticsware/espzero/blob/main/LICENSE)
18
+
16
19
  > A single MicroPython library that ports [picozero](https://github.com/raspberrypilearning/picozero) to the ESP32 family (WROOM, S3, C3, and more).
17
20
  > **"One codebase, many boards"** — hardware differences are absorbed by the Board Profile system.
18
21
 
@@ -20,10 +23,20 @@ Description-Content-Type: text/markdown
20
23
 
21
24
  ## Installation
22
25
 
23
- Copy the `espzero/` directory to the root of your ESP32 filesystem using Mu Editor, Thonny, or `mpremote`:
26
+ ### For your ESP32 board (Recommended)
27
+ Use `mpremote` to install directly from PyPI to your board:
24
28
 
29
+ ```bash
30
+ mpremote mip install espzero
25
31
  ```
26
- mpremote cp -r espzero/ :espzero/
32
+
33
+ Or manually copy the `espzero/` directory to your board's root.
34
+
35
+ ### For your PC (Development)
36
+ To get autocomplete and linting in your IDE:
37
+
38
+ ```bash
39
+ pip install espzero
27
40
  ```
28
41
 
29
42
  ---
@@ -1,5 +1,8 @@
1
1
  # espzero
2
2
 
3
+ [![PyPI version](https://badge.fury.io/py/espzero.svg)](https://badge.fury.io/py/espzero)
4
+ [![License](https://img.shields.io/github/license/roboticsware/espzero)](https://github.com/roboticsware/espzero/blob/main/LICENSE)
5
+
3
6
  > A single MicroPython library that ports [picozero](https://github.com/raspberrypilearning/picozero) to the ESP32 family (WROOM, S3, C3, and more).
4
7
  > **"One codebase, many boards"** — hardware differences are absorbed by the Board Profile system.
5
8
 
@@ -7,10 +10,20 @@
7
10
 
8
11
  ## Installation
9
12
 
10
- Copy the `espzero/` directory to the root of your ESP32 filesystem using Mu Editor, Thonny, or `mpremote`:
13
+ ### For your ESP32 board (Recommended)
14
+ Use `mpremote` to install directly from PyPI to your board:
11
15
 
16
+ ```bash
17
+ mpremote mip install espzero
12
18
  ```
13
- mpremote cp -r espzero/ :espzero/
19
+
20
+ Or manually copy the `espzero/` directory to your board's root.
21
+
22
+ ### For your PC (Development)
23
+ To get autocomplete and linting in your IDE:
24
+
25
+ ```bash
26
+ pip install espzero
14
27
  ```
15
28
 
16
29
  ---
@@ -0,0 +1,147 @@
1
+ # This file is part of espzero, automatically synced from
2
+ # https://github.com/roboticsware/espzero at revision 24cae2bc1c028458052675181e95f2a08fdf7481.
3
+ # Do not edit this file directly — run update_user_libs.py espzero instead.
4
+
5
+ """
6
+ espzero/__init__.py
7
+ Public entry point for the espzero library — an ESP32 port of picozero.
8
+
9
+ Quick start::
10
+
11
+ import espzero
12
+ espzero.begin() # initialise board (auto-detect)
13
+
14
+ from espzero import esp_led # built-in LED, ready after begin()
15
+ from time import sleep
16
+
17
+ while True:
18
+ esp_led.on()
19
+ sleep(1)
20
+ esp_led.off()
21
+ sleep(1)
22
+
23
+ Specify a board explicitly::
24
+
25
+ espzero.begin("esp32_devkit_v1") # override auto-detection
26
+
27
+ Import other components after begin()::
28
+
29
+ from espzero import LED, Button, Servo, WiFi
30
+
31
+ The board profile system abstracts hardware differences (pin aliases,
32
+ ADC attenuation, strapping pins, NeoPixel vs GPIO LEDs, etc.) so that
33
+ user code remains identical across supported boards.
34
+ """
35
+
36
+ from . import _hal
37
+
38
+ # ── Board → profile class mapping ─────────────────────────────
39
+ # Key : user-facing board name (passed to begin())
40
+ # Value : (module_name, class_name) for lazy import
41
+ _PROFILE_MAP = {
42
+ "esp32_devkit_v1": ("profiles.esp32_boards", "ESP32DevKitV1"),
43
+ "esp32_s3_devkit": ("profiles.esp32_boards", "ESP32S3DevKit"),
44
+ "esp32_c3_mini": ("profiles.esp32_boards", "ESP32C3Mini"),
45
+ "m5stack_atom": ("profiles.esp32_boards", "M5StackAtom"),
46
+ "wemos_d1_mini32": ("profiles.esp32_boards", "WemosD1Mini32"),
47
+ "esp8266_lolin_v3": ("profiles.esp32_boards", "ESP8266LolinV3"),
48
+ "esp32_38pin_nodemcu":("profiles.esp32_boards", "ESP32_38Pin_NodeMCU"),
49
+ }
50
+
51
+ # ── Internal state for convenience objects ─────────────────────
52
+ _esp_led = None # Built-in LED (DigitalLED or NeoPixelLED)
53
+ _esp_temp_sensor = None # Built-in temperature sensor
54
+
55
+ # Module-level __getattr__ (MicroPython 1.18+) for lazy loading.
56
+ # This prevents NoneType errors if user imports before calling begin().
57
+ def __getattr__(name):
58
+ if name == "esp_led":
59
+ if _esp_led is None:
60
+ raise RuntimeError(
61
+ "[espzero] ERROR: 'esp_led' is not initialized. "
62
+ "You must call espzero.begin() first."
63
+ )
64
+ return _esp_led
65
+ if name == "esp_temp_sensor":
66
+ return _esp_temp_sensor
67
+ raise AttributeError("module 'espzero' has no attribute '{}'".format(name))
68
+
69
+
70
+ def begin(board="auto"):
71
+ """
72
+ Initialise the board profile. Must be called before any espzero class.
73
+
74
+ :param board:
75
+ - ``"auto"`` – detect from ``sys.implementation._machine``
76
+ - A board name string – e.g. ``"esp32_devkit_v1"``
77
+ - A ``BoardProfile`` instance – for custom boards
78
+
79
+ Raises ``ValueError`` for unknown board name strings.
80
+ """
81
+ global _esp_led, _esp_temp_sensor
82
+
83
+ from .profiles._base import BoardProfile
84
+
85
+ if isinstance(board, BoardProfile):
86
+ _hal._profile = board
87
+
88
+ elif board == "auto":
89
+ from .profiles.auto import detect
90
+ begin(detect())
91
+ return
92
+
93
+ else:
94
+ if board not in _PROFILE_MAP:
95
+ raise ValueError(
96
+ "[espzero] Unknown board: '{}'. "
97
+ "Available boards: {}".format(board, list(_PROFILE_MAP.keys()))
98
+ )
99
+ mod_name, cls_name = _PROFILE_MAP[board]
100
+ # Dynamically import the profile module within the package
101
+ full_mod_name = __name__ + "." + mod_name
102
+ mod = __import__(full_mod_name, None, None, [cls_name])
103
+ _hal._profile = getattr(mod, cls_name)()
104
+
105
+ print("[espzero] Board: {} ({})".format(
106
+ _hal._profile.NAME, _hal._profile.CHIP))
107
+
108
+ # Initialise built-in LED — branch on LED type declared in the profile
109
+ from ._core import NeoPixelLED, LED as _LED
110
+ try:
111
+ p = _hal._profile
112
+ if p.INTERNAL_LED_TYPE == "neopixel":
113
+ _esp_led = NeoPixelLED(p.resolve_pin("internal"))
114
+ else:
115
+ _esp_led = _LED("internal",
116
+ pwm=False,
117
+ active_high=p.INTERNAL_LED_ACTIVE_HIGH)
118
+ except Exception as e:
119
+ print("[espzero] LED Init Error:", e)
120
+ _esp_led = None
121
+
122
+ # Initialise built-in temperature sensor
123
+ try:
124
+ from ._core import ESPTemperatureSensor
125
+ _esp_temp_sensor = ESPTemperatureSensor()
126
+ except Exception as e:
127
+ print("[espzero] TempSensor Init Error:", e)
128
+ _esp_temp_sensor = None
129
+
130
+
131
+ # ── Re-export public API ───────────────────────────────────────
132
+ from ._core import (
133
+ LED, DigitalLED, PWMLED, NeoPixelLED,
134
+ Buzzer, PWMBuzzer, Speaker,
135
+ RGBLED,
136
+ Servo,
137
+ Motor, Robot, Rover, Stepper,
138
+ Button, Switch, MotionSensor, TouchSensor,
139
+ Potentiometer, Pot,
140
+ TemperatureSensor, TempSensor, Thermistor,
141
+ DistanceSensor,
142
+ ESPTemperatureSensor,
143
+ DigitalOutputDevice, PWMOutputDevice,
144
+ DigitalInputDevice, AnalogInputDevice,
145
+ )
146
+ from ._wifi import WiFi
147
+ from ._touch import CapTouch