Hurrah! Finally had time to get the AS3935 lightning detector working! And it took some time….
With all these hot days over the last week there have been a few thunder storms. So the mission was to try and capture one with the new module to see if it really works.
The main difference between the Embedded Adventures module and the ones that have come before is this one defaults to using I2C rather than SPI. There are a number of Arduino libraries for this chip but only SloMusti’s supports I2C. This library does not use the stock Wire I2C library so you also have to download Rambo’s I2C library.
So wired it all up to my Arduino Nano that lives in my breadboard… not a lot happened!
First gotcha, the embedded adventures board has the I2C address hard wired as 0x03. So quick change to the example code and all looked better.
It appears there are some issues using the AS3935 chip in I2C mode with the default address of 0x00. I didn’t actually think that was a valid I2C address… never mind! Oh the joys of errata sheets.
Well… I can see the clouds flashing outside the window, I can hear the distant rumbles and the Isle if Wight live storm data showed there were about 100 strikes a minute within a 60 mile radius. I live about 20 miles north of their site so I should have been detecting. Nope!
Did some searching, saw people testing it with a piezo sparker so grabbed my blowtorch and clicked away… nothing. GRR!! Its 1am on a friday night so tired and fuzzy so went to bed a little pissed off.
Saturday morning is nice and sunny so no lightning to detect. GRRRR!! Did some more searching and came across this jem:
“The behaviour using I2C at address 0 is known to me and worked arround by using the address ADD0=ADD1=1 (Vdd). Testing this I have found another issue: If the voltage regulator is turned on, ADD0 and ADD1 must not be connected to Vdd (as described in the data sheet). If the voltage regulator is turned on and one of the address pins is set to the positive voltage supply (Vdd), the chip-intern voltage regulator will not be able to regulate the voltage. In my case the output regulated voltage was 4,3V instead of 3V as described in data sheet. I have contacted the AMS support with it and they confirmed this issue. They recommended to me to set the ADD0 and ADD1 pins to the voltage regulated supply (VREG). After connecting the address pins to VREG the regulated voltage became 3V =).”
I’d been powering it from 5V as the datasheet for the board stated 2.4-5.5V. Hmm… Flipped the power wire from the 5V to 3.3V, plugged the Nano into my PC, clicked the sparker on my blowtorch and BINGO! It registered as a ‘disturber’. Basically a signal that was generated by a spark but not real lightning.
So epic relief that the board was not a duffer, extreme annoyance that I’d missed a good storm and a bit of frustration that this chip appears to be more errata than datasheet. I see why the Tautic board was SPI.
Next job: convert the AS3935 library to use the Wire I2C and to allow direct writing of a known calibration value to the chip.
Also I need to look at the Wire library supplied with the generic STM32 Arduino support. It looks like it is bitbashed. Need to get it using the hardware I2C interfaces on the Cortex M3 STM32. Much faster and a lot less CPU time needed.