diff --git a/Arduino_board_code.ino b/Arduino_board_code.ino index 2dea573..a46e718 100755 --- a/Arduino_board_code.ino +++ b/Arduino_board_code.ino @@ -6,8 +6,7 @@ #define BMP085_ADDRESS 0x77 // I2C address of BMP085 -#include "D:\Users\reuterc\Desktop\Slow control\Arduino_board_code\FreqCounter\FreqCounter.h" -#include "D:\Users\reuterc\Desktop\Slow control\Arduino_board_code\FreqCounter\FreqCounter.cpp" +#include int freq, offset, sens; @@ -56,13 +55,20 @@ void setup(){ void loop() { - //pressure sensor and temperature read out + // check for the command to write data to serial port + if ((!Serial.available()) || (Serial.read() != 'r')) { + return; + } + // + //pressure sensor and temperature read out + // float temperature = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first float pressure = bmp085GetPressure(bmp085ReadUP()); - - //magnetic field sensor read out - + + // + //magnetic field sensor read out + // int x,y,z; //triple axis data float x1,y1,z1,r; @@ -72,7 +78,7 @@ void loop() Wire.endTransmission(); - //Read data from each axis, 2 registers per axis + //Read data from each axis, 2 registers per axis Wire.requestFrom(0x1E, 6); if(6<=Wire.available()){ x = Wire.read()<<8; //X msb @@ -88,21 +94,20 @@ void loop() z1=((float)z*.73); r= (sqrt((square(x1))+(square(y1))+(square(z1)))); - - //humidity sensor readout - //Get Frequency - FreqCounter::f_comp= 8; // Set compensation to 12 - FreqCounter::start(1000); // Start counting with gatetime of 1000ms - while (FreqCounter::f_ready == 0) // wait until counter ready - freq=FreqCounter::f_freq; // read result + // + //humidity sensor readout + // + //Get Frequency + FreqCounter::f_comp= 8; // Set compensation to 12 + FreqCounter::start(1000); // Start counting with gatetime of 1000ms + while (FreqCounter::f_ready == 0) // wait until counter ready + freq=FreqCounter::f_freq; // read result //Calculate RH //float RH = (offset-freq)*sens/4096; //Sure, you can use int - depending on what do you need //float RH = ((float)(offset -freq))*(float)sens/4096.0; float RH = ((float)(offset -freq)*sens)/4096.0; - //delay(1000); //wait a second and get values again. - //print out the values as a final step Serial.print("temperature: "); diff --git a/FreqCounter.zip b/FreqCounter.zip new file mode 100644 index 0000000..a39c950 Binary files /dev/null and b/FreqCounter.zip differ diff --git a/FreqCounter/Examples/FreqCounterLib_example/FreqCounterLib_example.ino b/FreqCounter/Examples/FreqCounterLib_example/FreqCounterLib_example.ino deleted file mode 100755 index 95ce3e0..0000000 --- a/FreqCounter/Examples/FreqCounterLib_example/FreqCounterLib_example.ino +++ /dev/null @@ -1,44 +0,0 @@ -// Frequency Counter Lib example - -/* - Martin Nawrath KHM LAB3 - Kunsthochschule f¸r Medien Kˆln - Academy of Media Arts - http://www.khm.de - http://interface.khm.de/index.php/labor/experimente/ - */ -#include - - -unsigned long frq; -int cnt; -int pinLed=13; - -void setup() { - pinMode(pinLed, OUTPUT); - - Serial.begin(115200); // connect to the serial port - - Serial.println("Frequency Counter"); - -} - - - -void loop() { - - // wait if any serial is going on - FreqCounter::f_comp=10; // Cal Value / Calibrate with professional Freq Counter - FreqCounter::start(100); // 100 ms Gate Time - - while (FreqCounter::f_ready == 0) - - frq=FreqCounter::f_freq; - Serial.print(cnt++); - Serial.print(" Freq: "); - Serial.println(frq); - delay(20); - digitalWrite(pinLed,!digitalRead(pinLed)); // blink Led - -} - diff --git a/FreqCounter/Examples/FreqCounterLib_example/FreqCounterLib_example.pde b/FreqCounter/Examples/FreqCounterLib_example/FreqCounterLib_example.pde deleted file mode 100755 index 95ce3e0..0000000 --- a/FreqCounter/Examples/FreqCounterLib_example/FreqCounterLib_example.pde +++ /dev/null @@ -1,44 +0,0 @@ -// Frequency Counter Lib example - -/* - Martin Nawrath KHM LAB3 - Kunsthochschule f¸r Medien Kˆln - Academy of Media Arts - http://www.khm.de - http://interface.khm.de/index.php/labor/experimente/ - */ -#include - - -unsigned long frq; -int cnt; -int pinLed=13; - -void setup() { - pinMode(pinLed, OUTPUT); - - Serial.begin(115200); // connect to the serial port - - Serial.println("Frequency Counter"); - -} - - - -void loop() { - - // wait if any serial is going on - FreqCounter::f_comp=10; // Cal Value / Calibrate with professional Freq Counter - FreqCounter::start(100); // 100 ms Gate Time - - while (FreqCounter::f_ready == 0) - - frq=FreqCounter::f_freq; - Serial.print(cnt++); - Serial.print(" Freq: "); - Serial.println(frq); - delay(20); - digitalWrite(pinLed,!digitalRead(pinLed)); // blink Led - -} - diff --git a/FreqCounter/FreqCounter.cpp b/FreqCounter/FreqCounter.cpp deleted file mode 100755 index 8d7adac..0000000 --- a/FreqCounter/FreqCounter.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - FreqCounter.h - - Using Counter1 for counting Frequency on T1 / PD5 / digitalPin 5 - Using Timer2 for Gatetime generation - - Martin Nawrath KHM LAB3 - Kunsthochschule für Medien Köln - Academy of Media Arts - http://www.khm.de - http://interface.khm.de/index.php/labor/experimente/ - - History: - Dec/08 - V1.0 - Oct/10 - V1.1 removed occasional glitches through interference with - Jan/12 - V1.2 Arduino 1.0 - timer0 - set intterrupt timebase to 1ms - works with atmega328 - - - - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include - -unsigned long FreqCounter::f_freq; - -volatile unsigned char FreqCounter::f_ready; -volatile unsigned char FreqCounter::f_mlt; -volatile unsigned int FreqCounter::f_tics; -volatile unsigned int FreqCounter::f_period; -volatile unsigned int FreqCounter::f_comp; - -void FreqCounter::start(int ms) { - -#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__) - - - TIMSK0 &=~(1<= FreqCounter::f_period) { - // end of gate time, measurement ready - - // GateCalibration Value, set to zero error with reference frequency counter - // delayMicroseconds(FreqCounter::f_comp); // 0.01=1/ 0.1=12 / 1=120 sec - delayMicroseconds(FreqCounter::f_comp); - TCCR1B = TCCR1B & ~7; // Gate Off / Counter T1 stopped - TIMSK2 &= ~(1< -#if defined(ARDUINO) && ARDUINO >= 100 -#include "Arduino.h" -#else -#include "WProgram.h" -#endif - -namespace FreqCounter { - - extern unsigned long f_freq; - extern volatile unsigned char f_ready; - extern volatile unsigned char f_mlt; - extern volatile unsigned int f_tics; - extern volatile unsigned int f_period; - extern volatile unsigned int f_comp; - - void start(int ms); - - -} - -#endif - - - - -