Hallo,
ich habe mich schon durch das Forum gelesen aber noch keine richtige ASntwort erhalten.
Aufbau
Ein Arduino Nano sendet Daten an einen anderen Arduino Nano - beide Module sind per Pin2 (Interrupt 0) angeschlossen. Beim Senden mit Arduino 1 leuchtet die TX LED kurz auf, RX-LED bei Arduino 2 jedoch nicht. Arduino 2 gibt auch keine Daten per serieller Konsole aus. Versorgungsspannung an beiden Module n i.O.
verwendetes Modul:
FS1000A mit angelötetet Drahtantenne
Anbei der Code vom Sender:
#include <VirtualWire.h>
#include <VirtualWire_Config.h>
//define LED
int notenNr = 0;
int noten[] = { 440, 585};
int dauer[] = { 600, 600};
int errorcounter = 0;
unsigned long aktuell = 0;
unsigned long tonBeginn = 0;
unsigned long tonDauer = 0;
const int ledgreen = 12;
const int ledred = 11;
const int detectwire = 10;
const int buzz = 9; //buzzer to arduino pin 9
int val = 0; // variable to store the read value
unsigned long currentmillis = 0;
unsigned long previousmillis1 = 0;
unsigned long previousmillis2 = 0;
unsigned long interval = 1000; // Interval zwischen zwei Änderungen
int wireState = 0; // current state of the button
int lastWireState = 0; // previous state of the button
void setup() {
Serial.begin(9600);
// virtual wire
vw_set_tx_pin(0); // pin
vw_setup(8000); // bps
//TX LED green
pinMode(ledgreen, OUTPUT);
pinMode(ledred, OUTPUT);
pinMode(detectwire, INPUT); // sets the digital pin 7 as input
pinMode(buzz, OUTPUT); // Set buzzer - pin 9 as an output
digitalWrite(ledgreen, LOW); // LED aus
digitalWrite(ledred, LOW); // sets the LED to the button's value
digitalWrite(ledgreen, HIGH); // LED anschalten für Betrieb
}
void loop() {
sendString("message", true);
aktuell = millis();
wireState = digitalRead(detectwire);
// compare the buttonState to its previous state
if (wireState != lastWireState) {
if (wireState == LOW){
Serial.println(errorcounter);
digitalWrite(ledred, HIGH); //LED rot an bei Kontakt mit heissem Draht bzw. Massepotential
errorcounter=errorcounter+1;
//alarm();
}
else {
digitalWrite(ledred, LOW); // LED rot aus
}
}
lastWireState = wireState;
}
void sendString(String message, bool wait)
{
byte messageLength = message.length() + 1;
// convert string to char array
char charBuffer[messageLength];
message.toCharArray(charBuffer, messageLength);
vw_send((uint8_t *)charBuffer, messageLength);
if (wait) vw_wait_tx();
Serial.println("sent: " + message);
}
void alarm (){
if(aktuell - tonBeginn > tonDauer )
{
tone(buzz, noten[notenNr] );
tonDauer = dauer[notenNr];
notenNr++;
if( notenNr == 2 )
notenNr = 0;
tonBeginn = aktuell;
}
}
Empfänger:
#include <VirtualWire.h>
#include <VirtualWire_Config.h>
#include <LiquidCrystal_I2C.h>
//0x3F
//Libraries
#include <Wire.h>
//Init
LiquidCrystal_I2C lcd(0x3F, 20, 4); // Set the LCD I2C address, if it's not working try 0x27
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
//global var
int state = 0; //set state FSM
// Ports RelayPort
int sw1 = 3;
int sw2 = 4;
// Which pins are connected to which LED
const byte greenLED = 6 ;
const byte redLED = 5 ;
// Variable holding the timer value so far. One for each "Timer"
unsigned long greenLEDtimer = 0 ;
unsigned long redLEDtimer = 0 ;
// Time periods of blinks in milliseconds (1000 milliseconds to a second).
// Time variable and constants are always unsigned long
const unsigned long greenLEDinterval = 555UL ;
const unsigned long redLEDinterval = 1234UL ;
// Variable to know what the current LED state is
int greenLEDState = LOW ;
int redLEDState = LOW ;
//LCD
unsigned long previousMillis2 = 0; // will store last time LED was updated
unsigned long ledMillis = 0; // Zeit für den Blinkrythmus der LED
//LESE Fehler am Draht
unsigned long previousmillis1 = 0;
unsigned long previousmillis2 = 0;
unsigned long previousmillis3 = 0;
unsigned long previousmillis4 = 0;
unsigned long interval = 500; // Interval zwischen zwei Änderungen
unsigned long intervalism = 200; // Interval zwischen zwei Änderungen
unsigned long intervalled = 500; // Interval zwischen zwei Änderungen
int count = 0;
const long intervallcd = 600; // interval at which to blink (milliseconds)
const long intervalls = 50; // interval at which to blink (milliseconds)
const long flanke = 100;
// Variables will change:
int ledState = LOW; // ledState used to set the LED
int flankenState = LOW;
bool start = false;
bool fehler = false;
bool pause = false;
bool detectededge = false;
bool blinking = false;
int errorcounter = 0;
int firsterror = 0;
int relayiterator = 0;
int receivedvalue = 0;
int lasterror = 0;
//TASTER Stati
int starter = LOW;
int clearer = LOW;
long lastDebounceTime1 = 0; // the last time the output pin was toggled
long lastDebounceTime2 = 0; // the last time the output pin was toggled
long lastDebounceTime3 = 0; // the last time the output pin was toggled
long lastDebounceTime4 = 0; // the last time the output pin was toggled
long lastDebounceTime5 = 0; // the last time the output pin was toggled
long debounceDelay = 400; // the debounce time; increase if the output flickers
int starterpin = 8;
int clearerpin = 7;
///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
Serial.println("device is ready...");
vw_set_rx_pin(0);
vw_setup(8000); // bps
vw_rx_start();
lcd.begin(); // iInit the LCD for 16 chars 2 lines
//Relay
pinMode(sw1, OUTPUT);
pinMode(sw2, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
digitalWrite(sw1, HIGH); // schaltet LED1 an
digitalWrite(sw2, HIGH); // schaltet LED1 an
digitalWrite(greenLED, HIGH); // schaltet LED1 an
digitalWrite(redLED, HIGH); // schaltet LED1 an
//State machine == 1
state = 1;
//
firsterror = 0;
Serial.println("Starting");
}
void loop() {
//get current system time
unsigned long currentLS1Millis = millis();
unsigned long currentLCDMillis = millis();
//Taster Status beziehen
starter = digitalRead(starterpin);
clearer = digitalRead(clearerpin);
if (vw_get_message(message, &messageLength)) // non-blocking
{
Serial.print("received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println();
}
}
Vielen Dank für Deine hilfe!