Comments (23)
Came across this issue again and some good news.
A softwire version of the library now exists - https://github.com/RobTillaart/SHT31_SW
Started again with a PR here
- #35
- a failed wrapper class https://github.com/RobTillaart/TwoWireSW
just to let you know,
Rob
from sht31.
Hi, Rob! I check sensors SHT31 on Arduino atmega 2560 with SHT31_SW + SoftwareWire - it works! And very fast! I replace SoftWire library on my PC. Unfortunately with SoftWire - don't work. Thank you for good job!
I think, you need correct SHT31_SW library finally with SoftwareWire library.
from sht31.
@SanSanysch
Will look into this latér today.
Can you post a stripped minimal version of your code?
Can you tell what the error message is?
from sht31.
From the i2c lib you use
If you want a solution running on an ARM MCU (Due,
Zero, Teensy 3.x), you want to use pins on port H or
above on an ATmega256, or you want to use many
different I2C buses, this library is not the right
Solution for you.
So it might be a pin problem.
Have you tried other pins for the sw i2c?
from sht31.
@SanSanysch
are you familiar with https://github.com/Testato/SoftwareWire ?
Not tested it myself (yet) but some of the contributers are involved with Arduino core.
from sht31.
Thanks for fast answer. Minimal code:
// SHT31 on hardware I2C
#include "Wire.h"
#include "SHT31.h"
SHT31 sht_a;
SHT31 sht_b;
// SHT31 on software I2C
#define SDA_PORT PORTD
#define SDA_PIN 3 // = D18
#define SCL_PORT PORTD
#define SCL_PIN 2 // = D19
#include <SoftWire.h>
SoftWire SWire = SoftWire();
void setup(void) {
Serial.begin(9600);
Wire.begin();
sht_a.begin(0x44);
sht_b.begin(0x45);
SWire.begin();
}
void SHT31(byte ADDR)
{
byte data[6];
SWire.beginTransmission(ADDR);
SWire.write(0x2C); // Send measurement command
SWire.write(0x06);
SWire.endTransmission(false);
SWire.requestFrom(ADDR,6);
if (SWire.available() == 6) { // считывание 6 байт данных
data[0] = SWire.read(); // cTemp msb
data[1] = SWire.read(); // cTemp lsb
data[2] = SWire.read(); // cTemp crc
data[3] = SWire.read(); // humidity msb
data[4] = SWire.read(); // humidity lsb
data[5] = SWire.read(); // humidity crc
}
// Convert the data
float cTemp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45;
float humidity = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0);
// Output data to serial monitor
Serial.print(ADDR);
Serial.print(" Humidity: ");
Serial.print(humidity);
Serial.print(" %RH");
Serial.print("\t");
Serial.print(" Temperature: ");
Serial.print(cTemp);
Serial.println(" C");
}
void loop()
{
sht_a.read(); // default = true/fast slow = false
Serial.println("===hardware I2C===");
Serial.print("sht_a");
Serial.print(" Humidity: ");
Serial.print(sht_a.getHumidity(), 1);
Serial.print(" %RH");
Serial.print("\t");
Serial.print(" Temperature: ");
Serial.print(sht_a.getTemperature(), 1);
Serial.println(" C");
sht_b.read(); // default = true/fast slow = false
Serial.print("sht_b");
Serial.print(" Humidity: ");
Serial.print(sht_b.getHumidity(), 1);
Serial.print(" %RH");
Serial.print("\t");
Serial.print(" Temperature: ");
Serial.print(sht_b.getTemperature(), 1);
Serial.println(" C");
Serial.println("===software I2C===");
SHT31(0x44);
SHT31(0x45);
Serial.println();
delay(2000);
}
Yes i familiar with https://github.com/Testato/SoftwareWire but not check.
Unfortunately, I will not at home until Sunday. Please, wait.
from sht31.
updated your post to do syntax highlighting.
from sht31.
I think the SoftWIre library blew up my SHT85 sensor which I used for testing. (stupid me :( )
Ordered new one however that will takes maybe a week..
from sht31.
@SanSanysch are you familiar with https://github.com/Testato/SoftwareWire ?
Not tested it myself (yet) but some of the contributers are involved with Arduino core.
you should have the v1.5.1 as this one inherits from TwoWire.
from sht31.
I checked https://github.com/Testato/SoftwareWire - it work. I replace library in my example above, but i did not understand, how to bind your library and SoftwareWire-library. In your library hard used Wire-library. I don't want edit your library.
If i specify:
SoftwareWire Wire(sda_pin, scl_pin);
Mistakes then compiling.
from sht31.
I found possible solution: https://github.com/Testato/SoftwareWire/wiki/Using-a-library-that-needs-a-TwoWire-pointer
may be your edit library for versatility. I'm sure, it's useful for someone.
I will check, if you do not have sensors.
from sht31.
There are two strategies discussed:
If the Arduino Wire library is not used at all
As more and more sensors / IC / display are available with I2C this scenario is unlikely. At least from a library point of view I just don't know if the user of my lib does or does not use more I2C devices. Looking at my own projects almost all use I2C character displays, sensors and PCF8574 (IO) for actuators. In fact on PCB's I always want one or two I2C connectors to extend functionality in the future (without redesigning main board).
So for me this is no option.
If the Arduino Wire library is also used
This is the safest assumption from library point of view. If I understand the example it is a "copy" of the LiquidCystal display library which has all TwoWire removed and SoftWire put in place instead. That would imply that maintenance for the library increases. I estimate minimal 30% extra time (especially testing). As I have now ~130 libraries from which 80+ uses Wire that would substantially increase the work. Yes I know it is useful for somebody (that's is why I share my libs) but please understand that it costs me substantial free time that I cannot spend on my own projects.
I will check, if you do not have sensors.
Thank you, I have ordered 2 SHT85's and I expect them end of this week (not confirmed)
from sht31.
Thank you, I have ordered 2 SHT85's and I expect them end of this week (not confirmed)
OK. I'll wait. Let me (all) know about the results.
from sht31.
Got order confirmation saying that the sensors are expected in 3rd week januari 2022.
So to be continued when (if) they arrive over 10 weeks or so.
Sorry for the inconvenience.
from sht31.
There did you bay sensors? To us, from China, comes in about a month.
There are no other options. Will wait...
from sht31.
Ordered them from rs-online, normally they deliver in 2 or 3 days.
from sht31.
Hi, Rob! You received sensors?
from sht31.
No, nothing, not even a message that they will be late ...
from sht31.
Had a lot of time to rethink the question and I decided to not change the library for this question.
Any softWire library that implements the TwoWire interface can be used with the SHT31 lib,
so there is a provision by means of dependency injection.
It is not my goal to maintain separate versions of libraries that are tuned to specific use-cases / projects.
The MIT license allows you to fork the library and patch it to whatever is needed and even use it commercially.
At the moment I have no concrete plans to write a TwoWire compatible softwire library, so that route will not be a part of a solution for your question. So I will close this issue.
FYI, the sensors are still not available :(
from sht31.
It's very good news! Thank you very much!!!
from sht31.
Give it a try!
from sht31.
@SanSanysch
Thanks for testing, that confirms my tests.
Hope to find some time this week.
from sht31.
@SanSanysch
Created a separate repo with an initial version with SoftwareWire
There are problems with build, but local build with 1.8.19 IDE and UNO works.
from sht31.
Related Issues (13)
- Exposing the raw temperature and humidity? HOT 6
- SHT31 library two I2C interfaces: example, advice needed HOT 31
- Add lastHeaterStopTime variable to prevent switching on the heater too early HOT 2
- Return 0.0C and 0.0% HOT 5
- isConnected returns true if voltaje to SHT31 is not connected. HOT 4
- prototype for 'bool SHT31::begin(uint8_t, uint8_t, uint8_t)' does not match any in class 'SHT31' HOT 6
- Using SHT31 in High Humidity Environment HOT 9
- check SHT2x functions added HOT 1
- Heater HOT 5
- SHT31 library with Arduino-ESP32 v2.0.5 HOT 8
- support Wire2 for ESP32
- Question on i2c error handling HOT 23
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sht31.