SpitFire-666 / arduino

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

arduino stuff

General

  • May have to set a different processor option per board

image

  • Setting COM port to a faster speed increases upload speed

image

Power Saving

an Arduino Nano draws less power than the Arduino UNO, and the Pro-Mini draws less than the Nano.

Sketches

Onboard LED - blink

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Stepper motor

28BYJ-48 Unipolar Stepper with ULN2003 driver

  • Driver accepts 12V BUT 5V motor doesn't like it, so use 5V

image

https://dronebotworkshop.com/stepper-motors-with-arduino/

/*
  Stepper Motor Demonstration 1
  Stepper-Demo1.ino
  Demonstrates 28BYJ-48 Unipolar Stepper with ULN2003 Driver
  Uses Arduino Stepper Library

  DroneBot Workshop 2018
  https://dronebotworkshop.com
*/

//Include the Arduino Stepper Library
#include <Stepper.h>

// Define Constants

// Number of steps per internal motor revolution 
const float STEPS_PER_REV = 32; 

//  Amount of Gear Reduction
const float GEAR_RED = 64;

// Number of steps per geared output rotation
const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED;

// Define Variables

// Number of Steps Required
int StepsRequired;

// Create Instance of Stepper Class
// Specify Pins used for motor coils
// The pins used are 8,9,10,11 
// Connected to ULN2003 Motor Driver In1, In2, In3, In4 
// Pins entered in sequence 1-3-2-4 for proper step sequencing

Stepper steppermotor(STEPS_PER_REV, 8, 10, 9, 11);

void setup()
{
// Nothing  (Stepper Library sets pins as outputs)
pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  // Slow - 4-step CW sequence to observe lights on driver board
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(100);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
 delay(100);                       // wait for a second
 digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(100);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
 
  //steppermotor.setSpeed(1);    
  StepsRequired  =  4;
  //steppermotor.step(StepsRequired);
  //delay(2000);

   // Rotate CW 1/2 turn slowly

//  StepsRequired  =  STEPS_PER_OUT_REV / 2; 
//  steppermotor.setSpeed(100);   
//  steppermotor.step(StepsRequired);
//  delay(1000);


   // Rotate CW full turn medium speed

  StepsRequired  =  STEPS_PER_OUT_REV; 
  steppermotor.setSpeed(1000);   // 1000 may be max??
  steppermotor.step(StepsRequired);
  delay(1000);


  // Rotate CCW full turn quickly

  StepsRequired  =  - STEPS_PER_OUT_REV; // 2;   
  steppermotor.setSpeed(1000);  
  steppermotor.step(StepsRequired);
  delay(1000);

}

ESP8266

image

image

  • Set board type

image

LED Blink

  • Note, onboard LED is inverted - LOW turns it on!
  • Onboard LED is connected to GPIO2
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  #define LED_BUILTIN 2
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
}

Stepper motor

  • use AccelStepper.h for stepper motors

WIFI

#include "ESP8266WiFi.h"

char ssid[]           = "MyWifiNetwork SSID";
const char* password  = "MyP@ssword"; 

void setup() {
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected.");
}

void loop() {

}

About