Friday, August 14, 2015

Internet of things - Rasberry Pi2

Hook up your board

  1. Insert the micro SD card you prepared (the slot is on the opposite side of the board shown below).
  2. Connect a network cable from your local network to the Ethernet port on the board. Make sure your development PC is on the same network.

  3. Connect an HDMI monitor to the HDMI port on the board.
  4. Connect the power supply to the micro USB port on the board.

Install the Rasbian 20XX-XX-XX-raspbian-wheezy.img or Ubuntu Mate image Windows

  1. Download the IMG for the Raspberry Pi 2 from or from for Ubuntu Mate.  For Ubuntu mate mouse over on one of the country icon and use wget if you want to download inside a Window shell
eg: wget

Put the Image on your SD card

Using the Win32DiskImager program

1.   Download the distribution from the downloads page or from a mirror or torrent. Make sure the distribution is for the Raspberry Pi, as others will not work. Usually these are zipped (compressed) files ending in .zip or .gz (something like "").
2.   Extract the image file from the downloaded .zip file, so you now have "distribution-name.img".
3.   Insert the SD card into your SD card reader and check what drive letter it was assigned. You can easily see the drive letter (for example G:) by looking in the left column of Windows Explorer. You can use the SD Card slot (if you have one) or a cheap Adapter in a USB slot.
4.   Download the Win32DiskImager utility (it is also a zip file). You can run this from a USB drive.

5.   Extract the executable from the zip file and run the Win32DiskImager utility; you may need to run the utility as Administrator! Right-click on the file, and select 'Run as Administrator'
6.   Select the image file you extracted above.
7.   Select the drive letter of the SD card in the device box. Be careful to select the correct drive; if you get the wrong one you can destroy your data on the computer's hard disk! If you are using an SD Card slot in your computer (if you have one) and can't see the drive in the Win32DiskImager window, try using a cheap Adapter in a USB slot.
8.   Click Write and wait for the write to complete.
9.   Exit the imager and eject the SD card.
10. You are now ready to plug the card into your Raspberry Pi


if you plan to use an apple keyboard (the white one) connect the Mouse directly on the Pi which now has 4 external USB! Sweet! Else the keyboard won't be recognize

User management in Raspbian is done on the command line. The default user is pi with the password raspberry. You can add users and change each user's password.


When logged in as the pi user you can change your password with the passwd command.

Enter passwd on the command line and hit Enter. You'll be prompted to enter your current password to authenticate, and then asked for a new password. Hit Enter on completion and you'll be asked to confirm it. Note that no characters will be displayed while entering your password. Once you've correctly confirmed, you'll be shown a success message (passwd: password updated successfully) and the new password will be in effect immediately.

If your user has sudo permissions, you can change another user's password with passwd proceeded by the user's username, e.g. sudo passwd bob will allow you to set the user bob's password, and then some additional optional values for the user such as their name. Just hit Enter to skip each of these options.


sudo dpkg-reconfigure keyboard-configuration

Reload the keymap

invoke-rc.d keyboard-setup start

AlaMode works on the Pi 2

ICoutesy Element 14
the new Pi 2 is quite snappy, even the web browser is quite useable. It should be a marvelous platform for your IOT projects! Especially with AlaMode.
It has the same form factor as the B+ so you have to plug the AlaMode’s shorter GPIO connector into one end of the header, and the board overlaps the connector end of the Pi by a few millimeters. I recommend putting some electrical tape over the metal cans of the connectors to keep from shorting AlaMode’s headers.
Because the Pi 2 has a new processor, the GPIO base addressed changed, which makes us update our patched version of avrdude. (needed because standard Arduinos use serial ports handshaking to toggle the reset line, we use a GPIO pin)
Get the new setup here:
tar -xvzf alamode-setup.tar.gz
cd alamode-setup
sudo ./setup
Note if you haven’t already, you’ll need a new version of Raspbian that supports the Pi2, plus installing Arduino 
pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get install arduino
before running the setup above.

      Ubuntu Mate

Re-size file system (Wheezy)

There are no utilities included for automatic file system re-sizing. However, it's not hard to do manually. Once booted:
$sudo fdisk /dev/mmcblk0
Delete the second partition (d, 2), then re-create it using the defaults (n, p, 2, enter, enter), then write and exit (w). Reboot the system, then:
$sudo resize2fs /dev/mmcblk0p2

$ sudo parted /dev/mmcblk0p2
(parted) print

In my case using a 16GB sdcard
Model: Unknown (unknown)
Disk: /dev/mmcblk0p2: 15.9 GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk FLags:

Number Start End Size File systen Flags
1      0.00B 15.9GB   ext4
(parted) quit

Hardware accelerated video

To play videos using hardware accelerated decoding you will need MPEG-2 and/or VC-1 licenses from the Raspberry Pi Store. You can then use omxplayer, which uses the Raspberry Pi VideoCore libraries, to provide hardware accelerated video playback.

