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)
This commit is contained in:
parent
88a48da595
commit
3d0dbe28fe
|
@ -15,16 +15,18 @@
|
||||||
void setup() {
|
void setup() {
|
||||||
Wire.begin(); // join i2c bus (address optional for master)
|
Wire.begin(); // join i2c bus (address optional for master)
|
||||||
Serial.begin(115200); // start serial for output
|
Serial.begin(115200); // start serial for output
|
||||||
while(!Serial);
|
while (!Serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
Wire.requestFrom(0x5F, sizeof(int)); // request 6 bytes from slave device #8
|
Wire.requestFrom(0x65, 2);
|
||||||
|
// Wait for data to become available -- can be a delayed response due to # of pins to enumerate
|
||||||
//while (Wire.available()) { // slave may send less than requested
|
while(!Wire.available());
|
||||||
uint8_t value = Wire.read(); // receive a byte as character
|
byte dip_1 = Wire.read();
|
||||||
Serial.println(value); // print the character
|
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);
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
|
@ -12,7 +12,7 @@
|
||||||
// 07 5/PD3/INT1
|
// 07 5/PD3/INT1
|
||||||
// 08 6/PD4
|
// 08 6/PD4
|
||||||
// 09 7/PD5
|
// 09 7/PD5
|
||||||
// 10 GND
|
// 10 GND
|
||||||
// 11 8/PD6
|
// 11 8/PD6
|
||||||
// 12 9/PB0/PCINT0
|
// 12 9/PB0/PCINT0
|
||||||
// 13 10/PB1/PCINT1
|
// 13 10/PB1/PCINT1
|
||||||
|
@ -28,10 +28,15 @@
|
||||||
// sda: 17
|
// sda: 17
|
||||||
// scl: 19
|
// scl: 19
|
||||||
|
|
||||||
// DIP Switch ATTiny Pins
|
// DIP Switch 1 ATTiny Pins
|
||||||
// 2 - 9
|
// 2 - 9
|
||||||
|
|
||||||
#define I2C_ADDRESS 0x96
|
// DIP Switch 2 ATTiny Pins
|
||||||
|
// 1
|
||||||
|
// 11-16
|
||||||
|
// 18
|
||||||
|
|
||||||
|
#define I2C_ADDRESS 0x65
|
||||||
|
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
|
||||||
|
@ -44,7 +49,15 @@ void setup() {
|
||||||
pinMode(5, INPUT);
|
pinMode(5, INPUT);
|
||||||
pinMode(6, INPUT);
|
pinMode(6, INPUT);
|
||||||
pinMode(7, 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.begin(I2C_ADDRESS);
|
||||||
Wire.onRequest(requestEvent);
|
Wire.onRequest(requestEvent);
|
||||||
}
|
}
|
||||||
|
@ -55,15 +68,24 @@ void loop() {
|
||||||
|
|
||||||
// function that executes whenever data is requested by master
|
// function that executes whenever data is requested by master
|
||||||
// this function is registered as an event, see setup()
|
// this function is registered as an event, see setup()
|
||||||
byte dip_switch = 0b00000000;
|
byte dip_switches[] = {0b00000000, 0b00000000};
|
||||||
void requestEvent() {
|
void requestEvent() {
|
||||||
bitWrite(dip_switch, 0, digitalRead(0));
|
bitWrite(dip_switches[0], 7, digitalRead(0));
|
||||||
bitWrite(dip_switch, 1, digitalRead(1));
|
bitWrite(dip_switches[0], 6, digitalRead(1));
|
||||||
bitWrite(dip_switch, 2, digitalRead(2));
|
bitWrite(dip_switches[0], 5, digitalRead(2));
|
||||||
bitWrite(dip_switch, 3, digitalRead(3));
|
bitWrite(dip_switches[0], 4, digitalRead(3));
|
||||||
bitWrite(dip_switch, 4, digitalRead(4));
|
bitWrite(dip_switches[0], 3, digitalRead(4));
|
||||||
bitWrite(dip_switch, 5, digitalRead(5));
|
bitWrite(dip_switches[0], 2, digitalRead(5));
|
||||||
bitWrite(dip_switch, 6, digitalRead(6));
|
bitWrite(dip_switches[0], 1, digitalRead(6));
|
||||||
bitWrite(dip_switch, 7, digitalRead(7));
|
bitWrite(dip_switches[0], 0, digitalRead(7));
|
||||||
Wire.write(dip_switch);
|
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,11 +115,19 @@ esphome:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
digitalWrite(13, LOW);
|
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 config
|
||||||
wifi:
|
wifi:
|
||||||
ssid: !secret wifi_ssid
|
ssid: !secret wifi_ssid
|
||||||
password: !secret wifi_password
|
password: !secret wifi_password
|
||||||
domain: !secret node_domain
|
domain: !secret node_domain
|
||||||
|
power_save_mode: light
|
||||||
|
|
||||||
# Enable I2C (Qwiic and others)
|
# Enable I2C (Qwiic and others)
|
||||||
i2c:
|
i2c:
|
||||||
|
@ -134,7 +142,7 @@ spi:
|
||||||
deep_sleep:
|
deep_sleep:
|
||||||
id: deep_sleep_main
|
id: deep_sleep_main
|
||||||
run_duration: 5min
|
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
|
wakeup_pin_mode: INVERT_WAKEUP # stop caring and be judicious about tolerance of goofy pin modes
|
||||||
|
|
||||||
# Enable logging
|
# Enable logging
|
||||||
|
|
Loading…
Reference in New Issue