Hallo,
Voor school moet ik een project maken met Arduino. Ik gebruik hierbij de analoge 16 ch CD74HC4067 multiplexer samen met een SD shield datalogger.
Ik werk met zeven verschillende sensoren waarvan drie verbonden zijn met arduino zelf en vier verbonden zijn met de multiplexer.
Ik krijg het maar niet te goei!
Apart werkt elke sensor wel goed, maar ze allemaal tegelijk runnen geeft ongeloofwaardige waardes.
Weet er iemand raad.. of wat ik fout doet? Want ik zie het niet meer
Ik ben nieuw hier, dus wist niet goed hoe ik de code moest toevoegen,
dan maar op deze manier:
#include <math.h>
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <SD.h>
RTC_DS1307 RTC;
//Digitale paarten
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
//SIG pin
int SIG_pin = 0;
// hartslag
// Variables
int pulsePin = 1; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin
// Volatile Variables, used in the interrupt service routine!
volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false; // becomes true when Arduoino finds a beat.
// Regards Serial OutPut -- Set This Up to your needs
static boolean serialVisual = true; // Set to 'false' by Default. Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
const int xBpin = readMux (5); // x-axis of the accelerometer
const int yBpin = readMux (6); // y-axis
const int zBpin = readMux (7); // z-axis (only on 3-axis models)
const int xHpin = readMux (1); // x-axis of the accelerometer
const int yHpin = readMux (2); // y-axis
const int zHpin = readMux (3); // z-axis (only on 3-axis models)
int readMux(int channel){
int controlPin[] = {s0, s1, s2, s3};
int muxChannel[16][4]={
{0,0,0,0}, //channel 0
{1,0,0,0}, //channel 1
{0,1,0,0}, //channel 2
{1,1,0,0}, //channel 3
{0,0,1,0}, //channel 4
{1,0,1,0}, //channel 5
{0,1,1,0}, //channel 6
{1,1,1,0}, //channel 7
{0,0,0,1}, //channel 8
{1,0,0,1}, //channel 9
{0,1,0,1}, //channel 10
{1,1,0,1}, //channel 11
{0,0,1,1}, //channel 12
{1,0,1,1}, //channel 13
{0,1,1,1}, //channel 14
{1,1,1,1} //channel 15
};
//loop through the 4 sig
//for(int i = 0; i < 4; i ++){
//digitalWrite(controlPin_, muxChannel[channel]);_
* //}*
* //read the value at the SIG pin*
* int val = analogRead(SIG_pin);
_ //return the value*_
* return val;*
* }*
void setup()
* {*
* pinMode(s0, OUTPUT); *
* pinMode(s1, OUTPUT); *
* pinMode(s2, OUTPUT); *
* pinMode(s3, OUTPUT); *
* //hartslag*
* pinMode(blinkPin,OUTPUT); *
* pinMode(fadePin,OUTPUT); *
* interruptSetup(); *
* Serial.begin(57600);*
* Wire.begin();*
* RTC.begin();*
* if (! RTC.isrunning()) {*
* Serial.println("RTC is NOT running!");*
* RTC.adjust(DateTime(DATE, TIME));
_ }*_
* Serial.print("Initializing SD card...");*
* pinMode(10, OUTPUT);*
* if (!SD.begin(4)) {*
* Serial.println("initialization failed!");*
* return;*
* }*
* Serial.println("initialization done.");*
* // accelerometer*
* analogReference(EXTERNAL);*
* pinMode(xBpin, INPUT);*
* pinMode(yBpin, INPUT);*
* pinMode(zBpin, INPUT);*
* pinMode(xHpin, INPUT);*
* pinMode(yHpin, INPUT);*
* pinMode(zHpin, INPUT);*
}
* //code temperatuur*
* double Thermister(int RawADC) *
*{ *
* double Temp;*
* Temp = log(((10240000/RawADC) - 10000));*
_ Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
* Temp = Temp - 273.15; *
* return Temp; *
}
void loop()
{
File myFile = SD.open("Data.txt", FILE_WRITE);
if(myFile)
_{
* DateTime now = RTC.now();*
* myFile.print(now.day(), DEC);*
* myFile.print('/');*
* myFile.print(now.month(), DEC);*
* myFile.print('/');*
* myFile.print(now.year(), DEC);*
* myFile.print("\t");*
* myFile.print(now.hour(), DEC);*
* myFile.print(':');*
* myFile.print(now.minute(), DEC);*
* myFile.print(':');*
* myFile.print(now.second(), DEC);*
* myFile.print("\t");*
* Serial.print(now.day(), DEC);*
* Serial.print('/');*
* Serial.print(now.month(), DEC);*
* Serial.print('/');*
* Serial.print(now.year(), DEC);*
* Serial.print("\t");*
* Serial.print(now.hour(), DEC);*
* Serial.print(':');*
* Serial.print(now.minute(), DEC);*
* Serial.print(':');*
* Serial.print(now.second(), DEC);*
* Serial.print("\t");*
* {*
* //temperatuur*
* int value; //Create an integer variable*
* double temp; //Variable to hold a temperature value*
* value=readMux(0); //Read the analog port 0 and store the value in val*
* temp=Thermister(value); //Runs the fancy math on the raw analog value*
* //Serial.println(temp); //Print the value to the serial port*
* Serial.print("Temperatuur= " + String (temp) + " graden ");*
* //ademhaling*
* int ademhaling = analogRead (2);*
* myFile.print("Resp:\t" + String (ademhaling) + "\t");*
* Serial.print("Resp:\t" + String (ademhaling) + "\t");*
* //gsr sensor*
* int gsrValue = readMux(4);*
* myFile.print("GSR:\t" + String ( gsrValue) + "\t");*
* Serial.print("GSR:\t" + String ( gsrValue) + "\t");*
* //vibratie*
* int vibratie = analogRead (3);*
* myFile.print("Vbr:\t" + String ( vibratie) + "\t");*
* Serial.print("Vbr:\t" + String ( vibratie) + "\t");*
* //accelerometer hoofd*
* float zeroH_G = 512.0;
_ float scaleH = 106; *_
* const int xHpin = readMux (1);*
* int xH = analogRead(xHpin);*
* myFile.print("aXH:\t" + String (((float)xH - zeroH_G)/scaleH) + "\tg\t");
Serial.print("aXH:\t" + String (((float)xH - zeroH_G)/scaleH) + "\tg\t");*
* const int yHpin = readMux (2);*
* int yH = analogRead(yHpin);*
* myFile.print("aYH:\t" + String (((float)yH - zeroH_G)/scaleH) + "\tg\t");
Serial.print("aYH:\t" + String (((float)yH - zeroH_G)/scaleH) + "\tg\t");*
* const int zHpin = readMux (3);*
* int zH = analogRead(zHpin);*
* myFile.print("aZH:\t" + String (((float)zH - zeroH_G)/scaleH) + "\tg\t");
Serial.print("aZH:\t" + String (((float)zH - zeroH_G)/scaleH) + "\tg\t");*
* //accelerometer been*
* float zeroB_G = 512.0;
_ float scaleB = 106; *_
* const int xBpin = readMux (5);*
* int xB = analogRead(xBpin);*
* myFile.print("aXB:\t" + String (((float)xB - zeroB_G)/scaleB) + "\tg\t");
Serial.print("aXB:\t" + String (((float)xB - zeroB_G)/scaleB) + "\tg\t");*
* const int yBpin = readMux (6);*
* int yB = analogRead(yBpin);*
* myFile.print("aYB:\t" + String (((float)yB - zeroB_G)/scaleB) + "\tg\t");
Serial.print("aYB:\t" + String (((float)yB - zeroB_G)/scaleB) + "\tg\t");*
* const int zBpin = readMux (7);*
* int zB = analogRead(zBpin);*
* myFile.print("aZB:\t" + String (((float)zB - zeroB_G)/scaleB) + "\tg\t");
Serial.print("aZB:\t" + String (((float)zB - zeroB_G)/scaleB) + "\tg\t");*
* //harstlag*
* serialOutput() ; *
* if (QS == true){ *
* digitalWrite(blinkPin,HIGH); // Blink LED, we got a beat. *
* fadeRate = 255; *
* serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial. *
* QS = false; // reset the Quantified Self flag for next time *
* }*
* ledFadeToBeat(); // Makes the LED Fade Effect Happen*
* myFile.print("Hartslag:\t" + String (BPM) + "\tBPM\t"); *
* }*
* Serial.println();*
* myFile.println(); *
* delay (100);*
myFile.close();}
}
void ledFadeToBeat(){
* fadeRate -= 15; // set LED fade value*
* fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!*
* analogWrite(fadePin,fadeRate); // fade LED*
* } *
DE_CODE.ino (7.54 KB)