Moin moin,
ich habe mir ein kleines Projekt zusammen gelötet auf Basis eines Arduino NANO. Quasi mein erstes Projekt, da ich absoluter neuling bin.
Angeschlossen ist:
- 1 Micro Servo
- 1 Dallas Temp Sensor
- 1 Durchflussmesser
- RF69 zur Übertragung
Mein Problem ist, altiviere ich "nur" den Servo (withoutsensors = 1). Funktioniert das Empfangen mittels 868 MHz problemlos.
Aktiviere ich aber die Sensoren (withoutsensors = 0) dann funktioniert das Empfangen nicht mehr.
Kann mir jemand einen Tip geben woran das liegt?
Vielen Dank
Gruß Kai O.
if(withoutsensors == 0){
sensors.requestTemperatures();
temperatur = sensors.getTempCByIndex(0) * 10 / 5.5;
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = (NbTopsFan * 60 / 5.5); //(Pulse frequency x 60) / 5.5Q, = flow rate in L/hour
};
#include "Arduino.h"
#include "RFMxx.h"
#include "SensorBase.h"
#include "CustomSensor.h"
#include "JeeLink.h"
#include <Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define debug 1 // Einschalten der Serial Ausgabe
#define withoutsensors 0 // Ohne Angeschlossene Sensoren
#define ONE_WIRE_BUS 4 // PIN FÜR TEMPSENSOR
#define servo 9 // PIN für Servo
#define MYID 0x0B // JeeLink ID
#define INTERVAL 58950 // Transmit intervall - 1050
//#define INTERVAL 10950
Servo myservo;
int Calc;
int hallsensor = 3; // PIN für den Durchflussmesser
int temperatur;
int temp = 0;
int pos = 0;
int maxpos = 160;
int id = 0;
JeeLink jeeLink;
RFMxx rfm(11, 12, 13, 10, 2);
unsigned long lastPeriodicTransmission = 0;
unsigned long txCounter = 0;
volatile int NbTopsFan;
void rpm (){
NbTopsFan++;
}
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(57600);
delay(50);
jeeLink.EnableLED(true);
rfm.InitialzeLaCrosse();
rfm.SetFrequency(868300ul);
rfm.SetDataRate(17241ul);
rfm.EnableReceiver(true);
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
attachInterrupt(digitalPinToInterrupt(3), rpm, RISING); //and the interrupt is attached
myservo.attach(9);
myservo.write(pos);
delay(15);
Serial.println("Initialized\n");
sensors.begin();
if(debug == 1) { Serial.println("Debug-Modus:"); }
}
void loop() {
rfm.Receive();
if (rfm.PayloadIsReady()) {
rfm.EnableReceiver(false);
byte payload[PAYLOADSIZE];
rfm.GetPayload(payload);
struct CustomSensor::Frame rxFrame;
CustomSensor::DecodeFrame(payload, &rxFrame);
if (rxFrame.IsValid) {
jeeLink.Blink(1);
if (rxFrame.ID == MYID) {
Serial.print("Received: ");
for (int i = 0; i < rxFrame.NbrOfDataBytes; i++) {
Serial.print(rxFrame.Data[i], DEC);
Serial.print(" ");
}
if(rxFrame.Data[0] == 20){
Serial.print("\n");
Serial.println("!!! Duengen !!!");
Serial.print("Wie oft Pumpen?: ");
Serial.println(rxFrame.Data[1], DEC);
int pump = rxFrame.Data[1];
for (id = 0; id < pump; id++){
Serial.println("\2");
Serial.print(id);
for (pos = 0; pos < maxpos; pos++) {
myservo.write(maxpos);
delay(1);
}
delay(2000);
for(pos = maxpos; pos >= 0; pos--) {
myservo.write(pos);
delay(1);
}
delay(2000);
}
}
Serial.println();
// wait a moment to give FHEM a chance to be ready to receive
delay(500);
}
}
rfm.EnableReceiver(true);
}
if(withoutsensors == 0){
sensors.requestTemperatures();
temperatur = sensors.getTempCByIndex(0) * 10 / 5.5;
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = (NbTopsFan * 60 / 5.5); //(Pulse frequency x 60) / 5.5Q, = flow rate in L/hour
};
// transmitt every 60 seconds a value
if(millis() > lastPeriodicTransmission + INTERVAL) {
struct CustomSensor::Frame frame;
frame.ID = MYID;
frame.NbrOfDataBytes = 5;
// Kennziffer zur Unterscheidung
frame.Data[0] = 1;
// Waterflowsensor
frame.Data[1] = NbTopsFan;
// Temperaturesensor
frame.Data[2] = temperatur;
// LeerByte - Reserve
frame.Data[3] = 0;
// LeerByte - Reserve
frame.Data[4] = 0;
if(debug == 1) {
Serial.print(frame.ID);
Serial.print(" ");
Serial.print(frame.Data[0]);
Serial.print(" ");
Serial.print(frame.Data[1]);
Serial.print(" ");
Serial.print(frame.Data[2]);
Serial.print(" ");
Serial.print(frame.Data[3]);
Serial.print(" ");
Serial.print(frame.Data[4]);
Serial.println("");
Serial.print(sensors.getTempCByIndex(0));
Serial.println(" C ");
}
CustomSensor::SendFrame(&frame, rfm);
lastPeriodicTransmission = millis();
}
}