[Arduino] Arduino receives strings

Source: Internet
Author: User

[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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.