![]() |
Forum Index : Microcontroller and PC projects : AS3935 lightning detector
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
I have had a play with setting the tuning capacitor. It assumes that your INT pin is also a counting pin. Replace the code starting after the DIM statements to the end of the main loop with: The oscillator frequency appears on the iNT pin so you can connect a meter or use the 'mite to read it. The frequency is the nominal 500kHz divided by 16 = 31250 Hz, well within the range of the 'mites. pressing 'C' while in the main loop will initiate the setcap SUB. It displays the current frequency and asks for a new capacitor value. Valid values are from 1 - 120. The software changes your entered value to a multiple of 8 and sets the register. It then displays the new frequency. entering -1 exits the setcap SUB and returns to the main loop. You should then alter the code with your shiny new capacitor value. A session looks like: VK7JH MMedit |
||||
Justplayin![]() Guru ![]() Joined: 31/01/2014 Location: United StatesPosts: 328 |
Jim, The setcap routine was fun to play with and I can see maybe 88pf value would be better than the 80pf marked on my boards packaging. BUT, your routine doesn't seem to be passing the correct values back to the main program. When I select 88pf the main program sets up for 8pf. Currently the program is not scrolling with the "Noise level too high" message however when I trigger the lightening emulator it only registers as a "disturber" no matter what level strike I trigger. Wish I had more to toy around with the code and compare/decode register values, unfortunately it has been a little extra busy at the office. --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
It looks like I left the *8 of the end of Once you know the new value, set in the DIM statement so it starts with the new value. Interestingly, I get better results with a higher value of cap than the supplied one too. supplied = 96, new value = 112 I measured the frequency with a meter as well as the 'mite. Jim VK7JH MMedit |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Bugger, Still haven't had a chance to try your code yet Jim, & had a pearler of a storm last night. Phil. |
||||
Justplayin![]() Guru ![]() Joined: 31/01/2014 Location: United StatesPosts: 328 |
That fixed the problem with wrong value being returned. Unfortunately after doing the setcap routine the program no longer responds to disturber/lightening events, even if I used the same cap value the program started with. If I re-run the program it works again until I do the setcap. Moved on to trying to produce a lightening interrupt. Eventually, out of frustration, I started plugging random values in for registers 0 and 1 until I finally produced a lightening interrupt. ![]() CASE 1 lightning_dist_km = AS3935_GetLightningDistKm(); Now I need to go back and work out what the values really should be using my random values as a starting reference. The weather channel is predicting thunder storms this weekend... Hopefully I can work them out by then. --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
That rogue semicolon is what happens when you translate arduino code and don't check things well enough. I hope that's the only one I missed. I am going to write a setup program that lets you play with most of the settings. Hopefully, it works better than my present cludge. I would like a bit more information about some of the settings but the chip manufacturer wants you to purchase their development board before you get the setup application notes. No sign of thunder storms here, just warnings about snow. Jim VK7JH MMedit |
||||
Justplayin![]() Guru ![]() Joined: 31/01/2014 Location: United StatesPosts: 328 |
Can't wait! Assembling the bits by hand is a real pain. That explains why the development board is outlandishly expensive and wny the data sheet is lacking in some detail. You can always hope for some rare "thunder snow". ![]() --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
A thunder storm when the hills are covered in snow is impressive to view. But not so impressive if you work for the local electricity mob and are on call Jim VK7JH MMedit |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Hi Jim & Curtis, I'm hoping to set something up to start giving this a try this weekend. Either an E64 or the Original Backpack. On the topic of using the Backpack, I presume the code should be fine if I disable the Display & Touch, but what if I decided to display the output on the LCD? Is that a doable option or is it not possible to use SPI for anything other than the display & touch. The E64 is a bit hard to add a display to without building a birds nest... But the other Option I have is to stick a 2.8" screen on a SnadPic; I do have a couple of Piggy Back boards to do that. (Thanks Palcal). Regards the calibration, I did email their support as they suggest & they replied with a value of 80pF. Thanks Phil. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
Provided you have use chip select pin on the display, you should be able to have both devices co-existing. That is why I only turn the SPI on during read/write operations and leave it fee when not in use. Once setup, the lightning detector doesn't initiate traffic on the SPI. It only triggers an interrupt when it has something to say. There are no critical timing events to worry about. Jim VK7JH MMedit |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Thanks Jim, Getting to it. It will go on a solderless board for starters, but just curious as the whether you went with straight or 90° header pins. 90° ones might.... or might not.... stand the aerial at the top in the final device. I see a 50% chance of deciding I made the wrong decision at a later stage. Phil. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
Phil, Geoff's new update to MMBasic has: . Relaxed error checking on I2C addresses to allow addresses 7 and below to be used. That means you can use I2C to talk to the sensor if it makes sharing easier for you I don't think it will make any difference to the ability of the sensor to do it's job, but it is good to have the choice of communication modes. Jim VK7JH MMedit |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Thanks Jim, I hadn't seen 5.04.05 until you mentioned it. Too busy carting firewood in & fitting a new fan to the wood heater. Expecting a few cold night; the type you are probably not accustom to. -2°C last night & heading for the same again tonight; already down to 5°. Phil. |
||||
Justplayin![]() Guru ![]() Joined: 31/01/2014 Location: United StatesPosts: 328 |
Played around with the register values trying for maximum sensitivity and came up with following: (your actual mileage may vary) Register 0 - 3Eh Register 1 - 11h Register 2 - C0h We had a lightening storm!!! ![]() The good news is I had lightening events triggered, and the distances readings diminished as the storm got closer. The bad news... As the storm moved away, the chip continued to output the distance of the closest event it recorded. The energy readings dropped, but the estimated distance remained at a constant 1km. ![]() --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
It is odd to have users of electronic equipment happy about electrical storms! Going by your settings, I assume you have a quite location as far as radio is concerned. I don't know why the device didn't detect the storm receding. Perhaps clearing the stats would help but according to the data sheet, it should work without any intervention. Jim VK7JH MMedit |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Finally got to have a look at this, but not sure I'm getting the expected results. [Code]wrt: 81 Act: 81 Frequency: 517424 New tuning capacitor (1 - 120pF)? 80 wrt: 8A Act: 8A capacitance set to 8x10 = 80pF Capacitor set to 80pF Frequency: 501728 New tuning capacitor (1 - 120pF)? -1 Playing With Fusion: AS3935 Lightning Sensor, SEN-39001-R01 beginning boot procedure.... wrt: 24 Act: 24 wrt: 20 Act: 20 wrt: 00 Act: 00 wrt: 24 Act: 24 set up for indoor operation wrt: 01 Act: 00 disturber detection enabled wrt: 00 Act: 00 wrt: 01 Act: 01 capacitance set to 8x1 = 8pF AS3935 manual cal complete 17:43:07 06-07-2017 Reg &H00: 24 Reg &H01: 22 Reg &H02: C2 Reg &H03: 00 Reg &H04: 00 Reg &H05: 00 Reg &H06: 00 Reg &H07: 3F Reg &H08: 01 AFE Gain Boost: 10010 Power-down: 0 Noise Floor Level: 010 Watchdog threshold: 0010 Clear statistics: 1 Minimum num lightning:00 Spike rejection: 0010 Freq div -ant tuning: 00 Mask Disturber: 0 Interrupt: 0000 Energy LSB: 00000000 Energy MSB: 00000000 Energy MMSB: 00000 Distance estimation: 111111 Display LCO on IRQ: 0 Display SRCO on IRQ: 0 Display TRCO on IRQ: 0 Internal Tuning Caps: 0001 Energy: 0[/code] It doesn't seem to be responding to the emulator. Also says the capacitor is set to 8pF after I enter 80; have I missed something in the thread? It's currently on a 28 pin backpack, screen & touch not configured. Using I2C (Ver 5.04.05) & Pin 16 for the Irq. Any thoughts? Phil. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
Phil, There are a couple of bugs in my code. Once you know the correct capacitance value, change the value in the DIM statement to suit and then just run the main program. I hope that makes sense! I will update the code with the fixes later. Jim VK7JH MMedit |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
2017-07-06_094644_AS3935.zip OK This version runs the same as before with a few 'refinements' A disturber event simply prints a 'D' rather than waste a full line. all other events print the time and event. Calibrating the capacitor value should work properly now. C to enter the set routine, -1 to exit the set routine. I intend to add adjustments for the other settings eventually. I made a lightning simulator using the Signal Generator Geoff described a few months ago. It seems to work. More details about that later. Jim VK7JH MMedit |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Thanks Jim, It looks like there's a fair bit of info about on different calibration settings. Mostly Arduino routines. Trying to see if I can understand them a bit. Setting the Noise floor was one that jumped out. Found missing edit I had which set 80pF as 8 so past that. But getting a lot of disturbers & a few phantom strikes without triggering the emulator. Guess that's where the noise floor comes in. Final thing I did last night was run it for about 30 seconds & capture the output. A NP++ search for "Disturber Detected" counts 73 instances. But if I then do a search for "Energy: 0", I get a count of 62. Some of the Disturber entries have a significant Energy Value. Don't quite understand what it means, but it's an interesting observation. Searching "Lightning Detected" has a count of 13, And Searching "Energy: 0\r\nLightning detected!" a count of 7. Don't know what that explains either. I attached the capture file if you're interested. Will create another one later & try & add known presses of the different buttons on the Emulator at known time stamps. Cheers. Phil.2017-07-06_213659_AS3935_Output.zip |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
all other events print the time and event. I might revert it to the full line for now; I can easily search that in a capture file. Another thing that might help is a Variable to count the disturbers & report them. Not sure how you'd define my front office in regards to RF noise. There's 3 Fluro's; Elecronic ballast in the 4' & iron in the two 2' ones. There's a Wifi AP a few metres away & another about 5m away in the next room. There's also an ESP-01 on the breadboard I'm using, about 3" away from the Lightning module. Not sure if that's a bad thing or irrelevant. Phil. |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |