Skip to content

Instantly share code, notes, and snippets.

@aerialist
aerialist / gist:e22118b6c92add4bc008bf7a33e9ded0
Last active September 28, 2024 04:41
KiCad script to layout key switch matrix with LED. Copy code and run it in Scripting Console by right clicking to chose "Paste And Run".
# starting position
sw = {}
led = {}
reg = {}
diode = {}
sw['ref'] = 'K'
sw['start_x'] = 42.4
sw['start_y'] = 30.3
sw['orientation'] = 180
sw['side'] = 0 # layer 0 = 'Front'
@aerialist
aerialist / gist:f8460f6a21f7cef5e073e9d6c5efcd29
Last active August 16, 2024 06:12
KiCad script to layout key switch matrix
# starting position
start_x = 42.4
start_y = 30.3
# distance between key switches
dx = 10.6
dy = 10.1
# number of rows and columns of the matrix
rown = 6
coln = 15
# Prefix of component reference
@aerialist
aerialist / gist:d1f93dcd9b510f84a6da4153226104a4
Created August 16, 2024 05:28
KiCad script to move all 'K*' components to 0,0 position
import pcbnew
board = pcbnew.GetBoard()
footprints = board.GetFootprints()
for footprint in footprints:
if footprint.GetReference()[0] == 'K':
footprint.SetPos(pcbnew.VECTOR2I_MM(0,0))
pcbnew.Refresh()
@aerialist
aerialist / euler_quaternion_unity.py
Last active March 6, 2022 14:15
Conver Euler angles to Quaternion, in the same manner as Unity
#!/usr/bin/env python
# coding: utf-8
# This code try to produce same quaternion from euler angles as Unity
# https://docs.unity3d.com/ScriptReference/Quaternion.html
# Oritinal code is from
# https://stackoverflow.com/questions/12088610/conversion-between-euler-quaternion-like-in-unity3d-engine/12122899#12122899
import numpy as np
@aerialist
aerialist / readme.md
Created April 30, 2020 13:29
Don't use external power for uCurrent gold

uCurrent Gold from EEVBlog is an excellent handy tool to measure mA or uA order of low current on battery powered IoT devices. https://www.eevblog.com/projects/ucurrent/

It normally run on CR2032 3v battery and it's voltage swing is capped to 0-1.2V. It also drains out poor quality cheap CR2032s rather quickly.

The web pages reads that you could extend the voltage swing by increasing the battery voltage, upto 5.5v. But don't be tempted add a DC jack to use external power supply!!

It's negative pole is used to make "virtual ground". It needs to be independent from the ground of DUT. So it's important the device runs on battery.

@aerialist
aerialist / read_scopy_csv.py
Last active April 25, 2020 03:08
Read csv file from ADALM2000 Scopy and create Python Pandas DataFrame
import pandas as pd
import datetime
def make_dt(timestr, start_dt):
"""
Take starting datetime object and time stamp string in '23:20:35' format
Return a datetime object with date info from starting datetime and time info from time stamp string
"""
ts = datetime.datetime.strptime(timestr, "%H:%M:%S")
@aerialist
aerialist / main.py
Created April 21, 2020 13:56
PySide2 QML boiler plate
# This Python file uses the following encoding: utf-8
# https://qmlbook.github.io/ch18-python/python.html
# This bug has already been fixed
# We can connect in QML
# https://bugreports.qt.io/browse/PYSIDE-634
# https://wiki.qt.io/Qt_for_Python_Signals_and_Slots
import sys
__ __
\ \ /\ / /
\ \ / \ / /
\ \/ /\ \/ /
\ / \ /
/ /\ / /\
/ /\ \/ /\ \
/ / \ / \ \
/_/ \/ \_\
@aerialist
aerialist / switchbot_bluepy.py
Created May 1, 2017 11:03
Activate switchbot by python with bluepy on Raspberry Pi
# Activate switchbot by python with bluepy on Raspberry Pi
# https://github.com/IanHarvey/bluepy
#
# Switchbot's API is taken from this
# https://github.com/OpenWonderLabs/python-host
import binascii
from bluepy.btle import Peripheral
# find your switchbot address by
"{:02X}".format(10)
# 0A
"{:#04X}".format(10)
# 0X0A