You have no items in your shopping cart.



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!

Get Running State Of Iteaduino Plus

The new sample of Iteaduino Plus arrived, pure black looks much better than the green one. IIC drive of ITEAD OS SDK was completed, and I want to connect it to an OLED screen with resolution of 128×64 and to display information such as the occupancy rate of CPU and memory of the board on the screen.

To achieve this function , first I need to figure out how to access the status of the mainboards in the program – of course, which is unfeasible on Arduino.

As ITEAD OS BETA version of the operating system is running on Iteaduino Plus, to view the status of the board, you can use shortcut key combination "ctrl + alt + T" to open the terminal window and then use command "top" to get detailed information:

However, how to read the information in the program? I am not sure about C, but Python does support getting some return information through command shell. Let’s take reading CPU occupancy rate as an example, we can get the current CPU occupancy rate by using command "cat / proc / stat" in the terminal:

In the terminal, we can also try using python interactive mode to read the information : first import os standard library, then use function popen to obtain the return information.

import os
info = os.popen ('cat / proc / stat'). read ()

From the results, we can see that CPU information is converted to a string and saved in info. Then we can get what we need by screening and analytic operations to the information.

Detailed contents of file stat will not be given here, as I will only make a brief introduction: we only need to use several contents of CPU in the first row, which are shown as below from left to right:

  • user: user mode cpu time
  • nice: cpu time occupied by the process with negative nice value 
  • system: cpu time occupied by kernel mode
  • idle: cpu idle time
  • iowait: time waiting for IO 
  • irq: System hardware interruption time
  • softirq: System software interruption time

To calculate CPU occupancy rate, we can use the following formula :

(user + nice + system) / (user + nice + system + idle)

As we mentioned above, information that we need is now in info. If it is in C, it is quite inconvenient to deal with this string, while string operations offered by python can quickly get what we need:
split the string wiht space, and convert the string into a list :

cpulist = info.split ()

After converting into the list, we can select the elements needed with operation like C language array to. Of course, there will still be elements in string format , then use function float () to transform them into floats:

load = float (cpulist [1]) + float (cpulist [2]) + float (cpulist [3])
total = load + float (cpulist [4])
cpu = load / total

Now we can see that the CPU occupacy rate is about 5% . Hoever, to output it to the OLED screen, I need to convert it into a percentage string – It may take me most of the day to complete the conversion with C. Well, python is really cool, as we only need one-row statement with python:

cpustring = str (cpu * 100) [: 4] + '%'

Done. At this point, we can send 5.88% as CPU occupancy rate of the board to OLED screen. Operation of memory occupancy rate is similar. I will update the complete code after finishing the whole display portion.