-
-
Save glmnet/49ca3d6a9742fc3649f4fbdeaa4cdf5d to your computer and use it in GitHub Desktop.
// this gist is no longer needed, | |
// see https://github.com/glmnet/esphome-components/blob/main/docs/arduino_port_extender.md | |
// for up to date information |
// this gist is no longer needed, | |
// see https://github.com/glmnet/esphome-components/blob/main/docs/arduino_port_extender.md | |
// for up to date information |
No I have not, what pin are you using, analog or digital?
@kc9ryt I confirmed with @glmnet and they said it is not currently possible to utilize this library like that as it has no way to link up the encoder stuff in ESPHome with the Arduino port expander. You would have to modify the code base to allow it to accept these functions.
I found another Arduino library that allows you to use Rotary Encoders over I2C but in its current state can't just be utilized like this library by including it and would have to be modified to be properly compatible. I ask the maintainer if it was possible to do something like this. They said they may be able to look into it unfortunately their health faltered and couldn't look into it.
Is there a new code compatible with Home Assistant 2023.8.2. if not, is it possible to modify the code ?
Is there a new code compatible with Home Assistant 2023.8.2. if not, is it possible to modify the code ?
This should work with latest HA and latest ESPHome, I’m still using it. If you need help go to discord server and ask there. When something doesn’t work you should say what the issue is otherwise nobody will know and won’t be able to help you.
How can I use this arduino port expander to read a dallas sensor ds18b20 connected to pin D2? is it a binary?
How can I use this arduino port expander to read a dallas sensor ds18b20 connected to pin D2? is it a binary?
Not possible
I am using this ino and h file for my ESPHome project.
I have described my Problem here: https://community.home-assistant.io/t/arduino-port-expander-problem-with-analog-and-digital-inputs/640313/2 and I think I have solved the Problem by myself by uncomment this line: https://gist.github.com/glmnet/49ca3d6a9742fc3649f4fbdeaa4cdf5d#file-arduino_port_expander-h-L180
I can use now both Pins (for example D3 for Output and A3 for Analog Input)
can you try the external component version?
it seems custom components are not going to be supported so I created this new version, I'm actively using for binary sensors and outputs, but did also try analog sensors and seems to work.
The arduino code is the same, no need to update it
you need to remove the - include on esphome: and see this example below:
external_components:
- source: github://glmnet/esphome@ape-external-component
components: [arduino_port_expander]
arduino_port_expander:
id: x
address: 0x08
analog_reference: DEFAULT
binary_sensor:
- platform: gpio
pin:
arduino_port_expander: x
number: 12
mode:
input: True
pullup: True
name: bs-12
id: ape_12
on_state:
then:
- light.toggle: l1
output:
- platform: gpio
pin:
arduino_port_expander: x
number: 13
mode:
output: True
id: ape_13
sensor:
- platform: arduino_port_expander
id: sx
pin: A0
name: Ardu A0
update_interval: 10s
filters:
- multiply: 0.0032258064516129 # x / 1023.0 * 3.3 v
I still need to put some readme somewhere, help welcome btw
For discussion https://discord.com/channels/429907082951524364/1169551049493860371
Nice, looks like, that it's working :-)
I can not test binary_sensor, but my 8 Outputs and 6 Analog Inputs are working directly.
My big test example:
esphome:
name: test_arduino
esp8266:
board: d1_mini
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
api:
ota:
# define i2c device
# for an ESP8266 SDA is D2 and goes to Arduino's A4
# SCL is D1 and goes to Arduino's A5
i2c:
id: i2c_component
logger:
level: DEBUG
external_components:
- source: github://glmnet/esphome@ape-external-component
components: [arduino_port_expander]
arduino_port_expander:
id: ape
address: 0x08
analog_reference: DEFAULT
output:
- platform: gpio
pin:
arduino_port_expander: ape
number: 9
mode:
output: True
id: relay_1
inverted: true
- platform: gpio
pin:
arduino_port_expander: ape
number: 8
mode:
output: True
id: relay_2
inverted: true
- platform: gpio
pin:
arduino_port_expander: ape
number: 7
mode:
output: True
id: relay_3
inverted: true
- platform: gpio
pin:
arduino_port_expander: ape
number: 6
mode:
output: True
id: relay_4
inverted: true
- platform: gpio
pin:
arduino_port_expander: ape
number: 5
mode:
output: True
id: relay_5
inverted: true
- platform: gpio
pin:
arduino_port_expander: ape
number: 4
mode:
output: True
id: relay_6
inverted: true
- platform: gpio
pin:
arduino_port_expander: ape
number: 3
mode:
output: True
id: relay_7
inverted: true
- platform: gpio
pin:
arduino_port_expander: ape
number: 2
mode:
output: True
id: relay_8
inverted: true
switch:
- platform: output
name: Relais 1
id: relais01
output: relay_1
- platform: output
name: Relais 2
id: relais02
output: relay_2
- platform: output
name: Relais 3
id: relais03
output: relay_3
- platform: output
name: Relais 4
id: relais04
output: relay_4
- platform: output
name: Relais 5
id: relais05
output: relay_5
- platform: output
name: Relais 6
id: relais06
output: relay_6
- platform: output
name: Relais 7
id: relais07
output: relay_7
- platform: output
name: Relais 8
id: relais08
output: relay_8
sensor:
- platform: arduino_port_expander
id: analog_input_1_humidity
pin: A6
name: Eingang 1 Bodenfeuchtigkeit
unit_of_measurement: "%"
device_class: humidity
state_class: measurement
accuracy_decimals: 0
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- calibrate_linear:
- 0.95 -> 100
- 2.5 -> 0
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);
- platform: arduino_port_expander
id: analog_input_1_voltage
pin: A6
name: Eingang 1 Spannung
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- platform: arduino_port_expander
id: analog_input_2_humidity
pin: A7
name: Eingang 2 Bodenfeuchtigkeit
unit_of_measurement: "%"
device_class: humidity
state_class: measurement
accuracy_decimals: 0
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- calibrate_linear:
- 0.95 -> 100
- 2.5 -> 0
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);
- platform: arduino_port_expander
id: analog_input_2_voltage
pin: A7
name: Eingang 2 Spannung
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- platform: arduino_port_expander
id: analog_input_3_humidity
pin: A0
name: Eingang 3 Bodenfeuchtigkeit
unit_of_measurement: "%"
device_class: humidity
state_class: measurement
accuracy_decimals: 0
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- calibrate_linear:
- 0.95 -> 100
- 2.5 -> 0
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);
- platform: arduino_port_expander
id: analog_input_3_voltage
pin: A0
name: Eingang 3 Spannung
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- platform: arduino_port_expander
id: analog_input_4_humidity
pin: A1
name: Eingang 4 Bodenfeuchtigkeit
unit_of_measurement: "%"
device_class: humidity
state_class: measurement
accuracy_decimals: 0
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- calibrate_linear:
- 0.95 -> 100
- 2.5 -> 0
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);
- platform: arduino_port_expander
id: analog_input_4_voltage
pin: A1
name: Eingang 4 Spannung
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- platform: arduino_port_expander
id: analog_input_5_humidity
pin: A2
name: Eingang 5 Bodenfeuchtigkeit
unit_of_measurement: "%"
device_class: humidity
state_class: measurement
accuracy_decimals: 0
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- calibrate_linear:
- 0.95 -> 100
- 2.5 -> 0
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);
- platform: arduino_port_expander
id: analog_input_5_voltage
pin: A2
name: Eingang 5 Spannung
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- platform: arduino_port_expander
id: analog_input_6_humidity
pin: A3
name: Eingang 6 Bodenfeuchtigkeit
unit_of_measurement: "%"
device_class: humidity
state_class: measurement
accuracy_decimals: 0
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
- calibrate_linear:
- 0.95 -> 100
- 2.5 -> 0
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);
- platform: arduino_port_expander
id: analog_input_6_voltage
pin: A3
name: Eingang 6 Spannung
update_interval: 10s
filters:
- multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
I am embarking on a project in which I need to use H711X
, which is natively supported by esphome but I do not have more pins for it.
I have quite a few sensors connected via I2C and when I saw this component arduino_port_expander
that allows you to expand I/O ports via I2C I thought it would be a very good option.
I had a pro mini lying around the house so I decided to upload the sketch and connect it to the esp32c3.
I currently do not have the H711X
, since I am considering the possibility of using it via I2C, but I have a DHT11
at home and I decided to test if the arduino_port_expander
component allows me to control it.
First I did tests by configuring an output associated with pin 13 of the Arduino and I was able to control the LED from home assistant perfectly.
Once I verified that arduino_port_expander
was working correctly I decided to try the DHT11
. First I had to modify the DHT11
component so that it allowed the arduino_port_expander
pins to be configured and not just the internal ones of the esp32 running esphome. Change InternalGPIOPin
to GPIOPin
in yaml:
arduino_port_expander:
id: ape1 # must identify somehow to later use
i2c_id: tca9548a_ch0
address: 0x08
analog_reference: DEFAULT
sensor:
- platform: dht
pin:
arduino_port_expander: ape1
number: 2
temperature:
name: "Living Room Temperature"
humidity:
name: "Living Room Humidity"
update_interval: 60s
Unfortunately, although it compiles perfectly, on boot it causes bootloop (I imagine due to wdt)
It seems that the sensors where communication is time critical do not work through I/O I2C expanders.
Still, arduino_port_expander
is a cool component.
Thank you!
I forgot to mention here I created a new repo for this. See here
@fran6120 thats a nice story but the end was predicted. If you’re short on pins you can try to use the expander for simple io pins, eg relays switches and save internal gpio for sensors which requiere fast io pins. (And also switching pin mode from input to output quickly)
Hi, do you know about the Problem, that neighborhood Analog Inuts have wrong values.
I want to read some of those Sensors: https://de.aliexpress.com/item/1005004819365767.html
Reading a single Sensor has no problems (eg A0). But if I add a second one to A1, the voltage is much higher as its really is.
I have no really solution.
On some Formthreads, they write, that you have to read the ANalog Pin twice and only use the second result:
https://forum.arduino.cc/t/analog-input-affected-by-its-neighbor/88758
or
https://forum.arduino.cc/t/cross-voltages-from-neighbor-analog-input/178708
That’s interesting. Didn’t know
you can try using update interval: none on the sensor s so you disable automatic polling. Then write an interval script which will call component update on the sensors, eg call it twice in A0 and the pick the value on the second call then call twice A1
Do you have a small example for me? I will test it shortly.
This does disables polling and calls to update explicitly
https://github.com/glmnet/esphome_devices/blob/master/my_home/eh-energia.yaml
You might want to create another template sensor which you’ll set the value you read the second time
Thank you,
I think I got it.
I added a dummy analogRead() to the arduino Script before the reading for publishing.
Also I found a thread: firmata/arduino#334 (comment)
I also have added a interval Script to my yaml, to read the Analog Sensors in the correct sequence
- interval: 60s
then:
- component.update: analog_input_3_humidity
- delay: 1s
- component.update: analog_input_3_voltage
- delay: 10s
- component.update: analog_input_4_humidity
- delay: 1s
- component.update: analog_input_4_voltage
- delay: 10s
- component.update: analog_input_5_humidity
- delay: 1s
- component.update: analog_input_5_voltage
- delay: 10s
- component.update: analog_input_6_humidity
- delay: 1s
- component.update: analog_input_6_voltage
- delay: 10s
- component.update: analog_input_1_humidity
- delay: 1s
- component.update: analog_input_1_voltage
- delay: 10s
- component.update: analog_input_2_humidity
- delay: 1s
- component.update: analog_input_2_voltage```
Now I will test it for a couple of Days :-)
Hola buen dia. Existe la manera de usar el sensor dht11 conectado en arduino. Soy nuevo en esto y no he encontrado la manera.
Hello i am trying to use Arduino Port Expander in my home project where reliability is really important .
As a test, temporary I braked the i2c line between the port expander and the esp device. I got a following error immediately (which is good) :
[E][component:112]: Component was marked as failed.
And never recovered (that is not good).
I wonder how can this made more robust? eg. after the transient is gone should recover by them self.
Thank you
Hello everyone,
I have a little dumb question, I have it all working (the first version was working for me here),
but .... if the i2c bus hangs for some reason, I know the command to reset the ESP8266 ---> "- platform: restart",
but not the NANO (in my case) ... (so the i2c bus won't reset), is there a easy way to reset the NANO too in that same command ?
GreetingZzz
lol ... I see it now, @balazs111 has the same question :-)
Hello,
here is the solution: https://community.home-assistant.io/t/arduino-port-expander-i2c-connection-not-recover-after-failure/745984
In the end decided to use modbus because i needed to breach a longer distance what i2c was not able to handle
Hi @glmnet,
any chance you make a version for Arduino Mega 2560?
I've been using a modified version from @thebradleysanders in the last years, but with the migration from custom to external components I've lost the possibility to update my devices with the latest versions of esphome.
Thanks. Bye,
Vito
@NonaSuomy Did you ever figure out how to get a rotary encoder to work?