Comunicacion Serial

Páginas: 12 (2885 palabras) Publicado: 4 de diciembre de 2012
Using USB Serial CommunicationTeensyduino provides a Serial object which is compatible with the Serial object on standard Arduino boards. Usually Serial is used to print information to the Arduino IDE Serial Monitor. void setup() { Serial.begin(9600); // USB is always 12 Mbit/sec } voidloop() { Serial.println("Hello World..."); delay(1000); // do not print too fast! }Unlike a standard Arduino, the Teensy Serial object always communicates at 12 Mbit/sec USB speed. Many computes, especially older Macs, can not update the serial monitor window if there is no delay to limit the speed! In this example, "Hello World..."is printed once per second. The Teensy does not actually become a serial device until your sketch is running, so you must select the serial port (Tools -> Serial Port menu) after your sketch begins. Standard Serial FunctionsAll of the standard Serial functions are supported. Serial.begin()Initialize the Serial object. The baud rate is ignored and communication always occurs at full USB speed.Serial.print() and Serial.println()Print a number or string. Serial.print() prints only the number or string, and Serial.println() prints it with a newline character. // Serial.print() can print many different types int number = 1234; Serial.println("string"); // string Serial.println('a'); // singlecharacter Serial.println(number); // number (base 10 if 16 or 32 bit) Serial.println(number, DEC); // number, base 10 (default) Serial.println(number, HEX); // number, base 16/hexidecimal Serial.println(number, OCT); // number, base 8/octal Serial.println(number, BIN); // number, base 2/binarySerial.println(number, BYTE); // number, as a single byte Serial.println(3.14); // number in floating point, 2 digitsOn a standard Arduino, this function waits while the data is transmitted. With Teensyduino, Serial.print() and Serial.println() typically return quickly when the message fits within the USB buffers. See Transmit Buffering below. Serial.write()Transmita byte. Serial.available()Returns the number of received bytes available to read, or zero if nothing has been received. On a standard Arduino, Serial.available() tends to report individual bytes, whereas large blocks can become instantly available with Teensyduino. See Receive Buffering below for details. Usually the return value from Serial.available() should be tested as a boolean, either thereis or is not data available. Only the bytes available from the most recently received USB packet are visible. See Inefficient Single Byte USB Packets below for details. Serial.read()Read 1 byte (0 to 255), if available, or -1 if nothing available. Normally Serial.read() is used after Serial.available(). For example: if (Serial.available()) {incomingByte = Serial.read(); // will not be -1 // actually do something with incomingByte }Serial.flush()Discard any received data that has not been read. Teensy USB Serial ExtensionsTeensyduino provides extensions to the standard Arduino Serial object, so you can access USB-specific features. Serial.send_now()Transmit any buffered data as soon as possible. SeeTransmit Buffering below. Serial.dtr()Read the DTR signal state. By default, DTR is low when no software has the serial device open, and it goes high when a program opens the port. Some programs override this behavior, but for normal software you can use DTR to know when a program is using the serial port. void loop() { pinMode(6,...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Comunicacion serial
  • comunicación serial
  • Comunicacion Serial
  • Comunicacion Serial
  • Comunicación Serial Asincrona
  • Comunicacion serial y paralela
  • Comunicación serial con el pic16f877
  • comunicacion serial y transmision de bits

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS