Backyard Brains Logo

Neuroscience for Everyone!

+1 (855) GET-SPIKES (855-438-7745)


items ()

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.

Time 2 hours
Difficulty Advanced

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 that we can get in almost any electronic components store.


Background

Designed and written by José Enrique López Pérez, student of Electronic Engineering in Oaxaca, Mexico.

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.

  1. Character data: when letters and numbers are sent to the LCD.
  2. 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 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’.

Downloads

Take our (.ino) LCD Sketch and load it on your Arduino

Video

Procedure

  1. Connect the digital pins 2 through 7 from the SpikerShield to the LCD as per the image below.
  2. Now connect the potentiometer (contrast control) to pins 1, 2 and 3 of the LCD, just like in the picture.
  3. Next, connect the LCD screen light's internal LED (you can find it in pins 15 positive and 16 negative). In the positive pin it is necessary to connect a 330 Ω resistor.

    In this step we will connect the following pins from the LCD to the breadboard: PIN-VDD, PIN-VSS y PIN-5(RW).

  4. Connect VCC and GND from the SpikeShield to the breadboard.
  5. In this last step we will load the program to the Arduino; if you can see the image of a cockroach and the message “BACKYARD BRAINS” than congratulations! You made it!

    Circuit Diagram

    Code description This code converts the analog signal of the EMG into a digital signal. This signal is then turned into a moving bar on the LCD that represents the proportional strength of your EMG signal! Below you can see the code, but if you want to download it, just click here

    The code

    #include  //Library to control the LCD.
    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);  //Start the library with the numbers of pins
    //Pin RS del LCD al pin 7 digital.
    //Pin E  del LCD al pin 6 digital.
    //Pin D4 del LCD al pin 5 digital.
    //Pin D5 del LCD al pin 4 digital.
    //Pin D6 del LCD al pin 3 digital.
    //Pin D7 del LCD al pin 2 digital.
    
    #define MAX 8    // Max range possible. Play with this value!
    #define NUM_COLUMNAS 16 // This is the max number of columns in the LCD
    int lecturas[10];  
    int lecturaFinal;
    byte cuadrosLcd = 0;
    byte multiplicador = 1;
    byte columnaX = 0;
    
    //Shows the image of a cockroach through 8 customer characters.
    
    byte a1[8] = {
      B10000,
      B01000,
      B00100,
      B00100,
      B00111,
      B01000,
      B10000,
      B11111
    };
    
    byte a2[8] = {
      B00000,
      B01000,
      B01001,
      B01001,
      B11111,
      B00000,
      B00000,
      B11111
    };
    
    byte a3[8] = {
      B01000,
      B10000,
      B00000,
      B00000,
      B11000,
      B10110,
      B01001,
      B11001
    };
    
    byte a4[8] = {
      B00000,
      B00000,
      B00000,
      B00000,
      B00010,
      B00100,
      B11000,
      B00000
    };
    
    byte a5[8] = {
      B11111,
      B10000,
      B01000,
      B00111,
      B00000,
      B00000,
      B00000,
      B00000
    };
    
    byte a6[8] = {
      B11111,
      B00000,
      B00000,
      B11111,
      B01001,
      B01001,
      B01000,
      B00000
    };
    
    byte a7[8] = {
      B11001,
      B01001,
      B10110,
      B11000,
      B00000,
      B00000,
      B10000,
      B01000
    };
    
    byte a8[8] = {
      B00000,
      B11000,
      B00100,
      B00010,
      B00000,
      B00000,
      B00000,
      B00000
    };
        
        
    
    void setup(){
      
      lcd.begin(16, 2);  //establishes the number of columns and rows in the LCD.
      
    //Creates custom characters.
      lcd.createChar(1, a1);
      lcd.createChar(2, a2);
      lcd.createChar(3, a3);
      lcd.createChar(4, a4);
      lcd.createChar(5, a5);
      lcd.createChar(6, a6);
      lcd.createChar(7, a7);
      lcd.createChar(8, a8);
        
    //Draws the cockroach in the LCD.
       lcd.setCursor(1, 0);
        for(int i=1;i<=4;i++){
        lcd.write(i);
      }
      
      lcd.setCursor(1, 1);
        for(int i=5;i<=8;i++){
        lcd.write(i);
      }
      
    //Shows the message "BACKYARD BRAINS".
      lcd.setCursor(7, 0);
      lcd.print("BACKYARD");
      lcd.setCursor(8, 1);
      lcd.print("BRAINS");
      
      delay(2000); //Espera 2000ms 
      lcd.clear(); //y despues limpia la pantalla. 
    
    }//End of void setup.
    
    
    void loop(){
      
      for(int i = 0; i < 10; i++){    //Makes 10 reads in ~ 0,02 seconds.
        lecturas[i] = analogRead(A0) * multiplicador;
        delay(2);
      }
      for(int i = 0; i < 10; i++){   //Makes an average of the ten reads
    
        lecturaFinal += lecturas[i];
      }
      lecturaFinal /= 10;
    
      lecturaFinal = constrain(lecturaFinal, 0, MAX); //Limits"lecturaFinal" to a defined range(0->MAX).
      cuadrosLcd = map(lecturaFinal, 0, MAX, 0, NUM_COLUMNAS); //Convert the value of"lecturafinal" to a number of pixels in the LCD.
      
        for(columnaX = 0 ; columnaX < cuadrosLcd ; columnaX++)
        {
          lcd.setCursor(columnaX, 0);     
          lcd.write(255);                 //displays(?) in columnX and row 1.
          lcd.setCursor(columnaX, 1);     
          lcd.write(255);                 //displays(?) in columnX and row 2.
          delay(30);
        }
       
        for(columnaX = cuadrosLcd  ; columnaX < 16 ; columnaX++)
        {
          lcd.setCursor(columnaX, 0);      
          lcd.write(254);                //displays( ) in columnX and row 1. 
          lcd.setCursor(columnaX, 1);    
          lcd.write(254);                //displays( ) in columnX and row2.
        }
        delay(10);
    }//End of void loop
    
        

    With this new experience, now you can make your own inventions. Tell us what you are making info@backyardbrains.com and maybe we can start a friendship!