Jump to content

Hello all, i am not sure if this is right place to ask but i am pretty much on the end of road


G+_Matej Raj?an
 Share

Recommended Posts

Hello all, i am not sure if this is right place to ask but i am pretty much on the end of road... I have a Wemos D1 mini, OLED shield (I2C) , temperature shield SHT30 (I2C) and SD card shield (standard 4 pin D5, D6, D7, D8 connection).

 

Everything works as a double with Wemos - I can read temp and send to display, i can write to the SD.

 

Troubles appear, when i try to read the TEMP the second time in the program, which is not possible. This code

 

void loop() {

 

if(sht30.get()==0){

Serial.print("Temperature in Celsius : ");

Serial.println(sht30.cTemp);

Serial.print("Relative Humidity : ");

Serial.println(sht30.humidity);

Serial.println();

}

else

{

Serial.println("Error!");

}

delay(1000);

 

}

 

works when i want to read a temp and send to display, but i want to log it on to SD card.

 

I tried to change the adress on TEMP shield, that did not work, i tried different SD shields (one with and without RTC clock) but same effect. I believe (with my basic knowledge of 1 month programming arduinos and stuff) there might be trouble that SD library (for wemos) is accessing some memory that SHT3x is then trying to read but falsely. One try would be to isolate the code to run in subfunction and output only the TEMP and HUMI value, second idea would be to read about the library but i cannot see list of the commands for it, no function, no nothing. I simply cannot understand how does it work. I also tried to put the

while (sht30.get()!=0){

delay(10);

}

to see if it reaches the state of the sensor to be able to read, but without success...

 

 

I can only get the TEMP and HUMI values once, then it is over.

Some ideas?

Link to comment
Share on other sites

A couple things. You didn't mention where you got the parts so I assume they match the following site: wiki.wemos.cc - WEMOS wiki [WEMOS Electronics]

 

I read thru the example for the SD Shield. It uses SPI, not I2C. I don't see where you created the SD handler or created a File to write to.

 

Here is the SD Eample: https://github.com/wemos/D1_mini_Examples/blob/master/examples/04.Shields/Micro_SD_Shield/Files/Files.ino

 

Good Luck

Link to comment
Share on other sites

Jim Hofmann Your reply helped me, but not in a straight way. You see, i tried every library separetly to see if my shields works. SD would write and read no problem (strange). I spent rest of my afternoon figuring out what is the proble, and i got into point only something with SD library was wrong, but not the initialization part, but in your sample code there was

...

if (!SD.begin(D8)) {

...

 

i had there only 4. (not d4, "4"). Quick glance to arduino pinout numbering and i corrected it to 15 (pin D8) which should be CS on SD shield. Uploeaded, and it now works, thanks a lot!

Link to comment
Share on other sites

I am not registered there, so code below.>

 

#include

#include

 

#ifdef U8X8_HAVE_HW_SPI

#include

#endif

#ifdef U8X8_HAVE_HW_I2C

#include

#endif

 

#include

#include

 

File myFile;

 

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=/ SCL, / data=/ SDA, / reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display

 

#include

 

SHT3X sht30(0x44);

 

float temp_c;

float temp_f;

float humidity2;

boolean sdini = 1;

 

int val_temp;

int val_humi;

 

void setup() {

 

Serial.begin(115200);

delay(100);

pinMode(LED_BUILTIN, OUTPUT);

Serial.println("Wemos boot");

u8g2.begin();

u8g2.clearBuffer();

u8g2.setFont(u8g2_font_5x7_mr);

u8g2.setCursor(0, 10);

u8g2.print("WEMOS BOOTING...");

u8g2.sendBuffer();

u8g2.clearBuffer();

digitalWrite(LED_BUILTIN, HIGH);

 

//----------------------------------------------

if (sdini == 1){

Serial.print("Initializing SD card...");

 

//if (!SD.begin(4)) {

if (!SD.begin(15)) {

Serial.println("initialization failed!");

delay(200);

return;

}

Serial.println("initialization done.");

sdini = 0;

}

}

 

 

void loop() {

// SPI.setDataMode(SPI_MODE3);

delay(5000);

digitalWrite(LED_BUILTIN, LOW);

delay(10);

digitalWrite(LED_BUILTIN, HIGH);

 

mojafunkcia();

 

u8g2.setFont(u8g2_font_inb19_mf );

u8g2.setCursor(7, 34);

//u8g2.print("T: ");

u8g2.print(sht30.cTemp);

u8g2.print((char)176);

u8g2.print("C");

u8g2.setCursor(7, 64);

//u8g2.print("H: ");

u8g2.print(sht30.humidity);

u8g2.print(" %");

u8g2.sendBuffer();

 

//-----------------------------------------------------------------------//

 

delay(2000);

 

 

myFile = SD.open("test.txt", FILE_WRITE);

if (myFile) {

Serial.println("Writing TEMP to test.txt...");

myFile.print("TEMP ");

delay(50);

myFile.print(sht30.cTemp);

delay(50);

myFile.print((char)176);

delay(50);

myFile.print("C;");

 

Serial.println("Writing HUMI to test.txt...");

myFile.print("HUMI ");

delay(50);

myFile.print(sht30.humidity);

delay(50);

myFile.println("%;");

delay(50);

myFile.close();

delay(50);

 

Serial.println("done.");

Serial.println();

} else {

// if the file didn't open, print an error:

Serial.println("error opening test.txt");

}

 

 

}

 

 

 

void mojafunkcia()

{

 

if(sht30.get()==0){

 

//sht30.get();

Serial.print("Temperature in Celsius : ");

Serial.println(sht30.cTemp);

Serial.print("Relative Humidity : ");

Serial.println(sht30.humidity);

 

 

}

else

{

Serial.println("Temperature read error!");

}

 

}

Link to comment
Share on other sites

Just for the lulz, i put a picture here, plan is to use this stack with SD shield, RTC clock (two in one, just one i have does not work :( ), sht30 (more recent one to be able to mount it somewhat outside the case, or near opening) OLED, and LIPO shield inside a waterproof case. Plan is to use temp and humi to send to my other wemos, which will also show temp. inside and adjust red/blue LED ring according temperature outside - red hot, blue cold. It is also planned to count the amount of power downs, hence the lipo shield which will keep it running for a short time.

I am using wemos mini pro to be able to connect external antenna (although these small antennas are really good).

 

On the left-

wemos mini pro

SD shield

 

on the right

OLED with proto I2C shield

SHT30 shield

 

bottom is 2 slot base, which i use mainly because it has screw holes.

But a lot of babysteps before it will do all of this.

31375%20-%20a1.jpg

Link to comment
Share on other sites

 Share

×
×
  • Create New...