element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Bluetooth Unleashed Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Bluetooth Unleashed Design Challenge
  • More
  • Cancel
Bluetooth Unleashed Design Challenge
Blog Smart exercise bike computer. Part #7: Integration of the LCD
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: yuritikhonov
  • Date Created: 22 Jun 2018 6:58 AM Date Created
  • Views 1656 views
  • Likes 7 likes
  • Comments 8 comments
  • bluetooth
  • lcd
  • freedom_development_platform
  • bluetooth_unleashed
  • frdm-k64f
  • frdm
  • design_challenges
  • frdm-kw41z
  • hd44780
  • nxp
  • bt_exercise_bike
  • sport
  • pca9675
Related
Recommended

Smart exercise bike computer. Part #7: Integration of the LCD

yuritikhonov
yuritikhonov
22 Jun 2018

Good day!

 

In my [first article about the exercise bike I wrote that I was planning to display the data of my computer on the screen of my smartphone However due to the temporary absence of  FRDM-KW41ZFRDM-KW41Z board equipped with Bluetooth module which is necessary for transferring information to a smartphone I can't do it In order to temporarily solve this problem I made a strategic decision until I get a board equipped with Bluetooth I will use the LCD display as a data output device which we will talk about in today's article

 

At work, we usually use graphic displays, for example [MT-1286J], but I do not need such a display for the exercise bike. Best I'd be suited with a display with a built-in character generator, for example [MT-16S2H]. In my home workshop I found a display of the kind (though made in China, but more on that later) and I will use it.

 

image

image

 

Connection of the LCD

 

The display I chose is equipped with a chip-driver HD44780, well-known to all embedded software developers. There are many "classic" schemes of its connection to the microcontroller. Let's onsider the two most interesting.

 

1. The standard scheme with 4-bit data bus. This connection option does not require any additional components except the resistor to adjust contrast. Let's take a look at the assignments of our display lines:

  • A, K – anode and cathode of the LCD back-light;
  • V0 – contrast calibration;
  • DB4 – DB7 – 4-bit data bus;
  • RS – selection between data and command mode;
  • E – strob signal.

 

As you can see, 6 lines are connected to the microcontroller. If instead of a 4-bit data bus we would use a faster 8-bit data bus, it would require 10 lines.

image

 

2. Scheme with additional driver and I2C interface. To reduce the number of lines coming to the microcontroller, you can use the I/O expander IC. When using the I2C interface, you can connect the display to the MCU with just two wires!

 

In 2011, I have [already experimented] with a similar scheme, then I used the NXP chip [PCA9675PW The solution mentioned had a number of minor drawbacks so I updated the scheme a little bit and now it is great to use it with  FRDM-K64FFRDM-K64F

image

 

Simple LCD driver

 

For the display, I've written a small library that includes three functions:

  • lcd::init() – initialization of the LCD;
  • lcd:send_two_bytes(one, two) – send data/command to the LCD;
  • lcd::write(pos, value) – write text or value on the LCD.

 

Display initialization function lcd::init performs the following actions:

  • setting the I2C interface to work in the default master-mode;
  • initial display setting (backlight on, cursor off, etc.)

 

To send data to the display, a tricky function lcd::send_two_bytes is used, which transmits to the I2C driver the data intended for the display, and the transfer is carried out in two stages: first, the data is transmitted with the installed strobe signal, and then the same data, but with the strobe signal removed, this is necessary in order to write the data frame to the memory of the chip HD44780.

 

The function lcd::write has two options: one for text output and the second for display of float type variable. In addition, I have provided the ability to output data to different "sectors" of the display. I did this to:

  • write the name of the parameter #1 (for example, speed) in the upper left corner;
  • write the value of the parameter #1 in the lower left corner;
  • write the name of the parameter #2 (for example, distance) in the upper right corner;
  • write the value of the parameter #2 in the lower right corner;

 

In today's article I will mention only a small piece of code that describes an example of using my driver. The driver itself can be found in the [official project repository].

 

// definitions
#define EXPERIMENT 1

// main function of the program
int main(void)
{
    // system init
    gpio::init();
    #if (TENSION_MODE == 2)
        adc::init();
    #endif
    BOARD_BootClockRUN();
    
    // LCD init
    lcd::init();

    // write text to LCD
    lcd::write(TEXT_UP_LEFT,  "Speed");
    lcd::write(TEXT_UP_RIGHT, "Distance");
    lcd::write(TEXT_DOWN_CENTER, "Hello Element14!");

    // exit from the program (if it's an experiment)
    #if (EXPERIMENT != 0)
        return 0;
    #endif

    // if it isn't an experiment then - start RTOS threads
    osThreadCreate (osThread(sensors), NULL);
    osThreadCreate (osThread(indication), NULL);
    
    // empty infinity loop
     for(;;)
    {
        osSignalWait(0, osWaitForever);
  }
}

 

The result of the program is presented in the photo:

image

 

Using of the LCD in exercise bike computer firmware

 

Now when we have the display driver, it's time to use it for its intended purpose! I added the function call lcd::write to the indication RTOS thread: now I put to the display values of speed and distance. During the experiments it was found out that the lcd::write function works rather slowly, for this reason I decided to call it not every RTOS clock cycle (10ms), but every 100 clock cycles. After all improvements, the code of the indication thread looks as follows:

 

static void indication(void const *args);
osThreadDef(indication, osPriorityNormal, 1, 0);
static void indication(void const *args)
{
    static int counts = 0;
    
    for (;;)
    {
        gpio::write(GREEN, distance > 0.25f); // LED is turned on if we passed 250 m
        gpio::write(RED,   speed    > 32.0f); // LED is turned on if we riding on 32 km/h
        
        counts++;
        if (counts > 10)
        {
            // output data to LCD
            lcd::write(TEXT_DOWN_LEFT, (float)speed);
            lcd::write(TEXT_DOWN_RIGHT, (float)distance);
            counts = 0;
        }
    }
}

 

As a demonstration of the results, I offer a photo of my computer installed on the bike (photo taken during training).image

 

Conclusion

 

Today I made an important strategic decision to continue the project despite the lack of key components And as you can see even without  FRDM-KW41ZFRDM-KW41Z my project looks more and more like a real bike computer

 

Before I finish my today's post, I'd like to address the community: during the experiments I had a little problem with the LCD display based on the HD44780 controller, if you have such a display — please take part in [voting] it will help me a lot in the project!

 

Thanks for reading and have a nice day!

  • Sign in to reply

Top Comments

  • genebren
    genebren over 7 years ago +3
    Another nice update on your design challenge project. I hope that you are able to get your WiFi board in time to send the data to your phone. I have not experience using this particular controller/display…
  • aspork42
    aspork42 over 7 years ago +3
    Nice update - It is starting to look real! Are you going to make it bilingual? You can have a switch on the side to make it come up in Cyrillic... If the LCD driver can support the character set. I've…
  • mcb1
    mcb1 over 7 years ago +3
    yuritikhonov The white on blue LCD's are much slower than the Black on Greenish LCD's. I suspect that to get white they make the crystal transparent, while the other the black pixel is simply blocking…
  • yuritikhonov
    yuritikhonov over 7 years ago in reply to three-phase

    Thanks Donald!

    As you can see the project does not stand still, at least for today I have a clear idea of where to move on!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • three-phase
    three-phase over 7 years ago

    Good to see the progress being made, hopefully the parts will arrive soon.

     

    kind regards

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • yuritikhonov
    yuritikhonov over 7 years ago in reply to mcb1

    Mark, thanks a lot for information!

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 7 years ago

    yuritikhonov

    The white on blue LCD's are much slower than the Black on Greenish LCD's.

    I suspect that to get white they make the crystal transparent, while the other the black pixel is simply blocking, and hence there is a speed difference.

    I have tried it with scrolling text using exactly the same Arduino and setup and just swapping the displays.

    Arduino, Temperature, LCD and more

    Line 105 is the scroll delay period, and for the White on Blue it needs to be increased to stop the ghosting.

     

     

    I've seen various libraries that claim to make LCD's quicker, but I haven't experimented to see if they are or not.

     

    Mark

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • yuritikhonov
    yuritikhonov over 7 years ago in reply to aspork42

    Hi James! I can do it in production version, but just for me it's not needed, because in my computer I use only known to me english words image

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube