PDA

View Full Version : How do I use the Parallax Serial LCD with Teensy 3



tdg8934
11-12-2012, 01:15 AM
How do I use the Teensy3 with the Parallax serial LCD? I tried following the Arduino code at the bottom of this link and there was errors using SoftwareSerial:

http://learn.parallax.com/KickStart/27977

I connected Vin and GND and pin 6. Should I be using the hardware UART instead of this SoftwareSerial library?

Thanks for your help.

--------------------------------------------

const int TxPin = 6;

#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);

void setup() {

pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);

mySerial.begin(9600);
delay(100);
mySerial.write(12); // Clear
mySerial.write(17); // Turn backlight on
delay(5); // Required delay
mySerial.print("Hello, world..."); // First line
mySerial.write(13); // Form feed
mySerial.print("from Parallax!"); // Second line
mySerial.write(212); // Quarter note
mySerial.write(220); // A tone
delay(3000); // Wait 3 seconds
mySerial.write(18); // Turn backlight off

}

void loop() {
}

el_supremo
11-12-2012, 01:28 AM
Try connecting the LCD to pin 8 which is the Tx pin for Serial3. Remove the SoftwareSerial stuff and change all occurrences of "mySerial" to "Serial3".

Pete

tdg8934
11-12-2012, 09:22 AM
Thanks Pete.

I got it to work after doing what you said:

//const int TxPin = 8;

//#include <SoftwareSerial.h>
//SoftwareSerial Serial3 = SoftwareSerial(255, TxPin);

void setup() {

//pinMode(TxPin, OUTPUT);
//digitalWrite(TxPin, HIGH);

Serial3.begin(9600);
delay(100);
Serial3.write(12); // Clear
Serial3.write(17); // Turn backlight on
delay(5); // Required delay
Serial3.print("Hello, world..."); // First line
Serial3.write(13); // Form feed
Serial3.print("from Parallax!"); // Second line
Serial3.write(212); // Quarter note
Serial3.write(220); // A tone
delay(3000); // Wait 3 seconds
Serial3.write(18); // Turn backlight off

}

void loop() {
}


Specifically for the Teensy 3.0, Where can I find out more about this somewhat confusing Serial1,2,3 (hardware,software?). Why use Serial3 and not 1? Just wanting to learn more.

Thanks!

el_supremo
11-12-2012, 02:23 PM
I should have pointed out that the Teensy is a 3v3 device. I didn't check the LCD but it is a 5V device. You can usually get away with transmitting serial 3V3 to a 5V device but receiving would probably blow the Teensy pin. The safest thing is to have a level shifter between the two.
The choice of Serial3 was purely arbitrary - I happen to be using it in a sketch. Serial1, Serial2 and Serial3 are hardware so you'll probably never need to use SoftwareSerial :-)

Pete

Paul
11-12-2012, 03:50 PM
Pete is correct, usually the 3V output signal from Teensy 3.0 can drive a 5V input on a serial device. Most 5V devices recognize under 0.8V as low and above 2V as high (the actual low/high transition is typically 1.4V, but could be anywhere between 0.8 to 2 volts).

But the 3v input on Teensy 3.0 is not 5V tolerant. If you directly connect a 5 volt signal to the pin, it might damage the Teensy board.

To connect the 5V output from the serial device to a RX pin on Teensy 3.0, the simplest way is using a resistor. A value in the range of 4.7K to 22K is about right. Just connect one side of the resistor to the 5V output and the other side to the 3V input (RX1, RX2, or RX3) on Teensy 3.0.

The inputs on Teensy 3.0 have a protection diode connected between the pin and Vcc. When the display sends 5 volts, a small current will flow through the resistor and diode, delivering a tiny amount of power to Teensy 3.0. The internal diode is capable of handling up to 10 mA. Normally Teensy 3.0 uses about 27 mA. As long as no single pin has more than 10 mA through its diode, and the total of all pins connected this way is less than the total current used, you're safe.

Lower resistors put more current through the input diode, but they add less delay due to forming a RC low-pass filter together with the tiny capacitance on the pin (approx 10 pF). At 22K, the filter is 723 kHz, which is plenty fast enough for any reasonable baud rate.

