示例#1
0
 def __init__(self):
     self.sensor = BH1750(SoftI2C(scl=Pin(22), sda=Pin(21)))
     self.max_level = 500
     self.last_day_list = None
     self.list = []
     self.last_measurement_time = 0
     self.get_level()
示例#2
0
    def __init__(self, gyro, acc, tau):
        # Class / object / constructor setup
        self.gx = None
        self.gy = None
        self.gz = None
        self.ax = None
        self.ay = None
        self.az = None

        self.gyroXcal = 0
        self.gyroYcal = 0
        self.gyroZcal = 0

        self.gyroRoll = 0
        self.gyroPitch = 0
        self.gyroYaw = 0

        self.roll = 0
        self.pitch = 0
        self.yaw = 0

        self.dtTimer = 0
        self.tau = tau

        self.gyroScaleFactor, self.gyroHex = self.gyroSensitivity(gyro)
        self.accScaleFactor, self.accHex = self.accelerometerSensitivity(acc)

        #Setting i2c pins to 11,12 on Raspberry Pico
        self.sda = Pin(8)
        self.scl = Pin(9)

        self.i2c = SoftI2C(sda=self.sda, scl=self.scl, freq=400000)
        self.address = 0x68
示例#3
0
def test1():
    COLLECT_NUMBER = 100
    i2c = SoftI2C(scl=Pin(20), sda=Pin(21), freq=200000)
    sensor = DFRobot_Ozone_IIC(i2c, OZONE_ADDRESS_3)
    sensor.set_mode(MEASURE_MODE_AUTOMATIC)
    while True:
        data = sensor.get_ozone_data(COLLECT_NUMBER)
        print(data, "ppb")  # Particules par miliard
        sleep_ms(1000)
示例#4
0
    def __init__(self):
        self.EN_DYN = Pin(16, Pin.OUT)
        self.EN_DYN.on()
        self.SPEED_PULSE = Pin(15, Pin.IN, pull=None)

        self.i2c = SoftI2C(scl=Pin(14), sda=Pin(12))
        self.oled = SSD1306_I2C(128, 64, self.i2c)

        self.ina = Ina219(self.i2c, r_shunt=50)
        self.ina.pga = 0  # maximum sensitivity
        self.ina.avg = 7  # maximum averaging

        self.btns = Btns([0, 2, 4, 32], 0.05)
    def __init__(self,
                 width = 128, height = 64,
                 scl_pin_id = 15, sda_pin_id = 4,
                 freq = 400000):

        self.width = width
        self.height = height
        self.poweron()
        self.i2c = SoftI2C(scl  = Pin(scl_pin_id, Pin.OUT),
                           sda  = Pin(sda_pin_id),
                           freq = freq)
        self.display = SSD1306_I2C(width, height, self.i2c)
        self.show = self.display.show
示例#6
0
文件: devices.py 项目: maro48m/piec
    def __init__(self):
        self.lcd = None
        self.lcd_light = True
        self.servo = None
        self.servo_pin = None
        self.display = None
        self.adc = None
        self.button = None
        self.thermometer = None

        if int(utils.get_config("servo_pin", -1)) > -1:
            self.servo_pin = Pin(int(utils.get_config("servo_pin", 4)))
            self.servo = PWM(self.servo_pin, freq=50)
            self.servo.duty(20)
            self.servo.duty(
                utils.map_temp_to_servo(
                    int(utils.get_config("piec_temperatura", 40))))
            del self.servo

        if int(utils.get_config("lcd_sda_pin", -1)) > -1:
            from esp8266_i2c_lcd import I2cLcd
            self.i2c = SoftI2C(scl=Pin(int(utils.get_config("lcd_scl_pin",
                                                            -1))),
                               sda=Pin(int(utils.get_config("lcd_sda_pin",
                                                            -1))),
                               freq=100000)
            self.lcd = I2cLcd(self.i2c, 0x27, 2, 16)
            self.lcd_wifi_chars(self.lcd)

            self.lcd.hide_cursor()
            self.lcd.clear()

        if int(utils.get_config("button_pin", -1)) > -1:
            self.button = Pin(int(utils.get_config("button_pin", 5)), Pin.IN,
                              Pin.PULL_UP)
        if int(utils.get_config("adc_pin", -1)) > -1:
            if sys.platform == "esp8266":
                self.adc = ADC(int(utils.get_config("adc_pin", 0)))
            elif sys.platform == "esp32":
                self.adc = ADC(Pin(int(utils.get_config("adc_pin", 2))))
                self.adc.atten(ADC.ATTN_11DB)
                self.adc.width(ADC.WIDTH_10BIT)

        if int(utils.get_config("thermometer_pin", -1)) > -1:
            import sensors
            self.thermometer = sensors.Sensory()
示例#7
0
 def __init__(self,
              i2c=SoftI2C(scl=Pin(22), sda=Pin(21), freq=1000000),
              address=const(0x48),
              width=128,
              height=64,
              addr=0x3c,
              external_vcc=False):
     self.addr = addr
     self.temp = bytearray(2)
     self.i2c = i2c
     self.con_ipstw = 0
     self.address = address
     self.np = neopixel.NeoPixel(Pin(12), 255, timing=1)
     self.Svn = ADC(Pin(36))  #SVP
     self.Svn.atten(ADC.ATTN_11DB)
     self.valSW = Pin(0, Pin.IN, Pin.PULL_UP)
     self.led = Pin(18, Pin.OUT)
     self.np[0] = (0, 0, 0)
     self.np[1] = (0, 0, 0)
     self.np[2] = (0, 0, 0)
     self.np.write()
     print('IPSTW...Run')
     super().__init__(width, height, external_vcc)
# Complete project details at https://RandomNerdTutorials.com/micropython-ssd1306-oled-scroll-shapes-esp32-esp8266/

from machine import Pin, SoftI2C
import ssd1306
from time import sleep

# ESP32 Pin assignment
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))

# ESP8266 Pin assignment
#i2c = SoftI2C(scl=Pin(5), sda=Pin(4))

oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

screen1_row1 = "Screen 1, row 1"
screen1_row2 = "Screen 1, row 2"
screen1_row3 = "Screen 1, row 3"

screen2_row1 = "Screen 2, row 1"
screen2_row2 = "Screen 2, row 2"

screen3_row1 = "Screen 3, row 1"

screen1 = [[0, 0, screen1_row1], [0, 16, screen1_row2], [0, 32, screen1_row3]]
screen2 = [[0, 0, screen2_row1], [0, 16, screen2_row2]]
screen3 = [[0, 40, screen3_row1]]


# Scroll in screen horizontally from left to right
示例#9
0
import utime
from machine import SoftI2C, Pin
from mpu6886 import MPU6886
from neopixel import NeoPixel

i2c = SoftI2C(scl=Pin(21), sda=Pin(25))
sensor = MPU6886(i2c)

gpio27 = Pin(27, Pin.OUT)
neopixels = NeoPixel(gpio27, 25)

class Font:

    def __init__(self):
        self.blocks = {'A': b'\x1e\x05\x05\x1e', 'B': b'\x1f\x15\x15\x0a',
                       'A90': b'\x06\x09\x0f\x09\x09'
                      }

    def bit_blit(self, char, pixels,
                     destination_x, destination_y, destination_w, destination_h,
                     foreground_color, background_color,
                     pindexFunc = lambda x,y,destination_w : y + destination_w * x):
        block = self.blocks[char]
        for source_x in range(len(block)):
            x = source_x + destination_x
            if x >= 0 and x < destination_w:
                column = block[source_x]
                for source_y in range(5):
                    y = source_y + destination_y
                    if y >= 0 and y < destination_h:
                        pixel_index = pindexFunc(x,y,destination_w)
示例#10
0
    config = dict()
    for line in lines:
      lineParts = line.split('=')
      if len(lineParts) > 1:
        config[lineParts[0].upper()] = lineParts[1]
  except Exception as e:
    print(e)
    print('{} not found.'.format(cfgFilename))
  return config

#-------------------------------------------------------------------------------
# setup
#-------------------------------------------------------------------------------
cfg = getConfig(CFGFILENAME)

i2c = SoftI2C(scl=Pin(int(cfg['SCLPIN'])), sda=Pin(int(cfg['SDAPIN'])))
oled = oledssd1306.Ssd1306I2c(int(cfg['OLEDWIDTH']), int(cfg['OLEDHIGHT']), i2c)

macAddr = int.from_bytes(WLAN().config('mac'), 'little')
macAddrStr = ubinascii.hexlify(WLAN().config('mac'),':').decode()

oled.fill(0)
oled.text('WLAN connect ...',0,1)
oled.show()
wlan = WLAN(STA_IF)
if cfg['IP'] != '':
 wlan.ifconfig((cfg['IP'], cfg['MASK'], cfg['GW'], cfg['DNS']))
wlan.active(True)
wlan.connect(SSID, PASSPHRASE)
while wlan.isconnected() == False:
  pass
示例#11
0
import machine, time, math, network, utime, json, gc
from machine import Pin, SoftI2C
import ssd1306
import urequests

wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect("ssid", "password")
time.sleep(8)

i2c = SoftI2C(scl=Pin(18), sda=Pin(19), freq=100000)

oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
oled.text('abc, World 1!', 0, 0)
oled.text('def, World 2!', 0, 10)
oled.text('3Hello, World 3!', 0, 20)
oled.show()

ddd = {'Bitcoin': 'btc_btcbitstamp'}
fontn = {
    '1': [
        0x00, 0x00, 0x00, 0x08, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
        0x08, 0x3E, 0x00, 0x00
    ],  #"1",0*/
    '2': [
        0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x02, 0x04, 0x08, 0x10, 0x20,
        0x42, 0x7E, 0x00, 0x00
    ],  #"2",1*/
    '3': [
示例#12
0
    "January", "February", "March", "April", "May", "June", "July", "August",
    "September", "October", "November", "December"
]
month_short = [
    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
    "Nov", "Dec"
]
day_of_week_str = [
    "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
    "Sunday"
]
day_of_week_short = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
#
# initialize I2C bus 0 on the t-watch
#
t_watch_i2c0 = SoftI2C(scl=Pin(T_WATCH_I2C0_SCL), sda=Pin(T_WATCH_I2C0_SDA))
#
# create a pcf8563 object on the I2C0 bus
#
pcf8563 = PCF8563(t_watch_i2c0)
currentTime = cetTime()
year = currentTime[0]
month = currentTime[1]
date = currentTime[2]
hour = currentTime[3]
minute = currentTime[4]
second = currentTime[5]
day = currentTime[6]
print(" Setting RTC to %s %d. %s %02d %02d:%02d:%02d" %
      (day_of_week_short[day], date, month_short[month], year, hour, minute,
       second))
示例#13
0
'''
实验名称:OLED显示屏(I2C总线)
版本:v1.0
日期:2021.1
作者:01Studio
社区:www.01studio.org
'''


from machine import SoftI2C,Pin         #从machine模块导入I2C、Pin子模块
from ssd1306 import SSD1306_I2C     #从ssd1306模块中导入SSD1306_I2C子模块

i2c = SoftI2C(scl=Pin(10), sda=Pin(11))   #SoftI2C初始化:scl--> 10, sda --> 11
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c) #OLED显示屏初始化:128*64分辨率,OLED的I2C地址是0x3c

oled.text("Hello World!", 0,  0)      #写入第1行内容
oled.text("MicroPython",  0, 20)      #写入第2行内容
oled.text("By 01Studio",  0, 50)      #写入第3行内容

oled.show()   #OLED执行显示
from ssd1306 import SSD1306_I2C
import urandom, utime, gc

freq(160000000)
gc.enable()
urandom.seed(sum([ADC(0).read() for _ in range(1000)
                  ]))  # generate randomize seed from floating analog pin

X = WIDTH // DOT_SIZE
Y = HEIGHT // DOT_SIZE
TOTAL = X * Y
board = [0 if urandom.getrandbits(RAND_BIT) else 1 for _ in range(TOTAL)]
gen = 0

display = SSD1306_I2C(WIDTH, HEIGHT,
                      SoftI2C(scl=Pin(5), sda=Pin(4), freq=400000))
display.fill(0)
display.show()

print('Conway\'s Game of Life: matrix size {} x {}'.format(X, Y))


def calculate_next_gen():  # calculate next generation of cells
    global board
    buffer = [0] * TOTAL
    for i in range(TOTAL):
        group = board[i-1:i+2] + \
                board[(i-1-X)%TOTAL:(i+2-X)%TOTAL] + \
                board[(i-1+X)%TOTAL:(i+2+X)%TOTAL]
        cells = sum(group)
        if not board[i]:
示例#15
0
# Complete project details at https://RandomNerdTutorials.com

from machine import Pin, SoftI2C
import ssd1306
from time import sleep

# Start I2C Communication SCL = 4 and SDA = 5 on Wemos Lolin32 ESP32 with built-in SSD1306 OLED
i2c = SoftI2C(scl=Pin(4), sda=Pin(5))

oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

oled.text('Hello, World 1!', 0, 0)
oled.text('Hello, World 2!', 0, 10)
oled.text('Hello, World 3!', 0, 20)

oled.show()
示例#16
0
def autoAntenna():
    oled.fill(0)
    oled.show()
    freq_temp = 0
    radio_temp = 0
    ant_temp = 0
    try:
        while (True):
            if 0 == p36.value() or 0 == p39.value() or 0 == p34.value(
            ) or 0 == p35.value():
                print('Manual Antenna')
                manualAntenna()
            rssi = str(station.status('rssi'))
            graphics.fill_rect(75, 10, 128, 10, 0)
            oled.text(rssi + 'dBm', 75, 10, 1)
            oled.show()
            bytesAddressPair = s.recvfrom(bufferSize)
            message = bytesAddressPair[0]
            clientMsg = "Message from Client:{}".format(message)
            parser1 = clientMsg.split("</Freq")[0]
            freq = int(float(parser1.split("Freq>")[1]))
            parser2 = clientMsg.split("</RadioNr")[0]
            radio = int(int(parser2.split("RadioNr>")[1]))
            parser3 = clientMsg.split("</Antenna")[0]
            ant = int(int(parser3.split("Antenna>")[1]))
            #print('in Auto loop')
            if radio != radio_temp or ant != ant_temp or freq != freq_temp:
                #need to add pin change above to work outside N1MM
                freq_temp = freq
                ant_temp = ant
                radio_temp = radio
                band = 0
                #Display ham bands and band decoder
                if 179999 < freq < 200000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b160.value(1)
                    band = '160'
                    print(band + " meters band, MCU:",
                          str(b160) + " Radio#:", radio, "N1MM Antenna#:", ant)
                if 349999 < freq < 400000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b80.value(1)
                    band = '80'
                    print(band + " meters band, MCU:",
                          str(b80) + " Radio#:", radio, "Antenna#:", ant)
                if 533050 < freq < 540350:
                    band = '60'

                if 699999 < freq < 730000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b40.value(1)
                    band = '40'
                    print(band + " meters band, MCU:",
                          str(b40) + " Radio#:", radio, "Antenna#:", ant)
                if 1010000 < freq < 1015000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b30.value(1)
                    band = '30'
                    print(band + " meters band, MCU:",
                          str(b30) + " Radio#:", radio, "Antenna#:", ant)
                if 1399999 < freq < 1435000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b20.value(1)
                    band = '20'
                    print(band + " meters band, MCU:",
                          str(b20) + " Radio#:", radio, "Antenna#:", ant)
                if 1806799 < freq < 1816800:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b17.value(1)
                    band = '17'
                    print(band + " meters band, MCU:",
                          str(b17) + " Radio#:", radio, "Antenna#:", ant)
                if 2099999 < freq < 2145000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b15.value(1)
                    band = '15'
                    print(band + " meters band, MCU:",
                          str(b15) + " Radio#:", radio, "Antenna#:", ant)
                if 2489000 < freq < 2499000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b12.value(1)
                    band = '12'
                    print(band + " meters band, MCU:",
                          str(b12) + " Radio#:", radio, "Antenna#:", ant)
                if 2696500 < freq < 2740500:
                    band = 'C.B. Band'
                if 2799999 < freq < 2970000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b10.value(1)
                    band = '10'
                    print(band + " meters band, MCU:",
                          str(b10) + " Radio#:", radio, "Antenna#:", ant)
                if 4999999 < freq < 5400000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b6.value(1)
                    band = '6'
                    print(band + " meters band, MCU:",
                          str(b6) + " Radio#:", radio, "Antenna#:", ant)
                if 14399999 < freq < 14800000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b2.value(1)
                    band = '2'
                    print(band + " meters band, MCU:",
                          str(b2) + " Radio#:", radio, "Antenna#:", ant)
                if 42000000 < freq < 45000000:
                    b160.value(0),b80.value(0),b40.value(0),b30.value(0),b20.value(0),b17.value(0),\
                    b15.value(0),b12.value(0),b10.value(0),b6.value(0),b2.value(0),b70.value(0)
                    b70.value(1)
                    band = '70c'
                    print(band + " meters band, MCU:",
                          str(b70) + " Radio#:", radio, "Antenna#:", ant)
                #Display outside the ham bands
                if 3000 < freq < 27900:
                    band = 'Long Wave '
                if 27999 < freq < 150000:
                    band = 'Medium Wave '
                if 150000 <freq< 179999 or 200001 <freq< 349999 or 400001 <freq< 533049 \
                    or 540351 <freq< 699999 or 730001 <freq< 1009999 or 1015001 <freq< 1400000 \
                     or 1435001 <freq< 1806800 or 1816800 <freq< 2100000 or 2145000 <freq< 2489000 \
                      or 2499000 <freq <2696500 or 2740500 <freq< 2800000 or 2970001 <freq< 3000000:
                    band = 'ShortWave  '
                if 3000001 < freq < 4999999 or 5400001 < freq < 30000001:
                    band = 'VHF       '
                if freq > 30000001:
                    band = 'UHF       '

                if ant == 2:
                    #Position 1
                    AnT = 'LONG WIRE'
                    Pin2.on()
                    sleep(0.1)
                    Pin4.on()
                    sleep(0.1)
                    Pin5.on()

                if ant == 0:
                    #Position 2
                    AnT = 'BEAM'
                    Pin2.off()
                    sleep(0.1)
                    Pin4.off()
                    sleep(0.1)
                    Pin5.on()

                if ant == 1:
                    #Position 3
                    AnT = '40m DIPOLE'
                    Pin2.off()
                    sleep(0.1)
                    Pin4.on()
                    sleep(0.1)
                    Pin5.on()

                if ant == 3:
                    #Position 4
                    AnT = 'DUMMY LOAD'
                    Pin2.off()
                    sleep(0.1)
                    Pin4.off()
                    sleep(0.1)
                    Pin5.off()

                # OLED initialization for boot time information
                i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=400000)
                oled.fill(0)
                oled.text('Band: ' + str(band) + ' mtrs', 0, 0)
                oled.text('Ant: ' + AnT, 0, 20, 1)
                #Uncoment the line below if you want more information in auto mode
                #Make sure you coment out the RSSI line 230, 231
                #Frequency information on the OLED, too crowded for me
                #oled.text('Frq: '+ str(freq), 0, 10)
                oled.show()
    except OSError:
        print('Error')
        oled.fill(0)
        oled.text('N1MM server down', 1, 1, 1)
        oled.text('...rebooting', 0, 20, 1)
        oled.show()
        sleep(1)
        autoAntenna()
示例#17
0
 def create_helpers(self):
     self.led = Pin(self.LED, Pin.OUT)
     self.i2c = SoftI2C(scl=Pin(self.OLED_SCL), sda=Pin(self.OLED_SDA))
     self.oled = OLED(self.i2c)
示例#18
0
#导入相关模块
import mpu6050,time
from machine import SoftI2C,Pin
from tftlcd import LCD43M


#定义常用颜色
WHITE=(255,255,255)
BLACK = (0,0,0)

#初始化LCD
d=LCD43M()
d.fill(WHITE)#填充白色

#MPU6050初始化,这里使用软件I2C
i2c = SoftI2C(sda=Pin("B9"), scl=Pin("B8"))
accelerometer = mpu6050.accel(i2c)

#显示标题
d.printStr('01Studio MPU6050', 40, 10, BLACK, size=4)

while True:

    #获取传感器信息
    value=accelerometer.get_values()

    #显示加速度数据
    d.printStr('Ac-X:'+str(value["AcX"]), 10, 100, BLACK, size=4)
    d.printStr('Ac-Y:'+str(value["AcY"]), 10, 150, BLACK, size=4)
    d.printStr('Ac-Z:'+str(value["AcZ"]), 10, 200, BLACK, size=4)
示例#19
0
 I have tested a few methods for setting up the I2C object. Only the software I2C worked, as used below.
 
 Course:
 MicroPython with the ESP32
 https://techexplorations.com

'''

from machine import Pin, SoftI2C  #I2C
import SSD1306  # Works with the SSD1315
from time import sleep

# ESP32 Pin assignment
#i2c = I2C(scl=Pin(25), sda=Pin(26), freq=400000)  # Gives deprecation warning
#i2c = I2C(1)  # Does not work
i2c = SoftI2C(scl=Pin(25), sda=Pin(26),
              freq=400000)  # Using software I2C WORKS

oled_width = 128
oled_height = 64
oled = SSD1306.SSD1306_I2C(oled_width, oled_height, i2c)

while True:
    oled.fill(0)
    oled.text('Welcome', 0, 0)
    oled.text('OLED Display', 0, 10)
    oled.text('line 3', 0, 20)
    oled.text('line 4', 0, 30)
    oled.show()
    sleep(1)
    oled.fill(1)
    oled.show()
示例#20
0
 Don't forget to save the library file (bme280_float.py) in the root directory of your ESP32, alongside
 this test file. If you are using a BME280 module similar to mine, its default address will be 0x76. This is
 what the library expects. If not, provide its actual address in the third parameter of the constructor.

 You can search for other sensor drivers: https://awesome-micropython.com/

 Course:
 MicroPython with the ESP32
 https://techexplorations.com

'''

from machine import SoftI2C, Pin, Timer
import bme280_float as bme280

i2c = SoftI2C(scl=Pin(22), sda=Pin(4), freq=400000)

bme = bme280.BME280(
    i2c=i2c, mode=bme280.BME280_OSAMPLE_8,
    address=bme280.BME280_I2CADDR)  # Works ok with explicit settings
#bme = bme280.BME280(i2c=i2c)  # Also works ok, defaults.


def read_sensor_isr(event):
    print(bme.values)
    print("")
    print("Temp: ", bme.values[0], ", Pressure: ", bme.values[1],
          ", Humidity: ", bme.values[2])


blink_timer = Timer(1)
 def __init__(self, sda_pin=15, scl_pin=16):
     self.i2c = SoftI2C(sda=Pin(sda_pin), scl=Pin(scl_pin))
     self.oled = SSD1306_I2C(128, 64, self.i2c, addr=0x3c)
     self.init_display()
示例#22
0
from machine import SoftI2C, Pin
import network
import ipstw
import time
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=1000000)
print(i2c.scan())

wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi = wifi.scan()

w = ipstw.IPSTW()
w.begin()

w.fill(0)
w.text("WiFi=%d " % len(wifi), 0, 0 * 8)
w.show()

