diff --git a/PDreadout/LeifTest/LeifTest.ino b/PDreadout/LeifTest/LeifTest.ino index 44e5d97f06ed17fbdc13cdb010baa3351355e913..4015d998f9bc56a2c61b6f1f3003dee6058145ed 100644 --- a/PDreadout/LeifTest/LeifTest.ino +++ b/PDreadout/LeifTest/LeifTest.ino @@ -1,51 +1,70 @@ #include <Arduino_AdvancedAnalog.h> -AdvancedADC adc(A0); -int length = 15000; +AdvancedADC adc1(A0); +const int length = 15000; int triggerPin = 2; + +int iterration = 0; + bool triggerOn = false; -int triggerMeasure = 0; -bool test = false; //if true sends sum over Signal else all siganls sep with tab +int triggerMeasure; +int HIGHcount = 0; +int LOWcount = 0; +int sum = 0; +bool test = false; +//SampleBuffer buf = adc1.read(); void setup() { Serial.begin(921600); - pinMode(2, INPUT); - if (!adc.begin(AN_RESOLUTION_16, 500000, length, 2 * length)) { - Serial.println("Failed to start analog acquisition!"); + pinMode(triggerPin, INPUT); + // Initialize ADC with: resolution, sample rate, number of samples per channel, queue depth + if (!adc1.begin(AN_RESOLUTION_8, 1000000, length, 10)) { + Serial.println("Failed to start ADC!"); while (1); } } void loop() { + // Check if an ADC measurement is ready triggerMeasure = digitalRead(triggerPin); - if (triggerOn == false && triggerMeasure == HIGH){ //HIGH oder 1 nicht ganz sicher - triggerOn = true;c:\Repositories\arduino-sketches\PDreadout\test\test.ino - if (adc.available()){ - Serial.println("adc1 available."); - SampleBuffer buf = adc.read(); + //Serial.println("Test"); + if(triggerOn == false && triggerMeasure == HIGH){ + HIGHcount++; + triggerOn = true; + //Serial.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + if(adc1.available() /*&& Serial.available()*/){ + + SampleBuffer buf = adc1.read(); + char input[20]; + int len; + len = Serial.readBytesUntil('\n', input ,20); + input[len] = '\0'; + //Serial.println("Test1111111111111111111111"); + switch (input[0]){ + case 'r': if(test){ - int sum = 0; - for (int i = 0; i < length; i++){ // summs over all values - sum += buf[i]; - - Serial.print(sum); // sends sum of Data - - } - }else{ - for(int j = 0; j < length; j++){ // sends Data sep with tab - Serial.print(buf[j]); + for (int i = 0; i < length; i++){ + Serial.print(buf[i]); Serial.print("\t"); + //Serial.write(buf[i]); // Send high byte + + } + Serial.println(); + }else{ + for (int i = 0; i < length; i++){ + sum += buf[i]; } + Serial.println(sum); + } + break; } - Serial.print("\n"); - + sum = 0; buf.release(); } - } - else if (triggerOn == true && triggerMeasure == LOW){//LOW oder 0 - triggerOn = false; + else if (triggerOn && triggerMeasure == LOW){ + triggerOn = false; + } } - diff --git a/PDreadout/test/test.ino b/PDreadout/test/test.ino index aef9cc27c61396cf280393e44f8ed0072f26e4a0..d4e1e23087fc91ea857d10d4765633a2f71da0ee 100644 --- a/PDreadout/test/test.ino +++ b/PDreadout/test/test.ino @@ -1,30 +1,71 @@ +/*const int sampleSize = 15000; +int sampleBuffer[sampleSize]; +void setup() { + Serial.begin(9600); // Set baud rate + + // Fill sampleBuffer with your data + for (int i = 0; i < sampleSize; i++) { + sampleBuffer[i] = analogRead(A0); // Example of reading analog input + } +} + +void loop() { + if (Serial.available() > 0) { + if (Serial.read() == 'r') { // Trigger sending data when 'S' is received + + Serial.write(sampleBuffer); // Send high byte + //Serial.write((byte)(sampleBuffer[i] & 0xFF)); // Send low byte + + } + } +}*/ #include <Arduino_AdvancedAnalog.h> -int buffer = 0; +int length = 100; AdvancedADC adc1(A0); - +int mySensVals[5] = {2, 4, -8, 3, 2}; void setup() { - // put your setup code here, to run once: - Serial.begin(9600); - adc1.begin(AN_RESOLUTION_16, 400000000, 20000, 10); + + Serial.begin(921600); + if (!adc1.begin(AN_RESOLUTION_8, 1000000, length, 10)) { + Serial.println("Failed to start ADC!"); + while (1); + } } + void loop() { - // put your main code here, to run repeatedly: - if (adc1.available()){ - SampleBuffer buf = adc1.read(); - if ( Serial.available() ){ - char input[20]; - int len; - len = Serial.readBytesUntil('\n', input, 20); - input[len] = '\0'; // Null terminating the array to interpret it as a string - switch (input[0]){ - case 'r': - Serial.println(buf); - break; - } + + //Serial.write(45); // send a byte with the value 45 + //SampleBuffer buf = adc1.read(); + //for(int i = 0; i < 5 ; i++){ + //buf[i] = mySesVals[i]; + //} + + //Serial.write(buf); + //Serial.write(mySensVals); + //Serial.println(mySensVals[1]); + //buf.release(); + //Serial.println(); + //delay(1000); + + //int bytesSent = Serial.write("hello"); //send the string "hello" and return the length of the string. + if (Serial.available() > 0) { + if (Serial.read() == 'r') { // Trigger sending data when 'S' is received + SampleBuffer buf = adc1.read(); + //for (int i = 0; i < 30; i++){ + //Serial.write(buf[i]); + //} + + Serial.write(*mySensVals,5); + buf.release(); + Serial.println(); + //delay(1000); + } - buf.release(); } } + + + \ No newline at end of file diff --git a/PDreadout/test_singleSignalReadout/test_singleSignalReadout_evaluation.py b/PDreadout/test_singleSignalReadout/test_singleSignalReadout_evaluation.py index fe050fe4ec63ba58dca0f679251d726f76fdfce9..6f396e2df128d4929330590b878ef859c900c009 100644 --- a/PDreadout/test_singleSignalReadout/test_singleSignalReadout_evaluation.py +++ b/PDreadout/test_singleSignalReadout/test_singleSignalReadout_evaluation.py @@ -1,3 +1,4 @@ +# ** # -*- coding: utf-8 -*- """ Created on Mon Apr 29 10:27:53 2024 @@ -9,7 +10,7 @@ from devices import arduino import matplotlib.pyplot as plt import numpy as np -device = arduino.Arduino("COM14", timeout=5000, baud_rate=921600) +device = arduino.Arduino("COM73", timeout=5000, baud_rate=921600) data = device.ask("r") data = data.split("\t") @@ -39,3 +40,5 @@ print(f"Abtastrate: ({round(np.mean(rate) / 1e6, 3)} +/- {round(np.std(rate) / 1 print(f"Periode T: {round(1 / np.mean(rate) * 1e9, 0)} ns") device.close() del device + +plt.show() diff --git a/PDreadout/test_triggerCapture/test_test.ino b/PDreadout/test_triggerCapture/test_test.ino deleted file mode 100644 index 4fe74a7003b1ebe49860ea2397e2e7c06c77797c..0000000000000000000000000000000000000000 --- a/PDreadout/test_triggerCapture/test_test.ino +++ /dev/null @@ -1,38 +0,0 @@ -const long length = 100000; -int triggerValues[length]; -int iteration = 0; -long start = 0; -long end = 0; - -void setup() { - // put your setup code here, to run once: - Serial.begin(9600); - pinMode(2, INPUT); -} - -void loop() { - int trigger = digitalRead(2); - triggerValues[iteration] = trigger; - iteration += 1; - if (iteration == length){ - end = micros(); - iteration = 0; - if ( Serial.available() ){ - char input[20]; - int len; - len = Serial.readBytesUntil('\n', input, 20); - input[len] = '\0'; // Null terminating the array to interpret it as a string - switch (input[0]){ - case 'r': - for (int i = 0; i < length; i++){ - Serial.print(triggerValues[i]); - Serial.print("\t"); - } - Serial.print(end - start); - Serial.println(); - break; - } - } - start = micros(); - } -}