220V relay problem

#1

Hi ! I tried to control my 220v relay that it’ll be ON during X seconds and OFF Y seconds. I already figure out how to do this switch between ON and OFF by using square-wave and time-to-duty but just with a LED because when I try with my relay this doesn’t work. I figure out that my relay doesn’t just work with True and False boolean, when it’s True it’s ON but when the signal change to False it’s still ON until the signal change to True again. I don’t found how to deal with that in order to have the same switch as my LED ( in my case 10sec ON 2sec OFF )

#2

D0-D1 are used by the serial port, if you are using debug this will not work, if so try another port.
For example D13 and connect the relay there to do the test.

1 Like
#3

Hi ! Thanks for you help, I’m not using debug so this wasn’t the problem.
After a long time and lots of tests I found this program and it’s working properly !
Finally I just need something that make a boolean signal that, instead of just send True or False, send True-False-True and False-True-False at specifics interval.
Do you know how can I connect this to internet (I’ve got a NodeMCU ESP8266) in order to control the times’ intervals or via a simple android application ?


Or do you know how to use buttons or encoder to navigate into a menu on LCD and change these values ?

#4

The “easiest” solution is probably to use two pots fed to map nodes to map 0-1 to the range you want for your numbers. For example, if you want 0-10 min for Toff, map 0-1 to 0-10. If Ton should be 1-24 hours, you might map 0-1 to 1-24, then multiply by 60 to convert to minutes. LCD could be used to display current Ton & Toff values. Note that by default, this configuration would allow 2.23 hours/minutes; you can force to an integer if that is preferred.

An alternative would be to use 4 buttons (or two encoders) to increase or decrease each number, but you will probably want extra code to restrict the range of each number. There are other alternatives, like a button to select which number to change, then pot to make the change (a very trivial “menu”). The “best” solution depends on what you have available and how you want it to work. With just two values to change, you need almost as many inputs to use a menu as just controlling directly. If you had many options to change, it would require too many pins to update each directly and a menu makes more sense.

Note that if you are using some sort of menu to determine which value to change, buttons or encoder would work better than a pot. The pot will have a set value based on its position, so the value you select to change will jump to whatever value the pot is set to rather than just being able to adjust its current value. 2 buttons or an encoder would allow you to adjust from current value.

To implement a menu, you would need buffers to store each value and a way to select which buffer to update while making adjustments. Here is one solution (which needs if-else(boolean) created in order to work):
image

It uses gweimer/utils/queue-buffer to create a fixed-depth stack. Initially no items are selected. The “or” feeding MENU bus determines if any items are selected; if yes, push false onto the stack; else push true onto the stack to select the 1st item. Each time the button is pushed, it pushes items down the stack to select the next item, so that only one element of the stack is true at any time. Pushing the button when the last item is true pushes true off the stack so that no items are selected and the process repeats.

An element on the stack being true allows buffer for that value to be update and adds a “>” in front of the display for that item so you know which one is selected.

If you want to use encoder/buttons to adjust the current number, things get considerably more complicated…

Not sure it will work, but here is an attempt to use buttons for incr/decr of selected value:
image

And apparently Ctrl-R in XOD reloads your workspace without asking if you want to save any changes, and I’ve already put too much time into this…

3 Likes
#5

Thank you, I’ll try that ! It’s look great ! :grinning:
I didn’t know what was the buffer use to. It seems to be a good way.

#6

Hi @gweimer , I tried your solution but I’ve an error message about the if-else(boolean)
Cannot find specialization if-else(boolean) for abstract xod/core/if-else.
Do I need to install a special library for this if-else(boolean) ?

#7

I think the latest release of XOD 0.29.1 that just came out fixes this for you. if-else is now generic instead of abstract.

1 Like
#8

I installed the lastest version XOD 0.29.1 and I have the same error message. I saw a topic that you have created about if-else(boolean) but I didn’t understand what can we do to create this new node. If it’s possible.

#9

Perhaps you have a local fork of the now-obsolete 0.29.0 xod/core. Take a look at $HOME/xod/__lib__. Do you see xod directory here? If so, delete it and restart the IDE.

1 Like
#10

In $HOME/xod/lib I have a file xod in which there is the library i2c. Should I delete this one and restart ? And should I reinstal i2c library after ?

#11

It worked better but durring the deployment I had a new error.

Compilation failed
Command C:\Users\Loan\AppData\Local\Programs\XOD IDE\resources\arduino-cli.exe --config-file=C:\Users\Loan\AppData\Local\Temp\arduino-cli48pUHk\.cli-config.yml compile --fqbn arduino:avr:uno --verbose C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556041835168_sketch failed with code 1
The generated C++ code contains errors. It can be due to a bad node implementation or if your board is not compatible with XOD runtime code. The original compiler error message is above. Fix C++ errors to continue. If you believe it is a bug, report the problem to XOD developers.

I deleted the xod file where you said.

#12

You need to scroll up to get the actual compile error

#13

I don’t know where to look to find the error. I’m new on XOD. So I copy/paste all the message.

Begin compiling code for the board Arduino/Genuino Uno :package:

Using board ‘uno’ from platform in folder: C:\Users\Loan\xod_packages_\packages\arduino\hardware\avr\1.6.21
Using core ‘arduino’ from platform in folder: C:\Users\Loan\xod_packages_\packages\arduino\hardware\avr\1.6.21

Detecting libraries used…

“C:\Users\Loan\xod\packages\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\cores\arduino” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\variants\standard” “C:\Users\Loan\AppData\Local\Temp\arduino-sketch-D05D71D5E7B02EB5A8200E0E756A94C0\sketch\xod_1556044093609_sketch.ino.cpp” -o nul

Alternatives for Wire.h: [Wire@1.0]
ResolveLibrary(Wire.h)
-> candidates: [Wire@1.0]

“C:\Users\Loan\xod\packages\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\cores\arduino” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\variants\standard” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src” “C:\Users\Loan\AppData\Local\Temp\arduino-sketch-D05D71D5E7B02EB5A8200E0E756A94C0\sketch\xod_1556044093609_sketch.ino.cpp” -o nul

Alternatives for LiquidCrystal_I2C.h: [LiquidCrystal_I2C]
ResolveLibrary(LiquidCrystal_I2C.h)
-> candidates: [LiquidCrystal_I2C]

“C:\Users\Loan\xod\packages\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\cores\arduino” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\variants\standard” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src” “-IC:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\libraries\LiquidCrystal_I2C” “C:\Users\Loan\AppData\Local\Temp\arduino-sketch-D05D71D5E7B02EB5A8200E0E756A94C0\sketch\xod_1556044093609_sketch.ino.cpp” -o nul

“C:\Users\Loan\xod\packages\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\cores\arduino” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\variants\standard” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src” “-IC:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\libraries\LiquidCrystal_I2C” “C:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\Wire.cpp” -o nul

“C:\Users\Loan\xod\packages\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\cores\arduino” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\variants\standard” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src” “-IC:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\libraries\LiquidCrystal_I2C” “C:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src\utility\twi.c” -o nul

“C:\Users\Loan\xod\packages\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\cores\arduino” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\variants\standard” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src” “-IC:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\libraries\LiquidCrystal_I2C” “C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp” -o nul

Generating function prototypes…

“C:\Users\Loan\xod\packages\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\cores\arduino” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\variants\standard” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src” “-IC:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\libraries\LiquidCrystal_I2C” “C:\Users\Loan\AppData\Local\Temp\arduino-sketch-D05D71D5E7B02EB5A8200E0E756A94C0\sketch\xod_1556044093609_sketch.ino.cpp” -o “C:\Users\Loan\AppData\Local\Temp\arduino-sketch-D05D71D5E7B02EB5A8200E0E756A94C0\preproc\ctags_target_for_gcc_minus_e.cpp”

“C:\Users\Loan\xod\packages\packages\builtin\tools\ctags\5.8-arduino11/ctags” -u --language-force=c++ -f - --c+±kinds=svpf --fields=KSTtzns --line-directives “C:\Users\Loan\AppData\Local\Temp\arduino-sketch-D05D71D5E7B02EB5A8200E0E756A94C0\preproc\ctags_target_for_gcc_minus_e.cpp”

Compiling sketch…

“C:\Users\Loan\xod\packages\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\cores\arduino” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\variants\standard” “-IC:\Users\Loan\xod\packages\packages\arduino\hardware\avr\1.6.21\libraries\Wire\src” “-IC:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\libraries\LiquidCrystal_I2C” “C:\Users\Loan\AppData\Local\Temp\arduino-sketch-D05D71D5E7B02EB5A8200E0E756A94C0\sketch\xod_1556044093609_sketch.ino.cpp” -o “C:\Users\Loan\AppData\Local\Temp\arduino-sketch-D05D71D5E7B02EB5A8200E0E756A94C0\sketch\xod_1556044093609_sketch.ino.cpp.o”

C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino: In function ‘void xod::____if_else__boolean::evaluate(xod::____if_else__boolean::Context)’:
C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino:2760:15: error: ‘output_R’ was not declared in this scope
emitValue<output_R>(ctx, cond ? trueVal : falseVal);
^
C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino:2760:15: note: suggested alternatives:
C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino:1694:8: note: ‘xod::xod__core__if_else__string::output_R’
struct output_R { };
^

C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino:2271:8: note: ‘xod::xod__core__if_else__number::output_R’
struct output_R { };
^
C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino:2760:55: error: no matching function for call to ‘emitValue(xod::____if_else__boolean::ContextObject*&, bool&)’
emitValue<output_R>(ctx, cond ? trueVal : falseVal);
^
C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino:2760:55: note: candidate is:
C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino:2742:33: note: template void xod::____if_else__boolean::emitValue(xod::____if_else__boolean::Context, typename xod::____if_else__boolean::ValueType::T)
template void emitValue(Context ctx, typename ValueType::T val) {
^
C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino:2742:33: note: template argument deduction/substitution failed:
C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch\xod_1556044093609_sketch.ino:2760:55: error: template argument 1 is invalid
emitValue<output_R>(ctx, cond ? trueVal : falseVal);
^

Multiple libraries were found for “Wire.h”
Used: C:\Users\Loan\xod_packages_\packages\arduino\hardware\avr\1.6.21\libraries\Wire
Multiple libraries were found for “LiquidCrystal_I2C.h”
Used: C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\libraries\LiquidCrystal_I2C

Using library Wire at version 1.0 in folder: C:\Users\Loan\xod_packages_\packages\arduino\hardware\avr\1.6.21\libraries\Wire
Using library LiquidCrystal_I2C in folder: C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\libraries\LiquidCrystal_I2C (legacy)

Error: exit status 1
Compilation failed.
Compilation failed
Command C:\Users\Loan\AppData\Local\Programs\XOD IDE\resources\arduino-cli.exe --config-file=C:\Users\Loan\AppData\Local\Temp\arduino-cli48pUHk\.cli-config.yml compile --fqbn arduino:avr:uno --verbose C:\Users\Loan\AppData\Local\Temp\xod_temp_sketchbookbMGit0\xod_1556044093609_sketch failed with code 1
The generated C++ code contains errors. It can be due to a bad node implementation or if your board is not compatible with XOD runtime code. The original compiler error message is above. Fix C++ errors to continue. If you believe it is a bug, report the problem to XOD developers.

#14

This is the 1st error message. It indicates the output pin “R” doesn’t exist for if-else node. I just noticed that the latest version did NOT change if-else. Did you create your own if-else(boolean) node and change the T/F/R pins to be boolean? If so, you need to name the new pins the same as the old.

#15

No I didn’t create if-else(boolean) node yet. I’m trying to isolate and when I put the select node with on the intput something boolean it’s the same, I had an error during the deployment. Do you think it can be that ? I’m just a beginer so I’m not really good I’m just trying to make thing simple to understand all the steps.


I’ll try to make my own if-else(boolean) now ! I just need to copy the if-else(number), and then change hte T/F/R by input(boolean) and output(boolean) ?

#16

Why we need a if-else(boolean) ? because, if I’m right (and I’m not sure :sweat_smile:), we want " >" to pass through if the MEM of the queue buffer is True and nothing if it’s not. So we don’t need a node like that ?
Capture1
I’m sorry if I’m mistaken.

#17

Yes. Pins are all that need to change. The C++ code will work auto-magically with new types.

1 Like
#18

It’s working ! But instead of > it’s True and False that change before Val1 and Val2 .
And when I push the menu-button after entering a new value for Val1, the Val2 is updated with the same value as Val1. I think it’s not so difficult to fix :wink:

#19

If-else(boolean) is only needed because queue-buffer uses select, which uses if-else and we are using queue-buffer to store boolean values.

#20

So I’ve to replace if-else which is in the node select in queue-buffer ? Or the one that is between the queue-buffer and the concat ? With this second choice it works !