pymcu-micropython 0.1.0a1__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.
Files changed (56) hide show
  1. pymcu_micropython-0.1.0a1/.github/workflows/publish.yml +78 -0
  2. pymcu_micropython-0.1.0a1/.gitignore +8 -0
  3. pymcu_micropython-0.1.0a1/PKG-INFO +6 -0
  4. pymcu_micropython-0.1.0a1/README.md +76 -0
  5. pymcu_micropython-0.1.0a1/examples/adc-read/pyproject.toml +19 -0
  6. pymcu_micropython-0.1.0a1/examples/adc-read/src/main.py +32 -0
  7. pymcu_micropython-0.1.0a1/examples/blink/pyproject.toml +19 -0
  8. pymcu_micropython-0.1.0a1/examples/blink/src/main.py +21 -0
  9. pymcu_micropython-0.1.0a1/examples/dht-sensor/pyproject.toml +20 -0
  10. pymcu_micropython-0.1.0a1/examples/dht-sensor/src/dht.py +115 -0
  11. pymcu_micropython-0.1.0a1/examples/dht-sensor/src/main.py +48 -0
  12. pymcu_micropython-0.1.0a1/examples/eeprom-avr/pyproject.toml +19 -0
  13. pymcu_micropython-0.1.0a1/examples/eeprom-avr/src/main.py +34 -0
  14. pymcu_micropython-0.1.0a1/examples/lm35-sensor/pyproject.toml +20 -0
  15. pymcu_micropython-0.1.0a1/examples/lm35-sensor/src/main.py +34 -0
  16. pymcu_micropython-0.1.0a1/examples/mem8-test/pyproject.toml +19 -0
  17. pymcu_micropython-0.1.0a1/examples/mem8-test/src/main.py +24 -0
  18. pymcu_micropython-0.1.0a1/examples/pwm-demo/pyproject.toml +20 -0
  19. pymcu_micropython-0.1.0a1/examples/pwm-demo/src/main.py +75 -0
  20. pymcu_micropython-0.1.0a1/examples/signal-led/pyproject.toml +19 -0
  21. pymcu_micropython-0.1.0a1/examples/signal-led/src/main.py +24 -0
  22. pymcu_micropython-0.1.0a1/examples/uart-echo/pyproject.toml +19 -0
  23. pymcu_micropython-0.1.0a1/examples/uart-echo/src/main.py +35 -0
  24. pymcu_micropython-0.1.0a1/examples/wdt-blink/pyproject.toml +19 -0
  25. pymcu_micropython-0.1.0a1/examples/wdt-blink/src/main.py +24 -0
  26. pymcu_micropython-0.1.0a1/pyproject.toml +20 -0
  27. pymcu_micropython-0.1.0a1/src/pymcu_micropython/__init__.py +2 -0
  28. pymcu_micropython-0.1.0a1/src/pymcu_micropython/avr.py +121 -0
  29. pymcu_micropython-0.1.0a1/src/pymcu_micropython/board_chips.py +33 -0
  30. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/__init__.py +2 -0
  31. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/arduino_mega.py +51 -0
  32. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/arduino_micro.py +17 -0
  33. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/arduino_nano.py +36 -0
  34. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/arduino_uno.py +39 -0
  35. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny13.py +11 -0
  36. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny13a.py +10 -0
  37. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny2313.py +12 -0
  38. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny24.py +12 -0
  39. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny25.py +11 -0
  40. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny4313.py +12 -0
  41. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny44.py +12 -0
  42. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny45.py +11 -0
  43. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny84.py +12 -0
  44. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/attiny85.py +11 -0
  45. pymcu_micropython-0.1.0a1/src/pymcu_micropython/boards/digispark.py +13 -0
  46. pymcu_micropython-0.1.0a1/src/pymcu_micropython/lm35.py +40 -0
  47. pymcu_micropython-0.1.0a1/src/pymcu_micropython/machine.py +753 -0
  48. pymcu_micropython-0.1.0a1/src/pymcu_micropython/micropython.py +35 -0
  49. pymcu_micropython-0.1.0a1/src/pymcu_micropython/utime.py +63 -0
  50. pymcu_micropython-0.1.0a1/tests/conftest.py +190 -0
  51. pymcu_micropython-0.1.0a1/tests/test_avr.py +130 -0
  52. pymcu_micropython-0.1.0a1/tests/test_boards.py +192 -0
  53. pymcu_micropython-0.1.0a1/tests/test_integration.py +355 -0
  54. pymcu_micropython-0.1.0a1/tests/test_machine.py +566 -0
  55. pymcu_micropython-0.1.0a1/tests/test_micropython.py +35 -0
  56. pymcu_micropython-0.1.0a1/tests/test_utime.py +42 -0
