当前位置:网站首页>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 :
边栏推荐
- [interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre
- 【MATLAB】MATLAB 仿真数字带通传输系统 — QPSK 和 OQPSK 系统
- Appearance of LabVIEW error dialog box
- 简单g++和gdb调试
- Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
- The first introduction, stages and methods of defense system breakthrough from the perspective of the red team
- Roles of rollup components
- 2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
- We believe that the development of consumer Internet will still be limited to the Internet industry itself
- Get the ID of the record just inserted from laravel
猜你喜欢

【QT】定时器

Capturing and sorting out external Fiddler -- Conversation bar and filter

KMP match string

National vocational college skills competition (secondary vocational group) network security competition questions - Analysis

Trie number dictionary tree

ETCD数据库源码分析——初始化总览

appliedzkp zkevm(13)中的Public Inputs

Just do it with your hands 7 - * project construction details 2 - hook configuration

2022 question bank and answers for safety management personnel of hazardous chemical business units

2022G2电站锅炉司炉特种作业证考试题库及答案
随机推荐
Network equipment emergency response Guide
Get the ID of the record just inserted from laravel
COMP1721 Creating Classes
练习-冒泡排序
Zhongke panyun-d module analysis and scoring standard
记几个智能手表相关芯片 蓝牙芯片 低功耗
Li Kou's 300th weekly match
Flutter calls Gaode map app to realize location search, route planning and reverse geocoding
Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
【MATLAB】通信信号调制通用函数 — 傅里叶变换
How to build your own knowledge engine? Community open application
ETCD数据库源码分析——初始化总览
[matlab] matlab simulation modulation system FM system
Share some of my telecommuting experience
简易零钱通
LM小型可编程控制器软件(基于CoDeSys)笔记二十二:错误4268/4052
【MATLAB】MATLAB 仿真模拟调制系统 — DSB 系统
Zhongke Panyun - data analysis and forensics packet flag
拓扑排序和关键路径的图形化显示