- 6 штук OLED Display с SPI интерфейсом, AtMega 1284P (arduino)
- GPS
- RTC PCF8563
- GY-87 MPU6050 HMC5883L BMP180 Модуль
- Потихоньку программируем. (Github)
Архив рубрики: Новости
Arduino + ATmega2560
TFT 2.8″ Example for pygame
import pygame
import os
from time import sleep
import RPi.GPIO as GPIO
#Note #21 changed to #27 for rev2 Pi
button_map = {23:(255,0,0), 22:(0,255,0), 21:(0,0,255), 18:(0,0,0)}
#Setup the GPIOs as inputs with Pull Ups since the buttons are connected to GND
GPIO.setmode(GPIO.BCM)
for k in button_map.keys():
GPIO.setup(k, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#Colours
WHITE = (255,255,255)
os.putenv('SDL_FBDEV', '/dev/fb1')
pygame.init()
pygame.mouse.set_visible(False)
lcd = pygame.display.set_mode((320, 240))
lcd.fill((0,0,0))
pygame.display.update()
font_big = pygame.font.Font(None, 100)
while True:
# Scan the buttons
for (k,v) in button_map.items():
if GPIO.input(k) == False:
lcd.fill(v)
text_surface = font_big.render('%d'%k, True, WHITE)
rect = text_surface.get_rect(center=(160,120))
lcd.blit(text_surface, rect)
pygame.display.update()
sleep(0.1)
import os
from time import sleep
import RPi.GPIO as GPIO
#Note #21 changed to #27 for rev2 Pi
button_map = {23:(255,0,0), 22:(0,255,0), 21:(0,0,255), 18:(0,0,0)}
#Setup the GPIOs as inputs with Pull Ups since the buttons are connected to GND
GPIO.setmode(GPIO.BCM)
for k in button_map.keys():
GPIO.setup(k, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#Colours
WHITE = (255,255,255)
os.putenv('SDL_FBDEV', '/dev/fb1')
pygame.init()
pygame.mouse.set_visible(False)
lcd = pygame.display.set_mode((320, 240))
lcd.fill((0,0,0))
pygame.display.update()
font_big = pygame.font.Font(None, 100)
while True:
# Scan the buttons
for (k,v) in button_map.items():
if GPIO.input(k) == False:
lcd.fill(v)
text_surface = font_big.render('%d'%k, True, WHITE)
rect = text_surface.get_rect(center=(160,120))
lcd.blit(text_surface, rect)
pygame.display.update()
sleep(0.1)
TouchScreen
import pygame
from pygame.locals import *
import os
from time import sleep
import RPi.GPIO as GPIO
#Setup the GPIOs as outputs - only 4 and 17 are available
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)
#Colours
WHITE = (255,255,255)
os.putenv('SDL_FBDEV', '/dev/fb1')
os.putenv('SDL_MOUSEDRV', 'TSLIB')
os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')
pygame.init()
pygame.mouse.set_visible(False)
lcd = pygame.display.set_mode((320, 240))
lcd.fill((0,0,0))
pygame.display.update()
font_big = pygame.font.Font(None, 50)
touch_buttons = {'17 on':(80,60), '4 on':(240,60), '17 off':(80,180), '4 off':(240,180)}
for k,v in touch_buttons.items():
text_surface = font_big.render('%s'%k, True, WHITE)
rect = text_surface.get_rect(center=v)
lcd.blit(text_surface, rect)
pygame.display.update()
while True:
# Scan touchscreen events
for event in pygame.event.get():
if(event.type is MOUSEBUTTONDOWN):
pos = pygame.mouse.get_pos()
print pos
elif(event.type is MOUSEBUTTONUP):
pos = pygame.mouse.get_pos()
print pos
#Find which quarter of the screen we're in
x,y = pos
if y < 120:
if x < 160:
GPIO.output(17, False)
else:
GPIO.output(4, False)
else:
if x < 160:
GPIO.output(17, True)
else:
GPIO.output(4, True)
sleep(0.1)
from pygame.locals import *
import os
from time import sleep
import RPi.GPIO as GPIO
#Setup the GPIOs as outputs - only 4 and 17 are available
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)
#Colours
WHITE = (255,255,255)
os.putenv('SDL_FBDEV', '/dev/fb1')
os.putenv('SDL_MOUSEDRV', 'TSLIB')
os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')
pygame.init()
pygame.mouse.set_visible(False)
lcd = pygame.display.set_mode((320, 240))
lcd.fill((0,0,0))
pygame.display.update()
font_big = pygame.font.Font(None, 50)
touch_buttons = {'17 on':(80,60), '4 on':(240,60), '17 off':(80,180), '4 off':(240,180)}
for k,v in touch_buttons.items():
text_surface = font_big.render('%s'%k, True, WHITE)
rect = text_surface.get_rect(center=v)
lcd.blit(text_surface, rect)
pygame.display.update()
while True:
# Scan touchscreen events
for event in pygame.event.get():
if(event.type is MOUSEBUTTONDOWN):
pos = pygame.mouse.get_pos()
print pos
elif(event.type is MOUSEBUTTONUP):
pos = pygame.mouse.get_pos()
print pos
#Find which quarter of the screen we're in
x,y = pos
if y < 120:
if x < 160:
GPIO.output(17, False)
else:
GPIO.output(4, False)
else:
if x < 160:
GPIO.output(17, True)
else:
GPIO.output(4, True)
sleep(0.1)
OLED Display 0.96″ I2C/SPI 128 X 64
Разрешение: 128*64
Угол обзора: > 160 градусов
Ультра-низким энергопотреблением: 0.08 Вт
Рабочее напряжение: 3-5 Вольт
Рабочая температура: от-30 до 70 градусов Цельсия
Размер: 27.0 мм * 27.0 мм * 4.1 мм
I2c/интерфейс
SSD1306
Arduino Library. (backup download:OLED_I2C)
SPI
Библиотеки для микроконтроллеров (Arduino, и.т.д.)
u8glib – https://code.google.com/p/u8glib/
Для Arduino
D/C =>11, RST=>13,SDA=>9,SCL=10
U8GLIB_SSD1306_128X64 u8g(10, 9, 12, 11,13);
12=Не подключаем.
VCC = 3.3v !!! ( На этом модуле нет преобразователя 3.3в )
U8GLIB_SSD1306_128X64 u8g(10,9,12,11,13); // Arduino Fio