This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:remotelab:sut:generalpurpose2:b1 [2019/07/24 23:44] – pczekalski | en:iot-open:remotelab:sut:generalpurpose2:b1 [2020/10/25 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ==== B1: Basic operations on the 4x20 LCD screen ==== | ||
| + | Whatever you do, you expect to have some output of the system. Sometimes there is a blinking LED, sometimes information about connected/ | ||
| + | |||
| + | <note important> | ||
| + | |||
| + | === Target group === | ||
| + | This hands-on lab guide is intended for the Beginners but other target groups may benefit from it, treating it as a tool for advanced projects. | ||
| + | |||
| + | === Prerequisites === | ||
| + | There are no other prerequisites than LCD I2C library. Mind, LCD is controlled via the I2C bus. LCD Display is 4×20 characters. LCD is controlled via I2C extender: LCM1602. The I2C extender address is 0x3F or 0x27 (depends on the laboratory node, please refer to the documentation!) and the I2C bus is connected to the pins D1 and D2 (D1 is SCL and D2 is SDA). | ||
| + | |||
| + | <note important> | ||
| + | * Nodes 1 through 5, 8 and 9 use 0x3F | ||
| + | * Nodes 10 and 11 use 0x27 | ||
| + | </ | ||
| + | |||
| + | === Scenario === | ||
| + | Initialize LCD screen, clear it then write some fancy text on it, i.e. "Hello IOT!" in the first line then your first name in the second line and the name of the city you're in, in the third. In the fourth line, print right-aligned number of '' | ||
| + | |||
| + | === Result === | ||
| + | You should see the texts and ticking counter in the video stream. | ||
| + | |||
| + | === Start === | ||
| + | There are no special steps to be performed. | ||
| + | |||
| + | === Steps === | ||
| + | |||
| + | == Step 1 == | ||
| + | Include LCD driver library: | ||
| + | <code c> | ||
| + | #include < | ||
| + | </ | ||
| + | == Step 2 == | ||
| + | Instantiate software controler component for the LCD display: | ||
| + | <code c> | ||
| + | LiquidCrystal_I2C lcd(0x3F, | ||
| + | // | ||
| + | // for a 20 chars and 4 line display | ||
| + | </ | ||
| + | == Step 3 == | ||
| + | Declare some variables: counter '' | ||
| + | <code c> | ||
| + | int i = 0; | ||
| + | char buffer [50]; | ||
| + | int n; | ||
| + | </ | ||
| + | We will use them in further part of the code. | ||
| + | == Step 3 == | ||
| + | Initialize display - we suggest to do it in '' | ||
| + | <code c> | ||
| + | ... | ||
| + | lcd.init(D2, | ||
| + | lcd.backlight(); | ||
| + | ... | ||
| + | </ | ||
| + | == Step 4 == | ||
| + | Clear the contents, set cursor and draw static text - still in '' | ||
| + | <code c> | ||
| + | ... | ||
| + | lcd.home(); | ||
| + | lcd.print(" | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | ... | ||
| + | </ | ||
| + | == Step 5 == | ||
| + | Implement '' | ||
| + | <code c> | ||
| + | ... | ||
| + | i++; | ||
| + | n=sprintf(buffer," | ||
| + | lcd.setCursor(20-n, | ||
| + | lcd.print(i); | ||
| + | delay(1000); | ||
| + | ... | ||
| + | </ | ||
| + | <note tip>'' | ||
| + | |||
| + | === Result validation === | ||
| + | Observe text, its position and counter ticking in lower, right corner. | ||
| + | |||