Skip to content

Instantly share code, notes, and snippets.

// Output sine wave with frequency sweep between 100Hz and 10kHz (32 samples) on analog pin A0 using the DAC and DMAC
// Generously initially donated by MartinL2
// Written for M0. Tested on Adafruit Feather M0 with ATWINC-1500 WiFi
//
// BDL change to 100Hz to 25000Hz
// BDL change to sweep in frequency, rather than period. This makes it look better on an FFT
// BDL change to have constant power in FFT bins. Each frequency operates for the same amount of time yielding constant
// power in the FFT
// Uploaded to Adafruit forum 17 July 2019
// Output sine wave with frequency sweep between 100Hz and 10kHz (32 samples) on analog pin A0 using the DAC and DMAC
// Generously initially donated by MartinL2
// Written for M0. Tested on Adafruit Feather M0 with ATWINC-1500 WiFi
//
// BDL change to 100Hz to 25000Hz
// BDL change to sweep in frequency, rather than period. This makes it look better on an FFT
// BDL change to have constant power in FFT bins. Each frequency operates for the same amount of time yielding constant
// power in the FFT
// Uploaded to Adafruit forum 17 July 2019
@dwblair
dwblair / conduct.ino
Created February 5, 2020 16:46
basic_conductivity_measure / samdX1
#include <Arduino.h>
#include "Adafruit_ZeroTimer.h"
// This example can have just about any frequency for the callback
// automatically calculated!
float freq = 20000.0; // the actual frequency seems to be half of this
// timer tester
Adafruit_ZeroTimer zerotimer = Adafruit_ZeroTimer(3);
import serial
from collections import OrderedDict
import numpy as np
#import IPython;IPython.embed() # USE ME FOR DEBUGGING
################################################################################
PORT = '/dev/ttyACM1'
BAUD = 115200
DEBUG = True
// temp variables
// which analog pin to connect
#define THERMISTORPIN A0
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
import serial
PORT='/dev/ttyACM0'
s=serial.Serial(PORT,115200,timeout=1)
SIZE = 1
NUM = 1000
RES = 12
RATE = 10
import serial
PORT='/dev/ttyACM0'
OUTFILE='out.csv'
#f=open(OUTFILE,"w+")
#f=open(OUTFILE,"a+")
s=serial.Serial(PORT,115200,timeout=1)
import serial
PORT='/dev/ttyACM0'
OUTFILE='out.csv'
NUM_SAMPLES = 1000
f=open(OUTFILE,"w+")
s=serial.Serial(PORT,115200,timeout=1)
('2219435784', '204')
2
uS:2.04
3
['116', '89', '6', '36', '117', '87', '6', '38', '119', '85', '4', '40', '120', '82', '3', '42', '120', '80', '3', '46', '121', '77', '1', '48', '122', '74', '1', '50', '122', '73', '1', '53', '123', '70', '0', '55', '123', '67', '0', '57', '124', '65', '0', '61', '123', '62', '0', '63', '124', '60', '0', '66', '123', '57', '0', '68', '123', '55', '0', '70', '123', '52', '1', '73', '123', '49', '1', '76', '122', '47', '2', '78', '121', '43', '2', '80', '120', '42', '3', '82', '120', '40', '10', '85', '119', '37', '5', '87', '118', '35', '6', '90', '117', '33', '8', '91', '115', '30', '9', '94']
4
('2220435784', '204')
5
uS:2.04
6
#include <Arduino.h>
#include "Adafruit_ZeroTimer.h" // https://github.com/dwblair/Adafruit_ZeroTimer
// timer 3 ----------------------
float freq3 = 1; // 10 Hz
volatile bool togglepin = false;
volatile bool togglepin2 = false;