Skip to content

Instantly share code, notes, and snippets.

View sourceperl's full-sized avatar

l.lefebvre sourceperl

  • Hauts-de-France
View GitHub Profile
@sourceperl
sourceperl / relay_class.py
Created December 5, 2014 15:06
Simple Python class for relay (manage edge front, toggle)
class Relay:
def __init__(self):
self.value = False
self._value = False
@property
def state(self):
"""Get the current relay state."""
return self.value
@sourceperl
sourceperl / rrd_peak_find.py
Created December 11, 2014 08:42
Find peak in value of an RRDtool base.
import rrdtool
import datetime
# retrieve RRD data (3 days past from now)
rrd = rrdtool.fetch('/home/pi/rrd/flow.rrd', 'AVERAGE', '-s -3d')
# timestamp start/end
start = rrd[0][0]
end = rrd[0][1]
step = rrd[0][2]
@sourceperl
sourceperl / fft_paper.pdf
Last active August 29, 2015 14:25
FFT sample in Python2.7
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sourceperl
sourceperl / rpi_panel.py
Last active September 23, 2015 19:58
Manage a Rpi Panel with pygame and framebuffer interface
import os
import pygame
import time
import signal
#some const
BLACK = (0, 0, 0)
RED = (200, 0, 0)
WHITE = (255,255,255)
*.o
*.elf
@sourceperl
sourceperl / gist:5658900
Last active December 17, 2015 19:10
Set MSP430 for low power mode
// set XTAL 32768 Hz on the board
void main(void) {
// Stop Watchdog
WDTCTL = WDTPW + WDTHOLD;
// MCLK:LFXT1CLK/8
// SMCLK:LFXT1CLK
BCSCTL2 = 0xF8;
// IO setup
P1DIR = 0xFF;
@sourceperl
sourceperl / low_bread.ino
Last active December 19, 2015 18:38
Lowpower Arduino test. An ATmega328P on a breadboard powered under 3.3v. Arduino bootloader at 8 MHz internal RC clock.
/*
An ATmega328P on a breadboard powered under 3.3v (2x AA battery)
Arduino bootloader at 8 MHz internal RC clock.
This example code is in the public domain.
Share it's happiness !!!
*/
#include <SPI.h>
@sourceperl
sourceperl / lcd_clock.py
Created February 26, 2016 15:51
Clock on a Rpi with a 4x20 LCD on I2C port
#!/usr/bin/env python3
import time
import schedule
import RPi_I2C_LCD
# global var
lcd = RPi_I2C_LCD.LCD()
def update_lcd():
@sourceperl
sourceperl / track_cap.py
Created June 14, 2016 15:00
Track a water bottle cap view by USB cam (use Python2 with open_cv 2 and numpy)
import cv2
import numpy as np
# open_cv track test :
#
# track blue object and check there are in circle area
# for test: object is a blue water bottle cap (color H,S,V = 202 (101 after normalized, 64, 59)
# some class
@sourceperl
sourceperl / rpi_timelapse.py
Created June 24, 2016 16:13
Tool for timelapse with PiCamera on Raspberry Pi
#!/usr/bin/env python
# shoot jpg images at regular interval for timelapse (store to img/)
#
# build MPEG4 video with jpg files :
# ffmpeg -framerate 10 -i img/image%04d.jpg -c:v libx264 -r 10 video/timelapse.mp4
#or
# ffmpeg -framerate 2 -i img/image%04d.jpg video/timelapse2.mp4
import time