Skip to content

Instantly share code, notes, and snippets.

//read the temperature of the integrated sensor on the Arduino DUE
float trans = 3.3/4096;
float offset = 0.8;
float factor = 0.00256;
int fixtemp = 27;
void setup() {
Serial.begin(9600);
}
//plug the Cosmic Pi Analogue PCB in to the arduino directly, make sure you've disconnected the VBias pin and powered the SiPM's
//via an alternative power supply
//This code reads A1 and A3 in free running mode. If the values are higher than threshold, it outputs the cumulative number of events
//and the time since the last event in milliseconds.
//the commented out part at the bottom can be used to output the actual data and is what we've been using to make some plots.
//this whole thing runs in a loop and is a long way from true realtime.
//J. Devine 29/08/16
@pingud98
pingud98 / CosmicPiAnalogueSoftwareTrigger2
Created September 1, 2016 20:18
A slightly modified and better version of the software trigger. Includes LED output on Pin 13 irrespective of communications.
uint16_t bufa; // 4 buffers of 256 readings
uint16_t bufb; // 4 buffers of 256 readings
bool firstrun = 0;
int t; //time since last event
float maxcount;
float slowfreq; //second frequency measure,
//int f;
int evt; //event
void setup() {
Serial.begin(115200);
@pingud98
pingud98 / Cosmic Pi Trigger Threshold test
Last active October 16, 2016 15:05
Cosmic Pi Trigger Threshold test
#include <Wire.h>
//this test works when testing with boards 1 and 2
//set the threshold as a 1 time value, max is 3.3V (voltage reference removed from protos)
//crashes due to 50Hz noise
//input thresholds not checked 100%
//minimum input signal duration 40ns for coincidence.
//at 40ns incident coincidence the output lasts for 150ns - plenty for the DUE to capture.
//Hardware is more reliable than DUE's noise immunity.
//Note the MAX5387LAUD+ doesn't support I2C readback.
@pingud98
pingud98 / Cosmic_Pi_PSU_Control
Created October 16, 2016 21:04
Power supply chip (MAX1932) control routine inc. bit banging for SPI.
//Cosmic Pi Power supply open loop controller
//sets a value to the PSU and then increments it every n seconds.
//MAX1923 chip, with the following resistor values for feedback:
//R6 = 25k
//R5 = 200k
//R8 = 10k
//the old routine has been amended to fix the endian type (now correct)
@pingud98
pingud98 / Cosmic_Pi_Analogue_LED_flash
Created October 20, 2016 21:57
Use this script to test the red/blue LED on the Cosmic Pi Analogue Board V2.2. Note it doesn't work when connected to the Main Board due to missing connections on main board V2 alpha
//flash the red/blue LED on the cosmic Pi analogue board when
//it's connected directly to the Arduino DUE
void setup() {
Serial.begin(115200);
Serial.println("Cosmic Pi Status: Alive");
//pinMode(13, OUTPUT);
pinMode(A1, OUTPUT);
@pingud98
pingud98 / CosmicPiPSUProfiler
Created November 23, 2016 22:27
Use to profile the voltage range from the CosmicPi BIAS psu
//Cosmic Pi Power supply open loop controller
//sets a value to the PSU and then increments it every n seconds.
//MAX1923 chip, with the following resistor values for feedback:
//R6 = 25k
//R5 = 200k
//R8 = 10k
//the old routine has been amended to fix the endian type (now correct)
@pingud98
pingud98 / DUEUniqueID
Created December 4, 2016 16:59
How to get the Unique ID from an Arduino DUE board
/* Code borrowed from http://forum.arduino.cc/index.php?topic=289190.0
Awesome work Mark T!*/
__attribute__ ((section (".ramfunc")))
void _EEFC_ReadUniqueID( unsigned int * pdwUniqueID )
{
unsigned int status ;
@pingud98
pingud98 / arduino-due_high-speed-ADC.ino
Created December 16, 2016 11:09 — forked from pklaus/arduino-due_high-speed-ADC.ino
Arduino Due: ADC → DMA → USB @ 1MSPS
#undef HID_ENABLED
// Arduino Due ADC->DMA->USB 1MSPS
// by stimmer
// from http://forum.arduino.cc/index.php?topic=137635.msg1136315#msg1136315
// Input: Analog in A0
// Output: Raw stream of uint16_t in range 0-4095 on Native USB Serial/ACM
// on linux, to stop the OS cooking your data:
// stty -F /dev/ttyACM0 raw -iexten -echo -echoe -echok -echoctl -echoke -onlcr
@pingud98
pingud98 / CosmicOscilloscope
Created December 16, 2016 12:42
Use ADC->DMA to render Cosmic Pi sampling as an oscilloscope on a PC running Python based on https://gist.github.com/pklaus/5921022
#undef HID_ENABLED
// Arduino Due ADC->DMA->USB 1MSPS
// by stimmer
// from http://forum.arduino.cc/index.php?topic=137635.msg1136315#msg1136315
// Input: Analog in A0
// Output: Raw stream of uint16_t in range 0-4095 on Native USB Serial/ACM
// on linux, to stop the OS cooking your data:
// stty -F /dev/ttyACM0 raw -iexten -echo -echoe -echok -echoctl -echoke -onlcr