How to define SDA and SCL pins?

Hi All,

I am using a Sensirion library that specifically requires the data and clock pins to be defined - otherwise it doesn’t work. https://github.com/HydroSense/sensirion

On the cubecell is there a way to define the pins either by a name or GPIO number?

thanks in advance

Paul

What do you mean? It’s C++, #define - keyword isn’t board-related and works literally everywhere. It shows in your own link how to use the library and how to specify the pins you want to use.

hi,

I’m sorry that the IIC pins of Cubecell cannot be redefined.

I’ll try to explain my issue a little better.

For the ESP32 boards, it’s an easy reference to GPIO pins which I think are the MCU pins on the ESP32, I use a Sodaq board too and the board libraries assign SCL_pin etc to them. So I can use this library easily with them.

So do the SDA and SCL have names or pin numbers I can use in this Sensirion library?

I’m still not sure I understand the problem. If I understand you correctly, yes, both SDA and SCL are already defined and you can just use them as-is in your code. If you wanted to use the SDA and SCL pins with the sensirion-library, you’d literally just do:

#include <sensirion.h>
SHT1x sensirion(SDA, SCL);

yep thats what I thought but it doesnt work unfortunately

“it doesnt work” isn’t particularly helpful. Are you getting an error compiling your sketch or what?

Hi,

Greeting from Heltec!

I’m sorry that the IIC pins of Cubecell cannot be redefined.

will have to check at work tomorrow, pretty sure it was wild figures or like it wasnt connected at all and all zeros.

Exactly the same result with the ESP32 and SAMD21 until i could use the pin definitions.

From what @jasonXu is saying it won’t be able to be done with the cubecells

That library doesn’t use I2C, it just reads and writes the pins you give it directly – it just does it all in plain software. There is nothing to redefine and what @jasonXu said is irrelevant. Besides which, you don’t even have to use the SDA or SCL pins for it at all: you can just give any two GPIO-pins, since, like I said, it doesn’t actually use I2C at all.

Whatever the issue is, it’s not related to any pin-definitions. Maybe there is a bug in the library, maybe you’ve got your wiring wrong, or whatever.

ok i’ll give two spare GPIO pins a go tomorrow, thanks for your help so far

OK had a chance to do some more testing

Two spare GPIO pins produced results the same as nothing connected.

Using simply SDA and SCL in the code produced these errors

SHT: crc error
 Got:      0xFF
 Expected: 0x42
Humidity: 2147483647%
SHT: crc error
 Got:      0xFF
 Expected: 0xE7
Temperature: -40 C

Hi @jasonXu,

I don’t need to redefine them, just need to know how they are referred to in the library.

I know when using i2c you don’t normally need to, but this Sensirion library works a bit different but still uses the SDA and SCL pins

/**
* ReadSHT31LS
*
* Read temperature and humidity values from an SHT31-LS
* May also work with the SHT1x series (SHT10, SHT11, SHT15) sensors.
*
* Copyright 2016 Alan Marchiori amm042@bucknell.edu
* ![](file:///C:\Users\Jason\AppData\Roaming\Tencent\QQTempSys\%W@GJ$ACOF(TYDYECOKVDYB.png)www.hydrosense.net
*/

#include <sensirion.h>

// Specify data and clock connections and instantiate sensirion object
#define dataPin SDA
#define clockPin SCL
#define ledPin GPIO3

sensirion sht(dataPin, clockPin);

void setup()
{
Serial.begin(9600); // Open serial connection to report values to host
Serial.println("Starting up");
pinMode(ledPin, OUTPUT);
}

void loop()
{
float temp_c;
float temp_f;
float humidity;

// blink
digitalWrite(ledPin, (digitalRead(ledPin) == HIGH) ^ 1);

if (1){
uint16_t status = sht.readStatus();
Serial.print("Status: 0x"); Serial.println(status, HEX);
}

if (1){
humidity = sht.readHumidity();
Serial.print("Humidity: "); Serial.print(humidity); Serial.println("%");
}

if (1){
temp_c = sht.readTemperatureC();
Serial.print("Temperature: "); Serial.print(temp_c, DEC); Serial.println(" C");
}

if (1){
temp_f = sht.readTemperatureF();
Serial.print("Temperature: "); Serial.print(temp_f, DEC); Serial.println(" F");
}

delay(2000);
}

Hi,

We downloaded the library you mentioned and compiled it.

I posted it.

Please compare it.

%E5%9B%BE%E7%89%87

Yeah thanks, I used those exactly as you had them, it compiled just fine, but the output on the serial monitor was as above