Emulated Onewire DS18b20, unable to be read by Teltonika FM1110 device

i work arduino library <> #include <OneWireSlave.h>

I want to do -programs how to make substitute for DS18b20

Which sened to teltonika Degrees;

mycode not work :confused:

#include "Arduino.h"
#include "LowLevel.h"
#include "OneWireSlave.h"



// Defines to access to Low and High bytes
#define Lo(x)   ((x) & 0xFF) 
#define Hi(x)   (((x)>>8) & 0xFF) 

// This is the pin that will be used for one-wire data (depending on your arduino model, you are limited to a few choices, because some pins don't have complete interrupt support)
// On Arduino Uno, you can use pin 2 or pin 3
Pin oneWireData(2);

// This is the ROM the arduino will respond to, make sure it doesn't conflict with another device, 0x28 - DS18B20 identificator
const byte owROM[] = {0x28, 0xF2, 0x27, 0xD6, 0x04, 0x00, 0x00, 0x3D};

// 0 - Low Byte Temperature 
// 1 - High Byte Temperature
// 2-7 - reserved
// 8 - CRC8
byte SCRATCHPAD[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x00};

// This function will be called each time the OneWire library has an event to notify (reset, error, byte received)
void owReceive(OneWireSlave::ReceiveEvent evt, byte data);

void setup() {
	// Setup the OneWire library
	//OneWire.setReceiveCallback(&owReceive);
	//OneWire.begin(owROM, oneWireData.getPinNumber());
}

void loop() {
	delay(100);  
  int temperature = 25;
  
  // Add temperature to the SCRATCHPAD
  if (temperature > 99)  temperature = 99;
  if (temperature < -55) temperature = -55;
  if (temperature >= 0) {
    SCRATCHPAD[0] = Lo(temperature*16);
    SCRATCHPAD[1] = Hi(temperature*16);
  } 
  else {
    SCRATCHPAD[0] = Lo(temperature*16);
    SCRATCHPAD[1] = Hi(temperature*16) | 0xF8;
  }
  // Add CRC8 to the SCRATCHPAD
 // SCRATCHPAD[8] = OneWire.crc8(SCRATCHPAD,8);
  
	cli();//disable interrupts

	sei();//enable interrupts
}

void owReceive(OneWireSlave::ReceiveEvent evt, byte data) {
	switch (evt) {
    case OneWireSlave::RE_Reset:
      break;
    case OneWireSlave::RE_Byte:
      // Read Scratchpad [BEh] command
      if (data == 0xBE) {
        // Send SCRATCHPAD 9 byte with temperature and CRC
        for (byte i = 8, j = 1; j<=9; i--, j++) {
        //  OneWire.write(&SCRATCHPAD[i],j, NULL);
          //Serial.print(5);
        }
      }
      break;
    case OneWireSlave::RE_Error:
		  break;
	  default:
		;
	}
}

This question has been asked before. Did you search for "Teltonika DS18B20" in the upper right of this page? If you had, you would have found this lengthy discussion, and this recent library.

Summary: you must have an Oscilloscope (best with 2 channels) or a Logic Analyzer (minimum).

You can buy one that's very cheap ($10) or very good ($300 or more). Because most people don't have a Teltonika device, you will have to do most of your own debugging OR you have to be able to capture data about its behaviour with an Oscilloscope or Logic Analyzer. Then we can look at the data and make suggestions.

If you don't have the right equipment, it's almost impossible to emulate the DS18B20 in a way that the Teltonika will accept. One critical signal lasts only 1us-3us, which is almost too short to detect. There are ways to do it, but you will need a 'scope or LA to verify and debug your sketch.

Oh, and you should memorize the DS18B20 spec sheet. :wink:

cheers,
/dev