Tutorial.SoftwareSerial History

Hide minor edits - Show changes to markup

June 05, 2010, at 07:16 PM by Equipo Traduccion -
Changed line 5 from:

En este tutorial aprenderas a implementar una comunicación serie asíncrona desde el programa de Arduino para comunicarte con otros dispositivos serie. Mediante la conexión serie por software podrás crear una conexión serie en cualquiera de los pines digitales E/S de Arduino. Esto debería ser usado cuando son necesarias varias conexiones serie. Si sólo es necesaria una conexión serie debería usarse el puerto serie hardware. Este es un tutorial del software de propósito general, NO un tutorial específico del dispositivo. Puedes encontrar un tutorial sobre comunicación con un ordenador aquí. Tutoriales sobre dispositivos específicos hay en la página de tutoriales. Para una buena explicación de comunicación serie mira

to:

En este tutorial aprenderás a implementar una comunicación serie asíncrona desde el programa de Arduino para comunicarte con otros dispositivos serie. Mediante la conexión serie por software podrás crear una conexión serie en cualquiera de los pines digitales E/S de Arduino. Esto debería ser usado cuando son necesarias varias conexiones serie. Si sólo es necesaria una conexión serie debería usarse el puerto serie hardware. Este es un tutorial del software de propósito general, NO un tutorial específico del dispositivo. Puedes encontrar un tutorial sobre comunicación con un ordenador aquí. Tutoriales sobre dispositivos específicos hay en la página de tutoriales. Para una buena explicación de comunicación serie mira

Changed lines 71-74 from:

Aquí configuramos las directrices de nuestra pre-compilación. Estas directrices de pre-compilación son procesadas anted de que la compilación real comience. Empiezan con "#" y no terminan con punto y coma.

Primer incluimos el fichero ctype.h en nuestra aplicación. esto nos da acceso a la función toupper() de la librería de C de operaciones con carácteres, que usaremos después en nuestro programa. Esta librería es parte de Arduino, así que no necesitas hacer nada más que escribir la línea #include para usarla. Después establecemos nuestras definiciones para el baudrate. Estas son las directrices de pre-compilación que definen los tiempos de espera para los diferentes baudrates. La línea #define bit9600Delay 84 hace que el compilador sustituya el número 85 en todos los sitios donde se encuentre la etiqueta "bit9600Delay". Las definiciones de pre-compilado se usan a menudo para constantes porque no utilizan espacio de memoría de programa en el microcontrolador.

to:

Aquí configuramos las directrices de nuestra pre-compilación. Estas directrices de pre-compilación son procesadas antes de que la compilación real comience. Empiezan con "#" y no terminan con punto y coma.

Primero incluimos el fichero ctype.h en nuestra aplicación. Esto nos da acceso a la función toupper() de la librería de C de operaciones con caracteres, que usaremos después en nuestro programa. Esta librería es parte de Arduino, así que no necesitas hacer nada más que escribir la línea #include para usarla. Después establecemos nuestras definiciones para el baudrate. Estas son las directrices de pre-compilación que definen los tiempos de espera para los diferentes baudrates. La línea #define bit9600Delay 84 hace que el compilador sustituya el número 85 en todos los sitios donde se encuentre la etiqueta "bit9600Delay". Las definiciones de pre-compilado se usan a menudo para constantes porque no utilizan espacio de memoria de programa en el microcontrolador.

Changed lines 79-80 from:

Aquí configuramos nuestros pines de transmisión (tx) y recepción (rx). Cambia los números de los pines para adaptarlo a tu aplicación. También asignamos una variable para guardar los datos rebibidos SWval.

to:

Aquí configuramos nuestros pines de transmisión (tx) y recepción (rx). Cambia los números de los pines para adaptarlo a tu aplicación. También asignamos una variable para guardar los datos recibidos SWval.

Changed lines 91-92 from:

Aquí inicializamos las líneas, encendemos nuestro LED de depuración y envíamos un mensaje de depuración para confirmar que todo está funcionando según lo planeado. Podemos pasar caracteres individuales a la función SWprint.

to:

Aquí inicializamos las líneas, encendemos nuestro LED de depuración y enviamos un mensaje de depuración para confirmar que todo está funcionando según lo planeado. Podemos pasar caracteres individuales a la función SWprint.

Changed lines 113-114 from:

