当前位置:网站首页>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 :
边栏推荐
- Thread pool: use thread pool to optimize query speed
- 记几个智能手表相关芯片 蓝牙芯片 低功耗
- NTFS security permissions
- C语言简易学生管理系统(含源码)
- 定制一个自己项目里需要的分页器
- 2022年T电梯修理操作证考试题库及模拟考试
- [technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
- Unity2d -- character moves and turns
- 由于使用flash存放参数时,擦除掉了flash的代码区导致进入硬件错误中断
- KMP match string
猜你喜欢
Simulated small root pile
《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记
简单g++和gdb调试
海力士EMMC5.0及5.1系列对比详解
抓包整理外篇fiddler———— 会话栏与过滤器
National vocational college skills competition (secondary vocational group) network security competition questions - Analysis
中职组网络安全—内存取证
LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
令人头痛的延时双删
Programming example of stm32f1 and stm32subeide -74hc595 drives 4-bit 7-segment nixie tube
随机推荐
2022年T电梯修理操作证考试题库及模拟考试
[matlab] general function of communication signal modulation Fourier transform
Topological sorting and graphical display of critical path
Annex I: power of attorney for 202x XXX attack and defense drill
Encryption and decryption
[matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system
Detailed comparison of Hynix emmc5.0 and 5.1 series
记几个智能手表相关芯片 蓝牙芯片 低功耗
COMP1721 Creating Classes
【MATLAB】MATLAB 仿真数字基带传输系统 — 双极性基带信号(余弦滚降成形脉冲)的眼图
Automated testing selenium foundation -- webdriverapi
2022 question bank and answers for safety management personnel of hazardous chemical business units
练习-冒泡排序
【QT】制作MyComboBox点击事件
Graduation design of small programs -- small programs of food and recipes
PostgreSQL has officially surpassed mysql. Is this guy too strong!
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
Zhongke panyun-d module analysis and scoring standard
Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis