Skip to content

Instantly share code, notes, and snippets.

@pingud98
pingud98 / logging.sh
Created July 21, 2015 11:47
Shell script for simultaneous data logging from two USB serial arduino's
#!/bin/sh
now=$(date +"%m_%d_%Y_%H_%M_%S")
echo "Start time"
echo $now
cat /dev/ttyACM0 > chanA_$now.csv &
cat /dev/ttyACM1 > chanB_$now.csv &
echo "Logging script running"
@pingud98
pingud98 / CosmicPi1
Created July 27, 2015 02:11
CosmicpiDraft1 - Full functionality
/*
Cosmic Pi fully integrated script mk1
Designed for Arduino Due, sampling performance <500ksps (to be measured)
untested. Runs on interrupt to pins 50 (time reset) and 49 (event detection)
*/
#include <Adafruit_GPS.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_BMP085_U.h>
int x; // read value
int adcloopctr;
unsigned long values[100];
const int eventtrigger = 49;
boolean eventhappened = false;
int sampledepth = 10;
int printctr = 0;
int readoutctr;
@pingud98
pingud98 / Distancemeasurement
Created August 27, 2015 07:33
HC-SR04 ultrasonic position sensor - without any wiring
/*
A (neat) cheat way of getting the HC-SR04 distance sensor working on an Arduino Uno
put it in the end, with the GND aligned with the GND pin next to pin 13 and AREF
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
@pingud98
pingud98 / dualchannel.ino
Created September 13, 2015 14:23
Cosmic Pi Dual Channel Readout
//this works from the electronics crate, reads out Ch 6 and Ch7 fast enough, peak samples generally occur at 4th position on readback.
//Shotky diodes are used to prevent negative voltage hurting the ADC.
int x; // read value
int adcloopctr;
unsigned long values[200];
const int eventtrigger = 49;
boolean eventhappened = false;
int sampledepth = 10;
int printctr = 0;
@pingud98
pingud98 / gist:5aeb7ad08d44fccec79f
Created October 2, 2015 22:15
Cosmic Pi Progress 02 10 15
#include <Adafruit_BMP085_U.h>
#include <Adafruit_GPS.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_10DOF.h>
#include <Adafruit_HTU21DF.h>
#include <Wire.h>
#define mySerial Serial1
#define GPSECHO true
@pingud98
pingud98 / HV set and ramp.ino
Created October 3, 2015 14:30
HV PSU Control algo
//upwards voltage ramp from 40V to 68.8V, takes approx 60 seconds to reach
//03 10 15 Jdevine
#include <SPI.h>
const int slaveAPin = 52;
void setup() {
pinMode (slaveAPin, OUTPUT);
digitalWrite(slaveAPin, LOW);
SPI.begin();
@pingud98
pingud98 / CosmicPiComplete31015
Created October 3, 2015 16:58
Cosmic Pi code inc. all sensors, ADC, trigger and HV PSU control
#include <Adafruit_BMP085_U.h>
#include <Adafruit_GPS.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_10DOF.h>
#include <Adafruit_HTU21DF.h>
#include <Wire.h>
#define mySerial Serial1
#define GPSECHO true
@pingud98
pingud98 / CosmicPiComplete0410151531.ino
Created October 4, 2015 13:31
This afternoon's cosmic pi
#include <Adafruit_BMP085_U.h>
#include <Adafruit_GPS.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_10DOF.h>
#include <Adafruit_HTU21DF.h>
#include <Wire.h>
#include <SPI.h>
@pingud98
pingud98 / Cosmic Pi ADCtrigger
Last active June 3, 2016 17:00
This script combines the timer triggering functionality with the free running ADC in two channel mode, reading in to a buffer using DMA. The net result is that we can sample events up to the design spec of 5Hz. The only limit on performance is how long it takes to get the data out. The sample rate on the ADC is approx 800ksps, though over 2 chan…
/*notes to Team Cosmic Pi
I just got this working in Cosimo's lab using a TTi TG5011 LXI function generator and a Tektronix TDS2024 scope.
It took a lot of fine tuning to get the right buffer read out, so that the rising edge can be consistently seen in the samples.
The buffer index (i.e. how many buffers back in time you need to go) will definitely change based on the rest of the code, but the principle is here
Don't forget that we're interleaving channels 1 and 2, therefore the nth sample is channel 1 and the n+1th sample is channel 2 etc. and if we're reading out 50, it's actually 25 from channel A etc.
Also note that the ADC seems to top out (4096) around 2.3V, I was expecting 3.3V, so maybe there's another setting to tweak here.
If you are testing this code independently here are your parameters for connection:
Set up a SAW wave, with a vertical rising edge, then monotonically decreasing
Amplitude (max) 2.3V, never above 3.3V or you'll cook the DUE