2
\$\begingroup\$

I have tried checking with an oscilloscope on the analogue pins when the sensor is plugged in and I don't seem to get anything as I normally would.

The hardware i2c channel works just fine on the mega, its the soft ones I am trying to use that don't seem to work

#include <Wire.h>
#include <Ports.h>
#include <PortsSHT21.h>
#include <SHT2x.h>

//Define soft i2c channels for 3 sensors
  SHT21 hsensor2 (2); // pins A1 and D5 - Sensor 2
  SHT21 hsensor3 (3); // pins A2 and D6 - Sensor 3
  SHT21 hsensor4 (4); // pins A3 and D7 - Sensor 4

//define variables for temp data
  float h, t;


void setup() 
{
    Wire.begin();
   Serial.begin(9600);
}

void loop()
{
   // Get data from first sensor hard I2C channel
    float hum1 = (SHT2x.GetHumidity());
    float temp1 = (SHT2x.GetTemperature());
    Serial.println("temp1");
    Serial.println(temp1); 

  // Get data from second sensor soft I2C
  hsensor2.measure(SHT21::HUMI);
  hsensor2.measure(SHT21::TEMP);
  hsensor2.calculate(h, t);
    float hum2 = (h);
    float temp2 = (t);
    Serial.println("temp2");
    Serial.println(temp2);     

   // Get data from third sensor soft I2C
  hsensor3.measure(SHT21::HUMI);
  hsensor3.measure(SHT21::TEMP);
  hsensor3.calculate(h, t);
    float hum3 = (h);
    float temp3 = (t);
    Serial.println("temp3");
    Serial.println(temp3);     

 // Get data from fourth sensor soft I2C  
  hsensor4.measure(SHT21::HUMI);
  hsensor4.measure(SHT21::TEMP);
  hsensor4.calculate(h, t);  
    float hum4 = (h);
    float temp4 = (t);
    Serial.println("temp4");
    Serial.println(temp4);
    Serial.println("");
    Serial.println("");
    delay(500);
}
\$\endgroup\$
2
  • 5
    \$\begingroup\$ Same comment as for your answer from a few minutes ago: don't expect people to know what SHT21 is. Give more details if you want a proper answer. (Especially Olin is very sensitive to this :-), and rightly so) \$\endgroup\$
    – stevenvh
    Apr 4, 2012 at 16:32
  • \$\begingroup\$ I don't see any relevant code, like thouse for software I2C or for port setup: I2C ports need to be open-drain. \$\endgroup\$
    – Turbo J
    Apr 5, 2012 at 4:27

1 Answer 1

2
\$\begingroup\$

Just for completeness, I believe Jonny Flowers has found the solution himself: http://arduino.cc/forum/index.php?topic=99832.0

He's also put his code online: https://github.com/mrjonny2/PortsSHT21

His solution is to edit the Ports.h file's

uint8_t portNum;

inline uint8_t digiPin() const
    { return portNum ? portNum + 3 : 18; }
inline uint8_t digiPin2() const
    { return portNum ? portNum + 13 : 19; }
inline uint8_t anaPin() const
    { return portNum - 1; }

to

uint8_t portNum;

inline uint8_t digiPin() const
    { return portNum ? portNum + 3 : 18; }
inline uint8_t digiPin2() const
    { return portNum ? portNum + 53 : 19; }
inline uint8_t anaPin() const
    { return portNum + 53; }
\$\endgroup\$
3
  • \$\begingroup\$ Hi yes, I completely forgot about this, thanks for putting it in. Did you find it on my paste bin? \$\endgroup\$ Sep 2, 2012 at 15:20
  • \$\begingroup\$ Nah, I just googled and came across the arduino forum I linked in my answer. \$\endgroup\$ Sep 2, 2012 at 18:11
  • \$\begingroup\$ Ah, I remember posting it somewhere. \$\endgroup\$ Sep 3, 2012 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.