Upload files to 'Archiv'
parent
25c3f1c6b6
commit
25dd894210
|
@ -0,0 +1,33 @@
|
||||||
|
const int adcPin = A0; // ADC-Pin
|
||||||
|
const int serialBaudRate = 115200; // Baudrate des seriellen Monitors
|
||||||
|
const float toggleDelay = 0.2; // Verzögerung zwischen dem Umschalten der Bits, in Mikrosekunden
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(serialBaudRate); // Starten des seriellen Monitors
|
||||||
|
analogReadResolution(12);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
uint32_t buffer[8] = {0}; // Initialisierung des Puffer-Arrays mit Nullen
|
||||||
|
uint8_t bitCount = 0; // Anzahl der erzeugten Bits
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
uint32_t randomValue = 0; // Initialisierung der zufälligen Zahl
|
||||||
|
|
||||||
|
while (bitCount < 32) {
|
||||||
|
uint16_t adcValue = analogRead(adcPin); // Lesen des ADC-Werts
|
||||||
|
uint32_t newBit = adcValue & 0x01; // Extrahieren des LSB aus dem ADC-Wert
|
||||||
|
randomValue = (randomValue << 1) | newBit; // Hinzufügen des neuen Bits an das LSB
|
||||||
|
bitCount++; // Inkrementierung der Anzahl der erzeugten Bits
|
||||||
|
delay(toggleDelay); // Verzögerung
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[i] = randomValue; // Speichern des zufälligen Werts im Puffer-Array
|
||||||
|
bitCount = 0; // Zurücksetzen der Anzahl der erzeugten Bits
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
Serial.write((byte*)&buffer[i], sizeof(buffer[i])); // Ausgabe der erzeugten 32-Bit-Werte als Bitfolge
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
import os
|
||||||
|
import serial
|
||||||
|
import time
|
||||||
|
|
||||||
|
ser = serial.Serial('COM3', 9600) # change port to input port from arduino
|
||||||
|
filename = 'mitNeumann_0_5'
|
||||||
|
|
||||||
|
start_time = time.time() # start time of read
|
||||||
|
|
||||||
|
with open(filename, 'wb') as file:
|
||||||
|
while os.path.getsize(filename) < 100000: # change to the desired file size in bits
|
||||||
|
if ser.in_waiting > 0:
|
||||||
|
data = ser.read(ser.in_waiting) # reading the data input from COM port
|
||||||
|
print(data)
|
||||||
|
file.write(data)
|
||||||
|
file.flush() # flush data to write
|
||||||
|
|
||||||
|
end_time = time.time() # end time of read
|
||||||
|
elapsed_time = end_time - start_time
|
||||||
|
|
||||||
|
seconds = int(elapsed_time)
|
||||||
|
milliseconds = int((elapsed_time % 1) * 100)
|
||||||
|
|
||||||
|
new_filename = f"{filename.split('.')[0]}_TimeInSeconds_{seconds}_{milliseconds}.txt" # filename in format filename_seconds_milliseconds as txt with needed time to finish read
|
||||||
|
|
||||||
|
os.rename(filename, new_filename) # change filename to new filename
|
||||||
|
|
||||||
|
print(f"time needed in seconds: {elapsed_time:.2f}. New filename: {new_filename}.") # console write
|
|
@ -0,0 +1,51 @@
|
||||||
|
import os
|
||||||
|
import serial
|
||||||
|
import string
|
||||||
|
import time
|
||||||
|
|
||||||
|
def is_hex(char):
|
||||||
|
return char in string.hexdigits
|
||||||
|
|
||||||
|
def convert_to_binary_string(filename):
|
||||||
|
# Open the file in binary mode
|
||||||
|
with open(filename, 'rb') as f:
|
||||||
|
# Read the contents of the file as bytes
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
# Convert the bytes to a string of binary digits
|
||||||
|
binary_str = ''.join(format(byte, '08b') for byte in content)
|
||||||
|
|
||||||
|
new_filename = f"{filename.split('.')[0]}_readable.txt" # filename in readable .txt format with Chars
|
||||||
|
|
||||||
|
|
||||||
|
# Write the binary string back to the file
|
||||||
|
with open(new_filename, 'w') as f:
|
||||||
|
f.write(binary_str)
|
||||||
|
|
||||||
|
ser = serial.Serial('COM3', 115200) # change port to input port from arduino
|
||||||
|
filename = 'baud115200_0_2_TEST'
|
||||||
|
|
||||||
|
start_time = time.time() # start time of read
|
||||||
|
|
||||||
|
with open(filename, 'wb') as file:
|
||||||
|
while os.path.getsize(filename) < 2500: # change to the desired file size in bits/8 (1,000,000 Bits = 125000)
|
||||||
|
if ser.in_waiting > 0:
|
||||||
|
data = ser.read(ser.in_waiting) # reading the data input from COM port
|
||||||
|
print(data)
|
||||||
|
file.write(data)
|
||||||
|
file.flush() # flush data to write
|
||||||
|
|
||||||
|
# Convert the contents of the file to a binary string
|
||||||
|
convert_to_binary_string(filename)
|
||||||
|
|
||||||
|
end_time = time.time() # end time of read
|
||||||
|
elapsed_time = end_time - start_time
|
||||||
|
|
||||||
|
seconds = int(elapsed_time)
|
||||||
|
milliseconds = int((elapsed_time % 1) * 100)
|
||||||
|
|
||||||
|
new_filename = f"{filename.split('.')[0]}_TimeInSeconds_{seconds}_{milliseconds}.bin" # filename in format filename_seconds_milliseconds as txt with needed time to finish read
|
||||||
|
|
||||||
|
os.rename(filename, new_filename) # change filename to new filename
|
||||||
|
|
||||||
|
print(f"time needed in seconds: {elapsed_time:.2f}. New filename: {new_filename}.") # console write
|
Loading…
Reference in New Issue