sì, alla fine ho usato un led IR (prima di aprire il post avevo provato con un comune led ma con scarsissimi risultati, troppo rumore) ma con il prescaler a 16 (circa 11000 letture al secondo)
poi i dati li ho analizzati con baudline, che mostra l'analisi di fourier delle frequenze.
con elica bipala 10x45:
MAX 7200rpm
MIN 2400rpm
rampa di salita: 100ms
rampa di discesa: 200ms
con elica tripla 9x5:
max 7700 RPM
min 1440 RPM
rampa salita: 370ms
rampa discesa: 1.2secondi
codice arduino (modificato da un vecchio codice):
#include <Servo.h>
Servo s;
void setup() {
// initialize the serial communication:
Serial.begin(460800);
delay(1000);
analogReference(EXTERNAL);
ADCSRA &= B11111100; //prescaler to 16, about ~77 kHz sample rate
s.attach(7);
}
unsigned long somma;
//int numeroSample = 300;
boolean stato = false;
int vel=0;
void loop() {
if (Serial.available()>0){
digitalWrite(13, stato?HIGH:LOW);
stato=!stato;
int i = Serial.read();
switch(i){
case 'm':
vel=0;
break;
case 'M':
digitalWrite(13, HIGH);
vel=180;
break;
case '+':
vel+=10;
break;
}
s.write(vel);
}
/*
somma=0;
//for (int i=0; i < numeroSample;i++){
somma+=analogRead(A0);
//}
// send the value of analog input 0:
Serial.println((int)(somma/numeroSample));
// wait a bit for the analog-to-digital converter
// to stabilize after the last reading:
//delay(2);
*/
Serial.write( (byte)map(analogRead(A0), 0, 1024, 0, 256) );
//Serial.write('\n');
}
codice processing (grafico +salvataggio del file in temp, che è in ram quindi nessuna lag):
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
FileWriter a;
void setup () {
// set the window size:
size(400, 300);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 460800);
// don't generate a serialEvent() unless you get a newline character:
//myPort.bufferUntil('\n');
// set inital background:
background(0);
try {
a = new FileWriter("/tmp/dati.txt", false);
}
catch(Exception e) {
e.printStackTrace();
}
}
void draw () {
// everything happens in the serialEvent()
}
int i=0;
long tempo = millis();
int stroke1;
char lettura[] = new char[1];
void serialEvent (Serial myPort) {
i++;
if (millis()-tempo>1000) {
println("Letture al sec:"+i);
i=0;
tempo= millis();
}
lettura[0] = (char)myPort.read();
int inRead = lettura[0];
float finByte = map(inRead, 0, 256, 0, height);
try {
a.write(lettura, 0, 1);
}
catch(Exception e) {
e.printStackTrace();
}
// draw the line:
stroke(stroke1, 34, 255);
line(xPos, height, xPos, height - finByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
if (stroke1 == 127)
stroke1=20;
else
stroke1 = 127;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
void keyReleased() {
if (key != CODED) {
switch(key) {
case 'z':
println("MAX");
myPort.write('M');
break;
case 'm':
println("min");
myPort.write('m');
break;
case '+':
println("+");
myPort.write('+');
break;
}
}
}
notare che si può comandare il servo da processing, con + (+10 al servo), m (servo al minimo), z (servo al massimo)