コード例 #1
0
 def __init__(self):
     self.i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)  #i2c settings
     self.display = sh1106.SH1106_I2C(
         128, 64, self.i2c, Pin(16),
         0x3c)  #Load the driver and set it to "display"
     self.bme = BME280(i2c=self.i2c)  #sensor function
     self.pump = PWM(Pin(14), freq=0,
                     duty=0)  #create PWM objekt and configure pump forward
     #self.pump_reverse = PWM(Pin(12), freq=0, duty=0) #create PWM objekt and configure pump backwards
     #self.button = Pin(0, Pin.IN, Pin.PULL_UP) #initialize button
     self.adc = ADS1115(
         self.i2c, self.addr, self.gain
     )  #create analog-digtial converter object to read analog humidity sensor
     self.time_start = ticks_ms() / 1000  #Sekunden
     self.autosetinterval = ticks_ms() / 1000 + 25200  #counter
     self.time_current = 0
     self.time_start = 0
     self.reset = 0
     self.epoche = 0
     self.water_storage = 1.2
     #self.water_use = 0
     #self.water_status = True
     self.button = Pin(0, Pin.IN, Pin.PULL_UP)
     #self.button.irq(trigger=Pin.IRQ_FALLING, handler=self.handle_interrupt)
     self.soil_dry = 20000  #CSensor >20000 /Annahme Test offen
     self.soil_ok = 15000  #CSensor 15000 bis 10000 /Annahme Test offen
     self.soil_humid = 10000  #CSensor 250 - bis 10000 /Annahme Test offen
     self.soil_humidity = None
     self.activateAndClearDisplay()
コード例 #2
0
 def __init__(self):
     self.i2c = I2C(scl=Pin(16), sda=Pin(17), freq=400000)
     self.display = sh1106.SH1106_I2C(128, 64, self.i2c, Pin(16), 0x3c)
     self.display.sleep(False)
     self.display.rotate(True, update=True)
     self.refresh()
     self.y_values = [1, 11, 21, 31, 41, 51]
     self.menu_options = list()
コード例 #3
0
ファイル: oled.py プロジェクト: meigrafd/ESP32_Klingel
 def __init__(self, freq=400000):
     # ValueError: Pins 16&17 cannot be used if SPIRAM is used
     RST = machine.Pin(0)
     SDA = machine.Pin(settings.SDA)
     SCL = machine.Pin(settings.SCL)
     self.i2c = machine.I2C(scl=SCL, sda=SDA, freq=freq)
     if 60 in set(self.i2c.scan()):
         self.display = sh1106.SH1106_I2C(settings.oledtype[0], settings.oledtype[1], self.i2c, RST, 0x3c)
         self.display.sleep(False)
         self.display.fill(0)
         self.display.rotate(True)
コード例 #4
0
def testOled():
    from machine import I2C, Pin
    import sh1106

    i2c = I2C(scl=Pin(SCL), sda=Pin(SDA), freq=400000)
    display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c)

    display.fill(0)
    display.text('Hello', 0, 0)
    display.text('World', 0, 10)
    display.rotate(True)
    display.show()
コード例 #5
0
ファイル: gamerGorl.py プロジェクト: bpwagner/GamerGorl
    def __init__(self):

        wemos_d1_pins = {
            'D0': 16,  # GPIO
            'D1': 5,  # GPIO, I2C SCL
            'D2': 4,  # GPIO, I2C SDA
            'D3': 0,  # GPIO
            'D4': 2,  # GPIO
            'D5': 14,  # GPIO, SPI SCK (Serial Clock)
            'D6': 12,  # GPIO, SPI MISO (Master in, Slave out)
            'D7': 13,  # GPIO, SPI MOSI (Master out, Slave in)
            'D8': 15,  # GPIO, SPI SS (Slave select)
            'A0': 0,  # Analog in, via ADC
            'RX': 3,  # Receive
            'TX': 1  # Transmit
        }

        # Game pins
        self.Buzzer = wemos_d1_pins['D8']
        self.Neo = wemos_d1_pins['D4']
        self.SDA = wemos_d1_pins['D2']
        self.SCL = wemos_d1_pins['D1']
        self.X_Sel_Pin = wemos_d1_pins['D6']
        self.Y_Sel_Pin = wemos_d1_pins['D5']
        self.Joy_Sw = wemos_d1_pins['D3']
        self.A_Sw = wemos_d1_pins['D7']
        self.B_Sw = wemos_d1_pins['D3']

        self.i2c = I2C(scl=Pin(self.SCL), sda=Pin(self.SDA), freq=400000)
        self.display = sh1106.SH1106_I2C(128, 64, self.i2c, Pin(16), 0x3c)

        # button pins
        self.A = Pin(self.A_Sw, Pin.IN, Pin.PULL_UP)
        self.B = Pin(self.B_Sw, Pin.IN, Pin.PULL_UP)

        # joystick pins
        self.X_Sel = Pin(self.X_Sel_Pin, Pin.OUT)
        self.Y_Sel = Pin(self.Y_Sel_Pin, Pin.OUT)
        self.X_Sel.value(0)
        self.Y_Sel.value(0)
        self.adc = machine.ADC(wemos_d1_pins['A0'])

        #led
        self.numLEDs = 19
        self.np = NeoPixel(Pin(self.Neo), self.numLEDs)

        #sound on
        self.playSound = True
コード例 #6
0
class MyMachine:
    # physical interfaces
    i2c = None
    display = None
    bme = None
    pump = None
    pump_reverse = None
    button = None
    adc = None
    # sensor variables
    temp = None
    hum = None
    pres = None
    volt = None
    water_storage = None
    water_storage_max = 1.2
    time_current = None
    epoche = 0  #Epoche
    # fixed values
    addr = 0x48
    gain = 1
    time_start = time.ticks_ms()  #start Wert des internen Zählers
    #config
    i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)  #i2c settings
    display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16),
                                0x3c)  #Load the driver and set it to "display"
    display.sleep(False)  #activate display
    display.fill(0)  #clear display
    bme = BME280.BME280(i2c=i2c)  #sensor function
    pumpe = PWM(Pin(14), freq=0,
                duty=0)  #create PWM objekt and configure pump forward
    pumpe_reverse = PWM(
        Pin(12), freq=0,
        duty=0)  #create PWM objekt and configure pump backwards
    button = Pin(0, Pin.IN, Pin.PULL_UP)  #initialize button
    addr = 0x48
    gain = 1
    adc = ads1x15.ADS1115(
        i2c, addr, gain
    )  #create analog-digtial converter object to read analog humidity sensor
    i = 0
    start = time.ticks_ms()  #start Wert des internen Zaehlers
    autosetinterval = 25200  #counter
    reset = 0  #reset for time counter
コード例 #7
0
ファイル: main.py プロジェクト: BoKKeR/CryptoTicker.Software
    def scanner(self):
        display_a = {}  #Left for PCB testing

        multiplexer_channel = 0
        while multiplexer_channel != 8:

            self.change_channel(multiplexer_channel)
            channel = multiplexer_channel

            try:
                disp = sh1106.SH1106_I2C(128, 64, i2c, None, 0x3c)
                state = 1
            except Exception:
                state = 0
            global displays
            displays.append(Xdisplay(channel, state))
            display_a.update({multiplexer_channel:
                              state})  #Left for PCB testing
            multiplexer_channel += 1

        print(display_a)
        return display_a