Esta es la función SWprint. Primero la línea de transmisión se pne en bajo para señalar un bit de start. Luego, utilizando una máscara de bits vamos cambiando el valor de la salida del pin alto o bajo 8 veces para los 8 bits del valor a transmitir. Finalmente ponemos la línea en alto otra vez para señalar un bit de stop. Por cada bit que transmitimos, mantenemos la línea en alto o bajo el tiempo específicado. En este ejemplo estamos usando un baudrate de 9600. Para usar 4800 simplemente reemplaza la variable bit9600Delay por bit4800Delay.

to:

Esta es la función SWprint. Primero la línea de transmisión se pone en bajo para señalar un bit de inicio. Luego, utilizando una máscara de bits vamos cambiando el valor de la salida del pin alto o bajo 8 veces para los 8 bits del valor a transmitir. Finalmente ponemos la línea en alto otra vez para señalar un bit de parada. Por cada bit que transmitimos, mantenemos la línea en alto o bajo el tiempo especificado. En este ejemplo estamos usando un baudrate de 9600. Para usar 4800 simplemente reemplaza la variable bit9600Delay por bit4800Delay.

Changed line 133 from:

Esta es la función SWread. Esta función espera a que llegue un byte por el pin de recepción y luego lo devuelve en la variable asignada. Primero esperamos a que la línea de recepción se ponga en bajo. Comprobamos después de la mitad del tiempo de espera para estar seguros de que la línea está todavía en bajo y no estamos recibiendo simplemente ruido en la línea. Luego repetimos utilizando una máscara de bits y desplazamos unos (1) o ceros (0) en nuestro byte de salida basandonos en lo que recibimos. Finalmente permitimos una pausa para el bit de stop y luego devolvemos el valor.

to:

Esta es la función SWread. Esta función espera a que llegue un byte por el pin de recepción y luego lo devuelve en la variable asignada. Primero esperamos a que la línea de recepción se ponga en bajo. Comprobamos después de la mitad del tiempo de espera para estar seguros de que la línea está todavía en bajo y no estamos recibiendo simplemente ruido en la línea. Luego repetimos utilizando una máscara de bits y desplazamos unos (1) o ceros (0) en nuestro byte de salida basándonos en lo que recibimos. Finalmente permitimos una pausa para el bit de parada y luego devolvemos el valor.

Changed lines 141-142 from:

Finalmente implementamos el loop de nuestro programa principal. En este programa simplemente esperamos a que lleguen carácteres, los cambiamos a mayúsculas y los envíamos de vuelta. Este será siempre un buen programa para ejecutar cuando queramos estar seguros de que la conexión serie está funcionando correctamente.

to:

Finalmente implementamos el loop de nuestro programa principal. En este programa simplemente esperamos a que lleguen caracteres, los cambiamos a mayúsculas y los enviamos de vuelta. Este será siempre un buen programa para ejecutar cuando queramos estar seguros de que la conexión serie está funcionando correctamente.

June 05, 2010, at 07:08 PM by Equipo Traduccion -
Changed lines 133-134 from:

Esta es la función SWread. This is the SWread function. This will wait for a byte to arrive on the recieve pin and then return it to the allocated variable. First we wait for the recieve line to be pulled low. We check after a half bit delay to make sure the line is still low and we didn't just recieve line noise. Then we iterate through a bit mask and shift 1s or 0s into our output byte based on what we recieve. Finally we allow a pause for the stop bit and then return the value.

to:

Esta es la función SWread. Esta función espera a que llegue un byte por el pin de recepción y luego lo devuelve en la variable asignada. Primero esperamos a que la línea de recepción se ponga en bajo. Comprobamos después de la mitad del tiempo de espera para estar seguros de que la línea está todavía en bajo y no estamos recibiendo simplemente ruido en la línea. Luego repetimos utilizando una máscara de bits y desplazamos unos (1) o ceros (0) en nuestro byte de salida basandonos en lo que recibimos. Finalmente permitimos una pausa para el bit de stop y luego devolvemos el valor.

Changed lines 141-146 from:

Finally we implement our main program loop. In this program we simply wait for characters to arrive, change them to uppercase and send them back. This is always a good program to run when you want to make sure a serial connection is working properly.

For lots of fun serial devices check out the Sparkfun online catalog. They have lots of easy to use serial modules for GPS, bluetooth, wi-fi, LCDs, etc.

For easy copy and pasting the full program text of this tutorial is below:

to:

Finalmente implementamos el loop de nuestro programa principal. En este programa simplemente esperamos a que lleguen carácteres, los cambiamos a mayúsculas y los envíamos de vuelta. Este será siempre un buen programa para ejecutar cuando queramos estar seguros de que la conexión serie está funcionando correctamente.

Para ver montones de dispositivos serie mira el catálogo online de Sparkfun. Tienen montones de módulos fáciles de usar para GPS, bluetooth, wi-fi, LCD's, etc.

Para facilitarte el trabajo, copia y pega el programa completo de este tutorial:

Changed line 217 from:

code and tutorial by Heather Dewey-Hagborg

to:

Código y tutorial de Heather Dewey-Hagborg

June 05, 2010, at 06:55 PM by Equipo Traduccion -
Changed lines 3-4 from:

Nota: ''Si sólo quieres usar un interfaz serie por software, mira la librería SoftwareSerial incluida en Arduino 0007 y posteriores. Léelo si quieres saber cómo funciona esa librería.

to:

Nota: Si sólo quieres usar un interfaz serie por software, mira la librería SoftwareSerial incluida en Arduino 0007 y posteriores. Léelo si quieres saber cómo funciona esa librería.

Changed lines 73-74 from:

Primer incluimos el fichero ctype.h en nuestra aplicación. esto nos da acceso a la función toupper() de la librería de C de operaciones con carácteres, que usaremos después en nuestro programa. Esta librería es parte de Arduino, así que no necesitas hacer nada más que escribir la línea #include para usarla. Después establecemos nuestras definiciones para el baudrate. Estas son las directrices de pre-compilación que definen los tiempos de espera para los diferentes baudrates. La línea #define bit9600Delay 84 hace que el compilador sustituya el número 85 en todos los sitios donde se encuentre oala etiqueta "bit9600Delay 84 @] line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip.

to:

Primer incluimos el fichero ctype.h en nuestra aplicación. esto nos da acceso a la función toupper() de la librería de C de operaciones con carácteres, que usaremos después en nuestro programa. Esta librería es parte de Arduino, así que no necesitas hacer nada más que escribir la línea #include para usarla. Después establecemos nuestras definiciones para el baudrate. Estas son las directrices de pre-compilación que definen los tiempos de espera para los diferentes baudrates. La línea #define bit9600Delay 84 hace que el compilador sustituya el número 85 en todos los sitios donde se encuentre la etiqueta "bit9600Delay". Las definiciones de pre-compilado se usan a menudo para constantes porque no utilizan espacio de memoría de programa en el microcontrolador.

Changed lines 79-80 from:

Here we set our transmit (tx) and recieve (rx) pins. Change the pin numbers to suit your application. We also allocate a variable to store our recieved data in, SWval.

to:

Aquí configuramos nuestros pines de transmisión (tx) y recepción (rx). Cambia los números de los pines para adaptarlo a tu aplicación. También asignamos una variable para guardar los datos rebibidos SWval.

Changed lines 91-92 from:

Here we initialize the lines, turn on our debugging LED and print a debugging message to confirm all is working as planned. We can pass inidvidual characters or numbers to the SWprint function.

to:

Aquí inicializamos las líneas, encendemos nuestro LED de depuración y envíamos un mensaje de depuración para confirmar que todo está funcionando según lo planeado. Podemos pasar caracteres individuales a la función SWprint.

Changed lines 113-114 from:

This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable bit9600Delay with bit4800Delay.

to:

Esta es la función SWprint. Primero la línea de transmisión se pne en bajo para señalar un bit de start. Luego, utilizando una máscara de bits vamos cambiando el valor de la salida del pin alto o bajo 8 veces para los 8 bits del valor a transmitir. Finalmente ponemos la línea en alto otra vez para señalar un bit de stop. Por cada bit que transmitimos, mantenemos la línea en alto o bajo el tiempo específicado. En este ejemplo estamos usando un baudrate de 9600. Para usar 4800 simplemente reemplaza la variable bit9600Delay por bit4800Delay.

Added line 133:

Esta es la función SWread.

June 05, 2010, at 06:29 PM by Equipo Traduccion -
Changed lines 22-23 from:

Envía un entero de longiud unn byte a través de la conexión serie por software

to:

Envía un entero de longitud un byte a través de la conexión serie por software

Changed lines 71-74 from:

Here we set up our pre-processor directives. Pre-processor directives are processed before the actual compilation begins. They start with a "#" and do not end with semi-colons.

First we include the file ctype.h in our application. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. This library is part of the Arduino install, so you don't need to do anything other than type the #include line in order to use it. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip.

to:

Aquí configuramos las directrices de nuestra pre-compilación. Estas directrices de pre-compilación son procesadas anted de que la compilación real comience. Empiezan con "#" y no terminan con punto y coma.

