Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DS18B20 sends wrong family code and wrong ROM #51

Open
katfreak2 opened this issue Feb 5, 2018 · 0 comments
Open

DS18B20 sends wrong family code and wrong ROM #51

katfreak2 opened this issue Feb 5, 2018 · 0 comments

Comments

@katfreak2
Copy link

Hi,

I used a atmega1284 to create a DS18B20 thermometer. The thermometer is working fine but when the search command(0x0F) is send my familiy code and ROM is totally different as when the match command (0x55) is send. Does someone know what the problem is here?

match
search

I used the example to emulate the DS18B20.

/*

#include "OneWireHub.h"
#include "DS18B20.h" // Digital Thermometer, 12bit

#include <SoftwareSerial.h>

constexpr uint8_t pin_led { 5 };
constexpr uint8_t pin_onewire { 3 };

auto hub = OneWireHub(pin_onewire);

auto ds18b20 = DS18B20(DS18B20::family_code, 0x00, 0x00, 0xB2, 0x18, 0xDA, 0x00); // DS18B20: 9-12bit, -55 - +85 degC
//auto ds18s20 = DS18B20(0x10, 0x00, 0x00, 0xA2, 0x18, 0xDA, 0x00); // DS18S20: 9 bit, -55 - +85 degC
//auto ds1822 = DS18B20(0x22, 0x00, 0x00, 0x22, 0x18, 0xDA, 0x00); // DS1822: 9-12bit, -55 - +125 degC

bool blinking(void);

SoftwareSerial mySerial(2, 4); // RX, TX

void setup()
{
mySerial.begin(9600);
mySerial.println("OneWire-Hub DS18B20 Temperature-Sensor");
mySerial.flush();

pinMode(pin_led, OUTPUT);

// Setup OneWire
hub.attach(ds18b20);

}

void loop()
{
ds18b20.scratchpad[2] = 0x96;
ds18b20.scratchpad[3] = 0x81;
// following function must be called periodically
hub.poll();
// this part is just for debugging (USE_mySerial_DEBUG in OneWire.h must be enabled for output)
if (hub.hasError()) hub.printError();

// Blink triggers the state-change
if (blinking())
{
    // Set temp
    static float temperature = 20.0;
    temperature += 0.1;
    if (temperature > 30.0) temperature = 20.0;
    ds18b20.setTemperature(temperature);       
}

}

bool blinking(void)
{
constexpr uint32_t interval = 1000; // interval at which to blink (milliseconds)
static uint32_t nextMillis = millis(); // will store next time LED will updated

if (millis() > nextMillis)
{
    nextMillis += interval;             // save the next time you blinked the LED
    static uint8_t ledState = LOW;      // ledState used to set the LED
    if (ledState == LOW)    ledState = HIGH;
    else                    ledState = LOW;
    digitalWrite(pin_led, ledState);
    return 1;
}
return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant