converting from Arduino to Z-UNO simple code help needed

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

converting from Arduino to Z-UNO simple code help needed

Post by Black Cat »

Hello from a frustrated Z-UNO user.

I have a simple Switch and Relay example from My Sensors site that will not compile in Z-UNO.

Can anyone please help in converting this from Arduino to Z-UNO, apart from deleting the Radio, I'm lost concerning libraries required etc.

Code: Select all

 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each
 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
 * network topology allowing messages to be routed to nodes.
 *
 * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
 *
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 *******************************
 *
 * REVISION HISTORY
 * Version 1.0 - Henrik Ekblad
 * 
 * DESCRIPTION
 * Example sketch for a "light switch" where you can control light or something 
 * else from both HA controller and a local physical button 
 * (connected between digital pin 3 and GND).
 * This node also works as a repeader for other nodes
 * http://www.mysensors.org/build/relay
 */ 

// Enable debug prints to serial monitor
#define MY_DEBUG 

// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69

// Enabled repeater feature for this node
#define MY_REPEATER_FEATURE

#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>

#define RELAY_PIN  4  // Arduino Digital I/O pin number for relay 
#define BUTTON_PIN  3  // Arduino Digital I/O pin number for button 
#define CHILD_ID 1   // Id of the sensor child
#define RELAY_ON 1
#define RELAY_OFF 0

Bounce debouncer = Bounce(); 
int oldValue=0;
bool state;

MyMessage msg(CHILD_ID,V_LIGHT);

void setup()  
{  
  // Setup the button
  pinMode(BUTTON_PIN,INPUT);
  // Activate internal pull-up
  digitalWrite(BUTTON_PIN,HIGH);
  
  // After setting up the button, setup debouncer
  debouncer.attach(BUTTON_PIN);
  debouncer.interval(5);

  // Make sure relays are off when starting up
  digitalWrite(RELAY_PIN, RELAY_OFF);
  // Then set relay pins in output mode
  pinMode(RELAY_PIN, OUTPUT);   
      
  // Set relay to last known state (using eeprom storage) 
  state = loadState(CHILD_ID);
  digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
}

void presentation()  {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Relay & Button", "1.0");

  // Register all sensors to gw (they will be created as child devices)
  present(CHILD_ID, S_LIGHT);
}

/*
*  Example on how to asynchronously check for new messages from gw
*/
void loop() 
{
  debouncer.update();
  // Get the update value
  int value = debouncer.read();
  if (value != oldValue && value==0) {
      send(msg.set(state?false:true), true); // Send new state and request ack back
  }
  oldValue = value;
} 
 
void receive(const MyMessage &message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.isAck()) {
     Serial.println("This is an ack from gateway");
  }

  if (message.type == V_LIGHT) {
     // Change relay state
     state = message.getBool();
     digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
     // Store state in eeprom
     saveState(CHILD_ID, state);
    
     // Write some debug info
     Serial.print("Incoming change for sensor:");
     Serial.print(message.sensor);
     Serial.print(", New status: ");
     Serial.println(message.getBool());
   } 
}

User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: converting from Arduino to Z-UNO simple code help needed

Post by PoltoS »

MySensors.h and Bounce2.h are missing, so it is impossible to tell you more. They will also certainly require some .cpp files with same name
A.Harrenberg
Posts: 201
Joined: 05 Sep 2016 22:27

Re: converting from Arduino to Z-UNO simple code help needed

Post by A.Harrenberg »

Hi,

if you only want to have a switch / relay working, why not using directly the examples from Z-Uno? You will need to setup the Z-Uno specific functions anyhow...

Regards,
Andreas.
fhem.de - ZWave development support
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: converting from Arduino to Z-UNO simple code help needed

Post by Black Cat »

Thanks for the reply, see my questions and sample code in other post.

I will return to this project once I have the 4 channel switch & relay working.
A.Harrenberg
Posts: 201
Joined: 05 Sep 2016 22:27

Re: converting from Arduino to Z-UNO simple code help needed

Post by A.Harrenberg »

Hi,

what other post? The initial post in this thread?
Maybe it is easier if you explain what you want to achieve instead of trying to convert some code from Arduino.

Regards,
Andreas.
fhem.de - ZWave development support
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: converting from Arduino to Z-UNO simple code help needed

Post by Black Cat »

viewtopic.php?f=3427&t=25083#p69265

As for achievement, a 16 channel Irrigation controller is the aim, but I need to develop it step by step, starting from a 2 channel rely & switch.

The code at the beginning could be similar to what is needed.
Post Reply