Go Down

Topic: Blynk+stepper motor+HMC5883 error (Read 35 times) previous topic - next topic

myrador

Need help. I have a problems with controll of stepper motor with blynk. I use HMC5883 i2c and easy driver for control stepper. But i have trouble with 1 direction. I think the problems is in ''void loop''. Conflict in my code. No error but my motor won't work when i add HMC5883 for direction of my tv antenna. Please Help me.

-esp d1 mini+easydrivers+HMC5883+Blynk


#include <Stepper.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
 
Stepper myStepper(200, 16, 14);
#include <Wire.h>

char auth[] ="xxxx";   
char ssid[] = "xxx";
char pass[] = "xxx";
int xVal=512;

Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);

 
void setup()
{
 
  Blynk.begin(auth, ssid, pass);
   myStepper.setSpeed(2500);
 
if(!mag.begin())
  {
    /* There was a problem detecting the HMC5883 ... check your connections */
    Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");
    while(1);
  }
   
}

void loop()
{
  Blynk.run();
 
  //HMC5883
  sensors_event_t event;
  mag.getEvent(&event);   
 float heading = atan2(event.magnetic.y, event.magnetic.x);
 float declinationAngle = 0.23;
  heading += declinationAngle;
  // Correct for when signs are reversed.
  if(heading < 0)
   heading += 2*PI;
   // Check for wrap due to addition of declination.
  if(heading > 2*PI)
    heading -= 2*PI;   
  // Convert radians to degrees for readability.
  float headingDegrees = heading * 180/M_PI;
  Blynk.virtualWrite(4, headingDegrees);
  delay(100);*/


 //Stepper joystick
   if( (xVal < 500)  ){
      myStepper.step(1);
     delayMicroseconds(150);
     }else if( xVal > 550){
     myStepper.step(-1);
     delayMicroseconds(150);
       
  }
 }
 
 BLYNK_WRITE(V1)
{
  xVal = param[0].asInt();
  }

Go Up