Difference between revisions of "Blog 14"
(21 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
== The BigRelay board == |
== The BigRelay board == |
||
In this post I will show my scripts for Raspberry Pi and Arduino, where I will let one after another |
In this post I will show my scripts for Raspberry Pi and Arduino, where I will let every relay one after another turn on and off. |
||
This can be a handy script, if you want to give a quick look if all the relays work. |
This can be a handy script, if you want to give a quick look if all the relays work. |
||
Hardware I used for Raspberry Pi: |
Hardware I used for the Raspberry Pi: |
||
*RPi_UI board ([[User Interface]]) |
*[http://www.bitwizard.nl/shop/raspberry-pi-ui-16x2 RPi_UI board] | ([[User Interface]]) |
||
*BigRelay board ([[Relay]]) |
*[http://www.bitwizard.nl/shop/bigrelay BigRelay board] | ([[Relay]]) |
||
Hardware I used for Arduino: |
Hardware I used for the Arduino: |
||
*SPI_LCD board([[LCD]]) |
*[http://www.bitwizard.nl/shop/lcd-interface SPI_LCD board] | ([[LCD]]) |
||
*[http://www.bitwizard.nl/shop/bigrelay BigRelay board] | ([[Relay]]) |
|||
== Raspberry Pi version == |
== Raspberry Pi version == |
||
Line 44: | Line 45: | ||
done |
done |
||
OnTime=1 |
|||
OffTime=0 |
|||
With OnTime and OffTime you can easily change the time of the relay being on or off. In this way you don't have to be searching in the script, where to change it. |
|||
bigrelay="bw_tool -s 50000 -a 9c" |
|||
This is for saying that with 'bigrelay' it has to do a command to the bigrelay. |
|||
trap onexit 1 2 3 15 ERR |
|||
function onexit() { |
|||
$bigrelay -W 10:0:b |
|||
exit |
|||
} |
|||
This is an onexit script, which makes it happen that when you leave the script with ctrl + c or an error that it will directly put all the relays in the off-state. |
|||
function dorelay() { |
|||
$bigrelay -W "$1":01:b |
|||
sleep $OnTime |
|||
$bigrelay -W "$1":00:b |
|||
sleep $OffTime |
|||
Here it will read the turn on and off times, the given relay number and will perform the on/off cycle on that relay. |
|||
while true; do |
|||
for i in `seq 20 25` ; do |
|||
dorelay $i |
|||
done |
|||
done |
|||
Here it will iterate the variable i from 20 to 25 and will run activate the doreplay function on each iteration. |
|||
== Arduino version == |
== Arduino version == |
||
Line 51: | Line 87: | ||
int offms = 500; |
int offms = 500; |
||
int onms = 1000; |
int onms = 1000; |
||
unsigned int s = 0; |
|||
void loop (void) |
void loop (void) |
||
Line 56: | Line 93: | ||
static int num = 0x20; |
static int num = 0x20; |
||
char buf[32]; |
|||
char buf[17]; |
|||
set_var (0x9c, 0x10, 0x00); |
set_var (0x9c, 0x10, 0x00); |
||
Line 64: | Line 100: | ||
delay(onms); |
delay(onms); |
||
if ( |
if (num < 0x25) num++; |
||
else { |
else { |
||
num = 0x20; s++; |
num = 0x20; s++; |
||
} |
} |
||
sprintf (buf, "Times: % |
sprintf (buf, "Times: %u", s); |
||
write_at_lcd (0, 0, buf); |
|||
sprintf (buf, "Relay: %d", num-0x20+1); |
|||
write_at_lcd (0, 1, buf); |
write_at_lcd (0, 1, buf); |
||
Serial.write (buf); |
Serial.write (buf); |
||
Line 75: | Line 113: | ||
} |
} |
||
This is not the full script! I used a script named [http://www.bitwizard.nl/software/ ardemo_lcd.pde], but I only replaced the void loop part. ( |
This is not the full script! I used a script named [http://www.bitwizard.nl/software/ ardemo_lcd.pde], but I only replaced the void loop part. ( That is the part you are seeing on this page )<br> If you want a link to the full script: [http://www.bitwizard.nl/source/BigRelayWiki.ino Click here!] |
||
int offms = 500; |
int offms = 500; |
||
int onms = 1000; |
int onms = 1000; |
||
Here you can set the time in milliseconds how long you the relay to turn on and off. You |
Here you can set the time in milliseconds for how long you the relay to turn on and off. You could also change the numbers in the delay command, but this makes it easier to find. |
||
unsigned int s = 0; |
|||
This will tell the script to start at 0 and to be an unsigned int. An unisgned int can get a larger value than a signed int. |
|||
static int num = 0x20; |
static int num = 0x20; |
||
Line 91: | Line 133: | ||
delay(onms); |
delay(onms); |
||
It says to BigRelay (0x9c) that register 10(0x10) has to be |
It says to BigRelay (0x9c) that register 10(0x10) has to be zero (0x00). |
||
So in other words all the relays on the BigRelay have to be turned off. |
So in other words all the relays on the BigRelay have to be turned off. |
||
( You can also change register 10 into num, and put it under the turn on command. ) |
( You can also change register 10 into num, and put it under the turn on command. ) |
||
Line 97: | Line 139: | ||
offms, onms and num will read the last values that were given to them. So at num when counting up it will become 21. |
offms, onms and num will read the last values that were given to them. So at num when counting up it will become 21. |
||
if ( |
if (num < 0x25) num++; |
||
else { |
else { |
||
num = 0x20; s++; |
num = 0x20; s++; |
||
Line 105: | Line 147: | ||
After it begins again with 20(0x20) I also count up with 1 s, this will be send to the display to say how many times it finished a full round clicking. |
After it begins again with 20(0x20) I also count up with 1 s, this will be send to the display to say how many times it finished a full round clicking. |
||
sprintf (buf, "Times: %u ", s); |
|||
write_at_lcd (0, 0, buf); |
|||
sprintf (buf, "Relay: %d", num-0x20+1); |
|||
⚫ | |||
write_at_lcd (0, 1, buf); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
Here it says to the display to print the text "Times:" ( for showing how many times it did all the relays ) and "relay:" ( for showing which relay is turned on ). |
Here it says to the display to print the text "Times:" ( for showing how many times it did all the relays ) and "relay:" ( for showing which relay is turned on ). |
||
The % |
The %d is for showing it in decimals and %u for showing in unsigned decimals. ( if you do %02d 1 will become 01. ) |
||
"num -0x20+1" counts 20 hexadecimals off num and after that counts 1 up. So, example: 25-20=5+1 = 6. |
|||
( if you count 19 or 21 hexadecimals down you would get a really different result. ) |
|||
[[File:ArduinoBigRelay.jpg|400px|thumb|none|]] |
|||
The green cable of pin 6 is connected with D10 off the arduino, that is needed for the chip select. So you could control multiple devices, like the BigRelay and the LCD. |
|||
== Useful links == |
|||
*Working with a 7FETs Stepper motors [[Blog 15]] |
|||
*Working with multiple 7FETs Stepper motors [[Blog 16]] |
|||
*Example script for working with arduino from BitWizard: [http://www.bitwizard.nl/software/ ardemo_lcd.pde] |
Latest revision as of 11:54, 2 December 2015
The BigRelay board
In this post I will show my scripts for Raspberry Pi and Arduino, where I will let every relay one after another turn on and off. This can be a handy script, if you want to give a quick look if all the relays work.
Hardware I used for the Raspberry Pi:
Hardware I used for the Arduino:
- SPI_LCD board | (LCD)
- BigRelay board | (Relay)
Raspberry Pi version
The script of the bash program:
#!/bin/bash OnTime=1 OffTime=0 bigrelay="bw_tool -s 50000 -a 9c" trap onexit 1 2 3 15 ERR function onexit() { $bigrelay -W 10:0:b exit } function dorelay() { $bigrelay -W "$1":01:b sleep $OnTime $bigrelay -W "$1":00:b sleep $OffTime } while true; do for i in `seq 20 25` ; do dorelay $i done done
OnTime=1 OffTime=0
With OnTime and OffTime you can easily change the time of the relay being on or off. In this way you don't have to be searching in the script, where to change it.
bigrelay="bw_tool -s 50000 -a 9c"
This is for saying that with 'bigrelay' it has to do a command to the bigrelay.
trap onexit 1 2 3 15 ERR function onexit() { $bigrelay -W 10:0:b exit }
This is an onexit script, which makes it happen that when you leave the script with ctrl + c or an error that it will directly put all the relays in the off-state.
function dorelay() { $bigrelay -W "$1":01:b sleep $OnTime $bigrelay -W "$1":00:b sleep $OffTime
Here it will read the turn on and off times, the given relay number and will perform the on/off cycle on that relay.
while true; do for i in `seq 20 25` ; do dorelay $i done done
Here it will iterate the variable i from 20 to 25 and will run activate the doreplay function on each iteration.
Arduino version
The script from the arduino program:
int offms = 500; int onms = 1000; unsigned int s = 0; void loop (void) { static int num = 0x20; char buf[32]; set_var (0x9c, 0x10, 0x00); delay(offms); set_var (0x9c, num, 0x01); delay(onms); if (num < 0x25) num++; else { num = 0x20; s++; } sprintf (buf, "Times: %u", s); write_at_lcd (0, 0, buf); sprintf (buf, "Relay: %d", num-0x20+1); write_at_lcd (0, 1, buf); Serial.write (buf); Serial.write ("\r\n"); }
This is not the full script! I used a script named ardemo_lcd.pde, but I only replaced the void loop part. ( That is the part you are seeing on this page )
If you want a link to the full script: Click here!
int offms = 500; int onms = 1000;
Here you can set the time in milliseconds for how long you the relay to turn on and off. You could also change the numbers in the delay command, but this makes it easier to find.
unsigned int s = 0;
This will tell the script to start at 0 and to be an unsigned int. An unisgned int can get a larger value than a signed int.
static int num = 0x20;
The above line will make it happen that when you upload the code it will directly start with relay 1(0x20).
set_var (0x9c, 0x10, 0x00); delay(offms); set_var (0x9c, num, 0x01); delay(onms);
It says to BigRelay (0x9c) that register 10(0x10) has to be zero (0x00). So in other words all the relays on the BigRelay have to be turned off. ( You can also change register 10 into num, and put it under the turn on command. )
offms, onms and num will read the last values that were given to them. So at num when counting up it will become 21.
if (num < 0x25) num++; else { num = 0x20; s++; }
Here I let num couting up with 1 every time a relay has been activated. After it reached above 25(0x25) it will start over again at 20(0x20). After it begins again with 20(0x20) I also count up with 1 s, this will be send to the display to say how many times it finished a full round clicking.
sprintf (buf, "Times: %u ", s); write_at_lcd (0, 0, buf); sprintf (buf, "Relay: %d", num-0x20+1); write_at_lcd (0, 1, buf); Serial.write (buf); Serial.write ("\r\n");
Here it says to the display to print the text "Times:" ( for showing how many times it did all the relays ) and "relay:" ( for showing which relay is turned on ). The %d is for showing it in decimals and %u for showing in unsigned decimals. ( if you do %02d 1 will become 01. ) "num -0x20+1" counts 20 hexadecimals off num and after that counts 1 up. So, example: 25-20=5+1 = 6. ( if you count 19 or 21 hexadecimals down you would get a really different result. )
The green cable of pin 6 is connected with D10 off the arduino, that is needed for the chip select. So you could control multiple devices, like the BigRelay and the LCD.
Useful links
- Working with a 7FETs Stepper motors Blog 15
- Working with multiple 7FETs Stepper motors Blog 16
- Example script for working with arduino from BitWizard: ardemo_lcd.pde