Code: Select all
open com "/dev/ttyUSB0:38400,n,8,1,BIN,CS0,CD0,TB0,RS" as sp
Code: Select all
open com "/dev/ttyUSB0:38400,n,8,1,BIN,CS0,CD0,TB0,RS" as sp
Shades of Harry Potter!caseih wrote:I solved the problem with this incantation: ...
So why not start there to begin with?... my ultimate goal is to transfer the code to an arduino processor eventually ...
There isn't anything "less than robust", on the Contrary it helps to make things more "robust".BasicCoder2 wrote:I find the need for a delay less than robust although I see it used that way in other example code.
It's faster and more convenient to develop on the computer first. I had to reverse-engineer the protocol after all, and having to recompile and upload after every change is a bit slow. So prototype in FB (because serial interfacing is easy there) in order to get it right, then translate to Arduino later. Ordinarily I'd prototype in Python, but I thought I'd use FB this time, and was pleased with the results. FB's old-fashioned locate and print served my purposes very well: I could simulate my little 2-line display in a window using normal FB screen output commands. In Python I'd have to use ncurses and I didn't want to have to learn that just yet.BasicCoder2 wrote:So why not start there to begin with?.
Instead of sleeping for the maximum time for the Arduino to do its thing it is better if the FreeBASIC program can get on with other things until the Arduino tells it it has completed its task.MrSwiss wrote:There isn't anything "less than robust", on the Contrary it helps to make things more "robust".BasicCoder2 wrote:I find the need for a delay less than robust although I see it used that way in other example code.
Code: Select all
do
if arduino ready for next command
send command
end if
do other stuff
loop
Yes, agreed, if there is something else, to do (which, in my Example, is NOT the Case!).BasicCoder2 wrote:Instead of sleeping for the maximum time for the Arduino to do its thing it is better if the FreeBASIC program can get on with other things until the Arduino tells it it has completed its task.Code: Select all
do if arduino ready for next command send command end if do other stuff loop
Code: Select all
while no_new_data()
sleep 20
wend
Code: Select all
sub ArduinoCB(pBuffer as ubyte ptr,size as integer)
' do anything with the incomming data
end sub
Indeed and thank for your examples for they seem to be sufficient at this stage for me to set up a simple two way communication between a FreeBASIC program and the Arduino. The servo example is working without a hitch although my robot project doesn't use servo motors instead I am using ordinary dc motors with encoders to control how many times they rotate any direction.MrSwiss wrote:This is the Main-Reason it is called a Example, and NOT a Application (it highlights a certain Point only,BasicCoder2 wrote:Instead of sleeping for the maximum time for the Arduino to do its thing it is better if the FreeBASIC program can get on with other things until the Arduino tells it it has completed its task.
leaving other Considerations by the Side, for ease of Readability/Understanding).
It is a lot of code and at this stage I am unsure how to use it. As you know I am not an advanced programmer like you and tend to think the way I did back in my MSDOS days. This is the reason I use FreeBASIC instead of being a top gun c++ programmer :)D.J.Peters wrote:@BasicCoder2 This is why I wrote the event driven COM port stuff.
Your description of what you are trying to do isn't all that clear to me. I read you as saying you want a remote keyboard and display for an electrical instrument that already has a keyboard and display? It doesn't seem to me that the code would be very complex and thus would be easy enough to develop up front using the Arduino board alone. I am not even sure where the serial connection comes into it? Does the current keyboard and display have a serial connection to the instrument?caseih wrote:In case you're curious what I'm trying to do is develop a remote display for an instrument.
If the final project will become a purely Arduino project than other Arduino users might also be interested or helpful on an Arduino forum where you can also post images and the circuits of your project.Anyway, I'm pleased with my progress and your queries here on the forum inspired me to get it working.
It's really easy (trust me) I ordered a cheap Arduino Uno R3 with MEGA328P chip and will show you how simple it is.BasicCoder2 wrote:It is a lot of code and at this stage I am unsure how to use it.
Instrument meaning a specialized device that does GPS tracking and recording. The user interface is a 2-line display and a couple of buttons. The main board communicates with the screen and buttons in the same chassis over a serial link. There's a protocol that is used to tell the screen what to display and where. And when buttons are pressed, this information is transmitted back to the main board over the link. Think of the screen and buttons as it's own separate computer, because it actually is. This sort of modularity is very common in the embedded world. One microprocessor may do the main work while another one handles the UI. Another yet may interface with sensors. They all communicate together over busses of different kinds, usually i2c or serial.BasicCoder2 wrote:Your description of what you are trying to do isn't all that clear to me. I read you as saying you want a remote keyboard and display for an electrical instrument that already has a keyboard and display? It doesn't seem to me that the code would be very complex and thus would be easy enough to develop up front using the Arduino board alone. I am not even sure where the serial connection comes into it? Does the current keyboard and display have a serial connection to the instrument?
Code: Select all
$PSLID,086,12D,12D,12D,12D,078,100,111,10A,104,10A,111,100,100,002,08F
$PSLID,10F,080,153,081,120,0CA,14E,14F,120,147,150,153,0C0,14F,176,172
$PSLID,172,169,164,165
Code: Select all
// FBArduino01
#define LED 13
void setup() {
// initialize serial communication at 9600 bits per second
Serial.begin(9600);
// wait for serial port to connect.
while (!Serial) ;
// make the LED pin as output
pinMode(LED,OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(LED, HIGH);
Serial.println("LED on");
delay(1000);
digitalWrite(LED, LOW);
Serial.println("LED off");
delay(1000);
}
Code: Select all
' fbarduion01.bas
#include "RS232.bas"
#define COMPORT 3 ' <--- !!! define your Arduino COM port here !!!
#define BAUDRATE 9600 ' use the same serial speed as in your arduino sketch
dim shared as RS232 Serial
' NOTE: On all Windows OS's the serial device works in binary mode only.
' So if you waiting for a complete string you have to collect all
' incomming data until chr(10) !"\n" are received.
sub ReceiveStringCB(byval buffer as ubyte ptr, byval size as integer)
static as string msg
dim as boolean StringComplete
dim as integer n
' copy chars from buffer to string
while n<size
' it's not a printable char
if buffer[n]<32 then
' it's a new line/string char
if buffer[n]=asc(!"\n") then
StringComplete=true
exit while
end if
else
msg &= chr(buffer[n])
end if
n+=1
wend
if StringComplete then
line (0,12)-step(639,8),0,BF
draw string (0,12),"arduino says: " & msg
if instr(msg,"on") then
circle (320,240),100,2,,,,F
else
circle (320,240),100,0,,,,F
end if
circle (320,240),100,15
msg=""
end if
end sub
' faked arduino Setup() style
sub Setup constructor
screenres 640,480
Serial.EventReceive = @ReceiveStringCB
if Serial.Open(COMPORT,BAUDRATE)=false then
draw string (0,0),"error: can't open RS232 at COM" & COMPORT & ":"
beep : sleep : end 1
else
draw string (0,0),"press [ESC] to quit ..."
end if
end sub
dim as boolean quit
while quit=false
var char = inkey()
if char=chr(27) then quit=true
sleep 200
wend
Serial.Close()
And are you going to use it for any fun projects?D.J.Peters wrote:I got the cheap Arduino UNO rev. 3 today.
Normaly I used all my MC's with codeblocks and the right GNU toolchain.BasicCoder2 wrote:And are you going to use it for any fun projects?