Trying to get a bldc motor and stepper motor to work on an rc project

This page summarizes the projects mentioned and recommended in the original post on /r/arduino

InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • PPM-reader

    An interrupt based PPM signal reader for Arduino

  • #include //library for PPM receiver input https://github.com/dimag0g/PPM-reader #include //library for stepper motor https://github.com/waspinator/AccelStepper const int interruptPin = 23; //ppm pin const int channelAmount = 8; //amount of channels const int motorPwmPin = 12; //motor pwm pin const int motorDirPin = 13; //motor direction pin const int stepDirPin = 34; //stepper motor driver direction pin const int stepPin = 35; //stepper motor driver step pulse pin const int sleepPin = 32; //stepper motor driver sleep pin const int resetPin = 33; //stepper motor driver reset pin const int m2Pin = 25; //stepper motor driver microstep pin const int m1Pin = 26; //stepper motor driver microstep pin const int m0Pin = 27; //stepper motor driver microstep pin const int enablePin = 14; //stepper motor driver enable pin const int navPin = 21; //navigation lights const int strobePin = 19; //strobe light const int intLightsPin = 18; //interior lights const int hornPin = 5; //horn const int batteryPin = 39; //battery voltage (voltage divider, 4S input) const int motorPwmChannel = 0; //pwm channel for motor speed const int lightsPwmChannel = 1; //pwm channel for interior light const int hornPwmChannel = 2; //pwm channel for horn sound unsigned long timer = 0; //timer for reading input and setting outputs unsigned long hornTimer = 0; //timer for horn sounds int hornCheck = 0; //horn sound state (high freq / low freq / off) const int voltageMeasurements = 100; //number of voltage measurements int voltage[voltageMeasurements]; //measurement array int voltageCounter = 0; //array index long voltageTotal = 0L; //total sum of measurements float batteryVoltage = 0.0; unsigned long voltageTimer = 0; //timer for starting a new measurement AccelStepper stepper(1, stepPin, stepDirPin); //stepper motor object PPMReader ppm(interruptPin, channelAmount); //ppm object int PWM[channelAmount]; //ppm values array void setup() { pinMode(sleepPin, OUTPUT); //set sleep/reset/enable pins digitalWrite(sleepPin, HIGH); pinMode(resetPin, OUTPUT); digitalWrite(resetPin, HIGH); pinMode(enablePin, OUTPUT); digitalWrite(enablePin, LOW); pinMode(m0Pin, OUTPUT); //set 1/32 microstepping digitalWrite(m0Pin, HIGH); pinMode(m1Pin, OUTPUT); digitalWrite(m1Pin, HIGH); pinMode(m2Pin, OUTPUT); digitalWrite(m2Pin, HIGH); pinMode(navPin, OUTPUT); //set bjt output pins pinMode(strobePin, OUTPUT); pinMode(intLightsPin, OUTPUT); pinMode(hornPin, OUTPUT); stepper.setMaxSpeed(1500); //set stepper motor speed/acc/pos stepper.setAcceleration(1000); stepper.setCurrentPosition(0); ledcSetup(motorPwmChannel, 500, 8); //motor pwm setup ledcAttachPin(motorPwmPin, motorPwmChannel); ledcSetup(lightsPwmChannel, 500, 8); //headlights pwm setup ledcAttachPin(intLightsPin, lightsPwmChannel); ledcSetup(hornPwmChannel, 2500, 8); //horn pwm setup ledcAttachPin(hornPin, hornPwmChannel); Serial.begin(115200); //Arduino <-> PC baudrate } void loop() { stepper.run(); //run stepper motor if necessary if(millis() - timer >= 20){ //obtain new control values if available timer = millis(); for (byte channel = 1; channel <= channelAmount; ++channel) { //loop over channels PWM[channel-1] = ppm.latestValidChannelValue(channel, 0); //obtain channels } PWM[0] = map(PWM[0], 1080, 1920, -100, 100)*16; //map ppm value to stepper motor angle PWM[0] = constrain(PWM[0], -1600, 1600); //constrain stepper motor angle PWM[1] = map(PWM[1], 1080, 1920, -100, 100); //map gearbox to 8 bit value PWM[1] = constrain(PWM[1], -100, 100); //constrain gearbox value PWM[2] = map(PWM[2], 1080, 1920, 0, 255); //map motor speed to 8 bit value PWM[2] = constrain(PWM[2], 0, 255); //constrain motor speed value PWM[3] = map(PWM[2], 1080, 1920, -100, 100); //map horn value PWM[3] = constrain(PWM[2], -100, 100); //constrain horn value PWM[4] = map(PWM[4], 1080, 1920, 0, 255); //map potmeter values to 8 bit value for lights PWM[4] = constrain(PWM[4], 0, 100); //constrain values PWM[5] = map(PWM[5], 1080, 1920, 0, 100); //map potmeter values PWM[5] = constrain(PWM[5], 0, 100); //constrain switch value PWM[6] = map(PWM[6], 1080, 1920, 0, 100); //map potmeter values PWM[6] = constrain(PWM[6], 0, 100); //constrain values PWM[7] = map(PWM[7], 1080, 1920, 0, 10); //map gear switch to boolean value PWM[7] = constrain(PWM[7], 0, 1); //constrain values if(PWM[1] > 50) digitalWrite(motorDirPin, HIGH); //forwards state if(PWM[1] < -50) digitalWrite(motorDirPin, LOW); //backwards state ledcWrite(motorPwmChannel, PWM[2]); //generate motor pwm value stepper.moveTo(PWM[0]); //set new rudder angle if(PWM[4] > 5) ledcWrite(lightsPwmChannel, PWM[4]); //write value for interior lights else digitalWrite(intLightsPin, LOW); //turn off lights if(PWM[3] < -50){ //sound horn if activated if(hornCheck == 0){ //when off, set high freq ledcWriteTone(hornPwmChannel, 3000); //sound the horn at high freq hornTimer = millis(); //start counting hornCheck = 1; //set status to 1 (high freq) } if(hornCheck == 1 && (millis() - hornTimer) > 100){ //when high freq, set low freq after 100ms ledcWriteTone(hornPwmChannel, 2500); //sound the horn at low freq hornTimer = millis(); //reset timer hornCheck = 2; //set status to 2 (low freq) } if(hornCheck == 2 && (millis() - hornTimer) > 100){ //when low freq, set high freq after 100ms ledcWriteTone(hornPwmChannel, 3000); //sound the horn at high freq hornTimer = millis(); //reset timer hornCheck = 1; //set status to 1 (high freq) } } else{ ledcWrite(hornPwmChannel, 0); //stop horn sound hornCheck = 0; //set status to 0 (off) } } }

  • AccelStepper

    Fork of AccelStepper

  • #include //library for PPM receiver input https://github.com/dimag0g/PPM-reader #include //library for stepper motor https://github.com/waspinator/AccelStepper const int interruptPin = 23; //ppm pin const int channelAmount = 8; //amount of channels const int motorPwmPin = 12; //motor pwm pin const int motorDirPin = 13; //motor direction pin const int stepDirPin = 34; //stepper motor driver direction pin const int stepPin = 35; //stepper motor driver step pulse pin const int sleepPin = 32; //stepper motor driver sleep pin const int resetPin = 33; //stepper motor driver reset pin const int m2Pin = 25; //stepper motor driver microstep pin const int m1Pin = 26; //stepper motor driver microstep pin const int m0Pin = 27; //stepper motor driver microstep pin const int enablePin = 14; //stepper motor driver enable pin const int navPin = 21; //navigation lights const int strobePin = 19; //strobe light const int intLightsPin = 18; //interior lights const int hornPin = 5; //horn const int batteryPin = 39; //battery voltage (voltage divider, 4S input) const int motorPwmChannel = 0; //pwm channel for motor speed const int lightsPwmChannel = 1; //pwm channel for interior light const int hornPwmChannel = 2; //pwm channel for horn sound unsigned long timer = 0; //timer for reading input and setting outputs unsigned long hornTimer = 0; //timer for horn sounds int hornCheck = 0; //horn sound state (high freq / low freq / off) const int voltageMeasurements = 100; //number of voltage measurements int voltage[voltageMeasurements]; //measurement array int voltageCounter = 0; //array index long voltageTotal = 0L; //total sum of measurements float batteryVoltage = 0.0; unsigned long voltageTimer = 0; //timer for starting a new measurement AccelStepper stepper(1, stepPin, stepDirPin); //stepper motor object PPMReader ppm(interruptPin, channelAmount); //ppm object int PWM[channelAmount]; //ppm values array void setup() { pinMode(sleepPin, OUTPUT); //set sleep/reset/enable pins digitalWrite(sleepPin, HIGH); pinMode(resetPin, OUTPUT); digitalWrite(resetPin, HIGH); pinMode(enablePin, OUTPUT); digitalWrite(enablePin, LOW); pinMode(m0Pin, OUTPUT); //set 1/32 microstepping digitalWrite(m0Pin, HIGH); pinMode(m1Pin, OUTPUT); digitalWrite(m1Pin, HIGH); pinMode(m2Pin, OUTPUT); digitalWrite(m2Pin, HIGH); pinMode(navPin, OUTPUT); //set bjt output pins pinMode(strobePin, OUTPUT); pinMode(intLightsPin, OUTPUT); pinMode(hornPin, OUTPUT); stepper.setMaxSpeed(1500); //set stepper motor speed/acc/pos stepper.setAcceleration(1000); stepper.setCurrentPosition(0); ledcSetup(motorPwmChannel, 500, 8); //motor pwm setup ledcAttachPin(motorPwmPin, motorPwmChannel); ledcSetup(lightsPwmChannel, 500, 8); //headlights pwm setup ledcAttachPin(intLightsPin, lightsPwmChannel); ledcSetup(hornPwmChannel, 2500, 8); //horn pwm setup ledcAttachPin(hornPin, hornPwmChannel); Serial.begin(115200); //Arduino <-> PC baudrate } void loop() { stepper.run(); //run stepper motor if necessary if(millis() - timer >= 20){ //obtain new control values if available timer = millis(); for (byte channel = 1; channel <= channelAmount; ++channel) { //loop over channels PWM[channel-1] = ppm.latestValidChannelValue(channel, 0); //obtain channels } PWM[0] = map(PWM[0], 1080, 1920, -100, 100)*16; //map ppm value to stepper motor angle PWM[0] = constrain(PWM[0], -1600, 1600); //constrain stepper motor angle PWM[1] = map(PWM[1], 1080, 1920, -100, 100); //map gearbox to 8 bit value PWM[1] = constrain(PWM[1], -100, 100); //constrain gearbox value PWM[2] = map(PWM[2], 1080, 1920, 0, 255); //map motor speed to 8 bit value PWM[2] = constrain(PWM[2], 0, 255); //constrain motor speed value PWM[3] = map(PWM[2], 1080, 1920, -100, 100); //map horn value PWM[3] = constrain(PWM[2], -100, 100); //constrain horn value PWM[4] = map(PWM[4], 1080, 1920, 0, 255); //map potmeter values to 8 bit value for lights PWM[4] = constrain(PWM[4], 0, 100); //constrain values PWM[5] = map(PWM[5], 1080, 1920, 0, 100); //map potmeter values PWM[5] = constrain(PWM[5], 0, 100); //constrain switch value PWM[6] = map(PWM[6], 1080, 1920, 0, 100); //map potmeter values PWM[6] = constrain(PWM[6], 0, 100); //constrain values PWM[7] = map(PWM[7], 1080, 1920, 0, 10); //map gear switch to boolean value PWM[7] = constrain(PWM[7], 0, 1); //constrain values if(PWM[1] > 50) digitalWrite(motorDirPin, HIGH); //forwards state if(PWM[1] < -50) digitalWrite(motorDirPin, LOW); //backwards state ledcWrite(motorPwmChannel, PWM[2]); //generate motor pwm value stepper.moveTo(PWM[0]); //set new rudder angle if(PWM[4] > 5) ledcWrite(lightsPwmChannel, PWM[4]); //write value for interior lights else digitalWrite(intLightsPin, LOW); //turn off lights if(PWM[3] < -50){ //sound horn if activated if(hornCheck == 0){ //when off, set high freq ledcWriteTone(hornPwmChannel, 3000); //sound the horn at high freq hornTimer = millis(); //start counting hornCheck = 1; //set status to 1 (high freq) } if(hornCheck == 1 && (millis() - hornTimer) > 100){ //when high freq, set low freq after 100ms ledcWriteTone(hornPwmChannel, 2500); //sound the horn at low freq hornTimer = millis(); //reset timer hornCheck = 2; //set status to 2 (low freq) } if(hornCheck == 2 && (millis() - hornTimer) > 100){ //when low freq, set high freq after 100ms ledcWriteTone(hornPwmChannel, 3000); //sound the horn at high freq hornTimer = millis(); //reset timer hornCheck = 1; //set status to 1 (high freq) } } else{ ledcWrite(hornPwmChannel, 0); //stop horn sound hornCheck = 0; //set status to 0 (off) } } }

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • React Native: An introduction

    2 projects | dev.to | 15 May 2024
  • New exponent functions that make SiLU and SoftMax 2x faster, at full acc

    1 project | news.ycombinator.com | 15 May 2024
  • An Empirical Evaluation of Columnar Storage Formats [pdf]

    1 project | news.ycombinator.com | 15 May 2024
  • Nearly all Nintendo 64 games can now be recompiled into native PC ports

    8 projects | news.ycombinator.com | 15 May 2024
  • Introducing Ripple's Brazil Fund: Fostering XRP Ledger Innovation in Brazil

    1 project | dev.to | 15 May 2024