Xiao esp32C6 and the DS18B20

I’m using the Xiao above (C6) mounted on the cool expansion board with the tiny display in the middle. I want to measure temperature with an 18B20 using the recommended Arduino IDE. So, I loaded the Dallas and One Wire libraries, and of course, it wouldn’t compile. So, I chased down the error and put the newest .h file in the One Wire library directory and it compiled, but it didn’t work.

I took the code example that everyone uses the first time, used pin 7 as the bus, and all I got back was the default -127 and -196 that usually indicates that the code didn’t see the 18B20.

So, I hunted the web looking for solutions and found another library, OneWireNg and loaded it. It compiled first time, but it didn’t work either. Same results.

So, I tried another sensor, same results. Then,instead of the waterproof sensor I want to use, I used one of the little ones, same results. In desperation, I chased the wires from the grove plug I used to the actual wires on the side of the C6 board. They checked out fine.

Yes, I have the resistor from 3.3 to the data line; that was the first thing I did.

Now, I may be a newby to the C6, but I’m not new to the 18B20, I’ve installed those things on a lot of devices to monitor temperatures from the heat sink on a large battery charger to the one inside my freezer; I have them controlling my A/C units. They ALL worked first try.

Not this time. Two different libraries and multiple sensors, same results. I even moved the 18B20 to pin 0 to see if that made a difference, same results.

What am I missing? Is there some secret to using one wire on the C6 that I missed in my hours of searching for answers. This really shouldn’t be hard.

I have the sensors, dozens of them in a bag (Digi had a sale a few years back). Both the waterproof ones and the little ones. I use them all the time with various little processors.

BUT I FOUND THE PROBLEM !!

After hours and hours of trying things, while I was typing in the question and describing the problem, I thought of something that I hadn’t tried, and absolutely none of the examples out there had in them. I tried it, and it worked.

I changed the code from this:

void setup() {
// Start the Serial Monitor
Serial.begin(115200);
// Start the DS18B20 sensor
sensors.begin();
}

to this:

void setup() {
// Start the Serial Monitor
Serial.begin(115200);
// Start the DS18B20 sensor
pinMode(oneWireBus, INPUT);
sensors.begin();
}

Yep, I had to let the device know what I was using the pin for. I have the pin (oneWireBus) defined as D7, not 7. None of the examples, tutorials, etc have this little jewel in them. That makes me wonder how many people actually do the things they spout off about on the web. It also make me wonder how many people try some of those things and just give up after trying for a couple of hours.

3 Likes

yes the BSP Board Support Package and excessivly high baud rate are usually the problem

How is that a factor?

the BSP controls how the pins are mapped… what physical pin goes to which gpio… each XIAO model had a different mapping scheme… the BSP works in the background to do this mapping… so for example if you use pin D7 with the board support package loaded for a XIAO ESP32s3 instead of an Esp32C3 all betts are off… D7 is not a real pin… it is a representation of a location on the board and a “variable” for lack of a better word in the code. If you multiply axb=c you cannot expect to get the same answer if you multiply exf=g will never ever work excessivly high baudrate will cause the XIAO to not accept new code upload without hard boot-reset and can be a pain in the A… also fast or slow baud can effect waste of processor respurces and interupt problems

So, if I had waited to initialize the serial port until after the one wire bus, it might have worked? Or maybe put a small delay between the the two it might have worked. I can test those items pretty easily. However, there was nothing going on at the time those things were happening. The board init should have finished before setup() was called, and just setting the baud rate shouldn’t interfere.

I may go back now and test the other libraries I tried (if I can remember them) and see if they work as well.

1 Like

Hi there,

So the BSP is only compatable with certain LIBs, more than likely the One wire is Older and requires an older BSP. also I have an example code with compiler output as well , so you can see which versions worked for the Xmas Demo I have on here. I used the DS18B20 code is included. Gove Expansion board demo.

HTH

GL :slight_smile: PJ :v:

Roll back the BSP in the boards tab. Embed or non-embed BSP’s
in the compiler output you can see FQBN. version
1st line, at the end(scroll right) :+1:

I’m not sure what’s actually wrong, or what works differently. I am sure that once I set the pin to be a digital pin, the 18B20 code started working. I must have looked at a hundred examples, and specifically ignored arduino (the non esp ones), and none of them set the data pin first. What gave me a clue was one person out there accidentally put the pin mode in when he first wrote the code, didn’t take it out, and it worked for him with the one library he could actually get to compile without errors.

It would seem that the xiao esp32C6 has some differences that the various libraries haven’t caught up to yet. Hence the compilation problems and fixes that haven’t made it into Arduino IDE yet.

I just stumbled into that and was fortunate enough to run across another person that had the same thing happen.