Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: Actuating Lens Project  (Read 1485 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am new at using Arduino and I need some help with this. I am doing a project involving measuring the focus of an object through a custom built lens. I have a simulink block diagram that gives me a graph on the measure of focus in real time. I would like to send this data to Arduino so that I can analyse the voltage needed for the best focus.

I have used the instrument control toolbox to send this serial data, however it keeps coming up with a timeout error/terminator. Alternatively I tried this code in the command box:
Quote
s=serial('COM1','BaudRate',9600);
fopen(s);
for i = 1:50
  fwrite(s, i, 'uint8', 'sync');
  rx(i) = fread(s, 1);
end

This gave an integer error saying I needed a postitive integer.

Can someone help with a code or point me in the right direction please?
Thank you.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 234
Posts: 14296
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You read a byte but do not test if there is one available. The common reaction of the read function is to return -1.

One solution is to read from serial until you do not have a -1.

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3085
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"uint" means unsigned int which means a positive integer.  A "uint8"  is a byte with an unsigned integer in it,
which means that the byte can have the range of values 0 to 255.

Whereas a signed  single-byte integer would have a value in the range -128 to +127
Logged

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: