Pages: [1]   Go Down
Author Topic: Actuating Lens Project  (Read 1463 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
for i = 1:50
  fwrite(s, i, 'uint8', 'sync');
  rx(i) = fread(s, 1);

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.

Global Moderator
Offline Offline
Shannon Member
Karma: 223
Posts: 13870
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.


Rob Tillaart

Nederlandse sectie -,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Faraday Member
Karma: 62
Posts: 3077
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

Pages: [1]   Go Up
Jump to: