def __init__(self): print("[DISP] Initialized") # Create ST7735 LCD display class self.st7735 = ST7735.ST7735(port=0, cs=ST7735.BG_SPI_CS_FRONT, dc=9, backlight=25, rotation=270, spi_speed_hz=4000000) # Initialize display self.st7735.begin() self.WIDTH = self.st7735.width self.HEIGHT = self.st7735.height # Set up canvas and font self.img = Image.new('RGBA', (self.WIDTH, self.HEIGHT), color=(0, 0, 0)) self.draw = ImageDraw.Draw(self.img) self.font_size_small = 10 self.font_size_medium = 15 self.font_size_large = 20 self.largefont = ImageFont.truetype(UserFont, self.font_size_large) self.smallfont = ImageFont.truetype(UserFont, self.font_size_small) self.mediumfont = ImageFont.truetype(UserFont, self.font_size_medium)
def __init__(self): # Create ST7735 LCD display class self.__lcd = ST7735.ST7735(port=0, cs=1, dc=9, backlight=12, rotation=270, spi_speed_hz=10000000) self.__lcd.begin() self.__image = Image.new('RGB', (self.__lcd.width, self.__lcd.height), color=(0, 0, 0)) self.__draw = ImageDraw.Draw(self.__image) path = os.path.dirname(os.path.realpath(__file__)) self.__font = ImageFont.truetype(path + "/fonts/Asap/Asap-Bold.ttf", 20) self.__smallfont = ImageFont.truetype( path + "/fonts/Asap/Asap-Bold.ttf", 10) self.__message = "" # The position of the top bar self.__top_pos = 25
def test_setup(GPIO, spidev, numpy): force_reimport('ST7735') import ST7735 display = ST7735.ST7735(port=0, cs=0, dc=24) del display GPIO.output.assert_has_calls( [mock.call(24, True), mock.call(24, False)], any_order=True)
def test_display(GPIO, spidev, numpy): force_reimport('ST7735') import ST7735 display = ST7735.ST7735(port=0, cs=0, dc=24) numpy.dstack().flatten().tolist.return_value = [0xff, 0x00, 0xff, 0x00] display.display(mock.MagicMock()) spidev.SpiDev().xfer3.assert_called_with([0xff, 0x00, 0xff, 0x00])
def test_setup(): sys.modules['numpy'] = mock.Mock() sys.modules['spidev'] = mock.Mock() sys.modules['RPi'] = mock.Mock() sys.modules['RPi.GPIO'] = mock.Mock() import ST7735 display = ST7735.ST7735(port=0, cs=0, dc=24) del display
def __init__(self): self.st7735 = ST7735.ST7735(port=0, cs=ST7735.BG_SPI_CS_BACK, dc=25, backlight=24, rst=27, rotation=90, spi_speed_hz=4000000) self.st7735.begin()
def initlcd(): global disp, draw disp = TFT.ST7735(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=SPEED_HZ)) disp.begin() draw = disp.draw() disp.display( Image.open('pi0toChroma.jpg').rotate(90).resize((WIDTH, HEIGHT)))
def test_128_64_0(GPIO, spidev, numpy): force_reimport('ST7735') import ST7735 display = ST7735.ST7735(port=0, cs=0, dc=24, width=128, height=64, rotation=0) assert display.width == 128 assert display.height == 64
def test_128_64_90(): _mock() import ST7735 display = ST7735.ST7735(port=0, cs=0, dc=24, width=128, height=64, rotation=90) assert display.width == 64 assert display.height == 128
def lcd_init(self): self.disp = ST7735.ST7735( port=0, cs=1, dc=9, backlight=12, rotation=270, spi_speed_hz=10000000 ) # Initialize display. self.disp.begin()
def __init__(self): self.csPins = [14, 15, 23, 7] self.gpio = GPIO.get_platform_gpio() for p in self.csPins: self.gpio.setup(p, GPIO.OUT) self.disp = TFT.ST7735(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=SPEED_HZ)) self.selectAllScreens() self.disp.begin() self.clearAll()
def __init__(self, font): # Create LCD instance self.disp = ST7735.ST7735(port=0, cs=ST7735.BG_SPI_CS_FRONT, dc=9, backlight=12, rotation=270, spi_speed_hz=10000000) # Initialize display self.disp.begin() self.WIDTH = self.disp.width self.HEIGHT = self.disp.height self.font = font
def __init__(self, bgcolor=COLOR_WHITE): self.spi = SPI.SpiDev(SPI_PORT, SPI_CH, max_speed_hz=SPI_SPEED) self.disp = TFT.ST7735(dc=AOPIN, rst=RSTPIN, spi=self.spi, width=TFT_WIDTH, height=TFT_HEIGHT) self.disp.begin() self.clear() self.bgcolor = bgcolor self.img = Image.new('RGB', TFT_SIZE, bgcolor) self.draw = ImageDraw.Draw(img) self.font = FONT_1 self.color = COLOR_BLACK
def create_display(): # Create TFT LCD display driver disp = ST7735.ST7735(TFT_RS, rst=TFT_RST, spi=SPI.SpiDev(TFT_SPI_PORT, TFT_SPI_DEVICE, max_speed_hz=TFT_SPEED_HZ), width=TFT_WIDTH, height=TFT_HEIGHT) # Initialize display, clear the buffer to white, write buffer to screen disp.begin() disp.clear((0, 0, 0)) disp.display() return disp
def initlcd(): """Initilize the lcd's.""" global disp, draw print 'initializing LCD' disp = TFT.ST7735(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=SPEED_HZ)) # setup SPI port disp.begin() # start screen class disp.display( Image.open('pi0toChroma.jpg').rotate(270).transpose( Image.FLIP_TOP_BOTTOM).resize( (WIDTH, HEIGHT))) # draw splash screen draw = disp.draw() # put splash screen on LCD's print 'LCD initialized'
def __init__(self): self.disp = ST7735.ST7735( port=0, cs=ST7735.BG_SPI_CS_FRONT, # BG_SPI_CSB_BACK or BG_SPI_CS_FRONT dc=9, backlight=12, rotation=270, spi_speed_hz=16 * 1000 * 1000 ) self.disp.begin() self.img = Image.new('RGB', (self.disp.width, self.disp.height), color=(0, 0, 0)) self.draw = ImageDraw.Draw(self.img) path = os.path.dirname(os.path.realpath(__file__)) self.font = ImageFont.truetype(path + "/fonts/Asap/Asap-Bold.ttf", 20) self.values = [1] * self.disp.width
def __init__(self): self.WIDTH = 128 self.HEIGHT = 160 self.display = TFT.ST7735(24, rst=25, spi=SPI.SpiDev(0, 0, max_speed_hz=4000000)) self.font1 = ImageFont.truetype('HelveticaBlkIt.ttf', 24) self.label_font = ImageFont.truetype('HelveticaBlkIt.ttf', 12) self.display.begin() self.signal_state = '' self.flash = False # Load an image. image = Image.open('/home/pi/Zigbee-signal-indicator/logo.jpg').rotate( 0).resize((self.WIDTH, self.HEIGHT)) self.display.display(image) self.draw = self.display.draw()
def display(var, time, runtime): # Opens the display for writing to disp = ST7735.ST7735(port=0, cs=1, dc=9, backlight=12, rotation=270, spi_speed_hz=10000000) disp.begin img = Image.new('RGB', (disp.width, disp.height), color=(0, 0, 0)) draw = ImageDraw.Draw(img) # Construct font types fontSizeHeader = 24 fontSizePara = 20 fontHeader = ImageFont.truetype("Asap-Bold.ttf", fontSizeHeader) fontPara = ImageFont.truetype("Asap-Bold.ttf", fontSizePara) # Depending on var apply traffic light colours # Currently configured for light if (var < 5): rect_colour = (0, 250, 200) text_colour = (250, 0, 200) elif (var < 9): rect_colour = (250, 190, 0) text_colour = (0, 190, 250) else: rect_colour = (250, 0, 0) text_colour = (0, 250, 250) # Output all values to the display draw.rectangle((0, 0, 160, 80), rect_colour) draw.text((0, 0), time, font=fontHeader, fill=text_colour) draw.text((disp.width / 2 - 75, disp.height / 2 - 5), "Current run time:", font=fontPara, fill=text_colour) draw.text((disp.height / 2 - 30, disp.width / 2 - 30), runtime, font=fontHeader, fill=text_colour) disp.display(img)
def test_setup_with_backlight(GPIO, spidev, numpy): force_reimport('ST7735') import ST7735 display = ST7735.ST7735(port=0, cs=0, dc=24, backlight=4) GPIO.setup.assert_called_with(4, GPIO.OUT) display.set_backlight(GPIO.HIGH) GPIO.output.assert_has_calls( [ mock.call(4, GPIO.LOW), mock.call(4, GPIO.HIGH), # Dozens of falls with True/False here # due to _init() being called and the display # setup setting the command/data pin mock.call(4, GPIO.HIGH) ], any_order=True)
def __init__(self): # BME280 temperature/pressure/humidity sensor self.bme280 = BME280() # Create ST7735 LCD display class self.st7735 = ST7735.ST7735(port=0, cs=1, dc=9, backlight=12, rotation=270, spi_speed_hz=10000000) # Initialize display self.st7735.begin() self.WIDTH = self.st7735.width self.HEIGHT = self.st7735.height # Set up canvas and font self.img = Image.new('RGB', (self.WIDTH, self.HEIGHT), color=(0, 0, 0)) self.draw = ImageDraw.Draw(self.img) self.path = os.path.dirname(os.path.realpath(__file__)) self.font_size = 20 self.font = ImageFont.truetype(UserFont, self.font_size) self.message = "" # The position of the top bar self.top_pos = 25 # Tuning factor for compensation. Decrease this number to adjust the # displayed temperature down, and increase to adjust up self.factor = 1.2 # Create a values dict to store the data self.variables = ["temperature", "light"] self.values = {} for v in self.variables: self.values[v] = [1] * self.WIDTH self.cpu_temps = [get_cpu_temperature()] * 5
def main(emulate_display=False, plugin=DEFAULT_PLUGIN): logger.info('Connecting display') if emulate_display: import display_emulator display = display_emulator.DisplayEmulator(WIDTH, HEIGHT, scale=2) else: import ST7735 as TFT import Adafruit_GPIO.SPI as SPI display = TFT.ST7735(DISPLAY_PIN_DC, rst=DISPLAY_PIN_RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=SPEED_HZ)) display.begin() frame_ui = FrameUI(WIDTH, HEIGHT) logger.info('Connecting to mod-host') mod = Mod() mod.remove_plugin(0) mod.add_plugin(0, plugin) logger.info('Connecting to JACK') jack_client = jack.Client('my_jack_client', no_start_server=False, servername=None) jack_client.activate() # logger.info('Connecting to ports') # connect_audio_midi(jack_client) logger.info('Looping') mod.render_loop(frame_ui, frame_callback=lambda image: display.display(image))
gif.py - Display a gif on the LCD. If you're using Breakout Garden, plug the 0.96" LCD (SPI) breakout into the front slot. """) if len(sys.argv) > 1: image_file = sys.argv[1] else: print("Usage: {} <filename.gif>".format(sys.argv[0])) sys.exit(0) # Create TFT LCD display class. disp = ST7735.ST7735( port=0, cs=ST7735.BG_SPI_CS_FRONT, # BG_SPI_CSB_BACK or BG_SPI_CS_FRONT dc=9, backlight=19, # 18 for back BG slot, 19 for front BG slot. spi_speed_hz=4000000) # Initialize display. disp.begin() width = disp.width height = disp.height # Load an image. print('Loading gif: {}...'.format(image_file)) image = Image.open(image_file) print('Drawing gif, press Ctrl+C to exit!')
"""all-in-one.py - Displays readings from all of Enviro plus' sensors Press Ctrl+C to exit! """) # BME280 temperature/pressure/humidity sensor bme280 = BME280() # PMS5003 particulate sensor pms5003 = PMS5003() # Create ST7735 LCD display class st7735 = ST7735.ST7735(port=0, cs=1, dc=9, backlight=12, rotation=270, spi_speed_hz=10000000) # Initialize display st7735.begin() WIDTH = st7735.width HEIGHT = st7735.height # Set up canvas and font img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0)) draw = ImageDraw.Draw(img) font_size = 20 font = ImageFont.truetype(UserFont, font_size)
SPI_DEVICE = 0 GPIO.setmode(GPIO.BCM) #we want to reference the GPIO by chip number GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) # shutter main switch is on pin 17 GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP ) # shutter preview switch is on pin 12 (halfway down) GPIO.setup(4, GPIO.OUT, initial=GPIO.HIGH) # status LED is on pin 4, turn it on GPIO.setup(16, GPIO.OUT, initial=GPIO.HIGH) # backlight control for LCD, turn it on (23?) # Create TFT LCD display class. disp = TFT.ST7735(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=SPEED_HZ)) # Initialize display disp.begin() disp.clear((0, 0, 0)) disp.display() print('Drawing logo') GPIO.output(16, 1) #turn on backlight start_time = time.time() image = Image.open('/home/pi/DLR_logo.bmp') image = image.resize((WIDTH, HEIGHT)) disp.display(image) end_time = time.time()
Install with: sudo pip3 install fonts font-roboto """) sys.exit(1) print("""analog.py This Automation HAT Mini example displays the three ADC analog input voltages numerically and as bar charts. Press CTRL+C to exit. """) # Create ST7735 LCD display class. disp = ST7735.ST7735(port=0, cs=ST7735.BG_SPI_CS_FRONT, dc=9, backlight=25, rotation=270, spi_speed_hz=4000000) # Initialise display. disp.begin() colour = (255, 181, 86) font = ImageFont.truetype(UserFont, 12) # Values to keep everything aligned nicely. text_x = 110 text_y = 34 bar_x = 25 bar_y = 37
device.display(data[n][2][i]) time.sleep(2) if __name__ == "__main__": try: imgl = [ 'eyes_v2_skyblue.gif', 'eyes_v2_light_brown.gif', 'eyes_v2_brown.gif', 'eyes_v2_indigo.gif', 'eyes_v2.gif', 'eyes_v2_love.gif', 'eyes_v2_blue.gif' ] L_eye = TFT.ST7735(rst=24, dc=25, x_offset=2, y_offset=3, rotate=180, spi=SPI.SpiDev(port=0, device=0, max_speed_hz=64 * 1000000)) R_eye = TFT.ST7735(rst=6, dc=12, x_offset=2, y_offset=3, rotate=180, spi=SPI.SpiDev(port=0, device=1, max_speed_hz=64 * 1000000)) #process간 통신을 위한 파이프 Lpup, Lsup = mp.Pipe() Rpup, Rsup = mp.Pipe()
# Setting up the display constants. WIDTH = 128 HEIGHT = 160 SPEED_HZ = 4000000 FONT_SIZE = 36 # Raspberry Pi configuration. Some basic setups and pin definitions. DC = 22 RST = 27 SPI_PORT = 0 SPI_DEVICE = 0 # Create TFT LCD display class. disp = TFT.ST7735(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=SPEED_HZ), width=WIDTH, height=HEIGHT) # Initialize display. disp.begin() # Clear the display to a red background. # Can pass any tuple of red, green, blue values (from 0 to 255 each). # disp.clear((0, 0, 0)) # Clear to a black screen. disp.clear() # Get a PIL Draw object to start drawing on the display buffer. draw = disp.draw()
GPIO.output(pin_led, GPIO.LOW) GPIO.setup(GATE_LED_PIN1, GPIO.OUT) GPIO.setup(GATE_LED_PIN2, GPIO.OUT) GPIO.output(GATE_LED_PIN1, GPIO.HIGH) #close GPIO.output(GATE_LED_PIN2, GPIO.HIGH) #close data1 = (c_uint * 288)() # data to store spectrum data data2 = (c_uint * 288)() meas = 1 black = 1 dark = 1 fnameindex = 0 # Display init spi = SPI.SpiDev(SPI_PORT, SPI_CH, max_speed_hz=SPI_SPEED) disp = TFT.ST7735(dc=AOPIN, rst=RSTPIN, spi=spi, width=128, height=128) disp.begin() disp.clear() img = Image.new('RGB', TFT_SIZE, COLOR_WHITE) draw = ImageDraw.Draw(img) font = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf" fontout = ImageFont.truetype(font, 11) draw.text((0, LINE1Y), " Mode: Measure", font=fontout, fill=COLOR_BLUE) draw.text((0, LINE2Y), " Bilirubin", font=fontout, fill=COLOR_BLUE) draw.text((0, LINE4Y), " SiO2", font=fontout, fill=COLOR_BLUE) disp.display(img) def ShowIP(): ip = subprocess.check_output(["hostname", "-I"]) ip = str(ip)
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from PIL import Image from PIL import ImageDraw from PIL import ImageFont import ST7735 # Create ST7735 LCD display class. disp = ST7735.ST7735( port=0, cs=0, dc=9, backlight=18, rotation=90, spi_speed_hz=4000000 ) # Initialize display. disp.begin() WIDTH = disp.width HEIGHT = disp.height # Clear the display to a red background. # Can pass any tuple of red, green, blue values (from 0 to 255 each). # Get a PIL Draw object to start drawing on the display buffer. img = Image.new('RGB', (WIDTH, HEIGHT), color=(255, 0, 0))
def run(dry_run=False, display=False): if dry_run: import mock_bme280 else: import smbus2 from bme280 import BME280 pass import time import sqlite3 if display: import ST7735 from PIL import Image from PIL import ImageDraw from PIL import ImageFont # Create LCD class instance. display_interface = ST7735.ST7735(port=0, cs=1, dc=9, backlight=12, rotation=270, spi_speed_hz=10000000) # Initialise the display display_interface.begin() # Width and height to calculate text position. WIDTH = display_interface.width HEIGHT = display_interface.height # New canvas to draw on. img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0)) draw = ImageDraw.Draw(img) # Text settings. # use a bitmap font font_size = 10 font = ImageFont.truetype("fonts/Asap-Bold.ttf", font_size) text_colour = (255, 255, 255) back_colour = (0, 170, 170) message = "Weather Station" size_x, size_y = draw.textsize(message, font) # Calculate text position x = (WIDTH - size_x) / 2 y = (HEIGHT / 2) - (size_y / 2) # Draw background rectangle and write text. draw.rectangle((0, 0, 160, 80), back_colour) draw.text((x, y), message, font=font, fill=text_colour) display_interface.display(img) # Initialise the BME280 if not dry_run: bus = smbus2.SMBus(1) bme280 = BME280(i2c_dev=bus) pass try: if dry_run: db_connection = sqlite3.connect('meassurements-test') else: db_connection = sqlite3.connect('meassurements') except sqlite3.Error as e: print("Database error: %s" % e) try: db_connection.execute( 'CREATE TABLE IF NOT EXISTS bme280 (id Integer primary key AUTOINCREMENT, temperature REAL, humidity REAL, pressure REAL);' ) except sqlite3.IntegrityError as e: print("Exception in _query %s" % e) while True: if dry_run: temperature = mock_bme280.get_temperature() pressure = mock_bme280.get_pressure() humidity = mock_bme280.get_humidity() else: temperature = bme280.get_temperature() pressure = bme280.get_pressure() humidity = bme280.get_humidity() if display: message = "Temperature: " + str( temperature) + "\n Pressure:" + str( pressure) + "\n Humidity: " + str(humidity) size_x, size_y = draw.textsize(message, font) # Calculate text position x = 0 y = HEIGHT # Draw background rectangle and write text. draw.rectangle((0, 0, 160, 80), back_colour) draw.text((x, y), message, font=font, fill=text_colour) display_interface.display(img) print("We use hardware") try: db_connection.execute( 'INSERT INTO bme280 (temperature, humidity, pressure) VALUES (?, ?, ?)', (temperature, humidity, pressure)) db_connection.commit() except sqlite3.IntegrityError as e: print("Exception in _query %s" % e) print("Temperature " + str(temperature)) print("Humedity: " + str(humidity)) print("Pressure: " + str(pressure)) time.sleep(5)