Skip to content

Loxone and Wemos D1 #65

@gahujipo

Description

@gahujipo

I tried to emulate a DS2438 on a Wemos D1 and find the "sensor" with Loxone. The Wemos D1 has only 3,3V pins so I used a level shifter to rise the signal to 5V. But it couldn't be found.

My wiring scheme is this:
1wire-scheme

My current code is this

#include "OneWireHub.h"
#include "DS2438.h"

constexpr uint8_t pin_led{LED_BUILTIN};
constexpr uint8_t pin_onewire{0}; // Arduino D3

auto hub = OneWireHub(pin_onewire);
auto ds2438 = DS2438(DS2438::family_code, 0x00, 0x00, 0x38, 0x24, 0xDA, 0x00); // todo what hex code for serial number

// the setup function runs once when you press reset or power the board
void setup()
{
	Serial.begin(115200);
	Serial.println("OneWire-Hub DS2438 BME680");

	pinMode(pin_led, OUTPUT);

	// Setup OneWire
	hub.attach(ds2438);

	Serial.print("Test: set Temperature in float 38 deg C: ");
	ds2438.setTemperature(38.0f);  // can vary from -55 to 125deg
	Serial.println(ds2438.getTemperature());
}

// the loop function runs over and over again until power down or reset
void loop()
{
	// following function must be called periodically
	hub.poll();

	// Blink triggers the state-change
	if (blinking())
	{
		static float    temp = 10.0;
		static uint16_t volt_10mV = 10;
		static uint16_t current = 10;

		if ((temp += 0.05) > 30.0) temp = 10.0;
		if ((volt_10mV++) > 200) volt_10mV = 10;
		if ((current++)   > 200) current = 10;

		ds2438.setTemperature(temp);
		ds2438.setVoltage(volt_10mV);
		ds2438.setCurrent(current);

		Serial.println(temp);
	}
}

bool blinking(void)
{
	const  uint32_t interval = 2000;          // 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;
}

Is this correct or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions