Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris nophead

View GitHub Profile
View ArduinoThermotat.scad
//
//! Arduino thermostat to control a beer fridge to use it as an environmental chamber.
//
// GNU GPL v2
// nop.head@gmail.com
// hydraraptor.blogspot.com
//
// Top level model
//
$pp1_colour = "grey";
@nophead
nophead / spring.scad
Created Jan 28, 2019
Demonstration of slow multiple polyhedron preview
View spring.scad
points = [[-0.0133416, -2.50818, 0.25], [-0.012326, -2.52659, 0.157319], [-0.00943391, -2.57901, 0.0787476], [-0.0051056, -2.65746, 0.0262479], [0, -2.75, 0.0078125], [0.0051056, -2.84254, 0.0262479], [0.00943391, -2.92099, 0.0787476], [0.012326, -2.97341, 0.157319], [0.0133416, -2.99182, 0.25], [0.012326, -2.97341, 0.342681], [0.00943391, -2.92099, 0.421252], [0.0051056, -2.84254, 0.473752], [0, -2.75, 0.492188], [-0.0051056, -2.65746, 0.473752], [-0.00943391, -2.57901, 0.421252], [-0.012326, -2.52659, 0.342681], [0.27588, -2.49259, 0.25], [0.277908, -2.51092, 0.157319], [0.283683, -2.5631, 0.0787476], [0.292327, -2.64119, 0.0262479], [0.302523, -2.73331, 0.0078125], [0.312718, -2.82543, 0.0262479], [0.321362, -2.90352, 0.0787476], [0.327137, -2.9557, 0.157319], [0.329165, -2.97403, 0.25], [0.327137, -2.9557, 0.342681], [0.321362, -2.90352, 0.421252], [0.312718, -2.82543, 0.473752], [0.302523, -2.73331, 0.492188], [0.292327, -2.64119, 0.473752], [0.283683, -2.5631, 0.421252], [0.277908, -2.51092, 0.342681],
@nophead
nophead / variac.ino
Last active Apr 24, 2018
ESP8266 Arduino sketch to control a variac with a stepper motor
View variac.ino
// ESP8266 Arduino sketch to control a variac with a stepper motor
// GNU GPL
// NopHead
// hydraraptor.blogspot.com
//
#include <ESP8266WiFi.h> //ESP8266 Core WiFi Library (you most likely already have this in your sketch)
#include <ArduinoOTA.h>
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include "WiFiManager.h"
@nophead
nophead / variac.py
Created Apr 24, 2018
Script to demontrate WiFi controlled varaic
View variac.py
#!/usr/bin/env python
import pycurl
from StringIO import StringIO
from time import *
import re
def curl(url):
buffer = StringIO()
c = pycurl.Curl()
@nophead
nophead / loop.cpp
Last active Apr 24, 2018
The main loop
View loop.cpp
float voltfloat = 0, currentfloat = 0, wattfloat = 0; // real unit values
float voltscalefactor = 0.0307162746 / 256; // calibration constants vary from device to device
float currentscalefactor = 1.553 / 256000;
float wattscalefactor = 15.49521794871 / 2560;
// the loop function runs over and over again forever
void loop() {
digitalWrite ( GREEN_LED, !!(millis() & 512) ); // flash the green LED
server.handleClient(); // run web server
@nophead
nophead / sync_isr.cpp
Last active Apr 24, 2018
ESP8266 SPI spy sync pin interrupt
View sync_isr.cpp
int voltint = 0, currentint = 0, wattint = 0; // raw values
void ICACHE_RAM_ATTR sync_isr() { // Sync pin interrupt on falling edge
SPI1S |= SPISSRES; // Reset HSPI slave
SPI1S &= ~SPISSRES;
SPI1CMD = SPICMDUSR; // Start HSPI slave
static bool glitch = false;
if(data_ready) { // If a data has been received by the HSPI
data_ready = false;
int volts = (data[0] << 16) + (data[1] << 8) + data[2]; // assemble 24 bits
@nophead
nophead / hspi_slave_isr_handler.cpp
Last active Apr 24, 2018
ESP8266 HSPI interrupt handler for spying on a SPI bus
View hspi_slave_isr_handler.cpp
const int length = 12; // length of packet minus the first byte
uint8_t data[length]; // raw data received
volatile bool data_ready = false; // set by HSPI interrupt handler when data is received
void ICACHE_RAM_ATTR hspi_slave_isr_handler(void *) {
uint32_t istatus = SPIIR;
if(istatus & (1 << SPII1)) { //SPI1 ISR
uint32_t status = SPI1S;
SPI1S &= ~(0x3E0); //disable interrupts
SPI1S |= SPISSRES; //reset
@nophead
nophead / hspi_slave_begin.cpp
Last active Mar 31, 2019
How to set up ESP8266 HSPI to spy on a SPI bus
View hspi_slave_begin.cpp
void hspi_slave_begin() {
pinMode(SCK, SPECIAL); // Both inputs in slave mode
pinMode(MOSI, SPECIAL);
SPI1C = 0; // SPI_CTRL_REG MSB first, single bit data mode.
SPI1S = SPISE | SPISBE | SPISCD | 0x3E0;// SPI_SLAVE_REG, set slave mode, WR/RD BUF enable, CMD define, enable interrupts
SPI1U = SPIUSSE; // SPI_USER_REG. SPI_CK_I_EDGE
SPI1CLK = 0; // SPI_CLOCK_REG
SPI1U1 = 7 << SPILADDR; // SPI_USER1_REG, set address length to 8 bits
SPI1U2 = 7 << SPILCOMMAND; // SPI_USER2_REG, set command length to 8 bits
SPI1S1 = (length * 8 - 1) << SPIS1LBUF; // SPI_SLAVE1_REG, SPI_SLV_BUF_BITLEN = 12 bytes
@nophead
nophead / void_test.scad
Created Apr 3, 2018
OpenSCAD script to test squashed wall theory
View void_test.scad
layer_height = 0.25; // slicer layer height
extrusion_width = 0.5; // slicer extrusion width
nozzle = 0.45; // extruder nozzle aperture
squeezed_wall = extrusion_width - layer_height / 2 + nozzle / 2 + extrusion_width / 2;
wall = 2 * extrusion_width;
w = 20;
h = 10;
base = 1;
difference() {
View esp12_carrier.scad
//
// GNU GPL v2
// nop.head@gmail.com
// hydraraptor.blogspot.com
//
// Adapts ESP12 module to 0.1" grid.
//
eps = 1/128; // small fudge factor to stop CSG barfing on coincident faces.
layer_height = 0.25; // slicer layer height
extrusion_width = 0.5; // slicer extrusion width
You can’t perform that action at this time.