Arduino USB > Firmata > I2C > [GPIO PCF8574 + MCP23017 + temp BMP280]

My question is:

  • What is the recommended way to connect multiple I2C boards to Arduino boards to:
    use both Ardu's GPIOs + the I2C expanders too?
  • Is firmata standard suitable for that, or I need to specify the I2C boards at the Arduino IDE, by writing a special C program?
  • What if I use MQTT for all those to be able to use ESP32 or Ethernet modules also?
  • Isn't MQTT too slow for handling "long press" + "Continuous dimming"?

Is there ANY full-example for this?

(I simply can not believe nobody ever used more than 16 IO ports and some I2C sensors plugged in via USB... )

< OFF >
I just wanted to control my house with wired, cheap :money_mouth_face: things...
(Had an expensive HomeControl before, but it's burned by a lightning.)

  • Bought all those things >>>
  • plugged in some Arduino boards via USB into my Raspberry Pi4 >>>
  • connected 8x PCF8574 + some MCP23017 via I2C >>>
  • and thought I just need to click "Discover" in OpenHAB and should work... :face_with_hand_over_mouth:

After 2 :spiral_calendar: month of searching the forums and analysing GitHub projects: here I am ... while still "sitting in the dark" :milky_way:* (literally, since I still can not use any switches and relays... :woozy_face: )*
So I've registered to this forum to ask for help. (YES, I've searched and red ALLLL topics related to "firmata & i2c" :nerd_face: ... except I've missed one?)

The goal is: to handle EVERY GPIO + sensors + rules via NodeRed, and just "push/receive" messages to/from OpenHAB to visualize the controls+values.
< /OFF >

Hi, can’t help you with firmata but with ESPeasy and ESP8266 (esp32 is as cheap but more complex so start with and ESP8266 - 80 MHz isn’t enough?) or even write your own code. Switching relays should not be a big project. Smooth dimming is more a thing with ESPEasy because it’s smallest timer for rules is 1sec. But own firmware can di the job.
I suggest start small and with simple things and ramp up using the experience you made.
Would not go the openhab/node-red path. Done it before abd not worth the effort taking care of two systems at all times where Node-Red can do the job on it’s own.
Just render the smallest project you can think of and start with that and forget smooth dimming for now.
And Yes you are right mqtt isn’t a good choice for sending values in a ordered and well timed way. Better think about sending one command like dimm, value, time and let the microcontroller do the job.
Discovery via mqtt needs homie compatible devices - ESPEasy & Node-RED can do this too. And much more transparent than openHAB as I experienced it a year ago (perhaps it’s better bow). So grab a Wemos D1 mini and start over again

1 Like

Thank you for sharing your experience!
I knew about ESP things, and I do not wish to buy or use any of those. All the forums are full with those, but, as you already stated yourself:

  • not suitable for quick response time.
  1. If I press a button, or start opening a door >> I need light. Immediately. Not 1+ sec later.
  2. Think about safety! Walking in a dark room is everything but recommended. Many bad things can happen within 1 sec...
  3. If a lightning strikes in nearby again > I don't want to drop into the trash everything again because of Wifi things. Shielded wires do not act as antennas.
  4. OpenHAB can handle my Artnet DMX dimmered bulbs and LED-stripes perfectly fine. None of the other system was able do that so quickly and easily. (Tried many of them!)

I understand you want good with your recommendation, but why do you force me into a way that is the opposite I've asked for?

I understand you are frustrated at not being able to get the information that you want but this is not a general forum for Arduino - it is a Node-RED specific place.

In general, sensors are usually placed around a home and that makes wireless devices more appropriate to communicate back to a central controller running Node-RED which is why ESP devices are generally recommended for such tasks.

Back to the OP - in general I would avoid firmata for all but simple bit banging of io when you want to tie up your PI :slight_smile: You would be better to just write i2c arduino code on the arduino so that it performs the basics of the task you need - and then use the USB serial to send messages to Node-RED - and receive commands - as and when you need to. There are lots of libraries for arduino for specific i2c devices - or just raw commands - but they are all arduino questions not Node-RED.

1 Like

I think you'll need to start with protecting your electrical installation against the lighting. This is quite of job and should not be done cheap way. After that done, it doesn't matter if you install wired or non wired pieces, they will be protected as much you have spent on protection.

Hi, not at all I want to force you into something that you don't like, only some ideas to perhaps solve your problem. You ask a question and you get a answer. Perhaps the answer don`t fit your needs, sorry. But I still have some comments. All only suggestions out of my own experience. Yours might differ

  • You were writing about arduinos and now you mention Artnet DMX. That's a complete other league.
  • I do not see any difference in wireless DMX or Wifi from a security point of view. All runs on the same public frequency band(s).
  • Ligtning problems as @hotNipi suggested probably has to solved in your electrical installation. There is where your KV surge comes from. They are rarely picked up over the air. If so you ... :hushed:
  • Compared to an arduino an ESP is a much more capable solution I have around 20 around my house and I`m happy: (My house was build 1890 with massive brick walls. So rewiring everything down to a switchboard is not an option for me).
  • I never experience a delay of 1sec in my installation. It is more between 25ms and 100ms. (But perhaps because I use professional WiFi-APs , Switch, dedicated Router, Server - All note expensive but selected for best performance - I do not use one of the fit for everything home routers nor a raspberry - but that`s another story.
  • You mentioned MQTT. If this don't suites you, perhaps take a look into websockets. 250Hz or even more is possible. I have currently 1137 topics and around 1.200 Messages per minute on my broker (that`s during development, in idle it is around 500). No performance issues at all.
  • Wifi light switches and dimmers I use (mostly of the shelf products flashed with my own firmware) work with immediate response. (automation is only a secondary mission objective). All a matter of design.
  • Same with other "critical" items like pumps, motors (people get killed by automatic garage doors and other motor driven things) or valves (too much water at the wrong place could do harm too). All of mine have a safe fail mode and can be overruled by physical switches. Timers run on the device not in Node-Red. If (why ever) a connection fails or more likely the software is buggy the valve either does what is safe or finish the task.
  • I gone the route of maintaining 2 systems (openHAB & Node-RED) and they work good together. But for many points you mentioned (security, speed, reliability) bringing another player to the game can create another bottleneck. Switch>node-red>openhab>visualize>openhab>node-red>relay? I suggest: switch>relay & >mqtt (with a first short loop feedback by the broker) > Node-Red (with another feedback)>dashboard and back. Perhaps the delay you mention comes form somewhere else.

Sorry If this don`t fit your needs. Sorry for TL;DR

Back to your OP:

  • ESP32 or whatever Yes, this is the way I would go
  • Long press dimming should be done inside the micro controller of your choice. Only send the values to update your visualization. You have the best visualization by your eyes when you press the button standing in the room (or did I understand you wrong again). Finding and opening a app on your phone while you stand in the room finding the correct control ... nice but. A physical wall switch/dimmer is my first choice. And when I switch on my TV/Projector with a good old IR remote control the light dims down. Nice to have but not necessary to work 100%. Or speak to the voice assistant of your choice.

And last but not least: as @dceejay suggested... think about write your own code.

1 Like

< OFF >
Thank you very very much to all of you for all these tips! :blush: :heartbeat:
It's great to see a vivid forum like this with so many people willing to help. I'm touched.

About the lightning:

  • yes, it came through the are Air! (Did not rain, it stroke in dry into the nearby Fuel-station)
  • in a radius of 1km each house in nearby streets suffered from it somehow. (TVs, fridge, heating, PCs, etc.)
  • weather conditions are getting worth each year.

About protection:

  • I use only professional routers + switches too
  • I have a sinus wave Legrand Niky 1500
  • electrically the house is well grounded.
  • the path of destoyed devices were easy to follow back to everything that worked as antennas. (Wifi-Routers, gate-phone)

About the project:

  • My whole house was already wired into one, central place. And I like it this way.
  • There are more than 100 switches hard wired with shielded cables.
  • There are 2 Tablets on walls + 2PC + 4 phones + 1 media server << all those with nonstop-opened HABpanel
  • So it would make much more sense for me to me, to find a software-solution for my existing setup, rather than change drop everything just because "there are more examples for the ESP design".

< /OFF >

It seems to me: Node-Red is the IDEAL, perfect, multi-functional tool, to do everything in "one place", while showing the whole project visually nicely.
I was very happy when I've found this free software, which can handle ALL of those things listed in the Title.

So I'm still looking for a NodeRed sketch / example how to use devices on I2C bus via Firmata?

Not for myself only, but ALL those people searching for the same things.
(Believe me, I have found hundreds of opened topics during these 2 month about these things without any real answers/solution, except: "go and buy some Sonoff / ESP ... thing".)

That's all what I would like to do! :slight_smile: Everything else would be handled at NodeRed.
(Well, maybe later some temp-sensors, but it's ok, to use ESPs for those. Temperature sensing isn't crucial, switching & dimming is.)

I know, but I would like to handle everything in Node-red. Firmata would have been just a "message-forwarder". Or is that not possible at all?
Do I really have to write C code to Arduino to push/receive I/O data from NR?

Isn't it possible to connect somehow Arduino NODE or the Johnny5 node to >> PCF8574 node ?

OK if you insist then this is the node you need to play with -

1 Like

interesting discussion, ideas and experiences!

I don't have much to add, the wired and wireless modes of communication have their advantages and disadvantages.

The Arduino and port expander via I2C works great, but you need to build the code depending on your preferences.
Further communication is via USB.

I was dealing with a PCF8575 (16x I/O port expander).
An Arduino with 4xPCF8575 (total = 64 inputs or outputs) works great.

What I would recommend is to use the interrupt function (from PCF8575 pdf: An interrupt is generated by any rising or falling edge of the port inputs in the input mode.).
The alternative to this is to do polling, but this causes constant activity on the USB and additional CPU load. On the Raspberry Pi 3B, depending on the frequency of polling, the CPU was about 20-35% increased, which is not small.
In my opinion, it is better to use interrupt and the option to call port readings as needed (see trigger below).
With this, in a static situation, there is no USB traffic in practice and therefore no processing.

The PCF8575 I/O operates at 5V and as such can directly control the relays or relays modules.
Care should be taken here to choose the "Trigger LOW" module.
Selecting such a relay module avoids flickering when booting arduino & PCF8575.
Also choosing module with optocouplers avoids the need for additional driver chips as is ULN2803.
Of course, choose the 5V relay module (with this module the trigger is 5V of course).
If you choose a 12V relay module, you will need to redesign the 5V trigger module.

I needed to develop a wire type I/O module, and choosing the Arduino (Nano) and PCF8575 was a winning combination for me.

My working principle (Arduino code) is extremly simple and ideal for Node-RED.

In short:
Eg. to set a port to a specified state. Send command: < A10 >. (without space; can't post like that).
In this case:
A = first group of 8 ports (first bank of PCF8575)
1 = port number,
0 = port state.


That is all for turn the relay ON or OFF!

To read the port status, it is easiest to install node-red-contrib-PCF8575-extractor (link is in the documentation).
After configuration (just choose which group of inputs to analyze), and on the outputs we have a state for each individual port.
The output states are 1, 0, or E.
1 = status is 1 :smile:
0 = status is 0,
E = Error (PCF8575 did not respond).


That is all, connect/disconnect port to GND and node output will be changed!

Each change on any port sends the state of the entire group (8xport).

It can also be posiible to send a trigger message (manual or at intervals) according to the USB.
The command to send is < T > (without space again).
This command checks all ports and returns statuses, including errors on PCF8575 (if any).

Full documentation is at

I hope it helps in which direction to go and what logic is used.

P.S. The module described on the link can work as an input or output module (selected by jumper).


1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.