TB2 001: LCD

Here’s a quick look at the code needed to use and write to the TB2’s LCD.

For this tutorial, we’ll just be using the LiquidCrystal.h library that comes standard with the Arduino IDE. For the TB2’s Quartet firmware, however, we’re using a custom library based on this one that reduces the delay times build into the standard library and reduces audio glitching.

First, we need to include the LCD library.

Next we need to initialize the library and tell it which of the Arduino DUE’s i/o pins we’re using. NOTE: Lines preceded by // are comments and are ignored by the compiler.

Now we get to the first of the two functions required by any Arduino sketch, the setup. In the. Inside the setup() function, we start with a line to initialize the display and to identify it as having 16 columns and two rows.

Next, we clear the display.

Then we set the position to 0 horizontal and 0 vertical (the top left corner).

And we write our first line.

We follow a similar process to set the position to the leftmost position in the second row, and to write the second line. We close the setup function with }.

That’s all the code we need to write to the LCD, but every Arduino sketch requires a setup() and a loop function. For now, we’ll just leave the loop function empty (well, there’s a comment in there, but comments are ignored).

And that’s it. Here’s the code in full again – you can copy it, paste it into the IDE and upload it to the Arduino DUE board on your TB2.

Experiment with the code (you’re highly unlikely to break something). Try changing the text. Note how text that is longer than 16 characters gets truncated.

To see all of the commands you can use with the LCD display, see the official LiquidCrystal Library reference.

Here’s the Arduino file if you prefer to download it rather than type it yourself: TB2_001_LCD

Leave a Reply

Your email address will not be published. Required fields are marked *