4-20mA.ker doesn't read I2C sensor

Hi,

I'm trying to connect an I2C sensor (a SHT20) to a 4-20mA.ker to convert the readings into a 4-20ma signal that I want to read from an Industruino IND.I/O D21G with an Ethernet module installed.
Here you can find the wiki of an equivalent sensor: https://wiki.dfrobot.com/SHT20_I2C_Temperature_%26_Humidity_Sensor__Waterproof_Probe__SKU__SEN0227
When I connect the sensor to the 4-20mA.ker, it is not detected. I tried with an I2C scanner sketch and the sensor address is not highlighted as available.
I double-checked the color scheme of the wires and the electrical connections, but they seem correct.
I have already checked the sensor with an Arduino Uno and the DFRobot library and it works fine.

I have tried both the SERCOM1 and SERCOM3 configurations, but the sensor hasn't been detected anyway.
I have noticed that the Arduino IDE throw a warning because the "Wire" library appears to be for SAMD architectures, but the sketch is compiled and loaded correctly to the 4-20mA.ker.

For the scketch, I have simply combined the example for the 4-20mA.ker with the DHT11 sensor and the example of the supplier of the SHT20.

I'm stuck and running out of ideas, can you please give me some advice on how to proceed?

Thanks,

Edoardo

 

Here the code:

#include <Wire.h>
#include <DFRobot_SHT20.h>

DFRobot_SHT20 sht20;

int dt_mis = 2000 ;
void setup() {
  Wire.begin();               
  SerialUSB.begin(9600);
  DAC->CTRLB.bit.REFSEL = 0x00; //Set DAC to external VREF (2.5V)
  analogWriteResolution(12);
  digitalWrite(PIN_EXT_3V3_ENABLE, HIGH);
  sht20.initSHT20();                         // Init SHT20 Sensor
  delay(1000);
  sht20.checkSHT20();                       // Check SHT20 Sensor                            
}

void loop() {
 float temp, humd;
 int microamps;
  temp = sht20.readTemperature();   // Read Temperature
  SerialUSB.print("Temperatura: ");
  SerialUSB.println(temp);
  microamps = map(temp, 0, 80, 12000, 20000);           // MAPPING
  if (temp>80) microamps = 11000;
  analogWrite(PIN_DAC0, uAmap(microamps));
  delay(dt_mis);

  humd = sht20.readHumidity();                  // Read Humidity
  SerialUSB.print("Umidità: ");
    SerialUSB.println(humd);
  microamps = map(humd, 40, 100, 4000, 10000);           // MAPPING
  if (isnan(humd)) microamps = 11000;
  analogWrite(PIN_DAC0, uAmap(microamps));
  delay(dt_mis);

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

// helper function to map milliamps to 0-4095 DAC range
int uAmap(int ua) {
  return map(ua, 3800, 20700, 0, 4095); // map microamps 3.8-20.7mA
}

 

I2C
Edoardo
Edoardo
14
| 1 1 1
Asked on 6/14/20, 3:02 PM
0
vote
2070 Views

Hi Tom,

Thanks for your reply.

I forgot to say that I have already modified the DFRobot library to comply with the Industruino request of the SerialUSB.

The sketch itself works fine, but it returns, for both humidity and temperature, the value 998, that is the error code for I2C timeout.

I connected the VCC to the 3.3V, GND to GND, SCL to D6 and SDA to D5. I have already tried both config 1 and config 3 but nothing has changed.

Could it be there's some issues with the Wire library?

Thanks!

Edoardo

Edoardo
Edoardo
14
| 1 1 1
Answered on 6/15/20, 6:57 AM
0
vote

I don't think there's an issue with the Wire library, it works well with another sensor the MPU6050. have you tried adding pullup resistors to the SCL and SDA lines, e.g. 10K each to 3v3

Tom
on 6/15/20, 7:12 AM

Hi Tom, Now everything works fine. Adding the pullup resistors solved the problem. I didn't try it before, because when I tested the sensor with the Arduino Uno, it worked with and without the resistors, so I tought they weren't necessery. Thank you very much! Edoardo

Edoardo
on 6/15/20, 1:02 PM

Great, thanks for the feedback, i have added a note in the documentation https://github.com/Industruino/documentation/blob/master/420maker.md

Tom
on 6/15/20, 11:24 PM

Hi, i think the problem is caused by the DFRobot_SHT20 library. The function sht20.checkSHT20(); prints to 'Serial' which is not the USB serial on the 4-20mAker. So you will have to change the library file https://github.com/DFRobot/DFRobot_SHT20/blob/master/DFRobot_SHT20.cpp lines 100,102,104 to SerialUSB instead of Serial.

Use Serial config1:SPI+I2C and connect the sensor to D5, D6.

Let us know if that solves it.

Tom
Tom
5675
| 1 1 3
Answered on 6/15/20, 1:10 AM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

61 follower(s)

Stats

Asked: 6/14/20, 3:02 PM
Seen: 2070 times
Last updated: 6/15/20, 7:01 AM