GithubHelp home page GithubHelp logo

stevemarple / as3935 Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 4.0 27 KB

Arduino library to support Austrian Microsystems AS3935 lightning sensor.

License: GNU Lesser General Public License v2.1

C++ 100.00%

as3935's People

Contributors

per1234 avatar stevemarple avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

as3935's Issues

IRQ handling with the ESP8266?

I modified the as3935_demo.ino as follow:

/*
-------------------------------
AS3935   |  ESP8266 (ModeMCU)
---------+---------------------
MISO/SDA |  D3
MISO     |  GND
SCK/SCL  |  D4
IRQ      |  D5
SI       |  +3,3V
CS       |  GND
GND      |  GND
Vdd      |  +3,3V
------------------------------

Pin mapping:
https://github.com/esp8266/Arduino/issues/584
*/

#include <AsyncDelay.h>
#include <SoftWire.h>
#include <AS3935.h>

#define SDA_PIN D3
#define SCL_PIN D4
#define IRQ_PIN D5

AS3935 as3935;
bool ledState = true;
AsyncDelay d;

void int2Handler(void)
{
  as3935.interruptHandler();
}


void readRegs(uint8_t start, uint8_t end)
{
  for (uint8_t reg = start; reg < end; ++reg) {
    delay(50);
    uint8_t val;
    as3935.readRegister(reg, val);

    Serial.print("Reg: 0x");
    Serial.print(reg, HEX);
    Serial.print(": 0x");
    Serial.println(val, HEX);
    Serial.flush();
  }
  Serial.print("State: ");
  Serial.println(as3935.getState(), DEC);
  Serial.println("-------------");
}

void setup(void)
{

  Serial.begin(115200);
  as3935.initialise(SDA_PIN, SCL_PIN, 0x03, 3, true, NULL);
  as3935.start();
  d.start(1000, AsyncDelay::MILLIS);

  while (!d.isExpired())
    as3935.process();
  
  readRegs(0, 0x09);
  as3935.setNoiseFloor(0);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, ledState);
  pinMode(IRQ_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(IRQ_PIN), int2Handler, RISING);
  d.start(1000, AsyncDelay::MILLIS);
  Serial.println("setup() done");
}

uint8_t count = 0;
void loop(void)
{
  if (as3935.process()) {
    uint8_t flags = as3935.getInterruptFlags();
    uint8_t dist = as3935.getDistance();

    Serial.println("-------------------");
    Serial.print("Interrupt flags: ");
    Serial.println(flags, HEX);
    Serial.print("Distance: ");
    Serial.println(dist, DEC);
  }
  if (as3935.getBusError()) 
    Serial.println("Bus error!");

    if (as3935.getTriggered()) 
    Serial.println("Triggered!");


  if (d.isExpired()) {
    ledState = !ledState;
    digitalWrite(LED_BUILTIN, ledState);
    
    if (++count > 5) {
      count = 0;
      readRegs(0, 0x09);
    }
    d.start(1000, AsyncDelay::MILLIS);
  }
  
}

But the issue is allways "Triggered!"

PORT OPEN 115200

Communication with MCU..Got answer! Communication with MCU established.
AutoDetect firmware...

Can't autodetect firmware, because proper answer not received (may be unknown firmware). 
Please, reset module or continue.
$
Reg: 0x1: 0x22
Reg: 0x2: 0xC2
Reg: 0x3: 0x0
Reg: 0x4: 0x0
Reg: 0x5: 0x0
Reg: 0x6: 0x0
Reg: 0x7: 0x3F
Reg: 0x8: 0x3
State: 4
-------------
setup() done
Reg: 0x0: 0x24
Reg: 0x1: 0x2
Reg: 0x2: 0xC2
Reg: 0x3: 0x0
Reg: 0x4: 0x0
Reg: 0x5: 0x0
Reg: 0x6: 0x0
Reg: 0x7: 0x3F
Reg: 0x8: 0x3
State: 5
-------------
-------------------
Interrupt flags: 1
Distance: 63
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
-------------------
Interrupt flags: 1
Distance: 63
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
-------------------
Interrupt flags: 1
Distance: 63
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
Triggered!
-------------------

Where is my fail?

Info about the external IRQs at the ESP8266:
https://techtutorialsx.com/2016/12/11/esp8266-external-interrupts/

[RFE] Support fot ESP8266

It it possible to add support for the ESP8266?

When i compile the AS3935_demo.ino, i get the following error:

D:\Users\3PO\Documents\Arduino\libraries\SoftWire\src\SoftWire.cpp:1:25: fatal error: util/atomic.h: No such file or directory

 #include <util/atomic.h>

                         ^

compilation terminated.

exit status 1
Fehler beim Kompilieren für das Board NodeMCU 1.0 (ESP-12E Module)

Thanks in advance. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.