You can also use a buffer chip to convert the signal. The 2 advantage of a buffer chip are much faster signal speed (not an issue... but you might care for a fast SPI device), and the buffer avoids the tiny current through the input diode. Normally that current isn't an issue, but it can be if you try to use the extremely low power sleep modes. First, if you're using the sleep modes, you probably want to minimize current, so "wasted" current through an input pin might be a big deal (but then, if you care about power you're probably running stuff at 3V). Second, the total of all the diode currents must be less than the current the chip is consuming, which is very low in those modes. If the total diode current is more than the chip's current, the chip's power voltage will rise, possibly damaging the chip. In those types of cases, you'd probably want to go to the trouble of using a buffer chip.

But in most normal uses, a 10K or 22K resistor works perfectly fine to connect between a 5V signal and a 3V input pin.

tdg8934
11-12-2012, 04:51 PM
Thanks Pete and Paul!

So the rule of thumb is:

For the Teensy 3.0 "3v3 outputs" (ie DIGITAL-DigitalWrite; PULSE WIDTH MOD-analogWrite; SERIAL-Serial1 (TX1), Serial2 (TX2), Serial3 (TX3); I2C-SDA?, SCL?; SPI-DOUT), I need to just connect a wire between them and the 5vdc input device (ie Serial LCD) because the 3v3 output from the Teensy 3.0 is within the 5vdc voltage range to make it work.

For the Teensy 3.0 "3v3 inputs" (ie DIGITAL-DigitalRead; ANALOG-analogRead; SERIAL-Serial1 (RX1), Serial2 (RX2), Serial3 (RX3); I2C-SDA?, SCL?; SPI-Everything except DOUT; TOUCH SENSING-touchRead), I need to use a 10K or 22K resistor between these inputs and the 5vdc input device (ie ??).

Let me know if I have this right.

Thank you.

Nantonos
11-13-2012, 08:35 AM
Specifically for the Teensy 3.0, Where can I find out more about this somewhat confusing Serial1,2,3 (hardware,software?). Why use Serial3 and not 1? Just wanting to learn more.


Standard Arduino boards (for example the Arduino Uno) have one serial controller (USART) in hardware. Also, this is connected to a serial-to-USB converter and thus to the USB socket. As the hardware serial is already in use for programming the chip and (often) for sending debug output over USB, people created a software serial implementation for when they wanted to talk to something other than the built-in serial-to-USB converter.

The serial implementation is slower, and ties up the software doing stuff that is better done with a cheap hardware chip.

More capable Arduino boards (such as the Arduino Mega2560) and the better Arduino-compatible boards (like Teensy 2.0, 2++ and 3.0) have multiple USARTs so they can maintain multiple hardware serial streams concurrently. The original hardware serial port was just called 'Serial' and the name can't be changed without affecting backwards compatibility (it should really be 'Serial0'); the extra ones were therefore called Serial1, Serial2 and Serial3.

Yes, you could have just as easily used Serial1 or Serial2 in your sketch.

The Teensy series have a useful extra feature over the Arduino boards. The USB is a native USB device rather than a serial port pretending to be a USB. This means that you can use your USB to emulate serial, but you can also set it to be, for example, a USB mouse, USB keyboard, USB joystick or a USB MIDI controller.

It also means that on Teensy boards, your Serial ('Serial0') is not tied up being one end of a serial-to-USB converter.

tdg8934
11-13-2012, 12:51 PM
Nantonos,

Thanks for your insight on this!

I did see an additional TX1 (faded out) on Digital pin 5 but it did not work like pin 1. Is this the additonal Serial (or Serial0) that you refered about?

However, I the code working on all 3 serial ports (TX) to the 5vdc serial Parallax LCD. Is there any specific Teensy 3.0 documentation pointing out these items such as Serial1, 2, 3 - or other Teensy 3.0 documentation I should be aware of?


// Teensy 3.0: (Digital Pins)
// Serial1 RX1 (pin 0), TX1 (pin 1)
// Serial2 RX2 (pin 9), TX2 (pin 10)
// Serial3 RX3 (pin 7), TX3 (pin 8)
//
// TX1, TX2 or TX3 digital pin goes to RX pin on serial Parallax LCD
// Vin pin provides +5vdc to the serial Parallax LCD
// GND pin provides GND to the serial Parallax LCD
//
//
// Arduino UNO: (Digital Pins)
// Serial RX (pin 0), TX (pin 1)
//
// 5V pin (Power) provides +5vdc to the serial Parallax LCD
// GND pin (Power) provides GND to the serial Parallax LCD
//
// Just replace all of the Serial3 commands with Serial (for use with the Arduino).
//
void setup() {

Serial3.begin(9600);
delay(100);
Serial3.write(12); // Clear
Serial3.write(17); // Turn backlight on
delay(5); // Required delay
Serial3.print("Hello, world..."); // First line
Serial3.write(13); // Form feed
Serial3.print("from Parallax!"); // Second line
Serial3.write(212); // Quarter note
Serial3.write(220); // A tone
delay(3000); // Wait 3 seconds
Serial3.write(18); // Turn backlight off
}
void loop() {
}



Thanks,

Tim

Paul
11-13-2012, 01:58 PM
I did see an additional TX1 (faded out) on Digital pin 5 but it did not work like pin 1.


Currently the software only supports the primary (black printed) pins. Right now, you can't use the grey ones... unless you write some tricky code to fiddle with the hardware registers.

At some point in the future, I will add functions to switch to using the grey pins instead of the black ones. Serial1.begin() on Teensy 3.0 will always default to pins 0 & 1, so when this extra function is added, your code using 0 & 1 will still work. You'll have to add an extra line, when the option becomes available, to switch to using pins 5 or 21.

donbrowne
01-23-2014, 03:07 AM
Thanks for posting the explanation of Serial1, Serial2 etc. here. I've been trying for hours to figure out why SoftwareSerial doesn't work.