Skip to content
Snippets Groups Projects
Commit 8c4ba3ad authored by Myres's avatar Myres
Browse files

Merge branch 'master' of git.rwth-aachen.de:nloqo/arduino-sketches

parents aaf7aa61 c54a39d6
No related branches found
No related tags found
No related merge requests found
#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();
if(test){
int sum = 0;
for (int i = 0; i < length; i++){ // summs over all values
sum += buf[i];
//Serial.println("Test");
if(triggerOn == false && triggerMeasure == HIGH){
HIGHcount++;
triggerOn = true;
//Serial.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaa");
if(adc1.available() /*&& Serial.available()*/){
Serial.print(sum); // sends sum of Data
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){
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 j = 0; j < length; j++){ // sends Data sep with tab
Serial.print(buf[j]);
Serial.print("\t");
for (int i = 0; i < length; i++){
sum += buf[i];
}
Serial.println(sum);
}
Serial.print("\n");
break;
}
sum = 0;
buf.release();
}
}
else if (triggerOn == true && triggerMeasure == LOW){//LOW oder 0
else if (triggerOn && triggerMeasure == LOW){
triggerOn = false;
}
}
/*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()){
//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();
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;
}
}
//for (int i = 0; i < 30; i++){
//Serial.write(buf[i]);
//}
Serial.write(*mySensVals,5);
buf.release();
Serial.println();
//delay(1000);
}
}
}
\ No newline at end of file
# **
# -*- 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()
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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment