Introduction: Open Hardware Rover With Arduino and Raspberry Pi

This Rover is based on Arduino and Raspberry PI 2.

The way to operate the rover and use the camera, is using a Wiimote and Nunchuk connected with the Arduino by a Bluetooh connection.

On the one hand, Arduino controls the servos and the brushless motor.

On the other hand, Raspberry Pi2 manages the video streaming send to the PC that you can watch in VLC.

Step 1: Materials

- RC Car (or something like this): I am using Survolt BX10 first generation.

- Arduino Uno.

- Arduino USB Shield.

- Bluetooh 4.0 Dongle: I am using this --> http://www.ebay.es/itm/Mini-USB-bluetooth-4-0-Dong...

- Raspberry pi 2 or 3.

- Wifi module for Raspberry.

- Pi camera V2

- Camera mount for 2 servos.

- 2 X servo.

- A lot of wires.

- Batteries, power banks.....

- Wiimote and Nunchuk.

Step 2: Setup the Raspberry Streaming

I am using the last Raspbian distribution at the date 26/8/2017

The first is to install the VLC in our Raspi.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install vlc

Now you have the VLC installed. The next step is setup the video stream.

The easiest way is making one script that we can launch:

#!/bin/bash

raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264

In this moment we have the stream prepared.

Don't forget to install the VLC in your computer!!

Step 3: Arduino Diagram

You have to connect all like it is in the picture.

The ESC's power pin don't have any connection.

Over the Arduino UNO you have to use the USB shield with the Bluetooh dongle in the USB port

Is important use the pins 2, 3, 4, 5, 6, 7 and 8 for the servo signal, because the rest of the pins are use for other kind of comunications with the USB Shield and the servos in the rest of pins don't work.

You can powered the Arduino with your favorite kind of battery.

Step 4: Arduino Code

/* You have to install in your Arduino IDE the USB Shield library */

#include  <Servo.h>
#include <Wii.h>
#include <usbhub.h>
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h> #endif
#define PINCAMERAY 2 
#define PINCAMERAZ 3
#define PINSERVO 4
#define PINMOTOR 5
#define STARTPWM 116
/*
 * Wiimote code
 */
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
//WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
bool printAngle=false;
/*
 * Servo code
 * For servos items we have to use PIN: 2, 3, 4, 5, 6, 7, 8
 */
int pulsoMotor=103; //Initial valor to initialice the ESC, if you are using a different esc, this valor maybe change.
int pulsoDireccion=90; // Initial valor for the direction servo
int direccion=0;
Servo servoY,servoZ,servoD, motor;
byte recibiendoByte ;
boolean iniciado = false;
int x,y, mov, dire;
/*
 * 
 */
void setup() {
  Serial.begin(115200);
  /*
   * Setup servos
   */
  servoY.attach(PINCAMERAY);
  servoZ.attach(PINCAMERAZ);
  servoD.attach(PINSERVO);
  motor.attach(PINMOTOR);
  while ( iniciado==false ){
          motor.write(0);   // Armado
          servoD.write(pulsoDireccion); 
          
          iniciado=true;
            
  } 
  motor.write(pulsoMotor);
  /*
   * Setup Wii
   */
  //Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  }
  
  Serial.print(F("\r\nWiimote Bluetooth Library Started"));
}
void loop() {
  Usb.Task();
  if (Wii.wiimoteConnected) {
    
      if(Wii.getButtonClick(A)){
        printAngle=!printAngle;
      }
      if(printAngle){
        Serial.println(Wii.getPitch());
        mov=Wii.getPitch();
        mov=map(Wii.getPitch(),0,360,0,180);
        
        if(mov > 117)
          motor.write(117);
        else
          if(mov <100)
            motor.write(100);
          else
            motor.write(mov);
        
        Serial.println(Wii.getRoll());
        dire=Wii.getRoll();
        //dire=map(Wii.getRoll(),0,360,0,180);
        if(dire <170)
          dire=0;
        else
          if(dire > 190)
            dire=180;
          else
            dire=90;
        
        servoD.write(dire);
      }
      if (Wii.nunchuckConnected) {
        if (Wii.getAnalogHat(HatX) > 137 ||  Wii.getAnalogHat(HatX) < 117 || Wii.getAnalogHat(HatY) > 137 || Wii.getAnalogHat(HatY) < 117) {
          
          x=map(Wii.getAnalogHat(HatX),34,239,0,180);
          y=map(Wii.getAnalogHat(HatY),30,244,0,180);
          
          servoY.write(x);
          servoZ.write(y+40);
        }
        
      }
      if(!printAngle){
        servoD.write(90);
        motor.write(102);
      }
    
 }
  
}

Step 5: Build the Rover

Now is the moment to mount all the things over our platform.

You can use your creativity in this step to make your oun rover.

Step 6: Run the Rover

In this point we have all the things prepared to start the Rover.

1 - Connect the batery to the ESC and power on the ESC (in this point you maybe obtain 2 bips in the ESC)

2- Charge the program on the Arduino (in this point you have to have other bip for confirmation)

3- Power on the wiimote pussing 1 and 2 at the same time.

4- Power on the Raspberry Pi 2.

5- Execute the Script to initialize the Streaming.

6- In the VLC program on your computer go to Media-> Open network, in this window you have to use this direction: http://yourraspberryIP:8090

You can watch the proccess in this video, Sorry I am Andalusian Spaniard :)

The Video Stream have a 3-5 seconds delay.

Enjoy the Rover!!!!