*I didn't understand the thing about posting code and using the carets or apostrophes so I'll post it like this
Hi
I am going for making a brushless motor spin by control from a micro joystick.
I wired it like this
https://drive.google.com/drive/folders/1KAzZPFLQr2zbFpn9zhCd2cAEPweDaRF5
I put this code onto a DigiSpark with an ATTINY85. It was originally for a plain ATTINY85 and then I changed the code a little for the DigiSpark.
// Program an ATTINY85 to set position of servo by position of potentiometer.
// Pot connected to pin A1, servo connected to pin D0
int val;
void setup()
{
pinMode(PB1, OUTPUT); //Defines D0 as output for servo
digitalWrite (PB1, LOW); // Sets servo output low
}
void loop()
{
val = analogRead(PB2); // Reads position of potentiometer
val = map(val, 0, 1023, 1000, 2000); //Scales the input range to pulse length values (uS)
digitalWrite (PB1, HIGH); // Generates a positive output pulse
delayMicroseconds (val);
digitalWrite (PB1, LOW);
delay (16); // Sets the frame rate
}
When I plugged in a battery the motor twitched and then it didn't do anything no matter what I did with the joystick.
Tell us more.
And about the ESC
Please remember to use code tags when posting code
I put a 4S lipo that was at storage charge of 15.2V into the plug that goes into the four in one ESC which is 50A.
Does the ESC need an arming sequence?
Thank you I will look into that
The code got changed to something from the TinySoftPWM library.
The micro joystick did nothing from zero to 75% of its movement, then at 75% throttle on the joystick, the light on the DigiSpark started to turn on, and the motor started to twitch. With the joystick at full, the LED was on and the motor stopped and started, stopped and started, mostly off, in short uncontrolled bursts. The one who gave me the code said "I believe the scaling of the 0-1024 from the analog read to the 0-256 of the PWM needs work."
I'm hoping to get the throttle working smoothly and correctly.
/* Cobbled together from the library example code for a test. It produces a good PWM waveform
* The library code is here: https://github.com/digistump/DigisparkArduinoIntegration/tree/master/libraries/DigisparkTinySoftPwm
*/
#include <TinySoftPwm.h>
int val;
void setup() {
pinMode(PB3, OUTPUT); // Defines PB3 as output
TinySoftPwm_begin(128, 0); /* 128 x TinySoftPwm_process() calls before overlap (Frequency tuning), 0 = PWM init for all declared pins */
}
void loop()
{
static uint32_t StartUs=micros();
static uint32_t StartMs=millis();
static uint8_t Pwm=0;
static int8_t Dir=1;
/***********************************************************/
/* Call TinySoftPwm_process() with a period of 60 us */
/* The PWM frequency = 128 x 60 # 7.7 ms -> F # 130Hz */
/* 128 is the first argument passed to TinySoftPwm_begin() */
/***********************************************************/
if((micros() - StartUs) >= 60)
{
/* We arrived here every 60 microseconds */
StartUs=micros();
TinySoftPwm_process(); /* This function shall be called periodically (like here, based on micros(), or in a timer ISR) */
}
/*************************************************************/
/* period of 10 ms */
/*************************************************************/
if((millis()-StartMs) >= 10)
{
StartMs=millis();
Pwm = analogRead(1); // Reads position of potentiometer from pin 2
Pwm = map(Pwm, 0, 1023, 0, 255);; // Scales the input range to PWM parameter
TinySoftPwm_analogWrite(PB3, Pwm); // Writes to output
TinySoftPwm_analogWrite(PB1, Pwm); // Writes to built in LED
}
}