[Arduino] Arduino receives strings
Related Articles [Arduino] Getting Started [10] communication between the Arduino bluetooth module and Android
In [Arduino] development entry [10] communication between the Arduino bluetooth module and Android, only single characters are sent.
Arduino Serial. read () can only read one byte at a time. The following method describes how to implement string communication.
Compilation requires only one piece of Arduino. Of course, you can use the [Arduino] development entry [10] Arduino bluetooth module to communicate with Android.
You can use the serial port monitor of the Arduino compiler to see the result. What text will be input and what text will be returned below.
Implementation Code, posted a lot on the Internet
String comdata = (Serial.available() > += (comdata.length() > =
The code is simple. comdata is a string type variable. Serial. available () is the data volume of the current Serial port buffer pool. Serial. read () is a read buffer pool statement that can only read one byte at a time.
With the String type variable, it is easy to add characters to strings, as well as troubles such as String output and value assignment, so the simple code can process serial data.
Note that delay (2) cannot be deleted when reading the serial port; otherwise, the serial port buffer does not have enough time to accept data. An error occurs even if the latency is reduced. The specific value can also be determined by the experiment.
Another reminder is that comdata is a string and an array. If each word is referenced, comdata [0] And comdata [1] can be used. Comdata [n]. If we want to retrieve each byte, we can use each reference.
Related Articles
[Arduino] Getting started with development tutorial [1] What is Arduino [Ardunio] Getting started with development tutorial [2] Data Type [Arduino] Getting started with development tutorial [3] Arduino development tool [Arduino] Getting started with development tutorial [4] Arduino Driver Installation [Arduino] development tutorial [5] Hello Arduino [Arduino] development tutorial [6] data type conversion function [Arduino] development tutorial [7] 7-segment display implementation + Source Code [Arduino] Getting Started development tutorial [8] steering gear operation + Source Code [Arduino] Getting Started [10] communication between the Arduino bluetooth module and Android
//////////////////////////////////////// //////
Reprinted original statement, please note
This article is from Ray-Ray's blog
Document address http://www.cnblogs.com/rayray/p/3198091.html
Thank you for your recommendation and favorites.
Your support! Our motivation!