two
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Standalone WiFi/GPIO/INA226 isolation test for the official MaixPy tool.
|
||||
|
||||
This file intentionally does not import project modules or start project
|
||||
threads. Select TEST_MODE below, then run the file directly.
|
||||
"""
|
||||
|
||||
import time
|
||||
|
||||
from maix import gpio, i2c, network, pinmap
|
||||
|
||||
|
||||
# Change only this value before each run.
|
||||
# wifi WiFi only
|
||||
# a25 A25 only
|
||||
# a23 A23 only
|
||||
# gpio A23/A26 only
|
||||
# ina INA226 only
|
||||
# gpio_ina GPIOs, then INA226
|
||||
# a25_wifi A25, then WiFi
|
||||
# a23_wifi A23, then WiFi
|
||||
# all GPIOs, INA226, then WiFi
|
||||
TEST_MODE = "a25_wifi"
|
||||
|
||||
WIFI_SSID = "sheling4b02-5G"
|
||||
WIFI_PASSWORD = "Aa12345678"
|
||||
WIFI_TIMEOUT_S = 20
|
||||
I2C_BUS_NUM = 5
|
||||
INA226_ADDR = 0x40
|
||||
|
||||
|
||||
def init_leds():
|
||||
return init_selected_leds(True, True)
|
||||
|
||||
|
||||
def init_selected_leds(use_a26, use_a23):
|
||||
outputs = []
|
||||
if use_a26:
|
||||
print("Initializing A25 -> GPIOA25")
|
||||
pinmap.set_pin_function("A25", "GPIOA25")
|
||||
green = gpio.GPIO("GPIOA25", gpio.Mode.OUT)
|
||||
green.value(0)
|
||||
outputs.append(("GPIOA25", green))
|
||||
print("GPIOA25 initialized LOW")
|
||||
if use_a23:
|
||||
print("Initializing A23 -> GPIOA23")
|
||||
pinmap.set_pin_function("A23", "GPIOA23")
|
||||
red = gpio.GPIO("GPIOA23", gpio.Mode.OUT)
|
||||
red.value(0)
|
||||
outputs.append(("GPIOA23", red))
|
||||
print("GPIOA23 initialized LOW")
|
||||
return outputs
|
||||
|
||||
|
||||
def test_ina226():
|
||||
# Match the board mapping used by the application before opening I2C5.
|
||||
pinmap.set_pin_function("A15", "I2C5_SCL")
|
||||
pinmap.set_pin_function("A27", "I2C5_SDA")
|
||||
print("A15/A27 configured for I2C5")
|
||||
print("Initializing I2C bus", I2C_BUS_NUM)
|
||||
bus = i2c.I2C(I2C_BUS_NUM, i2c.Mode.MASTER)
|
||||
print("Reading INA226 at 0x%02X" % INA226_ADDR)
|
||||
config = bus.readfrom_mem(INA226_ADDR, 0x00, 2)
|
||||
voltage_raw = bus.readfrom_mem(INA226_ADDR, 0x02, 2)
|
||||
voltage = ((voltage_raw[0] << 8) | voltage_raw[1]) * 1.25 / 1000
|
||||
print("INA226 config=0x%02X%02X voltage=%.3fV" % (config[0], config[1], voltage))
|
||||
return bus
|
||||
|
||||
|
||||
def test_wifi():
|
||||
print("Starting MaixPy WiFi connection...")
|
||||
wifi = network.wifi.Wifi()
|
||||
result = wifi.connect(WIFI_SSID, WIFI_PASSWORD, wait=True, timeout=WIFI_TIMEOUT_S)
|
||||
print("WiFi connect result:", result)
|
||||
print("WiFi connected:", wifi.is_connected())
|
||||
try:
|
||||
print("WiFi IP:", wifi.get_ip())
|
||||
except Exception as exc:
|
||||
print("WiFi status query failed:", exc)
|
||||
|
||||
|
||||
def main():
|
||||
valid = ("wifi", "a25", "a23", "gpio", "ina", "gpio_ina", "a25_wifi", "a23_wifi", "all")
|
||||
mode = TEST_MODE.lower()
|
||||
if mode not in valid:
|
||||
print("TEST_MODE must be one of:", ", ".join(valid))
|
||||
return 1
|
||||
|
||||
leds = []
|
||||
try:
|
||||
print("=== Standalone WiFi/GPIO/INA226 isolation ===")
|
||||
print("mode:", mode)
|
||||
if mode in ("a25", "a25_wifi"):
|
||||
leds = init_selected_leds(True, False)
|
||||
time.sleep(1)
|
||||
elif mode in ("a23", "a23_wifi"):
|
||||
leds = init_selected_leds(False, True)
|
||||
time.sleep(1)
|
||||
elif mode in ("gpio", "gpio_ina", "all"):
|
||||
leds = init_leds()
|
||||
time.sleep(1)
|
||||
if mode in ("ina", "gpio_ina", "all"):
|
||||
test_ina226()
|
||||
time.sleep(1)
|
||||
if mode in ("wifi", "a25_wifi", "a23_wifi", "all"):
|
||||
test_wifi()
|
||||
print("TEST COMPLETE")
|
||||
return 0
|
||||
except Exception as exc:
|
||||
print("TEST FAILED:", repr(exc))
|
||||
return 1
|
||||
finally:
|
||||
for name, led in leds:
|
||||
try:
|
||||
led.value(0)
|
||||
print(name, "LOW")
|
||||
except Exception as exc:
|
||||
print(name, "cleanup failed:", exc)
|
||||
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user