コード例 #8
0
def display_temperature_and_humidity(temperature, humidity, use_normal_text):

    # Note: This is conditionally imported to save memory.
    #       Since we are running a bunch of different processes
    #       (measuring using sensors, using wifi, sending data
    #       to cloud, showing data in the display), all those
    #       together made ESP8266 run out of memory when calling
    #       the cloud API to send data. Since the custom font
    #       processing is one of the most "memory consuming"
    #       process, we use it only if we are not sending data
    #       to cloud. If we do, we use normal text in the display
    #
    if not use_normal_text:
        # Import required libraries
        import freesans20
        import writer

    # Initialize I2C interface using the setup display pins
    i2c = machine.I2C(scl=machine.Pin(config.DISPLAY_SCL_PIN),
                      sda=machine.Pin(config.DISPLAY_SDA_PIN),
                      freq=400000)

    # Display detected?
    if 60 not in i2c.scan():
        print('Cannot find display')
        raise RuntimeError('Cannot find display')

    # For SSD1306 OLED Display
    # display = ssd1306.SSD1306_I2C(128, 64, i2c)

    # For SH1106 OLED Display
    display = sh1106.SH1106_I2C(128, 64, i2c, machine.Pin(16), 0x3c)

    # Custom font writer
    font_writer = None
    if not use_normal_text:
        font_writer = writer.Writer(display, freesans20)

    # Load PBM images
    temperature_pbm = load_image('temperature.pbm')
    units_pbm = load_image(
        'fahrenheit.pbm' if config.FAHRENHEIT else 'celsius.pbm')
    humidity_pbm = load_image('humidity.pbm')
    percent_pbm = load_image('percent.pbm')

    # Clean display content
    display.fill(0)

    # -------- V0 --------

    # Prepare text information using 16 pixels per line x 4 lines
    # Use formating ({:^16s}) to center text

    # Temperature (lines 1 & 2)
    # display.text('{:^16s}'.format('Temperature:'), 0, 0)
    # display.text('{:^16s}'.format(str(temperature) +
    #                              ('F' if config.FAHRENHEIT else 'C')), 0, 16)
    # Humidity (lines 3 & 4)
    # display.text('{:^16s}'.format('Humidity:'), 0, 32)
    # display.text('{:^16s}'.format(str(humidity) + '%'), 0, 48)

    # -------- V1 --------

    # Draw a rectangle along the display borders
    display.rect(0, 0, 128, 64, 1)

    # Draw a line in the middle to separate things
    display.line(64, 0, 64, 64, 1)

    # Draw temperature symbol
    display.blit(temperature_pbm, 24, 4)

    # Draw humidity symbol
    display.blit(humidity_pbm, 88, 4)

    # Draw units symbol
    display.blit(units_pbm, 28, 52)

    # Draw percent symbol
    display.blit(percent_pbm, 92, 52)

    # Format current temperature using custom fonts
    text = '{:.1f}'.format(temperature)

    if use_normal_text:
        # Use normal text
        display.text(text, (34 - len(text)) // 2, 30)
    else:
        # Use custom fonts
        textlen = font_writer.stringlen(text)
        font_writer.set_textpos((64 - textlen) // 2, 30)
        font_writer.printstring(text)

    # Format current humidity using custom fonts
    text = '{:.1f}'.format(humidity)

    if use_normal_text:
        # Use normal text
        display.text(text, 64 + (34 - len(text)) // 2, 30)
    else:
        # Use custom fonts
        textlen = font_writer.stringlen(text)
        font_writer.set_textpos(64 + (64 - textlen) // 2, 30)
        font_writer.printstring(text)

    # Show content
    print('Showing content in the display')
    display.rotate(config.DISPLAY_ROTATE)
    display.show()

    # Wait 10 seconds
    print('Waiting 10 seconds before display power off')
    time.sleep(10)

    # Power off display
    print('Powering off display')
    display.poweroff()
コード例 #9
0
            lowBeep()
        display.text(str(BPressed), 0, 10)
        display.text(str(JoyX), 0, 20)
        display.text(str(JoyY), 0, 30)
        print(str(JoyX) + "\t" + str(JoyY))
        display.pixel(JoyX // 20 + 50, JoyY // 20, 1)
        display.rotate(True)
        display.show()
        count = count + 1


if __name__ == '__main__':
    #setup the variables

    i2c = I2C(scl=Pin(SCL), sda=Pin(SDA), freq=400000)
    display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c)

    #button pins
    A = Pin(A_Sw, Pin.IN, Pin.PULL_UP)
    B = Pin(B_Sw, Pin.IN, Pin.PULL_UP)

    #joystick pins
    X_Sel = Pin(X_Sel_Pin, Pin.OUT)
    Y_Sel = Pin(Y_Sel_Pin, Pin.OUT)
    X_Sel.value(0)
    Y_Sel.value(0)
    adc = machine.ADC(wemos_d1_pins['A0'])

    #testOled()
    #testNeoPixels()
    #playSong()
コード例 #10
0
'''

from machine import I2C, Timer, Pin
import sh1106
import bme280_float as bme280
from time import sleep
import network, utime
import ujson as json
import uP_-_14_40_-_oled_bme_280_IFTTT_modules as modules

led = Pin(21, Pin.OUT)

i2c = I2C(0)

display = sh1106.SH1106_I2C(128, 64, i2c, None, 0x3c)

bme = bme280.BME280(   i2c=i2c,
                       mode=bme280.BME280_OSAMPLE_8,
                       address=bme280.BME280_I2CADDR ) # Works ok with explicity settings

with open("/wifi_settings_ifttt.json") as credentials_json:   # This pattern allows you to open and read an existing file.
    settings = json.loads(credentials_json.read())

url = "https://maker.ifttt.com/trigger/uPython/with/key/" + settings["ifttt_key"]

wlan = network.WLAN(network.STA_IF) # This will create a station interface object.
                                    # To create an access point, use AP_IF (not covered here).


def timer_isr(event):
コード例 #11
0
from adafruit_seesaw.digitalio import DigitalIO
from adafruit_seesaw.rotaryio import IncrementalEncoder

import sh1106

def showit():
    display.fill(0)
    display.text("Position: {}".format(rposition),12,32,1)
    display.text("Position: {}".format(lposition),12,43,1)
    display.show()

# Create the I2C interface.
i2c = busio.I2C(SCL, SDA,frequency=400000)


display = sh1106.SH1106_I2C(128,64,i2c)
rightseesaw = Seesaw(i2c, addr=0x37)
leftseesaw = Seesaw(i2c, addr=0x38)

right = IncrementalEncoder(rightseesaw)
left = IncrementalEncoder(leftseesaw)

last_rposition = 0
last_lposition = 0
rposition = 0
lposition = 0
showit()

while True:
    dirty = False
    # read position of the rotary encoder
コード例 #12
0
ファイル: test.py プロジェクト: MattHum/plantcontrol
import sh1106 #display lib
from time import sleep
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) #i2c settings
display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c) #Load the driver and set it to "display"
display.sleep(False) #activate display
display.fill(0) #clear display
temp = 1
hum = 2
pres = 3
volt = 3
Hallo world

def display_output(): #print to display
  display.rotate(flag=1) #rotate display 180°
  display.fill(0)
  display.text('HOT: ' + str(temp), 0, 1)
  display.text('AIR: ' + str(hum), 0, 15)
  display.text('PRES: ' + str(pres), 0, 30)
  display.text('HUMI: ' + str(volt), 0, 45)
  display.show()

while True: #main body
  display_output() #calls function to print data to display
  sleep(60)
コード例 #13
0
import machine
import uos
import sh1106
import utime
from machine import I2C, Pin, ADC

adc = machine.ADC(0)
i2c = I2C(scl=Pin(12), sda=Pin(14))
oled = sh1106.SH1106_I2C(128, 64, i2c)

while True:
    for _ in range(500):
        x = int(uos.urandom(1)[0] / 2)
        y = int(uos.urandom(1)[0] / 4)
        oled.pixel(x, y, 1)
    oled.show()
    utime.sleep_ms(200)
    oled.fill(0)
コード例 #14
0
ファイル: simon.py プロジェクト: jlennox/PicoPi
]

buzzer = machine.PWM(machine.Pin(28))

displayi2c = machine.I2C(1,
                         sda=machine.Pin(2),
                         scl=machine.Pin(3),
                         freq=800000)

# The display connects over I2C. The display has a command based language implemented
# on it's display controller chip (SH1106). Thankfully someone already wrote a MicrPython
# driver for it.
# https://github.com/robert-hh/SH1106
displayWidth = micropython.const(128)
displayHeight = micropython.const(64)
display = sh1106.SH1106_I2C(displayWidth, displayHeight, displayi2c, None, 60)
display.init_display()
display.contrast(255)
display.rotate(True)
display.invert(True)
display.poweron()


# Displays 2 rows of text centered on the screen.
def displayScore(label, wut):
    # Blank out the old pixels
    display.fill(0)

    # Each character is 8 pixels wide. Since we want half that (we're centering)
    # then we * 4 instead of * 8.
    display.text(label, int(displayWidth / 2) - len(label) * 4, 30 - 6, 1)
コード例 #15
0
hSize = 64  # display heigh in pixels
wSize = 128  # display width in pixels

temp = 0  # temperature from BME280
pres = 0  # atmospheric pressure from BME280
humi = 0  # humidity from BME280

temp_out = 0  # outside temperature via mqtt

# init ic2 object
#display_show('I2C Init...')
i2c = machine.I2C(scl=machine.Pin(pinScl), sda=machine.Pin(pinSda))
#display_show('OK')

# init display
display = sh1106.SH1106_I2C(128, 64, i2c, machine.Pin(16), 0x3c)
display_switch = 'ON'


def display_show(message):
    display.fill(0)
    display.text(str(message), 0, 20, 1)
    display.show()
    time.sleep_ms(1000)


display_show('HELLO! =)')

# mqtt messaged frequency
msg_frq = 60  # every 1 minute
now_mqtt = time.time()
コード例 #16
0
ファイル: main.py プロジェクト: BoKKeR/CryptoTicker.Software
 def __init__(self, orientation=0):
     for display in displays:
         if display.state == 1:
             multiplex.change_channel(display.channel)
             display.driver = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c)
コード例 #17
0
ファイル: boot.py プロジェクト: Luca8991/RemoteGaber
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
import uos, machine, sh1106
#uos.dupterm(None, 1) # disable REPL on UART(0)
import gc
#import webrepl
#webrepl.start()
gc.collect()

import network

import json

i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
oled = sh1106.SH1106_I2C(128, 64, i2c, None, 0x3c)

SSID = "<your-ssid>"
PWD = "<your-pwd>"

with open("params.json", "r") as r:
    params = json.load(r)

    SSID = params["wifi"]["ssid"]
    PWD = params["wifi"]["password"]

oled.fill(0)
oled.text("connecting to:", 0, 0)
oled.text(SSID, 0, 10)
oled.rotate(True)
oled.show()
コード例 #18
0
* Author(s): Kevin Neubauer
"""
import board
import busio
import sh1106
import time
import framebuf

WHITE = 1
BLACK = 0
SCRWIDTH = 128
SCRHEIGHT = 64

#initialize screen over I2C
i2c = busio.I2C(board.SCL, board.SDA)
display = sh1106.SH1106_I2C(SCRWIDTH, SCRHEIGHT, i2c, addr=0x3c)


class VirtualPetFramebuf:
    def __init__(self, intWidth, intHeight):
        self.height = intHeight
        self.width = intWidth
        bufsize = self.width * self.height // 8
        buf = bytearray(bufsize)
        for x in range(bufsize):
            buf[x] = 0
        self.framebuf = framebuf.FrameBuffer(buf, self.width, self.height,
                                             framebuf.MONO_VLSB)

    #function that takes 0 and 1 contents from a string and populates a framebuffer object
    def setContentsFromString(self, strBits, x_origin=0, y_origin=0):
コード例 #19
0
    'D4': 2,  # GPIO
    'D5': 14,  # GPIO, SPI SCK (Serial Clock)
    'D6': 12,  # GPIO, SPI MISO (Master in, Slave out)
    'D7': 13,  # GPIO, SPI MOSI (Master out, Slave in)
    'D8': 15,  # GPIO, SPI SS (Slave select)
    'A0': 0,  # Analog in, via ADC
    'RX': 3,  # Receive
    'TX': 1  # Transmit
}

# Setup the I2C for the display and initialize
i2c = I2C(-1,
          sda=Pin(wemos_d1_pins["D2"]),
          scl=Pin(wemos_d1_pins["D5"]),
          freq=400000)
display = sh1106.SH1106_I2C(dwidth, dheight, i2c, Pin(16), 0x3c)

# Setup wifi and connect
wlan = network.WLAN(network.STA_IF)  # Set wifi to station mode
wlan.active(True)  # Mark the interface as active
wlan.scan()  # Scan for access points (may not be needed)
wlan.connect(wifissid, wifipsk)  # connect to the AP configured above

# TODO: Should probably loop here waiting until wlan.isconnected() is True.
#       Maybe display wifi status, maybe attempt to reconnect.

# For loading files and debugging in a browser, otherwise use ampy
#import webrepl
#webrepl.start()