Arduino i2c Firmata

I have searched for hours but for the life of me can not find any information on using i2c with arduino, my end goal is to use a bme250 using arduino...

Current setup, ATMega using esp8266 for wifi, i can read and write pins.

How do i add the bme sensor to the flow?

1 Like

I've no idea whether you can use I2C with Firmata. Typically, you will write some simple custom Arduino code that uses a suitable library for your sensor.

I assume that, as you are using an attached ESP8266, you are also able to use networking on the Arduino. That means that you can simply add an MQTT library as well to make communication from the Arduino to Node-RED nice and simple.

the firmata library claims it works with i2c. but i dont know where to look for more information or create custom code. all the information i find is .js code and dont know where to put it and all information refers to a raspberry pi

Also, No networking. Using the ESP8266 as a wifi serial adapter. No networking on the mega

It isn't clear to me what devices you have and how they are interconnected and are to communicate with each other. Can you explain that in more detail please.

Unless the Firmata node already supports it, it would need amending. Not sure who is the author - is it a core node? I don't use it.

How is that then consumed on the Pi side? Seems like a bit of a waste of an ESP8266 :grinning:

Take a look at ESPeasy. Install it on the arduino, install MQTT on the Pi (or use another broker that you have installed) It will handle a bme280 sensor fine (I have several WeMos D1 Minis with BME280, DS18B20's or other sensors attached)

The ESPeasy device will send the data - at the interval you set - vie MQTT and you add a MQTT-on node to receive the data. Very simple once you get the process of installing ESPeasy down.

People are getting confused... My connections are;

PC, Debian 9 <------> Wired network <----> Wifi Router <----> ESP8266 <---> Arduino Mega <---> i2c Sensors

PC Running;
Node-Red
And many others

ESP8266 Running;
ESP-Link (Turning the esp8266 into a serial server and connected to the Arduino by serial port 3)

Mega 2560 running;
firmata plus firmware

I2c sensors;
BME280, Light, Air Quality, and others.

I have successful communication to the Arduino and can read write and update by the wifi from the PC.

Problem: No I2c Documentation for Arduino i2c through firmata, Only documents reference Raspberry Pi

What I want: Links to documents/web pages on how i2c works over firmata and arduino, shared experience of how to perform i2c communications through Arduino.

What I don't want: Links to documents/web pages on i2c with Raspberry PI. How to use firmata on Raspberry PI.

I think you need to find an Arduino forum to ask questions about that.

@cymplecy
Even though all the code is written in Node-Red using Node-Red library's ?

The node-red-node-arduino doesn't support i2c. The node-red-contrib-gpio node may do, but may not in the config you have (but worth a try to find out). But the most common arrangement as others have suggested is espeasy or tasmota on the esp with the sensor connected directly (no arduino)

1 Like

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

Is there ANY solution for this since than?
@ajsomething Could you find any examples anywhere to read i2c attached things through Firmata?

Sadly Johnny5 examples showing very strange wiring >> i2c to i2c, and not USB connected Arduino >>> i2c.

I2C standard allows only ca. 20cm maximum. While a shielded USB cable can handle 5meters, and can be extended with active devices multiple +5 +5 +5 meters while using hubs with star topoligy.
With an Ethernet shield 100m is possible.

What is the actual configuration you want... ? and what exact hardware are you targeting.
If you need i2c on arduino then it's usually best to just do that direct on the arduino using normal arduino tooling and then send data over standard serial to pc - or ethernet - or wifi (if not a raw arduino). You can of course also drive i2c direct from a Raspberry Pi running NodeRED - no arduino.

Raspberry Pi <==> Multiple Arduino boards connect with USB + Ethernet <==> all kinds of i2c sensors and additional GPIOs.

That's not really "NodeRed friendly".
Writing codes in C language in an editor that is not much better than a Notepad ... well that's very far from easy & visual & practical.


But since yesterday I think I will just drop Firmata and drop i2c fully,
and will try to move to MQTT2Serial via USB + ModBus attached sensors. (Or maybe Ardulink...)

Because there are too many problems with Firmata boards:

  • can not identify which board is which if the USB port order changes,
  • they do not auto-reconnect after clicking Deploy,
  • blinking PIN13 on startup -->> no way to turn that "feature" off
  • pulling up relays on startup by default

How does Ethernet allow you to connect to i2c?

Good question. I had no time yet to investigate it yet too much.
I guess with an Ethernet shield like here:


... but for Nano. Maybe W5500 ?

Found this:

If you aren't wedded to FIRMATA, this is a standard config. Just use MQTT to carry the data, libraries ready-made for both MQTT and i2c. Seriously, I hate C/C++ but you hardly have to write any code to get a decent sensor platform.

Of course, if you were prepared to consider ESP8266 or ESP32, then you don't need any code at all since there are several really good firmwares that will do the job.

Well as you have found out firmata is not that Node-RED friendly either - it really is a bit of a hack in that it sends continuous traffic up and down to drive it from the host end and poll around the client to read/write it's sensors. Not at all efficient.

As also often mentioned round here chips like the esp8266 and esp32 with built in wifi (and cheaper) are much easier to get connected these days - and then having their own ecosystem like ESPEasy and Tasmota firmware they can often handle most sensors you could possibly want... Ardunio is perfectly fine - but often does require that little bit extra to pull it all together - both those options you found are fine - and yes you will be writing code.

As you mention in one of your other posts - a lot of people here are Home Automation folk - but even that covers a massive range - from those who like writing code - to those who just want to use off the shelf bits and all in between.

2 Likes