Skip to content

Instantly share code, notes, and snippets.

View JamesNewton's full-sized avatar
💭
Dexter rocks!

JamesNewton

💭
Dexter rocks!
View GitHub Profile
@JamesNewton
JamesNewton / MassMind.org ENC1 3Wire ReadAngle Arduino
Created May 8, 2017 19:13
Arduino code to read the angle register from the MassMind.org ENC1 via 3 wire read only mode.
/*
Source from
http://forum.arduino.cc/index.php?topic=78881.msg1375885#msg1375885
* Ahmad Byagowi ([email protected])
* Date : Aug 31, 2013
* All code (c)2013 Ahmad Byagowi Consultant. all rights reserved
20170508 Minor edits to improve clarity by James Newton.
*/
//c2 pin tied to ground for 3 wire mode
@JamesNewton
JamesNewton / PinReadWrite.ino
Last active August 30, 2023 01:10
Simple Arduino script to set pins high, low, input, pull up, or analog/servo, clock in or out data, with timing/start/stop, and read all or a single pin back via serial IO. NOTE: THIS HAS BEEN REPLACED BY https://github.com/JamesNewton/Arduino_Dynamixel_Stepper_Controller
/*
PinReadWrite.ino
//20170512 initial version
//20170517 uS timing (was mS), vars are longs, i2C start/stop, and clock IN data w/.
//20201002 Returns valid JSON.
Simple Arduino script to set pins high, low, input, pull up, or analog/servo,
clock out data with timing, and read all or a single pin back via serial IO.
Written for the tiny-circuits.com TinyDuino in the end effector of the
Dexter robot from HDRobotic.com, but generally useful to turn the Arduino
@JamesNewton
JamesNewton / csv2OpenSCAD2png.bat
Created July 26, 2017 23:05
Render CSV data into png files for animation / video overlay via OpenSCAD
@echo off
if NOT [%2]==[] goto :doit
echo Usage:
echo %0 data.csv script.scad parameters
echo Where:
echo - data.csv is a csv file where each line corrisponds to a single frame to be produced in the PNG file
echo.
echo - script.scad is the script which will render the line of data into the PNG frame.
echo The script should parse the line of data and render a valid output
@JamesNewton
JamesNewton / BinHexExamples.c
Created February 2, 2018 01:49
Options for shortest possible binary to hex, multiple data types, light, fast, easy for the C compiler to optimize.
//For a live version of this, see:
//https://ideone.com/HDqleJ
#include <stdio.h>
#define loctype long
//#define loctype short
//#define loctype double
//#define loctype float
#define value 3735928559 //a fun value which turns into DEADBEEF in hex.
#define EOL 13
@JamesNewton
JamesNewton / encoderdisk.jscad
Last active October 15, 2019 15:51
OpenJSCAD code to make an encoder disk, Moved to: https://github.com/JamesNewton/HybridDiskEncoder
// title : OpenJSCAD.org encoder disk
// author : James Newton
// license : MIT License
// revision : 0
// tags : hdrobotics.com
// file : encoderdisk.jscad
// http://openjscad.com/#https://gist.githubusercontent.com/JamesNewton/c8598878736442c440bbe41d086291ac/raw//encoderdisk.jscad
function getParameterDefinitions() {
return [
@JamesNewton
JamesNewton / macros.h
Created November 4, 2021 00:51
Good C / C++ macros
//the Arduino map function.
#define MAP(x, in_min, in_max, out_min, out_max) (((x) - (in_min)) * ((out_max) - (out_min)) / ((in_max) - (in_min)) + (out_min))
#define SIGN(i) ((i)>0? 1:(i)<0?-1:0)
#define MAX(a, b) ((a)>(b)?(a):(b))
#define MIN(a, b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)<0?(0-(a)):(a))
@JamesNewton
JamesNewton / dial.jscad
Created February 20, 2025 04:57
OpenJSCAD.com code for a dial
//makes a dial for export as a DXF or SVG
//needs finishing
let resolution = 64
let slotfudge = 0.05
let slotlength = 2
function cutarc(r, a, i) {
let arcwidth = .1// a/2
let curvedpath = CSG.Path2D.arc({
center: [0,0,0],
@JamesNewton
JamesNewton / hello.asm
Last active September 20, 2025 04:10
RET FORTH
;1000 years ago, when I was 17, I wrote a FORTH for the Z80 on a Trash 80.
;It was unique for the time, because it used the machine language RET as NEXT for asm words.
;e.g. the machine stack pointed NOT at the data stack or return stack but instead
; at the list of word addresses being executed aka the thread.
;That meant that asm words could be strung together even faster than a standard asm program
;because there was no asm CALL the RET was both the return from the current asm word AND
;the call to the next one.
;The address of the data and return stacks were kept elsewhere...
;one of the other registers or a memory location (I don't remember, code is long lost).
;I think it was IX and IY.

Minimal Embedded Remote Graphics Interface Format

Embedded systems often need a small display. The programming required to support that distracts from the main focus of the project. IO pins are also costly. The simplest possible method of adding a display is desirable. Having a low cost separate processor to manage the display with an easy to load firmware and a simple command set seems like a good idea. A single serial tx pin (and rx if a touch screen is used) should be enough. Instead of using binary commands and supplying a library of code in every language,

@JamesNewton
JamesNewton / dynamixel_raw.ino
Created October 27, 2025 03:54
Dynamixel Servo TX/RX Raw
/*
This code does direct communications in both directions with Dynamixel servos
It doesn't use any libraries and provides minimal ping, write, read of registers
Really useful more just to see how they work than anything else.
I wrote it because a friend needed it to reduce code size on a minimal controller.
In a real environment with a Dynamixel attached, it will monitor register 116.
In testing / debugginer here, it uses the serial port to display testing results.
Obviously, for a real connection, you need to implement the hardware and use an IO
pin to switch the TX pin from driven to High-Z and wire it to the RX pin.
See it run at: