Skip to content

Commit

Permalink
Fix #12, add buffers to SW I2C (#13)
Browse files Browse the repository at this point in the history
- add buffers to SW I2C, see issue #12, should fix the SW I2C on AVR.
  - verified with SHT31 on AVR UNO
- minor edits
  • Loading branch information
RobTillaart committed Jun 14, 2024
1 parent 5eb0b6f commit 387a3db
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.3.0] - 2024-05-31
- add buffers to SW I2C, see issue #12, should fix the SW I2C on AVR.
- verified with SHT31 on AVR UNO
- minor edits

----

## [0.2.0] - 2023-12-09
- refactor API, follow SHT31

Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ devices on one Arduino.

The **SoftWire** library is portable, however it could not read (on AVR)
the SHT85 sensor which is command compatible with the SHT3x.
The cause is not found yet.
Therefore a separate repo is created based upon the AVR specific **SoftwareWire**
A fix has been made in 0.3.0 and works on AVR (UNO) with an SHT31.
See #12. It still has to be verified with an SHT85.
The solution was to add buffers for I2C.

A separate repo is created based upon the AVR specific **SoftwareWire**
see links below.
If you know a solution to get softWire working on AVR, please let me know.

The **SoftwareWire** library is an AVR specific and worked for the SHT85.
See https://github.com/RobTillaart/SHT31_SW/issues/5
Expand Down Expand Up @@ -197,7 +199,8 @@ Returns false if reading fails or in case of a CRC failure.
#### Should

- remove script for atomic if not needed any more.
- investigate why SHT85 does not work with SoftWire.
- verify SHT85 (as SHT31 works now).
- make **isCOnnected()** more robust, it now only fails on missing CLOCK.

#### Could

Expand Down
6 changes: 5 additions & 1 deletion SHT31_SW.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: SHT31_SW.cpp
// AUTHOR: Rob Tillaart, Gunter Haug
// VERSION: 0.2.0
// VERSION: 0.3.0
// DATE: 2019-02-08 (base SHT31 lib)
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
// to be used with the SoftWire library instead of (hardware) Wire.
Expand Down Expand Up @@ -36,6 +36,9 @@ bool SHT31_SW::begin()
return false;
}
_softWire->begin();
// See #12
_softWire->setTxBuffer(swTxBuffer, sizeof(swTxBuffer));
_softWire->setRxBuffer(swRxBuffer, sizeof(swRxBuffer));
return reset();
}

Expand Down Expand Up @@ -63,6 +66,7 @@ bool SHT31_SW::writeCmd(uint16_t cmd)
_error = SHT31_ERR_WRITECMD;
return false;
}
// delay(1);
return true;
}

Expand Down
8 changes: 6 additions & 2 deletions SHT31_SW.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: SHT31_SW.h
// AUTHOR: Rob Tillaart, Gunter Haug
// VERSION: 0.2.0
// VERSION: 0.3.0
// DATE: 2019-02-08 (base SHT31 lib)
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
// to be used with the SoftWire library instead of (hardware) Wire.
Expand All @@ -12,7 +12,7 @@
// https://github.com/RobTillaart/SHT31


#define SHT31_SW_LIB_VERSION (F("0.2.0"))
#define SHT31_SW_LIB_VERSION (F("0.3.0"))


#include "Arduino.h"
Expand All @@ -32,7 +32,11 @@ class SHT31_SW : public SHT31
private:
bool writeCmd(uint16_t cmd);
bool readBytes(uint8_t n, uint8_t *val);

SoftWire* _softWire;

char swTxBuffer[8]; // see #12
char swRxBuffer[8]; // see #12
};


Expand Down
4 changes: 2 additions & 2 deletions examples/SHT31_I2Cspeed/SHT31_I2Cspeed.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ void setup()

void loop()
{
for (uint32_t I2Cfreq = 50000; I2Cfreq < 500000; I2Cfreq += 50000)
for (uint32_t I2Cfreq = 50000; I2Cfreq <= 400000; I2Cfreq += 50000)
{
Serial.print(I2Cfreq/1000);
Serial.print(I2Cfreq / 1000);
sw.setClock(I2Cfreq);
test();
}
Expand Down
22 changes: 22 additions & 0 deletions examples/SHT31_I2Cspeed/performance_0.3.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

IDE: 1.8.19
Board: AVR UNO - no speed gain above 300K

SHT31_LIB_VERSION: 0.3.0
8010
50 9912 19.6 64.4
100 8892 19.5 64.4
150 8488 19.6 64.3
200 8300 19.6 64.4
250 8284 19.5 64.4
300 8088 19.6 64.5
350 8092 19.6 64.4
400 8088 19.6 64.5
450 8088 19.6 64.4
500 8088 19.6 64.4
550 8092 19.6 64.5
600 8088 19.6 64.4
650 8088 19.5 64.4
700 8092 19.7 64.4
750 8088 19.5 64.4
800 8096 19.5 64.4
8 changes: 6 additions & 2 deletions examples/SHT31_demo/SHT31_demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#define SHT31_ADDRESS 0x44


SoftWire sw(6, 7);
// SoftWire sw(32, 33);
// SoftWire sw(34, 35);
SoftWire sw(6, 7); // sda, scl

uint32_t start;
uint32_t stop;
Expand Down Expand Up @@ -52,7 +54,9 @@ void loop()
Serial.print("\t");
Serial.print(sht.getTemperature(), 1);
Serial.print("\t");
Serial.println(sht.getHumidity(), 1);
Serial.print(sht.getHumidity(), 1);
Serial.print("\t");
Serial.println(sht.getError(), HEX);
delay(3000);
}

Expand Down
3 changes: 2 additions & 1 deletion examples/SHT31_isConnected/SHT31_isConnected.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/SHT31_SW
//
// fails only when SCL line is disconnected.


#include "SoftWire.h"
Expand Down Expand Up @@ -76,4 +78,3 @@ void loop()


// -- END OF FILE --

3 changes: 1 addition & 2 deletions examples/SHT31_rawValues/SHT31_rawValues.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FILE: SHT31_async.ino
// FILE: SHT31_rawValues.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo async interface
// URL: https://github.com/RobTillaart/SHT31_SW
Expand Down Expand Up @@ -85,4 +85,3 @@ void loop()


// -- END OF FILE --

2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"version": "^1.1.2"
}
],
"version": "0.2.0",
"version": "0.3.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SHT31_SW
version=0.2.0
version=0.3.0
author=Rob Tillaart <rob.tillaart@gmail.com>, Gunter Haug
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for the I2C SHT31 temperature and humidity sensor
Expand Down

0 comments on commit 387a3db

Please sign in to comment.