Skip to content

Instantly share code, notes, and snippets.

@johnty
johnty / pigstest_servo
Created November 25, 2016 20:34
pigs servo test code
MAX=1700
MID=1500
MIN=1200
sudo pigpiod
pigs pfs 18 50 # set pwm freq to 50 hz on BCM18
pigs servo 18 $MID # set servo pulsewidth to MID us on BCM18
sleep 1
pigs servo 18 $MIN # set servo pulsewidth to MIN on BCM18
@johnty
johnty / server.js
Last active August 22, 2016 13:35
sandbox
// Import Express
var express = require("express");
var app = express();
// Import Cors: cross origin resource
var cors = require("cors");
app.use(cors());
// Import Mongoose
var mongoose = require("mongoose");
// instructions:
// 1.) install node.js and npm
// 2.) put this file in a folder
// 3.) go to this folder in terminal, and install ffi and ref using 'npm install ...'
// 4.) execute by typing `node node-ffi-mapper.js`
//
// note: refers explicitly to libmapper-0.2.dylib so make sure it is on the path!
var ref = require('ref');
var ffi = require('ffi');
@johnty
johnty / midi.json
Created July 7, 2016 21:50
simple node-red flow for displaying MIDI messages. requires node-red-contrib-ui and node-red-contrib-midi
[{"id":"c2c6477f.a696e8","type":"midi","z":"29801501.b12f9a","name":"MIDI In","filtermessage":"","port":"1","x":72,"y":42,"wires":[["a8489adb.12f6c8"]]},{"id":"a8489adb.12f6c8","type":"template","z":"29801501.b12f9a","name":"grab midi msg","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.message}}","x":139,"y":90,"wires":[["6a918548.45b34c"]]},{"id":"6a918548.45b34c","type":"csv","z":"29801501.b12f9a","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"","x":217,"y":41,"wires":[["cc1b3fe4.be9cc","7a9da23f.8e6a2c","fbdad48.cbcff28"]]},{"id":"cc1b3fe4.be9cc","type":"template","z":"29801501.b12f9a","name":"col1","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.col1}}","x":319,"y":83,"wires":[["b7bcfdb6.33e0f"]]},{"id":"7a9da23f.8e6a2c","type":"template","z":"29801501.b12f9a","name":"col2","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.
@johnty
johnty / sliders.json
Last active July 7, 2016 21:51
node-red flow for sliders example
[{"id":"8bc3934b.dec0c","type":"mcp3008","z":"bc7ea069.67a99","name":"","device":"/dev/spidev0.0","mode":"0x80","interval":"25","x":319,"y":156,"wires":[["941e2650.e518a8","178087e.871bf78"]]},{"id":"da077c2f.9bf43","type":"inject","z":"bc7ea069.67a99","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":true,"x":93,"y":72,"wires":[["8916983b.311a48"]]},{"id":"d1ea8f0e.568af","type":"inject","z":"bc7ea069.67a99","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"x":93.5,"y":37,"wires":[["8916983b.311a48"]]},{"id":"941e2650.e518a8","type":"debug","z":"bc7ea069.67a99","name":"","active":false,"console":"false","complete":"false","x":541,"y":156,"wires":[]},{"id":"178087e.871bf78","type":"ui_slider","z":"bc7ea069.67a99","tab":"e3257868.dcaa18","name":"Push","topic":"","group":"","order":1,"min":0,"max":"1023","x":527,"y":212,"wires":[["f2ec0099.fbb4c"]]},{"id":"b618b17a.ef5bb","type":"ui_gauge","z":"bc7ea069.67a99","tab":"e325786
@johnty
johnty / sys_mon_lcd.py
Last active October 24, 2017 11:21
python system monitor on 1602 lcd
#!/usr/bin/python
#--------------------------------------
# ___ ___ _ ____
# / _ \/ _ \(_) __/__ __ __
# / , _/ ___/ /\ \/ _ \/ // /
# /_/|_/_/ /_/___/ .__/\_, /
# /_/ /___/
#
# lcd_i2c.py
# LCD test script using I2C backpack.
@johnty
johnty / memstats.sh
Created May 4, 2016 15:41
print out memory stats
while true; do
echo -n memfree: "`free -m | head -2 | tail -1 | awk '{print $4}'` ";
echo -ne swap used: "`cat /proc/swaps | tail -1 | awk '{print $4}'` \r";
sleep 1;
done
@johnty
johnty / ESP8266-hue-sensor.ino
Created April 2, 2016 03:28
Arduino ESP8266 sketch for updating the status of a generic CLIP status sensor. hardcoded AP/password and Hue IP/API strings.
/**
Custom ESP8266 CLIP sensor for Philips Hue system
GPIO2's high/low state will emit two different status values
which can then be used to trigger Hue bridge events
You will need:
0.) Wifi network and Philips Hue bridge connected to it and set up, with an API key
1.) A custome IP sensor (CLIP) created in the Hue bridge
2.) A rule hooking up the status of the IP sensor and events we want
gpio load spi
while true;
do
gpio -x mcp3004:200:0 aread 200; #reads first channel of ADC; aread 201 reads 2nd channel, etc.
done
@johnty
johnty / midiNameMatch
Last active August 29, 2015 14:12
midi port name search/connect
int portInIndex = -1;
int portOutIndex = -1;
// print input ports to console
midiIn.listPorts(); // via instance
//ofxMidiIn::listPorts(); // via static as well
if (midiIn.getNumPorts()) {
for (int i=0; i<midiIn.getNumPorts(); i++) {
string pname = midiIn.getPortName(i);
if (ofStringTimesInString(pname, "ICubeX")) {