Hier der Arduino-Code:
/*
RPM Sensor for Hitec HTS-SS
Times a pulse on D2 and pulses it out on D13 in Hitecs RPM sensor format
This example code is in the public domain.
*/
#define LED 13
#define SENSOR 2
void setup() {
pinMode(LED, OUTPUT);
pinMode(SENSOR, INPUT);
digitalWrite(LED, LOW);
// PullUp for the sensor (may be needed for hall effect sensor)
// digitalWrite(SENSOR, HIGH);
}
void blink_Bit(bool b) {
digitalWrite(LED, b); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
}
void blink_BCD(uint8_t bcdnum) {
// 0 = all bits set
if (bcdnum == 0)
bcdnum = 10;
// Blink bcdnum of bits
for (int i = bcdnum; i>0; i--) {
blink_Bit(HIGH);
}
// Fill up to 10 bits
for (int i = 10 - bcdnum; i>0; i--) {
blink_Bit(LOW);
}
// long line of stop bits
delayMicroseconds(25); // wait a second...
}
void blink_Packet(uint32_t rpm) {
uint8_t value[10] = {0,0,0,0,0,0,0,0,0,0};
uint8_t i = 0;
// Convert RPM to BCD
while(rpm > 0){
value[i] = rpm % 10;
rpm /= 10;
i = i + 1;
}
// Send 2 Start bits
blink_Bit(HIGH);
blink_Bit(HIGH);
// and 5 digits as BCD
blink_BCD(value[4]);
blink_BCD(value[3]);
blink_BCD(value[2]);
blink_BCD(value[1]);
blink_BCD(value[0]);
}
void loop() {
uint32_t duration;
uint32_t rpm;
//Time one rotation, but wait no longer than .5 seconds for a pulse
duration = pulseIn(SENSOR, HIGH, 500000L);
rpm = duration;
if (duration > 0) {
//Add 2% as offset for the magnet, since it is not measured by pulseIn()
rpm += rpm / 50L;
// Devide one Minute (60 * 1000 * 1000 microsecs) by duration of a rotation
// And devide it again by 10 because the HTS-SS needs it this way
rpm = 6000000L / rpm;
}
// Send rpm to HTS-SS
blink_Packet(rpm);
// it needs some time...
delayMicroseconds(500000L - duration); // wait half a second
}
PS: Achtet beim Basteln darauf, dass die Sensor-Station 3,3V Signal braucht! Die normalen Hall-Effekt-Sensoren (TL4905) funktionieren erst ab 3,8V!
Gruss
Chris


Dabei ist im HZR des Rex 450 extra ein Platz fuer EINEN Magneten vorgesehen... Grosse Helis sind doch viel toleranter! 



Kommentar