Primer incluimos el fichero ctype.h en nuestra aplicación. esto nos da acceso a la función toupper() de la librería de C de operaciones con carácteres, que usaremos después en nuestro programa. Esta librería es parte de Arduino, así que no necesitas hacer nada más que escribir la línea #include para usarla. Después establecemos nuestras definiciones para el baudrate. Estas son las directrices de pre-compilación que definen los tiempos de espera para los diferentes baudrates. La línea #define bit9600Delay 84 hace que el compilador sustituya el número 85 en todos los sitios donde se encuentre oala etiqueta "bit9600Delay 84 @] line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip.

June 05, 2010, at 10:20 AM by Equipo Traduccion -
Changed lines 3-4 from:

Nota: ''Si sólo quieres usar un interfaz serie por software, mira la librería SoftwareSerial incluida en Arduino 0007 y posteriores. Leelo si quieres saber cómo funciona esa librería

to:

Nota: ''Si sólo quieres usar un interfaz serie por software, mira la librería SoftwareSerial incluida en Arduino 0007 y posteriores. Léelo si quieres saber cómo funciona esa librería.

Changed lines 6-12 from:

Device specific tutorials are on the Tutorial Page. For a good explanation of serial communication see Wikipedia. The software serial connection can run at 4800 baud or 9600 baud reliably.

Functions Available:

to:

Wikipedia.

La conexión serie por software puede funcionar a 4800 o a 9600 baudios.

Funciones disponibles:

Changed lines 13-15 from:

Returns a byte long integer value from the software serial connection

Example:

to:

Devuelve un entero de longitud un byte de la conexión serie por software

Ejemplo:

Deleted line 20:
Changed lines 22-25 from:

Sends a byte long integer value out the software serial connection

Example:

to:

Envía un entero de longiud unn byte a través de la conexión serie por software

Ejemplo:

Changed line 33 from:

Definitions Needed:

to:

Definiciones necesarias:

Changed lines 40-53 from:

These definitions set the delays necessary for 9600 baud and 4800 baud software serial operation.

Materials needed:

  • Device to communicate with
  • Solderless breadboard
  • Hookup wire
  • Arduino Microcontroller Module
  • Light emitting Diode (LED) - optional, for debugging

Prepare the breadboard

Insert the device you want to communicate with in the breadboard. Connect ground on the breadboard to ground from the microcontroller. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion. Make any other connections necessary for your device. Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground.

to:

Estas definiciones configuran los tiempos de espera necesarios para el funcionamiento del puerto serie a 9600 baudios y 4800 baudios.

Material necesario:

  • Dispositivo con el que comunicar
  • Placa de entrenamiento
  • Cables
  • Placa Arduino
  • LED - opcional, para depurar

Prepara la placa de entrenamiento

Conecta el dispositivo con el que quieres comunicarte en la placa de entrenamiento. Conecta la tierra de la placa de entrenamiento a la tierra del Arduino. Si tu dispositivo utiliza alimentación de 5V conecta el pin de 5V de la placa Arduino a los 5V de la placa de entrenamiento. Si no es así conecta alimentación y tierra de una fuente de alimentación alternativa a la placa de entrenamiento. Haz otras conexiones si son necesarias para tu dispositivo. Adicionalmente es posible que quieras conectar el LED para depurar entre el pin 13 y tierra.

Changed lines 56-57 from:

Decide which pins you want to use for transmitting and receiving. In this example we will use pin 7 for transmitting and pin 6 for receiving, but any of the digital pins should work.

to:

Decide que pines quieres usar para transmitir y para recibir. En este ejemplo usaremos el pin 7 para transmitir y el pin 6 para recibir, pero cualquiera de los pines digitales debería funcionar.

Changed lines 60-63 from:

Program the Arduino

Now we will write the code to enable serial data communication. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. We will walk through the code in small sections.

to:

Programa el Arduino

Ahora programaremos el código para habilitar la comunicación serie. Este programa simplemente esperará un carácter que llegará por el puerto serie, luego lo transmite de vuelta en mayúsculas por el puerto serie. Este es un buen programa general para comprobar el puerto serie, deberías ser capaz de extrapolarlo para cubrir tus necesidades de puerto serie. Vamos a examinar el código por secciones.

June 05, 2010, at 10:00 AM by Equipo Traduccion -
Changed lines 1-7 from:

Arduino Software Serial Interface

Note: If you just want to use a software serial interface, see the SoftwareSerial library included with Arduino 0007 and later. Read on if you'd like to know how that library works.

In this tutorial you will learn how to implement Asynchronous serial communication on the Arduino in software to communicate with other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page. For a good explanation of serial communication see Wikipedia.

to:

Interfaz Serie por Software para Arduino

Nota: ''Si sólo quieres usar un interfaz serie por software, mira la librería SoftwareSerial incluida en Arduino 0007 y posteriores. Leelo si quieres saber cómo funciona esa librería

En este tutorial aprenderas a implementar una comunicación serie asíncrona desde el programa de Arduino para comunicarte con otros dispositivos serie. Mediante la conexión serie por software podrás crear una conexión serie en cualquiera de los pines digitales E/S de Arduino. Esto debería ser usado cuando son necesarias varias conexiones serie. Si sólo es necesaria una conexión serie debería usarse el puerto serie hardware. Este es un tutorial del software de propósito general, NO un tutorial específico del dispositivo. Puedes encontrar un tutorial sobre comunicación con un ordenador aquí. Tutoriales sobre dispositivos específicos hay en la página de tutoriales. Para una buena explicación de comunicación serie mira

Device specific tutorials are on the Tutorial Page. For a good explanation of serial communication see Wikipedia.

February 26, 2007, at 05:40 PM by David A. Mellis -
Added lines 3-4:

Note: If you just want to use a software serial interface, see the SoftwareSerial library included with Arduino 0007 and later. Read on if you'd like to know how that library works.

September 05, 2006, at 07:55 PM by Heather Dewey-Hagborg -
Changed lines 214-216 from:

}@]

to:

}@]

code and tutorial by Heather Dewey-Hagborg

August 29, 2006, at 07:46 PM by Heather Dewey-Hagborg -
Changed lines 53-54 from:
to:
Changed lines 57-58 from:
to:
August 29, 2006, at 07:34 PM by Heather Dewey-Hagborg -
Changed lines 11-12 from:

Returns a byte long integer value

to:

Returns a byte long integer value from the software serial connection

August 29, 2006, at 07:25 PM by Heather Dewey-Hagborg -
Changed line 10 from:

SWread();

to:

SWread();

Changed line 20 from:

SWprint();

to:

SWprint();

August 29, 2006, at 07:19 PM by Heather Dewey-Hagborg -
Added lines 10-13:

SWread();

Returns a byte long integer value

Example:

Changed lines 15-16 from:

SWread();

to:

byte RXval; RXval = SWread();

Changed lines 18-19 from:

Returns a byte long integer value

to:

SWprint();

Sends a byte long integer value out the software serial connection

Added line 24:
Changed lines 26-27 from:

byte RXval; RXval = SWread();

to:

byte TXval = 'h'; byte TXval2 = 126; SWprint(TXval); SWprint(TXval2);

Added line 32:

Definitions Needed:

Changed lines 34-37 from:

SWprint();

to:
  1. define bit9600Delay 84
  2. define halfBit9600Delay 42
  3. define bit4800Delay 188
  4. define halfBit4800Delay 94
Deleted lines 38-55:

Sends a byte long integer value out the software serial connection

Example:

byte TXval = 'h';
byte TXval2 = 126;
SWprint(TXval);
SWprint(TXval2);

Definitions Needed:

#define bit9600Delay 84  
#define halfBit9600Delay 42
#define bit4800Delay 188 
#define halfBit4800Delay 94

August 29, 2006, at 07:18 PM by Heather Dewey-Hagborg -
Added line 10:

[@

Added line 12:

@]

Added line 16:

[@

Changed lines 19-21 from:
to:

@]

[@

Added line 23:

@]

Added lines 27-28:

[@

Changed lines 33-34 from:
to:

@]

Changed line 36 from:
to:

[@

Changed line 41 from:
to:

@]

August 29, 2006, at 07:15 PM by Heather Dewey-Hagborg -
Changed lines 5-6 from:

other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page. For a good explanation of serial communication see Wikipedia.

to:

other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page. For a good explanation of serial communication see Wikipedia. The software serial connection can run at 4800 baud or 9600 baud reliably.

Functions Available:

SWread(); Returns a byte long integer value

Example: byte RXval; RXval = SWread();

SWprint(); Sends a byte long integer value out the software serial connection

Example: byte TXval = 'h'; byte TXval2 = 126; SWprint(TXval); SWprint(TXval2);

Definitions Needed:

  1. define bit9600Delay 84
  2. define halfBit9600Delay 42
  3. define bit4800Delay 188
  4. define halfBit4800Delay 94

These definitions set the delays necessary for 9600 baud and 4800 baud software serial operation.

