esphome-docs/custom/spi.rst
Otto Winter 8d9b0d2375
Netlify (#153)
* Netlify

* Fix

* Faster doxygen

* Update Makefile

* Try without api

* Debug

* Fix

* Update Makefile

* Debug

* Try 1.8.13

* Remove debug

* Update Makefile

* Optimize
2019-02-07 13:54:45 +01:00

40 lines
890 B
ReStructuredText

Custom SPI Device
=================
Lots of devices communicate using the SPI protocol. If you want to integrate
a device into esphomelib that uses this protocol you can pretty much use almost
all Arduino-based code because the ``SPI`` library is also available in esphomelib.
See the other custom component guides for how to register components and make
them publish values.
.. code-block:: cpp
#include "esphomelib.h"
using namespace esphomelib;
class MyCustomComponent : public Component {
public:
void setup() override {
SPI.pins(SCK_PIN, MISO_PIN, MOSI_PIN);
SPI.begin();
pinMode(CS_PIN, OUTPUT);
}
void loop() override {
digitalWrite(CS_PIN, LOW);
SPI.beginTransaction(...);
SPI.write(0x42);
digitalWrite(CS_PIN, HIGH);
}
};
See Also
--------
- :ghedit:`Edit`
.. disqus::