salve
sono in possesso di un codice arduino che vorrei fare una modifica personalizzata , ma non sono in grado
Se la scrvo qualcuno mi puo fare la modifica ?
grazie saluti
salve
sono in possesso di un codice arduino che vorrei fare una modifica personalizzata , ma non sono in grado
Se la scrvo qualcuno mi puo fare la modifica ?
grazie saluti
Se copi il codice e ci spieghi cosa ti viene difficile da comprendere, sicuramente qualcuno ti aiuterà.
Se copi un codice scritto da altri e cerchi qualcuno che te lo modifichi, sicuramente nessuno ti aiuterà.
il codice è di libero utilizzo scaricato da un sito
come allego il codice ?
o metto il link ?
dovrei solo una piccola modifica fa accendere un led alla rilevazione di scariche elettriche , ed dopo 5 o 10 ravvicinate fa attivare un relè
Intanto comincia copiando il codice all'interno degli opportuni tag (basta che premi il primo tasto sulla sinistra) e postarlo qui
/*
Lightningdetector2.pde - AS3935 Franklin Lightning Sensor™ IC by AMS library demo code
Code by http://microcontroller-projects.com / Teodor Costachioiu (blog [at] microcontroller-projects [dot] com)
This Arduino sketch requires the AS3935 library from https://github.com/raivisr/AS3935-Arduino-Library
Based on the original library and code by:
LightningDetector.pde - AS3935 Franklin Lightning Sensor™ IC by AMS library demo code
Copyright (c) 2012 Raivis Rengelis (raivis [at] rrkb.lv). All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <SPI.h>
#include <AS3935.h>
#include <SoftwareSerial.h>
#define LCD_pin 5 // LCD data signal
const int NoDetect=30;
int counter;
int NumDisturber=0;
SoftwareSerial LCD = SoftwareSerial(0, LCD_pin);
void printAS3935Registers();
// Function prototype that provides SPI transfer and is passed to
// AS3935 to be used from within library, it is defined later in main sketch.
// That is up to user to deal with specific implementation of SPI
// Note that AS3935 library requires this function to have exactly this signature
// and it can not be member function of any C++ class, which happens
// to be almost any Arduino library
// Please make sure your implementation of choice does not deal with CS pin,
// library takes care about it on it's own
byte SPItransfer(byte sendByte);
// tunecap is needed to display the calibration register value
int tunecap;
// Iterrupt handler for AS3935 irqs
// and flag variable that indicates interrupt has been triggered
// Variables that get changed in interrupt routines need to be declared volatile
// otherwise compiler can optimize them away, assuming they never get changed
void AS3935Irq();
// volatile int AS3935IrqTriggered; - not needed anymore
// First parameter - SPI transfer function, second - Arduino pin used for CS
// and finally third argument - Arduino pin used for IRQ
// It is good idea to chose pin that has interrupts attached, that way one can use
// attachInterrupt in sketch to detect interrupt
// Library internally polls this pin when doing calibration, so being an interrupt pin
// is not a requirement
AS3935 AS3935(SPItransfer,3,2); //change to AS3935(SPITransfer,9,3) if using slot #2
// AS3935 AS3935(SPItransfer,77,26); //if using Flip & Click socket A
void setup()
{
serLCDInit();
backlightOn();
clearLCD();
lcdPosition(0,3);
LCD.print("Lightining");
lcdPosition(1,5);
LCD.print("Sensor");
delay(1500);
clearLCD();
Serial.begin(9600);
// first begin, then set parameters
SPI.begin();
// NB! chip uses SPI MODE1
SPI.setDataMode(SPI_MODE1);
// NB! max SPI clock speed that chip supports is 2MHz,
// but never use 500kHz, because that will cause interference
// to lightning detection circuit
SPI.setClockDivider(SPI_CLOCK_DIV16);
// and chip is MSB first
SPI.setBitOrder(MSBFIRST);
// reset all internal register values to defaults
AS3935.reset();
delay(10);
AS3935.setOutdoors();
AS3935.registerWrite(AS3935_NF_LEV,2); //write 2 in the Noise Level register
//AS3935.registerWrite(AS3935_SREJ,0); //write 2 in the Noise Level register
// and run calibration
// if lightning detector can not tune tank circuit to required tolerance,
// calibration function will return false
if(!AS3935.calibrate())
Serial.println("Tuning out of range, check your wiring, your sensor and make sure physics laws have not changed!");
// now we print the value in the calibration register TUN_CAP
// it is in the range 0 - 15
tunecap=AS3935.registerRead(AS3935_TUN_CAP); //Internal calibration
Serial.print("Tuning cap register is ");
Serial.println(tunecap);
// since this is demo code, we just go on minding our own business and ignore the fact that someone divided by zero
// first let's turn on disturber indication and print some register values from AS3935
// tell AS3935 we are indoors, for outdoors use setOutdoors() function
// AS3935.setOutdoors();
// turn on indication of distrubers, once you have AS3935 all tuned, you can turn those off with disableDisturbers()
AS3935.enableDisturbers();
printAS3935Registers();
// AS3935IrqTriggered = 0;
// Using interrupts means you do not have to check for pin being set continiously, chip does that for you and
// notifies your code
// demo is written and tested on ChipKit MAX32, irq pin is connected to max32 pin 2, that corresponds to interrupt 1
// look up what pins can be used as interrupts on your specific board and how pins map to int numbers
// ChipKit Max32 - irq connected to pin 2, or Arduino with irq connected to pin 3
// Uncomment the next line if using slot #2 of the Arduino mikroBUS adapter
// attachInterrupt(1,AS3935Irq,RISING);
// uncomment line below and comment out line above for Arduino Mega 2560, irq still connected to pin 2
attachInterrupt(0,AS3935Irq,RISING);
// attachInterrupt(digitalPinToInterrupt(26),AS3935Irq,RISING); // if using Flip & Click socket A
}
void loop()
{
// here we go into loop checking if interrupt has been triggered, which kind of defeats
// the whole purpose of interrupts, but in real life you could put your chip to sleep
// and lower power consumption or do other nifty things
// I prefer to move this code inside the interrupt routine itself
// Here I leave only some code to display "Waiting..." so I know everything works
delay(1000);
Serial.println("Waiting...");
if (counter==0)
{
NumDisturber=0;
counter=NoDetect;
clearLCD();
lcdPosition(0,1);
LCD.print("No lightining");
lcdPosition(1,4);
LCD.print("detected");
}
else
{
counter=counter - 1;
}
}
void printAS3935Registers()
{
int noiseFloor = AS3935.getNoiseFloor();
int spikeRejection = AS3935.getSpikeRejection();
int watchdogThreshold = AS3935.getWatchdogThreshold();
Serial.print("Noise floor is: ");
Serial.println(noiseFloor,DEC);
Serial.print("Spike rejection is: ");
Serial.println(spikeRejection,DEC);
Serial.print("Watchdog threshold is: ");
Serial.println(watchdogThreshold,DEC);
}
// this is implementation of SPI transfer that gets passed to AS3935
// you can (hopefully) wrap any SPI implementation in this
byte SPItransfer(byte sendByte)
{
return SPI.transfer(sendByte);
}
// this is irq handler for AS3935 interrupts, has to return void and take no arguments
// always make code in interrupt handlers fast and short
void AS3935Irq()
{
// there is no need for this flag anymore
// AS3935IrqTriggered = 1;
// I move all the code for dysplaiying events inside the interrupt routine
// again there is no need for this flag
// reset the flag
// AS3935IrqTriggered = 0;
// first step is to find out what caused interrupt
// as soon as we read interrupt cause register, irq pin goes low
int irqSource = AS3935.interruptSource();
// returned value is bitmap field, bit 0 - noise level too high, bit 2 - disturber detected, and finally bit 3 - lightning!
if (irqSource & 0b0001)
Serial.println("Noise level too high, try adjusting noise floor");
if (irqSource & 0b0100)
{
NumDisturber+=1;
Serial.println("Disturber detected");
clearLCD();
lcdPosition(0,0);
LCD.print("Disturb. Det: ");
LCD.print(NumDisturber,DEC);
counter=NoDetect;
}
if (irqSource & 0b1000)
{
// need to find how far that lightning stroke, function returns approximate distance in kilometers,
// where value 1 represents storm in detector's near victinity, and 63 - very distant, out of range stroke
// everything in between is just distance in kilometers
int strokeDistance = AS3935.lightningDistanceKm();
if (strokeDistance == 1)
{
Serial.println("Storm overhead, watch out!");
lcdPosition(1,1);
Serial.println("Storm overhead");
lcdPosition(1,3);
Serial.println("WATCH OUT!");
counter=NoDetect;
}
if (strokeDistance == 63)
{
Serial.println("Out of range lightning detected.");
lcdPosition(0,2);
Serial.println("Out of range");
lcdPosition(1,0);
Serial.println("lightning detect");
counter=NoDetect;
}
if (strokeDistance < 63 && strokeDistance > 1)
{
Serial.print("Lightning detected ");
Serial.print(strokeDistance,DEC);
Serial.println(" kilometers away.");
lcdPosition(1,0);
LCD.print("Distance: ");
LCD.print(strokeDistance,DEC);
LCD.print("km");
counter=NoDetect;
}
}
}
cobra91: ti ricordo che in conformità al regolamento, punto 7, devi editare il tuo post (quindi NON scrivendo un nuovo post, ma utilizzando il bottone More -> Modify che si trova in basso a destra del tuo post) e racchiudere il codice all'interno dei tag CODE (... sono quelli che in edit inserisce il bottone con icona fatta così: </>, tutto a sinistra).
In pratica, tutto il tuo codice dovrà trovarsi racchiuso tra due tag: [code] _il _tuo_ codice_ [/code]
così da non venire interpretato e non dare adito alla formazione di caratteri indesiderati o cattiva formattazione del testo. Grazie.
Guglielmo
si avevo provato ma risultava troppo lungo in un unica soluzione
cobra91: ti chiedo ancora una volta di sistemare il codice come ti ho chiesto.
Guglielmo
non ci sono riuscito mi appare un errore
The message exceeds the maximum allowed length (9000 characters).
Adesso ho notato che nella stessa cartella dove c'è il codice principale c'è anche un altro codice ma non so a cosa serve ?
io non sono esperto di codici arduino , lo posso allegare come documento o cartella tutti e 2 i codici ?
Allora devi allegare i codici, puoi allegare più di un codice quindi non ci sono particolari problemi se ne hai di più. Per allegare i codici clicca su attachments and other options (lo trovi sotto alla zona dove puoi scrivere) e selezioni i codici dal tuo pc. Semplice e veloce
Buona serata
Che modifica vuoi fare?
Ciao,
P.
Credo che tu voglia costruire una protezione in caso di temporale ravvicinato.
Isola la parte di codice che si occupa dei fulmini vicini, è su quella e sul loop che occorre agire.
Iniziamo da quella parte ed illustraci le tue difficoltà così possiamo spiegarti cosa fare, occorrono interventi sia software che hardware per collegare il LED ed il relè.
paulus1969:
Credo che tu voglia costruire una protezione in caso di temporale ravvicinato.
Vedo la cosa un po complicata.
La semplice formula: tempo in secondi tra lampo e tuono moltiplicato per 3 da la distanza in km del fulmine.
Ciao Uwe
ciao grazie per in tuo interessamento al mio problema
si esatta la tua suposizione , le modifiche hardware le ho gia realizzate sulla carta , adesso prima volevo vedere se era possibile la modifica del software
dettagli :
le verde che lampeggi alla rilevazione di scariche elettriche ,come la scritta che dovrebbe apparire sul display, incondizionato dalla distanza , potrebbe andare bene sul : ( pin 7 lampeggi 1 secondo).
led rosso che rilevi scariche piu forti o vicine potrebbe andare bene : ( pin 8 resta accesso 5 secondi ).
relè che si attivi quando quando le scariche sono ravvicinate come ad esmpio , 5 in un minuto ( pin 10 resta accesso per 1 minuto ) che ci collego un dispositivo buzzer o lampeggiante a 12 volt.
Poi a riguardo di tempi ed impostazioni lo modifico io qaundo installo il sistema ,basta che mi spieghi dove è scritto .
Qusta sarebbe la mia idea poi se e troppo complicata puoi modificarla
la parte del codice che si occupa della rilevazione credo che sia questa provo ad cercarla
ciao grazie
int LEDv ; = 7 // LED verde collegato al pin digitale 7
int LEDr ; = 8 // LED collegato al pin digitale 8
int relay ; = 10 // relè collegato al pin digitale 10
void setup() {
pinMode(LEDv, OUTPUT); // imposta il pin digitale come output
pinMode(LEDr, OUTPUT); // imposta il pin digitale come output
pinMode(relay ,OUTPUT); // imposta il pin digitale come output
}
void loop() {
digitalWrite(LEDv, HIGH); // accende il LED
delay(1000); // aspetta
digitalWrite(LED, LOW); // spegne il LED
}
void loop() {
digitalWrite(LEDr, HIGH); // accende il LED
delay(3000); // aspetta
digitalWrite(LED, LOW); // spegne il LED
}
void loop(){
digitalWrite(relay ,HIGH);
delay(60000);
digitalWrite(relay ,LOW);
}
cobra91: ti ho già detto che il codice va racchiuso tra i tag CODE ... vorrei evitare di continuare a ripeterlo ...
Guglielmo
si io ho cliccato su tag code