Showing posts with label Raspberry Pi 2. Show all posts
Showing posts with label Raspberry Pi 2. Show all posts

Monday, March 21, 2016

Make Buildroot (embedded Linux) for Raspberry Pi 2

Buildroot is a simple, efficient and easy-to-use tool to generate embedded Linux systems through cross-compilation.



To make sdcard image to run Buildroot on Raspberry Pi 2 using default config:

- Visit https://buildroot.org/ to download the latest stable release (2016.02 currently) - buildroot-2016.02.tar.gz.

- Unpack the downloaded file:
tar zxvf buildroot-2016.02.tar.gz

- Switch to the unpack folder:
cd buildroot-2016.02

- Copy the default config for Raspberry Pi 2:
$ cp configs/raspberrypi2_defconfig raspberrypi2_defconfig

- make:
$ make raspberrypi2_defconfig
$ make

- After make finished, buildroot-2016.02/output/images/sdcard.img will be created. It's the image file for Raspberry Pi 2.


- In my case, copy the sdcard.img file to Windows, and write to SD using Win32DiskImager.

- Then insert to Raspberry Pi 2 and boot-up. By default, the user "root" have no password.


Saturday, October 3, 2015

Friday, September 25, 2015

Python control Raspberry Pi 2 PWR/ACT LED, using RPi.GPIO or system's shell.

Last post show how to "Control Raspberry Pi 2 B on-board ACT LED with Python/RPi.GPIO", this example show how to control both the PWR and ACT LED of Raspberrry Pi 2 B, using Python, with RPi.GPIO and via system's shell by calling os.system().


*Please note that it's for Raspberrry Pi 2 B only*

Refer to Windows IoT document Raspberry Pi 2 Pin Mappings:
Red Power LED's GPIO# is 35.
Green Activity LED's GPIO# is 47.

In my experience, it cannot be perform using sudo, you have to login as root. To login as root, refer to the post "Set password of root".

pyGPIO.py
import sys
import os
import RPi.GPIO as GPIO
import time

print("**********************************************")
print("*** Toggle PWR/ACT LED on Raspberry Pi 2 B ***")
print("***        for Raspberry Pi 2 B only       ***")
print("**********************************************")
print("- System info -")
print(sys.version)
print("GPIO.VERSION: " + GPIO.VERSION)
print("GPIO.RPI_REVISION (deprecated): " + str(GPIO.RPI_REVISION))

print("")
print("GPIO.RPI_INFO:")
print(GPIO.RPI_INFO)

print("")
for keys,values in GPIO.RPI_INFO.items():
 print(keys + " : " + str(values))

print("")
#display trigger for led0 and led1
print("- Original trigger for led 0 -")
os.system("cat /sys/class/leds/led0/trigger")
print("- Original trigger for led 1 -")
os.system("cat /sys/class/leds/led1/trigger")

print("remove the trigger for led0 and led1")
os.system("echo none >/sys/class/leds/led0/trigger")
os.system("echo none >/sys/class/leds/led1/trigger")
os.system("cat /sys/class/leds/led0/trigger")
os.system("cat /sys/class/leds/led1/trigger")
print("")
 
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(35, GPIO.OUT) #Red PWR LED on RPi2B 
GPIO.setup(47, GPIO.OUT) #Green Activity LED on RPi2B

for num in range(1, 5):
    print num
    
    #Control led0 with RPi.GPIO
    GPIO.output(47, False)  #Turn OFF ACT LED for RPi 2 B
    GPIO.output(35, True) #Turn ON PWR LED for RPi 2 B
    print "LED PWR(RED)-ON ACT(GREEN)-OFF"
    time.sleep(2)

    #Control led1 with system's shell
    os.system("echo 1 >/sys/class/leds/led0/brightness")
    os.system("echo 0 >/sys/class/leds/led1/brightness")
    print "LED PWR(RED)-OFF ACT(GREEN)-ON"
    time.sleep(3)

