当前位置:网站首页>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 :
边栏推荐
- [matlab] communication signal modulation general function interpolation function
- When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error
- The second case analysis of the breakthrough of defense system from the perspective of the red team
- Notepad++--显示相关的配置
- 抓包整理外篇fiddler———— 会话栏与过滤器
- IP时代来临,电竞酒店如何借好游戏的“东风”?
- Zhongke Panyun - data analysis and forensics packet flag
- 2022危险化学品经营单位安全管理人员上岗证题库及答案
- 2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
- [matlab] matlab simulation - low pass Gaussian white noise
猜你喜欢
中职组网络安全—内存取证
Topological sorting and graphical display of critical path
Zhongke panyun-d module analysis and scoring standard
Headache delayed double deletion
A summary of the 8544 problem that SolidWorks Standard cannot obtain a license
中科磐云—2022广东木马信息获取解析
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre
LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
Simple g++ and GDB debugging
2022危险化学品经营单位安全管理人员上岗证题库及答案
随机推荐
cmake
[matlab] matlab simulation modulation system SSB system
【QT】定时器
[matlab] general function of communication signal modulation - generation of narrow-band Gaussian white noise
LM小型可编程控制器软件(基于CoDeSys)笔记二十二:错误4268/4052
【MATLAB】通信信号调制通用函数 — 傅里叶逆变换
【MATLAB】MATLAB 仿真模拟调制系统 — DSB 系统
flink1.13 sql基础语法(二)join操作
Graduation design of small programs -- small programs of food and recipes
Trie number dictionary tree
[paper summary] zero shot semantic segmentation
【MATLAB】通信信号调制通用函数 — 傅里叶变换
[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
KMP match string
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (cosine roll off forming pulse)
Integer type of C language
Share some of my telecommuting experience
National vocational college skills competition (secondary vocational group) network security competition questions - Analysis
2022g2 power station boiler stoker special operation certificate examination question bank and answers
2022 Guangdong provincial competition - code information acquisition and analysis flag