Hallo zusammen,
Ich habe leider zu spät gesehen, dass der andere Thread schon als "erledigt" markiert war, daher starte ich mal einen separaten an dieser Stelle.
Ich habe Empfänger und Sender nach dieser Anleitung gebaut und programmiert.
Die ATTinys sind mit dem RasPi direkt geflasht worden, hat auch alles geklappt, die Testprogramme laufen darauf. Der Sender sendet lediglich eine Testzeichenkette, der Empfänger gibt alles aus, was er empfängt.
Jetzt beginnt das Problem:
Ich bekomme beim Empfänger solche Ausgaben wie diese hier:
BAD-CRC
64
BAD-CRC
0
BAD-CRC
120 0▒▒▒@@▒ 8
pp▒@@`▒p@l▒`@▒x0 ,▒▒▒ ▒@▒
▒pP▒▒x▒ @@`p ▒ ▒p▒▒▒
BAD-CRC
0
BAD-CRC
0
BAD-CRC
24 ▒▒▒p ▒@p▒▒▒
p▒▒▒@▒`@p▒▒<@▒
BAD-CRC
64
BAD-CRC
80 @▒0 ▒@ @`@▒p8 x0
Alles anzeigen
Empfänger hat die NodeID 10, NetworkID 200, der Sender hat die NodeID 21, gleiches Network und Gateway die 10 vom Empfänger...
Die ersten Ziffern, die ausgegeben werden, sind die ID des Senders. Das ist schon verwunderlich, da nie die eigentliche NodeID des Senders ausgeben wird, sondern immer andere. Zwischenzeitlich werden auch Daten empfangen, die nicht vom Sender stammen, vermutlich andere Geräte in der Nähe. Wenn mein Sender aber sendet, erscheint meist die "0" als ID, was ja eigentlich für Broadcast reserviert ist.
Hier auch mal meine Sketches:
Empfänger:
// RFM12B Receiver for RaspberryPI
//
// Basiert zum Teil auf der Arbeit von Nathan Chantrell
//
// modified by meigrafd @ 16.12.2013 - for UART on RaspberryPI
//------------------------------------------------------------------------------
#include <RFM12B.h>
#include <avr/sleep.h>
#include <SoftwareSerial.h>
//------------------------------------------------------------------------------
// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
// By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10}
#define NODEID 10 //network ID used for this unit
#define NETWORKID 200 //the network ID we are on
#define ACK_TIME 2000 // # of ms to wait for an ack
#define SERIAL_BAUD 9600
//------------------------------------------------------------------------------
// PIN-Konfiguration
//------------------------------------------------------------------------------
// UART pins
#define rxPin 7 // D7, PA3
#define txPin 3 // pin an den der 433 Mhz Sender angeschlossen ist (D3, PA7)
// LED pin
#define LEDpin 8 // D8, PA2 - set to 0 to disable LED
/*
+-\/-+
VCC 1| |14 GND
(D0) PB0 2| |13 AREF (D10)
(D1) PB1 3| |12 PA1 (D9)
RESET 4| |11 PA2 (D8)
INT0 PWM (D2) PB2 5| |10 PA3 (D7)
PWM (D3) PA7 6| |9 PA4 (D6)
PWM (D4) PA6 7| |8 PA5 (D5) PWM
+----+
*/
//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start en
// - to stop encrypting call .Encrypt(NULL)
//#define KEY "ABCDABCDABCDABCD"
// Initialise UART
SoftwareSerial mySerial(rxPin, txPin);
// Need an instance of the Radio Module
RFM12B radio;
//##############################################################################
static void activityLED (byte mode) {
pinMode(LEDpin, OUTPUT);
digitalWrite(LEDpin, mode);
}
// blink led
static void blink (byte pin, byte n = 3) {
pinMode(pin, OUTPUT);
for (byte i = 0; i < 2 * n; ++i) {
delay(100);
digitalWrite(pin, !digitalRead(pin));
}
}
// init Setup
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(SERIAL_BAUD);
mySerial.println("SETUP RECEIVER");
radio.Initialize(NODEID, RF12_433MHZ, NETWORKID);
// #ifdef KEY
// radio.Encrypt((byte*)KEY); //comment this out to disable encryption
// #endif
if (LEDpin) {
activityLED(1); // LED on
delay(1000);
activityLED(0); // LED off
}
}
// Loop
void loop() {
if (radio.ReceiveComplete()) {
if (radio.CRCPass()) {
//node ID of TX, extracted from RF datapacket. Not transmitted as part of structure
mySerial.print(radio.GetSender(), DEC);
mySerial.print(" ");
int i;
for (byte i = 0; i < *radio.DataLen; i++) //can also use radio.GetDataLen() if you don't like pointers
mySerial.print((char) radio.Data[i]);
if (LEDpin) {
blink(LEDpin, 2);
}
if (radio.ACKRequested()) {
radio.SendACK();
}
} else {
mySerial.println("BAD-CRC");
mySerial.print(radio.GetSender(), DEC);
mySerial.print(" ");
int i;
for (byte i = 0; i < *radio.DataLen; i++) //can also use radio.GetDataLen() if you don't like pointers
mySerial.print((char) radio.Data[i]);
if (LEDpin) {
activityLED(1); // LED on
delay(1000);
activityLED(0); // LED off
}
}
mySerial.println();
}
}
Alles anzeigen
Test-Sender:
// RFM12B Sender for DHT22 Sensor
//
// Basiert zum Teil auf der Arbeit von Nathan Chantrell
//
// modified by meigrafd @ 16.12.2013
//------------------------------------------------------------------------------
#include <RFM12B.h>
#include <avr/sleep.h>
//#include <DHT.h>
//------------------------------------------------------------------------------
// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
// By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10}
#define NODEID 21 //network ID used for this unit
#define NETWORKID 200 //the network ID we are on
#define GATEWAYID 10 //the node ID we're sending to
#define ACK_TIME 2000 // # of ms to wait for an ack
#define SENDDELAY 5000 // wait this many ms between sending packets. 300000ms = 5min
#define requestACK false // request ACK? (true/false)
//------------------------------------------------------------------------------
// PIN-Konfiguration
//------------------------------------------------------------------------------
// SENSOR pins
//#define DHT11_PIN 10 // DHT sensor is connected on D10 (ATtiny pin 13)
//#define DHT11_POWER 9 // DHT Power pin is connected on D9 (ATtiny pin 12)
// LED pin
#define LEDpin 8 // D8, PA2 - set to 0 to disable LED
//------------------------------------------------------------------------------
/*
+-\/-+
VCC 1| |14 GND
(D0) PB0 2| |13 AREF (D10)
(D1) PB1 3| |12 PA1 (D9)
RESET 4| |11 PA2 (D8)
INT0 PWM (D2) PB2 5| |10 PA3 (D7)
PWM (D3) PA7 6| |9 PA4 (D6)
PWM (D4) PA6 7| |8 PA5 (D5) PWM
+----+
*/
//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start encrypting
// - to stop encrypting call .Encrypt(NULL)
//#define KEY "ABCDABCDABCDABCD"
// Need an instance of the Radio Module
RFM12B radio;
// Setup the DHT
//DHT myDHT(DHT11_PIN, DHT11);
// Variablen für Temperatur/Luftfeuchtigkeit
//long temp; long humi;
// Temperatur-String zum Versand per 433 Mhz
char msg[26];
//##############################################################################
static void activityLed (byte state, byte time = 0) {
if (LEDpin) {
pinMode(LEDpin, OUTPUT);
if (time == 0) {
digitalWrite(LEDpin, state);
} else {
digitalWrite(LEDpin, state);
delay(time);
digitalWrite(LEDpin, !state);
}
}
}
// blink led
static void blink (byte pin, byte n = 3) {
if (LEDpin) {
pinMode(pin, OUTPUT);
for (byte i = 0; i < 2 * n; ++i) {
delay(100);
digitalWrite(pin, !digitalRead(pin));
}
}
}
// sec since start
static unsigned long now() {
// FIXME 49-day overflow
return millis() / 1000;
}
//--------------------------------------------------------------------------------------------------
// Read current supply voltage (in mV)
//--------------------------------------------------------------------------------------------------
long readVcc() {
bitClear(PRR, PRADC);
ADCSRA |= bit(ADEN); // Enable the ADC
long result;
// Read 1.1V reference against Vcc
#if defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0); // For ATtiny84
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // For ATmega328
#endif
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate Vcc in mV
ADCSRA &= ~ bit(ADEN);
bitSet(PRR, PRADC); // Disable the ADC to save power
return result;
}
// init Setup
void setup() {
// pinMode(DHT11_POWER, OUTPUT); // set power pin for Sensor to output
// myDHT.begin();
radio.Initialize(NODEID, RF12_433MHZ, NETWORKID);
// #ifdef KEY
// radio.Encrypt((byte*)KEY); //comment this out to disable encryption
// #endif
// configure RFM12B
radio.Control(0xC040); // Adjust low battery voltage to 2.2V
radio.Sleep(); //sleep right away to save power
PRR = bit(PRTIM1); // only keep timer 0 going
analogReference(INTERNAL); // Set the aref to the internal 1.1V reference
ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
activityLed(1,1000); // LED on for 1000ms
}
// Loop
void loop() {
activityLed(1); // LED on
// pinMode(DHT11_POWER, OUTPUT); // set power pin for Sensor to output
// digitalWrite(DHT11_POWER, HIGH); // turn Sensor on
// DHT11_ERROR_t errorCode;
// delay(2500); // Kurzer Delay zur Initialisierung (DHT22 benoetigt mindestens 2 Sekunden fuer Aufwaermphase nach dem Power-On)
// errorCode = myDHT22.readData(); // read data from sensor
// myDHT.read();
// float h = myDHT.readHumidity();
// float t = myDHT.readTemperature();
activityLed(0); // LED off
// if (!isnan(t) && !isnan(h)) { // data is good
// int temp = (myDHT22.getTemperatureC()*100); // Get temperature reading and convert to integer, reversed at receiving end
// int humi = (myDHT22.getHumidity()*100); // Get humidity reading and convert to integer, reversed at receiving end
int vcc = readVcc(); // Get supply voltage
// msg-Variable mit Daten zum Versand fuellen, die spaeter an das WebScript uebergeben werden
//snprintf(msg, 26, "v=%d&t=%d&h=%d", vcc,temp,humi);
strcpy(msg, "1234567890ABCDEFGHIJ12345");
// strcpy(msg,"v=");
// itoa(vcc,&msg[strlen(msg)],10);
// strcat(msg,"&t=");
// itoa(t,&msg[strlen(msg)],10);
// strcat(msg,"&h=");
// itoa(h,&msg[strlen(msg)],10);
radio.Wakeup();
// delay(0);
radio.Send(GATEWAYID, (uint8_t *)msg, strlen(msg), requestACK);
radio.SendWait(2); //wait for RF to finish sending (2=standby mode)
radio.Sleep();
if (LEDpin) {
blink(LEDpin, 2); // blink LED
}
// }
// digitalWrite(DHT11_POWER, LOW); // turn Sensor off to save power
// pinMode(DHT11_POWER, INPUT); // set power pin for Sensor to input before sleeping, saves power
delay(SENDDELAY);
}
Alles anzeigen
Ich verzweifel langsam!:@ Was mache ich falsch??
Gruß, Benny