Go Down

Topic: Velleman K8056 8-channel relaycard library (Read 889 times) previous topic - next topic

Alban

Hi,

Last evening I finalized my first real library  :)
I wanted to control my Velleman K8056 relaycard with RS232 commands, using only 1 wire  :P

Feel free to comment me and advise me for better/cleaner programming:

http://www.reptile-addict.nl/arduino/?page_id=209

I wanted to put this on the playground but havn't got a clue on how to get it there  :smiley-red:
Best regards,

Alban

P.S. sorry for asking silly questions... I'm a mechanical engineer and not an electronics engineer ;)


www.reptile-addict.nl

Erdin

#1
Apr 21, 2013, 06:58 pm Last Edit: Apr 21, 2013, 07:11 pm by Erdin Reason: 1
http://playground.arduino.cc//Main/Participate

You can make an entry in the Relays section.
http://playground.arduino.cc//Main/InterfacingWithHardware#Output
search for relays.
If you add [[Code/VellemanK8056]] and save it, you can go the link and open that page and fill it.
I'm not sure about the "Code" section. If you don't use the "Code" section, the page will be made in the "Main" section.

Will the library compile with Uno selected ? I'm not sure about the Serial1, Serial2, Serial3.

Why not call the function "On", instead of Relais_ON ?
If the class would be called "Relay", it would be called with Relay.Relay_ON().

You could follow the digitalWrite(pin,HIGH/LOW) function, and use a parameter for On and Off: set( relay, HIGH=on/LOW=off)

Most Arduino functions use "begin()", instead of "Initialize()".

Why did you use real 'tabs' ? I thought that the Arduino IDE uses spaces as tabs.

Why did you use a switch() statement in RS232Instruction().
Would this do it: Relay = RelaisNr + '0';

What is the "switch (SerialID)" doing ? Every case is the same code.

Alban

#2
Apr 22, 2013, 05:35 am Last Edit: Apr 22, 2013, 04:27 pm by Alban Reason: 1
Quote
Will the library compile with Uno selected ? I'm not sure about the Serial1, Serial2, Serial3.

Yes, Serial1, Serial2 and Serial3 are only available when an Arduino MEGA2560 is selected:
Code: [Select]
#if defined(__AVR_ATmega2560__)
switch (SerialAddress) {
case 0:
Serial.begin(BaudRate);
SerialID=0;
break;
case 1:
Serial1.begin(BaudRate);
SerialID=1;
break;
case 2:
Serial2.begin(BaudRate);
SerialID=2;
break;
case 3:
Serial3.begin(BaudRate);
SerialID=3;
break;
default:
Serial.begin(BaudRate);
SerialID=0;
break;
}
#else
Serial.begin(2400);
SerialID=0;
#endif

For all other boards Serial.begin is used.

Quote
Why not call the function "On", instead of Relais_ON ?
If the class would be called "Relay", it would be called with Relay.Relay_ON().

Well, that just didn't occur to me  :P I'll change that in a next version. => DONE

Quote
You could follow the digitalWrite(pin,HIGH/LOW) function, and use a parameter for On and Off: set( relay, HIGH=on/LOW=off)

Good idea... => added Set function

Quote
Most Arduino functions use "begin()", instead of "Initialize()".

hmmm, that is true. Init or initialize is something I usually use, but for standarisation begin would be more intuative. => DONE

Quote
Why did you use real 'tabs' ? I thought that the Arduino IDE uses spaces as tabs.

tabs, I love tabs :) I use VisualMicro in VisualStudio 2010 to do both my Arduino coding as other programming languages. I'm used to use tabs.. Guilty as charged :)


Quote
Why did you use a switch() statement in RS232Instruction().
Would this do it: Relay = RelaisNr + '0';

I never realized or tried if that would work. I'll give it a shot :)

Quote
What is the "switch (SerialID)" doing ? Every case is the same code.

No it is not :p If SerialID is set to 3 => Serial3.write etc.. Was the easiest way I could think of to be able to use multiple Serial ports on my MEGA


I also moved the CardAddress from begin to the seperate functions because up to 255 cards could be connected.


Best regards,

Alban

P.S. sorry for asking silly questions... I'm a mechanical engineer and not an electronics engineer ;)


www.reptile-addict.nl

Erdin


Quote
What is the "switch (SerialID)" doing ? Every case is the same code.

No it is not :p If SerialID is set to 3 => Serial3.write etc.. Was the easiest way I could think of to be able to use multiple Serial ports on my MEGA


I see, they are not the same.

The Leonardo and Micro have two serial ports, "Serial" and "Serial1". Could you add that ?

Alban

#4
Apr 22, 2013, 03:08 pm Last Edit: Apr 22, 2013, 04:59 pm by Alban Reason: 1
Quote
The Leonardo and Micro have two serial ports, "Serial" and "Serial1". Could you add that ?

I added the old Mega1280 to the list it is similar to the 2560.

If I understand correctly, the Leonardo and the Micro have 2 serial ports:
Quote
Note that on the Micro, the Serial class refers to USB (CDC) communication; for TTL serial on pins 0 and 1, use the Serial1 class.

So actually for my purpose there is only one correct way: Serial1. The other Serial is only accessible thru USB??
COuld anyone enlighten me on the syntax to conditional compile for those 2 boards?
I guess I could do:
Code: [Select]
#ELIF defined(__AVR_xxxxx__)


Added support for Leonardo and Micro.
Best regards,

Alban

P.S. sorry for asking silly questions... I'm a mechanical engineer and not an electronics engineer ;)


www.reptile-addict.nl

Erdin

I didn't think of that. You are right, the pins on the Leonardo board are only Serial1. The "Serial" is the software serial port via usb and can not be used with hardware.

The define for Leonardo and Micro is __AVR_ATmega32U4__

Alban

#6
Apr 23, 2013, 01:07 pm Last Edit: Apr 29, 2013, 01:34 pm by Alban Reason: 1
new version is online

Added to the playground
Best regards,

Alban

P.S. sorry for asking silly questions... I'm a mechanical engineer and not an electronics engineer ;)


www.reptile-addict.nl

Go Up