Interested in a hobby like Arduino, I soon realized that the essence of this wonderful project is to allow people like me, who don't understand anything in circuitry, soldering and chips, but a little understanding in programming, to make something other than a personal computer work; flash the microcontroller without a programmer and no special knowledge on this topic.
Therefore, I want to help promote this project - programmers, this is a great entertainment just for you!
While the motors for my next mobile project are traveling in a kibitka harnessed by a troika of the fastest gastropods of the Russian Post, I conceived and, I must say, implemented, another (warm-up) project called “Arduino LCD Informer”. The essence of the project is for Arduino to display the data received from the computer on the LCD. On the computer, a separate program collects and sends them.
')

Ingredients
For the project we will need:
Arduino

This clever and clever kid, possesses not only brains (ATmega328), but also sense organs and manipulators - the inputs and outputs make it possible both to receive information from various sensors and send commands to different devices, including motors, LEDs, and of course lcd screens In addition, a usb connection with a computer is used not only for uploading ready-made programs to it, but also for two-way communication with programs running on a computer.
LCD text screen

We need the most common model, MT – 20S4A (MELT), HD44780 (Hitachi), KS0066 (Samsung) or their analogues.
I recommend MELT - I have one. The heart is warmed by a proud inscription - “MELT. Made in Russia". Support the domestic manufacturer! Moreover, the screen is made not only neatly and neatly, but also with the support of the Cyrillic alphabet, about which later.
Breadboard

Breadboard, as our overseas adversaries christened it, and in our opinion, a prototyping board. Briefly explain the essence. On the board are parallel lines of conductive material. If you stick the wiring into the hole, then all the holes above and below it (if you arrange the board so that the central band goes from right to left - as in the photo) will be connected to it. More precisely, everything is up to the central band - on both sides of it there are two unrelated parts of the board.
Thus, without soldering, without twisting, noise and dust, you can safely poke the wiring, planning and immediately checking the device operation pattern. One posting in the hole, the second - in the next, and the contact is ready.
On medium and large boards, two strips of conductors are provided at the edge, one for the ground and the other for power, since these two contacts are most often required.
Lapshichka wire

Designed for comfortable carrying current. Usually one end is stuck into the entrance-exit of the Arduine, and the other - into the board, or into the sensor. It will also be convenient to apply short jumper wiring.
Home-made cheesecakes with raspberry jam

Working on an empty stomach is not only harmful, but also useless. And in the course of work it is nice to reward yourself with syrnykom-others. For cheesecakes, we need cottage cheese (not isomorphic-smooth, and with normal graininess) - 400 grams of cottage cheese, 2 eggs, 50 grams of sugar, half a spoon of (tea) soda, a pinch of salt. Stir, and then stirring, gradually add flour, only about 200 grams. Then cover the dough and leave for 2 hours. Then heat the pan with a little oil, roll the balls, flatten them and fry.
Well, to taste, then add on top - to whom raspberry jam, to whom condensed milk, to whom as ...
Cooking
Assembly.
In order for the LCD to lightly illuminate us with its soft, warm, almost tube orange light, it is necessary to provide it with power (and earth), and to display information - connect it to the Arduino outputs.
If your board has strips for ground and power, you can bring them with Arduino exactly there. But do not despair - if they are not there, we can manage it this way.