print("")
print("Finished")
#rsume the trigger for led0 and 
#assume it's mmc0 and input
os.system("echo mmc0 >/sys/class/leds/led0/trigger")
os.system("echo input >/sys/class/leds/led1/trigger")

print("- Resummed trigger for led 0 -")
os.system("cat /sys/class/leds/led0/trigger")
print("- Resummed trigger for led 1 -")
os.system("cat /sys/class/leds/led1/trigger")
print("")


Thursday, September 24, 2015

Python/RPi.GPIO Control Raspberry Pi 2 B on-board ACT LED

I have a old example "Control the on-board LED using Python" to toggle Raspberry Pi 1 ACT LED. It's updated to toggle the ACT LED on Raspberry Pi 2.


On Raspberry Pi 2 B, the ACT LED is assigned pin 47.

pyGPIO.py
import sys
import RPi.GPIO as GPIO
import time

print(sys.version)
print("GPIO.VERSION: " + GPIO.VERSION)
print("GPIO.RPI_REVISION (deprecated): " + str(GPIO.RPI_REVISION))

print("")
print("GPIO.RPI_INFO:")
print(GPIO.RPI_INFO)

print("")
for keys,values in GPIO.RPI_INFO.items():
 print(keys + " : " + str(values))
 
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#GPIO.setup(16, GPIO.OUT)
GPIO.setup(47, GPIO.OUT)

for num in range(1, 5):
    print num
    #GPIO.output(16, True)   ##Turn OFF LED
    GPIO.output(47, False)   ##Turn OFF LED for RPi 2 B
    print "LED OFF"
    time.sleep(2)
    #GPIO.output(16, False) ##Turn ON LED
    GPIO.output(47, True)   ##Turn ON LED for RPi 2 B
    print "LED ON"
    time.sleep(3)

#GPIO.output(16, True)   ##Turn OFF LED
GPIO.output(47, False)   ##Turn OFF LED for RPi 2 B


In my experience, it cannot be perform using sudo, you have to login as root. To login as root, refer to the post "Set password of root".

Then login as root.

by default, the ACT LED is set triggered by mmc0. It can be checked with the command:

# cat /sys/class/leds/led0/trigger
none [mmc0] timer oneshot heartbeat backlight gpio cpu0 default-on

In order to program it as GPIO, remove the trigger with the command:
# echo none >/sys/class/leds/led0/trigger

Run our Python example, pyGPIO.py
# python pyGPIO.py

After test, resume the trigger by mmc0 with command (or reboot):
# echo mmc0 >/sys/class/leds/led0/trigger


Next:
- Python control Raspberry Pi 2 PWR/ACT LED, using RPi.GPIO or system's shell.

Sunday, September 20, 2015

Intro to Development and Deploying Applications to Windows IoT Core on Raspberry Pi 2

In this video we will go over deploying apps through Visual Studio and the web portal running on port 8080 of the Raspberry Pi2,  In addition, we will look at code examples using XAML User Interface code in both C# and C++.
source: https://channel9.msdn.com/Blogs/WinCoder/Intro-to-Development-and-Deploying-Applications-to-Windows-IoT-Core-on-Raspberry-Pi-2



Related: Setup Windows 10 IoT Core on Windows 10 and Raspberry Pi 2

Setup Windows 10 IoT Core on Windows 10 and Raspberry Pi 2

This videos show how to:
  • Install the Windows 10 IoT Core tools on Windows 10
  • Flash Windows 10 IoT Core image on micro-SD
  • Boot-up Windows 10 IoT Core on Raspberry Pi 2
  • Install Windows IoT Core Project Templates for Visual Studio 2015 

- Install the Windows 10 IoT Core tools on Windows 10


- Flash Windows 10 IoT Core image on micro-SD
* Advised use micro-SD of class 10, I tried class 4 but fail in boot-up.


- Boot-up Windows 10 IoT Core on Raspberry Pi 2
* Advised to connect mouse also, to navigate in Windows 10 IoT Core/Raspberry Pi 2 windows.


reference: http://ms-iot.github.io/content/en-US/win10/SetupRPI.htm

- Install Windows IoT Core Project Templates for Visual Studio 2015, Install Windows IoT Core Project Templates for Visual Studio 2015, directly from Visual Studio in the Extension and Updates dialog (Tools - Extensions and Updates - Online).


reference: http://ms-iot.github.io/content/en-US/win10/SetupPCRPI.htm


Related: Intro to Development and Deploying Applications to Windows IoT Core on Raspberry Pi 2

Thursday, August 13, 2015

Windows 10 IoT Core Public Released and Home Automation Contest

Windows 10 IoT Core Team are excited to announce the public release of Windows 10 IoT Core! With this are bringing the capabilities of Windows 10 to boards like the Raspberry Pi 2. Learn more about this exciting new release in the blog post, "Hello, Windows 10 IoT Core". You can download it now for free to use in your projects.


To celebrate the release, the "Windows 10 IoT Core - Home Automation Contest" is announced in collaboration with http://www.hackster.io/. To participate, build a home automation solution that leverages the power of Windows 10 IoT Core running on Raspberry Pi 2. The two grand prizes are a trip to Maker Faire, New York for a winner from US and to Maker Faire, Rome for a winner from Europe to demo your projects to your fellow Makers. Other prizes include up to $2000 in gift certificates and a free Raspberry Pi 2 kit to the top 100 shortlisted projects!

* See ‘Challenge Rules’ on https://www.hackster.io/challenges/Windows10Automation for more details about the contest.

Thursday, April 30, 2015

Windows 10 IoT Core Insider Preview with support for Raspberry Pi 2, available now.

Starting today you can download Windows 10 IoT Core Insider Preview with support for Raspberry Pi 2 and Intel’s Minnowboard Max. Windows 10 IoT Core is a new Windows 10 edition for low-cost, small-footprint devices that will be available ‘free’ for Makers and commercial device builders.

Get Started
Click to Learn how to set up the Raspberry Pi 2 and connect it to your computer. Note that this requires you to have a PC running Windows 10 Technical Preview.


Friday, April 24, 2015

My Raspberry Pi 2 cannot detect monitor resolution!!!

I use a DVI-HDMI cable to connect my Raspberry Pi 2 to Monitor. Originally, it can recognize the monitor as 1440x900. Suddenly, it cannot recognize it, and treat it as 640x480. Something fail on my RPi 2!? I know how to manually set resolution on /boot/config.txt, but I want it detect automatically.



Correct display on Raspberry Pi 1 board:

Friday, April 17, 2015

How cool is a fan for Raspberry Pi 2

This video show The cooling effect of fan case for Raspberry Pi 2. Run the Raspberry Pi 2 inside a open top case, to stable around 48C, then cover with fan, the temperature drop to around 37C.


The Python code can be found here: "Plot "vcgencmd measure_temp" on uptime, Raspberry Pi 1 vs 2".

Wednesday, April 8, 2015

Plot "vcgencmd measure_temp" on uptime, Raspberry Pi 1 vs 2

It's a Python script to plot "vcgencmd measure_temp" on uptime.

plotTemp.py
import os
import matplotlib.pyplot as plt
import multiprocessing

tempC = []
upTimes = []
plt.ion()
cnt=0

def getUpTIme():
    ut = os.popen("awk '{print $1}' /proc/uptime").readline()
    return ut

def plotNow():
    plt.clf()
    plt.ylim(20,60)
    plt.title(title)
    plt.grid(True)
    plt.ylabel('Temp (C)')
    plt.xlabel('uptime (S)')
    plt.plot(upTimes, tempC, 'rx-')
    plt.show()

numOfCPU = multiprocessing.cpu_count()
title = "temp. vs uptime@Raspberry Pi (" + str(numOfCPU) + " core)"

while True:
    ostemp = os.popen('vcgencmd measure_temp').readline()
    temp = (ostemp.replace("temp=", "").replace("'C\n", ""))
    tempC.append(temp)
    
    ut = getUpTIme()
    upTimes.append(ut)

    print(len(tempC))
    print(temp)
    print("uptime(sec) = "+ut)
    
    if len(tempC)>=200:
        tempC.pop(0)
        upTimes.pop(0)
    
    plotNow()
    plt.pause(1)



Run on Raspberry Pi 1 Model B, with medium overclock, at power up, running this script only:




Run on Raspberry Pi 2 Model B, with medium overclock.


at power up, running this sript only:

Playing Youtube:

Plot RPi 2 core temperature using Python 2 and matplotlib.pyplot

Similar to the previous example "Display Raspberry Pi CPU temperature graphically, using Python 2 with Matplotlib and drawnow", but use library of matplotlib.pyplot only, no drawnow.


import os
import matplotlib.pyplot as plt

tempC = []
plt.ion()
cnt=0

def plotNow():
    plt.clf()
    plt.ylim(20,80)
    plt.title('Raspberry Pi core temperture')
    plt.grid(True)
    plt.ylabel('Temp C')
    plt.plot(tempC, 'rx-', label='Degrees C')
    plt.legend(loc='upper right')
    plt.plot(tempC)
    plt.show()

#pre-load dummy data
for i in range(0,26):
    tempC.append(0)
    
while True:
    ostemp = os.popen('vcgencmd measure_temp').readline()
    temp = (ostemp.replace("temp=", "").replace("'C\n", ""))
    print(temp)
    tempC.append(temp)
    tempC.pop(0)
    plotNow()
    plt.pause(.5)



Saturday, April 4, 2015

Install latest version of Mono and MonoDevelop on Raspberry Pi/Raspbian

My previous post show Install Mono/MonoDevelop on Raspberry Pi/Raspbian using the default package repository. The installed version will be mono 3.2.8 and monodevelop 3.0.3.2. Alternatively, we can update the package repository on the system to install with latest release: mono 3.12.1 and monodevelop 5.7.0 currently.




The page http://www.monodevelop.com/download/linux/ and http://www.mono-project.com/docs/getting-started/install/linux/#debian-ubuntu-and-derivatives provide instructions to install MonoDevelop and Mono on Linux, include Debian. We can follow the steps to install on Raspberry Pi/Raspbian.

My steps is summrized here:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list

echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install mono-devel
sudo apt-get install mono-complete
sudo apt-get install referenceassemblies-pcl

sudo apt-get install monodevelop
sudo apt-get install monodevelop-nunit
sudo apt-get install monodevelop-versioncontrol
sudo apt-get install monodevelop-database

The videos show how to, on Raspberry Pi 2/Raspbian:



Here how it run remotely via ssh:



and via xrdp on Raspberry Pi and remmina on Ubuntu Linux:




Related:
- Solve MonoDevelop error: cannot execute "...". File name hase not been set.

Monday, March 30, 2015

Python display CPUs frequency graphically, run on Raspberry Pi 2/Linux


In Linux, the file "/sys/devices/system/cpu/*/cpufreq/scaling_cur_freq" show the available frequency your CPU(s) are scaled to currently, in KHz.

In Raspberry Pi 2/Raspbian, where is:
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq
/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq
/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq

This Python 2 example run on Raspberry Pi 2, to display CPU frequency graphically. (It seem that all CPU run on the same frequency)


plotCpuFreq.py
import os
import matplotlib.pyplot as plt
from drawnow import *

# Run on Raspberry Pi 2
# 4 CPUs
cpu0Freq = []
cpu1Freq = []
cpu2Freq = []
cpu3Freq = []

plt.ion()
cnt=0

