วันพฤหัสบดีที่ 30 สิงหาคม พ.ศ. 2561

(งาน18)https://www.hackster.io/JulienChateau/spideruino-5915e9


Spideruino

A Lego arachnid controlled by your smartphone.
IntermediateShowcase (no instructions)17,148
Spideruino


Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SparkFun Bluetooth Modem - BlueSMiRF Silver
SparkFun Bluetooth Modem - BlueSMiRF Silver
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
DC motor (generic)
×2
C.H.I.P. Approved 3.7 V LiPo Battery
C.H.I.P. Approved 3.7 V LiPo Battery
Really, a 4S lipo battery.
×4


Story



Schematics

ArduinoSchematic

Connect your Arduino to the Dual Bridge motor controller and to the bluetooth module.
Dc motor schematics warbodwjjf

How it walks

How to assemble the Lego bricks and gears in order to create that silly walk. Each motor drives 4 legs.
15875347 10155030129953804 5592007884128493841 o cci6kutoag

Inner gears.

The gear in the middle is the one driving the four other gears of the left side (same thing goes on the right side). to connect it to the motor, I had to cut a bit of the piece and glue it to the motor shaft. Then, you connect the legs to the gears, asynchronously (each on a gear hole) and tadam: silly walk.
Img 20170121 144513796 yzfru3nepb


Code

Nano Code

Arduino
Upload it to the Nano, it reads the Android orders incomming by bluetooth.
//ARDUINO Hiro NANO

//RXD to TXO (white)
//TXD to RXO (black)  BT adapter

// motor one
int enA = 11; //gris
int in1 = 10; // bleu
int in2 = 9; //vert
// motor two
int enB = 3; // violet
int in3 = 6; // jaune
int in4 = 5; // orange


char command;
String btdata;
int power;
int dir;
// Variables for the duration and the distance
long duration;
int distance;

void setup() {  
 
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(57600); 
  Serial.print("#ihihuuho");
  //MotorsForward();
}


void loop()
{  
  if (Serial.available() > 0)
  {
  }
  while (Serial.available() > 0)
  { command = (Serial.read());
    //Serial.println(" cmdd ");
    //Serial.println(command);

    
    //Serial.println("str: " + btdata);
    if (command == '?')
    {
      //Serial.println();
      //Serial.println("Command: " + btdata);

      delay(1);

     if (btdata.indexOf("forw") >= 0){
        MotorsForward(255);
        }
     if (btdata.indexOf("back") >= 0){
        MotorsBackward(255);
        }
      else{
        Serial.println("Command not recognized: " + btdata);
      }
      

      btdata = "";
      }
    else if (command == '/')
    {
      //Serial.println();
      //Serial.println("Direction: " + btdata);
      dir = btdata.toInt();
      btdata = "";
    }
    else if (command == '%')
    {
      //Serial.println();
      Serial.println("Power: " + btdata);
      power = btdata.toInt();
      btdata = "";
      if ( dir == 1 && power>0) {
        MotorsForward(power);
      }
      else if ( dir == 5 && power>0) {
        MotorsBackward(power);
      }
      else if ( dir == 7 && power>0) {
        MotorsSpinR(power);
      }
      else if ( dir == 3 && power>0) {
        MotorsSpinL(power);
      }
      else if ( dir == 8 && power>0) {
        MotorsFR(power);
      }
      else if ( dir == 2 && power>0) {
        MotorsFL(power);
      }
      else if ( dir == 4 && power>0) {
        MotorsBL(power);
      }
      else if ( dir == 6 && power>0) {
        MotorsBR(power);
      }
      else{
        MotorsStop();
      }
    }
    else{
      btdata = btdata + command;
    }

    
   }
   delay(500);
 }

void LedBlue()
{
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  //delay(1000);                       // wait for a second
}

void LedRed()
{
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level)
}


void MotorsBackward(int powa)
{
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  analogWrite(enA, powa);
  analogWrite(enB, powa);
  
}

void MotorsForward(int powa)
{
  // Serial.println("Forward!");

  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  analogWrite(enA, powa);
  analogWrite(enB, powa);
 
}

void MotorsSpinR(int powa)
{
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  analogWrite(enA, powa);
  analogWrite(enB, powa);
  
}
void MotorsSpinL(int powa)
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  analogWrite(enA, powa);
  analogWrite(enB, powa);
  
}
void MotorsFL(int powa)
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  analogWrite(enA, powa);  
}
void MotorsFR(int powa)
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  analogWrite(enB, powa);  
}
void MotorsBR(int powa)
{
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  analogWrite(enA, powa);  
}
void MotorsBL(int powa)
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  analogWrite(enB, powa);  
}

void MotorsStop()
{
  // now turn off motors
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น