if (len(wifi) > 3):
    w.sound(1000, 0.1)
    w.sound(1000, 0.1)
    w.sled(0, (10, 0, 0))
    w.sled(1, (0, 10, 0))
    w.sled(2, (0, 0, 10))
    time.sleep(0.5)
else:
    w.sound(1000, 1)

w.sled(0, (10, 0, 0))
w.sled(1, (0, 10, 0))
w.sled(2, (0, 0, 10))
示例#23
0
from third_party import string
from third_party import rsa
from umqtt.simple import MQTTClient
from ubinascii import b2a_base64

from sgp30 import SGP30
from config import *

from restapi import RestApi

sta_if = network.WLAN(network.STA_IF)
epoch_offset = 946684800

## sgp30 setup
i2c = SoftI2C(scl=Pin(device_config['scl']),
              sda=Pin(device_config['sda']),
              freq=100000)
sgp30 = SGP30(i2c)
sgp30.initialise_indoor_air_quality()

## neopixel
np = NeoPixel(Pin(device_config['led']), 1)

if app_config['audio']:
    ## audio setup
    SAMPLES_PER_SECOND = 11025

    audio_out = I2S(I2S.NUM0,
                    bck=Pin(device_config['bck']),
                    ws=Pin(device_config['ws']),
                    sdout=Pin(device_config['sdout']),
示例#24
0
from machine import SoftI2C, UART, Pin
import ssd1306  #引入ssd1306模块,ssd1306.py
import re

i2c = SoftI2C(sda=Pin(15), scl=Pin(16))
#设置I2C的SDA与SCL所在的引脚

oled = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c)
#创建一个ssd1306.SSD1306_I2C类的对象,初始化并设置屏幕像素,i2c引脚,i2c地址

uart1 = UART(1, tx=17, rx=18)
#选择UART接口,指定TX与RX使用的引脚

uart1.init(115200, bits=8, parity=None, stop=1)
#初始化,设置波特率,设置字符位数,设置奇偶校验,设置停止位

while True:
    uart1.any()  #检索是否收到信息,否则返回0,是则返回信息
    if not uart1.any() == 0:
        oled.fill(0)
        read = uart1.read()
        print(read)
        only_text = re.sub('\r' + '\n', ' ', read)
        oled.text(only_text, 0, 32)
        #设置在屏幕中将要显示的文字内容,设置起始像素点坐标
        oled.show()
        #将内容输出到oled屏幕上
示例#25
0
from machine import SoftI2C, Pin
from time import sleep
from APDS9960LITE import APDS9960LITE

# Initialise I2C bus
i2c = SoftI2C(scl=Pin("PB13"), sda=Pin("PB14"))
# Initialise APDS9960
apds9960 = APDS9960LITE(i2c)    # Create APDS9960 sensor object
apds9960.prox.enableSensor()    # Send I2C command to enable sensor
sleep(0.1)    # Let sensor measurement stabilise before starting loop
while True:
    proximity_measurement = apds9960.prox.proximityLevel    # Read the proximity
    # ...value
    print(proximity_measurement)    # Print proximity value
    sleep(0.2)    # Wait for measurement to be ready
示例#26
0
    print("Configuring OLED.")
    
    # configure OLED display
    oled_width = 128
    oled_height = 64
    # OLED reset pin
    i2c_rst = Pin(16, Pin.OUT)
    # Initialize the OLED display
    i2c_rst.value(0)
    time.sleep(0.010)
    i2c_rst.value(1) # must be held high after initialization
    # Setup the I2C lines
    i2c_scl = Pin(15, Pin.OUT, Pin.PULL_UP)
    i2c_sda = Pin(4, Pin.OUT, Pin.PULL_UP)
    # Create the bus object
    i2c = SoftI2C(scl=i2c_scl, sda=i2c_sda)
    # Create the display object
    oled = SSD1306_I2C(oled_width, oled_height, i2c)
    oled.fill(0)
    oled.text('Samim SmartHome', 0, 10)
    oled.text('LoRaMQTTDev '+str(DEV_VER), 0, 20)
    oled.show()
    print("OLED configured")

