Serial Port comunication witch arduino
-
- User
- Posts: 17
- Joined: Mon Jun 13, 2016 8:22 pm
Serial Port comunication witch arduino
Hi people, i dont know anymore what to do, i programmed a arduino with some commands, if i send with 9600 baud a "a" it steps a motor left and gives a "o" as ok, with putty everything works fine, with purebasic i can send but recive is not working, it starts that AviableSerialInput recognises nothing there, what is your idea?
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Port$ = "COM6"
CompilerElse
Port$ = "/dev/ttyS5"
CompilerEndIf
*buffer = AllocateMemory(128)
Puffer=Asc("a")
RPuffer.a=0
If OpenSerialPort(0, Port$, 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1, 10)
Debug "Successfully connected"
a=0
Repeat
a=a+1
b=0
Ergebnis = WriteSerialPortString(0, "a", #PB_Ascii)
;Debug "t"
Repeat
If AvailableSerialPortInput(0)
Ergebnis = ReadSerialPortData(0, @RPuffer, 1)
;Debug RPuffer
Debug "t"
If Chr(RPuffer)="o"
b=1
EndIf
EndIf
Until b=1
Debug "t"
;Delay(500)
Until a>100
Else
MessageRequester("Error", "Can't open the serial port: "+Port$)
EndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Port$ = "COM6"
CompilerElse
Port$ = "/dev/ttyS5"
CompilerEndIf
*buffer = AllocateMemory(128)
Puffer=Asc("a")
RPuffer.a=0
If OpenSerialPort(0, Port$, 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1, 10)
Debug "Successfully connected"
a=0
Repeat
a=a+1
b=0
Ergebnis = WriteSerialPortString(0, "a", #PB_Ascii)
;Debug "t"
Repeat
If AvailableSerialPortInput(0)
Ergebnis = ReadSerialPortData(0, @RPuffer, 1)
;Debug RPuffer
Debug "t"
If Chr(RPuffer)="o"
b=1
EndIf
EndIf
Until b=1
Debug "t"
;Delay(500)
Until a>100
Else
MessageRequester("Error", "Can't open the serial port: "+Port$)
EndIf
Re: Serial Port comunication witch arduino
Can you try this:
Code: Select all
EnableExplicit
Define Port$, a.i, Ergebnis.i, RPuffer.a, b.i
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Port$ = "COM6"
CompilerElse
Port$ = "/dev/ttyS5"
CompilerEndIf
If OpenSerialPort(0, Port$, 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 128, 128)
Debug "Successfully connected"
Repeat
a + 1
RPuffer = 'a'
If WriteSerialPortData(0, @RPuffer, 1) = 1
Debug "t"
Repeat
b = 100
If AvailableSerialPortInput(0)
If ReadSerialPortData(0, @RPuffer, 1) = 1
;Debug RPuffer
Debug "r: " + Chr(RPuffer)
If RPuffer = 'o'
Debug "ok"
Break
EndIf
EndIf
Else
Delay(10)
b - 1
EndIf
Until b = 0
If b = 0
Debug "r timeout"
EndIf
EndIf
Delay(500)
Until a = 10
Else
MessageRequester("Error", "Can't open the serial port: " + Port$)
EndIf
-
- User
- Posts: 17
- Joined: Mon Jun 13, 2016 8:22 pm
Re: Serial Port comunication witch arduino
Its still only
Successfully connected
t
damn
Successfully connected
t
damn
-
- User
- Posts: 17
- Joined: Mon Jun 13, 2016 8:22 pm
Re: Serial Port comunication witch arduino
Maybe a prb with newer Windows than ver 7???
-
- User
- Posts: 17
- Joined: Mon Jun 13, 2016 8:22 pm
Re: Serial Port comunication witch arduino
No its not working sorr<, my fail, was only the restart from arduino 

Last edited by xxfreshman on Tue Oct 15, 2019 9:51 pm, edited 1 time in total.
Re: Serial Port comunication witch arduino
Do you need to send #CR$ or #CRLF$ after the 't' command?
Jim
Jim
-
- User
- Posts: 17
- Joined: Mon Jun 13, 2016 8:22 pm
Re: Serial Port comunication witch arduino
no i need only to send a or b c d e not more, in putty i see the o as answer, and it works perfekt i changed allready to xon xoff, but still nothing.
Last edited by xxfreshman on Tue Oct 15, 2019 10:04 pm, edited 1 time in total.
-
- User
- Posts: 17
- Joined: Mon Jun 13, 2016 8:22 pm
Re: Serial Port comunication witch arduino
if i send endles a "a" it works but i need to get the "o" back this says me that the step motor was fine moving, and reciving this is not working.
Re: Serial Port comunication witch arduino
Please post a complete debug output of my code.
Re: Serial Port comunication witch arduino
I didn't have an Arduino handy but, using something similar, infratec's code works as expected
I tried different delays and with/without CR in the reply and everything still worked.
Jim
My BASIC code on the device:Successfully connected
t
r: o
ok
t
r: o
ok
t
r: o
ok
t
r: o
ok
t
r: o
ok
t
r: o
ok
t
r: o
ok
t
r: o
ok
t
r: o
ok
t
r: o
ok
Code: Select all
DO
k$ = INKEY$
IF k$ = "a" THEN
'pause 100
PRINT "o";
ENDIF
PAUSE 10
LOOP
Jim
-
- User
- Posts: 17
- Joined: Mon Jun 13, 2016 8:22 pm
Re: Serial Port comunication witch arduino
Arduino code
#include <Stepper.h>
const int stepsPerRevolution = 4;
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
int ledPinb = LED_BUILTIN;
int ledPin = 3;
int fadeValue = 0;
void setup() {
pinMode(ledPinb, OUTPUT);
digitalWrite(ledPinb, LOW);
// Set the speed to 5 rpm:
myStepper.setSpeed(2000);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
char received = (char)Serial.read();
//Serial.print(received);
if (received == 'a') {
digitalWrite(ledPinb, HIGH);
Serial.print("o");
myStepper.step(stepsPerRevolution);
//delay(500);
} else if (received == 'b') {
digitalWrite(ledPinb, LOW);
Serial.print("o");
myStepper.step(-stepsPerRevolution);
//delay(500);
}
if (received == 'c') {
if (fadeValue < 100) {
Serial.print("o");
fadeValue=fadeValue+1;
analogWrite(ledPin, fadeValue);
}
//delay(500);
} else if (received == 'd') {
if (fadeValue > 0) {
Serial.print("o");
fadeValue=fadeValue-1;
analogWrite(ledPin, fadeValue);
}
//delay(500);
}
}
}
AS I TOLD WITH PUTTY ITS WORKING FINE
NOT WITH PB.
#include <Stepper.h>
const int stepsPerRevolution = 4;
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
int ledPinb = LED_BUILTIN;
int ledPin = 3;
int fadeValue = 0;
void setup() {
pinMode(ledPinb, OUTPUT);
digitalWrite(ledPinb, LOW);
// Set the speed to 5 rpm:
myStepper.setSpeed(2000);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
char received = (char)Serial.read();
//Serial.print(received);
if (received == 'a') {
digitalWrite(ledPinb, HIGH);
Serial.print("o");
myStepper.step(stepsPerRevolution);
//delay(500);
} else if (received == 'b') {
digitalWrite(ledPinb, LOW);
Serial.print("o");
myStepper.step(-stepsPerRevolution);
//delay(500);
}
if (received == 'c') {
if (fadeValue < 100) {
Serial.print("o");
fadeValue=fadeValue+1;
analogWrite(ledPin, fadeValue);
}
//delay(500);
} else if (received == 'd') {
if (fadeValue > 0) {
Serial.print("o");
fadeValue=fadeValue-1;
analogWrite(ledPin, fadeValue);
}
//delay(500);
}
}
}
AS I TOLD WITH PUTTY ITS WORKING FINE
NOT WITH PB.
-
- User
- Posts: 17
- Joined: Mon Jun 13, 2016 8:22 pm
Re: Serial Port comunication witch arduino
could it that there is a bug that no reciving is possible?
-
- User
- Posts: 17
- Joined: Mon Jun 13, 2016 8:22 pm
Re: Serial Port comunication witch arduino
and again if i open a putty connection to this arduino code, i can set a "a" i get a "o" so why damn i get nothing in pb?
Re: Serial Port comunication witch arduino
I am using PB V5.71 on Widows 10
I tried both 32 and 64 bit versions.
I loaded your Arduino code onto a nano clone.
infratec's code runs as expected.
Your original code works but nowhere were you indicating that the "o" has been received.
I added one line to do this,
and your code successfully prints "o"
Jim
I tried both 32 and 64 bit versions.
I loaded your Arduino code onto a nano clone.
infratec's code runs as expected.
Your original code works but nowhere were you indicating that the "o" has been received.
I added one line to do this,
Code: Select all
Debug "t"
If Chr(RPuffer)="o"
Debug "o"
b=1
EndIf
I have run out of ideas.Successfully connected
t
o
t
t
o
t
t
o
Jim
Re: Serial Port comunication witch arduino
To see a bit more at the output:
Not tested or compiled.
Code: Select all
#include <Stepper.h>
const int stepsPerRevolution = 4;
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
int ledPinb = LED_BUILTIN;
int ledPin = 3;
int fadeValue = 0;
void setup() {
pinMode(ledPinb, OUTPUT);
digitalWrite(ledPinb, LOW);
// Set the speed to 5 rpm:
myStepper.setSpeed(2000);
Serial.begin(9600);
}
void loop() {
char Rcv;
if (Serial.available()) {
Rcv = (char) Serial.read();
switch(Rcv) {
case 'a':
digitalWrite(ledPinb, HIGH);
Serial.print("l");
myStepper.step(stepsPerRevolution);
break;
case 'b':
digitalWrite(ledPinb, LOW);
Serial.print("r");
myStepper.step(-stepsPerRevolution);
break;
case 'c':
if (fadeValue < 100) {
Serial.print("u");
fadeValue++;
analogWrite(ledPin, fadeValue);
} else {
Serial.print("t");
}
break;
case 'd':
if (fadeValue > 0) {
Serial.print("d");
fadeValue--;
analogWrite(ledPin, fadeValue);
} else {
Serial.print("b");
}
break;
default:
Serial.print("-");
}
}
}