Browse Source

Tweak dashboard update interval to help with battery life, add status LED just in case something pops up during operation for better indication of state, add DIP switch code and tweak the DIP switch i2c code to support two 8 pin DIP switches and report data via i2c (not integrated into dashboard yet)

master
KemoNine 3 years ago
parent
commit
3d0dbe28fe
  1. 18
      hardware/arduino/i2c_dip/master_reader/master_reader.ino
  2. BIN
      hardware/arduino/i2c_dip/schematic/Schematic_Home-Assistant_i2c-DIP-Switch_20190530194256.pdf
  3. BIN
      hardware/arduino/i2c_dip/schematic/Schematic_Home-Assistant_i2c-DIP-Switch_20190530194316.png
  4. 50
      hardware/arduino/i2c_dip/slave_sender/slave_sender.ino
  5. 10
      hardware/esphome/plant_dashboard/plant_dashboard.yaml

18
hardware/arduino/i2c_dip/master_reader/master_reader.ino

@ -15,16 +15,18 @@
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(115200); // start serial for output
while(!Serial);
while (!Serial);
}
void loop() {
Wire.requestFrom(0x5F, sizeof(int)); // request 6 bytes from slave device #8
//while (Wire.available()) { // slave may send less than requested
uint8_t value = Wire.read(); // receive a byte as character
Serial.println(value); // print the character
//}
Wire.requestFrom(0x65, 2);
// Wait for data to become available -- can be a delayed response due to # of pins to enumerate
while(!Wire.available());
byte dip_1 = Wire.read();
byte dip_2 = Wire.read();
Serial.print("DIP 1: ");
Serial.println(dip_1, BIN);
Serial.print("DIP 2: ");
Serial.println(dip_2, BIN);
delay(500);
}

BIN
hardware/arduino/i2c_dip/schematic/Schematic_Home-Assistant_i2c-DIP-Switch_20190530194256.pdf

Binary file not shown.

BIN
hardware/arduino/i2c_dip/schematic/Schematic_Home-Assistant_i2c-DIP-Switch_20190530194316.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

50
hardware/arduino/i2c_dip/slave_sender/slave_sender.ino

@ -12,7 +12,7 @@
// 07 5/PD3/INT1
// 08 6/PD4
// 09 7/PD5
// 10 GND
// 10 GND
// 11 8/PD6
// 12 9/PB0/PCINT0
// 13 10/PB1/PCINT1
@ -28,10 +28,15 @@
// sda: 17
// scl: 19
// DIP Switch ATTiny Pins
// DIP Switch 1 ATTiny Pins
// 2 - 9
#define I2C_ADDRESS 0x96
// DIP Switch 2 ATTiny Pins
// 1
// 11-16
// 18
#define I2C_ADDRESS 0x65
#include <Wire.h>
@ -44,7 +49,15 @@ void setup() {
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(17, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
pinMode(15, INPUT);
Wire.begin(I2C_ADDRESS);
Wire.onRequest(requestEvent);
}
@ -55,15 +68,24 @@ void loop() {
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
byte dip_switch = 0b00000000;
byte dip_switches[] = {0b00000000, 0b00000000};
void requestEvent() {
bitWrite(dip_switch, 0, digitalRead(0));
bitWrite(dip_switch, 1, digitalRead(1));
bitWrite(dip_switch, 2, digitalRead(2));
bitWrite(dip_switch, 3, digitalRead(3));
bitWrite(dip_switch, 4, digitalRead(4));
bitWrite(dip_switch, 5, digitalRead(5));
bitWrite(dip_switch, 6, digitalRead(6));
bitWrite(dip_switch, 7, digitalRead(7));
Wire.write(dip_switch);
bitWrite(dip_switches[0], 7, digitalRead(0));
bitWrite(dip_switches[0], 6, digitalRead(1));
bitWrite(dip_switches[0], 5, digitalRead(2));
bitWrite(dip_switches[0], 4, digitalRead(3));
bitWrite(dip_switches[0], 3, digitalRead(4));
bitWrite(dip_switches[0], 2, digitalRead(5));
bitWrite(dip_switches[0], 1, digitalRead(6));
bitWrite(dip_switches[0], 0, digitalRead(7));
bitWrite(dip_switches[1], 0, digitalRead(15));
bitWrite(dip_switches[1], 1, digitalRead(13));
bitWrite(dip_switches[1], 2, digitalRead(12));
bitWrite(dip_switches[1], 3, digitalRead(11));
bitWrite(dip_switches[1], 4, digitalRead(10));
bitWrite(dip_switches[1], 5, digitalRead(9));
bitWrite(dip_switches[1], 6, digitalRead(8));
bitWrite(dip_switches[1], 7, digitalRead(17));
Wire.write(dip_switches, sizeof(dip_switches));
}

10
hardware/esphome/plant_dashboard/plant_dashboard.yaml

@ -115,11 +115,19 @@ esphome:
- lambda: |-
digitalWrite(13, LOW);
# Basic status infos via blinky LED
# https://esphome.io/components/status_led.html
status_led:
pin:
number: 32
inverted: True
# WiFi config
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: !secret node_domain
power_save_mode: light
# Enable I2C (Qwiic and others)
i2c:
@ -134,7 +142,7 @@ spi:
deep_sleep:
id: deep_sleep_main
run_duration: 5min
sleep_duration: 1h
sleep_duration: 90min
wakeup_pin_mode: INVERT_WAKEUP # stop caring and be judicious about tolerance of goofy pin modes
# Enable logging

Loading…
Cancel
Save