Fabrication industrielle
Internet des objets industriel | Matériaux industriels | Entretien et réparation d'équipement | Programmation industrielle |
home  MfgRobots >> Fabrication industrielle >  >> Manufacturing Technology >> Processus de fabrication

Véhicule Télécommandé par Android avec Raspberry Pi et Shield Moteur

Composants et Fournitures

ComposantQuantité
Appareil Android1
Arduino 1011
Raspberry Pi 2 Modèle B1
Shield Moteur Dk Electronic1
Dongle WiFi Officiel Raspberry Pi1
Batterie Externe Trust 5V1

Applications et Services en Ligne

À Propos du Projet

À la fin du projet, nous contrôlerons un véhicule tout-terrain via le capteur accéléromètre d'un appareil Android.

Le projet inclut : shield moteur, Raspberry Pi, Arduino et moteurs DC.

ÉTAPE 1 : Bus I2C entre Raspberry Pi et Arduino

D'abord, nous devons établir un bus I2C entre le Raspberry Pi et l'Arduino. Vous pouvez voir pourquoi nous choisissons l'I2C ici.

Le code requis contenant à la fois l'I2C et le processus du shield moteur :


#include 
#define MyAddress 0x40
#include 
AF_DCMotor motorhiz(3);
AF_DCMotor motoryon(4);
byte DataToBeSend[1];
byte ReceivedData;
int counter = 0;

void setup() {
  Serial.begin(9600);
  Wire.begin(MyAddress);
  Wire.onReceive(I2CReceived);
  Wire.onRequest(I2CRequest);
  motorhiz.setSpeed(254);
  motorhiz.run(RELEASE);
  motoryon.setSpeed(254);
  motoryon.run(RELEASE);
}

void loop() {
  // DataToBeSend[0] = (DataToBeSend[0] >= 99) ? 0 : DataToBeSend[0] + 1;
}

void I2CReceived(int NumberOfBytes) {
  ReceivedData = Wire.read();
  int ReceivedDataInt = (int)ReceivedData;
  String ReceivedDataStr = String(ReceivedData);
  Serial.println(ReceivedDataInt);

  if(ReceivedDataInt >= 100) // Données X
  {
    Serial.println("DataX :" + ReceivedDataStr);
    if(ReceivedDataInt > 145 && ReceivedDataInt < 154) {
      Serial.println("RELEASE");
      motorhiz.run(RELEASE);
    } else if(ReceivedDataInt >= 100 && ReceivedDataInt < 104) {
      Serial.println("RELEASE");
      motorhiz.run(RELEASE);
    } else if(ReceivedDataInt >= 155) {
      ReceivedDataInt = ReceivedDataInt - 155;
      int motorSpeed = (ReceivedDataInt * 10) + 50;
      if(motorSpeed > 254) motorSpeed = 254;
      motorhiz.setSpeed(motorSpeed);
      motorhiz.run(BACKWARD);
      Serial.println("MotorHiz :" + String(motorSpeed));
    } else if(ReceivedDataInt >= 105) {
      ReceivedDataInt = ReceivedDataInt - 105;
      int motorSpeed = (ReceivedDataInt * 10) + 50;
      if(motorSpeed > 254) motorSpeed = 254;
      motorhiz.setSpeed(motorSpeed);
      motorhiz.run(FORWARD);
      Serial.println("MotorHiz :" + String(motorSpeed));
    }
  } else // Données Y
  {
    Serial.println("DataY :" + ReceivedDataStr);
    if(ReceivedDataInt > 45 && ReceivedDataInt < 54) {
      Serial.println("RELEASE");
      motoryon.run(RELEASE);
    } else if(ReceivedDataInt >= 0 && ReceivedDataInt < 4) {
      Serial.println("RELEASE");
      motoryon.run(RELEASE);
    } else if(ReceivedDataInt >= 55) {
      ReceivedDataInt = ReceivedDataInt - 55;
      int motorSpeed = (ReceivedDataInt * 12) + 50;
      if(motorSpeed > 254) motorSpeed = 254;
      motoryon.setSpeed(motorSpeed);
      motoryon.run(BACKWARD);
      Serial.println("MotorHiz :" + String(motorSpeed));
    } else if(ReceivedDataInt >= 5) {
      ReceivedDataInt = ReceivedDataInt - 5;
      int motorSpeed = (ReceivedDataInt * 12) + 50;
      if(motorSpeed > 254) motorSpeed = 254;
      motoryon.setSpeed(motorSpeed);
      motoryon.run(FORWARD);
      Serial.println("MotorHiz :" + String(motorSpeed));
    }
  }
}

void I2CRequest() {
  // Wire.write(DataToBeSend,1);
}

Schéma de brochage I2C pour communication entre Arduino et Raspberry Pi. Pas besoin d'alimentation externe pour l'Arduino : il sera alimenté par la broche Vout du Raspberry Pi.

ÉTAPE 2 : Code Raspberry Pi (Serveur Web)

Le code requis pour le Raspberry Pi (fonctionnant comme serveur web) qui envoie les données à l'Arduino via I2K est disponible en fin de page (Section Code).

ÉTAPE 3 : Application Android Cordova Visual Studio

Nous développons une application Android Cordova avec Visual Studio qui envoie les données de l'accéléromètre au serveur web via requêtes AJAX.

Le code est disponible en fin de page (Section Code).

EN RÉSUMÉ

  1. L'application Android envoie les données du capteur (accéléromètre téléphone) au serveur web sur Raspberry Pi.
  2. Le serveur web envoie les données (reçues de l'accéléromètre) à l'Arduino via I2C.
  3. L'Arduino traite les données et commande les moteurs via le shield moteur.

Code

Wiri.h Communication I2C et Shield Moteur (Arduino)

Communication I2C entre Arduino et Raspberry Pi. Pour communication série entre deux appareils avec minimum entrées/sorties.

Contrôleur Android à Distance (C#)

Téléchargement uniquement - pas d'aperçu.

Serveur Web Windows IoT (C#)

Téléchargement uniquement - pas d'aperçu.

Pièces Personnalisées et Boîtiers

Schéma de brochage Arduino vers Raspberry Pi

Schémas

Pour plus de détails : https://www.hackster.io/AnuragVasanwala/home-automation-0dcefc

Processus de fabrication

  1. Contrôler une LED avec un capteur de mouvement PIR sur Raspberry Pi
  2. Construire un robot intelligent avec le Bridge Shield – Intégration Raspberry Pi & Arduino
  3. Construire un robot Raspberry Pi piloté par Bluetooth avec retour audio
  4. Construire un robot piloté par Internet avec streaming vidéo Arduino & Raspberry Pi
  5. Robot à commande gestuelle piloté par Raspberry Pi
  6. Construire un robot piloté Wi‑Fi avec Raspberry Pi & Smartphone Android
  7. Construire un robot Raspberry Pi piloté Wi-Fi avec Python – Guide pas à pas
  8. Robot de détection humaine basé sur Arduino Uno : Intégration capteurs étape par étape
  9. Construire un Spybot Arduino piloté par Bluetooth