Upload files to 'Archiv'
parent
008137f82b
commit
25c3f1c6b6
|
@ -0,0 +1,16 @@
|
||||||
|
import Adafruit_ADS1x15
|
||||||
|
|
||||||
|
adc = Adafruit_ADS1x15.ADS1115(address=0x48, busnum=1)
|
||||||
|
|
||||||
|
binary_string = ''
|
||||||
|
random_number = 0
|
||||||
|
|
||||||
|
for i in range(1024):
|
||||||
|
raw_value = adc.read_adc(0, gain=1)
|
||||||
|
|
||||||
|
lsb =(raw_value & 0x01) << i
|
||||||
|
|
||||||
|
#binary_string= bin(lsb)[2:].zfill(32) + binary_string
|
||||||
|
random_number |= lsb
|
||||||
|
|
||||||
|
print("Random Number:", random_number)
|
|
@ -0,0 +1,48 @@
|
||||||
|
#include <wiringPi.h>
|
||||||
|
#include <wiringPiI2C.h>
|
||||||
|
|
||||||
|
const int adcAddr = 0x48; // ADC address
|
||||||
|
const int serialBaudRate = 115200; // Serial monitor baud rate
|
||||||
|
const float toggleDelay = 0.2; // Delay between toggling bits, in microseconds
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int fd; // File descriptor for I2C device
|
||||||
|
uint32_t buffer[8] = {0}; // Initialize buffer array with zeroes
|
||||||
|
uint8_t bitCount = 0; // Number of generated bits
|
||||||
|
|
||||||
|
// Initialize WiringPi and open I2C device
|
||||||
|
wiringPiSetup();
|
||||||
|
fd = wiringPiI2CSetup(adcAddr);
|
||||||
|
|
||||||
|
// Print buffer values in binary format
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
uint32_t randomValue = 0; // Initialize random value
|
||||||
|
|
||||||
|
while (bitCount < 32) {
|
||||||
|
uint16_t adcValue = wiringPiI2CReadReg16(fd, 0x00); // Read ADC value
|
||||||
|
uint32_t newBit = adcValue & 0x01; // Extract LSB from ADC value
|
||||||
|
randomValue = (randomValue << 1) | newBit; // Add new bit to LSB
|
||||||
|
bitCount++; // Increment number of generated bits
|
||||||
|
delayMicroseconds(toggleDelay); // Delay
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[i] = randomValue; // Save random value in buffer array
|
||||||
|
bitCount = 0; // Reset number of generated bits
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print buffer values in binary format
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
Serial.print(formatBinary(buffer[i])); // Print generated 32-bit values in binary format
|
||||||
|
}
|
||||||
|
Serial.println(); // New line to separate from other outputs
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
String formatBinary(uint32_t number) {
|
||||||
|
String binaryString = String(number, BIN); // Convert to binary string
|
||||||
|
while (binaryString.length() < 32) {
|
||||||
|
binaryString = "0" + binaryString; // Pad with leading zeroes
|
||||||
|
}
|
||||||
|
return binaryString;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import Adafruit_ADS1x15
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
|
||||||
|
adc = Adafruit_ADS1x15.ADS1115()
|
||||||
|
GAIN = 1
|
||||||
|
|
||||||
|
adc.start_adc_difference(0, gain=GAIN, data_rate=860)
|
||||||
|
|
||||||
|
bin_string = "" # Initialize binary string
|
||||||
|
|
||||||
|
while True:
|
||||||
|
for i in range(32): # Loop 32 times to generate 32-bit binary number
|
||||||
|
value = adc.get_last_result() # Read last conversion result
|
||||||
|
lsb = value & 0b00000001 # Extract LSB
|
||||||
|
bin_string += str(lsb) # Add LSB to binary string
|
||||||
|
bin_string = bin_string[-32:] # Keep only last 32 bits of binary string
|
||||||
|
bin_string = bin_string.zfill(32) # Pad binary string with leading zeros to ensure it is 32 bits long
|
||||||
|
print(bin_string) # Print binary string
|
||||||
|
bin_string = "" # Reset binary string back to empty string
|
||||||
|
# No need to delay, as we're using the built-in oscillator for noise
|
|
@ -0,0 +1,31 @@
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import Adafruit_ADS1x15
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import struct
|
||||||
|
|
||||||
|
adc = Adafruit_ADS1x15.ADS1115()
|
||||||
|
GAIN = 1
|
||||||
|
|
||||||
|
adc.start_adc_difference(0, gain=GAIN, data_rate=860)
|
||||||
|
|
||||||
|
num_samples = 1000 # Choose number of 32-bit binary numbers to generate
|
||||||
|
binary_filename = "binary_data4.bin" # Choose filename for binary file
|
||||||
|
txt_filename = "binary_data4.txt" # Choose filename for text file
|
||||||
|
|
||||||
|
with open(binary_filename, "wb") as bin_file, open(txt_filename, "w") as txt_file:
|
||||||
|
for i in range(num_samples):
|
||||||
|
bin_string = "" # Initialize binary string
|
||||||
|
for j in range(32): # Loop 32 times to generate 32-bit binary number
|
||||||
|
value = adc.get_last_result() # Read last conversion result
|
||||||
|
lsb = value & 0b01 # Extract LSB
|
||||||
|
#print (lsb)
|
||||||
|
bin_string += str(lsb) # Add LSB to binary string
|
||||||
|
bin_data = struct.pack("I", int(bin_string, 2)) # Convert binary string to 32-bit unsigned integer and pack into binary data
|
||||||
|
bin_file.write(bin_data) # Write binary data to file
|
||||||
|
txt_file.write(bin_string) # Write binary string to text file
|
||||||
|
if i < num_samples-1: # If not at the last sample, add a space to the end of the binary string in the text file
|
||||||
|
txt_file.write("")
|
||||||
|
time.sleep(0.00000001) # Wait for a short time before generating next sample
|
||||||
|
|
||||||
|
print("Binary file {} and text file {} generated successfully!".format(binary_filename, txt_filename))
|
|
@ -0,0 +1,48 @@
|
||||||
|
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)
|
||||||
|
|
||||||
|
# Write the binary string back to the file
|
||||||
|
with open(filename, 'w') as f:
|
||||||
|
f.write(binary_str)
|
||||||
|
|
||||||
|
ser = serial.Serial('/dev/ttyACM0', 115200) # change port to input port from arduino
|
||||||
|
filename = 'RAM_Test'
|
||||||
|
|
||||||
|
start_time = time.time() # start time of read
|
||||||
|
|
||||||
|
with open(filename, 'wb') as file:
|
||||||
|
while os.path.getsize(filename) < 1250000: # 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
|
||||||
|
|
||||||
|
# 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