August 23, 2006, at 09:09 PM by Heather Dewey-Hagborg -
Changed line 113 from:

//Created July 2006

to:

//Created August 15 2006

August 23, 2006, at 09:08 PM by Heather Dewey-Hagborg -
Added lines 113-116:

//Created July 2006 //Heather Dewey-Hagborg //http://www.arduino.cc

August 16, 2006, at 03:16 AM by Tom Igoe -
Changed lines 38-39 from:

First we include the file ctype.h in our application. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip.

to:

First we include the file ctype.h in our application. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. This library is part of the Arduino install, so you don't need to do anything other than type the #include line in order to use it. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip.

Changed line 86 from:
    delayMicroseconds(halfbit9600Delay);
to:
    delayMicroseconds(halfBit9600Delay);
Changed line 160 from:
    delayMicroseconds(halfbit9600Delay);
to:
    delayMicroseconds(halfBit9600Delay);
August 15, 2006, at 09:32 PM by Heather Dewey-Hagborg -
Changed lines 19-20 from:

Attach: pwr_wires_web.jpg

to:
Changed lines 23-24 from:

Attach: ser_wires_web.jpg

to:
August 15, 2006, at 09:30 PM by Heather Dewey-Hagborg -
Changed lines 19-20 from:

picture of device with connections

to:

Attach: pwr_wires_web.jpg

Changed lines 23-24 from:

picture of device with serial connections

to:

Attach: ser_wires_web.jpg

August 15, 2006, at 06:44 PM by Heather Dewey-Hagborg -
August 15, 2006, at 06:42 PM by Heather Dewey-Hagborg -
Changed lines 78-79 from:

This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable bit9600Delay with bit4800Delay.

to:

This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable bit9600Delay with bit4800Delay.

August 15, 2006, at 06:40 PM by Heather Dewey-Hagborg -
August 15, 2006, at 06:37 PM by Heather Dewey-Hagborg -
Changed line 3 from:

In this tutorial you will learn how to implement serial

to:

In this tutorial you will learn how to implement Asynchronous serial

Changed lines 5-6 from:

other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page.

to:

other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page. For a good explanation of serial communication see Wikipedia.

Changed lines 27-28 from:

Now we will write the code to enable serial data transmission. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. We will walk through the code in small sections.

to:

Now we will write the code to enable serial data communication. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. We will walk through the code in small sections.

August 15, 2006, at 06:22 PM by Heather Dewey-Hagborg -
Changed lines 36-37 from:

Here we set up our pre-processor directives. Pre-processor directives are processed before the actual compilation begins. They start with a "#" and do not end with semi-colons. First we include the file ctype.h in our application. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip.

to:

Here we set up our pre-processor directives. Pre-processor directives are processed before the actual compilation begins. They start with a "#" and do not end with semi-colons.

First we include the file ctype.h in our application. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip.

August 15, 2006, at 06:21 PM by Heather Dewey-Hagborg -
Changed lines 36-37 from:

Here we import the file ctype.h to our application. This gives us access to the toupper() function from the Character Operations C library. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates.

to:

Here we set up our pre-processor directives. Pre-processor directives are processed before the actual compilation begins. They start with a "#" and do not end with semi-colons. First we include the file ctype.h in our application. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip.

August 15, 2006, at 05:57 PM by Heather Dewey-Hagborg -
Changed lines 104-105 from:

Finally we implement our main program loop. In this program we simply wait for characters to arrive, chnge them to uppercase and send them back. This is always a good program to run when you want to make sure a serial connection is working properly.

to:

Finally we implement our main program loop. In this program we simply wait for characters to arrive, change them to uppercase and send them back. This is always a good program to run when you want to make sure a serial connection is working properly.

August 13, 2006, at 06:19 PM by Heather Dewey-Hagborg -
Changed line 101 from:
    SWprint(to_upper(SWval));
to:
    SWprint(toupper(SWval));
Changed line 173 from:
    SWprint(to_upper(SWval));
to:
    SWprint(toupper(SWval));
August 13, 2006, at 06:12 PM by Heather Dewey-Hagborg -
Changed lines 36-37 from:

Here we import the file ctype.h to our application. This gives us access to the toupper() function from the standard C library. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates.

to:

Here we import the file ctype.h to our application. This gives us access to the toupper() function from the Character Operations C library. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates.

August 13, 2006, at 06:03 PM by Heather Dewey-Hagborg -
Changed lines 5-6 from:

other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page.

to:

other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page.

Added line 48:
  digitalWrite(13,HIGH); //turn on debugging LED
Changed lines 54-55 from:

Here we initialize the lines and print a debugging message to confirm all is working as planned. We can pass inidvidual characters or numbers to the SWprint function.

to:

Here we initialize the lines, turn on our debugging LED and print a debugging message to confirm all is working as planned. We can pass inidvidual characters or numbers to the SWprint function.

Added line 126:
  digitalWrite(13,HIGH); //turn on debugging LED
August 13, 2006, at 06:00 PM by Heather Dewey-Hagborg -
Changed lines 39-41 from:

byte tx = 7;@] byte SWval;

to:

byte tx = 7; byte SWval;@]

Added lines 102-172:

Finally we implement our main program loop. In this program we simply wait for characters to arrive, chnge them to uppercase and send them back. This is always a good program to run when you want to make sure a serial connection is working properly.

For lots of fun serial devices check out the Sparkfun online catalog. They have lots of easy to use serial modules for GPS, bluetooth, wi-fi, LCDs, etc.

For easy copy and pasting the full program text of this tutorial is below:

#include <ctype.h>

#define bit9600Delay 84  
#define halfBit9600Delay 42
#define bit4800Delay 188 
#define halfBit4800Delay 94 

byte rx = 6;
byte tx = 7;
byte SWval;

void setup() {
  pinMode(rx,INPUT);
  pinMode(tx,OUTPUT);
  digitalWrite(tx,HIGH);
  SWprint('h');  //debugging hello
  SWprint('i');
  SWprint(10); //carriage return
}

void SWprint(int data)
{
  byte mask;
  //startbit
  digitalWrite(tx,LOW);
  delayMicroseconds(bit9600Delay);
  for (mask = 0x01; mask>0; mask <<= 1) {
    if (data & mask){ // choose bit
     digitalWrite(tx,HIGH); // send 1
    }
    else{
     digitalWrite(tx,LOW); // send 0
    }
    delayMicroseconds(bit9600Delay);
  }
  //stop bit
  digitalWrite(tx, HIGH);
  delayMicroseconds(bit9600Delay);
}

int SWread()
{
  byte val = 0;
  while (digitalRead(rx));
  //wait for start bit
  if (digitalRead(rx) == LOW) {
    delayMicroseconds(halfbit9600Delay);
    for (int offset = 0; offset < 8; offset++) {
     delayMicroseconds(bit9600Delay);
     val |= digitalRead(rx) << offset;
    }
    //wait for stop bit + extra
    delayMicroseconds(bit9600Delay); 
    delayMicroseconds(bit9600Delay);
    return val;
  }
}

void loop()
{
    SWval = SWread(); 
    SWprint(to_upper(SWval));
}
August 13, 2006, at 05:55 PM by Heather Dewey-Hagborg -
Changed lines 29-31 from:

