Skip to content

Instantly share code, notes, and snippets.

@raphaelyancey
Last active May 6, 2022 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphaelyancey/e89fedf45914b4e7e05d8ed2132089a1 to your computer and use it in GitHub Desktop.
Save raphaelyancey/e89fedf45914b4e7e05d8ed2132089a1 to your computer and use it in GitHub Desktop.
ESPHome & Adafruit DS3502 component
#include "esphome.h"
#include <Adafruit_DS3502.h>
Adafruit_DS3502 ds3502 = Adafruit_DS3502();
#define WIPER_VALUE_PIN A0
class DS3502_Component : public Component
{
public:
void setup() override
{
Serial.begin(115200);
// Wait until serial port is opened
while (!Serial)
{
delay(1);
}
ESP_LOGI("custom", "Adafruit DS3502 Test");
if (!ds3502.begin())
{
ESP_LOGI("custom", "Couldn't find DS3502 chip");
while (1)
;
}
ESP_LOGI("custom", "Found DS3502 chip");
}
void loop() override
{
ESP_LOGI("custom", "Wiper voltage with wiper set to 0: ");
ds3502.setWiper(0);
float wiper_value = analogRead(WIPER_VALUE_PIN);
wiper_value *= 12.0;
wiper_value /= 1024;
ESP_LOGI("custom", "%.1f", wiper_value);
ESP_LOGI("custom", " V");
ESP_LOGI("custom", "");
delay(1000);
ESP_LOGI("custom", "Wiper voltage with wiper set to 63: ");
ds3502.setWiper(63);
wiper_value = analogRead(WIPER_VALUE_PIN);
wiper_value *= 12.0;
wiper_value /= 1024;
ESP_LOGI("custom", "%.1f", wiper_value);
ESP_LOGI("custom", " V");
ESP_LOGI("custom", "");
delay(1000);
ESP_LOGI("custom", "Wiper voltage with wiper set to 127: ");
ds3502.setWiper(127);
wiper_value = analogRead(WIPER_VALUE_PIN);
wiper_value *= 12.0;
wiper_value /= 1024;
ESP_LOGI("custom", "%.1f", wiper_value);
ESP_LOGI("custom", " V");
ESP_LOGI("custom", "");
delay(1000);
}
};
esphome:
name: node
libraries:
- "Arduino"
- "Wire"
- "SPI"
- "Adafruit BusIO"
- "Adafruit DS3502"
includes:
- DS3502.h
# [...]
custom_component:
- lambda: |-
auto ds3502_component = new DS3502_Component();
return {ds3502_component};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment