It looks like you're new here. If you want to get involved, click one of these buttons!Sign In Register
It looks like you're new here. If you want to get involved, click one of these buttons!
Hi,I'm trying to build a device for environmental noise measurement and for this purpose I need to take samples at 48kHz for at least 0.05s to capture the whole frequency range of interest. However, there is something very peculiar about the way the device behaves. If I'm only acquireing samples, i.e. the rest of the code is commented out, everything works fine. If I add the lines of code that convert the ADC output codes to voltages, the program will make three loops and then the device resets. If I then uncomment the part of code to weight the samples (which I've checked and it works fine), the device won't even manage to acquire the samples. I does however enter the main loop. And finally, if I only try to acquire 100 samples, everything works flawlessly.
del tupleI get:
Can't find name [tuple]Anyway, it seems unlikely to be the actual reason.
import streams import A_weighting2 import rms import SPLmap import adc sampling_freq = 48000 preamp_gain = 125 # voltage gain of the preamp amp_gain = 100 # voltage gain of the amplifier mic_sens = 6.5 # [mV/Pa] sensitivity of the microphone th_sens = 0.00002 # [Pa] threshold of hearing V_th = th_sens*mic_sens*preamp_gain*amp_gain # [V] RMS voltage at threshold of hearing sampling_time = 0.05 # [s] sampling time inputAnalog = A0 # define the analog pin for reading the value ^ conv_const = 3300.0/4095.0 # reload the driver with a custom sampling frequency adc.done(ADC0) adc.init(ADC0, sampling_freq) streams.serial() pinMode(inputAnalog,INPUT_ANALOG) pinMode(LED0,OUTPUT) for i in range(2): sleep(1000) # wait for a second digitalWrite(LED0, HIGH) # turn the LED ON by setting the voltage HIGH sleep(1000) # wait for a second digitalWrite(LED0, LOW) # turn the LED OFF by setting the voltage LOW print("\rEntering loop") while True: samples = adc.read(ADC0, int(sampling_freq*sampling_time)) # get Raw values (0-4095) print("\r\tAcquired samples!") samples_conv =  # list of samples converted to voltage for i in range(len(samples)): samples_conv.append(samples[i]*conv_const) # Convert all raw values to millivolts samples = () print("\r\tSamples converted!") MS = A_weighting2.a_weight(samples_conv) # Get the Mean Square of the weighted samples using A-weighting print("\r\tWeighted samples!\n\n") #RMS = rms.rms(samples) # get the RMS value of weighted samples #print("Calculated RMS value!") #SPL = SPLmap.map(MS/V_th) # get a logarithm of the argument from a look-up table #print(SPL, "dBA") sleep(3000)