Experiment: Controlling an LCD Screen with Your Muscles
In many projects it is necessary to display information on a low cost screen. The best way to do it is using a display LCD.
What will you learn?
In this experiment you will be able to see a representation of the EMG signal that comes from the SpikerShield. This is displayed via a bar that moves proportionately to the muscle signal being read. Here we will use a common 16 x2 LCD model.
Equipment
Background
Originally designed and written by José Enrique López Pérez, student of Electronic Engineering in Oaxaca, Mexico.
Updated by Miguel Cornejo, high school student at Colegio Alberto Blest Gana in Santiago, Chile.
LCD screen: Liquid Crystal Display screens (LCD) have the capacity to show every alphanumeric character, allowing it to represent the information generated by any electronic equipment in an easy way and at low cost. The screen has a matrix of characters (usually 5x8 points) distributed in one, two or four lines of 16, 20, or even 40 characters each line. The most common configuration is two lines of 16 characters each ( 16x2, the first digit indicates the number of characters per line, and the second, the number of lines).
A character of 5x8 points
Pin functions in the LCD
There are two types of data that you can send to the LCD.
- Character data: when letters and numbers are sent to the LCD.
- Commands: When the LCD receives instructions like “Delete Display”, “Move Cursor”, “Move left”, etc...
LCD Functionality: The LCD modules are made of a crystal liquid screen and a micro-controller circuit. The Arduino microcontroller is in charge of receiving binary information through its pins D1 through D7 (it’s possible to use only pins D4 through D7) and to control this data through pins E, RS, and RW to show a group of characters and some symbols.
This LCD Module has an internal memory zone called CGROM where it stores a table with the 192 characters that can be displayed. Each character has its own binary representation of 8 bits. To display a character the LCD must receive the corresponding code through the data bus. For example, to display the character “A” the LCD must receive the following code: b’01000001’.....
But Wait!. There is a actually a much easier way to control LCDs, with only four cables using the more modern I²C protocol. There are only four cables connections we need between the LCD and the Arduino+Muscle SpikerShield: power, ground, SDL (serial data line), and SCL (serial clock line). The instructions continue below.
Downloads
Take our (.ino) LCD Sketch and load it on your Arduino
You will also need to add these two libraries (more info below).
Video
Procedure
The code
#include#include LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display #define MAX 800 //maximum possible reading. TWEAK THIS VALUE!! int finalReading; int Lit_Bank; void setup(){ Serial.begin(9600); //begin serial communica tions lcd.init(); // initialize the lcd lcd.init(); lcd.backlight(); } void loop(){ finalReading = analogRead(A0); // Reads in the Amplified EMG delay(25); // 10 ms delay lcd.clear(); // initialize the lcd Serial.print(finalReading); Serial.print("\t"); finalReading = constrain(finalReading, 0, MAX); Lit_Bank = map(finalReading, 0, MAX, 0, 16); // determines length of bar to light up depending on your EMG level Serial.println(Lit_Bank); if (Lit_Bank == 0) { lcd.setCursor(0,0); lcd.print(""); lcd.setCursor(0,1); lcd.print(""); } if (Lit_Bank == 1) { lcd.setCursor(0,0); lcd.print("0"); lcd.setCursor(0,1); lcd.print("0"); } if (Lit_Bank == 2) { lcd.setCursor(0,0); lcd.print("00"); lcd.setCursor(0,1); lcd.print("00"); } if (Lit_Bank == 3) { lcd.setCursor(0,0); lcd.print("000"); lcd.setCursor(0,1); lcd.print("000"); } if (Lit_Bank == 4) { lcd.setCursor(0,0); lcd.print("0000"); lcd.setCursor(0,1); lcd.print("0000"); } if (Lit_Bank == 5) { lcd.setCursor(0,0); lcd.print("00000"); lcd.setCursor(0,1); lcd.print("00000"); } if (Lit_Bank == 6) { lcd.setCursor(0,0); lcd.print("000000"); lcd.setCursor(0,1); lcd.print("000000"); } if (Lit_Bank == 7) { lcd.setCursor(0,0); lcd.print("0000000"); lcd.setCursor(0,1); lcd.print("0000000"); } if (Lit_Bank == 8) { lcd.setCursor(0,0); lcd.print("00000000"); lcd.setCursor(0,1); lcd.print("00000000"); } if (Lit_Bank == 9) { lcd.setCursor(0,0); lcd.print("000000000"); lcd.setCursor(0,1); lcd.print("000000000"); } if (Lit_Bank == 10) { lcd.setCursor(0,0); lcd.print("0000000000"); lcd.setCursor(0,1); lcd.print("0000000000"); } if (Lit_Bank == 11) { lcd.setCursor(0,0); lcd.print("00000000000"); lcd.setCursor(0,1); lcd.print("00000000000"); } if (Lit_Bank == 12) { lcd.setCursor(0,0); lcd.print("000000000000"); lcd.setCursor(0,1); lcd.print("000000000000"); } if (Lit_Bank == 13) { lcd.setCursor(0,0); lcd.print("0000000000000"); lcd.setCursor(0,1); lcd.print("0000000000000"); } if (Lit_Bank == 14) { lcd.setCursor(0,0); lcd.print("00000000000000"); lcd.setCursor(0,1); lcd.print("00000000000000"); } if (Lit_Bank == 15) { lcd.setCursor(0,0); lcd.print("000000000000000"); lcd.setCursor(0,1); lcd.print("000000000000000"); } if (Lit_Bank == 16) { lcd.setCursor(0,0); lcd.print("0000000000000000"); lcd.setCursor(0,1); lcd.print("0000000000000000"); } }