@@ -0,0 +1,78 @@
1
+ name: Publish
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ # Pure-Python wheel + sdist (hatchling). No native build matrix needed.
11
+ build:
12
+ name: Build wheel + sdist
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: read
16
+ steps:
17
+ - name: Checkout code
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Set up uv
21
+ uses: astral-sh/setup-uv@v5
22
+
23
+ - name: Build wheel + sdist
24
+ run: uv build
25
+
26
+ - name: Upload dist artifacts
27
+ uses: actions/upload-artifact@v4
28
+ with:
29
+ name: dist
30
+ path: dist/*
31
+ retention-days: 15
32
+
33
+ # Trusted Publishing (OIDC) to PyPI on every v* tag — stable and pre-release
34
+ # alike, so the 0.1.0a1 alpha lands on real PyPI alongside the core packages.
35
+ publish-pypi:
36
+ name: Publish to PyPI
37
+ needs: build
38
+ if: github.ref_type == 'tag'
39
+ runs-on: ubuntu-latest
40
+ environment: release
41
+ permissions:
42
+ id-token: write
43
+
44
+ steps:
45
+ - name: Download dist artifacts
46
+ uses: actions/download-artifact@v4
47
+ with:
48
+ name: dist
49
+ path: dist
50
+
51
+ - name: Set up uv
52
+ uses: astral-sh/setup-uv@v5
53
+
54
+ - name: Publish to PyPI
55
+ run: uv publish dist/*
56
+
57
+ # Manual smoke-test channel: dispatch without a tag publishes to TestPyPI.
58
+ publish-testpypi:
59
+ name: Publish to TestPyPI
60
+ needs: build
61
+ if: github.event_name == 'workflow_dispatch'
62
+ runs-on: ubuntu-latest
63
+ environment: prerelease
64
+ permissions:
65
+ id-token: write
66
+
67
+ steps:
68
+ - name: Download dist artifacts
69
+ uses: actions/download-artifact@v4
70
+ with:
71
+ name: dist
72
+ path: dist
73
+
74
+ - name: Set up uv
75
+ uses: astral-sh/setup-uv@v5
76
+
77
+ - name: Publish to TestPyPI
78
+ run: uv publish --publish-url https://test.pypi.org/legacy/ dist/*
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .venv/
8
+ .DS_Store
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: pymcu-micropython
3
+ Version: 0.1.0a1
4
+ Summary: MicroPython stdlib flavor for PyMCU
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: pymcu-stdlib>=0.1.0a1
@@ -0,0 +1,76 @@
1
+ # pymcu-micropython
2
+
3
+ MicroPython standard-library flavor for **PyMCU** — an AOT (ahead-of-time) Python compiler that targets microcontrollers.
4
+
5
+ ## What is this?
6
+
7
+ `pymcu-micropython` is a drop-in compatibility layer that lets you write firmware using the familiar [MicroPython](https://micropython.org/) API (`machine`, `utime`, `micropython` modules) while compiling it to bare-metal machine code with PyMCU. All classes and functions are implemented as zero-cost abstractions (ZCA): they are marked `@inline` so that no SRAM instance structs, no stack frames, and no interpreter overhead are introduced — the compiler resolves everything at compile time.
8
+
9
+ ## Modules
10
+
11
+ | Module | MicroPython equivalent | Description |
12
+ |--------|------------------------|-------------|
13
+ | `machine` | `machine` | `Pin`, `UART`, `ADC`, `PWM`, `SPI`, `I2C`, `Timer`, `WDT`, `Signal` |
14
+ | `utime` | `utime` / `time` | `sleep_ms()`, `sleep_us()`, `sleep()`, `ticks_ms()`, `ticks_us()`, `ticks_diff()`, `ticks_add()` |
15
+ | `micropython` | `micropython` | `const()`, `@native`, `@viper` stubs |
16
+
17
+ ## Installation
18
+
19
+ ```sh
20
+ pip install pymcu-micropython
21
+ ```
22
+
23
+ Or add it as a dependency in your project's `pyproject.toml`:
24
+
25
+ ```toml
26
+ [project]
27
+ dependencies = [
28
+ "pymcu>=0.1.0a1",
29
+ "pymcu-stdlib>=0.1.0a1",
30
+ "pymcu-micropython>=0.1.0a1",
31
+ ]
32
+ ```
33
+
34
+ ## Quick start
35
+
36
+ The API is intentionally identical to MicroPython, so existing MicroPython sketches work without modification:
37
+
38
+ ```python
39
+ from machine import Pin
40
+ from utime import sleep_ms
41
+
42
+ def main():
43
+ led = Pin(13, Pin.OUT) # Arduino Uno built-in LED (D13 = PB5)
44
+ while True:
45
+ led.value(1)
46
+ sleep_ms(500)
47
+ led.value(0)
48
+ sleep_ms(500)
49
+ ```
50
+
51
+ Compile and flash with PyMCU:
52
+
53
+ ```sh
54
+ pymcu build
55
+ pymcu flash
56
+ ```
57
+
58
+ ## Examples
59
+
60
+ | Example | Description |
61
+ |---------|-------------|
62
+ | [`examples/blink`](examples/blink) | Blink the built-in LED at 1 Hz |
63
+ | [`examples/adc-read`](examples/adc-read) | Read a potentiometer and print values over UART |
64
+ | [`examples/uart-echo`](examples/uart-echo) | Echo received bytes back over UART |
65
+
66
+ ## Supported boards
67
+
68
+ The library currently ships pin-mapping support for:
69
+
70
+ - **Arduino Uno** (ATmega328P)
71
+
72
+ Additional boards can be added by contributing a file under `src/pymcu_micropython/boards/`.
73
+
74
+ ## License
75
+
76
+ See [LICENSE](LICENSE) for details.
@@ -0,0 +1,19 @@
1
+ [project]
2
+ name = "adc-read"
3
+ version = "0.1.0a1"
4
+ requires-python = ">=3.11"
5
+ dependencies = [
6
+ "pymcu-stdlib>=0.1.0a1",
7
+ "pymcu-compiler[avr]>=0.1.0a1",
8
+ "pymcu-micropython>=0.1.0a1",
9
+ ]
10
+
11
+ [tool.pymcu]
12
+ board = "arduino_uno"
13
+ frequency = 16000000
14
+ sources = "src"
15
+ entry = "main.py"
16
+ stdlib = ["micropython"]
17
+
18
+ [tool.pymcu.flash]
19
+ programmer = "avrdude"
@@ -0,0 +1,32 @@
1
+ # ADC Read -- MicroPython style on Arduino Uno
2
+ #
3
+ # Demonstrates:
4
+ # machine.ADC -- read_u16() returns 0-65535 scaled from 10-bit ADC
5
+ # machine.UART -- print values over serial
6
+ # utime -- sleep_ms() between readings
7
+ #
8
+ # Wiring:
9
+ # A0: potentiometer center tap (or any analog voltage 0-5V)
10
+ #
11
+ # Expected behaviour:
12
+ # Prints ADC value every 200 ms over UART at 9600 baud
13
+
14
+ from machine import UART, ADC, Pin
15
+ from utime import sleep_ms
16
+ from pymcu.types import uint16
17
+
18
+
19
+ def main():
20
+ uart = UART(0, 9600)
21
+ adc = ADC(Pin(14)) # Pin(14) = A0 = PC0
22
+
23
+ uart.println("ADC ready")
24
+
25
+ while True:
26
+ val: uint16 = adc.read() # 0-1023
27
+ uart.write_str("ADC=")
28
+ # Print high byte as proxy for value (0-255 range)
29
+ from pymcu.types import uint8
30
+ hi: uint8 = val >> 2 # scale 0-1023 to 0-255
31
+ uart.print_byte(hi)
32
+ sleep_ms(200)
@@ -0,0 +1,19 @@
1
+ [project]
2
+ name = "blink"
3
+ version = "0.1.0a1"
4
+ requires-python = ">=3.11"
5
+ dependencies = [
6
+ "pymcu-stdlib>=0.1.0a1",
7
+ "pymcu-compiler[avr]>=0.1.0a1",
8
+ "pymcu-micropython>=0.1.0a1",
9
+ ]
10
+
11
+ [tool.pymcu]
12
+ board = "arduino_uno"
13
+ frequency = 16000000
14
+ sources = "src"
15
+ entry = "main.py"
16
+ stdlib = ["micropython"]
17
+
18
+ [tool.pymcu.flash]
19
+ programmer = "avrdude"
@@ -0,0 +1,21 @@
1
+ # Blink -- MicroPython style on Arduino Uno
2
+ #
3
+ # Demonstrates:
4
+ # machine.Pin -- integer pin numbers (D13 = PB5 built-in LED)
5
+ # utime -- sleep_ms() with no hardware timer dependency
6
+ #
7
+ # Wiring:
8
+ # No external wiring -- uses built-in LED on D13
9
+ #
10
+ # Expected behaviour:
11
+ # LED toggles at 1 Hz (500 ms per half-period) indefinitely
12
+
13
+ from machine import Pin
14
+ from utime import sleep_ms
15
+
16
+
17
+ def main():
18
+ led = Pin(13, Pin.OUT)
19
+ while True:
20
+ led.toggle()
21
+ sleep_ms(500)
@@ -0,0 +1,20 @@
1
+ [project]
2
+ name = "dht-sensor"
3
+ version = "0.1.0"
4
+ requires-python = ">=3.11"
5
+ dependencies = [
6
+ "pymcu-stdlib>=0.1.0a1",
7
+ "pymcu-compiler[avr]>=0.1.0a1",
8
+ "pymcu-micropython>=0.1.0a1",
9
+ ]
10
+
11
+ [tool.pymcu]
12
+ board = "arduino_uno"
13
+ frequency = 16000000
14
+ sources = "src"
15
+ entry = "main.py"
16
+ stdlib = ["micropython"]
17
+
18
+ [tool.pymcu.flash]
19
+ programmer = "avrdude"
20
+ # port = "/dev/cu.usbmodemXXXX" # set your board port here, or pass --port
@@ -0,0 +1,115 @@
1
+ # DHT11/DHT22 temperature and humidity driver (MicroPython style)
2
+ #
3
+ # API matches micropython-lib dht.py:
4
+ # sensor = DHT11(Pin(2, Pin.IN)) # or DHT22(...)
5
+ # sensor.measure() -- read sensor (updates internal state)
6
+ # sensor.humidity() -- humidity value
7
+ # sensor.temperature() -- temperature value
8
+ # sensor.failed -- True if read failed or checksum mismatch
9
+ # (PyMCU extension: real MicroPython raises Exception)
10
+ #
11
+ # DHT11: humidity() -> integer % RH, temperature() -> integer C
12
+ # DHT22: humidity() -> float % RH, temperature() -> float C (signed)
13
+ #
14
+ # Wiring:
15
+ # DATA -> pin passed in (e.g. D2), with 4.7 kohm pull-up to +5 V
16
+ # VCC -> +5 V (DHT11) or +3.3/5 V (DHT22)
17
+ # GND -> GND
18
+ #
19
+ # Protocol (single-wire, 40-bit):
20
+ # 1. MCU pulls low >= 18 ms (start signal)
21
+ # 2. MCU releases, sensor pulls low ~80 us then high ~80 us (ACK)
22
+ # 3. 40 bits: each bit starts with ~50 us LOW; HIGH duration decides value:
23
+ # count > 35 loop iterations = 1, else = 0
24
+ # 4. Checksum = lower 8 bits of sum of the first 4 bytes
25
+
26
+ from pymcu.types import uint8, inline
27
+ from machine import Pin, time_pulse_us
28
+ from utime import sleep_ms, sleep_us
29
+
30
+
31
+ class DHTBase:
32
+ @inline
33
+ def __init__(self, pin: Pin):
34
+ self._pin = pin
35
+ self.failed = False
36
+ self._hum_int = 0
37
+ self._hum_dec = 0
38
+ self._temp_int = 0
39
+ self._temp_dec = 0
40
+
41
+ @inline
42
+ def measure(self):
43
+ # Start signal: hold low >= 18 ms, then pull high 20-40 us before
44
+ # releasing to input. The high() call leaves PORT bit = 1 so that
45
+ # mode(IN) enables the AVR internal pull-up (PORT=1, DDR=0).
46
+ self._pin.mode(Pin.OUT)
47
+ self._pin.low()
48
+ sleep_ms(18)
49
+ self._pin.high()
50
+ sleep_us(30)
51
+ self._pin.mode(Pin.IN)
52
+
53
+ # ACK: sensor pulls low ~80 us, then high ~80 us
54
+ if time_pulse_us(self._pin, 0, 1000) < 0:
55
+ self.failed = True
56
+ return
57
+ if time_pulse_us(self._pin, 1, 1000) < 0:
58
+ self.failed = True
59
+ return
60
+
61
+ # Read five bytes: hum_int, hum_dec, temp_int, temp_dec, checksum
62
+ hum_int: uint8 = self._read_byte()
63
+ hum_dec: uint8 = self._read_byte()
64
+ temp_int: uint8 = self._read_byte()
65
+ temp_dec: uint8 = self._read_byte()
66
+ checksum: uint8 = self._read_byte()
67
+
68
+ expected: uint8 = (hum_int + hum_dec + temp_int + temp_dec) & 0xFF
69
+ if checksum != expected:
70
+ self.failed = True
71
+ return
72
+
73
+ self.failed = False
74
+ self._hum_int = hum_int
75
+ self._hum_dec = hum_dec
76
+ self._temp_int = temp_int
77
+ self._temp_dec = temp_dec
78
+
79
+ def _read_byte(self) -> uint8:
80
+ result: uint8 = 0
81
+ bit: uint8 = 0
82
+ while bit < 8:
83
+ # pulse_in(1) waits through the ~50 us bit-start LOW then
84
+ # measures the HIGH duration: ~26 us = 0, ~70 us = 1.
85
+ # Timeout returns -1 (int16) which is < 40, so the bit reads as 0;
86
+ # the checksum will catch any corrupted frame.
87
+ high_dur = time_pulse_us(self._pin, 1, 1000)
88
+ result = result << 1
89
+ if high_dur > 40:
90
+ result = result | 1
91
+ bit = bit + 1
92
+ return result
93
+
94
+
95
+ class DHT11(DHTBase):
96
+ @inline
97
+ def humidity(self) -> uint8:
98
+ return self._hum_int
99
+
100
+ @inline
101
+ def temperature(self) -> uint8:
102
+ return self._temp_int
103
+
104
+
105
+ class DHT22(DHTBase):
106
+ @inline
107
+ def humidity(self):
108
+ return (self._hum_int << 8 | self._hum_dec) * 0.1
109
+
110
+ @inline
111
+ def temperature(self):
112
+ t = ((self._temp_int & 0x7F) << 8 | self._temp_dec) * 0.1
113
+ if self._temp_int & 0x80:
114
+ t = 0 - t
115
+ return t
@@ -0,0 +1,48 @@
1
+ # DHT11 Sensor -- MicroPython style on Arduino Uno
2
+ #
3
+ # Demonstrates:
4
+ # machine.Pin -- integer pin numbers (D2 = PD2 sensor, D13 = PB5 LED)
5
+ # print() -- UART 0 auto-initialized at 115200 baud by pymcu build
6
+ # utime -- sleep_ms() between measurements
7
+ # local driver -- dht11.DHT11 reads temperature and humidity
8
+ #
9
+ # MicroPython equivalent (runs unmodified on any MicroPython board with DHT):
10
+ # from machine import Pin
11
+ # from utime import sleep_ms
12
+ # from dht import DHT11
13
+ # sensor = DHT11(Pin(2, Pin.IN))
14
+ #
15
+ # Wiring:
16
+ # DHT11 DATA -> D2 (4.7 kohm pull-up to +5 V recommended)
17
+ # DHT11 VCC -> +5 V
18
+ # DHT11 GND -> GND
19
+ # LED: built-in on D13 (no wiring needed)
20
+ #
21
+ # UART output (115200 baud, auto-initialized by pymcu build):
22
+ # Boot: "DHT11 ready"
23
+ # OK: "H: XX T: XX"
24
+ # Error: "read error"
25
+
26
+ from machine import Pin
27
+ from utime import sleep_ms
28
+ from dht import DHT11
29
+
30
+
31
+ led = Pin(13, Pin.OUT)
32
+ sensor = DHT11(Pin(2, Pin.IN))
33
+
34
+ print("DHT11 ready")
35
+
36
+ while True:
37
+ sensor.measure()
38
+
39
+ if sensor.failed:
40
+ print("read error")
41
+ led.low()
42
+ else:
43
+ print("H: ", sensor.humidity(), " T: ", sensor.temperature(), sep="")
44
+ led.high()
45
+ sleep_ms(100)
46
+ led.low()
47
+
48
+ sleep_ms(2000)
@@ -0,0 +1,19 @@
1
+ [project]
2
+ name = "eeprom-avr"
3
+ version = "0.1.0a1"
4
+ requires-python = ">=3.11"
5
+ dependencies = [
6
+ "pymcu-stdlib>=0.1.0a1",
7
+ "pymcu-compiler[avr]>=0.1.0a1",
8
+ "pymcu-micropython>=0.1.0a1",
9
+ ]
10
+
11
+ [tool.pymcu]
12
+ board = "arduino_uno"
13
+ frequency = 16000000
14
+ sources = "src"
15
+ entry = "main.py"
16
+ stdlib = ["micropython"]
17
+
18
+ [tool.pymcu.flash]
19
+ programmer = "avrdude"
@@ -0,0 +1,34 @@
1
+ # eeprom-avr -- AVR EEPROM read / write
2
+ #
3
+ # Demonstrates avr.EEPROM to persist a counter across power cycles.
4
+ # On each boot the counter is read from EEPROM, incremented, written
5
+ # back, then the value is blinked out on the built-in LED (D13 / PB5):
6
+ # - each digit blinked N times (1-second on / off per blink)
7
+ # - 3-second pause between boots
8
+ #
9
+ # EEPROM address 0 holds the counter (0-9, wraps to 0 at 10).
10
+ #
11
+ # Wiring: none -- built-in LED
12
+ # Expected: blink count increments by 1 each power cycle (wraps at 10)
13
+
14
+ from avr import EEPROM
15
+ from machine import Pin
16
+ from utime import sleep_ms
17
+
18
+ ADDR: int = 0
19
+
20
+ led = Pin(13, Pin.OUT)
21
+ ee = EEPROM()
22
+ n: int = ee.read(ADDR)
23
+ if n >= 10:
24
+ n = 0
25
+ count: int = n + 1
26
+ ee.write(ADDR, count)
27
+ i: int = 0
28
+ while i < count:
29
+ led.value(1)
30
+ sleep_ms(500)
31
+ led.value(0)
32
+ sleep_ms(500)
33
+ i = i + 1
34
+ sleep_ms(3000)
@@ -0,0 +1,20 @@
1
+ [project]
2
+ name = "lm35-sensor"
3
+ version = "0.1.0"
4
+ requires-python = ">=3.11"
5
+ dependencies = [
6
+ "pymcu-stdlib>=0.1.0a1",
7
+ "pymcu-compiler[avr]>=0.1.0a1",
8
+ "pymcu-micropython>=0.1.0a1",
9
+ ]
10
+
11
+ [tool.pymcu]
12
+ board = "arduino_uno"
13
+ frequency = 16000000
14
+ sources = "src"
15
+ entry = "main.py"
16
+ stdlib = ["micropython"]
17
+
18
+ [tool.pymcu.flash]
19
+ programmer = "avrdude"
20
+ # port = "/dev/cu.usbmodemXXXX" # set your board port here, or pass --port
@@ -0,0 +1,34 @@
1
+ # LM35 Temperature Sensor -- MicroPython style on Arduino Uno
2
+ #
3
+ # Demonstrates:
4
+ # machine.ADC -- analog read on A0
5
+ # lm35.LM35 -- temperature conversion (integer and tenths)
6
+ # utime -- sleep_ms() between readings
7
+ #
8
+ # MicroPython equivalent (runs unmodified on any MicroPython board):
9
+ # from machine import ADC
10
+ # from utime import sleep_ms
11
+ # from lm35 import LM35
12
+ # sensor = LM35(ADC(0))
13
+ #
14
+ # Wiring:
15
+ # LM35 VS -> +5 V
16
+ # LM35 GND -> GND
17
+ # LM35 VOUT -> A0
18
+ #
19
+ # UART output (115200 baud, auto-initialized by pymcu build):
20
+ # Boot: "LM35 ready"
21
+ # Every 1 s: "T: 24.8 C" (integer part + tenths combined)
22
+
23
+ from machine import ADC, Pin
24
+ from utime import sleep_ms
25
+ from lm35 import LM35
26
+
27
+
28
+ sensor = LM35(ADC(Pin(14))) # A0 = Pin(14) = PC0
29
+
30
+ print("LM35 ready")
31
+
32
+ while True:
33
+ print("T: ", sensor.temperature(), " C", sep="")
34
+ sleep_ms(1000)
@@ -0,0 +1,19 @@
1
+ [project]
2
+ name = "mem8-test"
3
+ version = "0.1.0a1"
4
+ requires-python = ">=3.11"
5
+ dependencies = [
6
+ "pymcu-stdlib>=0.1.0a1",
7
+ "pymcu-compiler[avr]>=0.1.0a1",
8
+ "pymcu-micropython>=0.1.0a1",
9
+ ]
10
+
11
+ [tool.pymcu]
12
+ board = "arduino_uno"
13
+ frequency = 16000000
14
+ sources = "src"
15
+ entry = "main.py"
16
+ stdlib = ["micropython"]
17
+
18
+ [tool.pymcu.flash]
19
+ programmer = "avrdude"
@@ -0,0 +1,24 @@
1
+ # mem8-test -- raw I/O register access via pymcu.chips
2
+ #
3
+ # Demonstrates direct AVR I/O register access by blinking the built-in
4
+ # LED (D13 / PB5) through DDRB and PORTB without using Pin.
5
+ #
6
+ # pymcu.chips.atmega328p exposes every hardware register as a typed
7
+ # ptr[uint8] module-level constant. The compiler maps reads/writes to
8
+ # the appropriate instruction (IN/OUT for I/O registers, LDS/STS for
9
+ # extended I/O). No special compiler magic required -- ptr is the
10
+ # standard PyMCU mechanism for raw memory access.
11
+ #
12
+ # Wiring: none -- built-in LED
13
+ # Expected: LED blinks at 2 Hz indefinitely
14
+
15
+ from pymcu.chips.atmega328p import DDRB, PORTB, PORTB5
16
+ from utime import sleep_ms
17
+
18
+ DDRB.value = DDRB.value | (1 << PORTB5)
19
+
20
+ while True:
21
+ PORTB.value = PORTB.value | (1 << PORTB5)
22
+ sleep_ms(250)
23
+ PORTB.value = PORTB.value & ~(1 << PORTB5)
24
+ sleep_ms(250)
@@ -0,0 +1,20 @@
1
+ [project]
2
+ name = "pwm-demo"
3
+ version = "0.1.0"
4
+ requires-python = ">=3.11"
5
+ dependencies = [
6
+ "pymcu-stdlib>=0.1.0a1",
7
+ "pymcu-compiler[avr]>=0.1.0a1",
8
+ "pymcu-micropython>=0.1.0a1",
9
+ ]
10
+
11
+ [tool.pymcu]
12
+ board = "arduino_uno"
13
+ frequency = 16000000
14
+ sources = "src"
15
+ entry = "main.py"
16
+ stdlib = ["micropython"]
17
+
18
+ [tool.pymcu.flash]
19
+ programmer = "avrdude"
20
+ # port = "/dev/cu.usbmodemXXXX" # set your board port here, or pass --port