ironsheep/lightning-detector-MQTT2HA-Daemon

Could you add an SPI interface?

Closed this issue · 24 comments

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

The current version (2) of SparkFun Lightning Detector - AS3935 comes with an SPI interface
The SparkFun clams the I2C interface is not reliable.
The I2C interface is still on the board, but looks like you have to cut traces on the board to enable it.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Add a SPI interface to the Daemon

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Cutting traces is a last resort and may cause the board to be unreliable due to the I2C chipset.
I would probably attempt to add the SPI interface.

Additional context
Add any other context or screenshots about the feature request here.

My board arrives tomorrow (July 20). Looking forward to playing with it in HA.
Thx

I can help if you are willing to do a bit of the work ;-) The two interfaces from a python code perspective should be pretty similar.

At first blush the worklist appears to be:

  • locate SPI python code that we can pattern after (do you have any, or know of, working examples?)
  • adapt the current code to select between SPI/i2c with new config.ini setting
  • add the SPI code and runtime switch between
  • test the new SPI support (code and setup docs) against a sensor board... to prove it all working
  • adjust the setup part of the README to describe what's needed to enable SPI (or i2C) depending on which the user wants.
  • release the new version to the repo.

I'm in the midst of a number of small projects (pretty much my life all the time ;-) but I can put some time into this if you will too.

Thoughts?

Nice, I'll lead off while you are wiring up by adding the config option in the code to select between SPI/I2C... I'll send a .zip to you... you can contact me at stephen@ironsheep.biz by email and I'll send it by return email...

Oh, hey alternatively, how about you just work with the content I push to the 'feature_add_spi_support' branch. Then i don't have to email anything... just thinking out loud here ;-)

Let me know if you are not comfortable playing in the source and then I can do the adaptation of SPI once you have working examples...

Any progress with this?

I was planning to attempt this by moving HA from the Hassio minimalist OS to full Raspbian running Hassio Supervised in Docker, however my RPi 3B seems to be running out of memory with HA and everything going when it's installed on Raspbian. Memory usage upwards of 800MB then locks up. Can't figure out how to install Python3 on the Hassio OS version yet.

I've moved HA onto my DS920+ and am gonna setup the RPi 3B to try to figure out the SPI interface of this detector. Goal will be to have the RPi 3B interface over SPI with the detector board, and the RPi will connect to HA's MQTT broker that's running on my DS920+, that way HA and all its addons get to benefit from 20GB of RAM and won't be running out of memory like it was on the RPi 3B.

I took a bunch of code from the RaspberryPi-AS3935 library to test out the code.

I tried out this library too, but it would not connect, with the lightning.connected variable always reporting as false even when using a very simplified code. I ended up using the steps at SparkFun to set the board to I2C. So far the strikes nearby that I can hear myself correspond to to an increase on the Lovelace Card.

I ended up using the steps at SparkFun to set the board to I2C. So far the strikes nearby that I can hear myself correspond to to an increase on the Lovelace Card.

I am having the same issues, but I could not solve them yet. Here I described what I tried:
https://community.home-assistant.io/t/lovelace-lightning-detector-card-for-as3935/214167/6?u=fugazzy
Can you give me a hint?

FYI- the new SPI addition just started working today. I'm finishing the addition an antenna tune portion next.
IMG_7777

Feel free to run the code from the /develop branch while you wait for the next release!

Tomorrow, I'll reconfigure my sensor to use SPI like the manufacturer suggests and see how well the develop branch works. Well, suppose I'll wait around until the next storm to actually make sure that it's working, but it is summer here in the Southeast US, so the next storm should be within a few days.

@lightmaster good, I'll look forward to hearing of your results.

When disabling I2C on the Sparkfun AS3935, after you cut CS and reconnect SI, does it matter whether or not you also cut the I2C PU?

Only cut/short the trace(s)/pad(s) indicated by sparkfun in their docs.
I would do the least amount of work to get SPI to work. If you want to go back to I2C you'll have less to undo.

Which version of their board do you have? Once I know I can then give a more precise answer if needed...

The same version depicted at the Sparkfun guide v20. I followed their directions to enable I2C originally, so I cut the trace SI and connected CS, then connected the middle and right pads on the I2C PU.

OK, reviewing your version (I have the Qwiic version - older model)
You do have to reverse the "Select Interface" shorts/opens.

The "I2C Pull Up Resistors" should be fine without reversing them.

As a note: my board uses 2.2K resistors which are connected all the time where yours' are open but you've shorted the middle and right pads. This will likely work without further change. If they weren't shorted before you awakened I2C then you should also be safe by removing the shorts.

But please let me know.

Its now setup to use SPI using the develop branch. After starting PiGPIOd before manually running the script, I didn't get any errors. I set the service to log to syslog so I can see any errors that might popup and its now running as a service, waiting for a storm to roll by.

Your pull request is merged and this SPI support is now released and avail in v2.2.0 and later.