arduino and runbasic home automation

new BookmarkLockedFalling
mmiscool
Full Member
***

mmiscool Avatar

Send me a message if you want to help with a WEB OS project
Posts: 106

Post by mmiscool on Aug 30, 2012 17:33:56 GMT -5

Hello all,

I have built a relay control board that can be operated from run basic.

For this project I used www.seeedstudio.com/depot/relay-shield-p-693.html

and a standard arduino uno board.


The code for the auduino is as follows.

unsigned char relayPin[4] = {4,5,6,7};

void setup()
{

Serial.begin(9600);

int i;
for(i = 0; i < 4; i++)
{
pinMode(relayPin[i],OUTPUT);
}
}


void loop()
{

char ser = Serial.read();

if(ser == 'o'){
digitalWrite(relayPin[2],HIGH);
delay(2000);
digitalWrite(relayPin[2],LOW);
delay(10000);
}
if(ser == 's'){
digitalWrite(relayPin[1],HIGH);
delay(2000);
digitalWrite(relayPin[1],LOW);
delay(10000);
}
}


The code for liberty basic is as follows and should be compiled and stored with the exe files as "arduinoout.exe" and should be stored in the Runbasic directory.

You must install the arduino drivers and configure the comm port in the code below to the correct number.


open "command.in" for input as #mike
input #mike, char.to.send$
close #mike

open "COM3:9600,n,8,1,ds0,cs0,rs" for random as #comm

print #comm, char.to.send$

close #comm
end


The code for runbasic is.

You can customize the arduino code to use any character as the control character and send it that character using the function below.


print arduinoout("o")
wait


function arduinoout(char.to.send$)
open "command.in" for output as #mike
print #mike, char.to.send$
close #mike

end function



Happy coding
-Mike
Check out the code wiki at http://smbisoft.com[br]The code wiki allows for multiple users to work on the same project at the same time in just basic.[br][br]SMBISoft ____888-LAN-Zoli _____ 888-526-9654
meerkat
Senior Member
****

meerkat Avatar

Posts: 250

mmiscool
Full Member
***

mmiscool Avatar

Send me a message if you want to help with a WEB OS project
Posts: 106

Check out the code wiki at http://smbisoft.com[br]The code wiki allows for multiple users to work on the same project at the same time in just basic.[br][br]SMBISoft ____888-LAN-Zoli _____ 888-526-9654
bruces
New Member
*

bruces Avatar

Posts: 2Male

Post by bruces on Jun 19, 2015 11:42:59 GMT -5

Hi mmiscool,
I'm very familiar with Arduino and LB, but new to RB. I understand that the RB function opens a file and writes the char "o" to it. And the LB program opens this file and sends the char out the serial port. But how does the RB program signal the LB program that a command has been written, and needs to be read and sent? Is this related to naming the LB executable the same as the RB function?

Thanks-- (sorry for the newbness)
Bruce
Last Edit: Jun 19, 2015 11:44:05 GMT -5 by bruces
kokenge
Senior Member
****

kokenge Avatar

Posts: 261

mmiscool
Full Member
***

mmiscool Avatar

Send me a message if you want to help with a WEB OS project
Posts: 106

Check out the code wiki at http://smbisoft.com[br]The code wiki allows for multiple users to work on the same project at the same time in just basic.[br][br]SMBISoft ____888-LAN-Zoli _____ 888-526-9654