Aug 13, 2014

Lego Offroader + RaspberryPI + BrickPI + Wifi + Cam

I started this as a "learning python code" project, it should be something interesting,
not only "hello world" examples from the books ;-).  
















Diving into deep and searching the web, i found many interesting, existing things.
It makes fun, putting them together to a new project. Here's the (short) description ...






hardware list ...

Lego 9398 4x4 Offroader
RaspberryPI Model B, 16GB class 10 SD card
BrickPI

USB Wifi Module with Antena for RaspberryPI  (use the one from Adafruit's store)
RaspberryPI Cam, cam cable 30cm

Battery Box 8xAA, 8x eneloop accus 1.2V / 1900mAh
Easy Acc power Bank 8400mAh
Lego Mindstorms Ultrasonic Sensors
Lego Power Functions L-Motors, Servo Motor (original form Lego 9398 set)
some (conversion) cables, (NXT cables, PF cables)




conversion cables ...

make this cables only if you know what you are doing, I will not be held responsible if you break your BrickPI, RaspberryPI or any other parts...


NXT to "Power Functions M / L / XL Motor"





NXT to "Power Functions Servo Motor"






Battery Box "~9V Power to Servo Motor"





power ...
EasyAcc 8400 mAh USB 5V/2,1A to RaspberryPI

Battery Box 8xAA 1.2V / 1900mAh eneloop accus with total

10.8V output to BrickPI
9.4V output to PF servo motor, works for me with no damage until now
(with some usage, the output voltage will be less ...)

lessons learned ...
Don't use a PowerBank with 9V/2A output to power the BrickPI (and RaspberryPI),
this could break your BrickPI (especially the SN chips on it) 


RaspberryPI image ...

Download the latest BrickPI image from Dexter Industries here

in my setup I used the image 2014.06.05

follow the guide from Dexter to prep the SD card


some common things ...

network IP's in this example
eth0 adapter: 192.168.4.99
wlan0 adapter: 192.168.3.1

static network address for eth0 ...
nano /etc/network/interfaces

auto lo
iface lo inet loopback
iface eth0 inet static
    address 192.168.4.99
    netmask 255.255.255.0
    gateway 192.168.4.1


RaspberryPI configuration ..
raspi-config
- expand filesystem
- enable camera
- overclock medium (900Mhz)
- advanced: hostname:rpi, memory-split: 16MB

# Debian and Firmware Updates  
aptitude update
aptitude safe-upgrade
reboot
# firmware update
rpi-update
reboot



web cam and video stream ...

for detailed instructions google  "RPi-Cam-Web-Interface"

here's the quick start guide:

mkdir /project
cd project
git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
chmod u+x RPi_Cam_Web_Interface_Installer.sh
./RPi_Cam_Web_Interface_Installer.sh install


config file ...
/etc/raspimjpeg


start/stop cam ...
/project/webcam/RPi_Cam_Web_Interface
./RPi_Cam_Web_Interface_Installer.sh stop
./RPi_Cam_Web_Interface_Installer.sh start


video Stream on the Smartphone
On the Pi, run:
sudo ln -s /run/shm/mjpeg/cam.jpg /var/www/cam.jpg



Wifi Acess Point ...

follow the guide from Adafruit 
Setting up a RaspberryPI as a wifi Access Point,
skip the chapter "Configure Network Address Translation" (you don't need it)

If you get an INVALID ARGUMENT warning from hostapd, you may need to compile your own version of hostapd - you'll find the instructions here

my wlan0 adapter didn't  get a static IP after boot, so I added in
/etc/rc.local 
on the bottom:

...
echo ""
echo "... starting from /etc/rc.local ...."
echo "... setting up wlan0 interface to IP 192.168.3.1 ..."
ifconfig wlan0 192.168.3.1
sleep 5
echo "... (re)starting DHCP server ..."
service isc-dhcp-server restart
...
exit 0


my Python scrips(s) ...
you'll find the script(s) on my GitHub page here,

just copy it to /project

to start it at boot time, put it to /etc/rc.local behind the wlan0 stuff

...
/project/lego_9398_XY_104.py &

my python code was build with the Dexter Image 2014.03.03. In this image, there was a problem with ultrasonic measurements. The workaround for this is still implemented in my code.
When I have more time, I'll test it with the standard ultarsonic implementation.



connect ...

getting connected to the wifi car;

install  "Sensorstream IMU+GPS" from "Google Play Store"




install "IP Cam View Lite" from "Google Play Store"

Select the menu icon
Press Manage Cameras
Select Add Camera then Generic URL
Give your cam a name
For Type choose Generic Video URL
Enter your URL, e.g. http://192.168.3.1:80/cam.jpg
Press Test
If it works, press Save