필터 지우기
필터 지우기

Comunicazione seriale con Arduino

조회 수: 4 (최근 30일)
LORENZO TUCCI
LORENZO TUCCI 2024년 4월 2일
답변: Muskan 2024년 6월 24일 6:23
Ciao, il problema riguarda una comunicazione seriale tra una teensy e un arduino. Io devo gestire la ricezione dei dati da parte dell'arduino con un modello simulink. Sto utilizzando il blocco serial receive ed il blocco protocol decoder, tuttavia i dati che invio non riesco a vederli in uscita dal blocco serial receive. Ho verificato che i dati vengano trasmessi facendo un breve codice nell'IDE di Arduino. Ho controllato anche che il numero della porta seriale e il baud rate siano corretti. Attualmente sto utilizzando un arduino Mega 2560 e un baud rate di 460800, ma ho provato anche con 115200. Attualmente sto inviando uno struct di 7 interi a 32bit.
Vorrei capire come risolvere.
Se servono ulteriori dettagli chiedete pure.
Grazie in anticipo per la disponibilità

답변 (1개)

Muskan
Muskan 2024년 6월 24일 6:23
As per my understanding of the query, to troubleshoot and solve the issue with serial communication between the Teensy and the Arduino Mega 2560 using Simulink, please follow these steps:
Step 1: Verify Hardware and Connections
  1. Check Connections: Ensure that the TX pin of the Teensy is connected to the RX pin of the Arduino Mega 2560, and the RX pin of the Teensy is connected to the TX pin of the Arduino Mega 2560.
  2. Common Ground: Ensure that both devices share a common ground.
Step 2: Verify Serial Communication in Arduino IDE
  • Since you have already verified the data transmission using the Arduino IDE, make sure the same settings are used in Simulink.
Step 3: Configure Simulink Model
  1. Serial Receive Block:
  • Set the correct serial port number (e.g., COMx).
  • Set the correct baud rate (e.g., 460800 or 115200).
  • Set the data type to uint8 if you are receiving raw bytes.
  • Set the data size to match the number of bytes you expect to receive (e.g., 28 bytes for 7 32-bit integers)
2. Protocol Decoder Block:
  • Configure the decoder to match the structure of the data being sent.
  • Ensure that the data type and size settings match the format of the transmitted data.
Step 4: Check Data Format and Endianness
  1. Data Packing: Ensure that the data is packed correctly on the Teensy side. For example, if you are sending a struct of 7 32-bit integers, ensure that each integer is packed correctly into the byte stream.
  2. Endianness: Ensure that both the Teensy and Arduino are using the same endianness (byte order) for the 32-bit integers.

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!