I would like to pass on to others, some of the work I have been developing using the Arduino Uno processor board and J basic.
This is intended to show how to use Serial port communication to and from a simple Basic program, without having to learn the more advanced C# type programs.
I realised coupling the two types of programs, you can develop some very interesting projects.
J basic is a free easy Basic program ( i.e. the free version of liberty basic ), this can be found and downloaded from the internet.
My interest is in AI and I have been developing a robot called Loopy , ( hence my Avatar photo ).
Loopy can do many exciting things like Talk, Remember Data, respond to room stimuli etc.
All this can be achieved by using Serial Communication between J basic and Arduino.
To get this working you will need a Arduino Uno (other boards may also work?).
An RS 232 to TTL converter.
If you are using a USB port on the PC you will also need a USB to RS232 converter
Some wires to link the RS 232 / TTL converter to the Arduino Uno board.
A Cable to connect the RS 232 / TTL converter to the PC, NOT a NULL type cable!.
A power source for the Arduino Uno.
(1) Connect all wires and cables, note I am using Arduino pins 5 = TX in and 6 = Rx out
(2) Download my Arduino Sketch “Arduino_Jbasic”.
(3) Download my Jbasic test program.
(4) Open up the Arduino Serial port monitor ( 57600 baud rate ), so you can see what is happening.
(5) Download Jbasic from the internet, and open and run my program.
(6) Click on the “Test 1” button.
(7) You should see the LED ( pin 13 )on the Arduino board flash on and off twice.
Here is a photo of the first test setup, more examples from my project / Serial Communication will be supplied in due course if there is enough interest, good luck.
//Serial communication Arduino to Jbasic
// Program created and written by Brian Archer
// No originality is claimed for this program, this example code is classed as public domain.
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#include <SoftwareSerial.h>
String readString = String(0);
// RS 232 / TTL connection.
SoftwareSerial mySerial(5,6); // Arduino board pin positions 5 = TXin, 6 = RXout This is the connection to and from the RS 232 / TTL board.
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void setup(){
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
// Setting the the serial ports baud rates
Serial.begin(57600); // this is the communication baud rate for the Arduino Text Monitor.
Serial.println("Start of Program");
Serial.println(" ");
delay (10);
mySerial.begin(4800); // this is the communication baud rate for the RS232 / TTL board, (Jbasic serial port generator).
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void loop() {
delay (1000); //Main loop delay, you can vary this time to suit your loop speed
Serial.println("Start of Loop");
Serial.println(" ");
delay(10);
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// readimg serial port
{
Serial.println("Reading serial");
Serial.println("");
while (mySerial.available()) {
delay(10);
if (mySerial.available() >0) {
char c = mySerial.read();
readString += c;}
}
if (readString.length() >0) {
delay(100);
}
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{
//Read option 1
if (readString == "test1") {
delay (10);
Serial.println("LED On");
Serial.println(" ");
digitalWrite(13, HIGH); // sets the LED on
delay(4000); // wait for a 4 seconds
Serial.println("LED Off");
Serial.println(" ");
digitalWrite(13, LOW); // sets the LED off
delay(2000); // wait for 2 seconds
Serial.println("LED On");
Serial.println(" ");
digitalWrite(13, HIGH); // sets the LED on
delay(4000); // wait for a 4 seconds
Serial.println("LED Off");
Serial.println(" ");
digitalWrite(13, LOW); // sets the LED off
delay(2000); // wait for 2 seconds
// Just insert your own program here, instead of turning the LED on pin 13 on and off.
}
else
{
digitalWrite(13, LOW); // set the LED off
}
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{
// Clear buffer, this is a must when using a loop.
readString="";
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{
// End of loop
Serial.println("End of Loop");
Serial.println(" ");
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
} // This is linked to the void loop () {
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// END of PROGRAM
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Jbasic Code
'Basic Serial Port Generator.
'Written by Brian Archer
'No originality is claimed for this program
'START
print " At start "
'This sets the foreground and background screen colours
BackgroundColor$ = "blue"
ForegroundColor$ = "yellow"
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'Setting up the Push Button positions and control procedures.
button #dialog2.accept, "Test 1", [Test1], UL, 10, 55 ' i.e. the box you click etc.
button #dialog2.accept, "Quit", [Quit], UL, 10, 85 ' i.e. the box you click etc.
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
UpperLeftX = 300
UpperLeftY = 2 'this sets the hight of the window from the top of the screen.
WindowWidth = 300 'this set the width dimension of the window.
WindowHeight = 200 'this set the hight dimension of the window.
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'open "Buttons" for dialog as #dialog2 'This is the screen push buttons
open "Element 14 Jbasic Test Program" for dialog as #dialog2 ' name of the window, that appears at the top of the blue screen.
print #dialog2, "font courier_new 8 italic" ' font type.
print #dialog2, "trapclose [Quit]" ' end your text command.
wait
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'This is the serial port output command.
'Remember to change the com port number to the com port of your computer
[Test1]
print "Sending Serial Command Test 1"
print ""
Com = 16384
'XXXXX CHANGE COM5 TO YOUR COM PORT NUMBER XXXXX.
open "com5:4800,n,8,1,ds0,cs0,rs" for random as #commHandle
for I = 1 to 10000
next I
print #commHandle, "test1";
for I = 1 to 10000
next I
close #commHandle
print "done"
print ""
for I = 1 to 80000
next I
wait
end
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[Quit]
print "At Quit"
print ""
close #dialog2
print "Program Stopped"
end
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'END OF PROGRAM
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Arduino_Jbasic.ino (2.86 KB)
Jbasic_Element14_Test1.bas (2.25 KB)