Go Down

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


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);
    /* There was a problem detecting the HMC5883 ... check your connections */
    Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");

void loop()
  sensors_event_t 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);

 //Stepper joystick
   if( (xVal < 500)  ){
     }else if( xVal > 550){
  xVal = param[0].asInt();

Go Up