Go Down

Topic: Actuating Lens Project (Read 1 time) previous topic - next topic

Eyedeal

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.

robtillaart

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 - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

michinyon

"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

Go Up