Skip to main content
Share Your Experience: Take the 2024 Developer Survey
7 votes
Accepted

Wire.h library works on Uno but won't compile for ATtiny85

You get this error, because the ATTiny85 doesn't have full I2C hardware. It only as an USI (Universal Serial Interface). This can be utilized to do the rest of the I2C protocol via software. There are ...
chrisl's user avatar
  • 16.3k
7 votes
Accepted

How to choose alternate I2C pins on ESP32?

I was able to resolve my issue thanks to Juraj comment. I did : Wire.begin(16, 17); htu21d.begin(Wire);
Gazouu's user avatar
  • 273
4 votes
Accepted

Which library to choose? <Wire.h> or "Wire.h"?

The proper distinction is exactly what paths are searched for the include files. <...> searches the "system" paths, while "..." searches both the system an "local" paths. From the GCC manual: ...
Majenko's user avatar
  • 105k
4 votes

Which library to choose? <Wire.h> or "Wire.h"?

http://en.cppreference.com/w/cpp/preprocessor/include #include <filename> The intent of this syntax is to search for the files under control of the implementation. Typical implementations ...
aaa's user avatar
  • 2,695
4 votes

Wire.h not found!

Use #include <Wire.h> Including files in double quotes (") will point to headers in current working directory first. Edit: ... and there is nothing wrong with copying headers to CWD if you are ...
user400344's user avatar
4 votes

Alternatives to Wire library for I2C

Also Procyon AVR library worth be checking. It is a bit old now but very professional and kinda minimalistic. Not much dependencies, should be fine to use just I2C module only. There is hardly ...
Flanker's user avatar
  • 529
4 votes

Arduino I2C Wire.onReceive hangs after a few loops

After a bit of tinkering, I noticed that removing the delay() call in the slave fixed it and there were no more hangs. Also, when using the Servo library to move a servo instead of blinking the led, ...
Valentin Brasso's user avatar
3 votes
Accepted

TWI Wire.setClock() on non arduino AVR MCU issue

Looking to get 100 kHz clock. What am I missing? Calculations are int (16-bits) by default in AVR GCC. Try 100*1000L. Or even better: #define F_TWI 100000L and use: TWBR = ((F_CPU/F_TWI)-16)/2; ...
Mikael Patel's user avatar
  • 7,969
3 votes

I2C from two masters (ATtiny85, ESP8266) to one slave (ATmega328)

If you have 1 receive only device, and 2 send-only devices, why not make the receive-only device the master, but have it poll (periodically, repeatedly ask) the slave devices to send any data they ...
jose can u c's user avatar
  • 6,974
3 votes

I2C protocol doesn't work properly

You may need to do some additional research. I'm debugging some I2C problems myself at the moment. Happy to share what my research has turned up: Guiding Ideas - What could break? Physical Layer ...
RowanP's user avatar
  • 869
3 votes
Accepted

Wire.endTransmission(false) hanging the program after running once when using MPU6050

In the comments below, @chrisl makes something explicit that I hadn't in previous edits. Reading it first may make the below easier to interpret: Useful fact about I2C on Arduino: Wire....
timemage's user avatar
  • 5,299
3 votes
Accepted

How detect I2C errors with requestFrom()

The Wire library does not give you any possibility to get error states, when requesting bytes from a slave. Basically you are stuck with the number of bytes being read. Though you can read some ...
chrisl's user avatar
  • 16.3k
3 votes

''Wire1' was not declared in this scope' in I2C_MPU6886 library

"M5Stack" is an ecosystem of ESP32 based boards and peripherals. All code for M5Stack peripherals is written for the M5Stack system. Not for the Uno. You have to find code for the Uno, not ...
Majenko's user avatar
  • 105k
3 votes
Accepted

Setup loops: never enters loop - restarting?

You can tell that something is going wrong between your println. Some advice in this case: eliminate the String entirely and replace the println with a series of print. This would let you narrow down ...
Chris's user avatar
  • 144
2 votes
Accepted

Arduino Wire.h send double to lcd

The Arduino Wire class does only support write() of byte, string and vector of bytes. To write a double it must first be converted to a string. This can be done with the standard C library function ...
Mikael Patel's user avatar
  • 7,969
2 votes

Update Variable via Arduino to Arduino I2C

I see now what the issue was. But to answer my questions: Wire.available(); will not work if called outside of an event handler. I confirmed this while reading through the Wire.cpp source code and it ...
Josh Wiens's user avatar
2 votes

Alternatives to Wire library for I2C

You can use completely different approach to the top question. Asking for alternatives you have given reason to this: getting rid of unused code in the binary. You can achieve removal of unused code ...
Damago's user avatar
  • 66
2 votes

wire.h multiple slave addresses

Is it possible to use wire.h on an Arduino Uno to act as a slave for more than one address? The quick answer is: No! The ATmega328 2-Wire Serial Interface has a special register for the address ...
Mikael Patel's user avatar
  • 7,969
2 votes

wire.h onReceive only triggering once

You are correct and that was the second part of the problem. The first part was that my code wasn't always retrieving every byte and this was hanging up the OnReceive function. Once I fixed that bug I ...
Peter Gottlieb's user avatar
2 votes

I2C Wire.write function doesn't seem to work

OK, I figured out what was going on... An example program that I downloaded to test the hardware was sending a "self address" command to the chip, which was causing the address to get set to 0x03 and ...
witch359's user avatar
2 votes

I2C Wire.write function doesn't seem to work

It looks like you have code for an I2C master. Sending to a slave involves sending the slave address, and waiting for an ACK from the slave (that is, the addressed slave pulls the data bus low). You ...
Nick Gammon's user avatar
  • 38.3k
2 votes

I2C Wire.write function doesn't seem to work

According to the captured communication NACK was received (confirmed in comments) and according to the Wire library twi_stop will be called (and sent) in this fault scenario. case TW_MT_SLA_NACK: // ...
KIIV's user avatar
  • 4,752
2 votes

Reading values from TTP229 capacitive touch sensor on arduino

mpr121 gives raw values it has 12 electrodes/capacitance sensing inputs https://www.sparkfun.com/datasheets/Components/MPR121.pdf https://github.com/BareConductive/mpr121/tree/public/MPR121/Examples/...
sashundel's user avatar
2 votes
Accepted

Servo jitter with two atmegas

The core problem is that servo control on an Arduino is done using timer interrupts and not hardware PWM. And of course your I2C reception is also using interrupts. Since the Arduino only has one ...
Majenko's user avatar
  • 105k
2 votes

How to choose alternate I2C pins on ESP32?

Here is the example of how you can change esp8266 i2c pins. I used it for my ESP8266 and bme280, but the same for Arduino and other sensors. #include <Wire.h> #include <Adafruit_Sensor.h> ...
Max Gorch's user avatar
2 votes
Accepted

I2C call during Wire.requestFrom

There is no Wire.write(address) in the Wire library. The function write() takes data and puts it into the library internal write buffer. It does nothing on the I2C bus. For master write operation (...
chrisl's user avatar
  • 16.3k
2 votes

Wire.h missing - Failing to upload I2C 16x2 LCD sketch

That library is special. It expects to be placed in the same location as the Wire library. You need to find the location of the Wire library and place this library alongside it. So you have: .../...
Majenko's user avatar
  • 105k
2 votes
Accepted

Questions about HMC5883L library

TBH the second version of the function is trash. The first version is (almost) the right way to do it. There's stuff in the second version that really shouldn't be there. There is absolutely no ...
Majenko's user avatar
  • 105k
2 votes

Wire SlaveReceiver : will the registered function in onRecieve interrupt/conflict with loop block?

Generally the onReceive callback function is called from an ISR in the Wire library. That means, that no other interrupts can be handled during that time. For this reason an ISR always should be as ...
chrisl's user avatar
  • 16.3k

Only top scored, non community-wiki answers of a minimum length are eligible