I just started experimenting with this SEEED MCU. I want to use this in a project I have to instrument bee hives. So the first code I uploaded was the “do nothing” code (basic shell with no code). I am using the Arduino IDE V2 and that worked fine. Then I modified to do a Serial print of “Hello World” and that worked fine.
So I decided to get bold and loaded the Arduino DHT 22 example code. I wired my DHT22 sensor as follows. + pin to the 5 Volt pin on the SEEED, - pin to ground on the SEEED and the data pin to the D7 pin on the SEEED. I then uncommented the Debug command in the DHT.h file to get debug information. Program compiled fine and upload initially went without a problem. But I received the following error from the Debug section of the cpp code: DHT timeout waiting for start signal high pulse.
Here’s the code that generates that message:
uint32_t cycles[80];
{
// End the start signal by setting data line high for 40 microseconds.
pinMode(_pin, INPUT_PULLUP);
// Delay a moment to let sensor pull data line low.
delayMicroseconds(pullTime);
// Now start reading the data line to get the value from the DHT sensor.
// Turn off interrupts temporarily because the next sections
// are timing critical and we don't want any interruptions.
InterruptLock lock;
// First expect a low signal for ~80 microseconds followed by a high signal
// for ~80 microseconds again.
if (expectPulse(LOW) == TIMEOUT) {
DEBUG_PRINTLN(F("DHT timeout waiting for start signal low pulse."));
_lastresult = false;
return _lastresult;
}
if (expectPulse(HIGH) == TIMEOUT) {
DEBUG_PRINTLN(F("DHT timeout waiting for start signal high pulse."));
_lastresult = false;
return _lastresult;
}
I did some checking and found several suggested solutions none of which worked. I changed pins for the data and that didn’t help either.
So I made some mods (baud speed and commented some code out and tried to upload. Well then I get a serial read error. I could not upload the code. I tried holding the boot and reset buttons as suggested and that worked a few times. I reset the upload speed from the tools menu and that didn’t work either. So now I have a SEEED that seems to be dead.
I then went to the command line and checked to see if I was even communicating with the SEEED, here is the command I used:
cu -l /dev/ttyACM0 -s 115200
And here is the result:
Rebooting…
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xb (SPI_FAST_FLASH_BOOT)
Saved PC:0x40048b82
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1058
load:0x403cc710,len:0x8a8
load:0x403ce710,len:0x2fac
entry 0x403cc710
DHT max clock cycles: 160000
Setup <— This is from a Serial.print in the program.
So it appears to be communicating somewhat, but not very well.
Any help will be greatly appreciated!!
If this is typical (and I hope it isn’t) of this MCU I will not be able to use it in my project. So if anyone has any suggestions I would really like to hear them.
Oh one other thing, the DHT sensor works fine on an Arduino UNO and the micro:bit boards.
Thanks in advance!!
Today I loaded and tried running the seeed with Visual Studio Code PlatformeIDE. It gave the same results including the failure to upload code after two or three uploads. I wonder if the code is being uploaded not over the old code but appended to the old code, hence the ram is being filled up then further uploads are blocked. Just a wild guess of course.
I think I found the problem. When I access the serial port with the command cu -l /dev/ttyACM0 -s 115200. What this command respond with is the output from the first program I wrote the Hello World program. So none of the other programs seem to be uploading. Very strange!
Ok, I am using the DHT library from Adafruit v 1.4.6. I have another few sensors due in today or tomorrow so I’ll try a different sensor. I re-flashed the factory image and will try to install the sketch later today. I am also going to get my Arduino UNO out and see if the sensor runs there, it was running fine on that MCU.
Ok, I found my mistake. I have been coding for Arduino for many years and just expected the same formatting rules to apply to XIAO. WRONG!! The pin declaration for Arduino is just the pin number, but it appears the pin number for the SEEED includes an aphanumeric. So where I was using 2 as the value of the pin variable, it should have been D2. Once I made that change all is good. Makes an old programmer feel really dumb. Guess I’ll read the documentation in the future!!!
The first stumbling blocks for someone coming from the Aruduino world are the pin names and the 3.3V I/O voltage.
I’m glad you were able to solve this problem.
well, I jumped too soon. It still is not working. So I loaded the test script from the dht22.h library. Here’s that code (with a mod I made to do a string dump of the data from the sensor)
#include <DHT22.h>
//define pin data
#define pinDATA 0 // SDA, or almost any other I/O pin
DHT22 dht22(pinDATA);
void setup() {
Serial.begin(115200); //1bit=10µs
Serial.println("\ntest capteur DTH22");
}
void loop() {
Serial.println(dht22.debug()); //optionnal
float t = dht22.getTemperature();
float h = dht22.getHumidity();
Serial.println("StringData");
Serial.println(dht22.getRawStrData());
if (dht22.getLastError() != dht22.OK) {
Serial.print("last error :");
Serial.println(dht22.getLastError());
}
Serial.print("h=");Serial.print(h);Serial.print("\t");
Serial.print("t=");Serial.println(t);
delay(2000); //Collecting period should be : >1.7 second
}
And here is a printout of the serial output.
### BEGIN DEDUG ###
look at datasheet for timing specs
t_80L t_80H t_50 t_Bit0 t_Bit1
80 80 50 0 0
error : 1
0000000000000000 0000000000000000 00000000
h t crc
0.0 0.0 TRUE
### END DEDUG ###
StringData
0000000000000000 0000000000000000 00000000
Very confusing to me. I have no way of debugging the sensor that I can find, I have tried two different Seeed XIAO ESP32c3 processors and two different sensors and get the same results. I have changed pins twice with no change and I have changed voltages with on change. I don’t know what else I can do to get this sensor working with the seeed.
I saw that, but all the examples were for the 4 pin sensor. I have the sensor already mounted on a pcb and I think the pull up is on the pcb. I could be wrong and I’ll do more research to make sure. Thanks for the input!!
Put a 4.7K ohm pullup resistor in the circuit and it now works fine. Many thanks. Wonder why the Arduino didn’t need a resistor. Strange.
Thanks msfujino for all your help, you may have saved what little hair I have left!