-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b97e19
commit 3ca45ba
Showing
14 changed files
with
874 additions
and
1,101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
 | ||
 | ||
 | ||
 | ||
 | ||
 | ||
|
||
<h3> </h3> | ||
|
||
MicroPython for bare ESP32 IOT Web System | ||
MicroPython for the LilyGo TTGO | ||
======================= | ||
<h2>w/ FTP updates</h2> | ||
<h2>w/ ST7789 C driver</h2> | ||
<p align="center"> | ||
<img src='image/wroom.png/'> | ||
<img src='image/TTGO.png/'> | ||
</p> | ||
<h3> </h3> | ||
<h3> | ||
<A HREF="https://github.com/SilverLogix/MicroPython-TTGO/releases/tag/v1.1.1">Latest Update</a> | ||
</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import micropython | ||
|
||
import machine | ||
# noinspection PyUnresolvedReferences | ||
from machine import Pin | ||
import debug | ||
import gfx | ||
|
||
|
||
machine.freq(80_000000) # 240_ | ||
|
||
gfx.init() | ||
gfx.boot(gfx.RED) | ||
|
||
# noinspection PyArgumentList | ||
machine.freq(240000000) | ||
micropython.alloc_emergency_exception_buf(100) | ||
debug.bug_boot() | ||
|
||
print(str('Booting...')) | ||
btn = Pin(35, Pin.IN) # Gpio 35 as button | ||
del debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,87 @@ | ||
import micropython | ||
|
||
def space_free(): # Display remaining free space | ||
from os import statvfs | ||
|
||
bits = statvfs('/flash') | ||
# print(str(bits)) | ||
blksize = bits[0] # 4096 | ||
blkfree = bits[3] # 12 | ||
freesize = blksize * blkfree # 49152 | ||
mbcalc = 1024 * 1024 # 1048576 | ||
mbfree = freesize / mbcalc # 0.046875 | ||
print("Free space:" + str(mbfree)) | ||
|
||
|
||
def m_freq(): # Get current machine Freq | ||
import machine | ||
|
||
gfr = str(machine.freq()) | ||
|
||
print("Mhz: " + gfr) | ||
|
||
return gfr | ||
|
||
|
||
def raw_temp(): # Get current CPU temp | ||
import esp32 | ||
|
||
raw = str(esp32.raw_temperature()) | ||
rtemp = ("CPU Temp: " + raw + "F") | ||
print(rtemp) | ||
rrr = rtemp | ||
return rrr | ||
|
||
|
||
def showVoltage(): # Show current(pun intended) used Voltage | ||
# noinspection PyUnresolvedReferences | ||
from machine import ADC, Pin | ||
|
||
adc = ADC(Pin(32)) | ||
|
||
vref = int(1100) | ||
|
||
v = adc.read() | ||
battery_voltage = (float(v) / 4095.0) * 2.0 * 3.3 * (vref / 1000.0) | ||
voltage = ("Voltage: {0:0.2f}v".format(battery_voltage)) | ||
print(voltage) | ||
|
||
ddd = voltage | ||
return ddd | ||
|
||
|
||
def getmac(): # Get and display chip MAC address | ||
def bug_boot(): | ||
import network | ||
import ubinascii | ||
mac = ubinascii.hexlify(network.WLAN(1).config('mac'), ':').decode() | ||
print(str(mac)) | ||
|
||
|
||
def pprint(): # Put it all together and PRINT | ||
import machine | ||
from os import statvfs | ||
import os | ||
import gc | ||
import time | ||
|
||
bits = statvfs('/flash') | ||
mbfree = bits[0] * bits[3] / (1024 * 1024) | ||
mac = ubinascii.hexlify(network.WLAN(1).config('mac'), ':').decode() | ||
dirr = str(os.listdir()) | ||
time.sleep_ms(100) | ||
|
||
print("") | ||
print(f"MAC: {mac}") | ||
print(f"Mhz: {machine.freq() / 1e6:.0f}") | ||
print(f"Flash: {mbfree:.2f} MB") | ||
print("") | ||
print("-------------------") | ||
getmac() | ||
space_free() | ||
m_freq() | ||
raw_temp() | ||
showVoltage() | ||
print("--------------------") | ||
print(f"Files: {dirr}") | ||
print("") | ||
|
||
del statvfs, network, ubinascii, machine, os | ||
gc.collect() | ||
|
||
|
||
''' | ||
N = 200_000 | ||
def time_it(f, n): | ||
import utime | ||
t0 = utime.ticks_us() | ||
f(n) | ||
t1 = utime.ticks_us() | ||
dt = utime.ticks_diff(t1, t0) | ||
fmt = '{:5.3f} sec, {:6.3f} usec/read : {:8.2f} kreads/sec' | ||
print(fmt.format(dt * 1e-6, dt / n, n / dt * 1e3)) | ||
|
||
time_it(showVoltage, N) | ||
''' | ||
# time_it(showVoltage, N) | ||
|
||
|
||
def serial_mem(mp: bool): | ||
import micropython | ||
|
||
micropython.mem_info(mp) | ||
del micropython | ||
|
||
|
||
@micropython.native | ||
def crash_esp32(): | ||
import machine | ||
""" | ||
Crash the ESP32 by writing to an invalid memory address. | ||
This will trigger a panic and reset the device. | ||
""" | ||
# Define an invalid memory address (aligned to 4 bytes) | ||
address = 0x00000000 # Using address 0, which is typically unmapped | ||
|
||
try: | ||
# Attempt to read from the invalid address | ||
machine.mem32[address] | ||
except Exception as e: | ||
print(f"Crash attempt triggered an exception: {e}") | ||
print("ESP32 should reset now.") | ||
|
||
|
||
def inf_recurs(depth=0): | ||
import utime | ||
"""Crash by stack overflow due to infinite recursion.""" | ||
print(f"Recursion depth: {depth}") | ||
utime.sleep_ms(1) # Small delay to allow for print | ||
return inf_recurs(depth + 1) | ||
|
||
|
||
def watchout(): | ||
"""Crash by triggering the watchdog timer.""" | ||
# Disable the software WDT if it's running | ||
try: | ||
import machine | ||
machine.WDT(timeout=1000) # 1 second timeout | ||
except: | ||
pass # Hardware WDT might still be active | ||
|
||
print("Waiting for watchdog timer...") | ||
while True: | ||
pass # Busy loop to prevent feeding the watchdog |
Oops, something went wrong.