This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import I2C | |
i2c=I2C(1) | |
i2c.init(freq=1000000) | |
oled = SSD1306_I2C(128, 64, i2c) | |
console = FBConsole(oled) | |
os.dupterm(console) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uio | |
class FBConsole(uio.IOBase): | |
def __init__(self, framebuf, bgcolor=0, fgcolor=-1, width=-1, height=-1): | |
self.fb = framebuf | |
if width > 0: | |
self.width=width | |
else: | |
try: | |
self.width=framebuf.width |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stm32 version of wiznet_connect.py | |
import network | |
nic = network.Ethernet() | |
while not nic.isconnected(): | |
pass | |
nic.active(True) | |
nic.ifconfig('dhcp') | |
print(nic.ifconfig()) | |
import socket | |
print(socket.getaddrinfo('micropython.org', 80)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MCP3204: | |
def __init__(self, spi, cs): | |
self.spi = spi | |
self.cs = cs | |
def read(self, ch): | |
cmd = 6 | (ch >> 2) | |
par = (ch << 6) & 0xff | |
send = bytearray([cmd, par, 0]) | |
recv = bytearray(3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin, SPI | |
spi = SPI(0) | |
dc = Pin(27,Pin.OUT) | |
res = Pin(22,Pin.OUT) | |
cs = Pin(17,Pin.OUT) | |
d = SSD1306_SPI(128,64,spi,dc,res,cs) | |
d.text("SPI OK", 0, 0) | |
d.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import machine | |
sd = machine.SD() | |
import os | |
os.mount(sd, '/sd') | |
os.chdir('sd') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Timer,I2C | |
i2c = I2C(1) | |
i2c.init() | |
d = SSD1306_I2C(128,64,i2c) | |
c = DS3231(i2c) | |
c.write([2018, 5, 30, 23, 30, 45, 3]) | |
day = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decimal2num(b): | |
return ((b & 0xf) + 10 * (b >> 4)) | |
def num2decimal(d): | |
return (d % 10) | (d // 10) << 4 | |
def hour_value(b): | |
result = decimal2num(b & 0x1f) | |
if (b & 0x20): | |
result += 12 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write_data(self, buf): | |
self.i2c.writeto(self.addr, bytearray([0x40]), False) | |
self.i2c.writeto(self.addr, buf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write_data(self, buf): | |
self.temp[0] = self.addr << 1 | |
self.temp[1] = 0x40 # Co=0, D/C#=1 | |
self.i2c.start() | |
self.i2c.write(self.temp) | |
self.i2c.write(buf) | |
self.i2c.stop() |