Help with my First Project

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
kartono
Posts: 6
Joined: 09 Mar 2018 08:59

Help with my First Project

Post by kartono »

Hi All,

Starting my first project with the Z-Uno :D :D

Im trying to get 4 outputs to drive 5v relays and i would like to monitor the current from each

Plan to use 30A current sensor with a output ratio on 66mV/a

Im a bit stuck on the current input of the sketch

Thanks for any help with this

/*
*
* 4 Relays, 4 current inputs
* Off - HIGH
* On - LOW
*/

// Pins definitions
#define LedPin1 9
#define LedPin2 10
#define LedPin3 11
#define LedPin4 12
#define AmpPin1 A0
#define AmpPin2 A1
#define AmpPin3 A2
#define AmpPin4 A3


// Global variables to store data reported via getters
byte switchValue1 = 0;
byte switchValue2 = 0;
byte switchValue3 = 0;
byte switchValue4 = 0;


ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);

// Set up 10 channels
ZUNO_SETUP_CHANNELS(
ZUNO_SWITCH_BINARY(getterSwitch1, setterSwitch1),
ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2),
ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch3),
ZUNO_SWITCH_BINARY(getterSwitch4, setterSwitch4),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp1),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp2),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp3),
ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp4)
);

void setup() {
// set up I/O pins. Analog and PWM will be automatically set up on analogRead/analogWrite functions call
pinMode(LedPin1, OUTPUT);
pinMode(LedPin2, OUTPUT);
pinMode(LedPin3, OUTPUT);
pinMode(LedPin4, OUTPUT);
}

void loop() {
int Amp1; // variable to store the value read
val = analogRead(A0); // read the input pin
Serial.println(Amp1); // debug output
}

// Getters and setters

void setterSwitch1(byte value) {
digitalWrite(LedPin1, (value > 0) ? LOW : HIGH);
switchValue1 = value;
}

byte getterSwitch1(){
return switchValue1;
}

void setterSwitch2(byte value) {
digitalWrite(LedPin2, (value > 0) ? LOW : HIGH);
switchValue2 = value;
}

byte getterSwitch2(){
return switchValue2;
}

void setterSwitch3(byte value) {
digitalWrite(LedPin3, (value > 0) ? LOW : HIGH);
switchValue3 = value;
}

byte getterSwitch3(){
return switchValue3;
}

void setterSwitch4(byte value) {
digitalWrite(LedPin4, (value > 0) ? LOW : HIGH);
switchValue4 = value;
}

byte getterSwitch4(){
return switchValue4;
}
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Help with my First Project

Post by p0lyg0n1 »

Hi,
What is your main problem? You didn't define getters getterAmp1/getterAmp2/getterAmp3/getterAmp4 as I see. Looks like you can stuck with this https://forum.z-wave.me/viewtopic.php?f ... 6&start=10. We have the issue with ADC when you try to use more then one channel. We add this to roadmap for version 2.1.4. See this https://forum.z-wave.me/viewtopic.php?f=3427&t=26236.
kartono
Posts: 6
Joined: 09 Mar 2018 08:59

Re: Help with my First Project

Post by kartono »

Hi,

Sorry for the noob questions....

But how do i define the getters?

Code: Select all

/* 
 * 
 * 4 Relays, 4 current inputs 
 * Off - HIGH
 * On - LOW
 */

// Pins definitions
#define LedPin1 9
#define LedPin2 10
#define LedPin3 11
#define LedPin4 12
#define AmpPin1 A0

// Global variables to store data reported via getters
byte switchValue1 = 0;
byte switchValue2 = 0;
byte switchValue3 = 0;
byte switchValue4 = 0;


ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);

// Set up 10 channels
ZUNO_SETUP_CHANNELS(
  ZUNO_SWITCH_BINARY(getterSwitch1, setterSwitch1),
  ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2),
  ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch3),
  ZUNO_SWITCH_BINARY(getterSwitch4, setterSwitch4),
  ZUNO_SENSOR_MULTILEVEL_CURRENT(getterAmp1)
);

int Amp1;

void setup() {
  // set up I/O pins. Analog and PWM will be automatically set up on analogRead/analogWrite functions call
  pinMode(LedPin1, OUTPUT);
  pinMode(LedPin2, OUTPUT);
  pinMode(LedPin3, OUTPUT);
  pinMode(LedPin4, OUTPUT);
  Serial.begin();
  Serial.println("start");
}

void loop() {
 int Amp1;               // variable to store the value read
  Amp1 = analogRead(A0);  // read the input pin
  Serial.println(Amp1);   // debug output
  zunoSendReport(1);
  delay(30000);
}

// Getters and setters

void setterSwitch1(byte value) {
  digitalWrite(LedPin1, (value > 0) ? LOW : HIGH);
  switchValue1 = value;
}

byte getterSwitch1(){
  return switchValue1;
}

 void setterSwitch2(byte value) {
  digitalWrite(LedPin2, (value > 0) ? LOW : HIGH);
  switchValue2 = value;
}

byte getterSwitch2(){
  return switchValue2;
}

void setterSwitch3(byte value) {
  digitalWrite(LedPin3, (value > 0) ? LOW : HIGH);
  switchValue3 = value;
}

byte getterSwitch3(){
  return switchValue3;
}

void setterSwitch4(byte value) {
  digitalWrite(LedPin4, (value > 0) ? LOW : HIGH);
  switchValue4 = value;
}

byte getterSwitch4(){
  return switchValue4;
}

int analogRead(A0){
  int val;

  val = analogRead(A0)
  current = Val/0.66
  return current;
}

word getterApm1(){
  return current;
}
so very new at this... thanks for all the help :D
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Help with my First Project

Post by PoltoS »

If you are very new, I would suggest to start first with a simple code: one switch and one meter and then extend it. Just easier to learn.

Also have a look on our quick start guide: https://z-uno.z-wave.me/QSG
Post Reply