How to connect DS18B20 - Which pins are available?
-
Hello,
I'm trying to connect a DS18B20 (onewire) temperature sensor on my M5Stack board, but I don't know which pins to use.
Could you tell me which pins are available (not connected) on the board? I use the headers on the side of the M5Stack box.
Here are my connections so far :
- VCC on the sensor => 3.3V on M5Stack
- GND => GND
- DATA on the sensor => ???
- A 4.7K resistor between VCC and DATA
Thanks!
-
@zazar has already done it.
-
@world101 在 How to connect DS18B20 - Which pins are available? 中说:
@zazar has already done it.
@zazar, if you come by, could you provide us with some information about your project? How did you connect the DS18B20 sensors (wich pins did you use)? Which Onewire/ds18b20 lib did you use, if any ?
Thanks!
-
Try it.
GPIO2 fully free
https://github.com/G6EJD/ESP32-DS18B20-Sensor-Reading -
@x-dron 在 How to connect DS18B20 - Which pins are available? 中说:
Try it.
GPIO2 fully free
https://github.com/G6EJD/ESP32-DS18B20-Sensor-ReadingI've already tried, and I can't find why it doesn't work, that's why I'm asking.
I've tried your example, I've just set the define ONE_WIRE_BUS to 2:
#define ONE_WIRE_BUS 2
The sensor is still not detected. Moreover, the board make a little piercing sound when it probes for the sensor and the temperature. I don't understand where it comes from, as GPIO2 should not be connected to the speaker...
Any ideas?
-
New information : I tried the exact same code than the one provided by @X-Dron (https://github.com/G6EJD/ESP32-DS18B20-Sensor-Reading) on an ESP8266 (using pin D3) and... it works perfectly (I tried with 1, then 2 and 3 sensors)!
Is there something I'm missing, or is there an hardware issue with my board?
-
This is what I used just to test read multiple sensors on the M5Stack:
#include <M5Stack.h> #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 5 // DS18B20 on arduino pin2 corresponds to D4 on physical board OneWire oneWire(ONE_WIRE_BUS); DallasTemperature DS18B20(&oneWire); void setup() { M5.begin(); M5.Lcd.setTextColor(TFT_WHITE,TFT_BLACK); M5.Lcd.setTextSize(2); } void loop() { float celsius; float fahrenheit; DS18B20.begin(); int count = DS18B20.getDS18Count(); //M5.Lcd.clear(); M5.Lcd.setCursor(0,0); M5.Lcd.print("Devices found: "); M5.Lcd.println(count); if (count > 0) { DS18B20.requestTemperatures(); for (int i=0; i < count; i++) { celsius = DS18B20.getTempCByIndex(i); fahrenheit = celsius * 1.8 + 32.0; celsius = round(celsius); fahrenheit = round(fahrenheit); M5.Lcd.print("Device "); M5.Lcd.print(i); M5.Lcd.print(": "); M5.Lcd.print(celsius,0); M5.Lcd.print( "C / "); M5.Lcd.print(fahrenheit,0); M5.Lcd.println("F"); } } delay(2000); }
-
OneWire version 2.3.4
DallasTemperature version 3.79 -
@zazar 在 How to connect DS18B20 - Which pins are available? 中说:
OneWire version 2.3.4
DallasTemperature version 3.79Thanks, @zazar!
I use exactly the same lib, and similar code without any result for now, unfortunately.
-
Here is a little report on my progression. In short : it still doesn't work!
I checked that the pin "works" correctly by connecting a relay to test in OUTPUT mode, and a push button (to test in INPUT) : it works!
I checked, double checked and triple checked the setup (wires, connections,...), everything is good.
I ran the same code on a Wemos D1 Mini (ESP8266) : it works.At this point, I'm lost? The pin and the code seem good, but it can't detect the sensor.
One thing I notice is that this weird whistling sound coming out of the board (not sure if it comes from the speaker or not) when the OneWire lib bitbangs the OneWire protocol on the pin.
So, I made another test program that toggles the pin rapidely (at the speed of the onewire lib - ~50µs) : I hear the sound!I'll try to find an oscilloscope to check the signal on the pin, as I suspect that "something" is going wrong when the pin is driven at "high" speed.
In the meantime, I hope that someone with more electronical knowledge will help me find a solution!
-
After years it still birps, but does not work.
Any new hints? -
@efried Found solution here : https://community.m5stack.com/post/1394
Add dacWrite (25,0); into the void loop