user20700377
Published © CC BY-SA

Viseesaw

Viseesaw uses the figure of a seesaw, to show metaphorically the inequality of two physical, conceptual or social realities.

BeginnerShowcase (no instructions)Over 1 day2,527
Viseesaw

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
Breadboard (generic)
Breadboard (generic)
×1
Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit - v2.3
×1
Adafruit Stepper motor - NEMA-17 size - 200 steps/rev, 12V 350mA
×1
Adafruit Stepper Motor Mount with Hardware - NEMA-17 Sized
×1
4 channel 2C Bi-directional Level Shifter
×1
Timing belt
×1
Aluminum GT2 Timing Pulley - 6mm Belt - 20 Tooth - 5mm Bore
×1

Story

Read more

Code

Viseesaw I

Arduino
/* This sketch has been programmed with the comabination of examples of 
 *  Adafruit assembled Motor Shield for Arduino v2 and Wifi Web Client
 *  31/3/2016
 */
/* 
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2 
---->	http://www.adafruit.com/products/1438
*/

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
int angle_web;
int angle;
int max_angle = 27;
float pulley_ratio = 0.5; // [shaft angle/motor_angle]   // (pulley 20 teeth (motor) - pullety 40 teeth (shaft)
int steps;
int motor_steps = 200;
float motor_ratio;   // [motor_angle/step] 
float total_ratio;   // [shaft_angle/step]
int angle_web_1;

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(motor_steps, 2);


/********************************************************************************
  Repeating Wifi Web Client

 This sketch connects to a a web server and makes a request
 using an Arduino Wifi shield.

 Circuit:
 * WiFi shield attached to pins SPI pins and pin 7

 created 23 April 2012
 modified 31 May 2012
 by Tom Igoe
 modified 13 Jan 2014
 by Federico Vanzati

 http://arduino.cc/en/Tutorial/WifiWebClientRepeating
 This code is in the public domain.
 */

#include <SPI.h>
#include <WiFi101.h>
 
char ssid[] = "";      //  your network SSID (name)
char pass[] = "";   // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)
/////
int status = WL_IDLE_STATUS;

// Initialize the Wifi client library
WiFiClient client;

// server address:
char server[] = "www.danielportoles.com";
//IPAddress server(64,131,82,241);

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 20L * 1000L; // delay between updates, in milliseconds
/********************************************************************************************************************** */

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  myMotor->setSpeed(6);  // 10 rpm   
  /* *************************************************************************************
   *  ***********************************************************************************
   */

   motor_ratio = 360 / (float) motor_steps;   // [motor_angle/step] 
   total_ratio = pulley_ratio * motor_ratio;    // [shaft_angle/step]

  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();

   
}

void loop() {
  
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  while (client.available()) {
    char c = client.read();
    if (c == 'L') {  // Start number
      c = client.read();
      angle_web_1 = c - '0';
      angle_web_1 = angle_web_1 * 10;
       c = client.read();
      int angle_web_2 = c - '0';
      angle_web = angle_web_1 + angle_web_2;
      if (angle_web > max_angle) { angle = max_angle;} else {angle = angle_web;}
      Serial.write("Angle read from website: ");
      Serial.print(angle_web);
      Serial.print("\t");
      Serial.write("Applied angle: ");
      Serial.print(angle);
      Serial.print("\n");
      steps = (int) ( angle/total_ratio );  // Convert number read in a webpage to number steps of stepmotor.
      Serial.write("Steps: ");
      Serial.println(steps);     
    }  
  }
    /* ************************************************************************************
   **************************************************************************************
  */
  delay (5000);
  Serial.println("Stepmotor Forward");
  myMotor->step(steps, FORWARD, MICROSTEP); //DOUBLE, INTERLEAVE, MICROSTEP
  delay (4000);
  Serial.println("Stepmotor Backward");
  myMotor->step(steps, BACKWARD, MICROSTEP); 
  delay (1000);
  //myMotor->release();

   /* ************************************************************************************
   **************************************************************************************
  */

  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
  }

  
}


// this method makes a HTTP connection to the server:
void httpRequest() {
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    //Serial.println("connecting...");
    // send the HTTP PUT request:
    client.println("GET /viseesaw/texto.php HTTP/1.1");
    client.println("Host: www.danielportoles.com");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made:
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}


  

Credits

user20700377

user20700377

1 project • 0 followers

Comments