Hello all, I am trying to figure out a way to us I2C and Software serial at the same time. I have been able to make two attiny85s talk to each other using TinyWire. Now I'm trying to add software serial to the mix. It gives me and error and says I can't use those two libraries together.
Here is the code:
#include <TinyWire.h>
#include <SoftwareSerial.h>
int masterAddress = 8;
const uint8_t rx = 4;
const uint8_t tx = 5;
SoftwareSerial bluetooth(rx, tx); // RX, TX pins for the Bluetooth module
void setup() {
TinyWire.begin();
bluetooth.begin(9600);
}
void loop() {
checkBluetooth();
}
void checkBluetooth() {
char charBuffer[20];
bluetooth.listen();
if (bluetooth.available() > 0) {
int numberOfBytesReceived = bluetooth.readBytesUntil('\n', charBuffer, 19);
charBuffer[numberOfBytesReceived] = '\0'; // Null-terminate the string
if (strstr(charBuffer, "LED")) {
TinyWire.beginTransmission(masterAddress);
TinyWire.send('1');
TinyWire.endTransmission();
delay(1000);
}
}
}
I have tried using the SoftwareWire library, but it doesn't seem to work either. If anyone has any advice, it would be greatly appreciated.
Both libraries use the pinchange interrupt PCINT0 and have an interrupt service routine for that; you can only have one interrupt service routine for a given interrupt.
Search results for ISR in the two libraries
D:\_ArduinoPortable\arduino-1.8.19-attiny\portable\sketchbook\libraries\TinyWire-master\twi.cpp (5 hits)
Line 667: ISR( USI_START_VECTOR )
Line 722: } // end ISR( USI_START_VECTOR )
Line 727: ISR( USI_OVERFLOW_VECTOR )
Line 817: } // end ISR( USI_OVERFLOW_VECTOR )
Line 821: ISR( PCINT0_vect )
D:\_ArduinoPortable\arduino-1.8.19-attiny\portable\sketchbook\libraries\TinyWire-master\twi.h (1 hit)
Line 12: * The master functionality is done directly (not in an ISR) and in case of a requestFrom blocking. The slave
D:\_ArduinoPortable\arduino-1.8.19-attiny\portable\packages\ATTinyCore\hardware\avr\1.5.2\libraries\SoftwareSerial\SoftwareSerial.cpp (7 hits)
Line 226: ISR(PCINT0_vect)
Line 233: ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));
Line 237: ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect));
Line 241: ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
Line 326: // ISR vector table) until the first delay. After the delay, there
Line 342: // time for ISR cleanup, which makes 115200 baud at 16Mhz work more
Line 360: // can be used inside the ISR without costing too much time.
The error that I get
C:\Users\Wim\AppData\Local\Temp\arduino_build_665508\libraries\TinyWire-master\twi.cpp.o (symbol from plugin): In function `USI_TWI_Master_Start()':
(.text+0x0): multiple definition of `__vector_2'
C:\Users\Wim\AppData\Local\Temp\arduino_build_665508\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
If you're not using the core or library that I mentioned above, please state what you're using.
Yes! You are right! In Fig-1, it is clearly indicated that I2C Bus (Pin-5 SDA, Pin7 SCL) is an alternative function of USI Interface (Pin-5 DI, Pin-6 DO, Pin-7 USCK).
It is my understanding that I2C Bus is an hardware entitity based on my experince of doing the following project to display the voltage of the RESET/-pin on the I2CLCD Unit (Fig-2) and to observe at what voltage level the mCU enters into RESET state.
In the following ATtiny85-OLED-DS1307 Project (Fig-1), I had to use all the tiny libraries (Tiny4kOLED.h, TinyRTClib.h, TinyWireM.h Library) so that the sketch is accomodated within 6 Kbyte user flash (6 KB user Flash + 2 KB Bootloader = 8 KB total) of the ATtiny85 of the Digispark Dev Board inspite of using ATTinyCore.
I have not used any of mentioned Tiny libraries so do not know whether TinyWire is a requirement. For all my uses I found the ATTinyCore Wire to be perfectly functional, hence the question.
What type of file the ATTinyCore is? Is it a Text File which contains the definitions of the symbolic names used in the sketch and the values of the fuse bits and lock bits? Does it contain the codes for the I2C functions, RTClib, and OLED functions?