Hi guys
I have a problem with my bluetooth connection. I hope you can give me an advice on how to proceed.
I have 4 force sensors hooked up to an Arduino Pro Mini and a bluetooth HC-05. The sensors are being recorded in Matlab and works fine the first time.
The problem is that I have to cut the power to the Arduino and Bluetooth each time, if I dont cut the power this error comes:
Error using icinterface/fopen (line 83)
Unsuccessful open: Cannot connect to the device. Possible reasons are another application
is connected
or the device is not available.
Error in BT_Arduino_Saal_2 (line 6)
fopen(arduino);
I have tried to clear all, close and open the Arduino in Matlab before running the script again, but the same error keeps coming until I restart the system.
This is my Matlab code:
clear all;
clc;
instrhwinfo('Bluetooth');
arduino = Bluetooth('HC-05',1);
fopen(arduino);
x=linspace(1,100); % 100 samples are recorded
numcols = 1; %1 coloum with data is made
y = {}; %All data are placed in y
for i=1:length(x);
data =fscanf(arduino,'%f'); % '%f' makes it decimals
IncomingString = char(data); % the incoming data is turned to characters
IncomingString = regexp(IncomingString, '\s*', 'split'); % data are split up, and in coloums
Heel(i,1)= IncomingString(1,3); %#ok<SAGROW> % read data from coloum 3
Metatars(i,1)= IncomingString(1,5);
Svang(i,1)= IncomingString(1,7);
Calcaneus(i,1)= IncomingString(1,9);
end
fclose(arduino);
PlotHeel = str2double(Heel); %Turn data from cell array to double data
figure(1)
plot(PlotHeel);
title('Heel'); xlabel('Samples'); ylabel('Volt');
PlotMetatars = str2double(Metatars);
figure(2)
plot(PlotMetatars);
title('Metatars'); xlabel('Samples'); ylabel('Volt');
PlotSvang = str2double(Svang);
figure(3)
plot(PlotSvang);
title('Svang'); xlabel('Samples'); ylabel('Volt');
PlotCalcaneus = str2double(Calcaneus);
figure(4)
plot(PlotCalcaneus);
title('Calcaneus'); xlabel('Samples'); ylabel('Volt');
This is my Arduino code:
void setup()
{
// Start serial at 9600 baud
Serial.begin(9600);
}
void loop()
{
// Read the input on analog pin 0:
int sensorValue = analogRead(A0);
int sensorValue2 = analogRead(A1);
int sensorValue3 = analogRead(A2);
int sensorValue4 = analogRead(A3);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = (sensorValue * (3.3 / 1023.0) * 33.33); // *33.33 er for at omdanne til N, sensoren kan give 1023 outputs, og de 0-3.3 v inddeles her. Hvis 110N er max og 3.3 v er max, diveres de for at finde omformningskonstanten.
float voltage2 = (sensorValue2 * (3.3 / 1023.0) * 33.33);
float voltage3 = (sensorValue3 * (3.3 / 1023.0) * 33.33);
float voltage4 = (sensorValue4 * (3.3 / 1023.0) * 33.33);
// Print out the value you read:
{
Serial.print(" Heel ");
Serial.print(voltage,4);
Serial.print(" Metatars ");
Serial.print(voltage2,4);
Serial.print(" Svang ");
Serial.print(voltage3,4);
Serial.print(" Calcanus ");
Serial.print(voltage4,4);
Serial.println();
}
// Wait 100 milliseconds
delay(100);
}
I hope you can help me - Kasper