def plotCpuFreq():
    plt.ylim(0,1500000)
    plt.title('Raspberry Pi 2 CPUs Frequency')
    plt.grid(True)
    plt.ylabel('KHz')
    plt.plot(cpu0Freq, 'r^-', label='cpu0')
    plt.plot(cpu1Freq, 'c>-', label='cpu1')
    plt.plot(cpu2Freq, 'bv-', label='cpu2')
    plt.plot(cpu3Freq, 'm<-', label='cpu3')
    plt.legend(loc='upper right')

#pre-load dummy data
for i in range(0,100):
    cpu0Freq.append(0)
    cpu1Freq.append(0)
    cpu2Freq.append(0)
    cpu3Freq.append(0)
    
while True:
    cpu0 = os.popen("awk '{print $1}' /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq").readline()
    cpu1 = os.popen("awk '{print $1}' /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq").readline()
    cpu2 = os.popen("awk '{print $1}' /sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq").readline()
    cpu3 = os.popen("awk '{print $1}' /sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq").readline()

    print(cpu0 + " " + cpu1 + " " + cpu2 + " " + cpu3)
    cpu0Freq.append(cpu0)
    cpu0Freq.pop(0)
    cpu1Freq.append(cpu1)
    cpu1Freq.pop(0)
    cpu2Freq.append(cpu2)
    cpu2Freq.pop(0)
    cpu3Freq.append(cpu3)
    cpu3Freq.pop(0)
    
    drawnow(plotCpuFreq)
    plt.pause(1)



To install needed libraries on Raspberry Pi, refer to "Install numpy, matplotlib and drawnow for Python 2".


The almost same code run on Linux with dual core.


plot2CpuFreq.py
import os
import matplotlib.pyplot as plt
from drawnow import *

# Run on Dual Core Atom
# with 2 CPU
cpu0Freq = []
cpu1Freq = []

plt.ion()
cnt=0

def plotCpuFreq():
    plt.ylim(0,2000000)
    plt.title('Dual Core CPUs Frequency')
    plt.grid(True)
    plt.ylabel('KHz')
    plt.plot(cpu0Freq, 'r^-', label='cpu0')
    plt.plot(cpu1Freq, 'c>-', label='cpu1')
    plt.legend(loc='upper right')

#pre-load dummy data
for i in range(0,100):
    cpu0Freq.append(0)
    cpu1Freq.append(0)
    
while True:
    cpu0 = os.popen("awk '{print $1}' /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq").readline()
    cpu1 = os.popen("awk '{print $1}' /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq").readline()

    print(cpu0 + " " + cpu1)
    cpu0Freq.append(cpu0)
    cpu0Freq.pop(0)
    cpu1Freq.append(cpu1)
    cpu1Freq.pop(0)
    
    drawnow(plotCpuFreq)
    plt.pause(1)



Sunday, March 29, 2015

Python display Raspberry Pi load average graphically

The file /proc/loadavg indicate the load average figures giving the number of jobs in the run queue (state R) or waiting for disk I/O (state D) averaged over 1, 5, and 15 minutes. This Python 2 example read the first figure (over 1 minutes) every second, and plot to figure using Matplotlib.


plotLoadAvg.py
import os
import matplotlib.pyplot as plt
from drawnow import *

loadavg = []

plt.ion()
cnt=0

def plotLoadAvg():
    plt.ylim(0,4)
    plt.title('Raspberry Pi load average')
    plt.grid(True)
    plt.ylabel('usage')
    plt.plot(loadavg, 'bo-', label='usage')
    plt.legend(loc='upper right')

#pre-load dummy data
for i in range(0,100):
    loadavg.append(0)
    
while True:

    usage = os.popen("awk '{print $1}' /proc/loadavg").readline()
    print(usage)
    loadavg.append(usage)
    loadavg.pop(0)
    drawnow(plotLoadAvg)
    plt.pause(1)



