当前位置:网站首页>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 :
边栏推荐
- Just do it with your hands 7 - * project construction details 2 - hook configuration
- Notepad++--显示相关的配置
- 加密和解密
- laravel 中获取刚刚插入的记录的id
- Graduation design of small programs -- small programs of food and recipes
- Write a complete answer applet (including single choice questions, judgment questions and multiple topics) (III) single choice questions, judgment questions, and the first question display
- 【MATLAB】通信信号调制通用函数 — 带通滤波器
- VSCode的有用插件
- 【MATLAB】MATLAB 仿真数字基带传输系统 — 双极性基带信号(第 I 类部分响应波形)的眼图
- Get the ID of the record just inserted from laravel
猜你喜欢
![[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre](/img/3e/b5df691ca1790469eb1b4e8ea5b4c0.png)
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre

《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记

LM small programmable controller software (based on CoDeSys) note XXI: error 3703

Zhongke panyun-d module analysis and scoring standard

全国职业院校技能大赛(中职组)网络安全竞赛试题—解析

关于solidworks standard无法获得许可 8544问题的总结

Automated testing selenium foundation -- webdriverapi

基于单片机的太阳能杀虫系统

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

Trie number dictionary tree
随机推荐
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
Daily question brushing record (12)
Write a complete answer applet (including single choice questions, judgment questions and multiple topics) (III) single choice questions, judgment questions, and the first question display
Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
2022G2电站锅炉司炉特种作业证考试题库及答案
【MATLAB】MATLAB 仿真模拟调制系统 — DSB 系统
中科磐云—数据分析与取证数据包flag
Yyds dry goods inventory TCP & UDP
Remote desktop client RDP
Unity2D--人物移动并转身
【MATLAB】MATLAB 仿真 — 低通高斯白噪声
Topological sorting and graphical display of critical path
[matlab] matlab simulates digital bandpass transmission systems - QPSK and OQPSK systems
Detailed comparison of Hynix emmc5.0 and 5.1 series
Just do it with your hands 7 - * project construction details 2 - hook configuration
全国职业院校技能大赛(中职组)网络安全竞赛试题—解析
Public inputs in appliedzkp zkevm (13)
Analysis of classical pointer and array written test questions in C language