EDIT: see post #8
solved with help from the first post, to avoid starting new thread I'm asking a few questions about best serial practices for fast processing
Original:
Hey guys so I'm having so many problems with serial read. I have had it doing numerous things that I want, including:
- read text
- read numbers
and it has also done numerous things I did not want:
- no space between characters
- no space between words
- number 13 between numbers
- unable to use serial.readstringuntil('13')
- many more
I tried the help page/documentation, and got things a little different, but still not how I want them.
Here's the arduino code:
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
String a;
void setup() {
// set up the LCD's number of columns and rows:
Serial.begin(9600); // set up Serial library at 9600 bps
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
while(Serial.available()) {
a= Serial.readString ;// read the incoming data as string
// String a = String(13, HEX);
Serial.print(a);
lcd.print(a);
}}
My matlab code has also gone several revisions and my head is just spinning at this point:
% Create a serial port object.
obj1 = instrfind('Type', 'serial', 'Port', 'COM8', 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = serial('COM8','BaudRate',9600,'Terminator','CR')
else
fclose(obj1);
obj1 = obj1(1)
end
% Connect to instrument object, obj1.
fopen(obj1);
% Communicating with instrument object, obj1.
%data1 = query(obj1, '*IDN?');
% Disconnect from instrument object, obj1.
totaltests=9999
test=1
pause on % to enable pause function
while test<totaltests
fprintf(obj1,test)
test=test+1;
pause(0.1); %in seconds, but actually doesn't works
end
fclose(obj1);
% Clean up all objects.
delete(obj1);
Where do I go from here?