On this tutorial i will try to show you how cool is python if combined with arduino, as i've already wrote on previous blogs Here dan Here . Sorry since i was writing only in Bahasa so please use google translate for your convenience and now i would like to write in english and i hope you'll understand.
First prepare some components from this schematic for amplifier part, the purpose is to create audio signal gain (from condenser mic) which is too weak for arduino's ADC to read from.
Since we only want to read the signal's voltage so we can skip loud speaker part, but if you want to hear some poor noisy sound then it is up to you. Pin no 5 of LM386 can directly feed into any arduino ADC pin and the power supply can directly connected to 5 volt on arduino. The Script is quite simple as i only copy and paste from arduino's ADC example scripts collection.
int analogPin = A0; // Any ADC Pin on ardiuno int val = 0; // variable to store the value read void setup() { Serial.begin(9600); // setup serial } void loop() { val = analogRead(analogPin); // read the input pin Serial.println(val); // send value to serial delay(100); // 100 ms delay is the best, try other number }
That is one simple scripts, i only use hardware serial directly connecting to USB COM port then the python will do the rest. Xlwings library is a simple tools to write and read directly to any excel 'cell' so then the graph chart on excel can becoming "alive" in real time if the data is changed rapidly.
import serial #serial library import xlwings as xw #excel library wb = xw.Book('Audio.xlsx') #file name, change accordingly sht = wb.sheets['data'] #sheets name, change it depend on your excel row = 1 serialPort = serial.Serial(port = "COM4", baudrate=9600, #baudrate bytesize=8, timeout=2, stopbits=serial.STOPBITS_ONE) serialString = "" while(1): if(serialPort.in_waiting > 0): #read if any serial data is coming serialString = serialPort.readline() data=serialString.decode('utf-8') print(data) if row == 51: #reset the row row=2 else: row=row+1 audio='A'+str(row) #new cell sht.range(audio).value= float(data) #write cell
The scripts read the integer value from ADC readout which is sent by arduino, then write it rapidly on cell A2 until A51 in excel file. The graph will be "dancing" according to the sound wave traveling through the condenser microphone.
As microsoft excel is easy to use or to customize then you can create any chart or graph you like and can be use as simple visualization as long as the data speed is not very fast, eg: Heart Beat or ECG.
I hope you understand and happy Visualizing your favorite music on Excel
Naya Marie Rivera , naya rivera, glee, @nayarivera, missing
0 komentar:
Posting Komentar