arduino V0.5

pull/2/head
ouki-wang 6 years ago
parent 65e0d1af8b
commit 26a9bf394f
  1. 20
      DFRobot_AS3935_I2C.cpp
  2. 7
      DFRobot_AS3935_I2C.h
  3. 42
      examples/DFRobot_AS3935_lightning_sensor_detailed/DFRobot_AS3935_lightning_sensor_detailed.ino
  4. 15
      examples/DFRobot_AS3935_lightning_sensor_ordinary/DFRobot_AS3935_lightning_sensor_ordinary.ino
  5. 1
      keywords.txt
  6. 11
      readme.md

@ -4,10 +4,15 @@ DFRobot_AS3935_I2C::DFRobot_AS3935_I2C(uint8_t irqx, uint8_t devAddx)
{
devAdd = devAddx;
irq = irqx;
// initalize the IRQ pins
pinMode(irq, INPUT);
}
DFRobot_AS3935_I2C::DFRobot_AS3935_I2C(uint8_t irqx)
{
irq = irqx;
// initalize the IRQ pins
pinMode(irq, INPUT);
}
void DFRobot_AS3935_I2C::setI2CAddress(uint8_t devAddx)
@ -52,16 +57,17 @@ void DFRobot_AS3935_I2C::singRegWrite(uint8_t regAdd, uint8_t dataMask, uint8_t
//Serial.println(singRegRead(regAdd),HEX);
}
void DFRobot_AS3935_I2C::defInit()
int DFRobot_AS3935_I2C::defInit()
{
reset(); // reset registers to default
return reset(); // reset registers to default
}
void DFRobot_AS3935_I2C::reset()
int DFRobot_AS3935_I2C::reset()
{
// run PRESET_DEFAULT Direct Command to set all registers in default state
I2c.write(devAdd, (uint8_t)0x3C, (uint8_t)0x96);
int error = I2c.write(devAdd, (uint8_t)0x3C, (uint8_t)0x96);
delay(2); // wait 2ms to complete
return error;
}
void DFRobot_AS3935_I2C::calRCO()
@ -139,8 +145,8 @@ void DFRobot_AS3935_I2C::setTuningCaps(uint8_t capVal)
{
singRegWrite(0x08, 0x0F, (capVal >> 3)); // set capacitance bits
}
Serial.print("capacitance set to 8x");
Serial.println((singRegRead(0x08) & 0x0F));
//Serial.print("capacitance set to 8x");
//Serial.println((singRegRead(0x08) & 0x0F));
}
uint8_t DFRobot_AS3935_I2C::getInterruptSrc(void)

@ -16,12 +16,13 @@ class DFRobot_AS3935_I2C
{
public:
DFRobot_AS3935_I2C(uint8_t irqx, uint8_t devAddx);
DFRobot_AS3935_I2C(uint8_t irqx);
/*! Set i2c address */
void setI2CAddress(uint8_t devAddx);
/*! Manual calibration */
void manualCal(uint8_t capacitance, uint8_t location, uint8_t disturber);
/*! reset registers to default */
void defInit(void);
int defInit(void);
void disturberEn(void);
void disturberDis(void);
void setIRQOutputSource(uint8_t irqSelect);
@ -45,13 +46,13 @@ class DFRobot_AS3935_I2C
void setLcoFdiv(uint8_t fdiv);
/*! View register data */
void printAllRegs(void);
void powerUp(void);
private:
uint8_t irq, devAdd;
uint8_t singRegRead(uint8_t regAdd);
void singRegWrite(uint8_t regAdd, uint8_t dataMask, uint8_t regData);
void reset(void);
void powerUp(void);
int reset(void);
void powerDown(void);
void calRCO(void);
};

@ -5,15 +5,16 @@
This sensor can detect lightning and display the distance and intensity of the lightning within 40 km
It can be set as indoor or outdoor mode.
The module has three I2C, these addresses are:
AS3935_ADD1 0x01 A0 = High A1 = Low
AS3935_ADD3 0x03 A0 = High A1 = High
AS3935_ADD2 0x02 A0 = Low A1 = High
AS3935_ADD1 0x01 A0 = 1 A1 = 0
AS3935_ADD2 0x02 A0 = 0 A1 = 1
AS3935_ADD3 0x03 A0 = 1 A1 = 1
Copyright [DFRobot](http://www.dfrobot.com), 2018
Copyright GNU Lesser General Public License
version V0.4
date 2018-11-15
version V0.5
date 2018-11-28
*/
#include "Lib_I2C.h"
@ -26,22 +27,12 @@ volatile int8_t AS3935IsrTrig = 0;
// Antenna tuning capcitance (must be integer multiple of 8, 8 - 120 pf)
#define AS3935_CAPACITANCE 96
// Indoor/outdoor mode selection
#define AS3935_INDOORS 0
#define AS3935_OUTDOORS 1
#define AS3935_MODE AS3935_INDOORS
// Enable/disable disturber detection
#define AS3935_DIST_DIS 0
#define AS3935_DIST_EN 1
#define AS3935_DIST AS3935_DIST_EN
// I2C address
#define AS3935_I2C_ADDR AS3935_ADD2
#define AS3935_I2C_ADDR AS3935_ADD3
void AS3935_ISR();
DFRobot_AS3935_I2C lightning0((uint8_t)IRQ_PIN, (uint8_t)AS3935_I2C_ADDR);
DFRobot_AS3935_I2C lightning0((uint8_t)IRQ_PIN);
void setup()
{
@ -57,9 +48,12 @@ void setup()
lightning0.setI2CAddress(AS3935_ADD3);
// Set registers to default
lightning0.defInit();
if(lightning0.defInit() != 0){
Serial.println("I2C init fail");
while(1){}
}
// Configure sensor
lightning0.manualCal(AS3935_CAPACITANCE, AS3935_MODE, AS3935_DIST);
lightning0.powerUp();
//set indoors or outdoors models
lightning0.setIndoors();
@ -69,6 +63,12 @@ void setup()
lightning0.disturberEn();
//lightning0.disturberDis();
lightning0.setIRQOutputSource(0);
delay(500);
//set capacitance
lightning0.setTuningCaps(AS3935_CAPACITANCE);
Serial.println("AS3935 manual cal complete");
// Enable interrupt (connect IRQ pin IRQ_PIN: 2, default)
// Connect the IRQ and GND pin to the oscilloscope.
// uncomment the following sentences to fine tune the antenna for better performance.
@ -77,12 +77,12 @@ void setup()
// lightning0.setLcoFdiv(0);
// lightning0.setIRQOutputSource(3);
// Set the noise level,use a default value greater than 7
// Set the noise level,more than 7 will use the default value:2
lightning0.setNoiseFloorLvl(2);
//uint8_t noiseLv = lightning0.getNoiseFloorLvl();
//used to modify WDTH,alues should only be between 0x00 and 0x0F (0 and 7)
lightning0.setWatchdogThreshold(0);
lightning0.setWatchdogThreshold(1);
//uint8_t wtdgThreshold = lightning0.getWatchdogThreshold();
//used to modify SREJ (spike rejection),values should only be between 0x00 and 0x0F (0 and 7)

@ -5,15 +5,15 @@
This sensor can detect lightning and display the distance and intensity of the lightning within 40 km
It can be set as indoor or outdoor mode.
The module has three I2C, these addresses are:
AS3935_ADD1 0x01 A0 = High A1 = Low
AS3935_ADD3 0x03 A0 = High A1 = High
AS3935_ADD2 0x02 A0 = Low A1 = High
AS3935_ADD1 0x01 A0 = 1 A1 = 0
AS3935_ADD2 0x02 A0 = 0 A1 = 1
AS3935_ADD3 0x03 A0 = 1 A1 = 1
Copyright [DFRobot](http://www.dfrobot.com), 2018
Copyright GNU Lesser General Public License
version V0.4
date 2018-11-15
version V0.5
date 2018-11-28
*/
#include "Lib_I2C.h"
@ -56,7 +56,10 @@ void setup()
delay(2);
// Set registers to default
lightning0.defInit();
if(lightning0.defInit() != 0){
Serial.println("I2C init fail");
while(1){}
}
// Configure sensor
lightning0.manualCal(AS3935_CAPACITANCE, AS3935_MODE, AS3935_DIST);
// Enable interrupt (connect IRQ pin IRQ_PIN: 2, default)

@ -46,6 +46,7 @@ getSpikeRejection KEYWORD2
setSpikeRejection KEYWORD2
setLcoFdiv KEYWORD2
printAllRegs KEYWORD2
powerUp KEYWORD2
#######################################
# Constants (LITERAL1)

@ -50,10 +50,19 @@ Download the library ZIP file and unzip it to the Arduino folder of the library.
*/
DFRobot_AS3935_I2C(uint8_t irqx, uint8_t devAddx);
/*
* @brief AS3935 object
*
* @param irqx irq pin
*/
DFRobot_AS3935_I2C(uint8_t irqx);
/*
* @brief reset registers to default
*
* @return 0 success
*/
void defInit(void);
int defInit(void);
/*
* @brief set i2c address

Loading…
Cancel
Save