Archiv der Kategorie: kickboard

K2 Kickboard ev mod – analog to pdm controller

After I avoided programming my own microcontroller to get the thing rolling in as little time as possible (sidetracking kills a lot of drive) – I finally decided it was time to take it on.

Actually the realisation that the cheap servo tester assumes the poti position when powering up as middle position convinced me that it was necessary to write my own speed controller – since I can’t (or at least not realiably/comfortably) use the braking functionality of the alien power sytem esc.

Also this way I can – or at least I can try to – write my own soft-start routine so people don’t fall off the back.

@phrewfuf encouraged me to program the arduino nano I tucked in a box some months back for when the time was right 😉
Since he didn’t send me the code I just set down myself today and took the first steps.

Also I had to wildlarize the freaking busted poti I pulled out of a part drawer. If you’re  not familiar with the term:

„widlarize“ (invented by Bob Widlar): You take the bad component to the anvil part of the vice and beat it with a hammer। It will make you feel so good, for no damaged parts will appear in your latest application।

It sucks so hard wasting time and money with  broken components that I consider not reusing old parts – or at least not the parts lying around shackspace 😉

Here is already another poti hooked up to an analogue pin linked to the pin the servo is connected to:

#include <Servo.h>

//onboard led
int ledPin = 13;

//servo pin
int escPin = 3;  // servo signal connected to digital pin 3
Servo escServo;

int potiPin = 7; // potentiometer wiper (middle terminal) connected to analog pin 3
int potiVal = 0;     // variable to store the value read from the poti

void setup()
{
  pinMode(ledPin, HIGH);
  escServo.attach(escPin);
  //initial Servo Position
  escServo.write(0);
}

void loop()
{

  potiVal = analogRead(potiPin);    // read the input pin
  potiVal = map (potiVal, 0, 1023, 0, 180); //convert input range to servo range
  escServo.write(potiVal);

}

Result:

Next up I need want to get interrupts working.