Dallas temperature sensor DS18S20 with the ATmega32-16PU

Hello,
I want to use the ATmega32-16PU together with a Dallas temperature sensor DS18S20.
I connected the data line of the DS18S20 to PIN 18. Within the code I use:

#define ONE_WIRE_BUS 12

See attached sketch. It’s the the one that comes with the Arduino Library for Dallas Temperature ICs.

The answer I get on serial is the following:

Requesting temperatures…DONE
Temp C: -127.00 Temp F: -196.60

Whe I pull out the data line I get the following answer:

Requesting temperatures…DONE
Temp C: 0.00 Temp F: 32.00

So I know at least it’s the right pin.

I know the sensor is ok because I checked it with an Arduino UNO just after the trial with the ATmega32-16PU.

Are there any incompatibilities with OneWire or is it the wrong port I used at the ATmega32-16PU ?

Thanks for your help.
Regards, AgeBee

single.ino (3.91 KB)

you need to tell the software which pin you connected to . 12 or 18 ?

michinyon: you need to tell the software which pin you connected to . 12 or 18 ?

When I use the famous blink sketch and put it like this ...

int led = 12;

... it blinks. So, I think the software already got the right pins.

Or, whereabout in the code is it necessary ?

The software needs to talk to the external device on the pin which you tell it to use. You have to actually connect the device to the same pin.

If you specify in the software that you are going to use pin 12, then you need to actually connect the device to pin 12. You said you used pin 18, which DOESN'T MAKE SENSE.

Using the pin with the hardware led really isn't the best idea, the one-wire bus transmission works by the microcontroller and the device pulling the voltage on that one wire down, having a led connected to that wire might be counterproductive. Use another pin, BUT MAKE SURE THE PIN YOU SPECIFY IN THE SKETCH IS THE SAME PIN THAT YOU PHYSICALLY CONNECTED THE DEVICE TO.

No, that didn't help. When I use ...

#define ONE_WIRE_BUS 12

and connect it to pin #12 there is no response.

I tried it with other pins, for example #0, #1 without success.

When you take a look into the pins_arduino.h of the mega32 library which I use you see the following array:

const uint8_t PROGMEM digital_pin_to_port_PGM[32] = {
    PB,  // PB0 ** D0
    PB,  // PB1 ** D1
    PB,  // PB2 ** D2
    PB,  // PB3 ** D3
    PB,  // PB4 ** D4
    PB,  // PB5 ** D5
    PB,  // PB6 ** D6
    PB,  // PB7 ** D7
    PD,  // PD0 ** D8
    PD,  // PD1 ** D9
    PD,  // PD2 ** D10
    PD,  // PD3 ** D11
    PD,  // PD4 ** D12
    PD,  // PD5 ** D13
    PD,  // PD6 ** D14
    PD,  // PD7 ** D15
    PC,  // PC0 ** D16
    PC,  // PC1 ** D17
    PC,  // PC2 ** D18
    PC,  // PC3 ** D19
    PC,  // PC4 ** D20
    PC,  // PC5 ** D21
    PC,  // PC6 ** D22
    PC,  // PC7 ** D23
    PA,  // PA7 ** A0 D24
    PA,  // PA6 ** A1 D25
    PA,  // PA5 ** A2 D26
    PA,  // PA4 ** A3 D27
    PA,  // PA3 ** A4 D28
    PA,  // PA2 ** A5 D29
    PA,  // PA1 ** A6 D30
    PA,  // PA0 ** A7 D31
};

Now you can see why I suspected that it has to be pin # 18 at the ATmega. D12 is mapped to PD4 which is pin #18 at the ATmega.

It seems that there is another reason why it does not work.

The pin numbers on the header on the arduino board are numbered by writing on the board.

These numbers do not correspond directly to the pin number of the actual microprocessor chip.

The correspondence of these numbers is available in a table somewhere , for your arduino model.

The chip numbers vary depending on the chip. The pin header numbers are the same, thats how you can use the same add-on shields on different arduino boards. A standard header interface.

When you write programs using the standard arduino c++, and you refer in your code to digital inputs and outputs to read or write from, the numbers you use are the pin numbers on the board headers, not the chip pin numbers.

Avoid using pins which are used for other things. For example, don't use pin 0 or 1, if those are the pins used for Serial RX/TX

When you ran that sketch, did it report that it detected any one-wire devices ?

Thanks michinyon for your explanation.

No, there is no output about that it detected a one-wire device.

Just a remark for my setup. I use an UBSTinyISB to flash the controller which is an ATmega32-16PU and you find the corresponding datasheet here: http://www.atmel.com/Images/doc2503.pdf

When I looked at your answer I think you mixed up the ATmega32-16PU with the ATmega328P. The latter uses PD0 and PD1 for RX/TX, respectively and is used within the Arduino.