I have been using a settings.py file with GLOBAL but after watching one of Damien's pycon talks on optimisation I'm concerned my method is horribly inefficient!
This is what I am doing at the moment
settings.py
Code: Select all
import os
import time
import sys
from machine import UART, Pin, WDT, Timer, SoftI2C, SoftSPI, RTC
from utils import AESTtime
import DS3231
import logging
def init():
global DATE_STRING, EX_RTC, RTC, INA3221, WLAN_SSID, WLAN_PASS, HOSTNAME, BROADCAST_ADDRESS, BROADCAST_PORT, UART, I2C
RTC = RTC()
INA3221 = None
WLAN_SSID = "GIGI-BEAR"
WLAN_PASS = "xxx"
BROADCAST_ADDRESS = "192.168.17.255"
BROADCAST_PORT = 3000
UART = UART(1, baudrate=115200, tx=37 , rx=38, txbuf=4096, rxbuf=4096, timeout=0)
I2C = None
current_date = AESTtime(time.time())
DATE_STRING = f'{current_date[0]}-{current_date[1]:02d}-{current_date[2]:02d}'
# Setup I2C
try:
I2C = SoftI2C(sda=Pin(33), scl=Pin(34), freq=400000)
LOGGER.debug("I2C started")
except:
LOGGER.debug("Couldnt start I2C")
try:
EX_RTC = DS3231.DS3231(I2C)
EX_RTC.get_time(set_rtc=True)
except:
print("Couldnt connect to DS3231")
Code: Select all
import settings
settings.init()
Code: Select all
import settings
settings.UART.write("Hello World!\n)