Okay, We're gonna buy PaHub to make it work.
Thank you all for your invaluable solutions and clarifications on my issue. Your help is greatly appreciated!
Okay, We're gonna buy PaHub to make it work.
Thank you all for your invaluable solutions and clarifications on my issue. Your help is greatly appreciated!
I'm just curious, Is there a way to accomplish this programmatically, without needing to physically change the addresses?
Thanks
Surya
The SHT30 perfectly worked with "M5UnitENV.h". Thanks again!
Here I am encountering another challenge: I'm attempting to read temperature data from both the SHT30 and SHT40 simultaneously. However, both sensors share the same I2C address (0x44), leading to an error. I also experimented with changing the address to 0x45, but unfortunately, it didn't resolve the issue. Any advice is greatly appreciated.
Here is my new setup:
Code:
#include <M5AtomS3.h>
#include <M5Unified.h>
#include "Wire.h"
#include "M5UnitENV.h"
#include <SensirionI2CSht4x.h>
SHT3X sht3x;
SensirionI2CSht4x sht4x;
float temperature, humidity;
void setup()
{
Serial.begin(115200);
if (!sht3x.begin(&Wire, SHT3X_I2C_ADDR, 2, 1, 400000U))
{
Serial.println("Couldn't find SHT3X");
// while (1)
// {
// Serial.println("Couldn't find SHT3X");
// delay(1000);
// }
}
sht4x.begin(Wire, SHT40_I2C_ADDR_45);
}
void loop()
{
temperature = humidity = NULL;
uint16_t error;
char errorMessage[256];
if (sht3x.update())
{
Serial.println("-----SHT3X-----");
Serial.print("Temperature: ");
Serial.print(sht3x.cTemp);
Serial.println(" degrees C");
Serial.print("Humidity: ");
Serial.print(sht3x.humidity);
Serial.println("% rH");
Serial.println("-------------\r\n");
}
error = sht4x.measureHighPrecision(temperature, humidity);
if (error)
{
Serial.print("Error trying to execute measureHighPrecision(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
}
else
{
Serial.println("-----SHT4X-----");
Serial.print("Temperature:");
Serial.print(temperature);
Serial.print("\t");
Serial.print("Humidity:");
Serial.println(humidity);
Serial.println("-------------\r\n");
}
delay(1000);
}
Thanks
Surya
I'm attempting to read temperature values from the SHT30 (Yanmis SHT30) sensor. However, I'm encountering an error mentioned below.
Can someone kindly provide me with guidance or solutions to resolve the issue I'm facing?
Here is my setup:
Code:
https://github.com/RobTillaart/SHT31/blob/master/examples/SHT31_rawValues/SHT31_rawValues.ino
#include <M5AtomS3.h>
#include <M5Unified.h>
#include "Wire.h"
#include "Wire.h"
#include "SHT31.h"
#define SHT31_ADDRESS 0x44
uint32_t start;
uint32_t stop;
uint32_t cnt;
SHT31 sht(SHT31_ADDRESS); // uses explicit address
void setup()
{
Serial.begin(115200);
Wire.begin();
Wire.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus();
sht.requestData();
cnt = 0;
}
void loop()
{
uint16_t rawTemperature;
uint16_t rawHumidity;
if (sht.dataReady())
{
start = micros();
bool success = sht.readData(); // default = true = fast
stop = micros();
sht.requestData(); // request for next sample
Serial.print("\t");
Serial.print(stop - start);
Serial.print("\t");
if (success == false)
{
Serial.println("Failed read");
}
else
{
rawTemperature = sht.getRawTemperature();
rawHumidity = sht.getRawHumidity();
Serial.print(rawTemperature, HEX);
Serial.print(" = ");
// This formula comes from page 14 of the SHT31 datasheet
Serial.print(rawTemperature * (175.0 / 65535) - 45, 1);
Serial.print("°C\t");
Serial.print(sht.getRawHumidity(), HEX);
Serial.print(" = ");
// This formula comes from page 14 of the SHT31 datasheet
Serial.print(rawHumidity * (100.0 / 65535), 1);
Serial.print("%\t");
Serial.println(cnt);
cnt = 0;
}
}
cnt++; // simulate other activity
delay(1000);
}
Hello @felmue
I implemented the change using GPIO10 for the random seed, and the I2C issue seems to be resolved. Your help is greatly appreciated!
Thank you for your fix!
Surya
Oops, I forgot to share the error message. Here it is
Hello @felmue
I have already attempted a short delay, but unfortunately, that doesn't work for me. As for periodic code execution, I will give it a try.
Thanks
Surya
Thank you so much for sharing your work!
Earlier, I successfully sent data over MQTT to AWS IoT Core in UIFlow2. However, in UIFlow2, I couldn't find a way to establish a (DHCP) Ethernet connection to AtomS3 using AtomPoE Base. That's why I decide to develop the code using PlatformIO. Do you have any reference Micropython script for an Ethernet connection?
I appreciate your input! Could you please share the link or specify the topic name related to the example you mentioned in the Project zone? I'm interested in diving deeper.
@teastain Thanks for the clarification!
Yeah, I understood that these sensors likely use different communication protocols. Also, I attempted to use a different GPIO pin for the DS18B20, and it worked perfectly for me.
Now, my only concern is my second script. Here, I'm using different ports for the ENV sensor and AtomPoE base in AtomS3. However, when I connect with the MQTT client, it breaks the ENV sensor's communication. Any advice is greatly appreciated!
In another script, I'm trying to upload 'ENV' sensor readings to AWS IoT Core using MQTT.
I've connected AtomPoE Base to AtomS3 for Ethernet, using the port behind AtomS3, and attached the ENV sensor to the Grove port. Both AtomPoE and the ENV sensor use different ports. However, when I use MQTT_Client.connect(), it triggers a similar crash in the ENV sensor. Without the connection, the sensor works perfectly fine.
Any advice on how to address this issue would be greatly appreciated!
#include <M5AtomS3.h>
#include <M5Unified.h>
#include <SPI.h>
#include <SSLClient.h>
#include <M5_Ethernet.h>
#include <PubSubClient.h>
#include "certificates.h"
#include <ArduinoJson.h>
#include <SensirionI2CSht4x.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_Sensor.h>
#define SCK 5
#define MISO 7
#define MOSI 8
#define CS 6
Adafruit_BMP280 bmp;
SensirionI2CSht4x sht4x;
float temperature, pressure, humidity;
// The MQTT topics that this device should publish/subscribe
#define AWS_IOT_PUBLISH_TOPIC "AtomS3/env"
#define AWS_IOT_SUBSCRIBE_TOPIC "AtomS3/msg"
const char my_cert[] = "-----BEGIN CERTIFICATE-----\n"
"MIIDWjCCAkKg...\n"
"-----END CERTIFICATE-----\n";
const char my_key[] = "-----BEGIN RSA PRIVATE KEY-----\n"
"MIIEowIBAAKCAQEAk...\n"
"-----END RSA PRIVATE KEY-----\n";
SSLClientParameters mTLS = SSLClientParameters::fromPEM(my_cert, sizeof my_cert, my_key, sizeof my_key);
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x89};
const char *mqttServer = "a1pexxx.amazonaws.com";
void callback(char *topic, byte *payload, unsigned int length)
{
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
}
Serial.println();
}
EthernetClient ethClient;
SSLClient ethClientSSL(ethClient, TAs, (size_t)TAs_NUM, 2);
PubSubClient client(mqttServer, 8883, callback, ethClientSSL);
void reconnect()
{
// Loop until we're reconnected
while (!client.connected())
{
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("arduinoClient"))
{
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("outTopic", "hello world");
// ... and resubscribe
client.subscribe("ENV_TEST");
}
else
{
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void publishMessage()
{
StaticJsonDocument<200> doc;
doc["temperature"] = temperature;
doc["humidity"] = humidity;
doc["pressure"] = pressure;
char jsonBuffer[512];
serializeJson(doc, jsonBuffer); // print to client
client.publish(AWS_IOT_PUBLISH_TOPIC, jsonBuffer);
}
void setup()
{
M5.begin();
M5.Power.begin(); // Init power
M5.Lcd.setTextSize(2);
M5.Lcd.println("Init..");
SPI.begin(SCK, MISO, MOSI, -1);
Wire.begin();
Serial.begin(115200);
while (!bmp.begin(BMP280_ADDRESS_ALT))
{
M5.Lcd.println("Could not find a valid BMP280 sensor, check wiring!");
Serial.println(F("BMP280 fail"));
}
M5.Lcd.clear(); // Clear the screen.
Serial.println(F("BMP280 test"));
uint16_t error;
char errorMessage[256];
sht4x.begin(Wire, SHT40_I2C_ADDR_44);
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
Adafruit_BMP280::SAMPLING_X2,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16,
Adafruit_BMP280::STANDBY_MS_500);
Ethernet.init(CS);
M5.Lcd.println("Connecting ethernet...");
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(1000);
}
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println(
"Ethernet shield was not found. Sorry, can't run without "
"hardware. :(");
while (true)
{
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF)
{
Serial.println("Ethernet cable is not connected.");
}
delay(5000);
ethClientSSL.setMutualAuthParams(mTLS);
Serial.println(client.connect("ENV_TEST"));
}
void loop()
{
if (!client.connected())
{
M5.Lcd.println("reconnecting...");
reconnect();
}
else
{
SPI.begin(SCK, MISO, MOSI, -1);
uint16_t error;
char errorMessage[256];
pressure = bmp.readPressure();
error = sht4x.measureHighPrecision(temperature, humidity);
if (error)
{
Serial.print("Error trying to execute measureHighPrecision(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
}
else
{
Serial.print("Temperature:");
Serial.print(temperature);
Serial.print("\t");
Serial.print("Humidity:");
Serial.println(humidity);
}
M5.Lcd.clear();
M5.Lcd.setCursor(0, 0); // Set the cursor to (0,0)
M5.Lcd.printf("T:%2.0f", temperature);
M5.Lcd.setCursor(0, 20);
M5.Lcd.printf("P:%2.0f", pressure);
M5.Lcd.setCursor(0, 40);
M5.Lcd.print("H:");
M5.Lcd.print(humidity);
M5.Lcd.print("%");
delay(100);
publishMessage();
}
client.loop();
delay(10000);
}
Thanks, @felmue, for the info!
Both sensors use the same Grove connector pins, and since AtomS3 has only one Grove port, I've connected both sensors with Grove-T connectors.
If they still don't work together, I'll try connecting one sensor directly to the GPIO port at the back of AtomS3. Any more suggestions are welcome!
I'm just getting started with AtomS3. I'm attempting to read temperature values from both the "M5 ENVIV Unit" and "DS18B20" sensors simultaneously. However, I'm encountering an error, specifically Error writing to I2C bus, which prevents me from successfully reading from the "M5 ENVIV Unit" sensor.
FYI: I can successfully read values from each sensor separately; the error only occurs when I try to read from both sensors simultaneously.
Could someone please offer guidance or solutions to resolve this issue? Your help would be greatly appreciated.
#include <M5Unified.h>
#include <SensirionI2CSht4x.h>
#include <Adafruit_BMP280.h>
#include <OneWire.h>
#include <DallasTemperature.h>
const int oneWireBus = 1;
void T2()
{
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
sensors.begin();
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
M5.Lcd.setCursor(0, 60);
M5.Lcd.printf("T2:%2.0f", temperatureC);
}
void ENV()
{
float temperature, pressure, humidity;
Adafruit_BMP280 bmp;
SensirionI2CSht4x sht4x;
bmp.begin(0x76);
uint16_t error;
char errorMessage[256];
sht4x.begin(Wire, 0x44);
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
Adafruit_BMP280::SAMPLING_X2,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16,
Adafruit_BMP280::STANDBY_MS_500);
delay(1000);
error = sht4x.measureHighPrecision(temperature, humidity);
if (error)
{
Serial.print("Error trying to execute measureHighPrecision(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
}
else
{
Serial.print("Temperature:");
Serial.print(temperature);
Serial.print("\t");
Serial.print("Humidity:");
Serial.println(humidity);
}
pressure = bmp.readPressure();
M5.Lcd.clear();
M5.Lcd.setCursor(0, 0);
M5.Lcd.printf("T:%2.0f", temperature);
M5.Lcd.setCursor(0, 20);
M5.Lcd.printf("P:%2.0f", pressure);
M5.Lcd.setCursor(0, 40);
M5.Lcd.print("H:");
M5.Lcd.print(humidity);
M5.Lcd.print("%");
}
void setup()
{
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
Serial.begin(115200);
Wire.begin();
Wire.setClock(100000);
}
void loop()
{
ENV();
T2();
delay(100);
}