Skip to content

Instantly share code, notes, and snippets.

View rwb27's full-sized avatar

Richard Bowman rwb27

View GitHub Profile
@rwb27
rwb27 / thing_descriptions.json
Last active May 30, 2024 22:52
Thing Descriptions for the OpenFlexure Microscope (v3 pre-release) (all TDs in a single JSON file)
{
"/camera/": {
"title": "StreamingPiCamera2",
"properties": {
"analogue_gain": {
"title": "analogue_gain",
"type": "number",
"forms": [
{
"href": "/camera/analogue_gain",
@rwb27
rwb27 / socks.md
Created February 14, 2020 09:08
Internet access for a Raspberry Pi on a hidden network

Setting up a SOCKS proxy on a Raspberry Pi

My problem: I have a bunch of Raspberry Pi computers, all connected via a network switch and USB ethernet port to a "gateway" Raspberry Pi. However, I don't particularly want them all to be internet-connected all of the time, because (1) it's possible there is a slight security risk and (2) my IT folk at work might not like it. OK, I should also mention (3) I tried and failed to get NAT and dnsmasq to work, and don't have time to finish debugging it.

My solution: I SSH in to my "gateway" Pi (is it ok to call it a gateway even though it's resolutely failing to route any traffic? Never mind...), and from there I can connect to my hidden Pi(s), let's say for arguments sake it's called hiddenpi.local.

ssh pi@hiddenpi.local

Now, I can SSH back again, setting up a SOCKS proxy:

@rwb27
rwb27 / benchtop_piezo.py
Created November 28, 2019 12:28
Controlling ThorLabs Piezo from Python
"""
This is a Python 3 wrapper for the Thorlabs BPC203 Benchtop Piezo controller.
It relies on the Thorlabs Kinesis API (so you should copy in, or add to your
Python path, the Kinesis DLLs). The easiest way to copy the right DLLs is
to use the "DLL copying utility" which is probably located in
c:/Program Files/Thorlabs/Kinesis
I also use the excellent ``pythonnet`` package to get access to the .NET API.
This is by far the least painful way to get Kinesis to work nicely as it
@rwb27
rwb27 / Readme.md
Last active February 24, 2019 15:51
A test object for "self-tapping" triangular holes in printed parts. Print the STL then fill out the Google form.

I've switched to using slightly triangular holes in my printed parts, because they "self tap" quite nicely using machine screws (the points of the triangles provide enough space that the swarf doesn't jam the thread). My hope is that this extends the tolerance on hole size, meaning I don't have to worry quite so much about getting diameters exactly right. This means the print should work first-time on a greater range of printers. If you could print the test piece below (trylinder_selftap_holes_test.stl) and then fill out the form that would be really helpful.

The easiest way to get the test piece is to right click the raw download link and choose "save link as..." to save to an STL file - gists don't give the files the correct mimetype,

@rwb27
rwb27 / shortcut.ps
Created January 24, 2019 15:15
How to create a shortcut in Windows 10 from PowerShell
$ws = New-Object -ComObject WScript.Shell;
$s = $ws.CreateShortcut('C:\Users\Public\Desktop\RDWorksV8.lnk');
$s.TargetPath = 'C:\Program Files (x86)\RDWorksV8\RDWorksV8.exe';
$s.save()
@rwb27
rwb27 / SETUP.md
Last active January 21, 2019 09:59
Build script for the OpenFlexure Microscope

Setting up the microscope build server (so far)

sudo apt-get install openscad

mkdir -p ~/dev/openflexure_microscope_builds/sparse_checkout/
cd ~/dev/openflexure_microscope_builds/sparse_checkout/

git init
git config core.sparsecheckout true
@rwb27
rwb27 / layout.pov
Created January 30, 2018 18:15
First rendering of an OpenFlexure Microscope in POV-Ray
/*
This file started with:
http://robottrouble.com/wp-content/uploads/2009/11/pov_layout.tmpl
Linked to from http://www.robottrouble.com/2009/12/01/auto-rendering-stl-files-to-png/
Then I took the suggestions from Thingiverse.com's Google group.
Then I added a bit more to center and scale the mesh.
Then I threw on (basic) animation support (Circles object around the Z axis.)
Uses axes_macro.inc found at http://lib.povray.org/searchcollection/download.php?objectName=AxesAndGridMacro&contributorTag=SharkD&version=1.2
Works with stl2pov 2.4.3
Tested with stl2pov 3.0.0beta, camera block below requires removal of sky, right and up lines. (May be different in final version.)
from __future__ import print_function
import PIL.Image
import PIL.ExifTags
import sys
import os
def formatted_exif_data(image):
"""Retrieve an image's EXIF data and return as a dictionary with string keys"""
# with thanks to https://stackoverflow.com/questions/4764932/in-python-how-do-i-read-the-exif-data-for-an-image
exif_data = {}
@rwb27
rwb27 / set_picamera_gain.py
Last active April 27, 2023 15:09
Manually setting gain of raspberry pi camera from within python
from __future__ import print_function
import picamera
from picamera import mmal, mmalobj, exc
from picamera.mmalobj import to_rational
import time
MMAL_PARAMETER_ANALOG_GAIN = mmal.MMAL_PARAMETER_GROUP_CAMERA + 0x59
MMAL_PARAMETER_DIGITAL_GAIN = mmal.MMAL_PARAMETER_GROUP_CAMERA + 0x5A
@rwb27
rwb27 / latexdockercmd.sh
Last active October 30, 2020 18:21
A simple work-around to use the excellent blang/latex Docker image from mingw on Windows
#!/bin/sh
if [[ `uname -s` == MINGW* ]];
then
#echo "MINGW Detected"
exec docker run --rm -i --net=none -v "`pwd | sed -E 's/^\/(.)\//\1:\//'`":/data blang/latex "$@"
else
#echo "Not running in MINGW"
exec docker run --rm -i --user="$(id -u):$(id -g)" --net=none -v "$PWD":/data blang/latex "$@"
fi