jerryshi
Posts: 2
Joined: Tue May 13, 2014 2:18 am
Location: China
Contact: Website

Use Itead SDK to Drive a 1602 LED

Sat Jun 07, 2014 1:48 am

Itead Studio made an SDK for linux system of Allwinner A10/20 chip before, which provided users with the underlying hardware driver interface for quick development of upper software, thus those who are not familiar with hardware can easily make a variety of creative applications combined with hardware and software.

Now, Itead SDK has been ported to Raspberry Pi, thus Raspberry Pi users can experience the convenient and rapid development like Arduino.

IteadOS SDK used the realization principle of WiringPI for reference by controlling the externally connected hardware modules through calling the system interface. The difference is, IteadOS SDK is deeply compatible with the Arduino code architecture, thus a lot of Arduino Libraries and Arduino based projects can be ported to use without too much modification. Moreover, ino files generated by Arduino IDE can be directly compiled.

The current version of the SDK provides the following underlying functional functions:

- GPIO (supports IO port operations and PWM)
- UART operation
- IIC operation (master mode)
- SPI operation (master mode)

Besides, it provides support for the libraries of the following modules:

- 1602 LED Module
- OLED module

This project is open source, and the lastest version of source code can be found on GIHUB: https://github.com/iteadsw

we will give two examples to illustrate how to use Itead SDK for rapid prototyping development.

Preparation

- Raspberry PI Rev_2 http://imall.iteadstudio.com/raspberry-pi.html
- LCD1602 Add-on http://imall.iteadstudio.com/raspberry- ... dd-on.html
- SD card
- 5V Micro USB power supply

Assembly

LCD1602 Add-on is customized for Raspberry Pi, and it is quite simple to assemble without any welding. Just plug the 26pin Interface into Raspberry Pi as shown in the picture below.
Image
Image
Image

Then install the SD card, connect the network cable and plug in the power supply to get it started.

When using it for the first time, we need to adjust the display contrast with a small screwdriver. Turn the divider until the box in the first line of LCD is displayed clearly.
Image
Image

Finally, the hardware preparation work is done.

Install Software

IteadOS SDK was tested under RASPBIAN Version:January 2014 http://www.raspberrypi.org/downloads/only, systems of other versions have not been tested for compability. To gain better compability, we suggest using the official RASPBIAN image of Raspberry Pi.

About how to install RASPBIAN system on the SD card, please refer to the official documentation http://www.raspberrypi.org/documentatio ... /README.md.

After installing the operating system, we will need to install the SDK.

Code: Select all

    git clone https://github.com/iteadsw/SDK.git
    cd SDK
    make Raspberry_Rv2
    make
    sudo make install
Drive A LCD1602

Pin definition

In Itead SDK, pin definition of Raspberry Pi is as follows:
Image

According to Schematic ftp://imall.iteadstudio.com/Modules/IM1 ... 227002.pdf offered by Itead Studio, we can see the connection between Raspberry Pi and LCD1602 Add-on as follows:
Image

Code - INO

Itead SDK supports compiling of ordinary c, cpp file and ino file.

INO file is an Arduino Sketch. Arduino is an open-source electronic prototyping platform allowing to create interactive electronic objects. Software written using Arduino are called sketches. These sketches are written in the text editor. Sketches are saved with the file extension .ino.

INO file has its own syntax, the following is a simple example to show how to compile INO file. Create a LCD.ino file, the contents are as follows:

Code: Select all

 // include the library code:
    #include <itead_LiquidCrystal.h>
    
    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(16,18,11,12,13,15);
    
    void setup() {
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    // Print a message to the LCD.
    lcd.print("hello, world!");
    }

    void loop() {
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    // print the number of seconds since reset:
    lcd.print(millis()/1000);
    }
Then compile in Terminal

Code: Select all

iteadcompile LCD LCD.ino
This program must be run with administrator privileges.

Code: Select all

sudo ./LCD


Display result is as follows:
Image

You may find that you have seen the code before? Yes, this is the code in Arduino official tutorial http://www.arduino.cc/en/Tutorial/LiquidCrystal, the only change is about the pin definition.

Code - C/CPP File

Next, let's take CPP file as an example, we still use the same LCD, but we want to display current time this time. Creat a file showtime.cpp, and the contents are as follows:

Code: Select all

// include the library code:
    #include <itead_LiquidCrystal.h>
    #include <time.h> 

    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(16,18,11,12,13,15);

    void setup() {
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    }

    main() {
    
    time_t rawtime;
    struct tm * timeinfo;
    
    setup();
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):    
    // lcd.setCursor(0, 0);
    
    // print system time 
    time ( &rawtime );
    timeinfo = localtime ( &rawtime );
    while(1)
        {  
        lcd.setCursor(0,0);
        lcd.print(asctime (timeinfo));
         delay(1000);
         }
    }
Then compile:

Code: Select all

iteadcompile showtime showtime.cpp
Also run with administrator privileges, add & so that the program can run at the background, and we can do other things at the same time.

Code: Select all

sudo ./showtime &
Image

You can use top to check CPU occupancy rate.
Image

In the process of using Raspberry Pi, the most maddening thing is that we cannot know the current IP of Raspberry Pi when logging in Raspberry Pi with SSH due to no router administrator privileges. With this screen, we can use it to display the current IP. Code is as follows:

Code: Select all

#include <sys/ioctl.h>
    #include <net/if.h>
    #include <netinet/in.h>  
    #include <arpa/inet.h>
    #include <string.h>
    #include <stdio.h>
    #include <itead_LiquidCrystal.h>
    #include <itead.h>
    
    LiquidCrystal lcd(16,18,11,12,13,15);
    
    
    int get_local_ip(char *ip)
    {
      int fd, intrface, retn = 0;
      int ip_cnt = 0;
      struct ifreq buf[INET_ADDRSTRLEN];
      struct ifconf ifc;
      if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0)
      {
        ifc.ifc_len = sizeof(buf);
        ifc.ifc_buf = (caddr_t)buf;
        if (!ioctl(fd, SIOCGIFCONF, (char *)&ifc))
        {
          intrface = ifc.ifc_len/sizeof(struct ifreq);
          while (intrface-- > 0)
          {
            if (!(ioctl(fd, SIOCGIFADDR, (char *)&buf[intrface])))
            {
              ip=(inet_ntoa(((struct sockaddr_in*)(&buf[intrface].ifr_addr))->sin_addr));
              printf("IP:%s\n", ip);
              lcd.setCursor(0, ip_cnt++);
              lcd.print("IP");
              lcd.print(ip_cnt);
              lcd.print(" :");
              lcd.print(ip);
              if(ip_cnt == 2)ip_cnt = 0;
            }
          }
        }
        return 0;
      }
    }
    
    int main()
    {
      char ip[64];
      memset(ip, 0, sizeof(ip));
    
      lcd.begin(16, 2);
      lcd.setCursor(0, 0);
    
      get_local_ip(ip);
      return 0;
    
    }
Image

lesterkell
Posts: 4
Joined: Sun Nov 02, 2014 12:26 pm

Re: Use Itead SDK to Drive a 1602 LED

Sun Nov 02, 2014 12:31 pm

Hi, I've been trying to get my pi to drive the 1602 Liquid Crystal display to work but the itead_LiquidCrystal.h file has an error. It's doesn't like line 50, class. Is there an updated file that will compile on the Pi.

Thanks

User avatar
DougieLawson
Posts: 35602
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Use Itead SDK to Drive a 1602 LED

Sun Nov 02, 2014 3:26 pm

Do you have the latest version from https://github.com/itead/SDK?
If you do then post your bug as an issue at https://github.com/itead/SDK/issues
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

ladedadeda
Posts: 1
Joined: Thu Feb 05, 2015 2:03 pm

Re: Use Itead SDK to Drive a 1602 LED

Thu Feb 05, 2015 2:06 pm

Hi,

for first time worked well for me, but now it's not working it all.

I get error:

[SDKERROR:itead_gpio.c,578,digitalWrite]->
gpio_mmap failed!

open /dev/mem error !
[SDKERROR:itead_gpio.c,458,digitalWrite]->
gpio_mmap failed!

open /dev/mem error !

Can you help plz?

besthosting
Posts: 5
Joined: Mon Jan 13, 2014 6:46 pm

Adafruit configuration

Sat Mar 16, 2019 7:06 pm

Configuration for Adafruit:
(https://learn.adafruit.com/character-lc ... cuitpython)

Code: Select all

import time
import board
import digitalio
import adafruit_character_lcd
import adafruit_character_lcd.character_lcd as characterlcd

# Character LCD Config:
# Modify this if you have a different sized character LCD
lcd_columns = 16
lcd_rows = 2

# Raspberry Pi Pin Config:
lcd_rs = digitalio.DigitalInOut(board.D23)
lcd_en = digitalio.DigitalInOut(board.D24)
lcd_d4 = digitalio.DigitalInOut(board.D17)
lcd_d5 = digitalio.DigitalInOut(board.D18)
lcd_d6 = digitalio.DigitalInOut(board.D27)
lcd_d7 = digitalio.DigitalInOut(board.D22)

# Init the lcd class

lcd = characterlcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows)

lcd.message = "Hello\nCircuitPython!"

Return to “HATs and other add-ons”