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.

#include <LiquidCrystal.h>

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.

// *** LCD ***
// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

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.

void setup() {
  // *** LCD ***
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

Next, we clear the display.

lcd.clear();

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

lcd.setCursor(0, 0);

And we write our first line.

lcd.print("Groovesizer");

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 }.

  lcd.setCursor(0, 1);
  lcd.print("TB2 001 LCD");
}

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).

void loop() {
  // put your main code here, to run repeatedly:

}

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.

#include <LiquidCrystal.h>

// *** LCD ***
// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // *** LCD ***
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Groovesizer");
  lcd.setCursor(0, 1);
  lcd.print("TB2 001 LCD");
}

void loop() {
  // put your main code here, to run repeatedly:

}

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 *