[@#define bit9600Delay 84

to:

[@#include <ctype.h>

  1. define bit9600Delay 84
Changed lines 36-37 from:

Here we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates.

to:

Here we import the file ctype.h to our application. This gives us access to the toupper() function from the standard C library. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates.

Changed lines 40-42 from:

Here we set our transmit (tx) and recieve (rx) pins. Change the pin numbers to suit your application.

to:

byte SWval;

Here we set our transmit (tx) and recieve (rx) pins. Change the pin numbers to suit your application. We also allocate a variable to store our recieved data in, SWval.

Added lines 96-101:
void loop()
{
    SWval = SWread(); 
    SWprint(to_upper(SWval));
}
August 13, 2006, at 05:48 PM by Heather Dewey-Hagborg -
Changed lines 78-79 from:
  // confirm that this is a real start bit, not line noise
to:
  //wait for start bit
Deleted lines 79-80:
    // frame start indicated by a falling edge and low start bit
    // jump to the middle of the low start bit
Deleted lines 80-81:
    // offset of the bit in the byte: from 0 (LSB) to 7 (MSB)
Deleted line 81:
     // jump to middle of next bit
Deleted lines 82-83:
     // read bit
Changed line 85 from:
    //pause for stop bit
to:
    //wait for stop bit + extra
Added line 93:
August 13, 2006, at 05:47 PM by Heather Dewey-Hagborg -
Changed lines 5-6 from:

other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. And device specific tutorials are on the Tutorial Page.

to:

other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page.

Added lines 73-101:
int SWread()
{
  byte val = 0;
  while (digitalRead(rx));

  // confirm that this is a real start bit, not line noise
  if (digitalRead(rx) == LOW) {
    // frame start indicated by a falling edge and low start bit
    // jump to the middle of the low start bit
    delayMicroseconds(halfbit9600Delay);

    // offset of the bit in the byte: from 0 (LSB) to 7 (MSB)
    for (int offset = 0; offset < 8; offset++) {
     // jump to middle of next bit
     delayMicroseconds(bit9600Delay);

     // read bit
     val |= digitalRead(rx) << offset;
    }
    //pause for stop bit
    delayMicroseconds(bit9600Delay); 
    delayMicroseconds(bit9600Delay);
    return val;
  }
}

This is the SWread function. This will wait for a byte to arrive on the recieve pin and then return it to the allocated variable. First we wait for the recieve line to be pulled low. We check after a half bit delay to make sure the line is still low and we didn't just recieve line noise. Then we iterate through a bit mask and shift 1s or 0s into our output byte based on what we recieve. Finally we allow a pause for the stop bit and then return the value.

August 13, 2006, at 05:38 PM by Heather Dewey-Hagborg -
Changed lines 72-73 from:

This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable "bit9600Delay" with "bit4800Delay".

to:

This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable bit9600Delay with bit4800Delay.

August 13, 2006, at 05:38 PM by Heather Dewey-Hagborg -
Changed line 29 from:

[@#define bit9600Delay 84 //total 104us

to:

[@#define bit9600Delay 84

Changed line 31 from:
  1. define bit4800Delay 188 //total 208us
to:
  1. define bit4800Delay 188
Changed lines 34-35 from:
to:

Here we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates.

byte rx = 6;
byte tx = 7;

Here we set our transmit (tx) and recieve (rx) pins. Change the pin numbers to suit your application.

void setup() {
  pinMode(rx,INPUT);
  pinMode(tx,OUTPUT);
  digitalWrite(tx,HIGH);
  SWprint('h');  //debugging hello
  SWprint('i');
  SWprint(10); //carriage return
}

Here we initialize the lines and print a debugging message to confirm all is working as planned. We can pass inidvidual characters or numbers to the SWprint function.

void SWprint(int data)
{
  byte mask;
  //startbit
  digitalWrite(tx,LOW);
  delayMicroseconds(bit9600Delay);
  for (mask = 0x01; mask>0; mask <<= 1) {
    if (data & mask){ // choose bit
     digitalWrite(tx,HIGH); // send 1
    }
    else{
     digitalWrite(tx,LOW); // send 0
    }
    delayMicroseconds(bit9600Delay);
  }
  //stop bit
  digitalWrite(tx, HIGH);
  delayMicroseconds(bit9600Delay);
}

This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable "bit9600Delay" with "bit4800Delay".

August 13, 2006, at 05:27 PM by Heather Dewey-Hagborg -
Added lines 22-36:

picture of device with serial connections

Program the Arduino

Now we will write the code to enable serial data transmission. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. We will walk through the code in small sections.

#define bit9600Delay 84  //total 104us
#define halfBit9600Delay 42
#define bit4800Delay 188 //total 208us
#define halfBit4800Delay 94 

August 13, 2006, at 05:19 PM by Heather Dewey-Hagborg -
Changed lines 17-19 from:

Insert the device you want to communicate with in the breadboard. Connect ground on the breadboard to ground from the microcontroller. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion. Make any other connections necessary for your device.

picture of device with connections

to:

Insert the device you want to communicate with in the breadboard. Connect ground on the breadboard to ground from the microcontroller. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion. Make any other connections necessary for your device. Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground.

picture of device with connections

Decide which pins you want to use for transmitting and receiving. In this example we will use pin 7 for transmitting and pin 6 for receiving, but any of the digital pins should work.

August 13, 2006, at 05:05 PM by Heather Dewey-Hagborg -
Changed lines 17-19 from:

Insert the device you want to communicate with in the breadboard.

to:

Insert the device you want to communicate with in the breadboard. Connect ground on the breadboard to ground from the microcontroller. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion. Make any other connections necessary for your device.

picture of device with connections

August 13, 2006, at 04:51 PM by Heather Dewey-Hagborg -
Added lines 1-17:

Arduino Software Serial Interface

In this tutorial you will learn how to implement serial communication on the Arduino in software to communicate with other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. And device specific tutorials are on the Tutorial Page.

Materials needed:

  • Device to communicate with
  • Solderless breadboard
  • Hookup wire
  • Arduino Microcontroller Module
  • Light emitting Diode (LED) - optional, for debugging

Prepare the breadboard

Insert the device you want to communicate with in the breadboard.

Share