How to communicate from Matlab/Simulink to Arduino Due by Wifi using a ESP8266 wifi chip

17 visualizzazioni (ultimi 30 giorni)
I try to setup a communication between Matlab 2016a/Simulink and Arduino Due through wifi with an ESP8266 wifi chip, following this tutorial:
I use the Simulink setup that Mathworks is providing, but I have 2 problems/questions:
1) In the Hardware Implementation configuration panel of Simulink (Simulation > Model Configuration Parameters > Hardware Implementation > "specify arduino model in hardware board field" > Target Hardware Ressources > Wifi shield properties), after specifying that I use an Arduino Due (I have downloaded the Arduino Support Package) I can't specify that I am using an ESP8266. Does it mean that the ESP8266 is not taken in charge in the package by Matlab anymore? Does it mean that the ESP8266 is not detected?
I have:
and following the tutorial I should have:
2) Do I have to program my ESP8266 to act as a server and assign an IP adress to it(through C++ code run on the Arduino) before trying to connect it with Matlab, or will Matlab do all the setup automatically? (For the configuration I have the Arduino connected via USB to my laptop).
Thanks in advance for the help!

Risposte (2)

Pradeep KS
Pradeep KS il 24 Nov 2017
Hi Laurent, ESP8266 WiFi board is supported as a shield in Simulink Arduino Support package starting from R2017b release. Its not supported in R2016a release as you mentioned.
To use ESP8266 with Simulink Arduino support package, AT firmware should be running in the ESP8266 board. Arduino and ESP8266 are interfaced using Serial communication.
Please refer to below link on interfacing ESP8266 WiFi board with Arduino hardware. https://www.mathworks.com/help/supportpkg/arduino/ug/connect-esp8266-to-arduino-hardware.html
-Pradeep
  2 Commenti
Laurent Storrer
Laurent Storrer il 2 Dic 2017
Hi Pradeep, first thank you for your answer. I've updated my Matlab version to R2017b and now I can select the ESP8266 option. However, there remain some problems, and I have 3 questions about them. I will try to describe my setup with accuracy:
  • I have an AT firmware on the ESP8266 and I run the following AT commands:
AT
AT+CWMODE_CUR=2
AT+CWSAP_CUR="ugv_wifi","protect",10,0
AT+CIPMUX=1
AT+CIPSTART=0,"UDP","192.168.2.1",444,333,0
So I make the ESP8266 act as a Wifi Access Point called "ugv_wifi" and assign the IP address 192.168.2.1 to it.
  • After that, I connect my computer to the network "ugv_wifi":
And it seems that the IP of my computer on this network is 192.168.4.2, which is already strange because it does not share the same subnet part as the ESP8266 (192.168.4 for the computer, different from 192.168.2 of the ESP8266).
where I specify the IP of the ESP8266 and the "ugv_wifi" network parameters. First question: is this well the IP of the ESP8266 and the "ugv_wifi" networks parameters that I have to specify, or should I put the IP of my computer instead?
  • I adapt the parameters of the UDP send block:
where in Remote IP I put the IP address of my computer on the "ugv_wifi" network, in Remote port the port of my computer, and in Local Port the port of my ESP8266. Second question: is this well the IP and port of my computer that I have to specify in the Remote fields, or those of my ESP8266? According to this block's documentation it should be of my computer but I'm not sure.
  • When deploying the Simulink Model on my ESP8266 I obtain the following error:
I tried the advices provided in the "Unable to assign IP address to Arduino Board connected to ESP8266" document but it did not work. Note: those advices are
Third question: do you have an idea how to fix this issue?
Thanks in advance for your help!
Laurent Storrer
Prathap moola
Prathap moola il 27 Nov 2018
Modificato: Prathap moola il 27 Nov 2018
hi guys,
I too have the same issue... how to fix it... how to assign ip adress to esp8266.
if any one can help me!
thank you.

Accedi per commentare.


Shreya Bharti
Shreya Bharti il 7 Mag 2021
Hello, I am trying to calculate distance through ultrasonic sensor which is interfaced with esp8266 and the complete system is working fine when running code on Arduino ide.But I want to display and plot distances using MATLAB code.Is it possible in any way?? I have tried lot of things but alone with esp8266 and sensor it's not working. Please help.

Community Treasure Hunt

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

Start Hunting!

Translated by