Skip to content

Instantly share code, notes, and snippets.

View boochow's full-sized avatar
🏠
Working from home

boochow

🏠
Working from home
View GitHub Profile
from micropython import const
from machine import Pin, I2C
import time
CLEAR_DISPLAY = const(0x01)
RETURN_HOME = const(0x02)
SET_ENTRY_MODE = const(0x04)
DISPLAY_ON = const(0x0C)
FUNCTION_SET = const(0x20)
OSC_FREQUENCY = const(0x10)
@boochow
boochow / ESP32-Micropython-HTTP-GET-sample.py
Created September 30, 2017 15:24
show current yen/dollar exchange rate on LCD
from micropython import const
from machine import Pin, I2C
import time
CLEAR_DISPLAY = const(0x01)
RETURN_HOME = const(0x02)
SET_ENTRY_MODE = const(0x04)
DISPLAY_ON = const(0x0C)
FUNCTION_SET = const(0x20)
OSC_FREQUENCY = const(0x10)
from micropython import const
from ssd1306 import SSD1306_SPI
SET_LOW_COLUMN = const(0x00)
SET_HIGH_COLUMN = const(0x10)
SET_PAGE_ADDR = const(0xb0)
SET_DISP_START_LINE = const(0x40)
class SH1106_SPI(SSD1306_SPI):
def show(self):
def main():
import network, socket
from machine import Pin
nic = network.WIZNET5K(pyb.SPI(2), Pin('PB12'), Pin('PC8'))
addr = socket.getaddrinfo('towel.blinkenlights.nl', 23)[0][-1]
s = socket.socket()
s.connect(addr)
while True:
data = s.recv(1500)
print(data.decode('utf-8'), end='')
def main():
import network, socket, ujson
from machine import Pin
nic = network.WIZNET5K(pyb.SPI(2), Pin('PB12'), Pin('PC8'))
addr = socket.getaddrinfo('api.fixer.io',80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send(bytes('GET /latest?base=USD&symbols=JPY HTTP/1.0\r\nHost: api.fixer.io\r\n\r\n', 'utf8'))
result = s.recv(1000)
s.close()
def main():
import urequests
r = urequests.get('http://api.fixer.io/latest?base=USD&symbols=JPY')
j = r.json()
print(j["date"])
print("JPY/" + j["base"] + ": " + str(j["rates"]["JPY"]))
from ST7735 import TFT,TFTColor
from machine import SPI,Pin
spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
tft=TFT(spi,16,17,18)
tft.initr()
tft.rgb(True)
tft.fill(TFT.BLACK)
minX = -2.0
maxX = 1.0
# Connect IO25 to DIN
import machine, neopixel, time
np = neopixel.NeoPixel(machine.Pin(25), 8)
for i in range(65):
np[(i + 7) % 8] = (0,0,0)
np[i % 8] = ((i * 4) % 64, (i * 8) % 64, (i * 16) % 64)
np.write()
time.sleep_ms(40)
def lan_connect(spi, cs, reset):
import network
nic = network.WIZNET5K(spi,cs,reset)
while not nic.isconnected():
pass
nic.active(True)
nic.ifconfig('dhcp')
print('network config:', nic.ifconfig())
def main():
@boochow
boochow / mac_address_from_hwid.py
Last active December 16, 2017 08:38
Ethernet MAC address from STM32 Hadware ID
import binascii
id = binascii.unhexlify("330051001551343236363539")
hash = 0x811c9dc5
for b in id:
hash = 16777619 * hash ^ b
print(hex(hash & 0x00ffffff))