From 4764fb9bab8a2b3c2819de4ac882b23b742fe248 Mon Sep 17 00:00:00 2001 From: dtb Date: Tue, 1 Aug 2023 21:25:54 -0400 Subject: [PATCH] beginning of gyro code --- tekubi/main.ino | 119 +++++++++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 47 deletions(-) diff --git a/tekubi/main.ino b/tekubi/main.ino index 28b8726..4549d9b 100644 --- a/tekubi/main.ino +++ b/tekubi/main.ino @@ -1,69 +1,94 @@ -#include -#include +/* TEKUBI + * ___________ ____________________________ + * | | | | + * | USB POWER | | TEENSY 4.0 | + * | | | | + * |__GND__5V__| |__Vin__GND__D3__SDA0__SCL0__| + * | | | | | | | + * | +--------+----|---|-+--|-----|----------+ + * | | | | | | | | + * +----|-------------+---|-|--|-----|----------|----+ + * | | | | | | | | | + * | | +---------|---+ | +---+ | | | + * __ | __ |__ | __ __ | __ |____ | | ____ | __ | __ + * | GND 5V INT | | GND Vcc | | | | Vcc GND | + * | (100mA?) | | (10mA) SDA--+-|----SDA (4mA) | + * | | | | | | | + * | GEIGER COUNTER | | GYRO SCL----+----SCL ECG | + * |________________| |______________| |______________| */ -/* https://github.com/jrowberg/i2cdevlib/ */ -#include "I2Cdev.h" -#include "MPU6050.h" - -#define RAD_LOG_PERIOD 5000 /* milliseconds; sample rate */ -#define MINUTE 60000 /* milliseconds in a minute */ - -/* USB power - * 5V -> Teensy Vin (100mA) - * GND -> Teensy GND - - * 5V -> Geiger 5V (100mA?) - * GND -> Geiger GND - - * 5V -> Gyro Vcc (10mA) - * GND -> Gyro GND - - * 5V -> ECG Vcc (4mA) - * GND -> ECG GND */ - -/* teensy 4.0 - * https://www.pjrc.com/store/teensy40.html */ /* geiger counter * https://www.rhelectronics.store * /radiation-detector-geiger-counter-diy-kit-second-edition * INT -> Teensy D3 */ +#include +#define RAD_LOG_PERIOD 5000 /* milliseconds; sample rate */ +#define MINUTE 60000 /* milliseconds in a minute */ +/* https://www.arduino.cc/reference/en/language/variables/data-types/ + * unsignedlong/ - 32 bit */ +unsigned long rad_count = 0; +unsigned long rad_cpm; +void rad_interrupt(){ ++rad_count; } +/* https://www.pjrc.com/teensy/td_timing_elaspedMillis.html */ +elapsedMillis rad_period = 0; +void geiger_setup(){ + pinMode(3, INPUT); + digitalWrite(3, HIGH); + attachInterrupt(0, rad_interrupt, FALLING); +} +void geiger_loop(){ + if(rad_period > RAD_LOG_PERIOD){ + rad_cpm = rad_count * (MINUTE / RAD_LOG_PERIOD); + rad_period = 0; + } + /* use rad_cpm */ +} /* gyro * https://www.elecrow.com/crowtail-mpu6050-accelerometer-gyro.html * SDA -> Teensy SDA0 * SCL -> Teensy SCL0 */ +/* https://github.com/jrowberg/i2cdevlib/ + * Most inexplicable stuff is because it was in Arduino/MPU6050/examples/ + * MPU6050_raw/MPU6050_raw.ino */ +#include "I2Cdev.h" +#include "MPU6050.h" +#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE +# include "Wire.h" +#endif +MPU6050 accelgyro; +int16_t accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z; +void gyro_setup(){ + #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE + Wire.begin(); + #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE + Fastwire::setup(400, true); + #endif + accelgyro.initialize(); +} +void gyro_loop(){ + accelgyro.getMotion6(&accel_x, &accel_y, &accel_z, + &gyro_x, &gyro_y, &gyro_z); + /* use accel_*, gyro_* */ +} /* ecg * https://www.elecrow.com/crowtail-pulse-sensor-p-1673.html * SDA -> Teensy SDA0 * SCL -> Teensy SCL0 */ - - -unsigned long rad_count = 0; -unsigned long rad_cpm; -/* https://www.pjrc.com/teensy/td_timing_elaspedMillis.html */ -elapsedMillis rad_period = 0; - -void rad_interrupt(){ - ++rad_count; +void ecg_setup(){ + /* I2C is set up in gyro_setup */ } +/* teensy 4.0 + * https://www.pjrc.com/store/teensy40.html */ void setup(){ - - /* geiger counter */{ - pinMode(3, INPUT); - digitalWrite(3, HIGH); - attachInterrupt(0, rad_interrupt, FALLING); - } + geiger_setup(); + gyro_setup(); + ecg_setup(); } - void loop(){ - - /* geiger counter */{ - if(rad_period > RAD_LOG_PERIOD){ - rad_cpm = rad_count * (MINUTE / RAD_LOG_PERIOD); - rad_period = 0; - } - } + geiger_loop(); + gyro_loop(); }