esphome-docs/custom/spi.rst

35 lines
826 B
ReStructuredText
Raw Normal View History

2018-12-01 09:46:37 +01:00
Custom SPI Device
=================
2018-12-05 10:19:48 +01:00
Lots of devices communicate using the SPI protocol. If you want to integrate
2019-02-16 23:25:23 +01:00
a device into ESPHome that uses this protocol you can pretty much use almost
all Arduino-based code because the ``SPI`` library is also available in ESPHome.
2018-12-01 09:46:37 +01:00
See the other custom component guides for how to register components and make
them publish values.
2019-03-17 12:10:03 +01:00
Please refer to the SPI library docs for more information.
2018-12-01 09:46:37 +01:00
.. code-block:: cpp
2019-02-16 23:25:23 +01:00
#include "esphome.h"
using namespace esphome;
2018-12-01 09:46:37 +01:00
class MyCustomComponent : public Component {
public:
void setup() override {
2019-03-17 12:10:03 +01:00
SPI.pins(SCK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
2018-12-05 10:19:48 +01:00
SPI.begin();
2018-12-01 09:46:37 +01:00
}
void loop() override {
2019-03-17 12:10:03 +01:00
SPI.beginTransaction(...)
2018-12-05 10:19:48 +01:00
SPI.write(0x42);
2018-12-01 09:46:37 +01:00
}
};
See Also
--------
- :ghedit:`Edit`