beginning of gyro code
This commit is contained in:
parent
7cdd6cefe5
commit
4764fb9bab
119
tekubi/main.ino
119
tekubi/main.ino
@ -1,69 +1,94 @@
|
|||||||
#include <SPI.h>
|
/* TEKUBI
|
||||||
#include <Wire.h>
|
* ___________ ____________________________
|
||||||
|
* | | | |
|
||||||
|
* | 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
|
/* geiger counter
|
||||||
* https://www.rhelectronics.store
|
* https://www.rhelectronics.store
|
||||||
* /radiation-detector-geiger-counter-diy-kit-second-edition
|
* /radiation-detector-geiger-counter-diy-kit-second-edition
|
||||||
* INT -> Teensy D3 */
|
* INT -> Teensy D3 */
|
||||||
|
#include <SPI.h>
|
||||||
|
#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
|
/* gyro
|
||||||
* https://www.elecrow.com/crowtail-mpu6050-accelerometer-gyro.html
|
* https://www.elecrow.com/crowtail-mpu6050-accelerometer-gyro.html
|
||||||
* SDA -> Teensy SDA0
|
* SDA -> Teensy SDA0
|
||||||
* SCL -> Teensy SCL0 */
|
* 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
|
/* ecg
|
||||||
* https://www.elecrow.com/crowtail-pulse-sensor-p-1673.html
|
* https://www.elecrow.com/crowtail-pulse-sensor-p-1673.html
|
||||||
* SDA -> Teensy SDA0
|
* SDA -> Teensy SDA0
|
||||||
* SCL -> Teensy SCL0 */
|
* SCL -> Teensy SCL0 */
|
||||||
|
void ecg_setup(){
|
||||||
|
/* I2C is set up in gyro_setup */
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* teensy 4.0
|
||||||
|
* https://www.pjrc.com/store/teensy40.html */
|
||||||
void setup(){
|
void setup(){
|
||||||
|
geiger_setup();
|
||||||
/* geiger counter */{
|
gyro_setup();
|
||||||
pinMode(3, INPUT);
|
ecg_setup();
|
||||||
digitalWrite(3, HIGH);
|
|
||||||
attachInterrupt(0, rad_interrupt, FALLING);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
|
geiger_loop();
|
||||||
/* geiger counter */{
|
gyro_loop();
|
||||||
if(rad_period > RAD_LOG_PERIOD){
|
|
||||||
rad_cpm = rad_count * (MINUTE / RAD_LOG_PERIOD);
|
|
||||||
rad_period = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user