esphome-docs/custom/spi.rst

40 lines
890 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
2018-12-01 09:46:37 +01:00
a device into esphomelib that uses this protocol you can pretty much use almost
2018-12-05 10:19:48 +01:00
all Arduino-based code because the ``SPI`` library is also available in esphomelib.
2018-12-01 09:46:37 +01:00
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 {
2018-12-05 10:19:48 +01:00
SPI.pins(SCK_PIN, MISO_PIN, MOSI_PIN);
SPI.begin();
2018-12-01 09:46:37 +01:00
2018-12-05 10:19:48 +01:00
pinMode(CS_PIN, OUTPUT);
2018-12-01 09:46:37 +01:00
}
void loop() override {
2018-12-05 10:19:48 +01:00
digitalWrite(CS_PIN, LOW);
SPI.beginTransaction(...);
SPI.write(0x42);
digitalWrite(CS_PIN, HIGH);
2018-12-01 09:46:37 +01:00
}
};
See Also
--------
- :ghedit:`Edit`
2018-12-01 09:46:37 +01:00
.. disqus::