Skip to content

Instantly share code, notes, and snippets.

@dpgeorge
dpgeorge / spi_slave_test.py
Created January 30, 2016 19:15
A script for the pyboard which implements a simple SPI slave in software
"""
This implements a simple SPI slave. It will run on PYBv1.0 and PYBv1.1.
The SPI slave logic is done in software and can cope with an SPI clock
frequency up to 125kHz.
There is no CS line, only SCLK, MOSI, MISO.
Clock format must be mode=0, which is polarity=CPOL=0, phase=CPHA=0 (clock
is low when idle and high when active, and data is sampled on first, rising
edge of clock).
@dpgeorge
dpgeorge / vcprate.py
Created December 27, 2015 17:30
vcprate.py
#!/usr/bin/env python
import time
import argparse
import serial
def drain_input(ser):
time.sleep(0.1)
while ser.inWaiting() > 0:
print('drain:', ser.read(ser.inWaiting())[:20])
@dpgeorge
dpgeorge / bootloader.py
Created March 26, 2015 22:15
A Python script to easily enter the bootloader on the pyboard
#!/usr/bin/env python
import time
import argparse
import serial
def bootloader(dev):
ser = serial.Serial(dev)
time.sleep(0.1)
while ser.inWaiting() > 0:
@dpgeorge
dpgeorge / lowpower.py
Created March 25, 2015 21:44
Low power test script for pyboard
# cycle through standby, stop, wfi, run modes
# uses either rtc wakeup or switch extint
# put pyb.usb_mode(None) in boot.py to save more power
# can also select lower CPU freq using, eg, pyb.freq(64000000)
import pyb, stm
from pyb import Pin
def low_power_test():
rtc = pyb.RTC()
@dpgeorge
dpgeorge / gist:cf701079aee1c8d201a4
Created August 18, 2014 21:42
Simple, minimal deflate/inflate code
// simple, minimal deflate/inflate code
// copyright 2010, Damien P. George
import "std.h";
import "iobuf.h";
uint con BSIZE = 1024;
type buf_history = (
byte own# buf,