if module_config['module_type']=='ESP32':
    print("Configuring ESP32.")
    device_spi = SoftSPI(baudrate = 10000000, 
            polarity = 0, phase = 0, bits = 8, firstbit = SoftSPI.MSB,
            sck = Pin(device_config['sck'], Pin.OUT, Pin.PULL_DOWN),
            mosi = Pin(device_config['mosi'], Pin.OUT, Pin.PULL_UP),
            miso = Pin(device_config['miso'], Pin.IN, Pin.PULL_UP))
示例#27
0
    if data < 0:  # NEC protocol sends repeat codes.
        print('Repeat code.')
    else:
        print('Data {:02x} Addr {:04x}'.format(data, addr))
        pBt.encoderChange = pBt.ENCODER_PUSH
    if data == 0x99:
        pBt.level += 2
    if data == 0x9a:
        pBt.level -= 2


test(1)

ir = NEC_16(Pin(39, Pin.IN), IR_Callback)

i2c = SoftI2C(scl=Pin(15), sda=Pin(4))

oleRz = Pin(16, Pin.OUT)
oleRz.value(0)
sleep(0.05)
oleRz.value(1)
oled_with = 128
oled_hight = 64
oled = SSD1306_I2C(oled_with, oled_hight, i2c)
lin_hight = 9
col_with = 8


def text_write(text, lin, col):
    oled.text(text, col * col_with, lin * lin_hight)
示例#28
0
spi.write_readinto(b"1234", buf)  # write to MOSI and read from MISO into the buffer
spi.write_readinto(buf, buf)  # write buf to MOSI and read MISO back into buf

# Hardware SPI
from machine import Pin, SPI

hspi = SPI(1, 10000000)
hspi = SPI(1, 10000000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
vspi = SPI(2, baudrate=80000000, polarity=0, phase=0, bits=8, firstbit=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19))


# Software I2C

from machine import Pin, SoftI2C

i2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=100000)

i2c.scan()  # scan for devices

i2c.readfrom(0x3A, 4)  # read 4 bytes from device with address 0x3a
i2c.writeto(0x3A, "12")  # write '12' to device with address 0x3a

buf = bytearray(10)  # create a buffer with 10 bytes


# Hardware I2C bus

from machine import Pin, I2C

i2c = I2C(0)
i2c = I2C(1, scl=Pin(5), sda=Pin(4), freq=400000)
示例#29
0
from machine import Pin, SoftI2C
from sh1106 import SH1106, SH1106_I2C

from menu import MainMenu

from time import sleep
from time import time

import config

#
# Create Display
#
i2c: SoftI2C = SoftI2C(scl=Pin(22), sda=Pin(21), freq=400000)
config.DISPLAY = SH1106_I2C(128, 64, i2c, addr=0x3c)
config.DISPLAY.sleep(False)

#
# Create Menu
#
config.MAIN_MENU = MainMenu(config.DISPLAY)

# Updates values on main menu
config.delay(config.delay())
config.blob(config.blob())
config.active(config.active())

# Impoprt pin listeners
import pinListener
示例#30
0
# With the ESP32 you can set almost any pin to have I2C capabilities.
# You just need to set that in your code.

from machine import Pin, SoftI2C
from time import sleep
import ssd1306
import BME280

i2c_oled = SoftI2C(scl=Pin(32), sda=Pin(33))
i2c_sensor = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000)

oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c_oled)

counter = 0
temp_sum = 0
hum_sum = 0
pres_sum = 0

while True:
    try:
        #         GET DATA FROM SENSOR AS STRING
        bme = BME280.BME280(i2c=i2c_sensor)
        temp_string = bme.temperature
        hum_string = bme.humidity
        pres_string = bme.pressure

        #         SHOW ON OLED SCREEN
        oled.fill(0)
        if temp_string != '0.00C':