For installation of the libraries, read "Install numpy, matplotlib and drawnow for Python 2".

Display Raspberry Pi CPU temperature graphically, using Python 2 with Matplotlib and drawnow

Python 2 example to display Raspberry Pi CPU temperature graphically, with Matplotlib and drawnow.



This exercise work on Python 2 and need matplotlib and drawnow, refer to "Install numpy, matplotlib and drawnow for Python 2".

plotTemp.py
import os
import matplotlib.pyplot as plt
from drawnow import *

tempC = []

plt.ion()
cnt=0

def plotTempC():
    plt.ylim(20,80)
    plt.title('Raspberry Pi core temperture')
    plt.grid(True)
    plt.ylabel('Temp C')
    plt.plot(tempC, 'rx-', label='Degrees C')
    plt.legend(loc='upper right')

#pre-load dummy data
for i in range(0,26):
    tempC.append(0)
    
while True:

    ostemp = os.popen('vcgencmd measure_temp').readline()
    temp = (ostemp.replace("temp=", "").replace("'C\n", ""))
    print(temp)
    tempC.append(temp)
    tempC.pop(0)
    drawnow(plotTempC)
    plt.pause(.5)





For Python 3:

Matplotlib for Python 3 is not support currently. I tried to build it from source (refer "Install numpy, matplotlib and drawnow for Python 2" and "Fail to build matplotlib for Python3, run on Raspberry Pi 2"), but nothing plotted while running.



Similar example without using drawnow, "Plot RPi 2 core temperature using Python 2 and matplotlib.pyplot".

Sunday, March 22, 2015

Install C/C++ plugins for NetBeans on Raspberry Pi 2/Raspbian

It is assumed you have NetBeans 8.0.2 installed on your Raspberry Pi 2/Raspbian. By installing C/C++ plugins to NetBeans IDE, you can develop in C/C++.


- Click Tools -> Plugins
- Select Available Plugins tab
- Search C/C++, and check it.
- Click Install


Install NetBeans IDE on Raspberry Pi 2/Raspbian, to program using Java

NetBeans IDE is the official IDE for Java 8. With quad-core ARM Cortex-A7 CPU on Raspberry Pi 2, pre-loaded Java 8 on Raspbian, it's easy to install NetBeans 8 on Raspberry Pi.


Visit NetBeans Download page (https://netbeans.org/downloads/), select Platform of OS Independent Zip, download and un-zip to any folder you want.

Switch to the unzipped /netbeans/bin folder, run the executable file netbeans:
$ ./netbeans

This video show how to download and install NetBeans IDE 8.0.2 on Raspberry Pi 2.



It is seem JavaFX not supported currently




x Error of failed request: BadMatch (invalid parameter attributes)

In the above demo video, I log-in Raspberry Pi 2 remotely with xrdp run on RPi 2, and remmina (Remote Desktop Client) on another PC running Ubuntu Linux.

Originally, I set Color depth of High color (15 bpp), it work once only. After then, I run netbeans next time, it fail with following error:

x Error of failed request: BadMatch (invalid parameter attributes)
  Major opcode of failed request: 72 (x_PutImage)
  Serial number of failed request: 51
  Current serial number in output stream: 55

To fix it in my case, set Color depth of High color (16 bpp).



Next:
- Install C/C++ plugins for NetBeans on Raspberry Pi 2/Raspbian

Related:
- A example of Java to get CPU frequency, build with NetBeans on Raspberry Pi, the jar run on other Linux machine also.

Wednesday, March 18, 2015

Install Android 4.4.2 KitKat on Raspberry Pi 2 with BerryBoot v2.0

With BerryBoot (refer to the post "Install Ubuntu Linaro on Raspberry Pi 2 with BerryBoot v2.0"), we can install Android 4.4.2 KitKat on Raspberry Pi.

This video show how the Android run on Raspberry Pi 2.

But the performance is so...! Hope it can be improved soon.