Difference between revisions of "Blog 14"
(6 intermediate revisions by 2 users not shown) | |||
Line 6: | Line 6: | ||
Hardware I used for the 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 the Arduino: |
Hardware I used for the Arduino: |
||
*SPI_LCD board([[LCD]]) |
*[http://www.bitwizard.nl/shop/lcd-interface SPI_LCD board] | ([[LCD]]) |
||
*BigRelay board ([[Relay]]) |
*[http://www.bitwizard.nl/shop/bigrelay BigRelay board] | ([[Relay]]) |
||
== Raspberry Pi version == |
== Raspberry Pi version == |
||
Line 62: | Line 62: | ||
} |
} |
||
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- |
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() { |
function dorelay() { |
||
Line 70: | Line 70: | ||
sleep $OffTime |
sleep $OffTime |
||
Here it will read the turn on and off times, the |
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 |
while true; do |
||
for i in `seq 20 25` ; do |
for i in `seq 20 25` ; do |
||
dorelay $i |
dorelay $i |
||
done |
done |
||
done |
|||
Here it will |
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 112: | 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. ( That is the part you are seeing on this page ) |
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; |
||
Line 121: | Line 122: | ||
unsigned int s = 0; |
unsigned int s = 0; |
||
This will tell the script to start at 0 and to be an unsigned int. An unisgned int can |
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 132: | 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 146: | 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); |
sprintf (buf, "Times: %u ", s); |
||
write_at_lcd (0, 0, buf); |
write_at_lcd (0, 0, buf); |
||
sprintf (buf, "Relay: %d", num-0x20+1); |
sprintf (buf, "Relay: %d", num-0x20+1); |
||
Line 154: | Line 155: | ||
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 %d is for showing it in decimals and |
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. |
"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. ) |
( if you count 19 or 21 hexadecimals down you would get a really different result. ) |
||
Line 161: | Line 162: | ||
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. |
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