addibble / HoverboardController

A sample Arduino sketch to drive one motor using the self balancing scooter motor controller - for 3.3V Arduino ONLY!
http://drewspewsmuse.blogspot.com/2016/06/how-i-hacked-self-balancing-scooter.html
35 stars 9 forks source link

Using with two motors? #1

Open grasmanek94 opened 5 years ago

grasmanek94 commented 5 years ago

Hey there, does anyone have some ideas to make the code work with two motors? I modified the code as such:

#include "SoftwareSerial9.h"

#define TX_L 11
#define RX_L 10
#define TX_R 6
#define RX_R 5

SoftwareSerial9 serial_left(RX_L,TX_L);
SoftwareSerial9 serial_right(RX_R,TX_R);

void setup() {
  serial_left.begin(26315);
  serial_right.begin(26315);
  Serial.begin(115200);
}

char c = ' ';
signed int sp_l=0;
signed int sp_r=0;
unsigned long time[2];

void loop() {
  Serial.println(c);
  if(c == ' ') {
    sp_l=0;
    sp_r=0;
  } else if(c == 'q') {
    sp_l -= 10;
  } else if(c == 'w') {
    sp_l += 10;
  } else if(c == '2') {
    sp_l += 100;
  }  else if(c == '1') {
    sp_l -= 100;
  } else if(c == 'o') {
    sp_r -= 10;
  } else if(c == 'p') {
    sp_r += 10;
  } else if(c == '0') {
    sp_r += 100;
  }  else if(c == '9') {
    sp_r -= 100;
  }
  Serial.print("speeds: ");
  Serial.print(sp_l);
  Serial.print(" / ");
  Serial.println(sp_r);
  do {
      time[0] = micros();

      serial_left.write9(256);
      serial_left.write9(sp_l & 0xFF);
      serial_left.write9((sp_l >> 8) & 0xFF);
      serial_left.write9(sp_l & 0xFF);
      serial_left.write9((sp_l >> 8) & 0xFF);
      serial_left.write9(85);

      serial_right.write9(256);
      serial_right.write9(sp_r & 0xFF);
      serial_right.write9((sp_r >> 8) & 0xFF);
      serial_right.write9(sp_r & 0xFF);
      serial_right.write9((sp_r >> 8) & 0xFF);
      serial_right.write9(85);

      time[1] = micros();
      delayMicroseconds(300 - (time[1] - time[0]));

  } while(!Serial.available());
  c=Serial.read();
}

But after a while both wheels start speeding up to max and become uncontrollable. Any ideas?

ziadchelala commented 4 years ago

Hello @grasmanek94, I am trying to complete this project and I am facing the same issue. Did you succeed solving it?

grasmanek94 commented 4 years ago

I resorted to buying a usb st-link v2 for stm8 and stm32 controllers and reprogrammed the board with the hoverboard hack firmware.

wayne281167 commented 4 years ago

the answer to the problem is to use 2 motherboards they are so cheap , one fir each motor

MattCurryCom commented 4 years ago

Trying to do this with an M5 stack, via serial. Any suggestions for the dual mode setup?