I’m new to the SAMD21, and I’m trying to adapt some code from the Uno to it. One “simple” device that I thought I’d start with is the DS18B20 thermal sensor – uses OneWire. I’ve got sample code that I had run on the Uno and it compiles and runs on the SAMD21, but it never gets out of the address-search loop.
Does anyone know if that code DOES work on the SAMD, or if it definitely won’t?
But more critically, I can’t determine what the pinouts are on the SAMD21. The figure here:
has the following pins on the inner row, from the top down:
switch
raw
3v3
gnd
d9
d4
…
MY board has its pins labeled
switch
raw
3v3
d9 (NOT GND!)
d4
…
Which should I believe? I’d really like that GND pin to be in there. But I’ve tried that pin as bot d9 and gnd, and it didn’t work either way.
Also, the datasheet on the web page above says that SAMD d9 is the same as Arduino d9 (etc.). Does that mean that I should use pin 9 in the .ino code to address that pin, or is there some other mapping I should be aware of?
I have to say that the SAMD21 is a nifty little device, and the Pro RF version with LoRa is really cool (yes, I’m sending to TTN). But figuring out how to program it and which libraries to use has been a bear.
It looks like the graphical datasheet is incorrect and somehow an extra GND got added in. The labels on the silkscreen are correct. (D9 is actually D9, not GND and you call it digital pin 9 in your code.)
Also, in case you haven’t figured it out already, the labels on the board are for the inside pin, not the ones on the edge of the board. All of the outside edge pins except for ‘Switch’ and ‘ANT’ are grounds. The white silkscreening around those indicate they are all connected together.
I’ll poke our team that maintains those drawings so that they can fix it.
Thanks, Chris. I believed the silkscreen but tried it both ways. Yes, it would be good to have someone fix that datasheet to avoid confusing others in the future. I also tried all the other Dn pins in the code just in case there was some other mislabeling … they all fail in the code’s address search, which is the first attempt to toggle the signal on that pin. And yes, I noticed that the signal pins on the inside rows are paired with grounding pins on the outside rows – I’m connecting to the inside pin for signal and using the outside pin as ground.
Has anyone used OneWire library on the SAMD21? Any reason it shouldn’t work?
All: the answer is “yes, the OneWire library works on the SAMD21, and it can read the DS18B20 thermal sensor”. I installed via the “manage libraries” dropdown menu in the Arduino IDE and installed the Adadfruit OneWire library described here: https://github.com/adafruit/MAX31850_OneWire.
The problem I was having was that my D9 pin only put out 1.8V when “high”. That was the pin I kept testing with. Finally decided to check voltages. The other Dn pins gave 3.3 v high,0 low and floated if other pins were asserted; D9 gave 1.8 high, a few mv low, and a few mv when other pins were asserted. Defective SAMD21 board. I’ll just avoid D9 on that board.
Tested with my other SAMD board and all pins behave as expected: 3.3v high, 0 low, and float when other pins are asserted.
So the lesson here: check your voltages before spending a day trying to figure out why your code doesn’t work.