See photos - pins 1, 3 and 5 require connection to earth. We stretch the wire from the Arduino contact marked GND (blue) to the row of holes on the board corresponding to the first contact, and to the 3rd and 5th row (which go to the 3rd and 5th contacts) draw the jumper from the first row ( red and yellow).
ATTENTION!1) We carry out all work on wire interruption when the power is disconnected from the Arduino - both usb and through the power connector!
By the way, therefore, I recommend to connect Arduino to usb via two cables - one regular usb, the second - an extension cord. Thus, instead of razbaltyvaniya usb-port on a computer or on Arduino will need to separate only the junction of the extension cord with a cable.
2) Different LCD numbers may vary. Read the instructions on your screen. In addition, the numbering of contacts can go either from left to right - 1, 2, 3, .., 16 - and, for example, 14, 13, 12, .., 2, 1, 15, 16. Contacts must be numbered at the screen.
If you are a beginner arduinist and do not know how to solder, take care to order a screen with already soldered legs-contacts. All contacts have a standard pitch, so our sixteen-inch screen will easily stick into the board. We stick our legs - a row of legs parallel to the central strip and closer to it so that the rest of the board on this side of the strip remains accessible for sticking the wires.
So, stretching the wire from the Arduino contact marked 5V to the board, supply 5 volts to the 2nd (power) and 15th (backlight) contacts. Earth - 1, 3, 5, 16.
In this case, the 3rd contact is the contrast, the higher the voltage, the duller the image. Earth = 0 = highest contrast.
After that, you can turn on Arduino (connect to usb) and see if the LCD is lit. If yes - congratulations! You can reward yourself with cheese. And turn off the Arduino from the power again!
Next, connect the screen control contacts. 4th - to the 4th exit Arduino. (All outputs with which we deal in the given project, are marked on Arduino as digital). This is an address signal.
6th screen pin - 5th Arduino pin. This is access permission.
Further data feeds:
lcd - Arduino
11 - 10
12 - 11
13 - 12
14 - 13
The result of my work is visible on the first photo. The wires are neatly assembled into a knot, and for stability, the screen is equipped with an elegant support taken from the children's metal constructor, bent into the required curve. It is connected to the screen with a bolt with a diameter of 3 mm in a specially provided mounting hole.
You can code!
Software
Arduino sketch
To write programs for Arduino and send them to it you need a shell, which can be downloaded from here:
arduino.cc/en/Main/SoftwareBriefly about usage. We connect Arduino, select its type (in my case it is Arduino Uno) in Tools / Board, then the port number in Tools / Serial port - usually, this is a port other than COM1. I got COM9.
Then we write programs. The button with a check mark checks the program, the arrow to the right compiles and uploads to Arduino.
The programs that Arduino performs are called sketches, and consist of three parts. First, the necessary libraries are connected. Then the setup function is filled with content, which is automatically executed once. It is the entire initialization of the equipment.
Then - the main function, the loop, which is automatically executed in an infinite loop.
Let's write the first sketch program:
// connect the library to work with LCD
#include <LiquidCrystal.h>
void setup ( )
{
// initialize the LCD, indicating the data contacts
LiquidCrystal lcd ( 4 , 5 , 10 , 11 , 12 , 13 ) ;
// specify the screen dimension and start working
lcd begin ( 20 , 4 ) ;
// write the first line
lcd print ( "Hello, world!" ) ;
// move the cursor to the second row, first column (numbered from 0)
lcd setCursor ( 0 , 1 ) ;
// Write the second line
lcd print ( "I love Habr!" ) ;
}
void loop ( )
{
// Nothing special to do
}
We now turn to our problem.
We need a sketch that will display data on the LCD, and we also need a program that will work on the computer, collect this data and send it to Arduino.
The choice of the language in which you can write a program for the computer remains for you - any language that allows you to work with COM ports will do. Of course, it was best to write such a program in C ++ - it takes little memory, hangs in the background and hangs. Unfortunately, I do not have enough knowledge to write such a program in C ++, so I will write on what I know - perl.
A working sketch for a project might look like this:
#include <LiquidCrystal.h>
// RS, E, DB5, DB6, DB7, DB8
LiquidCrystal lcd ( 4 , 5 , 10 , 11 , 12 , 13 ) ;
int inb = 0 ;
int pos = 0 ;
int line = 0 ;
void setup ( )
{
Serial. begin ( 9600 ) ;
lcd begin ( 20 , 4 ) ;
}
void loop ( )
{
lcd setCursor ( pos, line ) ;
if ( Serial. available ( ) > 0 ) {
inb = serial. read ( ) ;
if ( char ( inb ) == '|' ) {
pos = 0 ;
line ++ ;
}
else if ( char ( inb ) == '&' ) {
pos = 0 ;
line = 0 ;
}
else {
lcd print ( char ( inb ) ) ;
pos ++ ;
}
lcd setCursor ( pos, line ) ;
}
}
Arduino is waiting for the data to start, and immediately displays them on the screen.
Symbol | will work as a line break, and & - the end of the current data set.
Program to collect data and send them to the port.
In the program, we connect the libraries necessary for data collection, then we initialize everything, and then in a cycle we form a line containing the collected data and send it to the port.
#! / usr / bin / perl
# We connect the necessary modules
use LWP :: Simple ;
use Encode qw ( from_to _utf8_off ) ;
use Win32 :: SerialPort ;
use Win32 :: API :: Prototype ;
use Win32 :: SystemInfo ;
use Win32 :: DriveInfo ;
use constant { IDLE => 0 , KERNEL => 1 , USER => 2 } ;
# Connect function from Win32 API
InitWin32 ( ) ;
# Start value of ticks
@lasttime = SystemTimes ( ) ;
# Install the port for communication with the Arduino
$ port = InitSerial ( ) ;
# Möbius cycle
while ( 1 ) {
# Form a string
$ data = sprintf ( "CPU:% 3d% C:% 03d Gb | MEM:% 3d% D:% 03d Gb |" .
"T:% 02d'C P:% 03d |% 02d% -8s% 02d:% 02d | &" ,
CPU ( ) , Disk ( 'C' ) , MEM ( ) , Disk ( 'D' ) , Weather ( 'Moscow' ) , DateTime ( )
) ;
# Output to port
while ( $ data = ~ s / ( . ) // s ) {
$ port -> write ( $ 1 ) ;
$ port -> lookclear ;
}
# Waiting
sleep ( 10 ) ;
}
In order not to clutter the article with code, I provide a description of the functions used, and the program can be downloaded in full at the end of the article.
InitSerial - makes the necessary settings for working with a port from perl (Win32 :: SerialPort module)
closePort - stops working correctly with the port so that it can be resumed without any problems the next time you start it. It is hung up on a signal of interruption of the program.
CPU - counts the CPU load. Uses street magic (SystemTimes function), which I spied somewhere. To calculate the load, it uses the function from the kernel32 library GetSystemTimes, which joins the program in the InitWin32 function (Win32 :: API :: Prototype module).
MEM - returns the ratio of available physical memory to its total amount (Win32 :: SystemInfo module)
Weather - reads the temperature and pressure from the page Yandex. It does this no more than once every two hours.
DateTime - returns the current day of the month, month, hours and minutes
Disk - returns the amount of free disk space (Win32 :: DriveInfo module).
Russian language
My screen, as already mentioned, was produced in Russia. In this regard, they have two code pages - the first one (No. 0) contains Cyrillic letters, which have no analogues in the Latin alphabet. On the second (No. 1) there is a complete Russian alphabet, which is the same as cp-1251 in character codes. Therefore, if desired, we can display Russian letters on the screen without special expenses.
A small minus that I ran into is that there is no degree icon on page No. 1 (unlike page No. 0). Replaced with an apostrophe.
To control the screen using the LiquidCrystal library, designed for a common screen model. But of course, no one has done in it the possibility of switching code pages, since the giants of the grief do not know the support of two languages. Let's carry out simple modifications of the library.
It is located in% arduino_install_path% \ arduino-1.0 \ libraries \ LiquidCrystal
According to the documentation on the screen in the “Module Commands” section, the codepage is installed in the Function set command with the second bit.
Add a new constant to LiquidCrystal.h:
#define LCD_CODEPAGE 0x02
Then in LiquidCrystal.cpp we find the function void LiquidCrystal :: init () and in it we add this constant to the rest of the settings, like this:
if (fourbitmode)
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS | LCD_CODEPAGE;
else
_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS | LCD_CODEPAGE;
Thus, the 2nd bit will be raised, the screen will use the code page No. 1, and we can send it data in Russian in cp-1251 encoding (in my case it is the name of the month).
Files
Sketch for Arduino, a perl program for data collection, a revised LiquidCrystal library for working with code page No. 1, documentation for the MELT screenApplication
The use of LCD with Arduino as an informer is practically unlimited.
It may not be as convenient as a second monitor, but it can be useful. Time, weather, system information, debug ... By the way, one more example that recently occurred to me - tracking torrents in uTorrent through its WebAPI ...
But the main thing, of course, is the pleasure from the hobby that you want!