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
@boochow
boochow / main.py
Last active November 11, 2018 16:18
import os
from fbconsole import FBConsole
from rpi import RPiScreen
scr = FBConsole(RPiScreen(480,270))
os.dupterm(scr)
import gpu
import framebuf
class RPiScreen(framebuf.FrameBuffer):
def __init__(self, width, height):
self.width = width
self.height = height
gpu.fb_init(width,height,screen_w=1920,screen_h=1080)
super().__init__(gpu.fb_data(),width,height,framebuf.RGB565)
self
def uint32(x):
if x & 0x8000000:
x = x - 0xffffffff - 1
return x
def byte2pwm(b):
bits = "{:08b}".format(b)
data = 0
for c in bits:
data = (data << 4) | (0b1000 if c == '0' else 0b1110)
from machine import Clock, PWM, Pin
import time
Clock(Clock.PWM, enable=False, source=Clock.OSC, divi=6, divf=0, mash=0)
Clock(Clock.PWM, enable=True)
# set PWM to serializer mode, inverted (1 = L, 0 = H), FIFO enabled
p0 = PWM(Pin(18), mode=PWM.MODE_SERIALIZER, active=0, tick_hz=3200000, duty_ticks=0, period=32, ms=PWM.MS_ENABLE, polarity=1, use_fifo=1, fifo_repeat=0)
p1 = PWM(1, active=0, period=32, use_fifo=1) # both two PWMs must be fifo enabled (chip bug?)
>>> import pyb
>>> pyb.LED(1).on()
>>> pyb.LED(1).off()
>>>
import pyb, time
while(True):
pyb.LED(1).on()
time.sleep_ms(200)
pyb.LED(1).off()
time.sleep_ms(300)
>>> import pyb
>>> tim = pyb.Timer(1)
>>> tim.init(freq=10)
>>> tim.callback(lambda t:pyb.LED(1).toggle())
>>> tim.deinit()
>>>
>>> i2c = pyb.I2C(2, pyb.I2C.MASTER)
>>> i2c.scan()
[30, 41, 45, 86, 93, 95, 106]
>>>
>>> ht = HTS221(2)
>>> ht.get()
[73.21584, 36.9939]
>>> ht.getTemp()
36.9939
>>> ht.getHumi()
73.26691
>>>
import machine
import struct
import utime
I2C_2 = machine.I2C(2)
LSM6DSL_ADDR = 106
LSM6DSL_REG_CTRL1_XL = 0x10
LSM6DSL_REG_CTRL2_G = 0x11