2014年2月21日金曜日

MCU Gear Movies


Controlling Simple arm robot
I used Raspberry Pi,  iPad mini and PHP.


MCU Gear test with Raspberry Pi




Zigbee controled LPC 1114FN28 Tank with MCU Gear.
I try to use Lua script (loop) from my windows note PC.



This is a funny movie, to hack PS VITA.
My friend asked me "FF Thunder Plains (雷平原) are quite difficult to avoid thunder 200 times!".So, she try to make "Automatic Thunder Refuger" with Raspberry Pi , Python and MCU Gear(Board level reconfigurable circuit).
I just teach how to use photo sensor and small RC servo motor with these.

2014年2月19日水曜日

Web GPIO controller with PHP

INDEX
Set up Raspberry Pi Noobs
Install wiringPi
GPIO setting for Python.
(Python is the simplest sample code,.You don't need to check the number of GPIO. )
Web controller with PHP for MCU Gear
                                      

You can make GUI application easily.



                                      

Step 1: Install Apache and PHP

$sudo apt-get update
$sudo apt-get upgradesudo apt-get install apache2 php5
$sudo chown pi -R /var/www
$sudo updata-rc.d apache2 defaults

You can use HTML on /var/www/ folder.
                                      
Step 2 : Edit sudoers file

$sudo nano /etc/sudoers

Write "www-data ALL=(root) NOPASSWD: ALL" to the end of file.



Then you can use sudo command on PHP.

                                      

Step 3 : Download Sample program

$wget http://mcugear.org/RPitest/MUGear.tar
$tar xvf MCUGear.tar
$sudo mv -f MCUGear /usr/lib/cgi-bin

Then reboot RPi.
$sudo reboot

                                      

Step 4 : Test from you PC or Tablet.
Open browser and connect to 
http://raspberrypi.local/cgi-bin/MCUGear/index.php
or
http://[IP Address]/cgi-bin/MCUGear/index.php

You can see this page.



                                      

Step 5 :  How use it?

Push "Init Baseboard" botton that initialize baseboard and enable.

Read Input Pins : Read Input signal from Universal Module.
Write Output Pins : Write DA data to DA Module.
Read AD 2ch : Read AD data from 12bit AD 2ch module.
Read AD 8ch : Read AD data from 12bit AD 8ch module.
Write DA : Write DA data to DA Module.
Move RC Servo : Multifunction module 3ch PWM mode.

"Shutdown" is sudo halt command.
You do not need remote login for shutdown RPi.

PHP use System command format is
sudo python ***.py [module address] [data0] [data1] [data2] ...



GPIO setting for Python.

INDEX
Set up Raspberry Pi Noobs
Install wiringPi
GPIO setting for Python.
(Python is the simplest sample code,.You don't need to check the number of GPIO. )
Web GPIO controller with PHP
                                      

If you want to control GPIO with Python, you need this setting.




                                       Step 1 : Delete black list. And add "i2c-dev".

Open terminal, and type

$sudo nano /etc/modprobe.d/raspi-blacklist.conf

Type "#" to comment out bladk list. Put [ctrl]+[x] keys to save file.



$sudo nano /etc/modules
Write 
i2c-dev
at end of file. And  put [ctrl]+[x] keys to save file.



Step 2 : Install python-smbus

$sudo apt-get update

$sudo apt-get upgrade
$sudo apt-get install python-smbus
$sudo adduser pi i2c
$sudo reboot


Step 3 : I2C Test
Turn on MCU Gear. And type
$i2cdetect -y 0
or
$i2cdetect -y 1

It's depend on your Raspberry Pi version.



Step 4 : Setup SPI bus.
$sudo apt-get install python-dev
$sudo reboot

After reboot, check installed SPI.
$lsmod
Then you can see spi-bcm2708.





$mkdir python-spi 
$cd python-spi 
$wget https://raw.github.com/doceme/py-spidev/master/setup.py 
$wget https://raw.github.com/doceme/py-spidev/master/spidev_module.c 
$sudo python setup.py install 
$cd /home/pi/Desktop/
$wget http://mcugear.org/RPitest/MGPyVer1_1.tar
$tar xvf MGPyVer1_1.tar

You can see many sample program for each module.

$sudo python sample.py
is run command.

ex)LED blink test
This sample program apply to universal module.


N_VDD_VDD_VDD is address setting the reverse side of a module.
It means AD2 = VDD(+3V3) AD1 = VDD(+3V3)  AD0 = VDD(+3V3)
You can see detail on PCA9674 and PCA9674A datasheet.






You can simply check the sample program with LED and resister.



You can automatic wiring these pins on module.

p.NC : No connect c
p.outpin[0-5] : output pin
p.inpin[0-1] : input pin


Others are
SPI : MISO, MOSI, SCK, CE0 :
UART : TX, RX

You can check pin assigne on p.py.


! Option function is little bit difficult. You need to change sample program. (bank parameters)

Install wiringPi

INDEX
Set up Raspberry Pi Noobs
Install wiringPi
GPIO setting for Python.
(Python is the simplest sample code,.You don't need to check the number of GPIO. )
Web controller with PHP for MCU Gear
                                      

WiringPi is a GPIO access library written in C.



                                      

Step 1: Install
Type these command on your Pi's terminal.

$sudo apt-get install git-core

$sudo apt-get update
$sudo apt-get upgrade
$git clone git://git.drogon.net/wiringPi
$cd wiringPi
$git pull origin
$./build

test operation after build

$gpio -v
$gpio readall

You can see all IO setting like a picture.



Then reboot.
$sudo reboot

                                      
Step 2 : Download sample files, and compile.

$cd /home/pi/Desktop/
$wget http://www.mcugear.org/RPitest/MCUGearRPwp.tar
$tar xvf MCUGearRPwp.tar

Connect MCU Gear to Raspberry Pi and turn on.

You always need type these command for using I2C and SPI. 
$gpio load i2c 1000
$gpio load spi

Move directry.
$cd MCUGearRPwp

Compile it.

$g++ -Wall -o main main.c MCUGear.cpp MCUGearBase.cpp -lwiringPi
(MCU Gear sample program is C++ but main.c is C language.)

                                      

Step 3 : My favorite C & C++ editor is geany, It is very easy to use.
$sudo apt-get install geany

! Option function is little bit difficult. You need to change sample program. (bank parameters)

Set up Raspberry pi with NOOBS

INDEX
Set up Raspberry Pi Noobs
Install wiringPi
GPIO setting for Python.(Python is the simplest sample code,.You don't need to check the number of GPIO. 
)
Web controller with PHP for MCU Gear
                                      

Step 1 : Setup Raspbian on your SD card

Download NOOBS (offline and network install) from HERE.
Decompressed Zip file and move all files to SD card.

                                      

Step 2 :

Connect LAN cable, USB keyboard, USB mouse, HDMI cable, and SD card. Power on Raspberry Pi.
Select OS [Raspbian] and language.






                                      

Step 3 :

You can see dialog "succss" when finish the setting up the OS.



Push OK.

You can change password.
If you do not need to change, you ignore the setting.
default ID and Password is
ID : pi
Password : raspberry



                                      

Step 4 : Setup remote desktop appricatin




Type in these command for install remote desktop apprication. (If you do not need remote desktop, just type "$startx".)

$sudo apt-get update
$sudo apt-get upgrade
$sudo apt-get install xrdp
$ifconfig

Now, you can use remote desktop from windows with IP address (You can see it after ifconfig.).
Also, you can install avahi-deamon that allow you can access with NAME "raspberrypi.local" instead of the IP address.

$sudo apt-get install avahi-daemon

then reboot.

$sudo reboot

                                      

Step 5 : Try to accsess Raspberry Pi through the 


You can use remote desktop.
Input "rasberrypi.local"





username:pi
password:raspberry



You do not need check IP address.




                                      

If you can not remote login. Maybe, there is similar server (you can accsess with NAME like raspberrypi.local.)
Some router has such a NAME.

Try to connect other router and type

$ sudo rm /var/run/avahi-daemon/disabled-for-unicast-local
$ sudo /etc/init.d/avahi-daemon restart

or try access with IP addresss.