Redirecting audio output

You can select which audio device omxplayer should output audio to.
omxplayer -o hdmi video.mp4
For 3.5mm audio jack
omxplayer -o local video.mp4
The sound will output to HDMI by default if both HDMI and the 3.5mm audio jack are connected. You can, however, force the system to output to a particular device using amixer.
sudo amixer cset numid=3 2
For 3.5mm audio jack
sudo amixer cset numid=3 1

Wifi dongle

I purchased Netis WF2120 worked out of the box!! 

Microsoft Wireless All In one keyboard 

work out of the box with Raspbian Jessie 

Apple Wireless Keyboard and Apple Magic Mouse

I managed to get an "Apple Wireless Keyboard" and "Apple Magic Mouse" 
working.  The is a lot of crap out there on how to do it.  This is what 
worked here (blueman did NOT work).
The advantage of doing it this way is that the keyboard and mouse are available without X.
Here they work at boot.

Buy BLE USB dongle : Cirago BTA8000 worked out of the box!!

Get root
sudo -i

apt-get install bluetooth bluez-tools
Wait a long time....

check bluetooth status:
/etc/init.d/bluetooth status

You may need to start bluetooth, if its not running:
/etc/init.d/bluetooth start

hciconfig -a
You should see a line with "UP RUNNING PSCAN" probably on hci0

If its down you it may come up with:
hciconfig hci0 up

Once hci0 is up, find the address of the device you want to pair:
hcitool scan
and copy the bluetooth address to use in the following commands

pair the keyboard (here an old apple wireless keyboard):
bluez-simple-agent hci0 68:D9:3C:ED:47:15

it will prompt you for a pin, enter a 4 digit number for the keyboard, then type in on the keyboard and press enter on it.
For the mouse try 0000 or 1234. If you need to pair
again you may get and error. If so append repair after the and the old
pairing is deleted.

You want your Pi to remember that your keyboard’s paired with it so it will connect to that keyboard when it boots. You can tell your Pi to trust your keyboard with the bluez-test-device the device:
bluez-test-device trusted yes

and connect it:
bluez-test-input connect

Once you’ve got your Apple keyboard paired, trusted, and conneted, you can unplug your USB keyboard and reboot your Pi. If your Pi doesn’t immediately pick up your Apple keyboard on boot, you can prompt it to connect my pressing any key. The LED will flash once, and then you can type normally.repeat the pairing, trusting, connects for each device. I have only tested this with input
devices (eg keyboard and mouse).

If you need a GUI tool for Bluetooth install Blueman

sudo apt-get install blueman

For Cambridge Silicon Radio Bluetooth Dongle

make following change:
add line "blacklist hci_usb" into /etc/modprobe.d/alsa-base-blacklist.conf
and line "hci_usb reset=1" into /etc/modules. After reboot dongle should work

PS3 DualShick controller on PI

install dependencies first

sudo apt-get install bluez-utils bluez-compat bluez-hcidump checkinstall libusb-dev  libbluetooth-dev joystick

It takes a while.

After all type "hciconfig" in console, you should see something like this.

pi@raspberrypi ~ $ hciconfig
hci0: Type: BR/EDR Bus: USB
 BD Address: 00:1F:81:00:06:20 ACL MTU: 1021:4 SCO MTU: 180:1
RX bytes:1260 acl:0 sco:0 events:46 errors:0
TX bytes:452 acl:0 sco:0 commands:45 errors:0

if not, your dongle seems not to be recognized by system.

So now, we need to pairing the dongle with the gamepad using this tool.

download and compile it.

gcc -o sixpair sixpair.c -lusb

After this you should have a executable file "sixpair".
Now connect your  Dualshock via a USB cable for PS3 to Raspberry Pi and launch this file with sudo.

sudo ./sixpair

Current Bluetooth master: DE:AD:BE:EF:00:00
Setting master bd_addr to: 00:1F:81:00:06:20

If you see this, it was successful.

Install a Sixaxis Joystick Manager. Download a last archive and compile only important for us part.

tar xfvz QtSixA-1.5.1-src.tar.gz
cd QtSixA-1.5.1/sixad
sudo mkdir -p /var/lib/sixad/profiles
sudo checkinstall

the last command make automatically a package for you, so you can later simple uninstall it, if you won't it or use a different system, type  "sudo make install" instead of "sudo checkinstall"

Now test it, for this launch temporary a sixad daemon.

sudo sixad --start

Then press a "PS" button on Dualshock gamepad, if you feel a vibration, it works, congratulations!

After all you can make "sixad" daemon starting at boot time.

sudo update-rc.d sixad defaults

If you have any trouble with recognition, you can debug your Dualshock controller with "jstest".

sudo jstest /dev/input/js0

Finally you will need to purchase a charher for the PS3 controller if you don't have a PS3.
I got the Energizer one and I like it a lot

No comments: