Project

General

Profile

Transmission of DFRobot accelerometer data from ESP32 to Simulink via Wifi

Added by Muhamad Imran 11 months ago

Hey, I connected 6-axis accelerometers to my Arduino board and connected the board with ESP32. The sensor data reaches the ESP32 and is sent to Matlab via Wi-Fi in real-time. It is a successful code in the Matlab script. However, I am not able to send sensor data via Wifi straight to Simulink. I dowloaded Waijung 2 and trying it out in hopes to achieve this. I am unable to pull it off, as this is rather new to me. Most of the examples shown in Waijung 2 user guide were focused on uploading Matlab/Simulink codes into the ESP32 themselves.

I have tried a few models, with and without the use of Waijung 2 blocks. I could not find one which showed in detail how to receive Wi-Fi TCP/IP data from ESP32 to Simulink. I would really appreciate technical support to help me establish Wi-Fi communication and send data to Simulink. I attach below the Matlab and also Simulink files that didn't work. Thank you :)

https://wiki.dfrobot.com/Serial_6_Axis_Accelerometer_SKU_SEN0386


Replies (5)

RE: Transmission of DFRobot accelerometer data from ESP32 to Simulink via Wifi - Added by Parth Maheshwari (พาร์ท) 11 months ago

Hello,

I would like to confirm a few things:

1) Are you using SoftwareSerial Arduino library to communicate between the accelerometer sensors and the Arduino board?

2) Which serial communication protocol are you using to send data from Arduino to ESP32? Is it TCP?

RE: Transmission of DFRobot accelerometer data from ESP32 to Simulink via Wifi - Added by Muhamad Imran 11 months ago

1) Yes, I am using SoftwareSerial Arduino library

2) I am using UART, not TCP. But, I want the transfer of sensor data from ESP32 to Simulink to be TCP

I attach a file that shows the coding done for the Arduino and Esp32.

RE: Transmission of DFRobot accelerometer data from ESP32 to Simulink via Wifi - Added by Parth Maheshwari (พาร์ท) 11 months ago

Hello,

Apologies for the delayed response.

Although there are Simulink blocks to receive TCP data in Simulink from the computer (as you have already done so in the Unsuccesful_Simulink_Model.slx that you had attached), currently the Waijung 2 toolbox does not have a TCP block through which it can send data from ESP32 to the computer.

1. A solution I can suggest is to use UDP instead. Waijung 2 has the UDP blockset through which you can send data from ESP32 to the computer. Since you are using UART to send data from Arduino to ESP32, the data will be stored in the UART buffer of the ESP32. You can first use the Waijung 2 UART blockset to read the data from the UART buffer and then feed it into the Waijung 2 UDP block. This model will be flashed to the ESP32.

After that you can make a second model for the computer side, which will be same kind of Simulink model as Unsuccesful_Simulink_Model.slx using UDP Simulink blocks to receive the data in Simulink in real-time.

So you actually do not need to use External Mode in this case, as External Mode feature is specifically for monitoring and tuning parameters on the ESP32. Since you don't want to do that and simply want to send data from ESP32 into Simulink, using UDP is an option with the Waijung 2 blockset.

2. The most straightforward and stable solution for us (since we are ESP32 users and don't use Arduino) would be to directly use ESP32 to read the sensor data using I2C/SPI protocol directly in Simulink as Waijung 2 blockset has I2C/SPI block while ESP32 has in-built WiFi, hence eliminating the usage of Arduino. I remember you mentioning that using Arduino allows you to directly use SoftwareSerial library and also has a lot of GPIO pins, which will be useful for your application. If at some point you only want to use ESP32 and the Waijung 2 blockset, you will need a detailed datasheet of your sensor to configure and read it using I2C/SPI block. I can send you some examples later if this is the option you want to take.

Most accelerometers support SPI/I2C so this is also an option you can consider as it is direct and stable. Some sources say that SEN0386 supports SPI and I2C but some sources say it only supports UART. So you will need to double-check this if you are to consider option 2.

Hope this helps and let me know your thoughts.

Sincere regards,
Parth

RE: Transmission of DFRobot accelerometer data from ESP32 to Simulink via Wifi - Added by Muhamad Imran 11 months ago

Hello,

In relation to the first solution, TCP protocol is preferred since accuracy and reliability of the data transmission is of high priority. However, I would appreciate if you can create a basic Simulink model to receive data from esp32 via UDP protocol. I can try use it and see if it works and test how reliable it is.

As for the second solution, the SEN0386 is designed to only support UART. I don't see how it could work if the Arduino is eliminated since as previously mentioned, the ability for software serial and high number of pins are crucial.

Mathworks has openly mentioned that its 'Matlab-SImulink support package for arduino hardware' supports the esp32. Do you think it can be done through here?

https://www.mathworks.com/help/supportpkg/arduinoio/ug/configure-setup-for-esp32-hardware.html

What are your thoughts from my reply. I'm eager to know. Thank you

RE: Transmission of DFRobot accelerometer data from ESP32 to Simulink via Wifi - Added by Parth Maheshwari (พาร์ท) 11 months ago

Hi Imran,

Have you checked out the UDP demo? It provides the Simulink model needed to receive data from ESP32 via UDP protocol.

Regarding the Arduino support package supporting the ESP32, if sufficient driver blocks are provided for your use case, then this should be another possible solution as well.

Sincere regards,
Parth

    (1-5/5)