Problems with 1wire and MAX

Hi, I have modified the programmcode of Dallasonewire.h

It works like a charm if only one MAX3150K is connected.

Now I connect 10 works also but the Adress is the same because all adress pins are LOW. I get all Unique ROMS.

How can I get now all Temperatures without using adress. only use unique ROM?

The Code:

//--------------------------------------------------------------------------------------
// TempTX-tiny ATtiny84 Based Wireless Temperature Sensor Node
// By Nathan Chantrell http://nathan.chantrell.net
// Updated by Martin Harizanov (harizanov.com) to work with DS18B20
// To use with DS18B20 instead of TMP36, a 4K7 resistor is needed between the Digital 9 and Digital 10 of the ATTiny (Vdd and DQ)
// To get this to compile follow carefully the discussion here: http://arduino.cc/forum/index.php?topic=91491.0
// GNU GPL V3
//--------------------------------------------------------------------------------------
// modified by meigrafd @ 10.05.2014
//------------------------------------------------------------------------------
//#include <JeeLib.h> // https://github.com/jcw/jeelib
#include "pins_arduino.h"
#include <avr/sleep.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// PIN-Konfiguration 
//------------------------------------------------------------------------------
// SENSOR pins
#define ONE_WIRE_BUS 8   // DS18B20 Temperature sensor is connected on D10/ATtiny pin 13
#define ONE_WIRE_POWER 7  // DS18B20 Power pin is connected on D9/ATtiny pin 12
// LED pin
#define LEDpin 3          // D8, PA2 (ATtiny pin 11) - set to 0 to disable LED
#define SENDDELAY 1000
//------------------------------------------------------------------------------
/*
                    +-\/-+
              VCC  1|    |14  GND
         (D0) PB0  2|    |13  AREF (D10)
         (D1) PB1  3|    |12  PA1 (D9)
            RESET  4|    |11  PA2 (D8)
INT0  PWM (D2) PB2  5|    |10  PA3 (D7)
     PWM (D3) PA7  6|    |9   PA4 (D6)
     PWM (D4) PA6  7|    |8   PA5 (D5) PWM
                    +----+
*/

//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start encrypting
// - to stop encrypting call .Encrypt(NULL)
//#define KEY   "ABCDABCDABCDABCD"

//------------------------------------------------------------------------------

// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
DeviceAddress addr;

// Temperatur-String zum Versand per 433 Mhz
char msg[5];

//################################################################################â€########################################


// blink led
static void blink (byte pin, byte n = 3) {
 if (LEDpin) {
   pinMode(pin, OUTPUT);
   for (byte i = 0; i < 2 * n; ++i) {
     delay(100);
     digitalWrite(pin, !digitalRead(pin));
   }
 }
}

//--------------------------------------------------------------------------------------------------
// Read current supply voltage
//--------------------------------------------------------------------------------------------------
long readVcc() {
  bitClear(PRR, PRADC);
  ADCSRA |= bit(ADEN); // Enable the ADC
  long result;
  // Read 1.1V reference against Vcc
  #if defined(__AVR_ATtiny84__)
    ADMUX = _BV(MUX5) | _BV(MUX0); // For ATtiny84
  #else
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // For ATmega328
  #endif
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate Vcc in mV
  ADCSRA &= ~ bit(ADEN);
  bitSet(PRR, PRADC); // Disable the ADC to save power
  return result;
}

void setup() {
Serial.begin(38400);
PRR = bit(PRTIM1);          // only keep timer 0 going
ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
pinMode(ONE_WIRE_POWER, OUTPUT); // set power pin for DS18B20 to output
digitalWrite(ONE_WIRE_POWER, HIGH); // turn DS18B20 sensor on

delay(50); // Allow 50ms for the sensor to be ready
}

void loop() {


// Start up the library
sensors.begin();
sensors.requestTemperatures(); // Send the command to get temperatures  
int i=0;
int j=sensors.getDeviceCount();
for (uint8_t s=0; s < sensors.getDeviceCount(); s++) {
    // get the unique address 
    Serial.print(sensors.getAddress(addr, s));
    // just look at bottom two bytes, which is pretty likely to be unique
    int smalladdr = (addr[6] << 8) | addr[7];
    
    //Serial.print("#"); Serial.print(s); 
    Serial.print("ID:"); Serial.print(j);
    Serial.print("=");
    Serial.print(sensors.getTempCByIndex(i));  
    Serial.print(",");
    i++;
  }
i=0;
//digitalWrite(ONE_WIRE_POWER, LOW); // turn Sensor off to save power
//pinMode(ONE_WIRE_POWER, INPUT); // set power pin for Sensor to input before sleeping, saves power

float supplyV = readVcc(); // Get supply voltage
float supply = supplyV/1000;
//itoa(supplyV,&msg[strlen(msg)],10);
Serial.println(supply);

if (LEDpin) {
	
   blink(LEDpin, 2); // blink LED
}

delay(SENDDELAY);
}

Hope someone can help me quick. All Temperature reads the same value because of same adress.

What is a MAX3150K?

Please fix the indentation in your code. Just press control-T in the IDE editor.

Thermocouple to 1wire converter!

So... you mean a MAX31**8**50K? -_-

The latest OneWire library is here, and that page points to a good Dallas Temperature library here. Look in the examples subdirectory, also accessible from the IDE File/Examples menu.

How can I get now all Temperatures without using adress. only use unique ROM?

The Address pins don't affect the ROM selection process. The Address pin states are accessible in the CONFIG register, which is byte 4 of the scratchpad memory.

To read the temperature from a specific device, see the "Multiple" example:

      float tempC = sensors.getTempC( deviceAddress );

deviceAddress is the ROM serial number (an address), not the 4 Address pins on the MAX31850K.

Cheers,
/dev

I have done this but all devices with different ROM Have the same temperature but only one Thermocouple is connected. That is the Problem! hmm
I do not understand why. I get different ROM addresses, but all send me the same Temperature.
If i test my script with one ROM that is not correct it writes wrong device. So the CODE should be ok!

I defined it like this

DeviceAddress Max1 = { 0x3B, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };

then

float tempC = sensors.getTempC(Max1);

but all ROMs that I test shows the same Temperature. What is wrong with me :slight_smile:

Fixed it,

works great was a mistake in the hardware wire routing.

Thanks a bunch