Low Level: Serial Ports
|
The Serial_LCD library can use three kinds of serial port:
|
|
Arduino
|
chipKIT
|
Wiring
|
|
The ProxySerial.h library is a hardware abstraction library that manages the different kinds of serial ports and allows portability.
|
Hardware Serial Port
|
The Arduino Uno features one hardware serial port, mainly used for debugging.
But other boards like the Arduino mega2560, the Wiring S and the chipKIT Uno32, have additional ports. On the right, an example with port Serial1. Maximum speeds are:
|
// Include
#include "ProxySerial.h" #include "Serial_LCD.h" // Serial port choice #define mySerial Serial1 ProxySerial myPort(&mySerial); Serial_LCD myLCD( &myPort); // Serial port initialisation mySerial.begin(9600); myLCD.begin(); // Serial port speed up myLCD.setSpeed(38400); mySerial.begin(38400); |
Software Serial Port
|
The Arduino Uno features one hardware serial port, mainly used for debugging.
Hence the software serial port brought by NewSoftSerial.h for Arduino 23 or SoftwareSerial.h for Arduino 1.0. Maximum speeds are:
For Arduino 23, please use the NewSoftSerial release 11 beta and follow instructions provided at Tutorial 2: Playing with Serial Ports. |
// Include
#include "SoftwareSerial.h" // for Arduino 1.0 #include "ProxySerial.h" #include "Serial_LCD.h" // Serial port choice SoftwareSerial mySerial(2, 3); // RX, TX pins ProxySerial myPort(&mySerial); Serial_LCD myLCD( &myPort); // Serial port initialisation mySerial.begin(9600); myLCD.begin(); // Serial port speed up myLCD.setSpeed(38400); mySerial.begin(38400); |
I²C Serial Port
|
I²C to serial port bridge provides an extra serial port right on the I²C bus.
The specific I2C_Serial library is required. Just proceed as shown in the example on the right: Maximum speeds are:
|
// Include
#include "I2C_Serial.h" #include "ProxySerial.h" #include "Serial_LCD.h" // Serial port choice I2C_Serial mySerial; ProxySerial myPort(&mySerial); Serial_LCD myLCD( &myPort); // Serial port initialisation mySerial.begin(9600); myLCD.begin(); // Serial port speed up myLCD.setSpeed(38400); mySerial.begin(38400); |
Final Recommendation
|
Remember the LCD board is powered by a 12 MHz controller.
So it works fine with a 16 MHz Arduino board but issues may arise with the over-speedy 80 MHz chipKIT Uno32. While working with the chipKIT Uno32, consider including delay() in your code when appropriate, and specify a higher value for the securityDelay parameter. Learn more about Overload Protection. |
#define securityDelay 3
|