Gerade mal die beiden neuen Module untereinander getauscht.
Jetzt meldet der Sender ganz selten mal einen Sendefehler.
Mal eins von den alten Sendemodulen wieder reingesteckt (mit externer Antenne), das meldet brav die Fehler
und verbindet sich auch mit einem der neuen Modulen im Empfänger.
Ich glaube da habe ich irgendwelche nicht ganz kompatible Chinachips erwischt. Hat man ja schon mal gelesen.
Zuerst der Testsender (Achtung: Nicht auf Schönheit gucken, alles aus anderen Projekten geraubt, halt ein Test)
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include "RF24.h"
RF24 radio(A0, 10);
#define BASECHANNEL 42
LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE); // OLD I2C
typedef struct d
{
uint16_t key;
uint16_t dip;
uint16_t pwr;
} data;
uint64_t addresses[8] = {0xE8E8F0F0E1LL,0xE8E8F0F0E2LL,0xE8E8F0F0E3LL,0xE8E8F0F0E4LL,
0xE8E8F0F0E5LL,0xE8E8F0F0E6LL,0xE8E8F0F0E7LL,0xE8E8F0F0E8LL};
data dataRead;
uint64_t sendQueue; // Variable Sendque
void setup()
{
uint8_t queue;
lcd.begin(20,4);
lcd.setCursor(0,0);
lcd.print("NR24 Testsender V1.0");
lcd.setCursor(0,1);
pinMode(A0,OUTPUT);
pinMode(10,OUTPUT);
pinMode(SS,OUTPUT);
radio.begin();
radio.setChannel(BASECHANNEL); // geht nur in Stellung 000
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.setRetries(10, 15);
// Open a writing and reading pipe on each radio, with opposite addresses
sendQueue = addresses[0];
radio.openWritingPipe(sendQueue);
dataRead.key = 0;
}
//
//-----------------------------------
//
uint32_t failed = 0;
uint32_t good = 0;
char dispBuffer[40];
void loop()
{
uint8_t pipeNr;
uint16_t gap;
uint8_t row;
dataRead.key++;
if (dataRead.key >= 10000)
{
dataRead.key = 0;
}
delay(1000);
lcd.setCursor(0,1);
sprintf(dispBuffer,"Sending key : %04d",dataRead.key);
lcd.print(dispBuffer);
if (!radio.write(&dataRead,sizeof(data)))
{
lcd.setCursor(0,3);
failed++;
sprintf(dispBuffer,"Sending failed: %04d",failed);
lcd.print(dispBuffer);
}
else
{
good++;
lcd.setCursor(0,2);
sprintf(dispBuffer,"Sending good : %04d",good);
lcd.print(dispBuffer);
}
} // Loop
Und zu Allem Überfluss auch noch den Empfänger (Homefinder genannt, der weis halt wo ich wohne )
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <Wire.h>
#include "RF24.h"
#include <TimerOne.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADRESS 0x27
LiquidCrystal_I2C lcd(I2C_ADRESS, 2, 1, 0, 4, 5, 6, 7,3,POSITIVE); // Neuer Adapter
TinyGPS gps;
SoftwareSerial ss(4, 3);
typedef struct d
{
uint16_t key;
uint16_t dip;
uint16_t pwr;
} data;
uint64_t addresses[8] = {0xE8E8F0F0E1LL,0xE8E8F0F0E2LL,0xE8E8F0F0E3LL,0xE8E8F0F0E4LL,
0xE8E8F0F0E5LL,0xE8E8F0F0E6LL,0xE8E8F0F0E7LL,0xE8E8F0F0E8LL};
RF24 radio(A0, 10);
#define BASECHANNEL 42
const uint16_t BlinkPin = 2;
static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);
uint16_t giveVoltage()
{
.
.
.
return(uin);
}
void setup()
{
Serial.begin(9600);
ss.begin(9600); // SoftwareSerial starten
Timer1.initialize(600000);
radio.begin();
radio.setChannel(BASECHANNEL); // geht nur in Stellung 000
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.setRetries(10, 15);
radio.openReadingPipe(1, addresses[0]);
radio.startListening(); // Start listening
pinMode(BlinkPin,OUTPUT);
digitalWrite(BlinkPin,HIGH);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Homefinder V1.3");
delay(4000);
digitalWrite(BlinkPin,LOW);
lcd.setCursor(0,0);
lcd.print(" ");
}
//-----------------------------------------------
// Led blinken lassen
//-----------------------------------------------
uint16_t blinking = false;
void DoBlink()
{
digitalWrite(BlinkPin,!digitalRead(BlinkPin));
}
void StartBlink()
{
if (! blinking)
{
Timer1.attachInterrupt(DoBlink);
blinking = true;
}
}
void StopBlink()
{
if (blinking)
{
Timer1.detachInterrupt();
digitalWrite(BlinkPin,LOW);
blinking = false;
}
}
char dispBuffer[17];
static int flag = true;
static int cnt = 0;
uint32_t lastDataGot = 0;
data dataRead;
void loop()
{
float flat, flon;
unsigned long age, date, time, chars = 0;
unsigned short sentences = 0, failed = 0;
// static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
static const double LONDON_LAT = 51.545120, LONDON_LON = 7.328589; // Grimbergstasse 5
static int sats;
static float alt;
static int dist;
static float speed;
static int v;
sats = gps.satellites();
lcd.setCursor(0,0);
if (flag)
{
lcd.print("S");
if (sats == TinyGPS::GPS_INVALID_SATELLITES)
{
lcd.print("-- ");
}
else
{
sprintf(dispBuffer,"%02d ",sats);
lcd.print(dispBuffer);
}
smartdelay(0);
}
else
{
v=giveVoltage();
sprintf(dispBuffer,"%1d.%1dV",v / 1000,(v % 1000) / 100);
lcd.print(dispBuffer);
}
gps.f_get_position(&flat, &flon, &age);
print_date(gps);
smartdelay(0);
lcd.setCursor(10,0);
if (flag)
{
lcd.print("H");
alt = gps.f_altitude();
smartdelay(0);
if (alt == TinyGPS::GPS_INVALID_F_ALTITUDE)
{
lcd.print("xxx.x");
}
else
{
if (alt < 100.0) lcd.print(" ");
if (alt < 10.0) lcd.print(" ");
lcd.print(alt,1);
}
}
else
{
lcd.print("S");
speed = gps.f_speed_kmph();
if (speed < 100) lcd.print(" ");
if (speed < 10 ) lcd.print(" ");
lcd.print(speed,1);
}
smartdelay(0);
lcd.setCursor(0,1);
if (flat == TinyGPS::GPS_INVALID_F_ANGLE)
{
lcd.print("D####Km *** ");
smartdelay(0);
}
else
{
dist = (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON);
if (dist > 9999)
{
if (dist < 10000)
{
sprintf(dispBuffer,"D%1d.%02dKm",dist / 1000,dist % 1000);
}
else
{
if (dist < 100000)
{
sprintf(dispBuffer,"D%2d.%01dKm",dist / 1000,dist % 1000);
}
else
{
sprintf(dispBuffer,"D%04dKm ",dist / 1000);
}
}
}
else
{
sprintf(dispBuffer,"D %04dm ",dist);
}
smartdelay(0);
lcd.print(dispBuffer);
sprintf(dispBuffer,"%-3s ",TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)));
lcd.print(dispBuffer);
smartdelay(0);
}
cnt++;
if (cnt == 5)
{
flag = !flag;
cnt = 0;
}
smartdelay(500);
if (radio.available())
{
radio.read(&dataRead,sizeof(data));
sprintf(dispBuffer,"%04d",dataRead.key % 10000);
lcd.print(dispBuffer);
lastDataGot = millis();
StartBlink();
}
if ((millis() - lastDataGot) > 1200)
{
lcd.print("----");
StopBlink();
}
}
static void smartdelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
static void print_date(TinyGPS &gps)
{
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long age;
lcd.setCursor(4,0);
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
hour = hour + 2;
if (hour >= 24)
{
hour = hour - 24;
}
if (age == TinyGPS::GPS_INVALID_AGE)
{
lcd.print("++:++");
}
else
{
sprintf(dispBuffer,"%02d:%02d",hour,minute);
lcd.print(dispBuffer);
}
smartdelay(0);
}
Ulli
p.s. Beim Empfänger musste ich die "Spannungsmessfunktion" raus nehmen weil das Posting sonst zu lang ist.