Loading...

You have no items in your shopping cart.

 
 
 
×

Registration

Profile Informations

Login Datas

or login

First name is required!
Last name is required!
First name is not valid!
Last name is not valid!
This is not an email address!
Email address is required!
This email is already registered!
Password is required!
Enter a valid password!
Please enter 6 or more characters!
Please enter 16 or less characters!
Passwords are not same!
Terms and Conditions are required!
Email or Password is wrong!
Captcha is required!
Captcha is wrong!

Iteaduino Plus Work with OLED And 1602 Dispaly

Before maker faire 2014 commences, we finished version ITEAD OS 2.0BETA of A10 and A20 versions and upgraded the original ITEAD OS SDK. The new codes have been updated to github HERE.

In order to validate and demonstrate SDK, we made a DEMO:

Plug Arduino Plug into Iteaduino Plus, then connect it to ITEAD 1602 LCD shield, the real-time CPU occupacy rate of Iteaduino Plus can be displayed by OLED library and 1602  library in the SDK. For comparison, we also connected a 2.8 -inch TFT screen to display the current resource consumption of system .

ITEAD 1602 LCD shield is connected to Iteaduino Plus via GPIO, working in 4bit mode. We ported a 4bit 1602 driver library on Arduino directly. For more about the original library, please click here : LCD4Bit_mod

OLED screen is connected to Iteaduino Plus via IIC bus. We ported an Arduino OLED Arduino library of Adafruit to drive OLED screenon the Plug. For more about the original library, please click here : Adafruit_SSD1306

USB TFT LCD is connected to Iteaduino Plus via USB, you can see more detailed about this screen here: ROBOPEAK MINI USB DISPLAY

See the simple demo code here:

#include 
#include 
#include    

#include 
#include 
#include  

#define OLED_RESET 9

static double get_cpu_utilization(void);
static double get_cpu_occupy(void);


static LCD4Bit_mod lcd(2); 
static SSD1306 oled(OLED_RESET);

void setup()
{
	oled.begin(SSD1306_SWITCHCAPVCC, 0x3c);     // initialize with the I2C addr 0x3C (for the 128x64)
	oled.setTextSize(2);
  	oled.setTextColor(WHITE);
	
	lcd.init();
  	lcd.clear();
  	lcd.cursorTo(1,3);
  	lcd.printIn((char *)"< CPU % >");
}

void loop()
{
	static int cnt = 0;
	double occ;
	int iocc;
	occ = get_cpu_occupy();
	oled.clearDisplay();   // clears the screen and buffer
	
  	oled.setCursor(15,15);
	oled.print("< CPU % >"); 
	
	oled.setCursor(42,38); 
	
	oled.print(occ,2);

	iocc = (int)(occ*100 + 0.5);

	lcd.cursorTo(2,5);
	lcd.print(iocc/1000 + '0');
	lcd.print((iocc%1000)/100 + '0');
	lcd.print('.');
	lcd.print((iocc%100)/10 + '0');
	lcd.print((iocc%10) + '0');
	
	if(cnt++ % 2){
		oled.print("_");
		lcd.print('_');
	} else {
		oled.print(" ");
		lcd.print(' ');
	} 	
	
	oled.display();
}


static double get_cpu_occupy(void)
{
	FILE *fd;
	char obuff[1024];
	char oname[20];
	uint32_t ouser;
	uint32_t onice;
	uint32_t osystem;
	uint32_t oidle;
	uint32_t oiowait;
	uint32_t oirq;
	uint32_t osoftirq;

	char nbuff[1024];
	char nname[20];
	uint32_t nuser;
	uint32_t nnice;
	uint32_t nsystem;
	uint32_t nidle;
	uint32_t niowait;
	uint32_t nirq;
	uint32_t nsoftirq;
	
	uint32_t diff_all;
	uint32_t diff_occ;
	uint32_t diff_idle;
	
	//sleep(interval);
	
	fd = fopen ("/proc/stat", "r"); 
	if(fd == NULL) {
		sdkerr("fopen /proc/stat err\n");
		exit(1);
	}
	fgets(obuff, sizeof(obuff), fd);// read first line
	sscanf (obuff, "%s %u %u %u %u %u %u %u", 
		&oname, &ouser, &onice,&osystem, &oidle,&oiowait,&oirq,&osoftirq);
	//printf("oname=%s ouser=%u onice=%u osystem=%u oidle=%u\n", oname, ouser,onice,osystem,oidle);
	fclose(fd); 
	
	sleep(1);
	
	fd = fopen ("/proc/stat", "r"); 
	if(fd == NULL) {
		sdkerr("fopen /proc/stat err\n");
		exit(1);
	}
	fgets(nbuff, sizeof(nbuff), fd);// read first line
	sscanf (nbuff, "%s %u %u %u %u %u %u %u", 
		&nname, &nuser, &nnice,&nsystem, &nidle,&niowait,&nirq,&nsoftirq);
	//printf("nname=%s nuser=%u nnice=%u nsystem=%u nidle=%u\n", nname, nuser,nnice,nsystem,nidle);
	fclose(fd); 
	
	diff_all = (nuser - ouser)
		+ (nnice - onice)
		+ (nsystem - osystem)
		+ (nidle - oidle)
		+ (niowait - oiowait)
		+ (nirq - oirq)
		+ (nsoftirq - osoftirq);
	
	diff_idle = nidle - oidle;
	return 100.0 - diff_idle*100.0/diff_all;

}

static double get_cpu_utilization(void)
{
	FILE *fp = NULL;
	char info[1024];
	double rate=0;
	int i;
	char ch;
	fp = popen("top -d 0.5 -n 2 | grep %Cpu","r");
	if (fp == NULL){
		sdkerr("popen err\n");
	}
	
	ch = fgetc(fp);
	while( ch != '\n') {
		ch = fgetc(fp);
	}
	
	ch = fgetc(fp);
	for(i=0; ch != '\n';i++) {
		ch = fgetc(fp);
		info[i] = ch;
	}
	info[i]='\0';
		
	info[156+4]='\0';
	//info[133+8]='\0';
	rate = strtod(&info[156],NULL);
	if(pclose(fp) == -1 ){
		sdkerr("pclose err\n");
	}

	return 100.0f-rate;

}

In ITEAD OS SDK 2.0BETA, operating functions for GPIO and underlying buses were updated so that they can be more compatible with the Arduino operating functions and the existing Arduino upper operation libraries can be ported directly. Of course, we will continue to do such work.