当前位置:网站首页>Simulink and Arduino serial port communication
Simulink and Arduino serial port communication
2022-07-04 05:15:00 【lihe2021】
The purpose of this article is :Simulink And Arduino Serial port communication , And then get and Arduino Connected pressure sensor FSR402 The data of .
Simulink And Arduino There are two ways to interact (http://www.51hei.com/arduino/3989.html):
(1)Simulink Arduino Support package
(2)Simulink Serial port communication
As has been given Arduino It's programmed and read FSR402 Procedure for pressure values ( link :https://pan.baidu.com/s/1yadaWsIm-4wXirOJWflCLA
Extraction code :llhh), Hope again in Simulink Call serial port in , Reading data . here Simulink Arduino Support package Obviously not . Here we need to use Simulink Serial port module in Serial Receive, From the Serial Receive It can be seen from the module that what it receives is binary data .
Before implementation , The way of serial communication needs to be explained . There are generally two ways of serial communication : 1、 character ( Corresponding text mode ) 2、 byte ( Corresponding to binary mode )
character | byte |
---|---|
fscanf fprint (Matlab) | fread fwrite (Matlab) |
Serial. print (Arduino) | Serial.write (Arduino) |
Popular speaking , Character mode is for PC End display , Byte mode is more used to communicate with serial port devices .
So in Arduino In the program, we can find , It's using print Function to output data , Then you can check the output on the serial port monitor . however Serial Receive Received binary data , So you need to use write Function performs byte by byte output , Then write the pressure value to Arduino Corresponding serial port , thus Simulink Read through the serial port receiving module .
Arduino send out
Arduino In the use of union To send the float Type data . The code snippet is as follows
Definition union SeFrame
union SeFrame
{
long Long;
byte Byte[4];
};
SeFrame Sefram;
Send data code snippet :
void Send_long(long LONG)
{
Sefram.Long= LONG;
Serial.write(Sefram.Byte[0]);
Serial.write(Sefram.Byte[1]);
Serial.write(Sefram.Byte[2]);
Serial.write(Sefram.Byte[3]);
}
simulink Receive settings
Serial Receive Module :
data type Set to int32, Every data use 4 Bytes
data size Set to 1, Because there is only one data we want to send .
The end result is as follows :
边栏推荐
- cmake
- 【MATLAB】通信信号调制通用函数 — 傅里叶逆变换
- [matlab] matlab simulates digital baseband transmission system - digital baseband transmission system
- 2022 Guangdong provincial competition - code information acquisition and analysis flag
- [matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (cosine roll off forming pulse)
- [matlab] matlab simulation - simulate the AM modulation process of the modulation system
- Annex 2-2 confidentiality commitment docx
- Automated testing selenium foundation -- webdriverapi
- 数据标注是一块肥肉,盯上这块肉的不止中国丨曼孚科技
- The first introduction, stages and methods of defense system breakthrough from the perspective of the red team
猜你喜欢
随机推荐
LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
Network equipment emergency response Guide
ping端口神器psping
Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis
Capturing and sorting out external Fiddler -- Conversation bar and filter
[matlab] matlab simulation - simulate the AM modulation process of the modulation system
[matlab] general function of communication signal modulation bandpass filter
[matlab] matlab simulation - low pass Gaussian white noise
Graduation design of small programs -- small programs of food and recipes
RSA加密应用常见缺陷的原理与实践
Share some of my telecommuting experience
2022危险化学品经营单位安全管理人员上岗证题库及答案
Programming example of stm32f1 and stm32subeide -74hc595 drives 4-bit 7-segment nixie tube
Public inputs in appliedzkp zkevm (13)
[QT] timer
appliedzkp zkevm(11)中的EVM Proof
Notes on the paper "cross view transformers for real time map view semantic segmentation"
LabVIEW错误对话框的出现
中科磐云—2022广东木马信息获取解析
中職組網絡安全—內存取證