Effacer les filtres
Effacer les filtres

Connecting arduino to matlab via BT while using I2C communication

2 vues (au cours des 30 derniers jours)
Nerea Perez
Nerea Perez le 12 Juil 2022
Réponse apportée : Raj le 14 Sep 2023
I am currently on a project trying to send data from arduino to matlab. I have one arduino uno (master) that is recieving data from arduino uno (slave) and another board via I2C. Once the master gets that date I want it to send the data to matlab via BT HC05 connection. To start this procces I use the next code (this is the simplest version):
arduinoObj = serialport('COM4',9600);
pause(3);
flush(arduinoObj);
writeline(arduinoObj,'1');
arduinoObj.NumBytesWritten;
pause(1);
if arduinoObj.NumBytesAvailable>0
arduinoObj.NumBytesAvailable
x = readline(arduinoObj);
end
The problem is that the writeline command sometimes works and sometimes does not. With just an arduino, the board with I2C and de BT HC05 it works, the problem starts when adding a second arduino.

Réponse acceptée

Raj
Raj le 14 Sep 2023
Hi Nerea,
I understand you are facing issues with simultaneous serial communications in Arduino Uno.
Here are some viewpoints you should consider before proceeding-
  • Arduino Uno has only one hardware serial port and 2 software serial ports.
  • You can have multiple software serial instances in your code, but you can only use one at a time.
Refer to the Arduino uno documentation for more
You need to take extra care while using simultaneous serial communications.
Also, it is likely that your ‘writeline’ function is only working sometimes due to the absence of a loop which is not making the Arduino send the data repeatedly.
Additionally, you can try switching to Arduino Mega that has 3 hardware ports as a master device which will help in this scenario of multiple serial communications.
You can also refer to the following documentation by MathWorks regarding connecton of Arduino with MATLAB
I hope this resolves the query you had!

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by