# clear all VRAM def clrvram(): for i in range(8): vram[i] = 0 from machine import Pin, SPI import time cs = Pin(22, Pin.OUT) spi = SPI(0, baudrate=10000000, bits=8, polarity=0, phase=0, mosi=Pin(3), sck=Pin(2)) # Initialize MAX7219 x8 putled64(0x0c, 0x0101010101010101) # Not Shutdown Mode putled64(0x09, 0x0000000000000000) # No Decode Mode putled64(0x0a, 0x0505050505050505) # Set Brighteness putled64(0x0b, 0x0707070707070707) # Scan All LEDs vram = [0, 0, 0, 0, 0, 0, 0, 0] g = 40 #gravity while True: h = 0 while h < 64 * 256:
from st7789py import color565 as c565 ap_if = network.WLAN(network.AP_IF) ap_if.active(True) #ap_if.config(essid="\U0001F4A9", password="******") ap_if.config(essid="Epstein_Didn't_Kill_Himself", password="******") sta_if = network.WLAN(network.STA_IF) sta_if.active(False) #sta_if.connect("NTA2019", "notroll2019") gpios = [32, 33, 25] pins = [Pin(i, Pin.OUT) for i in gpios] Pin(4, Pin.OUT).value(1) spi = SPI(2, sck=Pin(18), mosi=Pin(19), miso=Pin(23), baudrate=20*1000*1000, polarity=1, phase=0) spi2 = SPI(1, sck=Pin(21), mosi=Pin(13), miso=Pin(12), baudrate=20*1000*1000, polarity=0, phase=0) display = st7789.ST7789( spi, 135, 240, reset=Pin(23, Pin.OUT), dc=Pin(16, Pin.OUT), cs = Pin(5, Pin.OUT) ) display.start_x = 52 display.start_y = 40 def blink_leds(): while True:
check_busy() check_SYS_FFC() # AGC if v_mode=='L': enable_AGC() #VSYNC data=bytearray([0,5,0,0]) c=write_data((0x800,0x54),data) #IRQ activation p4.irq(handler=get_frame,trigger=Pin.IRQ_RISING) #SPI at 20 MHz , the max according to the Lepton documentation vspi=SPI(2,baudrate=20000000,polarity=1,phase=1,sck=Pin(18),mosi=Pin(23), miso=Pin(19)) cs=Pin(5,Pin.OUT) cs.value(1) utime.sleep_ms(186) if c==0: pw2.deinit() p2.value(1) deadline = utime.ticks_add(utime.ticks_ms(), TIMEOUT) #/CS asserted cs.value(0) while (utime.ticks_diff(deadline, utime.ticks_ms()) > 0):
# Change Logs: # Date Author Notes # 2019-06-13 SummerGift first version # from machine import Pin, SPI PIN_CLK = 26 # PB10, get the pin number from get_pin_number.py PIN_MOSI = 27 # PB11 PIN_MISO = 28 # PB12 clk = Pin(("clk", PIN_CLK), Pin.OUT_PP) # Select the PIN_CLK pin device as the clock mosi = Pin(("mosi", PIN_MOSI), Pin.OUT_PP) # Select the PIN_MOSI pin device as the mosi miso = Pin(("miso", PIN_MISO), Pin.IN) # Select the PIN_MISO pin device as the miso spi = SPI(-1, 500000, polarity=0, phase=0, bits=8, firstbit=0, sck=clk, mosi=mosi, miso=miso) print(spi) spi.write("hello rt-thread!") spi.read(10)
def main(): ''' The big show! ''' #enable display and clear screen spi = SPI(1, baudrate=31250000, sck=Pin(18), mosi=Pin(19)) tft = st7789.ST7789( spi, 320, 240, reset=Pin(4, Pin.OUT), cs=Pin(13, Pin.OUT), dc=Pin(12, Pin.OUT), backlight=Pin(15, Pin.OUT), rotation=1) tft.fill(st7789.BLACK) # clear screen height = tft.height # height of display in pixels width = tft.width # width if display in pixels tfa = 0 # top free area when scrolling bfa = 0 # bottom free area when scrolling scroll = 0 # scroll position wheel = 0 # color wheel position tft.vscrdef(tfa, width, bfa) # set scroll area tft.vscsad(scroll + tfa) # set scroll position tft.fill(st7789.BLACK) # clear screen half = (height >> 1) - 1 # half the height of the dislay interval = 0 # steps between new points increment = 0 # increment per step counter = 1 # step counter, overflow to start current_y = 0 # current_y value (right point) last_y = 0 # last_y value (left point) # segment offsets x_offsets = [x * (width // 8) -1 for x in range(2,9)] while True: # when the counter exceeds the interval, save current_y to last_y, # choose a new random value for current_y between 0 and 1/2 the # height of the display, choose a new random interval then reset # the counter to 0 if counter > interval: last_y = current_y current_y = random.randint(0, half) counter = 0 interval = random.randint(10, 100) increment = 1/interval # increment per step # clear the first column of the display and scroll it tft.vline(scroll, 0, height, st7789.BLACK) tft.vscsad(scroll + tfa) # get the next point between last_y and current_y tween = int(between(last_y, current_y, counter * increment)) # draw mirrored pixels across the display at the offsets using the color_wheel effect for i, x_offset in enumerate(x_offsets): tft.pixel((scroll + x_offset) % width, half + tween, color_wheel(wheel+(i<<2))) tft.pixel((scroll + x_offset) % width, half - tween, color_wheel(wheel+(i<<2))) # increment scroll, counter, and wheel scroll = (scroll + 1) % width wheel = (wheel + 1) % 256 counter += 1
TFT_CS_PIN = const(13) TFT_RST_PIN = const(14) TFT_DC_PIN = const(15) fonts = [glcdfont, tt14, tt24, tt32] text = 'Hello Raspberry Pi Pico/ili9341' print(text) print("fonts available:") for f in fonts: print(f.__name__) spi = SPI(0, baudrate=40000000, miso=Pin(TFT_MISO_PIN), mosi=Pin(TFT_MOSI_PIN), sck=Pin(TFT_CLK_PIN)) print(spi) display = ILI9341(spi, cs=Pin(TFT_CS_PIN), dc=Pin(TFT_DC_PIN), rst=Pin(TFT_RST_PIN), w=SCR_WIDTH, h=SCR_HEIGHT, r=SCR_ROT) display.erase() display.set_pos(0, 0)
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from machine import Pin, SPI from gd import * import os import urandom # on recent MicroPython Firmware v1.10+ from time import sleep_ms from math import sqrt # Initialize the SPI Bus (on ESP8266-EVB) # Software SPI # spi = SPI(-1, baudrate=4000000, polarity=1, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12)) # Hardware SPI spi = SPI(2) # MOSI=Y8, MISO=Y7, SCK=Y6, SS=Y5 spi.init( baudrate=20000000, phase=0, polarity=0 ) # raise @ 20 Mhz # We must manage the SS signal ourself ss = Pin( Pin.board.Y5, Pin.OUT ) # Gameduino Lib gd = Gameduino( spi, ss ) gd.begin() os.chdir( '/sd' ) f_woodpic = open( 'Wood32_pic.bin', 'rb' ) # === Toolbox ================================================================== QROOK = 0 QKNIGHT = 1
def update( self ): """ Call it as often as possible to detect key pressed / key released """ # Read the current state self.read( store=1 ) for key in range( self.reader_count * 12 ): # Key state has changed? (pressed or release) if self.touched[key] != self.touched[key+(self.reader_count*12)]: self.debug( "Key %i is %s" %(key,"PRESSED" if self.touched[key]>0 else "Released") ) if self.on_key_change: self.on_key_change( key, pressed=(self.touched[key]>0) ) # remember the current state as last state self.touched[key+(self.reader_count*12)]=self.touched[key] # Create SPI bus for AD9833 spi = SPI(2, baudrate=9600, polarity=1, phase=0) i2c = I2C(2) # create organ & add voices organ = Organ( spi=spi, debug=True ) organ.add_voice( "Y2" ) # Add or remove depending on available voices organ.add_voice( "Y3" ) organ.add_voice( "Y4" ) organ.add_voice( "Y5" ) organ.clear_all() def keyboard_changed( key, pressed ): """ This will be called when a key is pressed or released """ global organ # Key from 0 to 7 are for corresponding notes in NOTES if 0<= key < len(KEYS):
# Nokia 5110 import pcd8544, framebuf # Temp sensor import dht12 # Initialise I2C for temp sensor i2c = I2C(scl=Pin(0), sda=Pin(2), freq=20000) i2c.scan() # should see sensor at [92] dht = dht12.DHT12(i2c) # Initialise SPI for display spi = SPI(1, baudrate=80000000, polarity=0, phase=0) cs = Pin(2) dc = Pin(15) rst = Pin(0) # backlight on bl = Pin(12, Pin.OUT, value=1) lcd = pcd8544.PCD8544(spi, cs, dc, rst) # Initialise framebuffer for display buffer = bytearray((lcd.height // 8) * lcd.width) framebuf = framebuf.FrameBuffer1(buffer, lcd.width, lcd.height) # Update display while(True):
import ssd1306 import sh1106 import gfx import utime from shapes3d import sphere, cube from machine import I2C, Pin, SPI oled_reset_pin = Pin(16, Pin.OUT) hspi = SPI(1, 10000000, sck=Pin(18), mosi=Pin(23), miso=Pin(19)) display1 = sh1106.SH1106_SPI(128, 64, hspi, dc=Pin(26), res=oled_reset_pin, cs=Pin(5)) display2 = sh1106.SH1106_SPI(128, 64, hspi, dc=Pin(33), res=oled_reset_pin, cs=Pin(2)) utime.sleep(1) display1.sleep(False) display1.rotate(1) display2.sleep(False) display2.rotate(1)
Example for 7.5 inch black & white Waveshare E-ink screen, V2 Run on ESP32 """ import epaper7in5_V2 from machine import Pin, SPI # SPIV on ESP32 sck = Pin(18) # CLK miso = Pin(19) # mosi = Pin(23) # DIN dc = Pin(32) # DC cs = Pin(33) # Chip Select rst = Pin(19) # RST busy = Pin(35) # BUSY spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=sck, miso=miso, mosi=mosi) e = epaper7in5_V2.EPD(spi, cs, dc, rst, busy) e.init() w = 800 h = 480 x = 0 y = 0 # -------------------- # use a frame buffer # 400 * 300 / 8 = 15000 - thats a lot of pixels import framebuf buf = bytearray(w * h // 8)
from machine import SPI, Pin import time # SPI bus init ssel = Pin(18, Pin.OUT) ssel.value(1) spi = SPI(1, baudrate=20000000, bits=8, sck=Pin(5, Pin.OUT), mosi=Pin(19, Pin.OUT), miso=Pin(4, Pin.IN), firstbit=SPI.MSB) # Write function def transaction(tx): ssel.value(False) # Select FPGA SPI device rx = bytearray([0]*len(tx)) spi.write_readinto(tx, rx) ssel.value(True) # De-select FPGA SPI device return rx def runTest(val): data = None for i in range(16):#0x100): prevData = data led = 1<<(i%8) if not (i>>3)&1 else 1<<(7-i%8) data = bytearray([led,val]) result = transaction(data) if prevData and not result == prevData: print("Test failed, expected {} got {}.".format(prevData, result)) return False time.sleep(0.01) first = False return True tests = 0
def main(): ''' Draw on screen using focaltouch sensor ''' try: # Turn on display backlight axp = axp202c.PMU() axp.enablePower(axp202c.AXP202_LDO2) # initialize display spi port spi = SPI(1, baudrate=32000000, polarity=1, phase=0, bits=8, firstbit=0, sck=Pin(18, Pin.OUT), mosi=Pin(19, Pin.OUT)) # configure display tft = st7789.ST7789(spi, 240, 240, cs=Pin(5, Pin.OUT), dc=Pin(27, Pin.OUT), backlight=Pin(12, Pin.OUT), rotation=2) # enable display and clear screen tft.init() tft.fill(st7789.BLACK) tft.text(font, "Draw", 104, 1, st7789.WHITE) # enable focaltouch touchscreen touch_i2c = SoftI2C(scl=Pin(32), sda=Pin(23)) touch = focaltouch.FocalTouch(touch_i2c) color_index = 0 color = 0 # draw color swatches used to select color to draw for color_index, color in enumerate(COLORS): tft.fill_rect(color_index * 30, 210, 30, 30, color) add_highlight(tft, color_index) while True: # can be up to two touches if touch.touched == 1: # get x and y points of the first touch p_x = touch.touches[0]['x'] p_y = touch.touches[0]['y'] # If point is in the lowest 30 rows of the screen # change color to swatch pressed. if p_y > 209: # remove highlight from around previous color swatch remove_highlight(tft, color_index, color) # update new color color_index = p_x // 30 color = COLORS[color_index] add_highlight(tft, color_index) else: # draw the pixel - would be better with lines tft.pixel(p_x, p_y, color) finally: # shutdown spi spi.deinit() # turn off display backlight axp.disablePower(axp202c.AXP202_LDO2)
# Released under the MIT licence from vs1053_syn import * from machine import SPI, Pin from pyb import Switch # For cancellation import time import os switch = Switch() # 128K conversion # ffmpeg -i yellow.flac -acodec libmp3lame -ab 128k yellow.mp3 # VBR conversion # ffmpeg -i yellow.flac -acodec libmp3lame -qscale:a 0 yellow.mp3 # Yeah, I know. I like Coldplay... spi = SPI(2) # 2 MOSI Y8 MISO Y7 SCK Y6 reset = Pin('Y5', Pin.OUT, value=1) # Active low hardware reset xcs = Pin('Y4', Pin.OUT, value=1) # Labelled CS on PCB, xcs on chip datasheet sdcs = Pin('Y3', Pin.OUT, value=1) # SD card CS xdcs = Pin('Y2', Pin.OUT, value=1) # Data chip select xdcs in datasheet dreq = Pin('Y1', Pin.IN) # Active high data request player = VS1053(spi, reset, dreq, xdcs, xcs, sdcs=sdcs, mp='/fc', cancb=lambda: switch()) player.patch() # Optional. From /fc/plugins
#sdin_pin = Pin(26) audio_out = I2S(I2S.NUM0, bck=bck_pin, ws=ws_pin, sdin=sdin_pin, standard=I2S.PHILIPS, mode=I2S.MASTER_RX, dataformat=I2S.B32, channelformat=I2S.ONLY_RIGHT, samplerate=SAMPLES_PER_SECOND * 2, dmacount=8, dmalen=256) Pin(18, Pin.OUT, value=1) spi = SPI(sck=Pin(23), mosi=Pin(12), miso=Pin(14)) try: sd = sdcard.SDCard(spi, Pin(2, Pin.OUT)) vfs = uos.VfsFat(sd) uos.mount(vfs, "/sd") except Exception as e: oled.fill(0) oled.text("error al montar sd", 4, 12) oled.show() audio_out.deinit() spi.deinit() raise e s = open('/sd/mic_recording.wav', 'wb') s.write(wav_header)
import machine, sdcard, os from machine import SPI, Pin #sd = sdcard.SDCard(SPI(-1, sck=Pin(14), mosi=Pin(13), miso=Pin(12)), Pin(15)) sd = sdcard.SDCard(SPI(2, sck=Pin(18), mosi=Pin(23), miso=Pin(19)), Pin(15)) os.mount(sd, '/sd') os.listdir('/sd')
# Smiley Screen Saver # Move a bitmap around, bounce it off walls like an old screensaver # VCC GND STM32F407ZGT6 from machine import Pin, SPI spi = SPI(2) spi.init(baudrate=2000000, polarity=0, phase=0) cs = Pin('B12', Pin.OUT) rst = Pin('B11', Pin.OUT) bl = Pin('B1', Pin.OUT, value=1) # backlight on # with framebuffer import hx1230_fb lcd = hx1230_fb.HX1230_FB_SPI(spi, cs, rst) # smiley 15x15 col major msb first - see smiley.gif import framebuf smiley = bytearray( b'\xE0\x38\xE4\x22\xA2\xE1\xE1\x61\xE1\x21\xA2\xE2\xE4\x38\xE0\x03\x0C\x10\x21\x21\x41\x48\x48\x48\x49\x25\x21\x10\x0C\x03' ) smiley_w = 15 smiley_h = 15 smiley_fbuf = framebuf.FrameBuffer(smiley, smiley_w, smiley_h, framebuf.MONO_VLSB) # area the smiley can move in bounds_w = lcd.width - smiley_w bounds_h = lcd.height - smiley_h # direction smiley is moving move_x = 1
from test1 import * from machine import Pin, SPI import mfrc522 spi = SPI(miso=Pin(19), mosi=Pin(21, Pin.OUT), sck=Pin(22, Pin.OUT)) rst_pin = Pin(4, Pin.OUT) sda_pin = Pin(23, Pin.OUT) rfid = mfrc522.MFRC522(spi, rst_pin, sda_pin) data1 = set_name('001') data = data1 + bytes(7) + set_value(20.0) rfid.write_card(data)
# interessante functies # 2017-0522 PePo initial setup import max7219 from machine import Pin, SPI from time import sleep # setup: #LoLin32: MOSI=23, MISO=19, SCK=18, CC=15 (my selection) spi = SPI(-1, 10000000, miso=Pin(19), mosi=Pin(23), sck=Pin(18)) display = max7219.Matrix8x8(spi, Pin(15)) # function segmenten(): zet de 'letters' per stuk aan/uit # elke 'letter' bestaat uit 8-segmenten (x-variabele). # Er zijn 8 'letters' (y-variabele). De telling is van rechts naar links def segmenten(on=True, wt=0.1): # voor elke 'letter' for x in range(8): # elke segment in de 'letter' for y in range(8): display.pixel(y, x, on) # 'letter' y, 'segment' x display.show() sleep(wt) # show some things with the whole strip segmenten(False, 0) #immediately segmenten(True, 0) segmenten(False, 0.4) # slow motion
def setup(self): mylib.collectMemory() # SPI FOR TFT/OV7670 FIFO self.hspi = SPI(1, baudrate=HSPI_BAUDRATE, polarity=0, phase=0, sck=Pin(TFT_SPI_SCK), mosi=Pin(TFT_SPI_MOSI), miso=Pin(TFT_SPI_MISO)) # # setup TFT Unit # self.tft = self.TFT_setup(self.hspi, TFT_DC, TFT_RESET, TFT_CS) # # SPI FOR SD Card # self.vspi = SPI(2, baudrate=VSPI_BAUDRATE, polarity=1, phase=0, sck=Pin(SD_SPI_SCK), mosi=Pin(SD_SPI_MOSI), miso=Pin(SD_SPI_MISO)) # # setup SD Unit # self.sd = self.SD_setup(self.vspi, SD_CS) if self.sd is None: self.stat_sd = False else: self.stat_sd = True mylib.wlan_connect(SSID, PASS) self.stat_ntp = mylib.ntp_setup() mylib.collectMemory() if self.stat_sd and self.stat_ntp: mylib.setupSDFileSystem(self.sd) else: print("Initialization failed, so skip setupSDFileSystem()") mylib.collectMemory() # # setup ImageSensor(OV7670) Unit # self.ov7670 = OV7670(I2C_SCL, I2C_SDA) self.stat_ov7670 = self.ov7670.getStatus() # setup FIFO if self.stat_ov7670: self.ov7670.setupFIFO(self.hspi, FIFO_VSYNC, FIFO_RDCLK, FIFO_WE, FIFO_RRST, FIFO_WRST, FIFO_PL) # setup shutter button and IRQ self.shutter = Pin(SHUTTER_BUTTON, Pin.IN) # 36 is assigned for ShutterButton self.shutter.irq(trigger=Pin.IRQ_FALLING, handler=self.cb_shutterPressed) return self.stat_sd and self.stat_ntp and self.stat_ov7670
def init_spi(self): self.spi=SPI(self.spi_channel, baudrate=self.spi_freq, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, sck=Pin(self.gpio_sck), mosi=Pin(self.gpio_mosi), miso=Pin(self.gpio_miso)) self.cs=Pin(self.gpio_cs,Pin.OUT) self.cs.off() self.led=Pin(self.gpio_led,Pin.OUT) self.led.off()
# simple basic example - ESP32 + 7segment display print("--- octopusLAB: test_display7.py ---") print("-> imports") from time import sleep from machine import Pin, SPI from utils.pinout import set_pinout from components.display7 import Display7 print("-> spi-init") pinout = set_pinout() spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(pinout.SPI_CLK_PIN), mosi=Pin(pinout.SPI_MOSI_PIN)) ss = Pin(pinout.SPI_CS0_PIN, Pin.OUT) #spi.deinit() #print("spi > close") print("-> display7-init") d7 = Display7(spi, ss) # 8 x 7segment display init d7.write_to_buffer('octopus') d7.display() sleep(3) print("-> display7-test") for i in range(6): d7.show(5 - i) sleep(0.5)
# # Test the print() function available on the driver. # The print() function relies on the FontDrawer and the font file veram_m15.bin # (available on the FreeType_generator Project located at # https://github.com/mchobby/freetype-generator ) # # See also the "test_fdrawer.py" offering better performance. # # In this sample we will: # * Use the font drawer on the ILI934x driver # from machine import SPI, Pin from ili934x import * # PYBStick config (idem with PYBStick-Feather-Face) spi = SPI(1, baudrate=40000000) cs_pin = Pin("S15") dc_pin = Pin("S13") rst_pin = None # r in 0..3 is rotation, r in 4..7 = rotation+miroring # Use 3 for landscape mode lcd = ILI9341(spi, cs=cs_pin, dc=dc_pin, rst=rst_pin, w=320, h=240, r=0) lcd.erase() lcd.font_name = 'veram_m15' # Use the inner print() statement if tge driver lcd.print("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 1234567890") #lcd.color = GREEN lcd.print("Lorem ipsum dolor sit amet, consectetur adipiscing elit.") #lcd.color = BLUE
from ST7735 import Display, color565 import cmath from nanogui import DObject, Label, Pointer, polar, conj, refresh # Fonts import fonts.arial10 as arial10 from writer import Writer, CWriter import utime import uos sck = Pin(18) miso = Pin(19) mosi = Pin(23) SPI_CS = 26 SPI_DC = 5 spi = SPI(2, baudrate=32000000, sck=sck, mosi=mosi, miso=miso) ADC_PIN = 34 st7735 = Display(spi, SPI_CS, SPI_DC) adc = ADC(Pin(ADC_PIN)) # create ADC object on ADC pin 34 adc.atten(ADC.ATTN_11DB) # This gives us max value at ~ 3.3V refresh(st7735) GREEN = color565(0, 255, 0) RED = color565(255, 0, 0) BLUE = color565(0, 0, 255) YELLOW = color565(255, 255, 0) BLACK = 0 CWriter.set_textpos(st7735, 0, 0) # In case previous tests have altered it wri = CWriter(st7735, arial10, GREEN, BLACK, verbose=False)
# OLDE连线示意,ESP8266开发板 # SCK ---> D5 ---> 14 # MOSI --> D6 ---> 12 # MIOS --> Null-->任意没有用的 # DC --> D8 ---> 15 # RES --> D7 ---> 13 # CS --> Null-->本次使用6针没有该引脚,指定一个空引脚即可 # 根据上面的连线,定义各个IO接口变量 SCK = Pin(14, Pin.OUT) MOSI = Pin(12, Pin.OUT) MISO = Pin(0) DC = Pin(15) RES = Pin(13) CS = Pin(16) # 初始化SPI对象,sck,mosi,miso 三个参数是必须的 spi = SPI(sck=SCK, mosi=MOSI, miso=MISO) # 初始化OLED对象,128*64 是屏幕的分辨率,所谓的大小 oled = SSD1306_SPI(128, 64, spi, dc=DC, res=RES, cs=CS) # 打开SPI通道 oled.poweron() # 初始化OLED显示 oled.init_display() with open('Micropython-logo.pbm', 'r') as f: f.readline() width, height = [int(v) for v in f.readline().split()] data = bytearray(f.read()) f.close() fbuf = framebuf.FrameBuffer(data, width, height, framebuf.MONO_HLSB) # oled.invert(1) oled.fill(0)
# Test the PBM reading on the SPI_LCD12864 LCD graphical screen 128x64 # # bpm & img libraries: https://github.com/mchobby/esp8266-upy/tree/master/FILEFORMAT/imglib # lcd12864 library: https://github.com/mchobby/esp8266-upy/tree/master/lcdspi-lcd12864/lib # mpy.pbm : image bitmap of older MicroPython logo # # LCD12864 hardware: https://shop.mchobby.be/fr/gravity-boson/1878-afficheur-lcd-128x64-spi-3-fils-3232100018785-dfrobot.html # from machine import SPI, Pin from lcd12864 import SPI_LCD12864 from img import open_image # PYBStick: S19=mosi, S23=sck, S26=/ss cs = Pin( 'S26', Pin.OUT, value=0 ) spi = SPI( 1 ) spi.init( polarity=0, phase=1 ) # Pico: GP7=mosi, GP6=sck, GP5=/ss #cs = Pin( 5, Pin.OUT, value=0 ) #spi = SPI( 0 ) #spi.init( polarity=0, phase=1 ) # PYBOARD: Y8=mosi, Y6=sck, Y5=/ss #cs = Pin( 'Y5', Pin.OUT, value=0 ) #spi = SPI( 2 ) #spi.init( polarity=0, phase=1 ) lcd = SPI_LCD12864( spi=spi, cs=cs ) # texte à X=10, Y=25, couleur=1 (trait) #lcd.text( "MicroPython !", 10, 25, 1 )
wlan.active(True) wlan.disconnect() wlan.connect(ssid, passwd) while (wlan.ifconfig()[0] == '0.0.0.0'): time.sleep(1) try: socket.getaddrinfo('dfrobot.com', 80)[0][4][0] except: print('can NOT connect to internet') return False return True spi = SPI(baudrate=100000, polarity=1, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12)) sd = sdcard.SDCard(spi, Pin(16)) os.umount() tmp = os.VfsFat(sd, "sd") if (connectWifi('rd', 'hidfrobot5353') == True): s = http_get('http://202.58.105.240/test.json') s = s[s.find('\r\n\r\n') + 4:] cfg = ujson.loads(s) f = open("config.json", "rw+") f.write(ujson.dumps(cfg)) f.close() print("get config file from internet") else:
except: S_DC = 'P10' S_MOSI = 'P11' S_MISO = 'P14' # SSD defaults try: from Config import S_DC, S_RES, S_CS # GPIO SSD pins except: S_DC = 'P5' S_RES = 'P6' S_CS = 'P7' # SSD default pins from machine import SPI print( 'Oled SPI: DC ~> %s, CS ~> %s, RST ~> %s, D1/MOSI ~> %s, D0/CLK ~> %s' % (S_DC, S_CS, S_RES, S_MOSI, S_CLKI)) spi = SPI(0, SPI.MASTER, baudrate=100000, pins=(S_CLKI, S_MOSI, S_MISO)) oled = SSD1306.SSD1306_SPI(width, height, spi, S_DC, S_RES, S_CS) else: oled = None print("Incorrect display bus %s" % useSSD) if oled: oled.fill(1) oled.show() sleep_ms(1000) oled.fill(0) oled.show() except Exception as e: oled = None print('Oled display failed: %s' % e)
sck = Pin(25) mosi = Pin(33) miso = Pin(32) cs = Pin(26, Pin.OUT) #reset=Pin(13) led = Pin(13, Pin.OUT) resetNum = 27 spi = SPI(1, baudrate=5000000, sck=sck, mosi=mosi, miso=miso) rfm9x = RFM9x(spi, cs, resetNum, 915.0) OLED_CURRENTLINE = OLED_CURRENTLINE + OLED_LINESKIP oled.text("Radio works;", 0, OLED_CURRENTLINE) oled.show() # wrap up OLED_CURRENTLINE = OLED_CURRENTLINE + OLED_LINESKIP oled.text("... oh, yeah.", 0, OLED_CURRENTLINE)
__DEBUG__ = True print("Setting TTNconfig") ttn_config = TTN(ttn_config['devaddr'], ttn_config['nwkey'], ttn_config['app'], country=ttn_config['country']) print("TTN Country:", TTN.country) print("Setting device_spi") device_spi = SPI(device_config['spi_unit'], baudrate=10000000, polarity=0, phase=0, bits=8, firstbit=SPI.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)) print("Setting lora") lora = SX127x(device_spi, pins=device_config, lora_parameters=lora_parameters, ttn_config=ttn_config) frame_counter = 0 def on_receive(lora, outgoing): payload = lora.read_payload()