Skip to content

Instantly share code, notes, and snippets.

@theterg
theterg / serial_port_logger.py
Created March 18, 2014 23:05
A simple python 3.0 script to log data from two different serial ports at one time
import serial
import sys
import time
import argparse
parser = argparse.ArgumentParser(description='Dump serial data from basis')
parser.add_argument('portA', type=str, help='Serial port A')
parser.add_argument('portB', type=str, help='Serial port B')
parser.add_argument('--baud', type=int, default=1000000, help='The baud rate of both devices')
parser.add_argument('--labelA', type=str, default='A')
@theterg
theterg / scope_get_data.py
Created February 26, 2014 21:23
Continually retrieve a single datapoint from any VISA device such as an oscilloscope or benchtop multimeter.
import visa
import sys
import pandas as pd
import numpy as np
import datetime
import time
import argparse
parser = argparse.ArgumentParser(description='Continuously retrieve data from scope as quickly as possible')
parser.add_argument('command', type=str, help='The command to execute. EG: MEAS:PWIDTH? CHANNEL3')
@theterg
theterg / pwmtest.py
Created February 10, 2014 13:38
Raspberry pi wiringpi2 pwm test
import wiringpi2 as wiringpi
import sys
import argparse
import time
parser = argparse.ArgumentParser()
# parser.add_argument('--clock', type=int, default=32)
parser.add_argument('--period', type=int, default=200)
parser.add_argument('--pulsewidth', type=int, default=15)
args = parser.parse_args()
@theterg
theterg / MioDecode.py
Created December 18, 2013 20:31
Found some data on a UART channel connecting the sensor board to the bluetooth/main MCU on a Mio Alpha watch. Wrote a quick script to assist in viewing the data on this bus.
'''
MioDecode.py
Reads data from the internal serial bus of a Mio Alpha and prints the BPM to screen.
Dependences:
-pyserial
Usage:
python.exe MioDecode.py --port='<serial port>' --baud=<baud rate>
@theterg
theterg / example.py
Created November 19, 2013 16:21
Example of reading in json configuration
import json
f = open('devinfo.json','r')
lines = f.readlines()
config = json.loads(lines[0])
print config['data_format']
print config['sensor_settings']['accelerometer']['scale']
@theterg
theterg / metadata.json
Created November 15, 2013 23:09
Sample prototype metadata
{
"gitref": "refs/heads/add_sd",
"gitsha": "5b5fba031cee12ffc9fa97977692062310f86ea7",
"devid": "533231003153344c3330373038343038",
"board": 201,
"tick_rate_hz": 1000,
"data_format": "0.1",
"sample_ticks": {
"accelerometer": 10,
"gyroscope": 33,
@theterg
theterg / Plottest.py
Created November 13, 2013 14:07
Matplotlib live plot animation without blitting
import pylab as plt
import numpy as np
import pandas as pd
import random
import time
start = time.time()
frames = pd.DataFrame([0], [0.0], ['data'])
plt.ion()
@theterg
theterg / pmc.c
Created October 30, 2013 23:23
Atmel Software Framework PMC implementation - NOP WAT
void pmc_enable_waitmode(void)
{
uint32_t i;
/* Flash in Deep Power Down mode */
i = PMC->PMC_FSMR;
i &= ~PMC_FSMR_FLPM_Msk;
i |= ul_flash_in_wait_mode;
PMC->PMC_FSMR = i;
@theterg
theterg / Makefile
Created August 2, 2013 18:11
Bluegiga BTLE test code modified to analyze CRP protocol notification data
CC = gcc
TARGET = test001
MACHINE = $(shell $(CC) -dumpmachine)
# Windows
ifneq (,$(or $(findstring mingw, $(MACHINE)), $(findstring cygwin, $(MACHINE))))
PLATFORM = WIN
LIBS = -lm -lsetupapi
RM = del
@theterg
theterg / studio6_linux_conversion.sh
Created July 25, 2013 18:24
A script to convert a Makefile produced by Atmel Studio 6 for arm-none-eabi on a linux host.
#!/bin/sh
PROJECT_NAME=$1
if [ "$PROJECT_NAME" != "" ]; then
# TARGET_DIR=${PROJECT_NAME}/${PROJECT_NAME}/Debug
TARGET_DIR=${PROJECT_NAME}
find ${TARGET_DIR} -iname "*.d" -type f -exec sed -i 's/c:\\.*\\bin\\//g' {} \;