Hello!
I have trouble to use Software I2C connections on my Arduino Nano BLE 33. I’ve tried the Softwire.h - Library with PlatformIO (and Arduino IDE), but I can’t find any I2C devices (even, the code compiled without errors).
Now, I found the SoftwareI2C.h (GitHub - micooke/SoftwareI2C: Software I2C library for Arduino (Not architecture specific) from Seeed Studio), which works very well on my Arduino Nano BLE 33 (I can find my two I2C devices on pin 6 and 7) - BUT only by compiling the script with the Arduino IDE. By compiling the same script with the same lib’s in PlatformIO, i can’t find any devices (even the script compiles without errors).
The script I used:
#define USE_SOFTWAREI2C
#define SOFTI2C_PIN_SDA 6
#define SOFTI2C_PIN_SCL 7
#ifdef USE_SOFTWAREI2C
#include <Arduino.h>
#include <SoftwareI2C.h> // https://github.com/micooke/SoftwareI2C
SoftwareI2C _i2c;
#else
#include <Wire.h>
#define _i2c Wire
#endif
#include <i2c_device_list.h> //adds 7952 bytes, so comment it out if you dont need it
bool device_found(uint8_t i2c_address)
{
_i2c.beginTransmission(i2c_address);
uint8_t device_found = (_i2c.endTransmission() == 0);
return device_found;
}
void setup()
{
Serial.begin(9600);
Serial.println(__FILE__);
Serial.println(__TIME__);
#ifdef USE_SOFTWAREI2C
Serial.print(F("Using SoftwareI2C. SDA,SCL = "));
Serial.print(SOFTI2C_PIN_SDA);
Serial.print(F(","));
Serial.println(SOFTI2C_PIN_SCL);
_i2c.init(SOFTI2C_PIN_SDA, SOFTI2C_PIN_SCL); // sda, scl
#else
Serial.println(F("Using Wire"));
#endif
_i2c.begin();
}
void loop() {
Serial.println(F("Scanning..."));
uint8_t numDevicesFound = 0;
// if there is something found at 0x74 then there is an error with the sda/scl setup
// there shouldnt be anything here - its reserved
if (device_found(0x7F) == false)
{
for(uint8_t address=1; address<128; ++address)
{
bool deviceFound = device_found(address);
if(deviceFound)
{
Serial.print(F("Found : 0x"));
if (address < 16) Serial.print(F("0"));
Serial.println(address, HEX);
#ifdef I2C_DEVICE_LIST_H
Serial.println(F("which could be one of the following devices"));
Serial.println(F("--------"));
String device_name = i2c_device_list(address);
Serial.println(device_name.c_str());
Serial.println(F("--------"));
#endif
++numDevicesFound;
}
}
}
if (!numDevicesFound)
{
Serial.println(F("No I2C devices found"));
}
delay(4000);
}
And my platfomio.ini:
env:nano33ble]
platform = nordicnrf52
board = nano33ble
framework = arduino
Can someone give me a hint, how to use Software I2C with PlatformIO?
There are some warning, when I compile with Arduino IDE or PlatformIO:
In file included from src\main.cpp:6:
src/SoftwareI2C.h: In constructor 'SoftwareI2C::SoftwareI2C(uint8_t, uint8_t)':
src/SoftwareI2C.h:48:13: warning: 'SoftwareI2C::_pinScl' will be initialized after [-Wreorder]
uint8_t _pinScl;
^~~~~~~
src/SoftwareI2C.h:47:13: warning: 'uint8_t SoftwareI2C::_pinSda' [-Wreorder]
uint8_t _pinSda;
^~~~~~~
src/SoftwareI2C.h:85:5: warning: when initialized here [-Wreorder]
SoftwareI2C(uint8_t pinSda = 7, uint8_t pinScl = 8) : _pinScl(pinScl), _pinSda(pinSda), _transmissionBegun(false), _i2c_address(0x3C) { setClock(100000); }
^~~~~~~~~~~
src/SoftwareI2C.h:57:10: warning: 'SoftwareI2C::_transmissionBegun' will be initialized after [-Wreorder]
bool _transmissionBegun;
^~~~~~~~~~~~~~~~~~
src/SoftwareI2C.h:55:13: warning: 'uint8_t SoftwareI2C::_i2c_address' [-Wreorder]
uint8_t _i2c_address;
^~~~~~~~~~~~
src/SoftwareI2C.h:85:5: warning: when initialized here [-Wreorder]
SoftwareI2C(uint8_t pinSda = 7, uint8_t pinScl = 8) : _pinScl(pinScl), _pinSda(pinSda), _transmissionBegun(false), _i2c_address(0x3C) { setClock(100000); }
^~~~~~~~~~~
Maybe this could help, to solve the problem?
Thanks a lot!
Klaus