capteur Foudre AS3935

bonjour à tous,

Depuis quelques jours, j’ai commencé un projet de me fabriquer une mini station météo, qui entre autre mesurera la proximité d’un orage. Il existe un capteur foudre Arduino. le AS3935 Lightning sensor.

je possède une carte Arduino R3. J’espère ne pas aller à l’encontre de vos règles. Merci de votre coup de main. Pour l’instant je n’ai pas fait moi même le code car je débute, mais j’ai quand même essayé des codes existant. J’ai téléchargé les librairies du AS3935. Mais je me trouve devant, des erreurs de compilation !?

voici les messages :

C:\Program Files (x86)\Arduino\libraries\AS3935/AS3935.h:1: error: stray '\357' in program
C:\Program Files (x86)\Arduino\libraries\AS3935/AS3935.h:1: error: stray '\273' in program
C:\Program Files (x86)\Arduino\libraries\AS3935/AS3935.h:1: error: stray '\277' in program[code]

et voici le code

#include <AS3935.h>

#include <SPI.h>
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);

// 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;

// 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,53,2);

void setup()
{
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
  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);
  // reset all internal register values to defaults
  AS3935.reset();
  // 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!");

  // 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.setIndoors();
  // 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
  attachInterrupt(1,AS3935Irq,RISING);
}

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
  if(AS3935IrqTriggered)
  {
    // 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)
      Serial.println("Disturber detected");
    if (irqSource & 0b1000)
    {
      // need to find how far that lightning stroke, function returns approximate distance in kilometers,
      // where value 1 represents storm in detectors 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!");
      if (strokeDistance == 63)
        Serial.println("Out of range lightning detected.");
      if (strokeDistance < 63 && strokeDistance > 1);
      {
        Serial.print("Lightning detected ");
        Serial.print(strokeDistance,DEC);
        Serial.println(" kilometers away.");
      }
    }
  }
}

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()
{
  AS3935IrqTriggered = 1;
}

Je ne connais ni le capteur AS3935 ni ses librairies, mais juste comme ça as tu bien choisis le type de carte dans la liste et le bon port ? et comment as tu inscris la librairie dans l'ide?

Bonjour,
Regarde il y a un projet de détection des impacts de foudre dans la revue hackable n°7 (juillet/août).
Le sujet a déjà fais l'objet d'une discussion sur le forum. Une petite recherche et tu rouveras.
@+
[edit] Il est là et en prime le lien vers la revue dans le dernier post

Bonjour,

Ton programme se compile correctement.
Tu es sur que tu as correctement téléchargé et installé la librairie AS3935?

Merci J Luc,
Icare et Kamill

Vous avez surement raison je débute pour télécharger les librairies ! en fait nul je suis grand Maitres !
et comment as tu procédé Kamill ? je ne veux pas user de votre temps non plus ! :slight_smile: mais c'est vrai que je bute depuis un moment dessus....encore merci à vous

Sub....

Bonjour,

J'ai téléchargé cette librairie
Mais à l'intérieur il y a un sous répertoire AS3935. Elle ne s'installe pas avec 'add .zip librarie', il faut copier le répertoire AS3935 dans Mes Documents\Atduino\libraries

@Subatonmic

AS3935 AS3935(SPItransfer,53,2);
Si tu utilise une Arduino uno tu ne peux pas initialiser le SPI sur la broche 53.

attachInterrupt(1,AS3935Irq,RISING); ??? interruption sur la 3 (les commentaires parle de la 2?)

if (strokeDistance == 63) ??? le fabricant annonce 40km maxi

ou as tu trouvé ce programme? Celui sur le site du fabricant est différent. j'utilise celui qui fonctionne en I2C. mais celui en SPI marche aussi.

Je relance ce post pour savoir si parmi vous certains on trouvé la bonne configuration.
J'utilise ce module, je suis en appartement en immeuble en ville, et je trouve que je choppe un peu trop de parasites. Si bien que j'ai du mal à voir le passage d'orage comme aujourd'hui.
Est ce la présence de wifi, de mon transfo à découpage ou d'autres parasites sur le 220 de l'immeuble, mystère.
Quels sont vos réglages qui fonctionnent bien?

  • In_door ou out_door?
  • as_3935_ADD ?
  • AS3935_DIST_DIS ou EN?
  • SPI ou I2C ?
    ....

Rigolo:
Je relance ce post pour savoir si parmi vous certains on trouvé la bonne configuration.

bonsoir
Perso connais pas (comprendre , je n'ai jamais joué avec 8) )
mais il me semble qu'il n'est pas qualifié "bon" capteur par le reseau