I am testing a RTC on an Arduino Nano Every with the code below (which works fine on an Arduino Uno), however every time I try and upload it gives the following error and exit status 1:
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp: In member function 'bool Adafruit_I2CDevice::setSpeed(uint32_t)':
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:270:5: error: 'TWSR' was not declared in this scope
TWSR = 0x0;
^~~~
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:270:5: note: suggested alternative: 'TWI0'
TWSR = 0x0;
^~~~
TWI0
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:274:5: error: 'TWSR' was not declared in this scope
TWSR = 0x1;
^~~~
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:274:5: note: suggested alternative: 'TWI0'
TWSR = 0x1;
^~~~
TWI0
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:278:5: error: 'TWSR' was not declared in this scope
TWSR = 0x2;
^~~~
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:278:5: note: suggested alternative: 'TWI0'
TWSR = 0x2;
^~~~
TWI0
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:282:5: error: 'TWSR' was not declared in this scope
TWSR = 0x3;
^~~~
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:282:5: note: suggested alternative: 'TWI0'
TWSR = 0x3;
^~~~
TWI0
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:290:3: error: 'TWBR' was not declared in this scope
TWBR = atwbr;
^~~~
C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:290:3: note: suggested alternative: 'TWI0'
TWBR = atwbr;
^~~~
TWI0
Multiple libraries were found for "Adafruit_I2CDevice.h"
Used: C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO
Not used: C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO-master
It suggested using "TWI0" as an alternative, but how would I change that? What is causing this error?
I've seen a few previous posts but none of them seemed to have a clear solution
Below is my full code:
#include <RTClib.h>
#include <Wire.h>
#include <Adafruit_I2CDevice.h>
RTC_DS1307 rtc;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
if(! rtc.begin()){
Serial.println("Couldnt find RTC");
while(1);
}
if(! rtc.isrunning()){
Serial.println("RTC is NOT running!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.println(now.hour(), DEC);
Serial.print('/');
Serial.print(now.minute(), DEC);
Serial.print('/');
Serial.print(now.second(), DEC);
}
I re-uploaded the code with Koepel's suggestion and instead of 'TWSR not declared' here were the errors I was getting:
In file included from C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO-master\Adafruit_I2CDevice.h:5:0,
from C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO-master\Adafruit_I2CDevice.cpp:1:
C:\Users\Xiaow\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\libraries\Wire\src/Wire.h: In member function 'bool Adafruit_I2CDevice::_read(uint8_t*, size_t, bool)':
C:\Users\Xiaow\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\libraries\Wire\src/Wire.h:64:12: note: candidate 1: size_t TwoWire::requestFrom(int, int, int)
size_t requestFrom(int, int, int);
^~~~~~~~~~~
C:\Users\Xiaow\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\libraries\Wire\src/Wire.h:62:12: note: candidate 2: virtual size_t TwoWire::requestFrom(uint8_t, size_t, bool)
size_t requestFrom(uint8_t, size_t, bool);
^~~~~~~~~~~
as well as
C:\Users\Xiaow\AppData\Local\Temp\arduino_build_433996\libraries\Adafruit_BusIO-master\Adafruit_I2CDevice.cpp.o (symbol from plugin): In function `Adafruit_I2CDevice::Adafruit_I2CDevice(unsigned char, TwoWire*)':
(.text+0x0): multiple definition of `Adafruit_I2CDevice::setSpeed(unsigned long)'
C:\Users\Xiaow\AppData\Local\Temp\arduino_build_433996\sketch\rtc_testing.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "Adafruit_I2CDevice.h"
Used: C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO-master
Not used: C:\Users\Xiaow\Documents\Arduino\libraries\Adafruit_BusIO
The error message seem to alternate between this and TWSR not declared randomly...
An alternative is to try and use RTClib version 1.14 and decline to add the Adafruit i/o if asked. It's not clear what platforms require Adafruit Bus I/O, but Version 2.0 and later embedded the use and didn't make it optional. You can remove the Adafruit Bus I/O library if you don't need it elsewhere.
Most of the useful features of RTCLib are in 1.14.
I meant replacing the function Adafruit_I2CDevice::setSpeed() in the library files. It only has to contain a call to setClock().
You have installed the Adafruit Bus IO library twice.
Next to your project folders is a folder "libraries", probably located at "Documents / Arduino / libraries'. Remove every library that you don't need and remove all the Bus IO libraries. Then start the Arduino IDE, go to the Library Manager, and install the Adafruit Bus IO library and other libraries that you need.