# Ovaltine's Segway Clone



## phaedrus (Aug 24, 2013)

Compiles fine here for an Uno with no mods required, although I've not installed it in any hardware. 

Cheers, P.


----------



## quikstep (Sep 23, 2013)

Hi Ovaltine!

I'm using Nano V3 and Sketch 1.0.5 of Linux.

My initial issue was:

Motors.ino:18:20: error: motors.h: No such file or directory
Motors.ino: In function ‘void initMotors()’:
Motors:136: error: ‘HZ_3906’ was not declared in this scope
Motors:137: error: ‘LEFT_PWM_PIN’ was not declared in this scope
Motors:138: error: ‘LEFT_DIR_PIN’ was not declared in this scope
Motors:139: error: ‘RIGHT_PWM_PIN’ was not declared in this scope
Motors:140: error: ‘RIGHT_DIR_PIN’ was not declared in this scope
Motors.ino: In function ‘void controlMotors(int, int)’:
Motors:150: error: ‘LEFT_DIR_PIN’ was not declared in this scope
Motors:154: error: ‘LEFT_DIR_PIN’ was not declared in this scope
Motors:156: error: ‘LEFT_PWM_PIN’ was not declared in this scope
Motors:161: error: ‘RIGHT_DIR_PIN’ was not declared in this scope
Motors:165: error: ‘RIGHT_DIR_PIN’ was not declared in this scope
Motors:167: error: ‘RIGHT_PWM_PIN’ was not declared in this scope

This is immediately rectified by changing Motors.ino
from #include "motors.h"
to #include "Motors.h"

Yes. Linux is such 

After that, the compilation was a breeze (for PWM_DIR_CONTROLLER).

I'm suspecting that you've some angle protection (ran out of time to check as I wanted to feedback to your good work ASAP). My serial printout (changed to 38400 baud) hung at:

X Accel Offset -1771Y Gyro Offset -190Y Gyro Min -23994Y Gyro Max 28699


But nice work there. My motors just came and I'm conceptualizing the ride soon.


----------



## Ovaltineo (Jul 18, 2013)

quikstep, I've now fixed the Linux bug. You need to get the latest code because I found out that pin 2 is not a PWM pin in the Uno/Nano.

The debug output is inside the clause which doesn't get called in an over-angle situation. You can move this or just change MIN_ANGLE and MAX_ANGLE.


----------



## Ovaltineo (Jul 18, 2013)

quikstep,

I just realized that it is not an over-angle situation. You have compiled and run in MODE_CALIBRATE, hence it will print all those samples, take the average, save to EEPROM, and halt. You now need comment out or delete #define MODE_CALIBRATE, compile and upload. This time, it will wait for you to level the board at +-2 degrees, then it  will start balancing on its own.


----------



## quikstep (Sep 23, 2013)

Hello Ovaltineo,

I can confirm that after commenting out MODE_CALIBERATE and changing some parameters for my situation ie. using MPU6050_X2_STEERING, PWM_DIR_CONTROLLER, Serial.begin(38400), MAX_ANGLE 30 and MIN_ANGLE -20, everything worked fine. This is at least working for Nano v3 + 2 MPU6050 only.

Thanks again for your help. Once I've hooked up everything, I'm confident I can also contribute to this forum.


----------



## phaedrus (Aug 24, 2013)

OT: I was mulling over things from the other thread and wonder if it's worth commenting on the MPU board orientation in your README file for your next revision?

Nice job getting all those scenarios coded BTW!

Cheers, P.


----------



## phaedrus (Aug 24, 2013)

quikstep said:


> Yes. Linux is such
> 
> ...
> 
> But nice work there. My motors just came and I'm conceptualizing the ride soon.


QS: Thank you for making that comment re Linux; although I've used it in many different situations over the past 15yrs or so it never occurred to me that there would be Linux support for the compiler - just goes to show I'm a bit slow, really it should have been obvious I suppose!

Also, it would be interesting to hear what motors you're using?

Cheers, P.


----------



## quikstep (Sep 23, 2013)

phaedrus said:


> QS: Thank you for making that comment re Linux; although I've used it in many different situations over the past 15yrs or so it never occurred to me that there would be Linux support for the compiler - just goes to show I'm a bit slow, really it should have been obvious I suppose!
> 
> Also, it would be interesting to hear what motors you're using?
> 
> Cheers, P.


Bought these motors from China http://mytaofocus.com/item.php?id=20159160122

RMB 345 for only 1 motor. Not recommended seller though. Been really having bad experience with this company. Had to harass my agent many times to get answers from the company.


----------



## phaedrus (Aug 24, 2013)

quikstep said:


> Bought these motors from China http://mytaofocus.com/item.php?id=20159160122
> 
> RMB 345 for only 1 motor. Not recommended seller though. Been really having bad experience with this company. Had to harass my agent many times to get answers from the company.


Shame about the seller, the motors look great! From the photographs in the advanced section it looks like they also do hub motors and/or complete balancing scooters. BLDC hub motors are something I'm keen to try at some stage.

Presently I'm using old mobility scooter motors which are relatively slow and with a right-angle gearbox it means there's a large motor casing that's got to stick out somewhere 

Anyway it'll be interesting to hear how your design works out 

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

*v2.3*

As P. has suggested, I have now included the sensor orientation in the README.

"Sensors must be aligned such that the X axis is level and pointing to the front of the vehicle."

I have now released v2.3. It fixes a bug in the sensor calibration (it didn't save all the calibration data, so steering might be bad). Everyone should re-calibrate using this version.

This version fixes a bug in the Roboclaw packet serial checksum which JRoque found.

I have also added support for the GY80 board which has an ADXL345 accelerometer and L3G4200D gyro.


----------



## Ovaltineo (Jul 18, 2013)

What I really want is to add some bling lights to the wheels! http://www.rcgroups.com/forums/showthread.php?t=465716  But the it won't work coz the wheels are turning too slowly .


----------



## phaedrus (Aug 24, 2013)

Now that's impressive!

I think the answer is simply to make the clone go faster . 

I've mentioned before that I'm interested in using BLDC motors; the ones I have in mind are from a washing machine (F&P smartdrive) which will do circa 1200rpm .

I'm sure that would that work with the LED's if you could stay on it 

Cheers, P.


----------



## JRoque (Mar 9, 2010)

Hi everyone.

OT, bringing the code discussion here since the build thread is getting long and winded. Keeping in mind that I don't know how the segway works in reality, here's a few questions:

- When the sensor is tilted past the given max angle, the motors seem to be commanded zero speed immediately. Would it be better to initiate a controlled slow-down while attempting to keep the vehicle balanced, if possible? Otherwise, speed demons like myself, pushing the handle forward for more speed and going past max angle, might suddenly get ejected forward when the motors grind to a stop.

- How does "calibration" work? I was expecting that, after running "cal" it would grab whatever position the sensor is in and call that "balanced". However, if I run the "cal" routine and then go in "run" mode without moving the sensor at all, the motors spin forward, presumably trying to reach balance.

- I've seen other clones bring out the P, I and D controls to external pots for tweaking. Is that really necessary or do you typically reach a good set of values quickly enough to not bother with the pots. Knowing me, if I bring those pots out, I'll be twisting them non-stop because "balancing nirvana could be one nudge away..." if you know what I mean.

So I haven't moved the electronics to the wheels yet but from what I've seen on the bench, this thing will work! Congrats again on the code.

JR


----------



## phaedrus (Aug 24, 2013)

JRoque said:


> Would it be better to initiate a controlled slow-down while attempting to keep the vehicle balanced, if possible?
> 
> - I've seen other clones bring out the P, I and D controls to external pots for tweaking. Is that really necessary or do you typically reach a good set of values quickly enough to not bother with the pots.



JR: Just as a comment on these two items - in some other balancing scooters there is a 'reserve' speed available to kick the rider back if they go too far. This is typically achieved by limiting max_motor to 60% - 70%, giving the possibility of 30% - 40% kick available to straighten you up (so to speak 

There are other designs that do the slow down thing you speak of, typically taking 1-2 secs to do so. 

In the former case, given the nature of some of the motors we're using it could possibly make the scooter very pedestrian under normal circumstances (I'd get something like 4km/h!) so I guess it's a bit of a trade-off, and so the slow-down system might be better, if your over-balance is correctable by that stage . I'm sure OT will comment on what he's done - possibly from empirical knowledge 

In the other query you have, FYI I've tried OT's code on my unit and it operated fairly well with the default levels he has set in his code. I too have seen other designs with the adjustments available externally, but there are plenty more without it. 

Personally I suspect the later gyro/accelerometer pairs are somewhat better than the earlier units and may well require less messing around. 

I'm doing a little more on my machine presently and will comment further on those values if/when I find a need to adjust them.

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

JR, I chose to do a full stop because, in my experience, the Segway runs into my calves if I fall forward (I live in a steep hill). Maybe sounding the buzzer before reaching Max angle is a good compromise.

There is another bug in the calibration routine which I will fix in the next release.

If you look at getP getI and getD, you will see that I babe commented out code there to read the values from pots. I used them initially and locked them in the code when I was happy. Since your drivetrain is different, I expect you'll be playing with these values a fair bit so the pots will be worth it.


----------



## Ovaltineo (Jul 18, 2013)

*v2.4*

I have fixed a gyro calibration bug. Please download v2.4. Select #defines in SegwayClone.h to match your hardware and re-calibrate.


----------



## Ovaltineo (Jul 18, 2013)

*v2.5*

Yes, you guessed it -- another calibration bug fixed in v2.5. This time, it is when reading data from EEPROM. I think this is the last of the calibration bugs . The good news is that if you already calibrated with v2.4, you don't need to re-calibrate coz the calibration data in EEPROM is valid.


----------



## quikstep (Sep 23, 2013)

*Re: v2.3*



Ovaltineo said:


> As P. has suggested, I have now included the sensor orientation in the README.
> 
> "Sensors must be aligned such that the X axis is level and pointing to the front of the vehicle."
> 
> ...


Had a rotten weekend where my car was hit and got summoned the next day 

For "Sensors must be aligned such that the X axis is level and pointing to the front of the vehicle.", is this the case for both breakout boards if I used 2 of them? Thanks.


----------



## Ovaltineo (Jul 18, 2013)

Yes, it applies for both single and dual boards. I actually have the steering sensor with the X axis pointing down on my clone, but I had to add a different code for that.

I have been testing single and dual sensors recently. With the current code, the dual sensor is better coz steering and board tilting do not affect each other. With a single sensor, the board dips when I'm turning coz the zero level of the tilt (pitch) is affected. I am going to test a more complicated algorithm that hopefully will address this.


----------



## Ovaltineo (Jul 18, 2013)

I tried the more complicated maths for computing tilt angles using the formulas in Tilt Sensing Using Linear Accelerometers and still couldn't get rid of the dipping of the board when turning while using one sensor. Now I realize that this is caused by not mounting the sensor at the exact intersection of the wheel axis and steering shaft axis. With the layout of my board, I can't do this so I mounted it on the steering shaft close to the front of the board.

The lesson learned is that you should use two sensors if you cannot mount a sensor in the ideal position. Or use one sensor for the board, and a potentiometer for the steering. At less than $4 each, I'd go for two MPU6050. 

With two sensors, you can also add terrain banking compensation (subtract board Y tilt from steering angle) though from my testing this doesn't work too well - it can get jittery. A complementary filter on the Y axis might fix this but I didn't try it.


----------



## JRoque (Mar 9, 2010)

Hi.

OT, can you recommend where in the code to add hysteresis? I'm particularly interested in this when the scooter is leveled (per calibration?). 

The issue I see (on the bench, mind you) is that the PID loop is accumulating the tiniest of errors that get progressively worse over time while the motors try to correct an angle that has not actually changed. 

Below is the (shortened) debug output showing what I mean. The gyro is fixed in a vise on my bench with no chance of moving. Notice how the motors speed up to compensate for, what I think it is, PID loop error correction.

Would some angle hysteresis before starting the motors fwd or rev help?


```
TEER ANGLE: -0.04 MOTOR: -170.71 LEFT: -170 RIGHT: -170
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
 ACCEL: -0.26 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: -0.02 MOTOR: 0.00 LEFT: 0 RIGHT: 0
 ACCEL: -0.24 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.01 MOTOR: -0.07 LEFT: 0 RIGHT: 0
 ACCEL: 0.11 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: -0.05 MOTOR: -0.15 LEFT: 0 RIGHT: 0
 ACCEL: 0.14 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.03 MOTOR: -0.25 LEFT: 0 RIGHT: 0
...
  ACCEL: 0.02 GYRO: 0.00 BOARD ANGLE: -0.06 STEER ANGLE: -0.04 MOTOR: -23.36 LEFT: -23 RIGHT: -23
 ACCEL: -0.24 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.08 MOTOR: -23.67 LEFT: -23 RIGHT: -23
 ACCEL: 0.32 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.07 MOTOR: -23.93 LEFT: -23 RIGHT: -24
 ACCEL: -0.06 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.03 MOTOR: -24.20 LEFT: -24 RIGHT: -24
 ACCEL: -0.26 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.08 MOTOR: -24.49 LEFT: -24 RIGHT: -24
 ACCEL: 0.30 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.11 MOTOR: -24.79 LEFT: -24 RIGHT: -25
 ACCEL: -0.14 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: -0.08 MOTOR: -25.02 LEFT: -24 RIGHT: -25
 ACCEL: -0.09 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.05 MOTOR: -25.22 LEFT: -25 RIGHT: -25
 ACCEL: -0.35 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.03 MOTOR: -25.45 LEFT: -25 RIGHT: -25
 ACCEL: 0.02 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.06 
...
 ACCEL: -0.27 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.04 MOTOR: -34.60 LEFT: -34 RIGHT: -34
 ACCEL: 0.19 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.06 MOTOR: -34.87 LEFT: -34 RIGHT: -35
 ACCEL: -0.38 GYRO: 0.00 BOARD ANGLE: -0.06 STEER ANGLE: -0.08 MOTOR: -35.19 LEFT: -34 RIGHT: -35
 ACCEL: 0.25 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.08 MOTOR: -35.51 LEFT: -35 RIGHT: -35
 ACCEL: -0.17 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: -0.09 MOTOR: -35.74 LEFT: -35 RIGHT: -36
 ACCEL: 0.02 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: -0.06 MOTOR: -35.90 LEFT: -35 RIGHT: -36
 ACCEL: 0.14 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.04 MOTOR: -36.04 LEFT: -35 RIGHT: -36
 ACCEL: 0.22 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.01 MOTOR: -36.11 LEFT: -36 RIGHT: -36
 ACCEL: -0.47 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: -0.01 MOTOR: -36.16 LEFT: -36 RIGHT: -36
 ACCEL: 0.15 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: -0.03 MOTOR: -36.28 LEFT: -36 RIGHT: -36
 ACCEL: 0.26 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.04 MOTOR: -36.44 LEFT: -36 RIGHT: -36
 ACCEL: -0.30 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: -0.11 MOTOR: -36.41 LEFT: -36 RIGHT: -36
 ACCEL: 0.21 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: -0.09 MOTOR: -36.40 LEFT: -36 RIGHT: -36
 ACCEL: 0.32 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: -0.07 MOTOR: -36.39 LEFT: -36 RIGHT: -36
 ACCEL: -0.13 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: -0.08 MOTOR: -36.36 LEFT: -36 RIGHT: -36
 ACCEL: 0.07 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: -0.04 MOTOR: -36.39 LEFT: -36 RIGHT: -36
 ACCEL: 0.23 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: -0.02 MOTOR: -36.42 LEFT: -36 RIGHT: -36
 ACCEL: -0.17 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: -0.06 MOTOR: -36.42 LEFT: -36 RIGHT: -36
 ACCEL: -0.13 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: -0.01 MOTOR: -36.38 LEFT: -36 RIGHT: -36
 ACCEL: -0.33 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.07 MOTOR: -36.47 LEFT: -36 RIGHT: -36
 ACCEL: -0.30 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.07 MOTOR: -36.65 LEFT: -36 RIGHT: -36
 ACCEL: -0.17 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: 0.00 MOTOR: -36.92 LEFT: -36 RIGHT: -36
 ...
 ACCEL: -0.03 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.02 MOTOR: -46.05 LEFT: -45 RIGHT: -46
 ACCEL: -0.20 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.02 MOTOR: -46.28 LEFT: -46 RIGHT: -46
 ACCEL: -0.27 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.04 MOTOR: -46.54 LEFT: -46 RIGHT: -46
 ACCEL: -0.63 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.06 MOTOR: -46.80 LEFT: -46 RIGHT: -46
 ACCEL: 0.01 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: -0.04 MOTOR: -47.02 LEFT: -46 RIGHT: -47
 ACCEL: -0.16 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: -0.06 MOTOR: -47.11 LEFT: -46 RIGHT: -47
 ACCEL: -0.26 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.06 MOTOR: -47.20 LEFT: -46 RIGHT: -47
 ACCEL: 0.14 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.07 MOTOR: -47.33 LEFT: -47 RIGHT: -47
 ACCEL: 0.01 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: -0.07 MOTOR: -47.38 LEFT: -47 RIGHT: -47
 ACCEL: -0.07 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: -0.06 MOTOR: -47.25 LEFT: -47 RIGHT: -47
 ACCEL: -0.06 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: -0.02 MOTOR: -47.27 LEFT: -47 RIGHT: -47
 ACCEL: -0.06 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: -0.01 MOTOR: -47.19 LEFT: -47 RIGHT: -47
 ACCEL: -0.41 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: -0.05 MOTOR: -47.16 LEFT: -46 RIGHT: -47
 ACCEL: -0.07 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.04 MOTOR: -47.22 LEFT: -47 RIGHT: -47
 ACCEL: 0.11 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.03 MOTOR: -47.36 LEFT: -47 RIGHT: -47
 ACCEL: -0.21 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.04 MOTOR: -47.47 LEFT: -47 RIGHT: -47
 ACCEL: 0.01 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: -0.04 MOTOR: -47.67 LEFT: -47 RIGHT: -47
 ACCEL: 0.02 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: -0.05 MOTOR: -47.85 LEFT: -47 RIGHT: -48
 ACCEL: -0.14 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.04 MOTOR: -48.06 LEFT: -47 RIGHT: -48
 ACCEL: 0.37 GYRO: 0.00 BOARD ANGLE: -0.06 STEER ANGLE: -0.08 MOTOR: -48.41 LEFT: -48 RIGHT: -48
 ACCEL: -0.13 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.09 MOTOR: -48.77 LEFT: -48 RIGHT: -49
 ACCEL: -0.23 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: -0.04 MOTOR: -49.02 LEFT: -48 RIGHT: -49
 ACCEL: 0.11 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.02 MOTOR: -49.23 LEFT: -49 RIGHT: -49
 ACCEL: 0.07 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: -0.04 MOTOR: -49.42 LEFT: -49 RIGHT: -49
 ACCEL: -0.38 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.05 MOTOR: -49.63 LEFT: -49 RIGHT: -49
 ACCEL: -0.16 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: -0.05 MOTOR: -49.88 LEFT: -49 RIGHT: -50
 ACCEL: -0.23 GYRO: 0.00 BOARD ANGLE: -0.06 STEER ANGLE: -0.03 MOTOR: -50.18 LEFT: -50 RIGHT: -50
 ACCEL: -0.38 GYRO: 0.00 BOARD ANGLE: -0.07 STEER ANGLE: -0.05 MOTOR: -50.59 LEFT: -50 RIGHT: -50
 ACCEL: -0.48 GYRO: 0.00 BOARD ANGLE: -0.07 STEER ANGLE: -0.01 MOTOR: -51.05 LEFT: -51 RIGHT: -51
 ACCEL: 0.09 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: -0.07 MOTOR: -51.44 LEFT: -51 RIGHT: -51
 ACCEL: -0.21 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.05 MOTOR: -51.65 LEFT: -51 RIGHT: -51
 ACCEL: -0.20 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: -0.00 MOTOR: -51.71 LEFT: -51 RIGHT: -51
 ACCEL: 0.09 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: -0.06 MOTOR: -51.71 LEFT: -51 RIGHT: -51
 ACCEL: 0.08 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: -0.06 MOTOR: -51.69 LEFT: -51 RIGHT: -51
```
JR


----------



## Ovaltineo (Jul 18, 2013)

JR, it is normal. The algorithm is designed to correct the smallest imbalance so there is no slack. There is hysteresis on the gyro (min and max during calibration), hence it is zero. But adding hysteresis on the accelerometer is not recommended by manufacturers. The accelerometer is detecting a slight incline (or just noise), and because there is no correction, the PID accumulates the motor value quickly over time. With motors and wheels on the ground, you won't see this behaviour.


----------



## phaedrus (Aug 24, 2013)

Ovaltineo said:


> The lesson learned is that you should use two sensors if you cannot mount a sensor in the ideal position. Or use one sensor for the board, and a potentiometer for the steering. At less than $4 each, I'd go for two MPU6050.


Interesting work OT.

Just to add to the body of information I've been using a hall-effect device for the steering input. Although the cost difference at this level is really immaterial (IMO) they are around $1ea, discounting the magnet. In my case the marginal cost was nearer to $0 since the mobility scooter I used for the motors already had a hall-effect device, and magnets, that were used for the speed control.

That said I am very attracted to the idea of using another MPU6050 for the steering. I'd not seen this anywhere else so it was a new and original concept to me, and very elegant IMO.

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

Thanks P! Only a couple of years ago, a single axis accelerometer would have cost a small fortune so it was unthinkable to use it for steering. I guess I came up with the idea because they are now so cheap, and for me, it was easier to install and more reliable than a pot.

I am now testing an Andriod app to control the Segway clone using bluetooth. It is a simple change on the Arduino app, but very complicated on the Android app. Early days yet, but stay tuned.


----------



## mizlplix (May 1, 2011)

I finally got both the new gyros in the mail...

I now have everything to proceed.

It is at this point that I need some assistance.

I have everything mounted to the small robot board. The claw is powered through a simple toggle switch. I have it in mode 7, packet serial.

The duino is powered from the same pack only through a regulator to limit it to 12vdc. 

I have one gyro mounted upright and the screw hole edge is forward. It looks to be correct.

The gyro is powered from the 3.3vdc pin on the duino, and ground to ground pin.

At this point all three boards power up and the three power LEDs each will light.

I know I need to use S1and S2 on the claw.

I know I must use the SDA and the SCL on the gyro.

Do I use the INT too?

Where on the duino do I hook them? 

My Ruggeduino is like an Uno SMD in construction.

Thx, miz


----------



## Ovaltineo (Jul 18, 2013)

Miz,

I'm assuming you bought the GY521 board (see image). I found the following from this thread http://forum.arduino.cc/index.php?topic=121825.0. 

Arduino +5V to VCC
Arduino GND to GND
Arduino analog input pin A4 to SDA
Arduino analog input pin A5 to SCL

But it is WRONG! The +5V connection to VCC is ok because the GY521 has a built in voltage regulator. However, you must add a resistor voltage divider on pins A4 and A5 to convert the Arduino logic level from 5V to 3.3.V. This means you connect a 15K resistor from A4 to ground and a 10K resistor from SDA to A4. Likewise, you connect a 15K resistor from A5 to ground and a 10K resistor from SCL to A5. 

You don't need to connect the other pins.

CORRECTION - The resistor voltage divider is not required. Just connect A4 to SDA and SCL to A5. This works even though the datasheet says max voltage for SDA and SCL is VDD + 0.5V.


----------



## phaedrus (Aug 24, 2013)

Interesting, I have my Uno & GY521 connected directly together w/out the resistive divider, note I was using the 3.3v output of the Uno to supply the GY board.

I do have the int connected but that's because I was using a different library that needed it.

FYI it worked fine with OT's code as is; I do also see some other comments suggesting the need for pull-up resistors on certain boards so I guess YMMV.

Anyway It will be good to hear how it goes Miz!

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

P. is right, I just got home and checked my circuit - I didn't use resistors either . Looks like I also ignored the datasheet when I put it together 11 months ago. It's still working so it must be ok.

I will edit my original post in case someone wastes their time with the resistors.


----------



## mizlplix (May 1, 2011)

" Just connect A4 to SDA and SCL to A5. "

OK, I just printed out the README and will do some work on it today. I will keep you posted!

Thanks,, Miz


----------



## mizlplix (May 1, 2011)

OK, everything is plugged in and correctly, I believe.

SCL to A5
SCD to A4

S1 to D6
S2 to D5

There is a dedicated ground wire that ties the gyro/Duino and Claw together. 

When I turn it on, the both motors run forward.

If I reset the Duino, the motors run in reverse momentarily while booting then resume in the forwards direction.

Everything seems OK.

I assume I need to calibrate the gyro at this point?

Miz


----------



## battagae (Aug 13, 2013)

When I open the SegwayClone file it contains multiple .ino files. I now have my Funduino board and am wondering if I'm somehow supposed to compile all the .ino files at once to the board or if there's a specific order in getting them onto the board. Basically how do I get the code onto the board I'm new at this?


----------



## JRoque (Mar 9, 2010)

mizlplix said:


> I assume I need to calibrate the gyro at this point? Miz


Yes I think that's the next step. OT sets the files to run calibration by default so load it and run it. After a few seconds, recompile in run mode (ie: //#define MODE_CALIBRATE) and send it to the Arduino again.



battagae said:


> Basically how do I get the code onto the board I'm new at this?


Hi and welcome to the forum. Assuming you're familiar with how Arduino works (I'm not ), load this file: SegwayClone.ino into the Arduino UI and that will load all other linked files in the project. Look for the README file that comes with the package for further instructions. Ask your questions here where Ovaltine or another member can give you a hand.

JR


----------



## Ovaltineo (Jul 18, 2013)

mizlplix said:


> When I turn it on, the both motors run forward.
> 
> If I reset the Duino, the motors run in reverse momentarily while booting then resume in the forwards direction.
> 
> ...


Miz, something is wrong with your setup. Assuming you haven't removed the #define MODE_CALIBRATE in SegwayClone.h, then it should already be in calibrate mode and the motors shouldn't be running at all. JR should be able to confirm this. Did you setup your Roboclaw in packet serial mode?


----------



## phaedrus (Aug 24, 2013)

battagae said:


> When I open the SegwayClone file it contains multiple .ino files. I now have my Funduino board and am wondering if I'm somehow supposed to compile all the .ino files at once to the board or if there's a specific order in getting them onto the board. Basically how do I get the code onto the board I'm new at this?


Just to extend JR's advice a little, and assuming you're using M$ and have installed the Arduino IDE, it's probably best if you put all of OT's files into one directory called 'segwayclone' under your 'Arduino' directory (normally in 'My Documents'). 

From there, using Windows Explorer, you should be able to simply click on 'segwayclone.ino' and it will bring up the Arduino IDE with the other required files auto-loaded in tabs across the interface.

At this stage, assuming you have your Arduino board plugged into the computer and the Arduino compiler is set to talk to the correct virtual com-port your Arduino is connected to you can just click on the 'tick' icon on the IDE and it should compile the code and upload it to the Arduino. Let us know if this runs ok, or if you have any problems.

Once you've got this established, using OT's code you'll need to calibrate the IMU board(s) level and set some parameters for the controller you're using etc before going much further...

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

*Android App*

I made some progress on my SegwayClone app for Android. I managed to remote control the Segway clone using the Android - in a limited way - because the laws of physics are against me . It only works on a flat surface and forward/backward response is not quick. The reason is that without a rider, the machine has a low center of gravity and the weight is distributed close to the wheel axis. This means that the torque needed to twist the board is almost the same as the torque needed to move the wheels. This means that if I add a positive offset to the motor output, the board will simply twist in the opposite direction to compensate - result = no movement. The only way I can make it move in the forward or backward direction is by changing the board angle until the weight of the handle overcomes the static balancing torque. This works on a flat surface. Unfortunately for me, the entire handle is made of aluminum and is very light. So, on a slight incline, the weight of the handle is not enough to make it move.

So, a SegwayClone remote control app is not that great. The good news is that the app can receive telemetry data from the machine. I'm already displaying battery voltage. I'm planning to add board angle, steering angle, motor output, and motor controller temperature. Adjusting the PID values real-time is also possible.

Anyone interested in this app should get a serial bluetooth slave device. Here's one for under $7 http://www.ebay.com/itm/Wireless-Se...178?pt=LH_DefaultDomain_0&hash=item2ec80c03a2

It's a 2 week wait so maybe just in time for me to complete the code.


----------



## Ovaltineo (Jul 18, 2013)

*v2.6*

I just released v2.6 to fix inverted steering angle that JR found. I also used new PID and STEER_MULTIPLIER values when using Roboclaw - copied from JR's values.


----------



## mizlplix (May 1, 2011)

OK, 

I am in mode 7- 3840 baud (code 4)

I uploaded 2.6

(The motors do not run, which is good)

I am using an UNO-Roboclaw-MPU6050 on tilt

Where does the steering gyro (another MPU6050) hook in. (I understand power and ground) 

SDA & SCL to what Duino pins?

Miz

PS: Android notebooks are $95.00 now and would be really cool to be able to carry one around when doing the final tilt/balancing refinements.
I actually have one and I can not find an Android version of the Arduino client. Just a couple of lame "helper" arduino apps that assist in coding
But do not allow sketches to load/download.


----------



## phaedrus (Aug 24, 2013)

*Re: Android App*



Ovaltineo said:


> I made some progress on my SegwayClone app for Android. I managed to remote control the Segway clone using the Android - in a limited way - because the laws of physics are against me


Well done with that - I did wonder how it work empirically (I'd put some thought into it myself and couldn't quite decide what would happen!). 

There are some examples of small balancing robots around that are externally controlled but when you look at their construction it's clear they've quite a lot of mass at the top of their chassis - given your findings I guess that explains why they appear to work as well as they do.

Did you try hanging a bag of sand or something off your handlebars? That might be interesting. Actually, in the interests of being completely silly, one could arrange a water based shift ballast system I suppose....

The bluetooth devices are very useful for this sort of project, I have one here too - certainly useful not to be quite so tethered to a moving machine! 

Anyway I'm off to weigh my chassis & let JR know, just for interest.

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

Miz,

The second MPU6050 hook up the same way as the first one - ie SDA and SCL goes to the same pins. The only difference is that you have to connect AD0 on the steering sensor to +5. This will change the address of the sensor.

After hooking this up and levelling, plug in the USB serial and bring up the serial monitor. Reboot the Arduino. This will calibrate both sensors - takes about a minute or two. The serial output will display some numbers and stop. If you have a buzzer plugged in, it will beep once before calibration and beep continuously after calibration.

With the USB serial still plugged in, edit SegwayClone.h Change #define MODE_CALIBRATE to //#define MODE_CALIBRATE. Upload the code to the Arduino.

After uploading, bring up the serial monitor. Reboot the Arduino. Look at the serial output. The board angle and steering angle should be close to zero. The motors will start moving. Move the board back and forth. The accel, gyro, and board angle should go from negative to positive accordingly. The motors should be moving back and forth too. VERY IMPORTANT - the motors should be moving forwards if the board is tilted forwards. If one or both are going in reverse, you must swap that motor's connections to the motor controller. Move the steering, it should change from negative to positive too. You should see a difference in the left and right motor output while doing this.

If everything turns out as expected, you are ready to put the machine on the ground. It should balance on its own and move slowly forward and backward. 

If everything is okay, then put the machine back on the bench. Edit Motors.h. Change from this
//	#define MOTOR_MAX 1500
#define MOTOR_MAX 180

to this
#define MOTOR_MAX 1500
//	#define MOTOR_MAX 180

Upload the code to the Arduino and repeat the bench test. The motors should be spinning faster now. If everything is okay, then put it on the ground and test. You will most probably need to change the KP and KD values in SegwayClone.h.

Good luck!


----------



## Ovaltineo (Jul 18, 2013)

*Re: Android App*



phaedrus said:


> Well done with that - I did wonder how it work empirically (I'd put some thought into it myself and couldn't quite decide what would happen!).
> 
> There are some examples of small balancing robots around that are externally controlled but when you look at their construction it's clear they've quite a lot of mass at the top of their chassis - given your findings I guess that explains why they appear to work as well as they do.
> 
> ...


I did hang my heavy cordless drill box on the handle. It certainly gave it more oomph, but with my light steering springs unable to hold it up, this was not a long term option. Also, I had to recalibrate because the balance point was different. I think it was an interesting exercise but not really practical. It might be useful though if I use a rigid tow bar to tow my cordless mower and the do the mowing by remote control !


----------



## battagae (Aug 13, 2013)

I'm currently trying to draw up a wiring schematic to have something on paper showing the connections between pins. I'm using 2xMPU6050, 2xBTS7960, and a Arduino Mega 2560 clone. So far I have VCC - VCC, GND - GND, SCL - A5, SDA - A4 for one of the MPU6050's. Can anyone help in specifying which pin connects where? I also don't have any of the wires needed to make these connections. Can somebody tell me what I should be using and where to find it? I know I'm not far along but your help has been awesome. I did manage to get the program uploaded no problem the IDE thought I was uploading onto an UNO after I corrected that it worked flawlessly.


----------



## phaedrus (Aug 24, 2013)

battagae said:


> I'm currently trying to draw up a wiring schematic to have something on paper showing the connections between pins. I'm using 2xMPU6050, 2xBTS7960, and a Arduino Mega 2560 clone. So far I have VCC - VCC, GND - GND, SCL - A5, SDA - A4 for one of the MPU6050's. Can anyone help in specifying which pin connects where? I also don't have any of the wires needed to make these connections. Can somebody tell me what I should be using and where to find it?


BG: It sounds like you have the MPU6050 and Mega connected together - or not?

If so, then you can start to see some action:

If you use the serial monitor of the Arduino IDE you should be able to see that when you tilt the MPU board various values will change (that would ordinarily contribute to keeping the machine upright). 

At this stage the next thing to connect up would be the PWM output from the mega to the motor controller. You still don't need the machine itself if you've not built that yet - I just used an old motor from a VCR connected to the motor controller output in order to see if it worked (I have been experimenting with my own code, and OT's and found this was a good methodology).

I'm just on my way out so don't have the time presently to say much more but if needed I could draw a block diagram and photograph it if you think that might help? 

Also, if you haven't got any connecting wires then you'll need to get some via ebay or you can just solder them directly to the boards.

Sorry if this is a bit cryptic but I've got to run and sort the kids out.

Cheers, P.


----------



## battagae (Aug 13, 2013)

One of my questions is more along the lines of what Miz was asking earlier. What would the specific pin to pin connections be from gyro 1 to mega, from gyro 2 to mega, and the same with my 2 BTS7960. For the connectors after looking at my components I assume I'll be using all male to female connections?


----------



## JRoque (Mar 9, 2010)

Hey there Battagae,

I believe these questions have been answered on the build thread and on the README file that comes with the project package.

It helps me figure out which pin is what in an Arduino board by having a schematic handy. I use the Ruggeduino board.

In essence, you need to connect both gyro boards to the I2C bus (SCL/SDA). To differentiate them, each gyro needs its own I2C address. You set that by either grounding or connecting 5V to the AD0 pin on the gyro boards. Grounded (low) is one address, 5V (high) is another address. High is already set by default, I believe. OT's code handles this and the README file says the tilting gyro is set low and the steering gyro is left set high.

The README file also specifies which pins to connect for PWM controlling, if that's what you plan to use. Hope this helps.

JR


----------



## Ovaltineo (Jul 18, 2013)

I have uploaded the schematic for the Mega + 2 X BTN7960 + 2 X MPU6050 in the first post. I actually downloaded and learned how to use TinyCAD this morning - already built two symbols and created the schematic. Finished it on the train before I arrived to work at 9:15am .


----------



## battagae (Aug 13, 2013)

Thanks a lot guys that should save me ton of time. I tried reading the README file but if I remember correctly it was a windows exec file and I'm on a Mac. I'll have a look at the schematic when I get to a computer then it's off to buy connectors and test and calibrate. What connectors are used between the motors and the btn7960? I'm using the same motors as Ovaltineo.


----------



## Ovaltineo (Jul 18, 2013)

The README is a text file, not an exe file. Give it a .txt extension if you cannot open it with a Mac.

The BTN7960 have screw terminals, so just connect the wires from the motors directly to these.


----------



## phaedrus (Aug 24, 2013)

Ovaltineo said:


> I actually downloaded and learned how to use TinyCAD this morning - already built two symbols and created the schematic.


Well done OT, that's a very impressively short learning curve.

Despite several of the things I do (or have done) for a living, including using Autocad and other such things from time to time, I prefer to hand draw some designs - particularly for smaller jobs. Probably it's 'cos I'm lazy, or an old bugger...!

P.


----------



## Ovaltineo (Jul 18, 2013)

Thanks P, but I think it is more to do with TinyCAD being easy to use .

I have now uploaded UNO/Roboclaw/MPU6050 schematic in the first post.


----------



## ketutsapta (Oct 6, 2013)

Hello Ovaltine,

Thank you very much about your sharing, and can you share again about the body/metalwork ? photos or picture size the body.

Thank you


----------



## phaedrus (Aug 24, 2013)

ketutsapta said:


> Thank you very much about your sharing, and can you share again about the body/metalwork ? photos or picture size the body.


KT: If you look at JR's post #45 on this thread you'll see he references the build thread where there are several photographs and a video of different builds, including OT's.

Cheers. P.


----------



## mizlplix (May 1, 2011)

OK, I verified that everything was plugged in as per the drawing. (BTW: I do not have an UNO, It is a Ruggeduino which is like an Uno SMD, so the drawing is not accurate for me.)

I turn it on. I get a green LED on all units.

I do as I read in the latest instructions:

I turn the unit on.
I bring up the serial monitor, I get:









I reset the board and get:









I edit SegwayClone.h by adding "//" before "#define MODE_CALIBRATE"
and upload. I bring up the serial monitor, reset and get:










No motor movement or anything.

Question? Can the motors even move if "#define MODE_RUN" had a " //" in front of it still?

Lost in AZ....Miz


----------



## phaedrus (Aug 24, 2013)

Miz, it looks a little like the terminal rate and that of the code are different, giving a relatively unintelligible output.

IIRC the code is set to give a serial rate of 115kbps, it might pay to check that your IDE serial monitor is set to the same. 

If they are both the same then it could be that your setup doesn't like it quite so fast - I'd try setting it to say 38400 in the code, upload that and start the serial monitor at the same speed. Hopefully that'll work - you may need to reset the Ruggeduino with the monitor running in order to get something to appear.

Once you get the monitor and Ruggeduino talking properly it will allow some debugging as to why nothing else is happening...

Cheers, P.


----------



## mizlplix (May 1, 2011)

Thx, P: I will play with it some then.

When I do something I am knowledgeable about, it always seems to go smoothly,
but when I delve into a rusty area, Murphy is always waiting for me because he knows I am as helpless as a child.

Miz


----------



## mizlplix (May 1, 2011)

What a cluster *()&$%^&() that was....

OK, it communicates at 115,200 Baud (it was on 9,600)

Thanks for the clue.

Miz









I get the first two lines on opening the serial monitor, the second two after editing define motors max AND reseting the board.

no gyro numbers.


----------



## Ovaltineo (Jul 18, 2013)

Miz,

Since you are using MPU6050 X2 instead of the GY80, edit SegwayClone.h so the first bit looks like below then upload to the Arduino. It will calibrate the MPU6050s.


```
#define MODE_CALIBRATE
//#define MODE_RUN

/*
Uncomment one STEERING type below
*/
//#define POT_STEERING
#define MPU6050_X2_STEERING
//#define MPU6050_X1_STEERING
//#define GY80_STEERING
```

Then edit SegwayClone.h again so the first bit looks like below then upload to the Arduino. The defaut is run mode so there is no need to uncomment #define MODE_RUN.


```
//#define MODE_CALIBRATE
//#define MODE_RUN

/*
Uncomment one STEERING type below
*/
//#define POT_STEERING
#define MPU6050_X2_STEERING
//#define MPU6050_X1_STEERING
//#define GY80_STEERING
```


----------



## Ovaltineo (Jul 18, 2013)

Hey guys, I'm not feeling too great at the moment. I might spend a few days or weeks in the hospital, so don't feel bad if I don't reply to your posts. It's a real bummer .


----------



## mizlplix (May 1, 2011)

Sorry to hear that OT. I wish you a speedy recovery and keep us posted how you are doing when possible.

I want to especially thank you for all of the great work on this project. I am literally a year ahead of where I would be if
I had to go it alone.

You will be in my thoughts.

Miz

(On second thought, maybe if you stood on your head for a while you would be right side up and it might help you.
All of that being upside down all of the time has got to be rough.)


----------



## phaedrus (Aug 24, 2013)

Ovaltineo said:


> Hey guys, I'm not feeling too great at the moment. I might spend a few days or weeks in the hospital, so don't feel bad if I don't reply to your posts. It's a real bummer .


OT: I just tried to find a way to send you a PM but it doesn't seem like this site supports that... edit: should have looked harder!!

Anyway, like Miz, I wish you all the best - I'm aware of of your previous scare and hope it's not as severe as that... We'll be thinking of you and keenly looking out for your early return, it's a good little community here and you'll be sorely missed in the interim.

Take care, P.


----------



## mizlplix (May 1, 2011)

Left click on the name of the person and a drop down menu appears. 

Select option two, send a PM.

Miz


----------



## phaedrus (Aug 24, 2013)

Yeah, thanks Miz, I found it about a millisecond after posting the message - hence my 'reason' for editing the post.

It really wasn't my day yesterday, although nowhere near as severe as OT's by the sound of it.

Cheers, P.


----------



## JRoque (Mar 9, 2010)

Yikes I missed that posting by OT. Hope he comes out ok. 

Too bad we don't have his own source code - we could probably find what's wrong with him, fix it, recompile and upload a new OT 2.0

Best wishes,
JR


----------



## Ovaltineo (Jul 18, 2013)

Thanks for your well wishes guys! I didn't go to hospital and am hoping I don't have to. The good news is that it has nothing to do with falling from a Segway, though such an incident is equally as dangerous .


----------



## battagae (Aug 13, 2013)

If I have 2 12V batteries how would they connect to the Arduino Mega in order to allow the motors a max of 24V? I was going to wire them in series to a DC barrel plug which is what the Mega takes but I just looked up the specs and it says 7-12V recommended.


----------



## JRoque (Mar 9, 2010)

Hi Bat.

Connect your batteries to fit your motors and controller. In my case, my motor nameplates say they're 24VDC. My motor controller also supports 24V input. So I used a 2 serial (and 2 parallel) battery configuration to reach 24VDC and plugged that directly to the motor controller.

Most microcontrollers (ie: Arduino) need 5V or 3.3V. If your Arduino board comes with an on-board voltage regulator, then follow the guidelines to power that accordingly. If they recommend a max of 12V then you need a DC to DC converter. In my case, I have a separate DC-DC converter that takes the 24V from the batteries and reduces it to 5V so I can feed it to the Arduino.

JR


----------



## mizlplix (May 1, 2011)

Hi:

I am using 6- 7.5 AH SLA 12v batteries. 2S/3P for a 24VDC X 22.5 AH pack.

Both my Roboclaw and Ruggeduino are good for 24 VDC, but I wanted some headroom on the "Duino". So, I run the Claw on straight pack voltage and the Dunio on 12VDC by using a simple regulator IC down to 12VDC. 

The 12VDC + goes to the VIN pin on the Duino.
12DVC - goes to one of the GRD pins on the Duino.

I have a main pack switch for the Scooter then a simple toggle switch to power up the Claw after the Duino boots.

I am going to place a Duino reset button on the handlebars and maybe a kill switch for the Claw too.

I also use the 70 AMP resettable breaker on the motors.

Miz

Miz


----------



## Ovaltineo (Jul 18, 2013)

Battagae, 

Miz is right. Use a DC-to-DC step down converter like this http://www.ebay.com/itm/DC-Buck-Con...833?pt=LH_DefaultDomain_0&hash=item417760b179. Important: adjust the output of the converter (turn the trimmer pot) to 11v (check with a voltmeter) before plugging it to the Arduino.


----------



## mizlplix (May 1, 2011)

OT: Could you give me a PN: for a FET to use to turn the Claw on and off using the Duino?

I deal with Mouser quite a bit.

Miz


----------



## Ovaltineo (Jul 18, 2013)

Miz, get the BS250.


----------



## mizlplix (May 1, 2011)

Cool, I just ordered 6. 

I was thinking of placing a manual switch in series with the FET and mounting on the handlebars for an emergency stop function.

When the button was on, it had no effect, but if pressed, it would drop out power to the Claw.

It might be a handy thing.........

I am contemplating an external reset button for the Duino also. One maybe down on the chassis somewhere that would make you put down at least one foot before performing the reset operation.

So, if you were riding and something locked up or started bucking, you press the kill button, then put one or both feet down, press reset and as soon as it booted you could press the kill switch again and remount.

Does this make sense?

Miz


----------



## Ovaltineo (Jul 18, 2013)

Sounds good Miz. Ideally, your kill switch will kill the main battery coz killing the logic power to the Roboclaw will not stop it if a MOSFET shorted (it happened to me). But, this requires a high-current relay. I haven't bothered doing this myself coz the BTN7960 is protected from thermal and current overload.


----------



## mizlplix (May 1, 2011)

I actually do have a high current relay, but can not remember it's specs.

It was for My BMS. It shut off 120 VAC @ 20 amps and used a signal from my BMS head board. 

It is an electronic relay and might do the job. I will check today.

Miz.


----------



## JRoque (Mar 9, 2010)

Hey Miz,

Many solid state relays use Triacs/SCR based switches that count on the zero-crossing nature of AC voltage to turn off. Most light dimmers work this way. Once turned on with DC, they won't turn off again. There are SSR designed for DC voltage.

A contactor, like the ones we use in EVs, would work well here though they can be bulky and expensive.

JR


----------



## chemamata (Oct 20, 2013)

Hello everyone.First Ovaltineo Congratulations for your excellent work.Secondly Ovaltineo Congratulations to share it with others.It gave me a `little electric chair and my first thought was about getting a Segway clone, controlled by Arduino.Unfortunately my programming skills are not to get into such work. Also, my English is null. All Google Translator translatesSearching the net I found this forum, namely the post of "mizlplix" with his "Another Segway clone".There you showed you and then you began this other post. So now I follow two, ha ha ha ha ha.I have already ordered the two sensors and controllers. The Arduino and I have of my first steps.As soon as I arrive I'm disassembling the chair and soldering irons, heh heh heh.Until then it is a pleasure to read all the interesting things you say


Hola a todos.
En primer lugar Felicidades a Ovaltineo por su excelente trabajo. 
En segundo lugar Felicidades a Ovaltineo por compartirlo con los demás.
Hace `poco me regalaron una silla electrica y en lo primero que pensé fué en hacerme un clon Segway, controlado por Arduino.
Desgraciadamente mis conocimientos de programación no son para meterme en semejante trabajo. Además mi Inglés es nulo. Todo lo traduce Google Translator
Buscando por la red encontré este foro, en concreto el post de "mizlplix" con su "Another Segway clone".
Allí apareciste tu y luego iniciaste este otro post. Así que ahora sigo dos, ja ja ja ja ja.
Ya tengo pedidos los dos sensores y los dos controladores. La placa Arduino ya la tengo de mis pinitos.
En cuanto me lleguen ya estoy desmontando la silla y soldando hierros, je je je.
Hasta entonces es un placer leer todas las cosas interesantes que decis


----------



## Ovaltineo (Jul 18, 2013)

Welcome to the forum chemamata. Don't hesitate to ask questions, even if your English is not good. Don't forget to buy a DC-to-DC step down converter to power your Arduino from the 24V battery.


----------



## chemamata (Oct 20, 2013)

Thanks for the welcome.
And thanks for the reminder, I had forgotten. I'm going for it.
Also, I think I've made ​​my first mistake. 
Instead of buying the BTN7960 I bought the BTS7960. This:
http://www.ebay.es/itm/221235721147?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
I think it is the same.


----------



## Ovaltineo (Jul 18, 2013)

That's the correct one. They are the same and this one has a heatsink. I recommend a 12v fan blowing on the two motor controllers too.


----------



## chemamata (Oct 20, 2013)

Great, thanksI 
have searched the DC-DC converter, 24v-12v. 
They cost a lot of money. I'm currently unemployed and I have to look at these issues of money.
I think I can work my idea.
LM7812. 
One for each fan (old computer) and another to power the arduino. 
Among the three is less than $3
What do you think?
Can it work?


----------



## Ovaltineo (Jul 18, 2013)

This is only $1.95. Capable o 3 amps, you only need 1 of this to power both Arduino and the fan.

You only need 1 fan to blow across the two controllers. The controllers don't get too hot, so you can use a small low-power fan, like those used for CPU coolers.


----------



## chemamata (Oct 20, 2013)

It is a wonder that Internet. 
As from the other side of the world can help.
Thank you very much


----------



## chemamata (Oct 20, 2013)

Hello Oval.
As I have ordered the parts and slow in coming , I'm looking at the files you have scheduled.
Taking advantage of your kindness , I want to ask you a few questions to better understand.
My configuration is as follows :
1x Arduino MEGA
2x MPU- 6050
2x BTS7960B
And your software
In the file " motors.h " you put :

# ifdef PWM_PWM_CONTROLLER

/ / # Define MOTOR_MAX 255
# define MOTOR_MAX 30

Does this defines the maximum speed ?.

File " SegwayClone.h "

I understand it is to calibrate or normal use.You have done well :

/ *
Uncomment one MODE below
* /
# define MODE_CALIBRATE
/ / # define MODE_RUN

/ *
Uncomment one type STEERING below
* /

/ / # define POT_STEERING
/ / # define MPU6050_X2_STEERING
/ / # define MPU6050_X1_STEERING
# define GY80_STEERING

/ *
Uncomment one type CONTROLLER below
* /

/ / # define PWM_PWM_CONTROLLER
/ / # define PWM_DIR_CONTROLLER
# define ROBOCLAW_CONTROLLER
# define BUZZER_PIN 12

For my setup I think we should modify it in this way :

/ *
Uncomment one MODE below
* /

# define MODE_CALIBRATE
/ / # define MODE_RUN

/ *
Uncomment one type STEERING below
* /
/ / # define POT_STEERING
# define MPU6050_X2_STEERING
/ / # define MPU6050_X1_STEERING
/ / # define GY80_STEERING

/ *
Uncomment one type CONTROLLER below
* /
# define PWM_PWM_CONTROLLER
/ / # define PWM_DIR_CONTROLLER
/ / # define ROBOCLAW_CONTROLLER

# define BUZZER_PIN 12

Am I right?

Then put:

# define MAX_ANGLE 18 / / adjust Depending on your machine
# define MIN_ANGLE -15 / / adjust Depending on your machine

What angles are these?

Do not quite understand how is calibrated.
I will read again the previous messages. Can anyone let me unread
Thanks


----------



## Ovaltineo (Jul 18, 2013)

Chemamata,

Yes MOTOR_MAX defines max power from motor controller. Leave it at 30 to test self balance of the machine. You cannot ride it. If everything works, set it to 255.

Yes, your SegwayClone.h modification is correct.

MAX_ANGLE is max tilt foward before motor is cut (for safety). MIN_ANGLE is max tilt backward before motor is cut.

To calbrate, level the Segway (or tilt back a little bit like I do), then reset your Arduino. This position will be burned in the EEPROM. While still levelled, remove MODE_CALIBRATE and re-program the Arduino. Make sure it is off the ground or no wheels attached when doing this first time. Check if tilting forward and back works as expected before testing it on the ground.


----------



## chemamata (Oct 20, 2013)

Ovaltineo.
Thank you very much.
That nerves!. Materials without actually!.
Aaagggg!!


----------



## quikstep (Sep 23, 2013)

Hey OT,

This is my "brain":









I'm using the version 2.6 code and have largely unchanged settings.
-MPU6050x2
-DIR controller
-38400 Serial printout.

My question is, is it usual for the code to start working only when I tilt it towards me (in this case, backwards)? Can you tell me the line of code that help me to reverse this behaviour without having to remount the left MPU6050?

Thanks!


----------



## Ovaltineo (Jul 18, 2013)

I cannot see the orientation of your MPU6050s, so I cannot tell if they are mounted correctly. Are they the ones under the red button? They should not be mounted together. One should be on the board, the other on the steering shaft. Both should have the X axis pointing to the front.

It should work when tilted forward or back. Connect it to the serial monitor (115200 baud). The board angle, accelerometer, and gyro should change from positive to negative when you tilt forward and back. The motor should go from positive to negative too. The steering angle should also go from positive to negative when you tilt the steering sensor left and right.

If it is not working like this, then try to re-calibrate. Make sure to keep it level when you re-program without calibrate mode. If this doesn't work, take a snapshot of the serial monitor when tilted forward and another shapshot when tilted back and post them here.

If this is working but the motors are going in reverse, then just swap the motor connections to your controller.


----------



## quikstep (Sep 23, 2013)

Ovaltineo said:


> I cannot see the orientation of your MPU6050s, so I cannot tell if they are mounted correctly. Are they the ones under the red button? They should not be mounted together. One should be on the board, the other on the steering shaft. Both should have the X axis pointing to the front.
> 
> It should work when tilted forward or back. Connect it to the serial monitor (115200 baud). The board angle, accelerometer, and gyro should change from positive to negative when you tilt forward and back. The motor should go from positive to negative too. The steering angle should also go from positive to negative when you tilt the steering sensor left and right.
> 
> ...


Below is the GY-521 board I used:









After re-calliberating and using 115200 Baud, it seems like I do not have the tilt backwards to start oddity. However 

1 concern remains: WHO_AM_I showing both at 0x68 address. I can confirm that right side board for steering is receiving 5v at AD0 pin.

1 concern created is the drifting of LEFT and RIGHT values. By the time I finish typing it's already at 30/30.

WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
ACCEL: 0.17 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: 0.05 MOTOR: -0.02 LEFT: 0 RIGHT: 0
ACCEL: -0.45 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.13 MOTOR: -0.13 LEFT: 0 RIGHT: 0
ACCEL: 0.02 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: 0.08 MOTOR: -0.21 LEFT: 0 RIGHT: 0
ACCEL: -0.10 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.06 MOTOR: -0.31 LEFT: 0 RIGHT: 0
ACCEL: -0.20 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.10 MOTOR: -0.63 LEFT: 0 RIGHT: 0
ACCEL: -0.01 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: 0.09 MOTOR: -1.19 LEFT: -1 RIGHT: 0
ACCEL: 0.08 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: 0.13 MOTOR: -1.73 LEFT: -2 RIGHT: -1
ACCEL: 0.22 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: 0.13 MOTOR: -2.20 LEFT: -2 RIGHT: -1
ACCEL: 0.31 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.10 MOTOR: -2.69 LEFT: -3 RIGHT: -2
ACCEL: 0.05 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.09 MOTOR: -3.08 LEFT: -3 RIGHT: -2
ACCEL: -0.15 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: 0.12 MOTOR: -3.63 LEFT: -4 RIGHT: -3
ACCEL: 0.29 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: 0.13 MOTOR: -4.28 LEFT: -4 RIGHT: -3
ACCEL: 0.06 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: 0.14 MOTOR: -4.86 LEFT: -5 RIGHT: -4
ACCEL: -0.01 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.13 MOTOR: -5.27 LEFT: -5 RIGHT: -4
ACCEL: 0.37 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.16 MOTOR: -5.66 LEFT: -6 RIGHT: -5
ACCEL: 0.34 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.11 MOTOR: -5.99 LEFT: -6 RIGHT: -5
ACCEL: 0.23 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.10 MOTOR: -6.23 LEFT: -6 RIGHT: -5
ACCEL: 0.12 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.09 MOTOR: -6.44 LEFT: -6 RIGHT: -6
ACCEL: -0.06 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.07 MOTOR: -6.63 LEFT: -6 RIGHT: -6
ACCEL: 0.15 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.09 MOTOR: -6.86 LEFT: -7 RIGHT: -6
ACCEL: 0.09 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.10 MOTOR: -7.10 LEFT: -7 RIGHT: -6
ACCEL: 0.75 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.10 MOTOR: -7.39 LEFT: -7 RIGHT: -7
ACCEL: 0.06 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: 0.10 MOTOR: -7.50 LEFT: -7 RIGHT: -7
ACCEL: 0.13 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.11 MOTOR: -7.36 LEFT: -7 RIGHT: -6
ACCEL: 0.30 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.13 MOTOR: -7.09 LEFT: -7 RIGHT: -6
ACCEL: -0.13 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: 0.10 MOTOR: -6.68 LEFT: -7 RIGHT: -6
ACCEL: 0.30 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: 0.07 MOTOR: -6.27 LEFT: -6 RIGHT: -6
ACCEL: 0.34 GYRO: 0.00 BOARD ANGLE: 0.04 STEER ANGLE: 0.07 MOTOR: -5.72 LEFT: -5 RIGHT: -5
ACCEL: -0.06 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.04 MOTOR: -5.30 LEFT: -5 RIGHT: -5
ACCEL: 0.17 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: 0.08 MOTOR: -5.16 LEFT: -5 RIGHT: -4
ACCEL: -0.06 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.10 MOTOR: -5.34 LEFT: -5 RIGHT: -4
ACCEL: 0.24 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.13 MOTOR: -5.60 LEFT: -6 RIGHT: -5
ACCEL: -0.22 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.06 MOTOR: -5.97 LEFT: -6 RIGHT: -5
ACCEL: -0.54 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.10 MOTOR: -6.39 LEFT: -6 RIGHT: -6
ACCEL: -0.36 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: 0.10 MOTOR: -6.96 LEFT: -7 RIGHT: -6
ACCEL: 0.12 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: 0.16 MOTOR: -7.62 LEFT: -8 RIGHT: -7
ACCEL: -0.24 GYRO: 0.00 BOARD ANGLE: -0.07 STEER ANGLE: 0.12 MOTOR: -8.43 LEFT: -8 RIGHT: -8
ACCEL: -0.24 GYRO: 0.00 BOARD ANGLE: -0.06 STEER ANGLE: 0.09 MOTOR: -9.34 LEFT: -9 RIGHT: -9
ACCEL: -0.37 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.08 MOTOR: -9.91 LEFT: -10 RIGHT: -9
ACCEL: -0.36 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.06 MOTOR: -10.27 LEFT: -10 RIGHT: -10
ACCEL: -0.31 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.05 MOTOR: -10.56 LEFT: -10 RIGHT: -10
ACCEL: -0.43 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.07 MOTOR: -10.74 LEFT: -10 RIGHT: -10
ACCEL: -0.45 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.09 MOTOR: -10.97 LEFT: -11 RIGHT: -10
ACCEL: -0.54 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.11 MOTOR: -11.11 LEFT: -11 RIGHT: -10
ACCEL: -0.19 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.13 MOTOR: -11.28 LEFT: -11 RIGHT: -10
ACCEL: -0.34 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: 0.11 MOTOR: -11.31 LEFT: -11 RIGHT: -10
ACCEL: -0.69 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.07 MOTOR: -11.49 LEFT: -11 RIGHT: -11
ACCEL: -0.26 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.15 MOTOR: -11.73 LEFT: -12 RIGHT: -11
ACCEL: -0.15 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.06 MOTOR: -11.93 LEFT: -12 RIGHT: -11
ACCEL: -0.27 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.07 MOTOR: -11.99 LEFT: -12 RIGHT: -11
ACCEL: -0.27 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.02 MOTOR: -12.10 LEFT: -12 RIGHT: -12
ACCEL: -0.06 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.02 MOTOR: -12.44 LEFT: -12 RIGHT: -12
ACCEL: 0.24 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: 0.00 MOTOR: -12.62 LEFT: -12 RIGHT: -12
ACCEL: -0.24 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: -0.00 MOTOR: -12.54 LEFT: -12 RIGHT: -12
ACCEL: -0.09 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.05 MOTOR: -12.19 LEFT: -12 RIGHT: -12
ACCEL: 0.19 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.02 MOTOR: -11.88 LEFT: -11 RIGHT: -11
ACCEL: 0.09 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: 0.02 MOTOR: -11.55 LEFT: -11 RIGHT: -11
ACCEL: -0.10 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: 0.00 MOTOR: -11.14 LEFT: -11 RIGHT: -11
ACCEL: -0.15 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: -0.04 MOTOR: -10.80 LEFT: -10 RIGHT: -10
ACCEL: 0.22 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: -0.00 MOTOR: -10.52 LEFT: -10 RIGHT: -10
ACCEL: 0.01 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: 0.01 MOTOR: -10.10 LEFT: -10 RIGHT: -10
ACCEL: 0.01 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.02 MOTOR: -9.79 LEFT: -9 RIGHT: -9
ACCEL: -0.02 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: -0.03 MOTOR: -9.66 LEFT: -9 RIGHT: -9
ACCEL: -0.09 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: -0.03 MOTOR: -9.59 LEFT: -9 RIGHT: -9
ACCEL: 0.22 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: -0.01 MOTOR: -9.28 LEFT: -9 RIGHT: -9
ACCEL: 0.08 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: -0.02 MOTOR: -8.85 LEFT: -8 RIGHT: -8
ACCEL: 0.09 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: -0.06 MOTOR: -8.40 LEFT: -8 RIGHT: -8
ACCEL: 0.57 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: -0.04 MOTOR: -8.01 LEFT: -7 RIGHT: -8
ACCEL: 0.03 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: -0.00 MOTOR: -7.74 LEFT: -7 RIGHT: -7
ACCEL: 0.02 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.05 MOTOR: -7.55 LEFT: -7 RIGHT: -7
ACCEL: -0.24 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.09 MOTOR: -7.86 LEFT: -8 RIGHT: -7
ACCEL: -0.06 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: 0.09 MOTOR: -8.36 LEFT: -8 RIGHT: -8
ACCEL: -0.29 GYRO: 0.00 BOARD ANGLE: -0.05 STEER ANGLE: 0.07 MOTOR: -8.98 LEFT: -9 RIGHT: -8
ACCEL: -0.08 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: 0.10 MOTOR: -9.61 LEFT: -9 RIGHT: -9

On the other note about not mounting them together, i was under the impression that board 1 takes care of ACCEL & GYRO while board 2 takes care of LEFT & RIGHT. It made me thought that they can be mounted together in the junction box which will be hung to the steering handle. Pls correct me if I'm wrong.


----------



## phaedrus (Aug 24, 2013)

QS: IMO the best place for the 'driving' IMU is at a line along the axis of the driving wheels - in other words place the main MPU board between the wheels at around the height of the axles if at all possible.

The steering MPU board would ideally be placed at the steering pivot axis so that essentially all it is seeing is tilt.

This is not to say that it won't work at all the way you have it but I suspect it could be problematic. IIRC OT did some work to see if a single IMU could be used and concluded that while it could placement was very critical. If you look back you'll see a post by him on this I think.

If you want to check the board addresses then use I2C scanner - the who_am_i routine doesn't report the 0x69 address, even though it is most likely there and correct.

Cheers, P.


----------



## battagae (Aug 13, 2013)

I've have everything wired and the motors are sort of reacting to the gyro tilt but it seems to be hit or miss. I've seen signs of it working but for the most part the movements are either sporadic or the motors constantly run after I return the gyro to level. I tried looking at the signal through an oscilloscope but it mimics the motors actions. I have a feeling my MPU6050's are bad but I hope it isn't the case and really don't want to buy new ones.

Just tried again calibration and run the motors now just run no matter how my board is tilted. A few times it takes a little tilt to get it started but then just keeps running.


----------



## phaedrus (Aug 24, 2013)

BG: It is fairly sensitive so it's entirely possible things are actually working as they should - the motors will ramp up and stay there for a bit if you tilt it just a small amount, there is a certain amount of hysteresis in response so they'll take some time to wind down if you tilt back. 

You should be able to monitor the serial data output that will give you some detail as to what's happening, I think it unlikely that your boards are faulty at this stage. 

I take it you've not actually got things in a chassis yet?

Cheers, P.


----------



## phaedrus (Aug 24, 2013)

*Minor steerng bug.*

Just FYI I had a minor but annoying bug in the steering whereby the machine would suddenly slow a wheel when turning left going forward, or backwards (it would alternate the wheel that slowed, but the steering position was the same). This is using PWM_DIR control.

It turned out that if MOTOR_MAX was set to 255 the problem occurred, at 254 it didn't. I've not yet researched why, and as I have made some minor modifications to this code it's not certain it would be replicable elsewhere, but in case someone else struck the issue I though it worth a mention.

Cheers, P.

BTW, we've also got a push-back operating, still very much beta code at this stage, and there are some refinements/testing yet to go through, but I'll post it up at some stage if it looks to be working ok...


----------



## battagae (Aug 13, 2013)

You're right I haven't fabricated anything yet but I'll probably be heading to the store in the next couple days. I'll try tilting it less and if I'm still running into problems I can upload a video of exactly what's going on. The reason I'm suspicious of my gyros is because an LED is out on one of them and I was scared thinking that 5V might have been too much.

Thanks for the help everyones feedback is helping me meet my deadline!


----------



## phaedrus (Aug 24, 2013)

battagae said:


> thinking that 5V might have been too much.


That should be ok - they have a regulator on board as I recall, although I run mine from the Arduino 3.3v line.

However if you have no LED lit then indeed there could be an issue - I suggest you (carefully!) follow through with a voltmeter and see if you have a break in the supply somewhere, or if indeed 5v is present at the VCC pin of that board and there's perhaps something else awry...

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

quikstep said:


> After re-calliberating and using 115200 Baud, it seems like I do not have the tilt backwards to start oddity. However
> 
> 1 concern remains: WHO_AM_I showing both at 0x68 address. I can confirm that right side board for steering is receiving 5v at AD0 pin.
> 
> ...


quikstep, the "who am i" check will always return 68 for both sensors. 

The "drift" that you can see is normal. It won't be there when you have wheels on the gound.

You must move the board gyro to the board itself, preferably along the wheel axis.


----------



## Ovaltineo (Jul 18, 2013)

*Re: Minor steerng bug.*



phaedrus said:


> Just FYI I had a minor but annoying bug in the steering whereby the machine would suddenly slow a wheel when turning left going forward, or backwards (it would alternate the wheel that slowed, but the steering position was the same). This is using PWM_DIR control.
> 
> It turned out that if MOTOR_MAX was set to 255 the problem occurred, at 254 it didn't. I've not yet researched why, and as I have made some minor modifications to this code it's not certain it would be replicable elsewhere, but in case someone else struck the issue I though it worth a mention.
> 
> ...


P., your controller uses n-channel mosfets for high side. This needs a boost voltage using capacitors and diodes that charge using the PWM. A PWM with 255 value is a constant 5v, this will not work with boost charging which needs a cyclic signal. Hence, MOTOR_MAX must be less than 255 for your controller.

I also have working push back code. Haven't tested it enough to release it though.


----------



## phaedrus (Aug 24, 2013)

Thanks for the info OT, however I'm not completely certain that's quite what was going on - the issue appeared to be in one direction only (sending 255 to *both* motors), and there was specific speed slowdown, suggesting commanded PWM to the controller.

However I didn't look at it on the monitor unfortunately, although it would be easy to re-create now that the root problem is known. I might do this so we can determine for sure & I'll post the result when I do.

Ok on the pushback, sounds good. Mine's working ok on my unit (subject to tweaking) but I've not really had much time to test it and it's really a bit of a work in progress so I'm loath to post anything at this stage. Also I'm still operating my machine at reduced voltage 'cos of the FET problems - I suspect it'd work somewhat better/different at the designed 24v and it'd be good to see how it went with that before releasing anything.

That said if it's of any use to you I'm happy to PM it to you - it's your project after all and if it helped (even to see how not to do it) we'd be pleased if that was the case.

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

P., 

I'm confused - in post #91, you said 


> Just FYI I had a minor but annoying bug in the steering whereby the machine would suddenly slow a wheel when turning left going forward, or backwards (it would alternate the wheel that slowed, but the steering position was the same). This is using PWM_DIR control.


then in post #96, you said


> the issue appeared to be in one direction only (sending 255 to *both* motors), and there was specific speed slowdown, suggesting commanded PWM to the controller.


So is it happening while going straight forward only? As I said, sending 255 with your controller will stop the boost voltage and will slow it down.


----------



## phaedrus (Aug 24, 2013)

No, sorry OT I've possibly not explained it well.

The issue occurs essentially if the steering is held in one direction only - so that going forward in this case it happens when turning left that the RH motors slows down after a certain speed is reached (thus rapidly slowing down the machine and straightening up the turn - if you don't step off).

Holding that same turn command but driving in reverse means that the problem occurs to the LH motor.

Driving straight ahead means there is no issue.

What I meant by the 255 to both motors was that the, as far as I know, without specifically observing it on screen (albeit in earlier testing I had), the controller will accept a 255 (5v no pulse) input without failure to both LH & RH motor - in other words it wasn't specific to just one side.

Now of course it's entirely possible that when I do look at the data stream I will see something different so it's still entirely possible your synopsis could be correct, but it would seem a little odd that the controller would go into a (say) half-speed mode on one side only given such input. Naturally it'd be much easier to diagnose with some info on the controller [a schematic would be great] but I guess we can't have everything! 

Anyway I figure it's worth mentioning in case anyone else struck the same problem, it did take a while to figure out a 'fix'...

Edit: Just to clarify further it would NOT fault in this way if the steering was held in the opposite direction (ie. turning to the right), it was this that lead us to wondering if there was some odd calculation going on since (1) the controller had demonstrated a PWM command of 255 was ok to both motors (2) the problem occurred only when the steering was held in one direction.

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

battagae said:


> You're right I haven't fabricated anything yet but I'll probably be heading to the store in the next couple days. I'll try tilting it less and if I'm still running into problems I can upload a video of exactly what's going on. The reason I'm suspicious of my gyros is because an LED is out on one of them and I was scared thinking that 5V might have been too much.
> 
> Thanks for the help everyones feedback is helping me meet my deadline!


battagae, 

Please capture the first page of the serial monitor output (disable auto-scroll) and post it here. I want to see if both sensors respond to the "WHO_AM_I" query.

Does the board angle change from positive to negative if you tilt the board sensor forward and back?

Does the steering angle change from positive to negative if you tilt the steering sensor right and left?


----------



## phaedrus (Aug 24, 2013)

Morning OT, I'm not certain if this site notifies one of PM's when they arrive - some don't - but FYI I sent you one yesterday with our early pushback code effort, in case it was of any use.

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

Thanks P, it's a bit more complex than mine, but probably more effective. I'll give it a test today if the weather is nice (Melbourne has 4 seasons in a day!).


----------



## phaedrus (Aug 24, 2013)

> Thanks P, it's a bit more complex than mine, but probably more effective. I'll give it a test today if the weather is nice (Melbourne has 4 seasons in a day!).


I'll be interested to hear how it goes - I'm still running mine on 12v so there's not much extra power in the motors and you can still tip it over.. yours should be quite a lot better there I expect.

I've never lived in Melbourne but have heard similar comments from others about the weather! We had plenty of breeze here so I had my two youngest out learning to sail today, not a bad life 

Cheers, P.


----------



## chemamata (Oct 20, 2013)

Ovaltineo.

Hello.
Before finding this post, I had bought this:

http://www.dimensionengineering.com/products/sabertooth2x25I 

think it's similar to ROBOCLAW.
It can be replaced without changing anything??.
It would be very difficult to adapt the firmware code
thank


----------



## Ovaltineo (Jul 18, 2013)

chemamata,
Looking at the specification document, the Sabertooth is very similar to the Roboclaw. But it doesn't support packet serial commands #32 and #33 that is used in the code, so it won't work without a change.

I will add support for the Sabertooth in the next version.


----------



## chemamata (Oct 20, 2013)

Thank you very much for your interest.
This well the firmware code is as broad as possible.
Few more variations that supports better hardware.


----------



## mizlplix (May 1, 2011)

For any of you using a Roboclaw or similar controller, here is a good place to go for help:

http://forums.basicmicro.com/

I have a post there for my error code problem.

The Admin works for Orion Robotics and watches the board closely and responds quickly.

AND: On the Roboclaw, in packet serial mode, the S3 pin becomes a "kill" switch, handy for those needing one......

Miz


----------



## robertholmberg (Oct 26, 2013)

Hi, I have now read all the posts and i am so in to this. Sadly im on a run and will not be back to where i can start building "my" clone until december. But time for planning. But i must say a great build by you so far. It has been a pleasure to read so far. 

If i buy a motor for higher Voltage (36V) than the board (BTS7960B) can handle and the battery will deliver, is it a problem or is it only that i cant use all the Power its made for?

Why im thinking about it is that i would like to later have a 36 Voltage circuit and change the BTS7960 for a 8960 dito and then just add some more batteries. But at the moment the 8960 is not widely available so i would like to start with this for now.

I probably going to buy the motors with a chain (or is it better to use a belt?), but the motor says a very high RPM and i wonder what size of sprocket would you suggest for the wheel? The motor will have the 11 tooth #25 sprocket i think. And the chain is it recommended to have it as short as possible?

More questions will come.

Cheers for now.

/Rob


----------



## phaedrus (Aug 24, 2013)

RH: That must be some run you're going on to last that long!

Assuming the type of motors we've been using (brushed permanent magnet DC) then they would likely still work at 24v, you just won't get as much speed/torque at the lower voltage. FYI I am currently running my machine at a similarly reduced voltage and it's workable, just not particularly fast and I can't tune it to work as I want quite so well.

You haven't said what RPM the motors are capable of but you can do a simple ratio calculation - deriving back from your driving wheel size and desired machine speed - to work out gear/sprocket sizes. I would allow for a 30% or so higher speed than desired in your calculation to allow for a pushback.

For example:

If you want to travel at say 10mph and you have a 16" wheel then the wheel must turn at around 210rpm. We want some capacity to go faster if needed for a pushback (say + 3mph) which would mean another 63rpm leaving a total required of 273rpm. For the sake of easy calculation let's say we need an even 200rpm.

From this you can work out that if you had motors that would do 400rpm then you'd need a 2:1 gear ratio, if they did 2000 rpm you'd need 10:1 etc in order to reach the desired speed. Note this assumes that the motors have sufficient power to acheive this.

Toothed belts may well be quieter and are quite strong so that would be a good alternative for the drive. The shorter the chain or belt, and within reason the tighter it is, then the better it would work as it would exhibit less lag.

Cheers, P.


----------



## robertholmberg (Oct 26, 2013)

Thank you for your answer.

Well, if it would be a run by feet I would end up slim, but it's just working abroad.

I got this motor that I probably will buy, I'm not german but an ok price, or anyone find cheaper including the shipping within Europe?

So would the calculation be like this:
Link: http://www.sunds-sportartikel.de/el...oter/36v-1000w-motor-fur-mach1-e-scooter.html
Details:
RPM: 3000
Watt: 1000
Volt: 36

To run this with only 24 Volt batteries, is it correct with the following calculation: W = U * I
Original: 1000 / 36 = 27,78
New: 27,78 * 36 = 666
Is it then 666 Watt i got from this motor to play with?

The small sprocket on the motor, I dont even know the size of this so i cant do the calculation yet. But as i read from your calculation i guess you were calculation the wheel size, is that right? It must also matter what size of sprocket I'm using on the wheel right? Or is that only how strong the clone would be? If i would use a exact the same sprocket it wouldn't be strong but fast, (at least in theory).
So i guess it is like this or I'm i wrong here too?

To make it all very easy, sizes are the circumference.
Wheel size 20cm
Sprocket on wheel 10cm
Sprocket motor: 5cm

5/10 = 0,5, this is how many laps the wheel takes for each round on the motor.
0,5/2 = 0,25, this is in this case the distance of travel per lap of motor.
If the motor would do 3000RPM (*0,25) it gives us 750 laps on the wheel.
750 laps (*20cm) on the wheel will transport us (15000 cm) 150 meter per minute.


Battery: (http://www.monsterscooterparts.com/24vo10amphob.html), I will take this just as an example. So then another question I was looking at and tried to figure out but my brain didn't help me. Here I'm not sure what type of battery i will get yet, but i guess it doesn't matter as long as the mAh is the same.
Lets take a look at 2 times 12 Volt 10Ah, they will be able to run for how long before its to low and need a charge?

I thought (and now its time for you to laugh at me) that you could calculate this like this: 24 Volt * 10 Ah = 240 Watt for one hour, and since the motor consume 666 in the above example i could only run this for 0,36 Hours?
//Edit: This is only for one motor, so since I'm using two of them, i guess i can only run half of this time right?

Im i doing the calculation completely wrong or did i just check out a very weak battery for the task?

/Rob


----------



## mizlplix (May 1, 2011)

Some rules to ponder:

1- a Segway's top speed is 12.5 MPH (Or as fast as you are willing to fall off)

2- There is no such thing as "too much battery". (I have a 22AH pack @ 24VDC)

3- You need a very tall tire to roll over surface imperfections. (Do not go too short)

4-You need a medium wide tire for flotation.(sand and dirt)

5- Use a SLA, NiCad, NiMh or LiPo battery. (something that is not messy)

6-At the speeds you are traveling, a chain drive is quiet (if tensioned properly).

7- A belt drive is twice the cost of chains.

8- Do not get hung up on a low center of gravity. Try for it, yes, but not
at the loss of standing room or batteries.

9- Plan on a kill button on your handlebars...........

10- Do not cheat on strength of your tiller bar assembly. Plan everything else around it, not the other way. It is the only control you have.

Miz


----------



## phaedrus (Aug 24, 2013)

RH: I agree with Miz here, you need a good sized wheel - 20cm (~8") would not be that great really. IMO twice that would be good (I'm talking about the total diameter including the tyre).

If you were to use a 40cm wheel (~16") then at Miz' 12.5mph (20kmh) the wheel needs to rotate at 260RPM (I'll ignore the need for pushback presently).

If your motor maximum RPM is 3000 then the required ration is 3000:260 or about 11:1 (since 11 * 260 = 2860). So the diameter of your gear wheel (sprocket, assuming chain drive) attached to the drive wheel would need to be 11x the size of the drive gear on the motor.

I'm running out of time to go over the rest since I need to take the kids out but consider that you won't be going full speed all the time and so you'll get a lot more range out of a battery than you've calculated. 

Cheers, P.


----------



## robertholmberg (Oct 26, 2013)

Yes indeed, i will get a bigger wheel, i just did it like that for the easy calculation, not that i planned to use it for real. But i think i got this part now. 20 Inch-ish, maybe it would be nice to lasercut a nice metal part for the hub of the wheel.

Is it a calculation or recommendation of how strong (guess it's called torque) to set the motors compared speed - torque, don't get the question to sound right, but hope that you will understand.


----------



## phaedrus (Aug 24, 2013)

I didn't run the site through Translate but it didn't look to me as if it gave torque specs for the motor.

That said I expect it should be fine - at 1kw input and assuming say 75% efficiency you have approx 1hp (per side) at the motor shaft. Given the gear ratio then there should be plenty of power available at the wheel for your purpose.

Cheers, P.


----------



## battagae (Aug 13, 2013)

I've attached the image what's there just keeps repeating! I also have a video I'll upload if you'd like. You can change it to a jpeg if it doesn't open in it's current format.

The second attached it's supposed to be running. I did this with one gyro the one that has a working LED

UPDATE: Fixed the problem. The connections to the pins on the gyro weren't solid so I put a couple solders on it and everything seems to be working!!


----------



## chemamata (Oct 20, 2013)

Hello.
Today I have reached the MPU-6050.
I could not resist the temptation to connect them to the Arduino. First the Arduino UNO MEGA and then R3.
I put in "Calibrate" and the monitor numbers have started dating a while. After stopped and so has quedao thing.
I guess that makes it okay right?.


battagae:
For all I know, the feeling that the outputs of the MPU6050 (Gyroscopios) have not properly connected to the Arduino.If you MEGA to pins "scl" and "sda" if the UNO to Analog pins 4 and 5.Try it.


----------



## markula (Oct 27, 2013)

Hi 

If people need motors. Lock at this. 

http://chinaxiangyang.en.alibaba.com/product/449412960-200556142/low_rpm_dc_motor_XYD_18.html

24-48V
250-1000W. 

Or i think this one i better. 
http://www.gngebike.com/one-side-axle-motor

350W 24V motor, gear and wheel. 
230 USD with shipping world wide.


----------



## mizlplix (May 1, 2011)

Just a thought:

On one of these balancing vehicles, the overall width is regulated by the width of a standard doorway (or your narrowest doorway you plan to use.) There are some 30" ones out there......

Subtract some comfortable operating clearance, say 2" per side and you have about 26" overall.

The optimal standing room needed is when the feet are at least a shoulders width apart at the outside. Maybe 21" in my case.


The design of the motor/drive/wheel/tire is very important because it encroaches into this space.

In our above example, we have 5" to use. Divided by two units and we have 2.5" per motor/drive unit.

Most of that is used up by the tire/rim width. But, it can have a negative offset and the gearbox/ chain/belt can be included in it if done properly.

The two examples in the above post have a good form factor if a dished-negatively offset wheel is used. 

We also must consider the gear ratio/tire roll out (diameter) and need about a 10-13 MPH top speed.

If I had mine to do over, I would just remove the gearboxes, turn the motors and use a chain drive with a taller/wider tire. That way I could get a lower CG with a decently good top speed as well as stability over rough-uneven terrain.

Miz


----------



## nopap (Sep 30, 2013)

Hi,
I'm new to the forum and haven't posted anything yet. 
I'm currently building my Segway and found this nice piece of code. Many thanks to ovaltine !
I'll soon post pics, my project should be running shortly. 

If you are interested, I've added Sabertooth support to it, using the Sabertooth library for packet serial commands. 
I currently run a Sabertooth 2x60A.

I still got some tuning to do, like was done for the roboclaw, currently the motors start way too fast. 
When done I can post the new code here, or maybe directly to you ovaltine if you are interested and you'd like to avoid multiplication of code posts.

Cheers


----------



## chemamata (Oct 20, 2013)

Hello Nopap.
Yes I would be interested in the code for the Sabertooth. 
I'm the one with that driver.Ovaltine kindly offered to develop the code.
It would be nice when it works well, come upstairs the code and circuit diagram. Ovaltine implement it in their soft.Chema


----------



## Ovaltineo (Jul 18, 2013)

This is a bit late, but I've been very busy with work, plus had to spend some time in hospital for a "health check".

I've just released v2.7 with Sabertooth support. I also added Phaedrus' pushback code -- use with caution (helmet, paddings) coz aggressive parameters WILL throw you off the vehicle. There's also support for a voltage sensor. The simple on - off buzzer has been replace with a multi-pattern (like morse code) alarm handler from Multiwii.

Please edit SegwayClone.h to match your hardware before using -- it is set to CALIBRATE mode and ROBOCLAW by default!!

I will update the schematics to add the voltage sensor (resistor voltage divider) later. Essentially, it's like this:

Battery----22K----A3----4.7K----Gnd


----------



## mizlplix (May 1, 2011)

Thx O.T.

I have sent the Roboclaw back for diagnosis.


So,I'm looking at a week or more down time.




The Sabertooth lookslike a good controller too. It is the same price as the roboclaw.


What would be a mild starting point value for the kick back?


Thanks, miz


----------



## Ovaltineo (Jul 18, 2013)

Miz,

I think the default values I have in the code are a mild values. I have set them to kickback early -- assuming your MOTOR_MAX is already set to 1500 for the Roboclaw.


----------



## chemamata (Oct 20, 2013)

OT.
I hope the checkup at the hospital is all OK.
I'm trying to connect to the arduino Sabertooth according to your diagram.
Not find it anywhere the value of p-mosfet. Does it matter either?
Can you tell me what the ideal?. I've configured as you say (I think).I've configured as described in section marked with the orange. 
I hope that is correct.
thanks


----------



## Ovaltineo (Jul 18, 2013)

Chemamata,

I have uploaded schematic for connecting Sabertooth to UNO. There is no option to use enable pin with Sabertooth, so no need for a MOSFET. But you must connect an emergency stop button -- you WILL need it!

You must configure it as "Packetized Serial, address 128". You also need to set the baud rate at 38400 -- I think you need to use the DEScribe software to do that.


----------



## chemamata (Oct 20, 2013)

OT.
Thank you very much.
I understand that the scheme is the new (still puts Roboclaw). 
Apparently not the settings I thought. Is the following.
I will need emergency stop JAJAJAJAJAJA. Surely if.
These days I am distracted with mushrooms, I like going to the mountain to look for, and now the time.
Have if I just mount the clone and electronics amount. I promise to upload pictures of the result.


----------



## markula (Oct 27, 2013)

Hi 

You are all talking about the Roboclaw controller. It cost around 125 USD. 
If you bought 2 of the BTS7960B 43A you are around 30 USD, and have 13A more power. 

So 70% cheaper, and more power. 
Or is it something i miss here ?


----------



## phaedrus (Aug 24, 2013)

OT: I trust the check went well, and good to see the latest code revision.

I'd be interested in comments on how the pushback goes for those of you with decent motors - JR, have you tried it??

I think my new controllers have arrived today so will try and fit those in the weekend if I have a moment.

MK: I'm with you but to be fair these other controllers are 'smart' devices and so will accept a range of different inputs, and offer various protections etc (from what I read). Accordingly they may have a wider appeal I guess.

In this instance I'm not sure these things are necessary but there are perhaps other cases where they're useful (or indeed someone may disagree with that view and have a valid reason why they could/should be used on this project 

P.


----------



## mizlplix (May 1, 2011)

OT has recommended the two BTS7960B 43A controllers. They are supported in his code, but he recommends you put a fan on them.

The Roboclaw may be rated less, but it is a rugged design (and to be truthful, I feel they will actually out perform under heavy loads).

So is the Sabertooth controller. (at $125 also)

Use what ever you want.

I just happened to have a Roboclaw from another project. OT was nice enough to add code for it.

Same can be said for the gyros. Mine cost $40. His were $6 each and required two. (steering balancing)

If doing another Segway, I now know to design the steering to intersect the balancing and yaw axis both. Then only one gyro need to be used.

As well as using two wheel/hub motors with their built in controllers. (More foot room and taller 20" wheels)

Miz


----------



## Ovaltineo (Jul 18, 2013)

The Roboclaw is good if you want to add wheel encoders in the future. This will make it perform consistently on different gradients -- assuming your motors have enough grunt.

The Sabertooth is a poor cousin of the Roboclaw. It doesn't support encoders, no advanced commands, and have only 7-bit resolution. Sold at the same price as the Roboclaw, it is a scam.

The BTN7960s are good on paper, but I recently found out that they are not as good as what the technical specifications say. One of mine died after a short ride on grass. With pushback enabled, it was peaking motor output as I struggled to traverse the bumpy lawn with my machine's smallish 12-inch wheels. About 5 minutes of this and one of the BTN7960s died. They are only 300 watt motors and each has a 15 amp circuit breaker in series, so continuous current would have been below 15A. I doubt if the current peaked above 30A, so it simply didn't perform to specs.

Having said that, it is cheap and relatively easy to fix (especially if you have a re-flow soldering station). So I would still recommend it for this project. Just have a spare module or chip ($4.75) in case it dies.


----------



## mizlplix (May 1, 2011)

For future reference, I have been reading up on the encoder section in the Roboclaw manual. It is quite in=depth, but somewhat confusing. 

Example: I can not find what the pulse count is per revolution. What is it looking for? My encoders are 360 PPr.

iz


----------



## markula (Oct 27, 2013)

mizlplix said:


> For future reference, I have been reading up on the encoder section in the Roboclaw manual. It is quite in=depth, but somewhat confusing.
> 
> Example: I can not find what the pulse count is per revolution. What is it looking for? My encoders are 360 PPr.
> 
> iz


Why use an encoder?

The arduino send a PPM singal to the Roboclaw to output of 5V so in no load is eksampel 30 RMP. But it is maybe uphill so it is only spinning 27 RPM. 

It is so that the Roboclaw is then sending out 5,2V and the wheel go 30 RPM. 

Is that right ?


----------



## mizlplix (May 1, 2011)

The Balance gyro tells the arduino that it is not happy, (out of balance), the Arduino "tells" the Roboclaw to rotate the two motors forwards to balance.

The Roboclaw then waits for the Arduino, which waits for the Gyro to pass the word that it is "happy" and back in balance.

The Roboclaw just keeps feeding current and assumes the motors are rotating.

With encoders, the Roboclaw "knows" the motors are working and how far and fast. 

This adds a little bit of precision and better control.

(I hope) Miz


----------



## chemamata (Oct 20, 2013)

OT.
Hello.
I'm trying to understand the connection of the Sabertooth scheme.
I do not understand the arduino pin A3.
Would you care to explain?
thanks


----------



## Ovaltineo (Jul 18, 2013)

With encoders, you'll get the same speed for the same tilt, regardless of the gradient (if the motors haven't maxed out). Without encoders (and the appropriate code), you need to lean further with increasing gradients. It is easy to over-tilt in this situation.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> OT.
> Hello.
> I'm trying to understand the connection of the Sabertooth scheme.
> I do not understand the arduino pin A3.
> ...


I've updated the schematics, check it. A3 is for measuring battery voltage so an appropriate alarm is generated by the buzzer. It has nothing to do with the Sabertooth.


----------



## chemamata (Oct 20, 2013)

ok.
thank you very much


----------



## markula (Oct 27, 2013)

Can you also support 3 LEDs for the a battery indicator ?

Like green, Yellow and red.

So you can have 5 stages.

1. Green 
2. Green/yellow
3. Yellow
4.Yellow/Red
5.Red


----------



## phaedrus (Aug 24, 2013)

markula said:


> Can you also support 3 LEDs for the a battery indicator ?


Yes, that would be reasonably straightforward.

I've not actually looked at this section of OT's code but given that he's kindly made it open under the GPL you can modify it and make it do what you want.

IMO something like this would be a good start to learning how to write some code - perhaps you could write just the indicator code, load that up and adjust as needed to suit how you want it work, then include that in the main segclone code (and become a 'hacker' in doing so 

I'm not sure it's worth reinventing something here as there are a number of googleable indicator examples around if you want some ideas about how this might work, but let us know if you get stuck with it.

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

I've just released v2.8. It fixes Sabertooth (it won't compile ) and voltage check bug (wrong #define). I've also added LED support as requested by markula.

Place a Green LED+resistor on D9, Yellow LED+resistor on D10, and Red LED + resistor on D11. Voltage levels can be set in Alarms.h -MIN_BATTERY1 to MIN_BATTERY4.

I will update schematics later.


----------



## robertholmberg (Oct 26, 2013)

Wow, you are fast and impressive when it comes to all those bits and bytes in the coding. I havent tried yet, and I cant wait for my time when I get my stuff to try it out. But now when i see the battery limits and showing, which i think i will show on a screen on my handles. But My question, is it in the program so that it can be or maybe already to turn off if you go under a level om Voltage if you are using Litium?

I mean you know that you cant drive further but if you lean it to someone and they just drive until it stops working it might be a problem in those cases. Or do I think wrong here?


----------



## Ovaltineo (Jul 18, 2013)

It is not in the code to stop or slow down the motors below a critical voltage. Doing so can be dangerous - it can throw off the passenger if it happens while going forward. Even if there is logic there to wait until it is idle, it can also be inconvenient - the battery voltage can sag under heavy load (going up a steep hill) but still ok otherwise. If you have a buzzer installed, I suggest you tell the user to stop when it beeps with critical voltage (pattern=long long long).


----------



## mizlplix (May 1, 2011)

Well, I finally got my controller back and working normal.

I am dumping the Ruggeduino and buying a standard Arduino Uno.

Reason: The Ruggeduino is not the same as a Uno. It is similar to an Uno-SMD.
It is still not recognised as an Uno.

It requires a special driver to tell Windows "Hey stupid"...."Over here, this one".

While I got it to work under a windows environment, I own a really nice 8" Android tablet. 
I planned to use it to do all of the coding and fine tuning. It is wonderfully portable and easy to use.


Problem.......There is no Android driver to tell the software that the Ruggeduino is an Uno. It will never communicate......

So I have a real Uno on order.

Back to waiting.

Miz


----------



## Ovaltineo (Jul 18, 2013)

I've just uploaded v2.9 which fixes the compilation bug in v2.8 and properly initializes the LED output pins.

I've also updated the schematics to include the optional voltage level indicator LEDs.


----------



## robertholmberg (Oct 26, 2013)

Hi,

How did it go with your BT? Is it up and running now and you can log it all on your phone while driving?

/Rob


----------



## Ovaltineo (Jul 18, 2013)

Rob,

I got the Bluetooth app running a long time ago, but I'm not happy with the binding time -- it takes a minute for the phone to bind to the Bluetooth adapter. I've put it on hold until I can find a solution. The problem might be that I'm using a platform called "Processing" which makes it much easier to develop Android apps, but it uses an old version of the Android libraries.

It is 100X much easier to make changes to the Arduino code, so I've been doing that lately. I will get back on the Android app when time permits.


----------



## chemamata (Oct 20, 2013)

OT.

One question.
To calibrate. Should we put it in balance?. Or not matter much.
thanks


----------



## Ovaltineo (Jul 18, 2013)

You should calibrate with the board and steering at the level that you want to be the idle position. Usually, this is the level position. For me, it is at about -5 degrees from level.


----------



## chemamata (Oct 20, 2013)

OK.
Thank you very much.


----------



## Centrex (Nov 24, 2013)

Hi Ovaltino
Firstly I am very impressed by all the work you have done on the segway clone.
I am only just into Arduino programming and am a little puzzled you dont seem to define what pins are used as outputs but the dwgs show 9,10,11,12 and 13.
Are these defined in the various library .h files.
All part of the learning curve.
Thanks
Cliff


----------



## chemamata (Oct 20, 2013)

OT

S.O.S. HELP

My clone-segway not calibrated.
Something I do wrong to calibrate my clone, but not it can be.
This is what appears on the monitor:

Error = 4
Gyro -3560
Error = 4
Gyro 6386
Error = 4
Gyro -3560
Error = 4
Gyro 6386
Error = 4
Gyro -3560
Error = 4
Gyro 6386
Error = 4
Gyro -3560
Error = 4
Gyro 6386
Error = 4
Gyro -3560
Error = 4
Gyro 6386
Error = 4
Gyro -3560
Error = 4
Gyro 6386
Error = 4
Gyro -3560
Error = 4
Gyro 6386
X Accel Offset 9252Y Gyro Offset 1413Y Gyro Min -3560Y Gyro Max 6386

Can you help?
thanks


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Hi Ovaltino
> Firstly I am very impressed by all the work you have done on the segway clone.
> I am only just into Arduino programming and am a little puzzled you dont seem to define what pins are used as outputs but the dwgs show 9,10,11,12 and 13.
> Are these defined in the various library .h files.
> ...


I haven't got a PC with me now, but from memory, they are LED and buzzer pins defined in SegwayClone.h. They are initialized in initAlarms in Alarms.ino.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> OT
> 
> S.O.S. HELP
> 
> ...


Check the connection to the MPU6050s. Error 4 means the Arduino cannot talk to the modules.


----------



## chemamata (Oct 20, 2013)

Thank you.
Tomorrow I will try again.


----------



## chemamata (Oct 20, 2013)

Hello.
Error 4 corrected.
A gyroscope was dead.
Now the error is 2.
In the file "alarm.h" says "noGPS. No GPS??.
You can tell me that can happen?
thanks

EDIT:

Error = 2
Gyro -2729
Error = 2
Gyro 22517
Error = 2
Gyro -2729
Error = 2
Gyro 22517
Error = 2
Gyro -2729
Error = 2
Gyro 22517
Error = 2
Gyro -2729
X Accel Offset -25058Y Gyro Offset 9894Y Gyro Min -2729Y Gyro Max 22517


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> Hello.
> Error 4 corrected.
> A gyroscope was dead.
> Now the error is 2.
> ...


Error 2 is also a connection error to the MPU6050s. Can you post a snapshot of the start of the trace (not the end)? Can you post pics of how you connected the two sensors to the Arduino?


----------



## chemamata (Oct 20, 2013)

Yes. 
Tomorrow I put the initial frame and photo mount.
thanks


----------



## Ovaltineo (Jul 18, 2013)

Look at post #114. battagae had the same error which he fixed by soldering the pins properly.


----------



## chemamata (Oct 20, 2013)

thank you very much


----------



## chemamata (Oct 20, 2013)

Well, well . I hope I explain it well ...............And google translate it correctly.
I think gyroscopes funcionana correctly. 
This is the initial reading :

WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
Gyro -4518
Gyro -5004
Gyro -4107
Gyro -3834
Gyro -3850
Gyro -4457
Gyro -4257
Gyro -4615
Gyro -4183
Gyro -4454
Gyro -4956
Gyro -4684
Gyro -4616
Gyro -3908

Try the readings are a little weird , is that they are not ensu gyroscopios workplace, but I think they are working properly .
BUT . Now what are the drivers do not work . I think it is problem of configuration and programming .
Let me explain.
According to post # 124 OT . I set the option Sabertooth # 5 .Right. The Segway - clone does absolutely nothing.
According to the " monitor" all is well. The Sabertooth does not know. Change settings to option 4 . Well , the engines make noise. They do not move , but make noise (communication) , it's something.
I understand that now the problem is that the Sabertooth does not "understand " the Arduino.
I suppose it's code problem .Ovaltineo and tell me if I'm right , and if you do well to review the code.
thanks


----------



## Ovaltineo (Jul 18, 2013)

I checked the code - it looks OK. 

After setting option #5, you need to set the baud rate to 38400. Did you do that using the DEScribe software?


----------



## chemamata (Oct 20, 2013)

When I bought the Sabertooth mo coming any software.


----------



## chemamata (Oct 20, 2013)

ok.*
I have already downloaded.
Tomorrow I try.
thanks


----------



## chemamata (Oct 20, 2013)

Hello.
No way.

I connect the Sabertooth smoothly. We change the baud to 38400. But there is no way to change the address to 128. 
It is connected by the address 129.
In your code:
File motors:
line 188. Put address 0x7F (127)
File motors.h
line 71. Put address 0x80 (128).
No conflict?
If you change the two sites by 0x81 (129) work?
thanks


----------



## chemamata (Oct 20, 2013)

Hello.
I changed the addresses 0x81 and does not work.
This is the beginning of "monitor" mode run.

WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
ACCEL: -39.39 GYRO: 0.00 BOARD ANGLE: -2.01 STEER ANGLE: 6.58 MOTOR: -1.63 LEFT: -13 RIGHT: 9
ACCEL: -1.96 GYRO: 0.00 BOARD ANGLE: -1.63 STEER ANGLE: 8.98 MOTOR: -17.51 LEFT: -20 RIGHT: -1
ACCEL: -42.96 GYRO: 0.00 BOARD ANGLE: -1.72 STEER ANGLE: 9.81 MOTOR: -20.00 LEFT: -20 RIGHT: -2
ACCEL: -53.34 GYRO: 0.00 BOARD ANGLE: -2.47 STEER ANGLE: 10.11 MOTOR: -20.00 LEFT: -20 RIGHT: -2
ACCEL: 12.31 GYRO: 0.00 BOARD ANGLE: -2.91 STEER ANGLE: 10.20 MOTOR: -20.00 LEFT: -20 RIGHT: -2
ACCEL: 50.61 GYRO: 0.00 BOARD ANGLE: -3.55 STEER ANGLE: 10.28 MOTOR: -20.00 LEFT: -20 RIGHT: -2
ACCEL: 63.81 GYRO: 0.00 BOARD ANGLE: -5.60 STEER ANGLE: 10.30 MOTOR: -20.00 LEFT: -20 RIGHT: -1
ACCEL: -24.20 GYRO: 0.00 BOARD ANGLE: -2.25 STEER ANGLE: 10.32 MOTOR: -20.00 LEFT: -20 RIGHT: -1
ACCEL: 4.53 GYRO: 0.00 BOARD ANGLE: 1.22 STEER ANGLE: 10.34 MOTOR: -18.53 LEFT: -20 RIGHT: 0
ACCEL: 18.20 GYRO: 0.00 BOARD ANGLE: 1.04 STEER ANGLE: 10.33 MOTOR: -9.25 LEFT: -20 RIGHT: 8
ACCEL: 11.76 GYRO: 0.00 BOARD ANGLE: 3.58 STEER ANGLE: 10.32 MOTOR: 7.32 LEFT: -10 RIGHT: 20
ACCEL: 39.99 GYRO: 0.00 BOARD ANGLE: 4.48 STEER ANGLE: 10.35 MOTOR: 20.00 LEFT: 1 RIGHT: 20


But the motors do not move


----------



## Ovaltineo (Jul 18, 2013)

Did you set the address to 0x81 in Sabertooth or did you modify #define SABERTOOTH_ADDRESS? Or did you do both (this is the correct thing to do)?

I have attached the part of the Sabertooth manual that specifies how to set the address. It clearly has a setting for 128 (0x80). You can try this setting or modify #define SABERTOOTH_ADDRESS in Motors.h to match the address that you have set.


----------



## chemamata (Oct 20, 2013)

If I put the address 128 (off-off-on-on-on-on) The sabertooth ignores anything.
If I put the address 128. (off-off-on-on-on-on), but the software will put the 129 (0x81). The Sabertooth does "something".
If I have a video and upload it.
thanks


----------



## chemamata (Oct 20, 2013)

Have if I do well.
I changed the batteries by a power supply.
The engines have changed the two bulbs in my car.

https://www.dropbox.com/s/9bl7qv3i55b9wxq/Sabertooth.AVI

You see, something works, but does not regulate. 
O on or off. Not regulated.If I put the code 0x80 (128).
Does absolutely nothing.
thanks


----------



## Ovaltineo (Jul 18, 2013)

Plese run the following sketch and report the results.

```
#include <SoftwareSerial.h>
#define SABERTOOTH_ADDRESS 0x80
#define M1_FORWARD 0
#define M1_BACKWARD 1
#define M2_FORWARD 4
#define M2_BACKWARD 5
// software serial pins for non-mega boards
#define SOFT_TX_PIN 6   // connect to S1 pin
#define SOFT_RX_PIN 5   // do not connect
 
SoftwareSerial Serial1(SOFT_RX_PIN, SOFT_TX_PIN); // RX, TX
 
void sendCommand(byte command, int param)
{
 byte packet[4];
 packet[0] = SABERTOOTH_ADDRESS;
 packet[1] = command;
 packet[2] = param;
 packet[3] = (packet[0]+packet[1]+packet[2]) & 0x7F;
 Serial1.write(packet, sizeof(packet));
}
void setSpeedMotor1(int speed)
{
 if (speed >= 0)
  sendCommand(M1_FORWARD, speed);
 else
  sendCommand(M1_BACKWARD, -speed);
}
void setSpeedMotor2(int speed)
{
 if (speed >= 0)
  sendCommand(M2_FORWARD, speed);
 else
  sendCommand(M2_BACKWARD, -speed);
}
void initMotors(void)
{
 Serial1.begin(38400);   // initialize serial port
 //stop motors
 controlMotors(0, 0);  
}
 
void controlMotors(int speedL, int speedR) 
{
 setSpeedMotor1(speedL);
 setSpeedMotor2(speedR);
}
void setup()
{
 Serial.begin(115200);
 initMotors();
}
static int speed = 0;
static int increment = 1;
static int count = 0;
void loop()
{
 speed = speed + increment;
 if (speed >= 127)
  increment = -1;
 else if (speed <= -127)
  increment = 1;
 Serial.print("Speed = ");
 Serial.println(speed);
 controlMotors(speed, speed);
 delay(500);
}
```


----------



## chemamata (Oct 20, 2013)

The blots.
I think I got it.
Let me to do some more tests


----------



## chemamata (Oct 20, 2013)

OK. 
I've gotten a 12v engine. small for testing.
With the 0x80 address. NOTHING. Only account.
With the 0x81 address. Account and moves the motor.
from 25 to -25 does nothing. if after accelerating and changing the direction of rotation. etc. ..


----------



## Ovaltineo (Jul 18, 2013)

So, it works from +25 to +127 and -25 to -127?


----------



## chemamata (Oct 20, 2013)

Yes.
But the software address 129.
the Sabertooth address 128.
Incomprehensible, but true


----------



## chemamata (Oct 20, 2013)

Hello
I completed the test code you sent on Segway-clone. Nothing small engine and car bulbs.With the address 0x80, NOTHING.With the address 0x81 Clone enpieza to spin, first slowly and then accelerates. First one way and then the other.This may be because the engines mount one so I connected with reversed polarity.If I connect either polarity clone goes forward and backward accelerating and braking.I understand that this ALMOST everything right. But understand that you can not pass


----------



## Ovaltineo (Jul 18, 2013)

So it works with 0x81. Strange, but in one part of the manual, it does say

```
[LEFT][FONT=Times-Roman]The packet format for the Sabertooth consists of an address byte, a command byte, a data byte[/FONT]
[FONT=Times-Roman]and a seven bit checksum. [B]Address bytes have value greater than 128[/B], and all subsequent bytes[/FONT][/LEFT]
[FONT=Times-Roman]have values 127 or lower. [/FONT]
```
This contradicts the part where the address range is from 128 to 135. So, the documentation is strange too.
Using address 0x81, I suggest you continue as if everything is working. Load the SegwayClone application and check if it is behaving as expected. You will need to increase MOTOR_MAX in Motors.h. The maximum value for MOTOR_MAX is 127 for the Sabertooth.


----------



## chemamata (Oct 20, 2013)

Hello.
Nothing. No way.
The Clone-Segway does not work.
When I do the test you sent, it does perfectly. When I put in "calibrate" mode, so does good.
But when I put in "RUN" mode, it's like gyroscopes fail to operate, or the information does not get the Sabertooth.I copy some "monitor" in "run" mode.

WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
ACCEL: 10.39 GYRO: 0.00 BOARD ANGLE: -1.14 STEER ANGLE: -0.05 MOTOR: -5.67 LEFT: -5 RIGHT: -5
ACCEL: -33.77 GYRO: 0.00 BOARD ANGLE: 0.32 STEER ANGLE: -0.09 MOTOR: -4.60 LEFT: -4 RIGHT: -4
ACCEL: 38.69 GYRO: 0.00 BOARD ANGLE: -1.30 STEER ANGLE: -0.13 MOTOR: -6.53 LEFT: -6 RIGHT: -6
ACCEL: -5.74 GYRO: 0.00 BOARD ANGLE: -4.95 STEER ANGLE: -0.15 MOTOR: -27.58 LEFT: -27 RIGHT: -27
ACCEL: 54.26 GYRO: 0.00 BOARD ANGLE: -8.54 STEER ANGLE: -0.11 MOTOR: -50.00 LEFT: -49 RIGHT: -50
ACCEL: -29.59 GYRO: 0.00 BOARD ANGLE: -11.52 STEER ANGLE: -0.16 MOTOR: -50.00 LEFT: -49 RIGHT: -50
ACCEL: 57.74 GYRO: 0.00 BOARD ANGLE: -10.24 STEER ANGLE: -0.16 MOTOR: -50.00 LEFT: -49 RIGHT: -50
ACCEL: 72.55 GYRO: 0.00 BOARD ANGLE: -9.91 STEER ANGLE: -0.18 MOTOR: -50.00 LEFT: -49 RIGHT: -50
ACCEL: -65.06 GYRO: 0.00 BOARD ANGLE: -8.09 STEER ANGLE: -0.20 MOTOR: -50.00 LEFT: -49 RIGHT: -50
ACCEL: -64.56 GYRO: 0.00 BOARD ANGLE: -5.52 STEER ANGLE: -0.20 MOTOR: -50.00 LEFT: -49 RIGHT: -50
ACCEL: 49.78 GYRO: 0.00 BOARD ANGLE: -5.64 STEER ANGLE: -0.25 MOTOR: -50.00 LEFT: -49 RIGHT: -50
ACCEL: 67.95 GYRO: 0.00 BOARD ANGLE: -1.39 STEER ANGLE: -0.25 MOTOR: -50.00 LEFT: -49 RIGHT: -50
................................
.................................

GYRO: 0.00 ????

It is possible?.I think there is a problem here.
In "CALIBRATE" reads the gyro well. But in "RUN" does not read well Gyroscope

The clone moves as and where you want.
Sometimes going forward. Reset the Arduino.
Now slowly spins right. Reset the Arduino.
Now fast backward. Reset the Arduino.
Now fast forward. Reset
..........
As you want.

thanks


----------



## Ovaltineo (Jul 18, 2013)

Here's what I think.
1. DIP switch #4 in your Sabertooth has a solder link (or open), hence hardcoding it to "1". You can verify this by trying other addresses (and changing #define SABERTOOTH_ADDRESS to match). I am guessing that only odd numbers would work.
2. You were moving the sensors during calibration. This will make the gyro insensitive to movements.

Upload the application in CALIBRATE mode. Make sure the sensors are *completely still* during the calibration (about 2 minutes). Leave the USB cable plugged in. When finished, make sure the sensors are still *completely still *then upload the application in RUN mode. 

Move the board sensor. Is gyro value changing now?

It is normal for the motors to seem to runaway during bench testing. This only happens when the wheels are not connected or off the ground. As long as the motors eventually spin in the forward direction while the board sensor is tilted forward, and the reverse direction while the board board sensor is tilted backward, then it is good. It will take some time for the motor to reverse direction during bench testing. This is normal.

Another thing to remember is that during the start of RUN mode, it will wait for the board to level before it starts moving the motors. When you over tilt the board, it will stop the motors and wait for it to level before running again.


----------



## chemamata (Oct 20, 2013)

MMmmmm
I'm almost ashamed to say.
I think the switch to the 128 direction, made ​​him always wrong.
I see from "inside" the pcb and instinctively put # 1 on the left, and it is right.
Tomorrow I check. 
It would be a little embarrassed.
Failure rookie.


----------



## Ovaltineo (Jul 18, 2013)

Some good news - I got the Android Bluetooth problem sorted out. I've attached an image of what the app looks like.

The bad news is that registration with the Google store is $25. Well, the real problem is that I'm a tightass  so I might have to put a cost on the app. Let me know how many would be buying this app, so I can divide $25 with this number. So 5 people would mean $5. It won't count if you haven't posted before in this thread - so don't create fake account guys !

Be aware that you need a Bluetooth module like this http://www.ebay.com/itm/Wireless-Se...178?pt=LH_DefaultDomain_0&hash=item2ec80c03a2.


----------



## chemamata (Oct 20, 2013)

OT.
Do not quite understand what you mean. Google Translate does what he can.
For example the word "tightass" not translated, and I lose.
I understand something and ask about charges collaboration.For me there is no problem.
Tell me how do you get the $ 5.I do not understand very well that application is. Something to collect data on the phone right?.
I can not find much use, but ........
See more useful pressure meter on each foot. and weight difference to rotate the clone. (eg)
The bluetooth module I have other jobs.


----------



## Ovaltineo (Jul 18, 2013)

I don't want to spend a little of my own money, so I'm a tight ass - culo apretado . Hmm, maybe it doesn't translate well in Spanish.

It is a nice to see those telemetry data on the phone, like the instruments in a car, don't you think? And you can change the P and D values without having to re-upload the firmware everytime.


----------



## chemamata (Oct 20, 2013)

Ha ha ha ha ha ha ha ha ha (laughter) ............................. (laughs)
I suppose one your expression. I understand that you're hard up.
Me too, I've been out of work more than 2 years. damn Crisis
Well, my account with $ 5.
P and D??
P = power
D = direction.
If so, that alone was worth it.
Now as you say the command you


----------



## phaedrus (Aug 24, 2013)

Ovaltineo said:


> The bad news is that registration with the Google store is $25.


OT, well done on that application it looks good.

FWIW I refuse to use the Google Store for a number of reasons, and will only install apps directly from the producer to my Android device.

I mention this not to take a swing at Google, but to say that it works fine simply installing from a *.apk file _sans_ store - so if you had a mind you could simply release that file here and people could access it accordingly.

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

Thanks P. I'm glad to say that the application looks like a pro. 
I'm reading about self-signed certificates as we speak and should be able to release directly here without paying $25 to Google.


----------



## pedro59 (Dec 4, 2013)

Hello Ovaltine, Hello all,

I'm french excuse my bad english
I m newbie and for hobby i want to build a segway like. i have seen your tread. i'm really intrested, but i know nothing about electronic, and coding. for building the chassis its not a problem but the rest ouch. can you help me ?

thank you


----------



## Ovaltineo (Jul 18, 2013)

pedro59,
To be brutally honest, this project is not for electronic and Arduino beginners. From my short experience here, you and I will get frustrated with very simple problems that takes days to resolve. Without any electronic and programming skills, this project is doomed to fail. I suggest looking for a local friend who can assist you.


----------



## chemamata (Oct 20, 2013)

Error -11
Hello.
No way. 
Everything is as it should be.To test softare you sent me, what change for up to 50 and -50. He could not go to clone how fast will (ha ha ha ha ha laughs). Makes perfect.
The calibration makes it perfect and put "run" mode .................
This is what happens.
I begin with the "Emergency Stop" holdWhen he lost the stop is when it gives the error -11.

What is the error -11

WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
ACCEL: 5.51 GYRO: 0.00 BOARD ANGLE: 1.23 STEER ANGLE: 3.84 MOTOR: 3.49 LEFT: -3 RIGHT: 10
ACCEL: -4.13 GYRO: -8.89 BOARD ANGLE: 3.18 STEER ANGLE: 5.16 MOTOR: 19.99 LEFT: 10 RIGHT: 29
ACCEL: 38.20 GYRO: 0.00 BOARD ANGLE: 1.81 STEER ANGLE: 5.67 MOTOR: 36.91 LEFT: 26 RIGHT: 46
ACCEL: -20.35 GYRO: 0.00 BOARD ANGLE: 1.53 STEER ANGLE: 5.86 MOTOR: 50.00 LEFT: 39 RIGHT: 50
ACCEL: -19.85 GYRO: 0.00 BOARD ANGLE: 2.14 STEER ANGLE: 5.96 MOTOR: 50.00 LEFT: 39 RIGHT: 50
ACCEL: 11.68 GYRO: 0.00 BOARD ANGLE: 2.90 STEER ANGLE: 5.97 MOTOR: 50.00 LEFT: 39 RIGHT: 50
ACCEL: -3.86 GYRO: 0.00 BOARD ANGLE: 1.04 STEER ANGLE: 5.99 MOTOR: 50.00 LEFT: 39 RIGHT: 50
Error = -11
Error = -11
Error = 2
Error = 2
Error = -11
ACCEL: -73.11 GYRO: 0.00 BOARD ANGLE: 2.13 STEER ANGLE: 9.73 MOTOR: 20.28 LEFT: 3 RIGHT: 37
ACCEL: -14.60 GYRO: 0.00 BOARD ANGLE: -0.41 STEER ANGLE: 8.47 MOTOR: 27.31 LEFT: 12 RIGHT: 42
Error = 2
Error = -11
Error = 2
ACCEL: 64.74 GYRO: 0.00 BOARD ANGLE: 3.45 STEER ANGLE: 10.87 MOTOR: 49.48 LEFT: 30 RIGHT: 50
Error = -11
Error = 4

I forgot.The direction of the Sabertooth is 128. all right


----------



## mizlplix (May 1, 2011)

So, I finally get time to work on the Segway (like) vehicle. 

I examine the new replacement board I got and it is not an "Arduino" either. It is some back door, clone that has some extra pins on it....Grrrr

It has all of the normal Uno pins plus three extras. They are labeled SCL and SDA....and no label...

Thats all I need. More variables to mess with...not!

So, I throw it in the stock bin and go try to find a real Arduino Uno board. The trouble is that everyone sells them as if the copies ARE an Arduino.
And at $17.00Each, it is almost too much trouble to send back (I pay return shipping).

My quest goes on.

Miz


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> Error -11
> Hello.
> No way.
> Everything is as it should be.To test softare you sent me, what change for up to 50 and -50. He could not go to clone how fast will (ha ha ha ha ha laughs). Makes perfect.
> ...


Those errors are from sensor connection. The accel going from -4 to 38 then -20 and the gyro jumping from 0 to -8.89 then back to 0 are signs that things are not healthy. 

Is this during bench test (wheels off ground) or during ground test? 

Do not release the emergency stop while the system is running. Releasing it while the motor outputs are high (50 in this case) will mean a sudden rush of current which upsets your system. Even if you didn't get errors, this is dangerous. Use emergency stop only to stop. To re-enable, turn of the power, release the emergency stop and turn on the power.

I think you also have a noisy power to the Arduino. Can you please take pictures of your components and connections? Include switches and DC-to-DC converter, sensors, arduino, sabertooth, motors.


----------



## Ovaltineo (Jul 18, 2013)

mizlplix said:


> So, I finally get time to work on the Segway (like) vehicle.
> 
> I examine the new replacement board I got and it is not an "Arduino" either. It is some back door, clone that has some extra pins on it....Grrrr
> 
> ...


Miz, I don't really understand why you have to replace the Ruggeduino. It works like an UNO and the code here supports it. Perhaps you should use a PC instead of an Android tablet to program & monitor it.


----------



## chemamata (Oct 20, 2013)

OT.
If you have used this photo that I found


----------



## cyclone (Dec 8, 2013)

Hello Seniors, i am new here and found this site with your thread and really needed help with my project. I have been with my 6 weeks now struggling with my project and cant find a way to get a code for my segway clone. most youtube videos that i have ask for codes seems to neglect and reject my inquiries. My project is all done and complete but the code. These are my components. 

Arduino Uno R3, Sabertooth 2x25, MPU6050, Kill cord, engage switch with 10k linear pot for the steering.

Just like i said, i am all wired and connected following the schematic that i acquire with someone. I have the Arduino environment downloaded already to my pc. All i need is the program sketch for my set up. To be honest, this is the only lacking with my ability to finish this project. I have been hearing about the Kalman Filter and PID. I also already downloaded the library of the Sabertooth 2x25 from dimentionsengineering website.

Can you or someone point me in the right direction? or someone can help me with the sketch...? thanks...


----------



## chemamata (Oct 20, 2013)

In post # 1 of this thread. Ovaltineo friend has schemes and soft required.
I encourage


----------



## mizlplix (May 1, 2011)

O.T. has posted his sketch version here:
http://www.diyelectriccar.com/forums/attachment.php?attachmentid=17421&d=1384518776


He even has support for your selection of equipment here:
http://www.diyelectriccar.com/forums/attachment.php?attachmentid=17424&stc=1&thumb=1&d=1384518892


There are the needed instructions on this page:
http://www.diyelectriccar.com/forums/showthread.php/ovaltines-segway-clone-89471.html

AND in the README in the sketch.

Items must be turned on and off according to your need and equipment. Then the gyro zeroed, then calibration turned off , then the motor power set up at the last step.

If all goes well, it will function, but you will have to fine tune the parameters for the board to balance as conditions and equipment varies.

Miz


----------



## cyclone (Dec 8, 2013)

Will check for the links, i noticed the version for the arduino is r2. Mine is r3, is there a going to be a problem if i downloaded the sketch on my r3? And looks like i needed 2 mpu6050 instead of one... one is for the tilt and one is for the steering. Looks awesome to me instead of linear pot... thanks


----------



## chemamata (Oct 20, 2013)

Well, you can say no more.
I know you can set everything in SegwayClone.h. But as the potentiometer is connected.
Ovaltineo if you have help.


----------



## cyclone (Dec 8, 2013)

chemamata said:


> Well, you can say no more.
> I know you can set everything in SegwayClone.h. But as the potentiometer is connected.
> Ovaltineo if you have help.


 I was starting to scratch my head with the zip file containing multiple sketch. what exactly i need to do with these? do i only need to load segway clone sketch and everything will work after these? or needed to do something more with other program? on the read me file, i like the way it mentioned that the sketch supports one mpu6050 for tilt and steering but i prolly going to use two for one of each function. hoping for all your patience, just like i said, am new to arduino thing... thanks


----------



## cyclone (Dec 8, 2013)

verified the sketch segway clone, its giving me multiple error... anyone can point me whats wrong? thanks...


----------



## chemamata (Oct 20, 2013)

If the "tools" tab you've chosen well the "card" and "serial port" should not give any problems.


----------



## cyclone (Dec 8, 2013)

chemamata said:


> If the "tools" tab you've chosen well the "card" and "serial port" should not give any problems.


 yup, i am using the correct serial port. it is only when i verify the sketch before uploading. it shows multiple error...


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> OT.
> If you have used this photo that I found


1. The sensors should be level with the X-axis parallel to the ground and pointing to the front of the vehicle. If you haven't done this, then you need to calibrate again.

2. The board sensor should be fixed to the board and the steering sensor to the steering shaft.

3. Are those round pins that plug into the square Arduino ports? It they are the same ones that I have, then they are not tight fitting and could break the connection as the board jerks when the motors kick in.


----------



## Ovaltineo (Jul 18, 2013)

cyclone said:


> yup, i am using the correct serial port. it is only when i verify the sketch before uploading. it shows multiple error...


When you loaded the SegwayClone.ino file, does it load the other files in multiple tabs? Can you post the errors that you are getting?


----------



## chemamata (Oct 20, 2013)

OK.
I'll put them to good and welding cables.
thanks


----------



## cyclone (Dec 8, 2013)

Ovaltineo said:


> When you loaded the SegwayClone.ino file, does it load the other files in multiple tabs? Can you post the errors that you are getting?





> steer_accel*=*getSteerAccel();


it says, was not declared in this scope...


----------



## cyclone (Dec 8, 2013)

Ovaltineo said:


> When you loaded the SegwayClone.ino file, does it load the other files in multiple tabs? Can you post the errors that you are getting?


i am only loading the segway clone.ino file... can you correct me on this, you have mentioned it should be on multiple files when loading? how do you do this? thanks...


----------



## cyclone (Dec 8, 2013)

Ovaltineo said:


> When you loaded the SegwayClone.ino file, does it load the other files in multiple tabs? Can you post the errors that you are getting?


i think i got what you mean. i have manage to put the whole file to the library and loaded the sketch with multiple files. now, the problem is this when i verify it. i am now getting this error...



> EEPROM.write(address, low);


EEPROM was not declared in this scope...


----------



## Ovaltineo (Jul 18, 2013)

Did you install the latest Arduino IDE? I'm using v1.0.5. When you go to Sketch - Import Library, do you see EEPROM in the list? If not, I would suggest that you re-install the Arduino IDE.


----------



## cyclone (Dec 8, 2013)

Ovaltineo said:


> Did you install the latest Arduino IDE? I'm using v1.0.5. When you go to Sketch - Import Library, do you see EEPROM in the list? If not, I would suggest that you re-install the Arduino IDE.


Yup, i do have the latest version. Can you re check and verify the sketch if you dont get the same error msg. I have included pictures for reference... thanks


----------



## Ovaltineo (Jul 18, 2013)

cyclone said:


> Yup, i do have the latest version. Can you re check and verify the sketch if you dont get the same error msg. I have included pictures for reference... thanks
> 
> http://s133.photobucket.com/user/de...45883394499_1066368194_n_zpse457b05d.jpg.html
> http://s133.photobucket.com/user/de...345883634505_145818357_n_zps1f03a089.jpg.html


OK, I have managed to replicate your problem. You have accidentally added SegwayClone as a library. To fix this (in Windows 7), go to C:\Users\<user>\Documents\Arduino\libraries and delete the SegwayClone directory. After this, just use File-Open to open SegwayClone.ino. This should compile properly now. If you have uncommented #define POT_STEERING, then you will get a different compile error. I have fixed this in v3.0.


----------



## Ovaltineo (Jul 18, 2013)

In post #1, I have released v3.0 of SegwayClone. It supports the HC06 "linvor" Bluetooth transceiver module like this http://www.ebay.com/itm/Wireless-Se...178?pt=LH_DefaultDomain_0&hash=item2ec80c03a2. This will allow the CloneConsole Android application to connect to SegwayClone.

There is also support for two TC74 temperature sensors which connect via the I2C bus. This sensor comes in several model numbers as it comes with several addresses -- get the TC74A0 and TC74A2. If you get a different model, change the address in TC74.h.

I have also released CloneConsole Android app.


----------



## cyclone (Dec 8, 2013)

Ovaltineo said:


> OK, I have managed to replicate your problem. You have accidentally added SegwayClone as a library. To fix this (in Windows 7), go to C:\Users\<user>\Documents\Arduino\libraries and delete the SegwayClone directory. After this, just use File-Open to open SegwayClone.ino. This should compile properly now. If you have uncommented #define POT_STEERING, then you will get a different compile error. I have fixed this in v3.0.


 I have manage to delete the old files on my documents and downloaded your new version 3.0. Upon loading the sketch segwayclone.ino and verify the sketch, now it gives me this error...


----------



## Ovaltineo (Jul 18, 2013)

Well, I don't think you followed my instructions. You used Sketch - File Add, instead of File - Open. Really, opening an Arduino file/project shouldn't be this hard ! Don't people use File - Open to open files anymore??


----------



## chemamata (Oct 20, 2013)

When you unzip the file SegwayClone_v3.0.zip appear 20 files.When you open the segwayclone.ino must be in the same directory as the other. The 20 files in the same directory. This directory must have the same name "segwayclone".Opening with the Arduino IDE segwayclone.ino file. They have many tabs appear as files in the directory (20).


----------



## Ovaltineo (Jul 18, 2013)

I've updated the schematics in post #1 to include HC06 Bluetooth module and TC74 temperature sensors.


----------



## cyclone (Dec 8, 2013)

Ovaltineo said:


> Well, I don't think you followed my instructions. You used Sketch - File Add, instead of File - Open. Really, opening an Arduino file/project shouldn't be this hard ! Don't people use File - Open to open files anymore??


I did also do that procedure. I dont know why? But whenever i open different files other than yours it loads and verify ok. If i can ask for ur patience can you make a how to youtube video that i can watch how you do it from opening the zip file till it loads and verify if it dont give u error... thanks hoping you guys get easy on me...lol appreciate all the help...


----------



## cyclone (Dec 8, 2013)

chemamata said:


> When you unzip the file SegwayClone_v3.0.zip appear 20 files.When you open the segwayclone.ino must be in the same directory as the other. The 20 files in the same directory. This directory must have the same name "segwayclone".Opening with the Arduino IDE segwayclone.ino file. They have many tabs appear as files in the directory (20).


I did also do that procedure. I dont know why? But whenever i open different files other than yours it loads and verify ok. If i can ask for ur patience can you make a how to youtube video that i can watch how you do it from opening the zip file till it loads and verify if it dont give u error... thanks hoping you guys get easy on me...lol appreciate all the help


----------



## cyclone (Dec 8, 2013)

chemamata said:


> When you unzip the file SegwayClone_v3.0.zip appear 20 files.When you open the segwayclone.ino must be in the same directory as the other. The 20 files in the same directory. This directory must have the same name "segwayclone".Opening with the Arduino IDE segwayclone.ino file. They have many tabs appear as files in the directory (20).


here is the video of what i did and the error after loading...
http://youtu.be/-w46JW4QO1E


----------



## Ovaltineo (Jul 18, 2013)

In your video, you still did not use File-Open . Why?????????

I can see that SegwayClone is again in your library. Remove it as per post #208. Make sure it doesn't show on list with the other libraries. If it still does, uninstall Arduino IDE and re-install it. Do NOT add SegwayClone as a library.

When it is no longer in the library list, use File-Open (do not click any other shortcuts buttons) to load SegwayClone.ino.


----------



## cyclone (Dec 8, 2013)

Ovaltineo said:


> In your video, you still did not use File-Open . Why?????????
> 
> I can see that SegwayClone is again in your library. Remove it as per post #208. Make sure it doesn't show on list with the other libraries. If it still does, uninstall Arduino IDE and re-install it. Do NOT add SegwayClone as a library.
> 
> When it is no longer in the library list, use File-Open (do not click any other shortcuts buttons) to load SegwayClone.ino.


Lol...epic fail...


----------



## cyclone (Dec 8, 2013)

I finally got it now. verified it, it compiles and it loads... I found the problem, i think windows 8.1 users will have this problem. if you can make a note on your list that in order to open the zip file.
here is what i did:
1.open zip file, save to my downloads folder.
2.open folder, double click on SegwayClone folder.
3.as of your new version, there are now 20 arduino files (.ino), h files and read me file all together.
4.here is the tricky part for to be able to load all the files together. double click on every arduino files (.ino) and it will promt a message, "in able to open file it has to be in a folder". click cancel on every file you open then close the IDE window. After that do the same thing, double click on every h file and everytime it open just close the window. disregard read me file...
5.here is the last part, open the SegwayClone Arduino (.ino) file again for the last time, there on a new window of Arduino IDE you'll see all the files altogether... 
THIS TIME, you can now verify it, compiled with no error...

Took me hours to figure this out. This only happens with computers with Windows 8.1, windows 8 users might wanted to check yours if this is the same issue when opening files... thanks again...


----------



## cyclone (Dec 8, 2013)

Here is the pin set up for Sabertooth 2x25 users. 38400bps rate per Ovaltinies post...


----------



## mizlplix (May 1, 2011)

To everyone reading this thread:
_____________________________________________

This is a very technical subject and thereby hard to understand.

Some languages other than English do not always have the words to convey a true meaning of exactly what is intended.

When using a translator, it becomes even more difficult.

In some languages, the sentence structure is reversed from English and when translated that way has a different meaning.

My point is that sometimes there is never going to be a way to get things correct. Sorry but true, there is always going to be a communication block and no solution to a problem.

It is not fair to O.T. to expect him to solve every problem given this language/idea barrier.

Sincerely, Miz


----------



## chemamata (Oct 20, 2013)

MIz.
I agree with you that the language is a barrier. ........................... sometimes insurmountable.
But only sometimes. For politicians are not understood. The rest of the world does pretty well.
I also agree with you that no expert but, if I have some knowledge of what you have in hand.
BUT, I think you're not the one for you OT insuar tien because no help, or tired, or whatever.
OT I think does an excellent job. helping those in need.I guess if someone is passed, OT will send a private message to tell.

This world would suck if people who can not share the knowledge with others.

OT. and follows good person.


ESPAÑOL

MIz.

Estoy de acuerdo contigo en que el idioma es una barrera. ......................a veces insalvable. Pero solo a veces. Para no entenderse estan los politicos. El resto del mundo lo hace bastante bien.

Tambien estoy de acuerdo contigo en que aunque no experto, si hay que tener nociones de lo que tienes entre manos.

PERO, creo que no eres quien para insuar que OT no tien porque ayudar, o que se cansa, o lo que sea.

Creo que OT hace una labor excelente. ayudando a quien lo necesita.
Supongo que si alguien se pasa, OT le enviará un mensaje privado para decirle.

Este mundo sería una mierda si las personas que saben no comparten el saber con los demás.

OT. sigue así de buena persona.


----------



## chemamata (Oct 20, 2013)

Cyclone.

Sasbertooth 2 x 25

Mode paquetin: 1, 2 -> OFF, OFF.
38400 baud and address 128:3,4,5,6 pin -> ON, ON, ON, ON.

Be careful since you look part. I did it wrong at first. (rookie mistake) and now I put almost backwards.


----------



## cyclone (Dec 8, 2013)

chemamata said:


> Cyclone.
> 
> Sasbertooth 2 x 25
> 
> ...


Omg, this is another question that i am going to ask again. On dimensionengineering website 38400 Baud had my picture for this set up. Where and what exactly this set up works with?. Kindly verify this to me cause am about to finish mine with all the wirings connected


----------



## cyclone (Dec 8, 2013)

mizlplix said:


> To everyone reading this thread:
> _____________________________________________
> 
> This is a very technical subject and thereby hard to understand.
> ...


Should be alright, homosapiens does have a wide complexity of knowledge. We understand things even it is not written nor spoken. Common sense as what they say. There are difficulties sometimes, frustrations arises but in the end it will be solved no matter what... i have no problem asking for question and ask more if i dont get it. That is what communication is all about


----------



## cyclone (Dec 8, 2013)

chemamata said:


> Cyclone.
> 
> Sasbertooth 2 x 25
> 
> ...


I saw what you mean... good point there. I had my picture set up for simplified serial 38400 baud. And verified yours as Packetized Serial address 128 as per mentioned in the sketch... thanks...


----------



## chemamata (Oct 20, 2013)

Get off the "describes" software and documentation from here:
http://www.dimensionengineering.com/info/describe
In this documentation reads:
"Next, you will need to put the device into a describe-mode support.For Syren / Sabertooth, the DIP switch settings are:1 and 2 OFF (Serial Packet mode)4, 5, and 6 ON (address 128, optional but recommended)
For Kangaroo, the DIP switch setting is:......... "
Sabertooth connect to the PC. and you'll see.


----------



## cyclone (Dec 8, 2013)

chemamata said:


> Get off the "describes" software and documentation from here:
> http://www.dimensionengineering.com/info/describe
> In this documentation reads:
> "Next, you will need to put the device into a describe-mode support.For Syren / Sabertooth, the DIP switch settings are:1 and 2 OFF (Serial Packet mode)4, 5, and 6 ON (address 128, optional but recommended)
> ...


Awesome!!! Thanks for the info...


----------



## mizlplix (May 1, 2011)

Just posted this morning.
http://www.diyelectriccar.com/forum...oter-only-1400-91668.html?p=373125#post373125

Likely to be moved to the classified section though.

$1,400 + shipping from China. Kinda pricey for most of us.

Miz


----------



## chemamata (Oct 20, 2013)

As if.
A lot of money for me too.
I'm recycling a wheelchair got.After some problems with the Chinese, I finally have come to the engine drivers.
Sabertooth also wanted to recycle, but I have not been able. 
I guess with these drivers (BTS7960) will not have many problems.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> As if.
> A lot of money for me a too.
> I'm recycling a wheelchair got.After some problems with the Chinese, I finally have come to the engine drivers.
> Sabertooth also wanted to recycle, but I have not been able.
> I guess with these drivers (BTS7960) will not have many problems.


I had the impression that the Sabertooth was working after working out that you got DIP switch reversed. Something else wrong with it?


----------



## chemamata (Oct 20, 2013)

The usual.
The "test.ino" does well. Calibration is done right. But the "Run" mode does nothing. 
Is something weird. Something very weird.
At the moment I park and I'll stick with the 7960. The first thing to work.
I'm already desperate means (jajajajajajaja, laugh).


----------



## Ovaltineo (Jul 18, 2013)

Are you still getting errors? Please post SegwayClone.h and Motors.h. Also, post photos of the position if the two sensors during calibration.


----------



## chemamata (Oct 20, 2013)

Although I have changed the drivers for the motors, do not worry, as soon as they run well and enjoy a little bit, I return with the sabertooth. You have to make it work with the Sabertooth and the software is perfected as much as possible.
As not let me attach extensions .h, the renamed a do.


----------



## chemamata (Oct 20, 2013)

I also will upload a cabtura of calibration and a bit of Run mode.
Not attached in the previous post, it wont let me.


----------



## chemamata (Oct 20, 2013)

Do not leave me. Then I try again


----------



## chemamata (Oct 20, 2013)

I've split the file into two:
. - Mode calibrate
. - Mode run

Do not let me upload it. We'll split into two Run_1 and run_2


----------



## Ovaltineo (Jul 18, 2013)

Please post SegwayClone.h, not SegwayClone.ino. Also post pictures of the two sensors as they are mounted. I want to see the orientation.

With the results of the "RUN" that you posted, were the sensors level the whole time?


----------



## chemamata (Oct 20, 2013)

Sorry. I have a few days head elsewhere


----------



## markula (Oct 27, 2013)

Hi 

Will this motor driver work? 

http://www.ebay.com/itm/3-36V-10A-P...854?pt=LH_DefaultDomain_0&hash=item3a857cf806

Its rated to 15A but that is witout cooling. If you attatch heatsink the transistors is rated to 110A but the TO 220 package can only handle 70A. And if the paths is to weak on the circuit board you can solder it all the way.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> Sorry. I have a few days head elsewhere


Your SegwayClone.h looks good. Looking at your calibrate results, it looks like you haven't levelled your board sensor or it maybe defective. You didn't post the pictures of your sensors while mounted, so I cannot tell. Can you please swap the two sensors and post the calibrate and run monitor outputs? To swap, simply disconnect AD0 to Vcc on one and connect AD0 to Vcc on the other.

Even with the defective or unlevelled sensor, the motors should be running. If not, I am guessing that the Sabertooth didn't get finish booting up before the Arduino started sending commands. Can you try holding the reset button on the Arduino while powering up your system? After a few seconds, release the reset and see if makes a difference.


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> Hi
> 
> Will this motor driver work?
> 
> ...


This board will work with my code. Heatsink (use insulators) and solder in the trace are required.


----------



## chemamata (Oct 20, 2013)

Tomorrow I think I get 2 new gyroscopes.
Something had thought.As the amount and arrive to begin.
thanks


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> Tomorrow I think I get 2 new gyroscopes.
> Something had thought.As the amount and arrive to begin.
> thanks


You might be wasting your money.

In the picture of post #190, you had the sensors just hanging in a non-level (WRONG) position. Is this the same position when they are calibrated? Can you post more pictures? I've been asking for this many times and you don't reply. I would appreciate if you answer all my questions. Otherwise, we will just go around in circles.

Did you try swapping the two sensors you already have? Can you post the output results?


----------



## chemamata (Oct 20, 2013)

Still have not gotten my new gyroscopes.
The results of the "monitor" that were recently attached it with gyros "level", horizontal to the ground, as they in their final location.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> Still have not gotten my new gyroscopes.
> The results of the "monitor" that were recently attached it with gyros "level", horizontal to the ground, as they in their final location.


OK, instead of swapping the sensors, you can also make the following change in MPU6050.h:

// I2C address for the MPU-6050 board sensor is 0x68.
#define MPU6050_I2C_ADDRESS 0x69
// I2C address for the MPU-6050 steer sensor is 0x69.
#define MPU6050_ALT_I2C_ADDRESS 0x68

Post the calibrate and run results after this change.


----------



## Centrex (Nov 24, 2013)

Hi
What are the TC74AO devices used for in the schematics.
Regards
Centrex.


----------



## cyclone (Dec 8, 2013)

Centrex said:


> Hi
> What are the TC74AO devices used for in the schematics.
> Regards
> Centrex.


Temperature Sensors per post no.1


----------



## Ovaltineo (Jul 18, 2013)

cyclone said:


> Temperature Sensors per post no.1


Correct. They are optional and useful only if you install the Bluetooth module and run the Android app. You can use it to monitor the temperature of your motor controllers or the motors themselves. In my case, the motors get really hot (going uphill) -- almost double the temperature of the controllers! With temp sensors and Android app, I know when to give the motors a rest.


----------



## cyclone (Dec 8, 2013)

Ovaltineo said:


> Correct. They are optional and useful only if you install the Bluetooth module and run the Android app. You can use it to monitor the temperature of your motor controllers or the motors themselves. In my case, the motors get really hot (going uphill) -- almost double the temperature of the controllers! With temp sensors and Android app, I know when to give the motors a rest.


 wow, didnt know you have integrated this this to the android. what app did you use on this?


----------



## Ovaltineo (Jul 18, 2013)

cyclone said:


> wow, didnt know you have integrated this this to the android. what app did you use on this?


I announced the Android app release in post #209. The APK is zipped and can be downloaded in post #1. I did not release it on the Android app store to avoid paying the $25 registration fee .


----------



## Centrex (Nov 24, 2013)

Hi
I note in the readme instructions that a pot can be used for steering, this pot is to be connected to A3 on the Arduino.
A little later in the readme a voltage divider can be used to monitor the battery volts, this is also connected to A3. As you can only have one or the other would it not be possible to use one of the other available analogue inputs for the battery volts. This would give both options if required.
Regards
Cliff.


----------



## Centrex (Nov 24, 2013)

I have just downloaded ver 3 of the software.
When I try to compile (verify) I get a getsteeraccel not declared error.
What am I doing wrong.

Not very cluey with Arduino

cliff


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Hi
> I note in the readme instructions that a pot can be used for steering, this pot is to be connected to A3 on the Arduino.
> A little later in the readme a voltage divider can be used to monitor the battery volts, this is also connected to A3. As you can only have one or the other would it not be possible to use one of the other available analogue inputs for the battery volts. This would give both options if required.
> Regards
> Cliff.


Good point. I have fixed this in v3.1 which I've just released. POT_STEERING is now using A1.


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> I have just downloaded ver 3 of the software.
> When I try to compile (verify) I get a getsteeraccel not declared error.
> What am I doing wrong.
> 
> ...


You need to unzip the file with the SegwayClone directory and all files intact. Then use File-Open to open SegwayClone.ino.

Look back at post #203 and the subsequent posts if you are still having problems.


----------



## Centrex (Nov 24, 2013)

Thanks Ovaltino
All now working as far as I can tell.
In cal mode the buzzer works and a whole of info scrolls down the screen and then I get an error 2 followed by more info and then at the end a line with offsets.
I am only using one imu5060.

I had the problem of the segwayclone in the library.

Thanks
Cliff


----------



## Ovaltineo (Jul 18, 2013)

Error 2 is not good. Make sure you have secure connections between MPU6050 and Arduino.


----------



## wired (Nov 24, 2013)

Hello Ovaltineo,
Have looked at V3.1 information and wondered if you could advise where the other connections of the steering pot go. And it is possible that I have missed it.

Thanks,
Darcy


----------



## Ovaltineo (Jul 18, 2013)

wired said:


> Hello Ovaltineo,
> Have looked at V3.1 information and wondered if you could advise where the other connections of the steering pot go. And it is possible that I have missed it.
> 
> Thanks,
> Darcy


With a steering pot, pin 1 goes to ground, pin 2 goes to A1, and pin 3 goes to +5. You can reverse steering direction by swapping pin 1 and pin 3.


----------



## robertholmberg (Oct 26, 2013)

So im on the road, I started my project as well. And now when I try to upload the run version i ran into a problem:

SegwayClone.ino: In function 'void loop()':
SegwayClone:302: error: 'board_offset' was not declared in this scope
SegwayClone:303: error: 'steer_offset' was not declared in this scope

If I do a calibration upload it goes well, if I go without bluetooth it goes good as well. But as soon as i uncomment the line for using the BT it comes and I cant upload.
So I got the bluetooth installed on my segway and could find it but I cant connect since I got the problem above.

Another problem I ran into that i searched for a while and I thought i broked my Mega was that I couldn't upload it got stacked on uploading~95% It was because i had my Vcc5+ connected, I took that cable out and i could upload the program again.

So far it goes better than expected and it is great to have it started.

Edit:
I did declare the two values and it did compile, but not sure if its how it suppose to be done, I couldn't get the bluetooth working anyway, Not sure what i did wrong, but i guess its just to connect with 1234 and then start the program and it should show the info on the screen?

And the LED indication, I did try to have batteries with different Voltage, so I saw the red and green, but i think i saw it was blinking on the orange as well. Is that the purpose then it goes down or was it just something wrong with my setup?

Another problem i did have now was one of my two btn7960 acted weird, it was always giving full power no matter how i changed the gyros, changed it to another one and it ran as it was supposed. Did any other who got the btn7960 have the same problem?


----------



## Ovaltineo (Jul 18, 2013)

robertholmberg said:


> So im on the road, I started my project as well. And now when I try to upload the run version i ran into a problem:
> 
> SegwayClone.ino: In function 'void loop()':
> SegwayClone:302: error: 'board_offset' was not declared in this scope
> ...


Robert,

Looks like you are the first one to try the Bluetooth coz you found a bug that no one else has reported. I have fixed this in v3.2.

There is no hysteresis or averaging on the battery voltage measurement, so the LEDs will appear to blink if the voltage rises and falls between the threshold voltages 24v, 23v, 22v, and 21v.

To use the Bluetooth:
1. make sure your phone is already paired with the "linvor" Bluetooth module.
2. upload SegwayClone with BLUETOOTH enabled and MODE_CALIBRATE enabled. Doing this will change the Bluetooth module serial speed to 115200.
3. upload SegwayClone with BLUETOOTH enabled and MODE_CALIBRATE disabled.
4. turn on your clone. The red light on the Bluetooth module should blink.
5. run the android app. After 10 seconds, the red light on the Bluetooth module should stay on. The app background will turn white when it is connected and the screen should update in real time.

My two BTN7960s were good, though one died prematurely under heavy load. Fixed it by replacing the chip.


----------



## alvinlkk (Nov 14, 2013)

Hi, this is what i have done so far
*i've connected most of them needed to test run to see the 24v motor run. im stuck here
-Funduino Mega 2560
-BTN7960 x2
-MPU6050 x2

*uploaded OT's code and "it says done uploaded". i assume its successful
*i havent connect the motor yet

question is. what i can see from OT's MEGA scheme. the MPU6050 Steer has 2 +5v meaning i have to connect 2 (+5v) on the same sensor?


----------



## Centrex (Nov 24, 2013)

alvinlkk said:


> Hi, this is what i have done so far
> *i've connected most of them needed to test run to see the 24v motor run. im stuck here
> -Funduino Mega 2560
> -BTN7960 x2
> ...


The extra 5volt connection on the mpu is to change its I2C address, this is all explained in the readme file attached to the software. Also read how to install the software on the Arduino and how to access it, some of us have been caught.
Regards
Cliff


----------



## Centrex (Nov 24, 2013)

Hi
Does anyone have info on where to get the manual for the BTN7960 speed controller, NOT the chip but the complete board as used by Ovaltino and others.
Thanks
Cliff


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Hi
> Does anyone have info on where to get the manual for the BTN7960 speed controller, NOT the chip but the complete board as used by Ovaltino and others.
> Thanks
> Cliff


I haven't found one. But the design is based on the full-bridge circuit described in the chip document.


----------



## Centrex (Nov 24, 2013)

Thanks Ovaltineo
I have a further question ......

Using two BTN7960 motor controllers
On pages 2 and 3 of the readme you say if using a UNO/NANO:
Right motor PWM is pin 9
Right motor DIR is pin 10
Left motor PWM is pin 3
Left motor DIR is pin 11

This is in conflict with the segwayclone.h file which says to connect the battery leds to pins 9,10 and 11 .
The MEGA dwg uses 9,10 and 11 for the volts but different set of pins for the motor control.

Can I just use the pin specified in the MEGA dwg for my UNO.

I see by the motors.h file that pins 9,10 and 11 are used to control the motors except in the MEGA, so do I now assume the the battery volts is not available when using the UNO and a pair of BT7960 controllers.
A little confused.
regards
Cliff


----------



## robertholmberg (Oct 26, 2013)

Ovaltineo said:


> To use the Bluetooth:
> 1. make sure your phone is already paired with the "linvor" Bluetooth module.
> 2. upload SegwayClone with BLUETOOTH enabled and MODE_CALIBRATE enabled. Doing this will change the Bluetooth module serial speed to 115200.
> 3. upload SegwayClone with BLUETOOTH enabled and MODE_CALIBRATE disabled.
> ...


I tried to just using the BT, and the two MPU 6050 to see if i can get it working. But it does not. I did like you wrote. But the LED on the BT never stops blinking (and the app never gets white, it stays light blue, which it turns into quite fast after its yellow and said it found the HC-06), so i guess it never gets connected. Sadly right now i have no other BT to try, but my phone can connect to other units so it shoudn't be a problem. And it can pair and password 1234 works.

If it is blue and white in yours and it gets the connection, I do have another problem, because nothing gets updated in the program.

I don't know if i got some other problem here, but I had another problem as I wrote earlier about not being able to upload any sketch to the Mega, its stops at about 95%, and now i found out that this occur when i have the plus to the BT module connected.

//This below I solved by changing the pis i did set wrong TX to TX and RX to RX...
I actually had Another problem when i have this connected is when i do the calibration is that it gets some noise (I guess) because it show me some weird letters in my console (code attached below).

When I do the calibration without the BT plus (5V) connected it gets the letters correct. In the attached log i attach first the good (without BT) and then the bad (with BT) connected to the Mega.

Any other experienced similar problem?



> ��•WHO_AM_I : 68, error = 0
> PWR_MGMT_2 : 0, error = 0
> Gyro -19
> Gyro -54
> ...


//Shorted the gyro info since max letters was reached in the answer


----------



## markula (Oct 27, 2013)

Hi 

I use PWM_DIR_CONTROLLER. 
But it is removed the +5V on Pin 7 that i need. 

It work if i use PWM_PWM but then i just get one directions on the wheels. I think that is since the DIR input want 0V or +5V, not PWM signal. 

I just tried to copy the lines from PWM_PWM_CONTROLLER but it dident work. 

Like this:
In Motors,H.

#ifdef PWM_PWM_CONTROLLER
//	#define MOTOR_MAX 255
#define MOTOR_MAX 30

// PWM pins for motor
#ifdef MEGA	
#define RIGHT_BACKWARD_PIN	2
#define RIGHT_FORWARD_PIN	3
#define LEFT_BACKWARD_PIN	5
#define LEFT_FORWARD_PIN	6
#define MOTOR_ENABLE_PIN	7
#else
#define RIGHT_BACKWARD_PIN	9
#define RIGHT_FORWARD_PIN	10
#define LEFT_BACKWARD_PIN	3
#define LEFT_FORWARD_PIN	11
#define MOTOR_ENABLE_PIN	7
#endif
#endif


And in Motors:

#ifdef PWM_DIR_CONTROLLER
void initMotors(void)
{
setPwmFrequency(HZ_3906); 
pinMode(MOTOR_ENABLE_PIN, OUTPUT);
pinMode(LEFT_PWM_PIN, OUTPUT); 
pinMode(LEFT_DIR_PIN, OUTPUT); 
pinMode(RIGHT_PWM_PIN, OUTPUT); 
pinMode(RIGHT_DIR_PIN, OUTPUT); 
digitalWrite(LEFT_PWM_PIN, LOW); 
digitalWrite(RIGHT_PWM_PIN, LOW);

I mesured and it still 0V out on pin 7. 
I am green with programing. 

Can you help ?


----------



## schilli (Jan 1, 2014)

*Please help me to buy the correct hardware 36V*

Hello everyone,

i am glad to find this forum.
Please excuse my bad english, because i am from Germany.
I am 41 years old and still bought some things:

1) two geared motores with 750 W 36 V. They need ~25A
2) tyres, batteries and the rest of the mechanic.


I have read very much here and if i am correct, i will need a ardu mega, 2x mpu 6050, thomethig to get 11 or 12v for the mega and two bts7969b.
But i also read, that the bts cant do 36V.

I hope, you will help me, to get the correct hardware!

Thanks still now for your time you will spent in my problem.

Christian


----------



## robertholmberg (Oct 26, 2013)

Hi schilli,

I guess you are not doing your own driver, but pre made ones, and if you are using the same as the rest of us you should go for 24V, since the max voltage is 27V for those. If you using the chip and doing it yourself I think the maximum was 45V, but not hundred on that one.

From the datasheet:
Absolute Maximum Ratings
Parameter Symbol Limit Values Unit Conditions
Min. Max. Voltages
Supply Voltage VS 45V
Logic Input Voltage VIN 5.3V


----------



## schilli (Jan 1, 2014)

Hello Robert,

can i use this motor also with 24 V ?

http://shop.mat-con.net/epages/62158737.sf/de_DE/?ObjectPath=/Shops/62158737/Products/my1020z3

then is the max turning ~320 U/min

my tyres have a radius from 16cm at the moment, so that it will became 19km/h


----------



## robertholmberg (Oct 26, 2013)

Didn't check anything but saw that its the same type of motor as the one i ordered, but without gear and from another place. You can run it on lower voltage, but you loose power.

I bought this one:
http://www.sunds-sportartikel.de/ma...-36volt-motor-my1020-fur-mach1-e-scooter.html

/Robert


----------



## schilli (Jan 1, 2014)

Hello Robert,

i will try it.

can you help me please, what i need to finish?

Arduino mega or uno?

2x sabertooth or roboclaw or btn7960?

24v to 12v

2x mpu 6050

need i tc74?

do i need a poti for steering? or did this the 6050?

anything else?

Many thanks for your help!

Christian


----------



## markula (Oct 27, 2013)

schilli said:


> Hello Robert,
> 
> i will try it.
> 
> ...


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Thanks Ovaltineo
> I have a further question ......
> 
> Using two BTN7960 motor controllers
> ...


Cliff, you are right - there is a conflict between the LED pins and BTN7960 pins when using an UNO. I have fixed this in v3.3. I have also added new schematic for UNO with BTN7960 controllers. This uses pins 4, 5, and 6 for the LEDs.

BTW, BTN7960 is a PWM-PWM controller, *not* a PWM-DIR controller.


----------



## Centrex (Nov 24, 2013)

Thanks for that, I actually tried using pins 2,3 and 4 without causing a problem.
I will stay with yours.

Thanks again
Cliff


----------



## Ovaltineo (Jul 18, 2013)

robertholmberg said:


> I tried to just using the BT, and the two MPU 6050 to see if i can get it working. But it does not. I did like you wrote. But the LED on the BT never stops blinking (and the app never gets white, it stays light blue, which it turns into quite fast after its yellow and said it found the HC-06), so i guess it never gets connected. Sadly right now i have no other BT to try, but my phone can connect to other units so it shoudn't be a problem. And it can pair and password 1234 works.


OK, when paired with your phone, does the name come up as "linvor", "HC-06", or something else? I had assumed it would be "linvor" but I guess this would depend on the firmware. Let me know the name and I will add it to the Android app pairing list.




robertholmberg said:


> I don't know if i got some other problem here, but I had another problem as I wrote earlier about not being able to upload any sketch to the Mega, its stops at about 95%, and now i found out that this occur when i have the plus to the BT module connected.
> 
> //This below I solved by changing the pis i did set wrong TX to TX and RX to RX...
> I actually had Another problem when i have this connected is when i do the calibration is that it gets some noise (I guess) because it show me some weird letters in my console (code attached below).
> ...


It looks like RX0 and TX3 on your Mega are tied together. Maybe a mistake in your connection or a soldering fault during manufacture. Use a multimeter to check if they are shorted and desolder if necessary.


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> Hi
> 
> I use PWM_DIR_CONTROLLER.
> But it is removed the +5V on Pin 7 that i need.
> ...


You were almost there. You just need to add the following at the end of initMotors.
digitalWrite(MOTOR_ENABLE_PIN, HIGH);


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello Robert,
> 
> i will try it.
> 
> ...


I believe you'll be ok with 24V - 2X 500W is plenty of power for a clone. 

Get a Mega clone, it is much better than the UNO for only a few dollars more.

You need an adjustable DC-to-DC voltage converter to convert from 24V to 11V for the Arduino supply.

I would recommend 2X BTN7960 because they are cheap and do the job, downside is there is no warranty/support. If you don't really care about cost, then the Roboclaw might be better (you only need 1) - as long as you can get local warranty/support. I won't recommend the Sabertooth - it is expensive yet has half the resolution of the BTN7960.

You need a 5v buzzer.

I suggest getting the resistors for battery voltage sensing.

The following are optional - you can add them later when the basics are working:

1. voltage indicator LEDs
2. TC74A0 and TC74A2 
3. HC-06 bluetooth module


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> I believe you'll be ok with 24V - 2X 500W is plenty of power for a clone.
> 
> Get a Mega clone, it is much better than the UNO for only a few dollars more.
> 
> ...



Hello Ovaltineo,

first i want to say: thank you for your help!

And now a few question, i hope you can help me:

1) you wrote, that the BTN7960 can up to 45V. I found a 7960 and a bts7970 (http://www.ebay.de/itm/281236245289?_trksid=p2055119.m1438.l2649&ssPageName=STRK:MEBIDX:IT)

what is better? to try my 36v motors with 24V(i already have three batteries and a charger) or with 36V if the BTN/BTS can handle this.

2) here a MPU and mega to see. i would order, if you say, its ok.

http://www.amazon.de/SainSmart-MPU-...TF8&colid=32NDC5L2J5UZP&coliid=I1G4RT1D015Q88

http://www.amazon.de/SainSmart-Mega...TF8&colid=32NDC5L2J5UZP&coliid=I25VD2QNWTDSDO

Thanks a lot


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> I believe you'll be ok with 24V - 2X 500W is plenty of power for a clone.
> 
> Get a Mega clone, it is much better than the UNO for only a few dollars more.
> 
> ...



Two more questions please:

at the moment, i plan the frame for cutting on my cnc router.

1)is it better to have a low center of gravity or exactly in the middle of the tyres?

2) how strong must the springs are for the steering? is it possible to use shock absorder


Thanks

Christian


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello Ovaltineo,
> 
> first i want to say: thank you for your help!
> 
> ...


I did not say that the BTS7960 will handle 45V -- I think it was Rob who said it. It *won't*. The BTS79XX chips will handle only 28V. The BTS7960 can handle 43A while the BTS7970 can handle 68A. Get two with a heatsink like this:

http://www.ebay.de/itm/Dual-BTS7970...646?pt=LH_DefaultDomain_0&hash=item27d52b1b86

Amazon is expensive. eBay is much cheaper but shipping will probably take longer

http://www.ebay.de/itm/MPU-6050-Sen...E_TV_Video_Audio_Sonstige&hash=item5d476d1750


http://www.ebay.de/itm/Atmega-2560-...=Wissenschaftliche_Geräte&hash=item3f291f83ab


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Two more questions please:
> 
> at the moment, i plan the frame for cutting on my cnc router.
> 
> ...


Lower is better but center of gravity doesn't matter much. Just make sure you have enough ground clearance for steep hills and obstacles. 
Strong springs are good as long as it is easy enough to move the steering.


----------



## Ovaltineo (Jul 18, 2013)

I have a new version (V1.2) of the Android app. I have changed the angle indicator for the steering and board tilt to an aircraft-style attitude indicator. I will upload it later today.


----------



## robertholmberg (Oct 26, 2013)

Ovaltineo said:


> I did not say that the BTS7960 will handle 45V -- I think it was Rob who said it. It *won't*. The BTS79XX chips will handle only 28V. The BTS7960 can handle 43A while the BTS7970 can handle 68A. Get two with a heatsink like this:


Hi,

Yes it was me who said it, my bad if it came wrong. Just that the Maximum is suppose to be according to the data sheet (thought thats what you wanted to know): http://www.infineon.com/dgdl/BTN796...fileId=db3a304316f66ee80117642084e76a7c&ack=t

And also if it wasnt understandble its the absolute max, its not made for running in more than 28. Im trying to be little bit more clear next time.


I got it "working" my second last day at home and I wanted to try it. I did my built on a piece of wood and thought a bit wrong and it brook when i standed on it, this i should have thought of when i took the wood, but i wasnt thinking. So i didnt do a real test. But when i tried to run it without myself on it seem to work before it brooked.

I had big wheels and i might try with smaller later since it felt hard to get up and keep the balance. Another thing I felt i had a problem is to keep the steering straight since my strings there are a bit loose.


*OT*, I sadly cant try the program anymore for a while since I'm not longer at home. But i will see if i can do a small setup to see if i can get a connection on my breadboard.

Tha name is HC-06 and not Linvor for me. But i guess it could also be changed with the initial setup of the bluetooth at the same time as the baud rate are set?

When i did the calibration, i did it totally on a flat setup, but should i move the wehicle a bit or why is those data that comes up so different? I have a big difference even though i didnt move. But i just thought that those values will be the "0" and where it doesnt move, or is to just know the average of the center point?

/Rob


----------



## Centrex (Nov 24, 2013)

Hi Ovaltino
I have made a little pcb that sits on the Arduino which gives me screw terminals for all the connections as well as the buzzer and the voltage leds, all works well.
I have no motors or controllers connected and the imu is firmly held horizontal at all times.
Segwayclone.h is set for pot steering and pwmpwn motors as well as the leds.
No motors connected.


I go through the cal mode with no errors.
In run mode all appears ok with no errors and the steer showing 0 the imu varies a little around 0.001 the motors start of at very low numbers which start to creep up to at least 30.
All from the serial display.

After a few seconds the BUZZER starts a very rapid beeping that never stops.

Any thoughts on why this would be so.

regards
Cliff


----------



## Centrex (Nov 24, 2013)

here is a picture of the interface, gives nice solid connections to the various other parts.








it is sitting on top of a Freetronics UNO clone


Cliff


----------



## FlyBoyKB (Jan 9, 2014)

Ovaltino - This is a great site! I'm looking to start my project but I plan to build a small robot first. The problem I'm having is downloading your code. When I click on the code .zip file on the first page it only tries to download a .php file rather than the whole zip. What am I doing wrong.

Thanks again for your efforts.

kb


----------



## robertholmberg (Oct 26, 2013)

Hi Cliff,

I have the same thing happen to my one when i tried it without any resistance.
But as soon as i put it on floor with wheel on it worked. Im not sure its right or so, but thats my experience when i tried. And i guess the code just increase the speed to try to make the segway strait and when it feel no effect of the speed it got it increase it more and more. So if you try to move it back or forward i guess it would change.

The buzzer im not sure about.

/Rob


----------



## Centrex (Nov 24, 2013)

Thanks Rob
The continuous buzzer maybe related to what you found.
One of these days I will get some controllers and see what happens, I can always disconnect the buzzer.

for the other poster with the download problem are you sure you are downloading segwayclone.zip the latest version as it is usually not a prob to unzip it.

regards
Cliff


----------



## schilli (Jan 1, 2014)

Thank you Ovaltine and Robert 

for your help till now. 
I am still waiting for the BTN. If they arrive, i have everything you told me and can start with the electronic!
At the moment, i try to find a solution to connect the motor and the wheel.

I anybody knows a compatible motor driver for 36V and 25A, please tell me.

If somebody wants, i can take pictures and show them.


----------



## schilli (Jan 1, 2014)

Hello Ovaltine,

the more i read, i have one more question:

the mpu 6050 have to detect the angel of the steering "tool".
i think, the angle must be between 5 and 10degree.
i dont no, how exact the mpu works, or could it be an idee, to transfer the angle 
with a rate of x2 or x3 to get better response?


----------



## Ovaltineo (Jul 18, 2013)

robertholmberg said:


> I got it "working" my second last day at home and I wanted to try it. I did my built on a piece of wood and thought a bit wrong and it brook when i standed on it, this i should have thought of when i took the wood, but i wasnt thinking. So i didnt do a real test. But when i tried to run it without myself on it seem to work before it brooked.
> 
> I had big wheels and i might try with smaller later since it felt hard to get up and keep the balance. Another thing I felt i had a problem is to keep the steering straight since my strings there are a bit loose.
> /Rob


I am using 1 inch marine plywood. A metal frame would be better (though heavier) but I don't have a welder.

You can keep the big wheels if you use an L plate or something to bring the platform below the wheel axis. I am actually upsizing my wheels from 12 inches to 16 inches to make it easier to get over bumps.



robertholmberg said:


> *OT*, I sadly cant try the program anymore for a while since I'm not longer at home. But i will see if i can do a small setup to see if i can get a connection on my breadboard.
> 
> Tha name is HC-06 and not Linvor for me. But i guess it could also be changed with the initial setup of the bluetooth at the same time as the baud rate are set?
> 
> ...


I followed your advice and just released v3.4 where I modify the Bluetooth module name during calibration.

During calibration, the code gets the average value of the level/center point. This average is not zero. During runtime, the average is subtracted from the current value to get the angle offset from level.


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Thanks Rob
> The continuous buzzer maybe related to what you found.
> One of these days I will get some controllers and see what happens, I can always disconnect the buzzer.
> 
> ...


Rob is right about the increasing motor output. The buzzer will sound when the motor output reaches MOTOR_MAX. This is deliberately set to a low value for troubleshooting. Depending on your controller, this should be increased to the true MAX value (eg 255 for a PWM controller).


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello Ovaltine,
> 
> the more i read, i have one more question:
> 
> ...


The angle is multiplied by the STEER_MULTIPLIER defined in SegwayClone.h. This value depends on the type of motor controller. You can modify to change the steering response. If you make it too large, it will be too twitchy (and dangerous) at medium to high speeds.


----------



## MBEV (Sep 28, 2008)

New here....

Just catching up with DIY Segway projects and found this thread! Some useful stuff here…. Thanks to all the posters.

I built one a couple of years ago and went through two versions and would now like to commence a 3rd using motors with much less backlash then my current ones. I had thought about going with common brushless hub motors but it seems that fast switching between forward/reverse is not that good an idea? Open to suggestions here! At the moment I’m favouring brushed DC with a good belt drive arrangement to give me the desired speed range.

My old project is documented here if interested:
http://www.brucewhite.net/Segway%20Project/Index.htm

A little YouTube video using it is included on that URL as well.


Cheers
Bruce


----------



## schilli (Jan 1, 2014)

Hello Ovaltine,

tomorrow i want to plane both mpu, and before i do wrong, i will ask you:
Where is the best place for both sensors? 
I wrote something like in the middle of x and y.
In two different pics, i saw the second sensor one time horizontal and once vertical. What´s better?

Thanks for answering my questions


----------



## markula (Oct 27, 2013)

Hi 

I think i have all the electrinics and software function now. 

When i use 2x 21W light bulbs as the motors everything works fine.

But when i connect the motors i get the long beep and it tries to start the motors.

I can se that it tries but it like the ampere is to high. So the axle on the weel just moves and then it restarts. After that i get the long beep and the axle just move.

I have tride to change Motor_MAX to 255, under calibration mode it is on 30. 

I can post some photos or a video if that helps ? 

Markus


----------



## robertholmberg (Oct 26, 2013)

MBEV said:


> New here....
> 
> Just catching up with DIY Segway projects and found this thread! Some useful stuff here…. Thanks to all the posters.
> 
> ...


Sorry not being able to help you about the motors. But i went through your buildings and must say you did a very great job with photos and everything.

I was laughing a bit about the height of everything for myself when i saw the batteries on top of each other. But it worked great and then it became smaller. Haha

/Rob


----------



## robertholmberg (Oct 26, 2013)

schilli said:


> Hello Ovaltine,
> 
> tomorrow i want to plane both mpu, and before i do wrong, i will ask you:
> Where is the best place for both sensors?
> ...


No, they are placed the same way, but one as you wrote and the other on your steering so it feels how you want to turn, left or right.

As in post 200:
http://www.diyelectriccar.com/forums/showpost.php?p=372746&postcount=200

/Rob


----------



## MBEV (Sep 28, 2008)

_Sorry motor choice question most likely not best on this build thread…._
Have started a new thread re *Segway Clone motor selection*.
_Just a comment;_ It is interest when you get one of these up and running with a degree of success, how things go around in circles. I should have realized early on that drive train play would have been an issue but convinced myself that the electronics could compensate. Increasing the feedback response (gain) helped but in general this got me to a rather ‘jerky’ stage which made for a very poor ride! In the end I decided I had it as good as I could without decreasing the mechanical play. Replacing the coupler nylon bits with the available aftermarket rubber assemblies seemed a good idea, but under full load these also had far too much play (rubber compresses each way). Even after making my ‘free’ hubs solid, I was not happy with the outcome! Now for Mk III… If I was starting again from scratch, I would concentrate on getting the balancing and forward/back motions sorted out first and worry about any refinements to steering etc long after that.
Cheers
Bruce


----------



## Ovaltineo (Jul 18, 2013)

MBEV said:


> New here....
> 
> Just catching up with DIY Segway projects and found this thread! Some useful stuff here…. Thanks to all the posters.
> 
> ...


Bruce, your craftsmanship is absolutely top notch . I live not too far away (900km south) -- we should combine our skills and sell DIY kits to Queensland where this beast is legal .


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> Hi
> 
> I think i have all the electrinics and software function now.
> 
> ...


From what I understand, it looks like the Arduino is resetting under load. Can you post the serial monitor output to confirm? What power supply are you using - batteries or a benchtop power supply? Are you using a step-down DC-to-DC converter to supply 11V-12V to the Arduino? A video would be good.


----------



## markula (Oct 27, 2013)

Ovaltineo said:


> From what I understand, it looks like the Arduino is resetting under load. Can you post the serial monitor output to confirm? What power supply are you using - batteries or a benchtop power supply? Are you using a step-down DC-to-DC converter to supply 11V-12V to the Arduino? A video would be good.


Yes i think that is the problem. I can try to get out the serial monitor output. 

I am using a RC 10Ah 22.2V 10C battery. And a DC DC LM2596 from ebay to 11V to arduino.( i can try to se hvat happens to the voltage at the start up. Maybe i need a conducter to power the arduino when the motors starts. I can take a video soon.

Here is some photos: 





Markus


----------



## FlyBoyKB (Jan 9, 2014)

Anyone:

Is there a way to download the code from this site? If so, how?

Thanks

kb


----------



## robertholmberg (Oct 26, 2013)

FlyBoyKB said:


> Anyone:
> 
> Is there a way to download the code from this site? If so, how?
> 
> ...


How about you start reading from page 1?

/Rob


----------



## FlyBoyKB (Jan 9, 2014)

Rob - I have read from page 1 of both this and the build thread. I see a link on page one "SegwayClone v3.4.zip" but it only downloads the .php and not the .zip. Any help?

kb


----------



## robertholmberg (Oct 26, 2013)

I would guess its something with your internet settings or so, maybe a firewall or any other thing who set the "computer to internet"-settings. Maybe you try downloading it in another browser. If it still doesn't work, try on another computer. Maybe you just have try make it all default or so.

You got the correct link.

/Robert


----------



## FlyBoyKB (Jan 9, 2014)

Thanks Ed- It was a compatibility issue. I.E. 11 does not handle php files unless in the browser you go to Tools , Compatibility View Settings and Add the web site to the compatibility list. It then will download the .zip file. Hope this might help someone else also.

kb


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> Yes i think that is the problem. I can try to get out the serial monitor output.
> 
> I am using a RC 10Ah 22.2V 10C battery. And a DC DC LM2596 from ebay to 11V to arduino.( i can try to se hvat happens to the voltage at the start up. Maybe i need a conducter to power the arduino when the motors starts. I can take a video soon.
> 
> Markus


I think I know what your problem is. The +5 pin on your motor controller is probably not an ENABLE pin. The controller probably doesn't have a built-in +5 power supply. Connecting this to PIN 7 will draw too much current and could reset the Arduino. Instead of PIN 7, you should connect it to +5 on the Arduino. Can you post the documentation for this controller? If the logic circuit is completely isolated, you may need to connect GND as well.


----------



## markula (Oct 27, 2013)

Ovaltineo said:


> I think I know what your problem is. The +5 pin on your motor controller is probably not an ENABLE pin. The controller probably doesn't have a built-in +5 power supply. Connecting this to PIN 7 will draw too much current and could reset the Arduino. Instead of PIN 7, you should connect it to +5 on the Arduino. Can you post the documentation for this controller? If the logic circuit is completely isolated, you may need to connect GND as well.


I dont have much info on the motor controller.
http://www.ebay.com/itm/251347662854?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

okey, the GND is not isolated. it full connection between GND on input and GND power 24V in. 

I dont think the motor contoller have +5V build in power. I will try tomorrow to take +5V from arduino +5V and not pin 7. 

I am pretty sure that is the problem. Thanks


----------



## chemamata (Oct 20, 2013)

Hello everyone.
After these dates eating and drinking more than usual (at least in Spain), and after solving various personal problems, I again try to run my clone.
See that there are more people who become another clone. My most sincere congratulations to all.
Now I have it removed. At home I have the electronics, power supply and printer motors to set well and know that everything is working properly before mounting "real".
At first I think everything works correctly. but after
PROBLEM.
Forward smoothly. 
Forward and to either side, no problem.
Backwards, no problem.
The problem is when I turn backwards. The rotation does backwards. 
If right turn the spinning wheel is on the right, the left wheel should rotate.

O.T.
What can happen?I suppose it's problem Soft. no?
Thank you very much


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> Hello everyone.
> After these dates eating and drinking more than usual (at least in Spain), and after solving various personal problems, I again try to run my clone.
> See that there are more people who become another clone. My most sincere congratulations to all.
> Now I have it removed. At home I have the electronics, power supply and printer motors to set well and know that everything is working properly before mounting "real".
> ...


This is normal. Even real Segway do it this way. It will get out of balance if not done this way.


----------



## chemamata (Oct 20, 2013)

Yupii!Yupii!Yupii!Yupii!Yupii!
So I think I have everything already done.
As we have assembled and running, I upload some pictures to give encouragement and some idea to those who want to try.
I'm already nervous hoping that works.
YUUUUUPPPPPPPPIIIIIIII!


----------



## phaedrus (Aug 24, 2013)

markula said:


> I dont have much info on the motor controller.
> http://www.ebay.com/itm/251347662854?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
> 
> okey, the GND is not isolated. it full connection between GND on input and GND power 24V in.
> ...


I have used that controller. It requires the +5V to operate and IIRC it consumes 15ma or so - easily handled by the Arduino supply.

It works fine in this [segway] combination as long as you don't power it up until the Arduino has completed its initialisation process - I found that it would spin the wheels for a period and then go into hard brake, which popped some of the FETs. 

In my case I countered this by simply using a spare pin to supply the controller and taking it high a second or two after turn-on. It would be a simple matter to include such a facility in amongst OT's code if there's not something there already (sorry it's been a while since I looked).

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> Yupii!Yupii!Yupii!Yupii!Yupii!
> So I think I have everything already done.
> As we have assembled and running, I upload some pictures to give encouragement and some idea to those who want to try.
> I'm already nervous hoping that works.
> YUUUUUPPPPPPPPIIIIIIII!


Congratulations !!! Remember to increase MOTOR_MAX to 255. Wear a helmet and protective gear coz you are going to fall sooner than you think .

Looking forward to the pictures and video.


----------



## chemamata (Oct 20, 2013)

For now I'll put it to 100. 
I suppose it's a good value. When it stops raining and I test amount. 
I will upload pictures and videos.


----------



## schilli (Jan 1, 2014)

Hello Ovaltine,

can you please look at this motor drive, the site is in english.

http://www.robotik-teile.de/Controller/Motor-Driver/Pololu-High-Power-Motor-Driver-36v20-CS.html

When i read you readme.txt from your zip, the drive could go.
What is your opinion? Could it go with 36V and your code?

Thanks for answering.


----------



## robertholmberg (Oct 26, 2013)

schilli said:


> Hello Ovaltine,
> 
> can you please look at this motor drive, the site is in english.
> 
> ...


It looks positive, but you can not be sure since no one else tried it. It runs PWM. You might have to change a few settings but i would guess it works, don't use it in the "drive-brake"-mode though, could be fun for everyone else then you driving it  Didn't go through the whole page in detail. Maybe someone else does.


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello Ovaltine,
> 
> can you please look at this motor drive, the site is in english.
> 
> ...


Yes, this will work -- you need two. Drive-brake (Rob is wrong on this one) and drive-coast will both work. You need to select PWM_DIR_CONTROLLER in SegwayClone.h.

I suggest attaching a heatsink so it can handle more power.


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> Yes, this will work -- you need two. Drive-brake (Rob is wrong on this one) and drive-coast will both work. You need to select PWM_DIR_CONTROLLER in SegwayClone.h.
> 
> I suggest attaching a heatsink so it can handle more power.



Many thanks for all your answers.
My english is not so good, and technical english is very difficult.

What do you mean is better? 
drive brake or drive coast

did you mean a fan for heatsink?

what kind of diagramm from the four on the first site here should i go near?


----------



## robertholmberg (Oct 26, 2013)

Ovaltineo said:


> Yes, this will work -- you need two. Drive-brake (Rob is wrong on this one) and drive-coast will both work. You need to select PWM_DIR_CONTROLLER in SegwayClone.h.
> 
> I suggest attaching a heatsink so it can handle more power.


Hmm, i guess I am, but I really thought when it goes pwm, lets say sending 50% on and the rest off, the 50% breaking would be a bit risky and shaky, but isnt it something that you feel on a two wheel like a segway clone?. And the second thought wasn't if it is working or not, but just that it use more power to drive it since it brake the motor (and the wheels in the end)?

I learned something new and I'm happy to be corrected. Cheers.

/Robert


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Many thanks for all your answers.
> My english is not so good, and technical english is very difficult.
> 
> What do you mean is better?
> ...


I've only used drive-brake and most sign-magnitude controllers use drive-brake. One of the best sign-magnitude documentation http://www.modularcircuits.com/blog/articles/h-bridge-secrets/sign-magnitude-drive/ only discuss drive-brake too. So, I'll pick drive-brake.

I meant heatsink. You can add a fan later if the heatsink gets too hot.

I will create a new schematic for this controller.


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> I've only used drive-brake and most sign-magnitude controllers use drive-brake. One of the best sign-magnitude documentation http://www.modularcircuits.com/blog/articles/h-bridge-secrets/sign-magnitude-drive/ only discuss drive-brake too. So, I'll pick drive-brake.
> 
> I meant heatsink. You can add a fan later if the heatsink gets too hot.
> 
> I will create a new schematic for this controller.


Thank you OT for your work.
The motor drivers came today, so that i have everything here to connect!
I will start slowly, so that i can check your schematic.
if the schematic will take longer, it where very helpful for me, if you can tell me what pin from mega to controller have to connect


Now, i know,what you mean with heatsink; thanks for google. I will use it!
Many thanks before

Christian


----------



## markula (Oct 27, 2013)

phaedrus said:


> I have used that controller. It requires the +5V to operate and IIRC it consumes 15ma or so - easily handled by the Arduino supply.
> 
> It works fine in this [segway] combination as long as you don't power it up until the Arduino has completed its initialisation process - I found that it would spin the wheels for a period and then go into hard brake, which popped some of the FETs.
> 
> ...


I should have read that before my smoke test.. xP 

So now i think i buy a relay card like this: 
http://www.ebay.com/itm/5V-10A-2-Ch...836?pt=LH_DefaultDomain_0&hash=item5af59cf4c4

So the relay card get power +5V from arduino. And enable 1 from pin 7. And then when the relay connect in it delivers +5V to the motor controller.

But do the pin 7 power on before or after iniziation of the arduino software ?

Thanks, Markus


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Thank you OT for your work.
> The motor drivers came today, so that i have everything here to connect!
> I will start slowly, so that i can check your schematic.
> if the schematic will take longer, it where very helpful for me, if you can tell me what pin from mega to controller have to connect
> ...


I have added the schematic in post #1. Select PWM_DIR_CONTROLLER in SegwayClone.h.


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> I should have read that before my smoke test.. xP
> 
> So now i think i buy a relay card like this:
> http://www.ebay.com/itm/5V-10A-2-Ch...836?pt=LH_DefaultDomain_0&hash=item5af59cf4c4
> ...


Have you tested just connecting 5V to the Arduino +5V? If the motors are initially spinning during reset, just try adding a 10K pull-down resistor on the PWM signal.


----------



## schilli (Jan 1, 2014)

Thank you very much OT,

i will try tomorrow.


----------



## markula (Oct 27, 2013)

Ovaltineo said:


> Have you tested just connecting 5V to the Arduino +5V? If the motors are initially spinning during reset, just try adding a 10K pull-down resistor on the PWM signal.


Yes i just powered +5 on motor controller to +5V from arduino supply. But in my program i have it enable on pin 7. 

So does the arduino turn on pin 7 before ore after initialization ? (will it work with the relay)

I will also add 10K pull down resistors on PWM.


----------



## schilli (Jan 1, 2014)

Hello OT,

can you explane me the following text passage:

The motor and motor power connections are on one side of the board, and the control connections (5V logic) are on the other side. The motor supply should be capable of delivering the high current the motor will require, and a large capacitor should be installed between V+ and ground close to the motor driver to decrease electrical noise. Two axial capacitors are included and one or both can be installed by soldering them into the V+ and GND pins (labeled '+' and '-' on the bottom silkscreen) along the long edges of the board. Such installations are compact but might limit heat sinking options; also, depending on the power supply quality and motor characteristics, a larger capacitor might be required. There are two options for connecting to the high-power signals (V+, OUTA, OUTB, GND): large holes on 0.2" centers, which are compatible with the included terminal blocks, and pairs of 0.1"-spaced holes that can be used with perfboards, breadboards, and 0.1" connectors.

my problem: should i take a capacitor? one or two? or buy an other bigger one?
what means "decrease electric noise"?

Thank for helping me


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> Yes i just powered +5 on motor controller to +5V from arduino supply. But in my program i have it enable on pin 7.
> 
> So does the arduino turn on pin 7 before ore after initialization ? (will it work with the relay)
> 
> I will also add 10K pull down resistors on PWM.


Try it without a relay (enable pin is not used). Use a relay only if the motor spins during initialization. Use a 10K pull down on the enable pin too. All Arduino pins go into floating HIGH (high impedance input mode) during reset, hence you need to pull it down if you want it LOW during initalization.


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello OT,
> 
> can you explane me the following text passage:
> 
> ...


The PWM frequency used in this application is only 3.9khz so I suggest using a 50V capacitor between 680uf to 1000uf.

"Electrical noise" is the ripple current coming back from the motor. A capacitor is used to decrease/absorb this noise. Bigger capacitor=less noise.


----------



## markula (Oct 27, 2013)

Is it possible to add this car remote controll?

http://www.ebay.com/itm/370946741588?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

Is like you get 1X +12V in 0,5 sek to open, and lock 2X of +12V(+12V 0,5 sek--pause--12V 0,5 sek. 

So just not anybody can drive away with it.


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> Is it possible to add this car remote controll?
> 
> http://www.ebay.com/itm/370946741588?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
> 
> ...


It is possible, but not worth the effort. A remote control relay is much easier to implement - no source code change necessary. Just use the relay to break the power supply to the Arduino.
http://www.ebay.com/bhp/remote-control-relay-12v


----------



## schilli (Jan 1, 2014)

Hello all,

a few minutes ago it works the first time. But it costs me 100€ because the two motor controllers have been killed on the first test at 36V.

My problem is, when the mega is off, the motors run. So i have first to start the mega board and then the motors. 
I think, when i do this, and wait, until the software runs and start the motors during the steering is not zero, the motors will start soon.
Can anybody help me.
The motor controllers have no extra 5V. they get the power direct.

Thanks a lot

Tomorrow i will test my third case for the clone, because its difficult to fix the Motors

P.S.
Is it normal, that the led from the mpu is always red?


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello all,
> 
> a few minutes ago it works the first time. But it costs me 100€ because the two motor controllers have been killed on the first test at 36V.
> 
> ...


I'm sorry to hear that your controller died. When you say the motors run when the mega is off, does this happen also when the mega is reset or initialising? I expected that you will power on everything at once, that is, one switch to turn on the battery that powers everything. Did you try it that way? During the first few seconds, the Mega will initialise. But according to the controller spec, PWMH is pulled LOW, so the motors should not run until the Mega pulses PWMH. Next time, test with a small load.


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> I'm sorry to hear that your controller died. When you say the motors run when the mega is off, does this happen also when the mega is reset or initialising? I expected that you will power on everything at once, that is, one switch to turn on the battery that powers everything. Did you try it that way? During the first few seconds, the Mega will initialise. But according to the controller spec, PWMH is pulled LOW, so the motors should not run until the Mega pulses PWMH. Next time, test with a small load.


Yesterday the test was with 12V.
During reset or initialising is everthing ok.
What is better, power on similar or use a relay and power on Motors a second later?
Today i will test at 24V

One more info for you OT:
i dont hear a Long tone after calibrate, like written in the readme. 
I also searched and found no code for this tone. Is that right?


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Yesterday the test was with 12V.
> During reset or initialising is everthing ok.
> What is better, power on similar or use a relay and power on Motors a second later?
> Today i will test at 24V
> ...


I'm a bit confused, I thought you said you killed the controllers when testing with 36V.

You should power on everything at the same time. 

Oh yes, looks like I accidentally deleted the buzzer(true) after calibration when I introduced the patterned alarm handler. I have fixed it in v3.5.

BTW, it is normal for the MPU6050 module red LED to be ON when there is power.


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> I'm a bit confused, I thought you said you killed the controllers when testing with 36V.
> 
> You should power on everything at the same time.
> 
> ...


Hello OT,

on sunday evening, i did the first test, and powered the motor controller with 36V (the mega was of), so i saw a little fire at the batterie pole, i tried to connect.

Tommorrow, i will test with 12V and power on both at the same time. We will see, if itt is ok, or better starting the motor one second later.

Here you see the prototype. At the moment, i use my wood router to get my first case.
It makes much fun, to see every day a little more.

Thanks OT for all your fast help and the help i think, i will need in the next days.


----------



## Centrex (Nov 24, 2013)

Hi all
Can someone give me the physical dimensions of the BTS7960 controller please. The dimension that one gets from China vary all over the place.
Regards
Cliff


----------



## chemamata (Oct 20, 2013)

Centrex said:


> Hi all
> Can someone give me the physical dimensions of the BTS7960 controller please. The dimension that one gets from China vary all over the place.
> Regards
> Cliff


I enclose photos in millimeters and inches. regards
If you need the measurements of holes, warns


----------



## chemamata (Oct 20, 2013)

I thought for a little longer, but you control measures, hahahaha


----------



## Centrex (Nov 24, 2013)

Thanks for the pictures unfortunately not what I want, I am after the measurements for the BTS7960 motor controller.
Regards
Cliff
Another question.. 
What is the difference between the BTN7960 and the BTS 7960.


----------



## chemamata (Oct 20, 2013)

Centrex said:


> Thanks for the pictures unfortunately not what I want, I am after the measurements for the BTS7960 motor controller.
> Regards
> Cliff



Sorry. 
So I do not understand what you need. Things google translator


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Thanks for the pictures unfortunately not what I want, I am after the measurements for the BTS7960 motor controller.
> Regards
> Cliff
> Another question..
> What is the difference between the BTN7960 and the BTS 7960.


Width=5cm
Length=5cm
Height=4cm (including heatsink and components)


BTS7960 5.5~27.5V 43A discontinued
BTN7960 4.5~28.0v 47A in production 

You will find that 99% of modules sold as BTS7960 actually has BTN7960 chips on it.


----------



## Centrex (Nov 24, 2013)

Hi Ovaltineo
Thanks for the info, it will help plan where to put components.
Regards
Cliff

Have you ever put any pictures of your segclone on the forum.


----------



## Ovaltineo (Jul 18, 2013)

I've posted some pics in another thread.


----------



## FlyBoyKB (Jan 9, 2014)

Question:

1. Do I need to "tell" the software that I'm using a MEGA other than choosing the MEGA 2560 as the Board in the IDE?

2. I was able to calibrate the MPU-6050 fine. I switched to the run mode, compiled and uploaded in RUN mode. In run I can open the serial monitor and see proper values, but I don't get any motor rotation. Is there a way to test the BTS7960's?

kb


----------



## Ovaltineo (Jul 18, 2013)

The compiler knows that you have chosen MEGA as a board and the application uses this automatically.

Did you uncomment PWM_PWM_CONTROLLER in SegwayClone.h? You need to do this if using the BTS7960.

To test the BTS7960, you can run this:



```
#define RIGHT_BACKWARD_PIN 2
  #define RIGHT_FORWARD_PIN 3
  #define LEFT_BACKWARD_PIN 5
  #define LEFT_FORWARD_PIN 6
  #define MOTOR_ENABLE_PIN 7
 
 
 void initMotors(void)
 {
  pinMode(MOTOR_ENABLE_PIN, OUTPUT);
  pinMode(LEFT_BACKWARD_PIN, OUTPUT);  // set left motor pin to output
  pinMode(LEFT_FORWARD_PIN, OUTPUT);  // set left motor pin to output
  pinMode(RIGHT_BACKWARD_PIN, OUTPUT); // set right motor pin to output
  pinMode(RIGHT_FORWARD_PIN, OUTPUT);  // set right motor pin to output
  analogWrite(LEFT_FORWARD_PIN, 0);  // stop left motor
  analogWrite(LEFT_BACKWARD_PIN, 0);  // stop left motor
  analogWrite(RIGHT_FORWARD_PIN, 0);  // stop right motor
  analogWrite(RIGHT_BACKWARD_PIN, 0);  // stop right motor
  digitalWrite(LEFT_FORWARD_PIN, LOW);
  digitalWrite(LEFT_BACKWARD_PIN, LOW);
  digitalWrite(RIGHT_FORWARD_PIN, LOW);
  digitalWrite(RIGHT_BACKWARD_PIN, LOW);
  digitalWrite(MOTOR_ENABLE_PIN, HIGH);
 }
 
 void controlMotors(int speedL, int speedR) {
  if (speedL<0) 
  {
   speedL = -speedL;
   analogWrite(LEFT_FORWARD_PIN, 0);
   analogWrite(LEFT_BACKWARD_PIN, speedL);
  }
  else
  {
   analogWrite(LEFT_BACKWARD_PIN, 0);
   analogWrite(LEFT_FORWARD_PIN, speedL);
  }
  if (speedR<0) 
  {
   speedR = -speedR;
   analogWrite(RIGHT_FORWARD_PIN, 0);
   analogWrite(RIGHT_BACKWARD_PIN, speedR);
  }
  else
  {
   analogWrite(RIGHT_BACKWARD_PIN, 0);
   analogWrite(RIGHT_FORWARD_PIN, speedR);
  }
 }
 
void setup()
{
  Serial.begin(115200);
  initMotors();
}
 
 
static int speed = 0;
static int increment = 1;
static int count = 0;
 
 
void loop()
{
  speed = speed + increment;
  if (speed >= 127)
    increment = -1;
  else if (speed <= -127)
    increment = 1;
  Serial.print("Speed = ");
  Serial.println(speed);
  controlMotors(speed, speed);
  delay(500);
}
```


----------



## FlyBoyKB (Jan 9, 2014)

I did uncomment the PWM_PWM_CONTROLLER.

As background: This is a self balancing robot model but I'm using the MEGA, BTS7960, MPU6050 with Pololu 12V motors. What might be different is that I'm powering the BTS with a separate 12V lipo and the MEGA thru the USB port. I've tried attaching and not attaching the BTS ground to the MEGA since they are powered by separate power sources thus no common ground. But neither works.

I'll next try the BTS test code and get back to you. Thanks,

kb


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

I tried the BTS test code on both BTS units with no response. 

I did test both motors separately by applying 12volts directly to the motors and both work fine. Any other ideas? From anyone?

Thanks,

kb


----------



## Uri (Nov 2, 2013)

Hi!
My name is Uri and I'm following both "segway's" forums for some time now and I'm highly impressed by the wonderful work you all do here 
Please excuse me for my English, as it not as good as yours
I'm inspired and exiting to work with you guys and to share what I've done so far 
I have 2 projects that I'm working on, an Electric Unicycle (Half Segway?) and Segway clone
Electric Unicycle Parts list:
1 X Arduino Uno R3 compatible
1 X BTN7960 
1 X MPU6050
2 X SLA 12V 7Ah batteries
1 X 24V 250W gearmotor MY1016Z2

Segway clone parts list:
1 X Arduino Mega R3 compatible
2 X MPU6050
1 X Sabertooth 2X25
2 X 24V 250W gearmotor MY1016Z2


Thanks to Ovaltineo schematics and code (Great work) I could test the Unicycle with a small motor and it work very good.
However, I'm facing problems with the Sabertooth,
I changed the Baudrate to 38400 using DEScribe & FTDI cable.
DIP switch is Packetized Serial at address 128. (1,2 OFF 2,4,5,6 ON)
Batteries connected to the Sabertooth
12V power supply to Arduino Mega
Sabertooth S1 to the Arduino Mega pin 7
2 X MPU6050s connected to Arduino Mega (aligned and calibrated and then to “run” mode)
Unfortunately nothing happen and the motor does not spin at all
I saw that *Chemamata faced similar problem, but my address is O.K at 128
It does not work also with the Uno or any other pin.

Very frustrating, I feel like I'm “almost there”....
Any ideas?

Thank you

Here is a short video: http://www.youtube.com/watch?v=NgL4GamNs2Q












My BTN7960 Max 43A DC Motor Driver Drive


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> I tried the BTS test code on both BTS units with no response.
> 
> ...


Can you post pics of the connections to the Mega and the BTS? Maybe you've swapped the pins or something. Maybe you are so unlucky that you got two dud modules.

BTW, with separate power supplies, you MUST connect the +5v and ground from BTS to Mega.


----------



## Ovaltineo (Jul 18, 2013)

Uri said:


> Hi!
> My name is Uri and I'm following both "segway's" forums for some time now and I'm highly impressed by the wonderful work you all do here
> Please excuse me for my English, as it not as good as yours
> I'm inspired and exiting to work with you guys and to share what I've done so far
> ...


Since you have separate power supplies, you need to connect the Arduino ground to the Sabertooth ground.


----------



## FlyBoyKB (Jan 9, 2014)

Oval..
I will post pictures ASAP. In the mean time can I verify the PWM outputs using a voltmeter? Shouldn't I see the voltage from the outputs to the BTS increasing from 0 to 5V as I tilt the robot? If that won't work could I use an LED and resistor and see the brightness change?

kb


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval..
> I will post pictures ASAP. In the mean time can I verify the PWM outputs using a voltmeter? Shouldn't I see the voltage from the outputs to the BTS increasing from 0 to 5V as I tilt the robot? If that won't work could I use an LED and resistor and see the brightness change?
> 
> kb


Yes, I think both of those should work. An analog voltmeter will work better than digital in this case.


----------



## Uri (Nov 2, 2013)

Ovaltineo said:


> Since you have separate power supplies, you need to connect the Arduino ground to the Sabertooth ground.


It is working!! 
Thank you Ovaltineo
Now I can get my hands dirty with the mechanical stuff
I will keep inform


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

As a test, I replaced the Mega with an Uno and - wella - it worked! So I started testing the Mega board and found that some of the PWM pins worked and some didn't. I changed the pin numbers in the motors.h file and now it works! I can't explain the problem with the board and I'll do a better test and document the results to see if there is a pattern. But for now it's working. I do need to increase the sensitivity and motor speed before I can test the robot to stand on its own. I did change the motor_max to 255 but it still is too slow.

Can you give me a direction to go in the code to increase the 'reactions' of the robot?

I'd like to thank you for your efforts with this project and the help you've given me.

kb


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> As a test, I replaced the Mega with an Uno and - wella - it worked! So I started testing the Mega board and found that some of the PWM pins worked and some didn't. I changed the pin numbers in the motors.h file and now it works! I can't explain the problem with the board and I'll do a better test and document the results to see if there is a pattern. But for now it's working. I do need to increase the sensitivity and motor speed before I can test the robot to stand on its own. I did change the motor_max to 255 but it still is too slow.
> 
> ...


Is the max speed too slow even when motor output is 255? If yes, then perhaps your motor is the problem? What are the specifications of the motor? Maybe you need to use a higher voltage. 

But if it is the reaction that is slow (not the max speed) then you should increase KP and KD in SegwayClone.h.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

That helped a lot. I thought I had coded it for 255 max_motor but I guess I hadn't. Also the PID seems to help but I'll have to play with those. 

As reference, what I'm building is inspired by the "Balanduino". Just Google Balanduino. There is a lot of interesting info. There is even a Kickstarter project for it. But their robot project uses a proprietary board thus the open source code won't work with the Mega as written and I'm not yet up to making the necessary code changes. Maybe there is something they have coded that might be useful for this project?

I'll keep working and let you know how it turns out.

Thanks, KB


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> That helped a lot. I thought I had coded it for 255 max_motor but I guess I hadn't. Also the PID seems to help but I'll have to play with those.
> 
> ...


I looked at the Balanduino when I was researching this project. There is a lot of code in it for remote control via Xbox, PS3, and Wii controls which would not be useful (and not work well) with a full-sized Segway. The rest of the code is similar to the code already implemented in this project. 

If you want to use my code for a Balanduino-type project, then you might want to add the Bluetooth module. I actually wrote an Android app to remotely control the Segway but found that it doesn't work well with a bottom heavy Segway. It should work well with a Balanduino-type (top-heavy) Segway though.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

I got the robot model to balance today with your code. He would stay still and upright forever but if I push him too much he oscillates and falls. I think I'll have to work on the PID values.

I have a Bluetooth module I bought for this project like the ones suggested here. If you have Arduino code, installation instructions, and the Android app for steering I'd like to try it. I also plan to add your app for PID settings.

Today I broke a wheel hub so I'm down for a while but I ordered new metal hubs from Pololu this afternoon. For reference, my bot looks just like the Balanduino .

kb


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> I got the robot model to balance today with your code. He would stay still and upright forever but if I push him too much he oscillates and falls. I think I'll have to work on the PID values.
> 
> ...


Unzip the CloneConsole zip file and email the PAK file to yourself. Use your Android phone to open this email and click on the PAK file - it should install. 

Enable the Bluetooth module in SegwayClone.h and enable MODE_CALIBRATE. Load the program and let it calibrate. Disable MODE_CALIBRATE and load the program.

Pair your phone to the Bluetooth module -- it should come up as SEGWAY. When paired, you can launch CloneConsole. The screen should turn white and update in real-time within about 10 seconds.

Let me know if you got this going -- I haven't heard anyone confirm that they can get the app working.

In the meantime, I'll get the remote control function merged with this app. I'll release it if you can get the basic app working.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

I successfully loaded the app to my phone and paired with the HC-06 module. I uncommented the Bluetooth option but had to comment out a few lines in SegwayClone.ino pertaining to the voltage e.g. Vf not declared. Evidently if you don't have certain options activate the code won't verify.

By commenting those few lines the code verified and uploaded to the Mega. I ran in calibrate mode then run mode. Even though the red light on the HC-06 was solid and paired I never saw info coming back to the phone. The numbers and scales on the app screen were very off e.g. temperature, l and R motor Turn and Tilt. The P and D values never changed either.

Here's a Picture of my bot:


----------



## Ovaltineo (Jul 18, 2013)

According to the phone, what is the name of the Bluetooth module? When paired and running, what is the background color of the CloneConsole app?


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

I did some experimenting:
1. The phone discovers "Segway" and the background turns white when it connects.
2. Over a period of time some of the numbers changed occasionally to very strange values.
3. I tried changing to 9600 baud - no luck. So back to 115200.
4. Next - remember I had to comment out the three lines in the SegwayClone.ino in the Bluetooth section dealing with volt since I had no value for Vf. 
*** FIX ***
I uncommented those 3 lines and replaced Vf with 2 so the prog would compile and the serial3.writes would have a volt value to send. Now it works perfect! So I might surmise that the code on the phone is looking for all the data its expecting to receive or it gets 'mangled' and doesn't know what to do.

So I plan to implement the voltage check - although I'll have to make a few changes in the code and voltage divider circuit to handle my 3S (11.7v) source.

If there is anything else I can help test let me know. Now on to the steering?

kb


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

I've done a little more experimenting. I think I can change the Pd and Pi values from the phone and observe the results in the way the motors react to tilts, but maybe the values aren't being saved since the next time you start up the bot and app the last saved Pi and Pd values saved are not displayed on the phone, only the defaults .7 and .3.

I don't quite understand the command 'P' and 'd'. Where are these coming from? And did you mean an uppercase 'P' and a lowercase 'd'?

Thanks, kb


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> I've done a little more experimenting. I think I can change the Pd and Pi values from the phone and observe the results in the way the motors react to tilts, but maybe the values aren't being saved since the next time you start up the bot and app the last saved Pi and Pd values saved are not displayed on the phone, only the defaults .7 and .3.
> 
> ...


Good work!

Yes, the Pd and Pi are not saved to EEPROM, they are only saved to the runtime value. I will add an option in the next version to save it to EEPROM.

The phone communicates with the Arduino using a serial stream via the Bluetooth module. 'P' is a command from the phone (to the Arduino) to save the Pd and Pi values. 'd' is a command from the phone requesting data (telemetry). In the next version, I will add another command to set the tilt and steer offset.

Give me a few days to make these changes.


----------



## Centrex (Nov 24, 2013)

One for Oval
Did you change the 25volt electro caps across the supply to the BTS7960.
It seems a bit dangerous to only have 25volt caps on something that is supposed to work up to at least 24volts.
Caps at least 35 or better still 50volt would be safer.

Regards
Cliff


----------



## Ovaltineo (Jul 18, 2013)

I figured I'll change them when they blow. They haven't done that yet despite all the regenerative braking I'm doing. I've blown one BTN7960 chip though.


----------



## Ovaltineo (Jul 18, 2013)

Ovaltineo said:


> Good work!
> 
> Yes, the Pd and Pi are not saved to EEPROM, they are only saved to the runtime value. I will add an option in the next version to save it to EEPROM.
> 
> ...


I have just released v3.6 with these changes to the Arduino code. 

I'm now working on the Android app to merge the remote control app with the CloneConsole telemetry app.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

Thanks for the new code. I think there is a misspelling in the SegwayClone.ino file. At about line 65. The variable there is EEPROM_PD_ADDR and should be EEPROM_P_ADDR. No biggie. Compiles fine after change.


----------



## schilli (Jan 1, 2014)

Oval...

Hello,

after a horror week, it goes on todoay.

One Question:

I have two TC74A0 and two TC74a2.
Which one should i use?

Thanks a lot


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Oval...
> 
> Hello,
> 
> ...


As per the schematics, you need one of each. You can't use the same chip twice because the address will be the same.


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> Thanks for the new code. I think there is a misspelling in the SegwayClone.ino file. At about line 65. The variable there is EEPROM_PD_ADDR and should be EEPROM_P_ADDR. No biggie. Compiles fine after change.


I actually tested it but must have forgotten to save before zipping .

Just released fix in v3.7 - EEPROM_PD_ADDR should be EEPROM_PD_SAVED_ADDR.


----------



## schilli (Jan 1, 2014)

Hello Oval,

one problem at the moment.
After calibrate, in the run modus, the beeper beeps very often and sometimes stopps for a moment.

in the serial monitor, i saw the motor at 30, so i tested with motormax 60.
the same problem.

Something you have to know, the pololu are not powered, because i am sitting in the office.

You get a picture and two txt from the serial monitor to check please. there is an error code.

Please help me

Info: 
1)i tested bluetooth, paring ok, screen white, but no data
2)i think there is a mistake in the picture with pololu/mega. the lines from the hc-06 rx and tx come to the board tx and rx


One more question please: 
after calibrate, the loooong beep comes. Is it correct, that i now uploade run modus? Because if i start the board a second time in calibrate modus and start then the upload run modus, i do not know, if the eprom is correct.


----------



## schilli (Jan 1, 2014)

Hello OT

It´s now 1 o´clock in the night.

it enough for now.

I wrote many sites here, and if i am correct, the fast beeping will stop if i use the board with tires?
But what is with the mistake in the serial monitor? chamata had the same problem, but i did not found his solution.

I put here one more serial monitor from run mode,
so you can see steering, board, gyro and acc

I hope i will read a solution from you in the next days


----------



## Ovaltineo (Jul 18, 2013)

The constant beeping (motor output at maximum) will stop when you have tires on the ground to provide feedback to the PD loop.

The error 11 is an error in the I2C bus. Make sure all connections are tight and secure (*soldered *to the MPU6050). If this fails, I suggest using shielded cable for the connection between Arduino and the MPU6050 sensors.


----------



## Ovaltineo (Jul 18, 2013)

Ovaltineo said:


> I have just released v3.6 with these changes to the Arduino code.
> 
> I'm now working on the Android app to merge the remote control app with the CloneConsole telemetry app.


I have now released v1.3 of the CloneConsole Arduino app. Press the option menu to switch between "telemetry" screen and "remote control" screen.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

I've downloaded the new 1.3 Android app ( to my Samsung Galaxy S3). The app loads and connects but the option button (lower left on my phone) does not switch screens. Am I doing this incorrectly?

Thanks for your efforts. I don't know how you've learned to do all this programming and do it so quickly? Is this related to your "real" job? 

What software do you use to create the Android app? 

Half a World Away,

kb


----------



## chemamata (Oct 20, 2013)

Hello everyone. 
I've finally finished my clone. 
I still do not dominate, but it will come. I have some photos and a short video. 


Oval. I would like the direction (left or right), more responsive. I mean, no need to move both the "handle". I can tell you as seh ago. 
Thank you all for the help you have given me. And I hope you follow, since this seems to have no end. (good)

The video will not let me upload

Here you can see the video: 
http://youtu.be/oTiYrlTkCcY


----------



## chemamata (Oct 20, 2013)

FlyBoyKB 

look here:

http://madebyfrutos.wordpress.com/2013/05/02/vertibot/


----------



## FlyBoyKB (Jan 9, 2014)

chemamata said:


> FlyBoyKB
> 
> look here:
> 
> http://madebyfrutos.wordpress.com/2013/05/02/vertibot/


Chemamata:

Very nice work! I hope to soon be at your level. I'll try to put up a video when I get there. Can you remotely steer your robot?

KB


----------



## chemamata (Oct 20, 2013)

no no no. 
The page is not mine. Just because it was also have the software and you need to make yours. I think the Segway-clone does not have the same performance.


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> I've downloaded the new 1.3 Android app ( to my Samsung Galaxy S3). The app loads and connects but the option button (lower left on my phone) does not switch screens. Am I doing this incorrectly?
> 
> ...


The menu on my phone is on the bottom right hand side -- see the attached image. I'm surprised that the S3 have it on the other side. In any case, I don't know why this wouldn't work . Let me know if you still can't get it to work -- I will add a button if needed. BTW, what version of Android firmware is on your phone?

I work in IT (looking after application servers and web security). I was a programmer 10 years ago (C & Java) and I taught myself Assembly Language on my ZX81 when I was 14 , so it wasn't too difficult to learn Arduino and Android programming. 

I use Processing 2 for the Android platform.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> Hello everyone.
> I've finally finished my clone.
> I still do not dominate, but it will come. I have some photos and a short video.
> 
> ...


Well done!!! I laughed at the video coz you kept bumping into things . You need to increase STEER_MULTIPLIER in the correct section in SegwayClone.h to get more sensitivity in the steering. Looks like you need to increase KP and KD as well.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> no no no.
> The page is not mine. Just because it was also have the software and you need to make yours. I think the Segway-clone does not have the same performance.


Yes it is not the same - it is better!


----------



## chemamata (Oct 20, 2013)

Ovaltineo said:


> Yes it is not the same - it is better!






Man, I think things are different, not better or worse


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

My phone is a Samsung Galaxy S3 with Android 4.1.2. 

Below is a photo of the screen I see when I open the app. I've noted the option button at the lower left.









kb


----------



## schilli (Jan 1, 2014)

Hello OT,

Error 11 is away. I did new connections. But like in Nr 376, there is at the beginning the message in the monitor "Who i am..."
Is that normal?

Tomorrow, i will marry the mechanic with the hareware!
You will get pictures!


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello OT,
> 
> Error 11 is away. I did new connections. But like in Nr 376, there is at the beginning the message in the monitor "Who i am..."
> Is that normal?
> ...


Yes, it is normal. I thought for a second there that you are going to marry your mechanic !


----------



## Centrex (Nov 24, 2013)

For Ovaltine

I have a Freetronics UNO R3 and a GY521 IMU. the IMU is set up on a level platform. Segwayclone.h is set up for pwm/pwm and pot steering with no other features enabled.
I run the segwayclone in calibration mode which reports no errors with the long beep at the end.
I then run the software in run mode, monitoring the output via the serial information it reports no errors it also shows zero steering angle and a very small number from the IMU (0.05 or thereabouts).
The motor left and right then start to increase until the set figure of 30 is reached.
The IMU is not moved and remains in the location when calibrated.

Two things puzzle me.... one the buzzer never stops beeping at a very rapid rate.
Two why does the motor numbers keep increasing even though the IMU has not moved.

The motor numbers do change if I operate the steering pot but always come back to the 30 figure when the pot is centered, and the continuous noise from the buzzer.

I have used a logic probe on the pwm pins that would go to a bts7960 and I get pulses on say pin 11 with low on 10 if I move the steering pot I can get pulses on pin 10 and a low on pin 11. I do not have a BTS7960 So I dont know if this correct to drive the device and a connected motor.
Regards
Cliff

I see from a previous post that the beeping should stop when I have wheels on the ground.
I remember there was a BTS7960 test program can you tel me where.
Thanks


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> My phone is a Samsung Galaxy S3 with Android 4.1.2.
> 
> ...


I have just released v1.4 of the CloneConsole with an onscreen button (*) to swap the screens.


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> For Ovaltine
> 
> I have a Freetronics UNO R3 and a GY521 IMU. the IMU is set up on a level platform. Segwayclone.h is set up for pwm/pwm and pot steering with no other features enabled.
> I run the segwayclone in calibration mode which reports no errors with the long beep at the end.
> ...


Without wheels on the ground to provide feedback to the PD loop, the motors will increase rapidly. Even without movement, tiny fluctuations on the accelerometer will feed into the PD loop. The beeping is an alarm that the motor has reached MOTOR_MAX.

There is a test program a few pages back from here. I will spend the same amount of time as you searching for it, so please help yourself.

The behavior of pins 10 and 11 as you described are working as expected. The PWM switches between these pins depending on the motor direction.


----------



## FlyBoyKB (Jan 9, 2014)

Ovaltineo said:


> I have just released v1.4 of the CloneConsole with an onscreen button (*) to swap the screens.


I downloaded the new app. Now my option button works to change screens! I get a new screen with X=0 and below that Y=0 and a crosshair.

Will this screen eventually allow me to send steering info to the robot? Will there have to be a new choice for steering type? No hurry on anything. The robot tipped over and jarred some wires loose somewhere. I have ordered new premium jumper wires and I think I will get a solderable perfboard to mount the led's, buzzer, and maybe the voltage divider.

Engineering question: With an 11.7 volt input my calculations say I could use either a 10K and 6.8K resistor set or 1K and 660ohm set. With these low voltages and currents is either one better?

kb


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> I downloaded the new app. Now my option button works to change screens! I get a new screen with X=0 and below that Y=0 and a crosshair.
> 
> Will this screen eventually allow me to send steering info to the robot? Will there have to be a new choice for steering type? No hurry on anything. The robot tipped over and jarred some wires loose somewhere. I have ordered new premium jumper wires and I think I will get a solderable perfboard to mount the led's, buzzer, and maybe the voltage divider.
> 
> ...


There is no need for a new type of steering -- running the CloneConsole disables whatever steering is defined on the clone and enables remote control steering. You just discovered a bug . This is what you want (for a balancing robot), but not what the rest of us needs for a ride-on Segway. I will change the Arduino program so that the steering gets disabled only if the CloneConsole is on the "remote control" screen but not on the "telemetry" screen.

Here's how to use the remote control. Think of the screen as a joystick. The X value affects the left/right movement and the Y value affects the forward/backward movement. Note that robot will keep it's momentum even at centre stick (or finger off the screen), you need to input gradual opposite input to stop it. It is similar to flying a helicopter.

Use the 10K and 6.8K. Using the lower value resistors will unnecessarily drain 10X the current.


----------



## Ovaltineo (Jul 18, 2013)

I've just released v3.8 of the Arduino program.


v3.8 Fixed "remote control" bug - local steering is now disabled only when CloneConsole Android app is on "remote control" screen.


----------



## chemamata (Oct 20, 2013)

Hello 
I have finished my "clone". Each day is better adjusted. 
When you put the electronics had many problems, all summarized in one. (And what it cost me to find!. Damn) 
configuration: 
2xBTS7960 
2xMPU6050 
When running "caliber", so good. 
When executing "run". For the "monitor", so good. But the "clone" hacvía weird things. Very rare. 
solution: 
run "calibrate" normal. 
before running "run" that controls the MPU6050 go forward and do you have to give back swing. It is looking forward to calibrate, put it back to "run". So I did and is working well. I know it sounds a little odd, but is well running. 
I have found no explanation yet. 
I mention this so that you may assist a colleague to the same thing happens.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> But the "clone" hacvía weird things. Very rare.


There is some meaning lost in the English translation. I don't understand. can you describe what happens when you "run" the clone after normal calibration?

Two questions - is the clone level when you load the program in calibrate mode? Is the clone still level when you load the program in run mode? 



> solution:
> run "calibrate" normal.
> before running "run" that controls the MPU6050 go forward and do you have to give back swing. It is looking forward to calibrate, put it back to "run".


I don't understand this either. Are you saying that you deliberately move the clone during calibration to fix the "problem" you are trying to describe above?


----------



## schilli (Jan 1, 2014)

Hello ot, hello all,

my fist prototype is ready, you see the pictures and my mistakes i did 3 o´clock in the morning. The first test with 12v was ok at 255 without me. After testing 24v, the connection between motor and tire is is not strong enough.
I will fix this problem today.

At the moment with the three batteries the clone is too big.
i think, i will order lifepo, so the motors are nearer togeather and lower weight.

OT question:

clone is in run modus, i want to calibrate. So i connect to pc and start upload. But before the clone starts for a short while in run mode.

I have one time more to say:

Thank you for all your help.

At last, the last picture should be what i want to get in future! If somebody knows the homepage of this picture, please tell me, because i saved this picture a long time ago.

OT: 
I did not have a mechanic  to marry


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello ot, hello all,
> 
> my fist prototype is ready, you see the pictures and my mistakes i did 3 o´clock in the morning. The first test with 12v was ok at 255 without me. After testing 24v, the connection between motor and tire is is not strong enough.
> I will fix this problem today.
> ...


Nice work!!!

Yes, clone will run in the current mode until loading of the program (with new mode) is complete. Hence, battery power MUST be OFF while uploading a program.

It will be better if you can fit the steering bearings inside the case. Maybe just invert the cover and move the springs to the front?


----------



## chemamata (Oct 20, 2013)

Ovaltineo said:


> There is some meaning lost in the English translation. I don't understand. can you describe what happens when you "run" the clone after normal calibration?
> 
> Two questions - is the clone level when you load the program in calibrate mode? Is the clone still level when you load the program in run mode?
> 
> I don't understand this either. Are you saying that you deliberately move the clone during calibration to fix the "problem" you are trying to describe above?



First I climb the MEGA firmware in "calibrate" 
Then, without touching anything, get in the MEGA firmware in "run" mode. 
Now is when you do strange things. starts spinning. 
Solution. 
give half back to gyroscopio that controls go forward and backward, which is forward, put it back. And cough resolved. 
I hope you now understand


----------



## chemamata (Oct 20, 2013)

schilli. 
That job of yours looks great. 
encouragement


----------



## chemamata (Oct 20, 2013)

OT. 
Can you tell me the difference between KP and KD. 
I think I find it easier to adjust, knowing what I play? 
thanks


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

The new phone app steering screen seems to work well. I can only test it visualizing the steering angle numbers in the terminal screen as one of my BTs7960's failed. ( I have a new one on order.)

On the main screen of the app - observations:
- the P and D values are not read from the device and displayed to the screen. I've tested this by changing them in the IDE and uploading. Connecting the app and the app always says .7 and .3.
- the P and D bars adjust to 'minus' values and a max of about 4.17. The 4.17 'might' be sufficient but should the values ever go negative?
- adjusting either the P or D values around 1.4 or so caused the value and adjustment bar to go negative and save the negative values to the machine.
- after several adjusts and saves the app brown adjustment bar completely disappeared.

I added code to the terminal display to show the Pf and Df values. They indeed went negative. I then closed the terminal screen. Disconnected. Reconnected and uploaded the code from the IDE. When I started the terminal screen surprisingly the values from the SegwayClone.h file had not over written the old values. The terminal screen displayed the old values saved from the app. Just something you might want to test.

As yet I have no way to test the temperatures or battery voltage.

Just observations. In NO way are they criticisms. I think you've done a marvelous job. I'm envious of your abilities.

As always if there's something I can help test just let me know.

kb


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

I did some more testing and found that the PID values in the SegwayClone.h file aren't saved unless you're in Calibrate. I guess that makes sense as is?

kb


----------



## schilli (Jan 1, 2014)

Hello all,

if you see my pictures below, you will see, that the third batterie make the clone too big.
Now i want to install another type of battery. What would you take?

1) LiPo
2) LiFePo4

OT: the springs are in front


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> The new phone app steering screen seems to work well. I can only test it visualizing the steering angle numbers in the terminal screen as one of my BTs7960's failed. ( I have a new one on order.)


Wow, how did you manage to blow one of those BTS7960 with such small motors? They are supposed to work up to 43A .


> On the main screen of the app - observations:
> - the P and D values are not read from the device and displayed to the screen. I've tested this by changing them in the IDE and uploading. Connecting the app and the app always says .7 and .3.


KP and KD values are now stored in EEPROM and reset from SegwayClone.h only during calibration.


> - the P and D bars adjust to 'minus' values and a max of about 4.17. The 4.17 'might' be sufficient but should the values ever go negative?


No, it is a bug. I will fix it. I can increase the max to 10 or more but resolution will decrease.


> - adjusting either the P or D values around 1.4 or so caused the value and adjustment bar to go negative and save the negative values to the machine.
> - after several adjusts and saves the app brown adjustment bar completely disappeared.


I think you found another bug .


> I added code to the terminal display to show the Pf and Df values. They indeed went negative. I then closed the terminal screen. Disconnected. Reconnected and uploaded the code from the IDE. When I started the terminal screen surprisingly the values from the SegwayClone.h file had not over written the old values. The terminal screen displayed the old values saved from the app. Just something you might want to test.


KP and KD values are now stored in EEPROM and reset from SegwayClone.h only during calibration. I've just realized that this should only happen for those with Bluetooth enabled.


> As yet I have no way to test the temperatures or battery voltage.
> 
> Just observations. In NO way are they criticisms. I think you've done a marvelous job. I'm envious of your abilities.
> 
> ...


Bug reports are ALWAYS welcome . It means someone is actually testing the code, not just myself.


----------



## Ovaltineo (Jul 18, 2013)

chemamata said:


> OT.
> Can you tell me the difference between KP and KD.
> I think I find it easier to adjust, knowing what I play?
> thanks


KP is the Proportional multiplier. It is multiplied with the angle of tilt which the accelerometer can measure. So more tilt will result in higher motor output.

KD is the Derivative multiplier. Derivative is the change in angle over time (angular velocity) which the gyro can measure. KD is multiplied with the gyro output. So a fast tilt will result in higher motor output. The angular velocity can get much bigger than the tilt angle, hence KD is less than KP.


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello all,
> 
> if you see my pictures below, you will see, that the third batterie make the clone too big.
> Now i want to install another type of battery. What would you take?
> ...


I'm using 2 X 4300ma 11.1v Lipos. I will get bigger ones if I were you. I have no experience with LiFePo4 so I don't know which is better.

When I say in front, I meant the face/bumper of your machine. The way it is, your feet will get caught in the springs in case you over tilt. It is much safer to keep the top platform clear. Here's how my v1 mine looks like. My v2 looks the same except there is no more box (with battery) at the front.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

Just curious about the time difference. It is 4pm here Sunday afternoon.. What's the corresponding day and time is it in Australia?

The BTN7960 I think was not working entirely correctly from the start. Then it just stopped working all together. The soldering job on that board was not the best!

While I'm waiting for the new components I'm relocating existing ones. I also hope to make a board with the voltage divider, LEDs. buzzer, HC-06, and power connection. I've never tried to make such a thing. We'll see how that works out.

kb


----------



## Ovaltineo (Jul 18, 2013)

4pm Sunday in Ohio is 8am Monday in Melbourne during summer (DST).
I use an Arduino Mega prototyping board to fit those components and connectors.


----------



## Centrex (Nov 24, 2013)

Hi Ovaltino

In the dwg for the UNO and BTN7960 you show pins 10 and 11 going to the left hand motor and pins 3 and 9 going to the right hand motor.

In the motors.h file you have defined RIGHT_BACKWARD_PIN as 9
RIGHT_FORWARD_PIN as 10
LEFT_BACKWARD_PIN as 3
LEFT_FORWARD_PIN as 11

This appears to be in conflict with the dwg.

The pins you have allocated for the mega have the correct relationship in the motors.h file and the dwg.

Am I missing something.
regards
Cliff


----------



## Ovaltineo (Jul 18, 2013)

Well spotted. It is a bug in the schematic. The software is correct.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

I hate to ask, but do you have a picture of the prototype board with the components? 

I just ordered a prototype board for this project.

kb


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> I hate to ask, but do you have a picture of the prototype board with the components?
> 
> ...


Take a look at post #94 here http://www.diyelectriccar.com/forums/showthread.php?p=362682#post362682

It's very crowded with a lot of connectors.


----------



## Centrex (Nov 24, 2013)

Hi
Getting the pin numbers correct on the UNO has made the world of difference I can now balance my test platform and stop the buzzer from beeping. 
Have there been any updates to the balancing in the software since you have added the Bluetooth options.
Thanks Oval for your quick update on the pins.
Cliff


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> On the main screen of the app - observations:
> - the P and D bars adjust to 'minus' values and a max of about 4.17. The 4.17 'might' be sufficient but should the values ever go negative?
> - adjusting either the P or D values around 1.4 or so caused the value and adjustment bar to go negative and save the negative values to the machine.
> - after several adjusts and saves the app brown adjustment bar completely disappeared.


I think I've fixed these bugs on the Android app. 

CloneConsole v1.5
Fixed bug where P and D values can become negative. Increased P and D range by using exponential range, however, resolution decreases exponentially too.


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Hi
> Getting the pin numbers correct on the UNO has made the world of difference I can now balance my test platform and stop the buzzer from beeping.
> Have there been any updates to the balancing in the software since you have added the Bluetooth options.
> Thanks Oval for your quick update on the pins.
> Cliff


Good to hear! 
You can check the changes for each release on post #1. There is no change in the balancing algorithm, but worthwhile changes if using the Android app.


----------



## schilli (Jan 1, 2014)

What a shit,

i think, the second two motor controllers are dead.
yesterday, i tested the clone with the new connection between motor and tires and heared something. So i lift up and started a second time.
Both motors are running fast forward. I stoped the power suply and
THE MOTORS STOPPED HARD. I think the controllery are dead.

OT,
what do you think about drive-coast mode?
Esle, i have to put a manual switch to the motor and turn this off before arduino off.
But i have luck, i have two btn here, so i can test the new batteries today.
LiFePo are working at -20 degree.

One more info for you OT for the app: I installed on HTC HD2 and i can´t see the complete display. On my new S4 active the display shows everything and there is much free room.
Excuse my bad english.


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> What a shit,
> 
> i think, the second two motor controllers are dead.
> yesterday, i tested the clone with the new connection between motor and tires and heared something. So i lift up and started a second time.
> ...


Why is it a problem when turning off the clone? A single switch that turns off everything is not OK? I don't think it would have caused the problem you described above.

I haven't used a controller in drive-coast mode before -- you can always try it -- it shouldn't break anything that drive-brake mode hasn't already broken .

The Android app is hard-coded for a 1280 x 720 screen. It will take me a LONG time to make it scalable to different screen sizes. I might do it someday if enough users ask for it.


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> Why is it a problem when turning off the clone? A single switch that turns off everything is not OK? I don't think it would have caused the problem you described above.


I think, if i turn off everything at the same time, the motor controller becomes no signal any more and goes in stop modus. So the still running motors will make a very high power for a short time.
At the moment i disconnect / connect the power from battery to motordriver. I think it could be better to connect between controller and motor?!




Ovaltineo said:


> I haven't used a controller in drive-coast mode before -- you can always try it -- it shouldn't break anything that drive-brake mode hasn't already broken .
> 
> The Android app is hard-coded for a 1280 x 720 screen. It will take me a LONG time to make it scalable to different screen sizes. I might do it someday if enough users ask for it.


I only wanted to inform you. For me absolutely ok!



But ant other question, would it be able to write an extra code to program without many hours, so that i can connect a switch, where i can decide calibrate or run without new uploud.
I could think other would like this too.


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> I think, if i turn off everything at the same time, the motor controller becomes no signal any more and goes in stop modus. So the still running motors will make a very high power for a short time.
> At the moment i disconnect / connect the power from battery to motordriver. I think it could be better to connect between controller and motor?!


Most of us would be switching off everything by turning off the power from the battery. Doing this while the motors are turning should not be a problem, even if the controller stops the motors - the FETs will handle back-EMF from the motor and most of the power would dissipate as heat in the motor coils. Can you confirm that your controllers have died (twice) this way? If so, stay away from those controllers.



> I only wanted to inform you. For me absolutely ok!
> 
> But ant other question, would it be able to write an extra code to program without many hours, so that i can connect a switch, where i can decide calibrate or run without new uploud.
> I could think other would like this too.


Well, looks like it is easy to make the Android app scalable without re-writing most of the code. I found this function called scale(X,Y)! 
And yes, I will add a calibrate button.


----------



## Uri (Nov 2, 2013)

Hi

As I see that many of us have problems with the BTN's drivers I wonder what will be the most effective motor drive for our needs

I got this list from Ebay, 

What do you think?


http://www.ebay.com/itm/DC-12-30V-5...405?pt=LH_DefaultDomain_0&hash=item27cb6f2cfd

http://www.ebay.com/itm/3v-36V-Dual...872?pt=LH_DefaultDomain_0&hash=item43bd1190f0

http://www.ebay.com/itm/Double-BTS7...077?pt=LH_DefaultDomain_0&hash=item4179b3e96d

http://www.ebay.com/itm/30A-Single-...714?pt=LH_DefaultDomain_0&hash=item3a80b7c292

http://www.ebay.com/itm/New-50A-Sin...023?pt=LH_DefaultDomain_0&hash=item3384da7b4f


http://www.ebay.com/itm/43A-BTS7960...806?pt=LH_DefaultDomain_0&hash=item27d447dc5e

http://www.ebay.com/itm/Double-BTS7...112?pt=LH_DefaultDomain_0&hash=item27cb805a48


Uri


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> Most of us would be switching off everything by turning off the power from the battery. Doing this while the motors are turning should not be a problem, even if the controller stops the motors - the FETs will handle back-EMF from the motor and most of the power would dissipate as heat in the motor coils. Can you confirm that your controllers have died (twice) this way? If so, stay away from those controllers.
> 
> 
> Well, looks like it is easy to make the Android app scalable without re-writing most of the code. I found this function called scale(X,Y)!
> And yes, I will add a calibrate button.


Hello OT,

a few minutes ago, i checked everything and saw that the fuse was dead. I was happy! Then i tested and must see, that one controller was out of order. He started with burning.
Tomorrow i get a new one, and will do the last test. If he goes out again, i will change to btn.

Here you can see the new battery, so that i can make the case closer.
And for you two pictures from the app on htc and s4.

It very nice to get so much help from you. I hope i can step on the clone in a few days with the new case.
After that i will start with bluetooth and tc74.

I am happy to hear, that you plan a calibrate button


----------



## Ovaltineo (Jul 18, 2013)

I have just released v1.6 of the Android app. Please let me know if it scales properly on your phones.

I will add the Calibrate button in the next release -- it is more complicated than I thought.


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> I have just released v1.6 of the Android app. Please let me know if it scales properly on your phones.
> 
> I will add the Calibrate button in the next release -- it is more complicated than I thought.


Hello ot, a very fast work. 
The first screen is perfect on the s4. The screen with thecross is not in the middle and not complete to see. 
Pictures in a Fee hours, it is very late in germany


----------



## Ovaltineo (Jul 18, 2013)

I just released v1.7 of CloneConsole to fix the scaling of the remote control view.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

Just FYI - The new 1.7 console version looks perfect on my Samsung Galaxy S3.

kb


----------



## Ovaltineo (Jul 18, 2013)

Uri said:


> Hi
> 
> As I see that many of us have problems with the BTN's drivers I wonder what will be the most effective motor drive for our needs
> 
> ...


Only 5A. Don't buy this.



> #2 http://www.ebay.com/itm/3v-36V-Dual...872?pt=LH_DefaultDomain_0&hash=item43bd1190f0


15A may not be enough. Needs heatsink and solder on the power traces to handle more current. Easy to replace FETs if they blow.




> #3 http://www.ebay.com/itm/Double-BTS7...077?pt=LH_DefaultDomain_0&hash=item4179b3e96d


This is what I use. 



> #4 http://www.ebay.com/itm/30A-Single-...714?pt=LH_DefaultDomain_0&hash=item3a80b7c292


Initially looks good, but this is only 12V! You can't use this.



> #5 http://www.ebay.com/itm/New-50A-Sin...023?pt=LH_DefaultDomain_0&hash=item3384da7b4f


Looks exactly like #4 above with a higher current rating. But still only 12V. You can't use this.


> #6 http://www.ebay.com/itm/43A-BTS7960...806?pt=LH_DefaultDomain_0&hash=item27d447dc5e


Essentally the same as #3 but without heatsink. Don't buy this.



> #7 http://www.ebay.com/itm/Double-BTS7...112?pt=LH_DefaultDomain_0&hash=item27cb805a48


This is the same as #3, except the vendor (wrongly) claims 68A instead of 43A.


----------



## wired (Nov 24, 2013)

Ovaltineo said:


> Only 5A. Don't buy this.
> 
> 
> 15A may not be enough. Needs heatsink and solder on the power traces to handle more current. Easy to replace FETs if they blow.
> ...


Hello Ovaltineo,
I saw this link that has a dual motor controller that can be plugged in as a shield to reduce the wiring:
http://www.aliexpress.com/item/50A-...ive-module-Arduino-Compatible/1598609418.html

But it looks as if the required control functions are slightly different to what you use for the Uno and Mega.

Cheers,
Darcy


----------



## schilli (Jan 1, 2014)

Hello OT,

today was the next test after changing the motor controller.
With 12V perfect. 
After changing to 24V perfect for a few seconds and after that the clone always wants to go forward quiet hard.

Do you have any idear?

Greets from Germany

Chris


----------



## chemamata (Oct 20, 2013)

wired. 

Look at this:

http://www.aliexpress.com/item/50A-...e-for-Smart-Car-Strong-Braking/709407235.html


----------



## robertholmberg (Oct 26, 2013)

chemamata said:


> wired.
> 
> Look at this:
> 
> http://www.aliexpress.com/item/50A-...e-for-Smart-Car-Strong-Braking/709407235.html


Hi,

this is the same "problem" as the ones in the long list on the last page: Rated voltage: 3V-15V. You cant use 24 volt or even higher. So its not useful us long as not playing with only 12 Volt.

/Robert


----------



## Ovaltineo (Jul 18, 2013)

wired said:


> Hello Ovaltineo,
> I saw this link that has a dual motor controller that can be plugged in as a shield to reduce the wiring:
> http://www.aliexpress.com/item/50A-...ive-module-Arduino-Compatible/1598609418.html
> 
> ...


I think I can modify the code to support it. Are you using an UNO or Mega?


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Hello OT,
> 
> today was the next test after changing the motor controller.
> With 12V perfect.
> ...


Which motor controller are you using? Can you post pictures of all connections? What voltage are you supplying to the Arduino? Separate battery or dc-to-dc converter?


----------



## chemamata (Oct 20, 2013)

True, he had not noticed. 
Sorry


----------



## schilli (Jan 1, 2014)

Good evening ot, 
After sleeping a night and a little bit Brainstorming, could it be that i have to change something like pid ob kp kd? Wenn i increase to 24v and the Motors have so much Power. 
I think i have to teach the sSoftware not to give so much Power by a little angle forward. 
But how?


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> Which motor controller are you using? Can you post pictures of all connections? What voltage are you supplying to the Arduino? Separate battery or dc-to-dc converter?


1 Polle 36v 23a 
2 connection like your picture on site 1
3 ca 11,5v with dc to dc


----------



## wired (Nov 24, 2013)

Ovaltineo said:


> I think I can modify the code to support it. Are you using an UNO or Mega?


Hello Ovaltineo and thank you for your encouraging response. I am currently using a Uno (actually a Magpie from LittleBird) with 2 7960 controllers but would prefer to use the dual controller shield to reduce the wiring. 

Thanks,
Darcy


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Good evening ot,
> After sleeping a night and a little bit Brainstorming, could it be that i have to change something like pid ob kp kd? Wenn i increase to 24v and the Motors have so much Power.
> I think i have to teach the sSoftware not to give so much Power by a little angle forward.
> But how?


I'm confused with your description of what is happening. You said at 24v it is perfect for a few seconds and then always wants to go forward. Even if you tilt back, it still wants to go forward? If yes, then changing PD & KD cannot fix this. Did you check the output voltage of the dc-to-dc converter after changing to 24v? Did you reduce the battery back to 12v to check that everything is still working properly? Did you connect ground between Arduino and controller? You shouldn't. 

Please post pictures - there is no point telling me it is like my schematic.


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> I'm confused with your description of what is happening. You said at 24v it is perfect for a few seconds and then always wants to go forward. Even if you tilt back, it still wants to go forward? If yes, then changing PD & KD cannot fix this. Did you check the output voltage of the dc-to-dc converter after changing to 24v? Did you reduce the battery back to 12v to check that everything is still working properly? Did you connect ground between Arduino and controller? You shouldn't.
> 
> Please post pictures - there is no point telling me it is like my schematic.


Ok ot,

i will try one more and give you some pictures.
with 12v and motor max everything was perfect.
After that, i tried 24V. The first few seconds everything was ok. The reaction of the motors was quiete hard. And suddenly the clone always wants to go forward, no reaction when i tilt back or tried to steer.

You get some pictures, i hope they will help.

But at the moment i have one more problem, the connetions between motor and axle from the tyres is not strong enough.
I will cut two flanges, then the problem is away.
At the test the connection was still ok. 

In my oppinion as an beginner, i would they, that the software give to much power to the motors with 24v or better the motors have to much power.


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Ok ot,
> 
> i will try one more and give you some pictures.
> with 12v and motor max everything was perfect.
> ...


The higher voltage will produce stronger spikes from the motors -- these can cause a glitch. I have experienced this problem when I was using my own home-made motor controller. It worked at 12V but at 24V it was prone to "locking up" and going to full power. I got rid of the problem by using completely isolated power supply for the Arduino and using opto-couplers for the signals. It was too complicated so I switched to the BTS7960 controllers which did not have this problem.

Make sure there is no ground connection from the Pololu except to the battery. If you have already done this, then I can only suggest changing to a different controller like I did.


----------



## wired (Nov 24, 2013)

Ovaltineo said:


> The higher voltage will produce stronger spikes from the motors -- these can cause a glitch. I have experienced this problem when I was using my own home-made motor controller. It worked at 12V but at 24V it was prone to "locking up" and going to full power. I got rid of the problem by using completely isolated power supply for the Arduino and using opto-couplers for the signals. It was too complicated so I switched to the BTS7960 controllers which did not have this problem.
> 
> Make sure there is no ground connection from the Pololu except to the battery. If you have already done this, then I can only suggest changing to a different controller like I did.


Here is a Pololu link regarding RFI motor suppression:
http://www.pololu.com/docs/0J15/9

Darcy


----------



## schilli (Jan 1, 2014)

Good morning from germany OT and all others

As soon as my connection between motor and tyres is fixed, i will try an extra power supply for arduino.
And like you say ot, if it will go >> ok, if not, i will chanche to bts/btn.


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Good morning from germany OT and all others
> 
> As soon as my connection between motor and tyres is fixed, i will try an extra power supply for arduino.
> And like you say ot, if it will go >> ok, if not, i will chanche to bts/btn.


In my experience, a separate power supply for the Arduino is not useful unless you use opto-couplers between the Arduino and the controller. Because without opto-couplers, you need to connect the ground from the Arduino battery to the controller logic ground -- spikes will travel through this ground. Try the recommendations from the link that Darcy (wired) has posted.


----------



## Centrex (Nov 24, 2013)

Hi Oval
Another problem has cropped up.
PWM PWM with pot (10k) steering has a problem whenever the pot exceeds +30 or -30 as reported by the serial output the motor output and direction can do a sudden reversal of the output.
Changing the steering multiplier appears to have no effect.
If necessary I will try and include the output from the serial connection. Perhaps the software needs to include something to limit the range of the steering pot.
Regards
Cliff


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Hi Oval
> Another problem has cropped up.
> PWM PWM with pot (10k) steering has a problem whenever the pot exceeds +30 or -30 as reported by the serial output the motor output and direction can do a sudden reversal of the output.
> Changing the steering multiplier appears to have no effect.
> ...


Did you set MOTOR_MAX to 255? Did you reduce the steer multiplier in the correct section of SegwayClone.h? 

Post the serial output so we can see what's going on. 

It maybe normal -- one motor becomes positive and the other negative if you turn while not moving forward or backward.


----------



## Centrex (Nov 24, 2013)

Hi Oval

Steer multiplier set to 1.5 Motor max to 255.

makes no difference as soon as the steer pot reaches 30 it abruptly goes to -30 and vice versa.
one motor says it is running at 255 as the pot is varied the other motor slows down until the critical point then both motors reverse.

all of this is done of course with the wheels jacked up as it would take off like rocket.

cant get a screen grab.
regards
Cliff



edit the motors keep going in the same direction but the speed has swapped from left right and vice versa this all happens as the steer pot passes through 30 or -30.


----------



## schilli (Jan 1, 2014)

Hello OT,

now my mechanic connetion between motor and axle from the wheel is ready.
You can see a picture below.

I will try it with a second power supply and if i have no success, i will change the controller. I have two still here.


----------



## Centrex (Nov 24, 2013)

Here is the serial output dump which shows the abrupt change from -31 to +31

regards
Cliff


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Here is the serial output dump which shows the abrupt change from -31 to +31
> 
> regards
> Cliff


It was an integer to float conversion bug. I've just released v3.9 to fix it.


> v3.9 Fixed integer conversion error when using POT_STEERING. Added Bluetooth command to initiate calibration. During startup, P and D values are retrieved from EEPROM only if BLUETOOTH is enabled.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

While I'm waiting for a new 7960 to arrive from China I've been thinking. (Always dangerous!) Have you given any thought to incorporating wheel encoders to the program? The motors I have for my mini bot (Pololu 37D http://www.pololu.com/product/1443) have encoders. The research I've done indicates the incorporation of encoder information to the motor function can increase the performance of the bot. Are these used on full sized Segway Clones?

kb


----------



## Ovaltineo (Jul 18, 2013)

Wheel encoders will definitely improve the performance, especially for a full-sized clone. It will enable the rider to maintain a steady lean and go over bumps and hills - the motor output increases if the wheels are not turning fast enough. 

I don't have wheel encoders, so writing complicated code to support it for the multiple controllers that I also don't have would be crazy.

It will be complicated coz its another PID loop. It is best employed in the motor controller itself. The Roboclaw motor controller supports encoders and would be the best solution for this.


----------



## FlyBoyKB (Jan 9, 2014)

Thanks Oval. I can see integrating encoders would be a nightmare for one let alone multiple motor/controller combinations. I'm trying to teach myself enough C language to 'attempt' doing it myself for my minibot. Normal Arduino code is pretty self explanatory but I'm getting lost with the attachInterrupt and direct manipulation of the registers. I'll get a book and study other peoples code and see what I can do.

kb


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Thanks Oval. I can see integrating encoders would be a nightmare for one let alone multiple motor/controller combinations. I'm trying to teach myself enough C language to 'attempt' doing it myself for my minibot. Normal Arduino code is pretty self explanatory but I'm getting lost with the attachInterrupt and direct manipulation of the registers. I'll get a book and study other peoples code and see what I can do.
> 
> kb


There is no need to learn about interrupts or direct manipulation of registers. You can use the following library to measure the frequency of the encoder pulse output. It happens in the background so the PID loop timing will probably not be affected.
http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/


----------



## Centrex (Nov 24, 2013)

Ovaltineo said:


> It was an integer to float conversion bug. I've just released v3.9 to fix it.


Thanks Oval I will check it out on the weekend, but I am sure all will be OK now. May still limit the steering pot travel initially for safety sake.
Regards
Cliff


----------



## schilli (Jan 1, 2014)

Good evening from germany

Today, i changed from pololu to btn7960.
Every cable like the picture on site 1.
But nothing happens with the motors


----------



## Ovaltineo (Jul 18, 2013)

Did you select PWM_PWM_CONTROLLER in SegwayClone.h?


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> Did you select PWM_PWM_CONTROLLER in SegwayClone.h?


Yes, i did.
And i checked 24v for motor are ok.


----------



## Ovaltineo (Jul 18, 2013)

schilli said:


> Yes, i did.
> And i checked 24v for motor are ok.


You haven't blown a fuse like last time? On the serial monitor, are the motor outputs ok? Can you check the PWM output with an oscilloscope or logic probe?

Can you post CLEAR (last ones were blurred) pictures of connections on Arduino AND motor controllers?


----------



## Uri (Nov 2, 2013)

Hi
While I'm waiting for more parts to come by the mail I've found the
Teensy USB Board, Version 3.1
https://www.pjrc.com/store/teensy31.html

It does look very impressive & powerful. The price is just under $20 a piece

Is it any good for us?

Regards 

Uri


----------



## Centrex (Nov 24, 2013)

wired said:


> Hello Ovaltineo,
> I saw this link that has a dual motor controller that can be plugged in as a shield to reduce the wiring:
> http://www.aliexpress.com/item/50A-...ive-module-Arduino-Compatible/1598609418.html
> 
> ...


Hi Oval
Ver 3.9 works beautifully with pot steering and playing around with the steering multiplier gives very good sensitivity to the steering.

Have you given any thought to implementing the dual controller that Wired (Darcy) mentioned, certainly tidy up some of the wires running around the base.
Regards
Cliff


----------



## Ovaltineo (Jul 18, 2013)

Uri said:


> Hi
> While I'm waiting for more parts to come by the mail I've found the
> Teensy USB Board, Version 3.1
> https://www.pjrc.com/store/teensy31.html
> ...


I honestly don't know if it will work. There is no advantage using a 32-bit processor for this purpose. For $17, I'd prefer an Arduino MEGA clone which has multiple serial ports, and plenty of room to put connectors and other components when used with a prototype board.


----------



## electricpolo (Mar 15, 2011)

First up, thank you Ovaltineo and all the other contributors for the huge effort that has gone into this project & thread.
I built a LiFePo powered VW Electric Polo 2 1/2 years ago from an open source project just like this. The car has now done over 35,000 kms.
I have decided to turn my hand at building one of these as they have always intrigued me.
Rough plans include 19x7 quad wheels & tyres, lithium battery pack, dual 24V 500W motors geared down with toothed belts, Roboclaw 2x60A controller & a rider LCD display panel for battery & speed.

A couple of questions for those that may know the answer.
Would it be possible to double up on the MPU6050 ie have 2 on the steering & 2 on the tilt with the second pair going to say A1 & A2. 
The software would add the 2 results & use the average.
This would introduce a level of redundancy should one of the MPU6050s fail in service.
I think also that using Smoothing on the A3 input would be very beneficial. The pack voltage in my car during normal driving can vary anywhere from 149V to 125V just due to sag.
Perhaps a low value poly cap & a high value bleed resistor across A3 & Gnd could also help to smooth out the rapid fluctuations.


----------



## markula (Oct 27, 2013)

Hi 

If some have trubles with the BTN 7960. 
I found this on Ebay yesturday. 

http://www.ebay.com/itm/1pcsx-New-D...ltDomain_0&hash=item3a7b9af952#ht_3662wt_1125

I am pretty sure that is use the same singal ( PWM,PWM) That the BTN use. but is have 4 220 package mosfets. 

If you change heatzink a to220 pacage can easy handle 50A continues.


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Hi Oval
> Ver 3.9 works beautifully with pot steering and playing around with the steering multiplier gives very good sensitivity to the steering.
> 
> Have you given any thought to implementing the dual controller that Wired (Darcy) mentioned, certainly tidy up some of the wires running around the base.
> ...


I will add support if someone confirms to have bought it.


----------



## electricpolo (Mar 15, 2011)

The RoboClaw can also read main battery voltage. 
Perhaps it can be used in conjunction with Smoothing for the voltage check & do away with the divider.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> First up, thank you Ovaltineo and all the other contributors for the huge effort that has gone into this project & thread.
> I built a LiFePo powered VW Electric Polo 2 1/2 years ago from an open source project just like this. The car has now done over 35,000 kms.
> I have decided to turn my hand at building one of these as they have always intrigued me.
> Rough plans include 19x7 quad wheels & tyres, lithium battery pack, dual 24V 500W motors geared down with toothed belts, Roboclaw 2x60A controller & a rider LCD display panel for battery & speed.
> ...


 In my opinion, adding redundancy on the MPU6050 is like adding another steering wheel on a car, it is a bit of an unnecessary overkill. Due to the high power involved, the most likely component to fail in a Segway clone are the motor controllers, followed by the drivetrain. But these are also very difficult to make redundant -- hence the high cost of a real Segway. In any case, there are only 2 addresses possible for the common MPU6050 module, adding 2 more will require a separate I2C bus (it is not an analog gyro+accelerometer).

When I added the voltage sensor, I wanted to see the voltage fluctuations of the battery, hence, I didn't add any capacitor or averaging algorithm. I leave it to you guys to modify the circuit or program to suit your own preference.


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> Hi
> 
> If some have trubles with the BTN 7960.
> I found this on Ebay yesturday.
> ...


I can't say that the signals are the same -- there is no documentation on that link.


----------



## markula (Oct 27, 2013)

Ovaltineo said:


> I can't say that the signals are the same -- there is no documentation on that link.


 



http://www.ebay.com/itm/DC-15-24V-4...ltDomain_0&hash=item2a23476fb3#ht_5451wt_1363


----------



## electricpolo (Mar 15, 2011)

Thanks for the explanation, Ovaltineo. Hadn't realised about the MPU6050 address issue.
I've already ordered some parts & am looking forward to this project. Will post some pics when there is something to see..


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> http://www.ebay.com/itm/DC-15-24V-4...ltDomain_0&hash=item2a23476fb3#ht_5451wt_1363


It looks like it may work. The only thing I'm not sure of is if the PWM should be held high or low while the other PWM is pulsed.


----------



## markula (Oct 27, 2013)

I have now made a model. Just used a old RC car. 
But i have problems because it try do be in balance but its to slow to respond. I think this not will be a problem with the real segway because its slower to react. 

But i found the KPD values.

#define KP 0.7	// proportional constant - use if not using potentiometer
#define KI 0	// integral constant - use if not using potentiometer
#define KD 0.3	// derivative constant - use if not using potentiometer

Do you have a poredure to how to set this values ? or what it shuld be when the segway is just a small model?.


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> I have now made a model. Just used a old RC car.
> But i have problems because it try do be in balance but its to slow to respond. I think this not will be a problem with the real segway because its slower to react.
> 
> But i found the KPD values.
> ...


First off, the motor + drivetrain must be fast enough to respond. No amount of PD tuning will work if they are too slow. For a balance bot, you'll get best results with wheels directly attached to the motor -- they must have enough torque to do this.

How to adjust P & D. I would start by setting D to zero. Then I would increase P until it oscillates. I would then back off P little by little until oscillation stops. I would then increase D until the response is fast but doesn't oscillate. This is tedious if you have to upload the Arduino app every time. I suggest using the Bluetooth and adjusting P & D with the Android app.


----------



## Centrex (Nov 24, 2013)

Hi Oval
A question that has nothing to do with Segway clones just about Arduino maths.

In the following formulae what do the ? and the : do.

ADCvals[ADCinput] * 5*((advis[ADCinput].lower *?* adivs[ADCinput].upper /adivs[ADCinput].lower *:* 0) +1) / (1024 * adivs[ADCinput].gain) + (ADCinput == 0 *?* 0.75 *:* 0)

If it not something for the forum just delete the post.

Thanks
Cliff


----------



## FlyBoyKB (Jan 9, 2014)

All - I received my replacement BTN. It's installed it but I'm not quite done. I first wanted to finish a wooden geared clock I started. Here's the finished product:

I'll have the bot ready for testing very soon!


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Hi Oval
> A question that has nothing to do with Segway clones just about Arduino maths.
> 
> In the following formulae what do the ? and the : do.
> ...


(if condition is true or > 1)?[then this value]:[else this value]

For example, if (adivs[ADCinput].lower > 0) and ADCinput == 0, this equation is simply

ADCvals[ADCinput] * 5*((adivs[ADCinput].upper /adivs[ADCinput].lower) +1) / (1024 * adivs[ADCinput].gain) + (0.75)


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> All - I received my replacement BTN. It's installed it but I'm not quite done. I first wanted to finish a wooden geared clock I started. Here's the finished product:
> 
> I'll have the bot ready for testing very soon!


Wow! Your craftsmanship is amazing! You could probably build the only Segway in the world with a wooden gear drive .


----------



## nstr (Mar 2, 2014)

Hello guys from far away.
I just have reading a big part of this topic, but my english is not fluent and i can't find there something like "Readme for dummies".
If we can get x-y angles through ACC and GYRO from one unit, why we need's 2x MPU-6050? And what main difference (for the final device) of using 1 insted of 2 pcs?


----------



## Ovaltineo (Jul 18, 2013)

nstr said:


> Hello guys from far away.
> I just have reading a big part of this topic, but my english is not fluent and i can't find there something like "Readme for dummies".
> If we can get x-y angles through ACC and GYRO from one unit, why we need's 2x MPU-6050? And what main difference (for the final device) of using 1 insted of 2 pcs?


If you use 1 MPU-6050, you MUST mount it in the intersection of the steering shaft and wheel axle. This is not always possible when you consider placement of batteries and other components. With 2xMPU-6050, you can mount 1 MPU-6050 anywhere along the steering shaft and the other MPU-6050 anywhere on the board.

I have tried using 1 MPU-6050 mounted towards the front of the steering shaft (not at the intersection with the wheel axle), but found that this caused unexpected tilt when turning. This can probably be solved by angular coordinate translation in the maths computation, but it's been 30 years since I did those maths in university, so I gave up , and just used 2x MPU 6050.


----------



## nstr (Mar 2, 2014)

*Ovaltineo*
Big thank you!


----------



## Centrex (Nov 24, 2013)

Ovaltineo said:


> (if condition is true or > 1)?[then this value]:[else this value]
> 
> For example, if (adivs[ADCinput].lower > 0) and ADCinput == 0, this equation is simply
> 
> ADCvals[ADCinput] * 5*((adivs[ADCinput].upper /adivs[ADCinput].lower) +1) / (1024 * adivs[ADCinput].gain) + (0.75)



Thanks Oval, nothing I have on the Arduino maths gives a clue to this sort of short hand.
Regards
Cliff


----------



## schilli (Jan 1, 2014)

FlyBoyKB said:


> All - I received my replacement BTN. It's installed it but I'm not quite done. I first wanted to finish a wooden geared clock I started. Here's the finished product:
> 
> I'll have the bot ready for testing very soon!


Hello FlyBoyKB,

the watch looks fantastic. Do you have a plan of it? If yes, could i get him? I have a wood router and would try it.

Greets from Germany

Christian


----------



## FlyBoyKB (Jan 9, 2014)

Schilli - 

Not to hijack this thread but to answer your questions. I saw this clock in the Spring 2011 issue of ScrollSaw Woodworking and Crafts magazine. It was designed by Clayton Boyer and plans are available from him at http://www.lisaboyer.com/Claytonsite/Genesispage1.htm.

I don't know if there are CNC router files available. I made the clock from solid Walnut and Baltic Birch plywood using an band saw, scroll saw and sand paper. Lots of fun. Thanks for your interest.

Now - back to the SegwayClone...


----------



## adamson (Mar 2, 2014)

Hello, do You think, can I use this driver Curtis PMC 1225-2702(I have one  ) in this project?


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Hello, do You think, can I use this driver Curtis PMC 1225-2702(I have one  ) in this project?


Unfortunately, you can't .


----------



## adamson (Mar 2, 2014)

Thanks for reply Ovaltineo . So I must to buy something 
What driver do You reccomend? I'm thinking about btn7960, but I have 350 W motors with gearbox, will it be ok?


----------



## Ovaltineo (Jul 18, 2013)

Yes, BTN7960 would be good for those.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

I now have the SegwayMiniClone back up and running. Here's a short video:


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> I now have the SegwayMiniClone back up and running. Here's a short video:


Good work! Have you tried the Bluetooth remote control? Post a video too if you get it working.


----------



## FlyBoyKB (Jan 9, 2014)

Ovaltineo said:


> Good work! Have you tried the Bluetooth remote control? Post a video too if you get it working.


I have the Bluetooth working - sort of. I've done a little testing. Here are my observations:
1. On return from the steering screen the first page no longer updates although the connection is still maintained. Going back and forth the steering screen always works.
2. The PID values do not update from the Arduino on startup. They always indicate the .7 and .3 values until you change them on the screen and do a save. Then they are correct but if you stop the system and restart, even though you changed the values, on startup it still displays the .7 and .3.
3. After a couple PID changes and saves the slider locks up, goes negative and actually saves the negative values to the Arduino. (I tested this by adding and viewing the PID values in the serial monitor display)
4. I've done minimal testing of the steering but it seems inconsistent. Should the steering allow you to go backwards? It doesn't seem to. Should I try adjusting the steering multiplier?

Any way, thanks. I'll try to test more today.

P.S. How is your project coming? Do you have anymore video? I guess it's summer in Australia so you can get outside. I was using the snowblower AGAIN this weekend. Our winter has just been brutal.

kb


----------



## FlyBoyKB (Jan 9, 2014)

I thought of something else. I worked all one day trying to get the bot to balance. It just would not. The reactions were much too slow. That whole day I had the GY-521 mounted on the axle rotation centerline between the motors (probably a half inch from each encoder. As soon as I moved it up to the second level of the bot it started working well. I don't have an explanation. Could it be the interference of the motor/encoders? Or is there not enough movement to properly 'stimulate' the gyro/accel? Any ideas? Has anyone else experienced this phenomenon?


----------



## Rjkley (Feb 25, 2014)

Why do not you use a temperature sensor DS18B20? 
As this example http://www.ebay.com/itm/SN9F-DS18B2...Electrical_Test_Equipment&hash=item1c394049c7 
He's much cheaper and more affordable.


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> I have the Bluetooth working - sort of. I've done a little testing. Here are my observations:
> 1. On return from the steering screen the first page no longer updates although the connection is still maintained. Going back and forth the steering screen always works.
> 2. The PID values do not update from the Arduino on startup. They always indicate the .7 and .3 values until you change them on the screen and do a save. Then they are correct but if you stop the system and restart, even though you changed the values, on startup it still displays the .7 and .3.
> 3. After a couple PID changes and saves the slider locks up, goes negative and actually saves the negative values to the Arduino. (I tested this by adding and viewing the PID values in the serial monitor display)
> ...


Hmm, looks like it needs more work and testing. I've been coding on the train to work but haven't had a chance to test and debug.

My project was stalled for while -- I bought 2X500 watt motors with planetary gearbox. But I struggled to get wheels with fixed 18-tooth sprocket. I've finally sourced 2 X 16-inch kids bike wheels with coaster brakes. I just need to convert them to fixed gear by spot welding.


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> I thought of something else. I worked all one day trying to get the bot to balance. It just would not. The reactions were much too slow. That whole day I had the GY-521 mounted on the axle rotation centerline between the motors (probably a half inch from each encoder. As soon as I moved it up to the second level of the bot it started working well. I don't have an explanation. Could it be the interference of the motor/encoders? Or is there not enough movement to properly 'stimulate' the gyro/accel? Any ideas? Has anyone else experienced this phenomenon?


On the axle, the accelerometer only experience changes in acceleration due to gravity. Away from the axle, the accelerometer will also experience lateral acceleration.


----------



## Ovaltineo (Jul 18, 2013)

Rjkley said:


> Why do not you use a temperature sensor DS18B20?
> As this example http://www.ebay.com/itm/SN9F-DS18B2...Electrical_Test_Equipment&hash=item1c394049c7
> He's much cheaper and more affordable.


Simple. I get the TC74 for free (Microchip samples) and they get delivered within a few days!


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

here's a little more info about the steering:

If your phone is on the steering screen and the phone held vertically for reference (e.g. the screen switch button you added is in the bottom right quadrant):

Results of test - 
quadrants 1 & 2 (top 2 quadrants):
straight up: (forward) x=0 and Y=positive - doesn't work. I think the bot 'leans' way too far forward and falls over? 
left turn = quadrant 1 where x=positive? and y = positive - Appears to work but I question the x sign?
right turn = quadrant 2 where x = negative? and y = positive - Appears to work but I question the x sign?

Quadrants 3 & 4 (bottom 2 quadrants):
straight down (backward): x=0; y=negative The bot actually moves forward instead of backward, but I can control it this way.
right turn = quadrant 4 x=negative? and y=negative Works but the bot is going forward.
left turn = quadrant 3 x= positive? and y=negative Works but the bot is going forward.

There doesn't appear to be a backward control.

Even if I hold the phone horizontally the positives and negatives are not right and the forward straight right on the X axis etc.


Question:
1. Does the steering multiplier apply with remote control? Maybe it should to make it a little less sensitive?
2. Is the forward backward controlled by adjusting the lean and the left right controlled by motor speed differential?

Thanks for your efforts. If this needs clarification let me know.

kb


----------



## Rjkley (Feb 25, 2014)

Only I started to order parts on the Segway, I saw Scooter Rino. And the funny thing is that my gearmotors are more suitable time for Rino. A wheel can be taken from an old jeep  And two motors in both the present parallels as in Segway security.


----------



## phaedrus (Aug 24, 2013)

Ovaltineo said:


> I bought 2X500 watt motors with planetary gearbox.


Hi OT, where did you get the motors from? Could you mount the wheels directly on the output shaft? 

I'm interested in updating mine at some stage and so am always on the lookout for something better. The problem of course is the freight cost downunder...

Cheers, P.


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> here's a little more info about the steering:
> 
> ...


Ignore the X sign, it is reversed on purpose. I'm surprised that it leans too much forward when Y is positive and still leans forward when Y is negative. It is meant to lean backwards. Either you have a forward tilt in your calibration or there is a bug in the code. It is most probably a bug.



> Question:
> 1. Does the steering multiplier apply with remote control? Maybe it should to make it a little less sensitive?


 Yes, the STEER_MULTIPLIER is used. Make it smaller.


> 2. Is the forward backward controlled by adjusting the lean and the left right controlled by motor speed differential?


Yes, that's the idea. A bug might prevent that from happening .


----------



## electricpolo (Mar 15, 2011)

I recently bought 2 of these planetary gearbox motors for my project. I got them from Motion Dynamics. Link is here http://www.motiondynamics.com.au/dayton-500w-0.67-hp-24v-dc-planetary-500rpm.html.
They are solid motor with a bit of weight in them so freight is likely to be $$$.
I have already pulled one apart to cast an engineering eye over them for Segway clone use.
1. Backlash. The sun gear on the motor shaft is a slightly loose fit resulting in a small amount of backlash. This gear can be fixed on the shaft with 'High Strength Bearing Retainer.
2. Easy to add a small shaft extension which comes through the brush end of the motor. Will be fitting some AMT-102-V rotary encoders flat aaginst the brush end.
3. Very strong & very quiet. Much better construction than the common offset spur gear type on eBay.
4. Planet gear arms & output shaft are nice & chunky but the output shaft is very short. It comes with an 11 tooth sprocket but I have worked out how to mount a timing pulley in its place.
5.The output shaft bearings are very close together & this is fine with the applied load from the sprocket or pulley but not if the applied load moved away from the bearings say from a directly mounted wheel. 
6.Mounting a wheel directly on the output shaft would be almost impossible due to the shaft only protruding about 15mm + thread.
7.Secondly, if #6 could be overcome, the moment of force being applied to the bearings & the aluminium bearing housing would be many times greater because the sprocket is only 15mm from the bearing but the centre of the wheel could easily be 100mm or more away.
The housing, the bearings & the planetary gears would fail very fast.
8.Much better to use HTD Hi Torque belts & pulleys (no backlash). 
9.The original chain drive could be used but all chains have some backlash.
10.These motors will need a 60A 120A peak controller. They can draw over 100A getting close to stall.
Attached is a picture of the output shaft


----------



## Ovaltineo (Jul 18, 2013)

Rjkley said:


> Only I started to order parts on the Segway, I saw Scooter Rino. And the funny thing is that my gearmotors are more suitable time for Rino. A wheel can be taken from an old jeep  And two motors in both the present parallels as in Segway security.


Not exactly sure what you mean. Maybe you can post some pictures?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> I recently bought 2 of these planetary gearbox motors for my project. I got them from Motion Dynamics. Link is here http://www.motiondynamics.com.au/dayton-500w-0.67-hp-24v-dc-planetary-500rpm.html.
> They are solid motor with a bit of weight in them so freight is likely to be $$$.
> I have already pulled one apart to cast an engineering eye over them for Segway clone use.
> 1. Backlash. The sun gear on the motor shaft is a slightly loose fit resulting in a small amount of backlash. This gear can be fixed on the shaft with 'High Strength Bearing Retainer.
> ...


That is exactly what I bought as well. Because I live in a "hill", I am increasing the torque by driving an 18-tooth wheel sprocket from the 11-tooth drive sprocket.

Hopefully, this will keep the motors from stalling and burning my 43A BTN7960 -- fingers crossed !


----------



## FlyBoyKB (Jan 9, 2014)

Oval... more info

I found the following by printing the board_offset and steer_offset to the serial monitor:

Y values - from top of Y axis moving down toward X axis -9 to -15 
- from bottom Y axis moving up toward X axis -7 to -1 

X Values - from far left X axis moving toward Y axis +7 to +1
- from far right X axis moving toward Y axis -7 to -1

kb


----------



## adamson (Mar 2, 2014)

Now I'm ready. 
I've got 2 motors worm gear 25:1 about 200 rpm and two aprilia 13'' wheels.


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval... more info
> 
> I found the following by printing the board_offset and steer_offset to the serial monitor:
> 
> ...


 
Today is your lucky day ! I've just released v4.0 of Arduino and v1.8 of CloneConsole to fix these bugs. Calibrate via CloneConsole is now available too.




> Arduino v4.0
> Fixed a few bugs with communication interface to CloneConsole Android app. Fixed intermittent "Error 11" on I2C bus.
> Added new configuration parameters BOARD_OFFSET_DIVIDER and STEER_OFFSET_DIVIDER which specify CloneConsole remote control sensitivity.
> 
> ...


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Now I'm ready.
> I've got 2 motors worm gear 25:1 about 200 rpm and two aprilia 13'' wheels.


Aprilia wheels! Super cool !!


----------



## Rjkley (Feb 25, 2014)

Ovaltineo said:


> Not exactly sure what you mean. Maybe you can post some pictures?


Sorry while translating the name was distorted. Properly Ryno.
http://www.youtube.com/watch?v=0wTfQiGFAKE


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Have found a compile bug in the new 4.0 version.
Version 3.9 using Nano & HC06 Bluetooth.
Compiles fine & Android app can see & connect to 'Segway'

Version 4.0 gets a compile error
SegwayClone.ino: In function 'void loop()';
SegwayClone:324: error: 'Serial3' was not declared in this scope

I am still learning Arduino and have tried comparing 3.9 to 4.0 but I can't find what is causing the error.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

Congratulations! I'm using a Mega card and HC-06 and all compiles and runs just fine. The remote controls now work very well and the connectivity seems solid.

Notes:
1. I picked Pot Steering in the code though I don't have pot steering. When I upload the code the startup steer Angle is 34.25. To correct this I changed line 116 in SegwayClone.ino from: return (pot * 240.0/1023.0) to return (0*240.0/1023.0). This starts the program with a 0 Steer Angle and the Bluetooth steering takes over. Should I be setting this up differently?

2. I notice that my motors are not 'equal' therefore one seems to react differently to speed commands. Where might be the best place to apply a multiplier, which might be a decimal e.g. .9 or .85 to the faster motor? In the Motors tab in controlMotors() I see the values are int. Would a decimal multiplier work somewhere in this function? Or is there a better place to apply a factor?

Great job! I think we're getting down to the very small improvements from here on.

I'm following the full size clone adventures with great interest. Next up will be my attempt to build a full size version.

kb


----------



## FlyBoyKB (Jan 9, 2014)

""CloneConsole v1.8
Added Calibrate view. Fixed saving of P and D. Revamped remote control for more resolution and configurable sensitivity. Added "ACK"s to improve synch between Android and Arduino.""

Oval - In the quote above what does "configurable sensitivity" refer to?


----------



## FlyBoyKB (Jan 9, 2014)

All...

Here's a video of the Bot with the latest software packs:
SegwayCloneV4.0 and CloneConsolev1.8






 
Great job Oval...

kb


----------



## electricpolo (Mar 15, 2011)

*Re: Segway Clone 4.0*

I did a couple of tests & found that Version 4.0 compiles OK on a Mega but will give the not declared compile error on either a Nano or Uno.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> Have found a compile bug in the new 4.0 version.
> Version 3.9 using Nano & HC06 Bluetooth.
> Compiles fine & Android app can see & connect to 'Segway'
> ...


The Arduino compiler is buggy and can be unpredictable sometimes. I've just released v4.1 to fix it.


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> ""CloneConsole v1.8
> Added Calibrate view. Fixed saving of P and D. Revamped remote control for more resolution and configurable sensitivity. Added "ACK"s to improve synch between Android and Arduino.""
> 
> Oval - In the quote above what does "configurable sensitivity" refer to?


Change the parameters below to adjust sensitivity.

#define STEER_OFFSET_DIVIDER -70.0 // bluetooth remote control steer offset (X) divider. Higher value makes X movement less sensitive.
#define BOARD_OFFSET_DIVIDER -70.0 // bluetooth remote control board offset (Y) divider. Higher value makes Y movement less sensitive.


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> Congratulations! I'm using a Mega card and HC-06 and all compiles and runs just fine. The remote controls now work very well and the connectivity seems solid.
> 
> ...


Instead of POT_STEERING, try using MPU6050_X1_STEERING.



> 2. I notice that my motors are not 'equal' therefore one seems to react differently to speed commands. Where might be the best place to apply a multiplier, which might be a decimal e.g. .9 or .85 to the faster motor? In the Motors tab in controlMotors() I see the values are int. Would a decimal multiplier work somewhere in this function? Or is there a better place to apply a factor?


In v4.1, I added the new parameter MOTOR_LR_RATIO to cater for asymmetric motors. It's default value is 1.0. Change it to > 1 (eg 1.1) if left motor is slower and < 1 (eg 0.9) if left motor is faster.


----------



## FlyBoyKB (Jan 9, 2014)

Oval...

Everything you've added seems to work well for me. 

Questions:
1. Can MIN_BATTERY values be decimal e.g. 12, 11.5, 11, etc? If not probably no big deal.
2. Is the I in PID not a very important adjustment? I ask since there is a P and D on the remote screen but no I.

Suggestion:
When setting up using the USB, the battery is disconnected. This causes the low battery alarm to sound continuously. Note by default during this time the voltage reads a spurious 4.4 volts. My solution was to add to the voltage sensing code (about line 309 in SegwayClone.ino) an if clause (if (Vf < 5) alarmArry(ALARM_BATTERY) = 0; the elseif'd the next line. Seems to work. You might have better methods to deal with this. 

kb


----------



## electricpolo (Mar 15, 2011)

> The Arduino compiler is buggy and can be unpredictable sometimes. I've just released v4.1 to fix it.


Thanks. Version 4.1 compiles fine.


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval...
> 
> Everything you've added seems to work well for me.
> 
> ...


Yes, you can use decimal values.


> 2. Is the I in PID not a very important adjustment? I ask since there is a P and D on the remote screen but no I.


I used to have "I" in the PID computation but found that the best value for "I" is zero, so I just removed it. It is most probably because the PID algorithm is based on MIT's Segway code which didn't use "I".


> Suggestion:
> When setting up using the USB, the battery is disconnected. This causes the low battery alarm to sound continuously. Note by default during this time the voltage reads a spurious 4.4 volts. My solution was to add to the voltage sensing code (about line 309 in SegwayClone.ino) an if clause (if (Vf < 5) alarmArry(ALARM_BATTERY) = 0; the elseif'd the next line. Seems to work. You might have better methods to deal with this.
> 
> kb


Yes, that's a good idea. I will add that to the code.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
I hope you can help me out with a compile error. 
I have a RoboClaw 2x60A controller & 2 of the planetary motors that I have fitted AMT102 rotary encoders to. 
I am intending to use the RoboClaw inbuilt encoder routines to more accurately control the clone speed.
My immediate problem is when I try & use the Arduino packet serial example from the RoboClaw user manual, this is what happens:

The compiler gets stuck on the line RoboClaw roboclaw(5,6); 

It then throws up the following error message

Error: No matching function call to ‘RoboClaw::RoboClaw(int, int)
Documents\Arduino\libraries\RoboClaw/RoboClaw.h:93: note: candidates are: RoboClaw::RoboClaw(uint8_t, uint8_t, uint32_t, bool)
Documents\Arduino\libraries\RoboClaw/RoboClaw.h:93: note: RoboClaw::RoboClaw(const RoboClaw&)

I am using IDE compiler 1.0.5

I would like to get the examples working so I can better understand how the Arduino - packet serial - RoboClaw all work together.


----------



## Ovaltineo (Jul 18, 2013)

I've just released v4.2 of the Arduino sketch.



> v4.2
> Disabled alarm if voltage is below 5V (powered by USB). Added INVERT_STEERING option to swap left and right steering. Added FAN_PIN option to turn on fan output when temperature goes above TEMP_FAN_ON.


----------



## electricpolo (Mar 15, 2011)

Attached are some pics of my modified 500 watt planetary gearbox motors. These pics show how I fitted a rotary encoder to the rear of the motor. These encoders will be used together with a 2x60A RoboClaw controller.

The sun gear on the other end of the shaft has been fixed on with High Strength Bearing Retaining Compound. This removes most of the backlash in these motors.
Will shortly post a couple of pics of the timing pulley fitted in place of the original chain sprocket and using the original output shaft.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> I hope you can help me out with a compile error.
> I have a RoboClaw 2x60A controller & 2 of the planetary motors that I have fitted AMT102 rotary encoders to.
> I am intending to use the RoboClaw inbuilt encoder routines to more accurately control the clone speed.
> ...


The sample code should work. Did you download the Roboclaw library from here?
http://www.pololu.com/file/download/roboclaw_arduino.zip?file_id=0J517


----------



## electricpolo (Mar 15, 2011)

Heard back from Nathan at RoboClaw. As it turns out, the example in the User Manual uses the older RoboClaw library.
The problem line RoboClaw roboclaw(5,6) should read RoboClaw roboclaw(5,6,10000) or (5,6,10000,true).
I was going from the user manual & Nathan said the examples in the user manual hadn't been updated but the examples included with the library had been.
Code compiles now.


----------



## schilli (Jan 1, 2014)

Hello all,

Two weeks are over, and nothing goes on. Yesterday i got a new motorcontroller with 36v and 30A cont 60A peak.

http://www.aliexpress.com/snapshot/6026415483.html

I will test it tomorrow and hope it will run, othertimes i hove to go back to 24V.
It is time to stand on the clone and not in front of it.


----------



## Rjkley (Feb 25, 2014)

In CloneConsole for Android would like to have 5 customizable buttons. 1 - unlock (default after loading the device is locked), 2 - Demo mode (50% stroke), 3 - to ride (5 minutes ride, 2 minutes decreased speed and lock), 4 and 5, I have not figured out, but useful.

For control I would use here, these modules http://www.ebay.com/itm/2PCS-Arduin...718?pt=LH_DefaultDomain_0&hash=item27c59c138е 100 meters is more than a Bluetooth connection.


----------



## Ovaltineo (Jul 18, 2013)

Rjkley said:


> In CloneConsole for Android would like to have 5 customizable buttons. 1 - unlock (default after loading the device is locked), 2 - Demo mode (50% stroke), 3 - to ride (5 minutes ride, 2 minutes decreased speed and lock), 4 and 5, I have not figured out, but useful.


I can add a demo, lock/unlock functions, but I don't know about having the device locked after loading (by default). There are a few users of the Segway clone -- I don't want to annoy other people (including me) just so that it fits your requirements.



> For control I would use here, these modules http://www.ebay.com/itm/2PCS-Arduin...718?pt=LH_DefaultDomain_0&hash=item27c59c138е 100 meters is more than a Bluetooth connection.


You need a pair of those to work. How are you going to connect one of them to your Android phone?


----------



## wired (Nov 24, 2013)

Hello Oval,
I have now received an Elechouse dual motor controller (referred to as the 2nd version on their site) and it works with the sample code from Elechouse. But as I mentioned in a previous forum post I suspect that it is not compatible with your current seg clone code.

The link for the controller is:
http://www.elechouse.com/elechouse/index.php?main_page=product_info&products_id=2179

Elechouse also provides sample code and an associated library at this link:

http://www.elechouse.com/elechouse/... driver/50a motor driver code for arduino.rar

The dual controller plugs in to the screw terminal shield that plugs in to the Uno 11 with the idea of reducing the amount of wiring required.

Could you, as time permits, advise if you would consider coding changes for this dual motor controller.

Thanks,
Darcy


----------



## Rjkley (Feb 25, 2014)

Ovaltineo said:


> I can add a demo, lock/unlock functions, but I don't know about having the device locked after loading (by default). There are a few users of the Segway clone -- I don't want to annoy other people (including me) just so that it fits your requirements.


I saw this on the present security Segway. There she performed using iButtons. Integrate or embed it in your Segway clone - your decision. But it will be terribly hurt if it is stolen. And so there is no sense of theft. Who needs idle iron? Or other situation: while you were absent teenager to ride Segway and crippled.

I am happy to watch your project. And take ideas from it for yourself. I consider it my duty to share their ideas. If you do not need it - say and I will not.



Ovaltineo said:


> You need a pair of those to work. How are you going to connect one of them to your Android phone?


So two of them are. And some sort of atmega or attiny as a management.

By the way, why did you use two gyro? For he that in the control handle provides all the necessary data! A platform that duplicates the longitudinal data.


----------



## Ovaltineo (Jul 18, 2013)

wired said:


> Hello Oval,
> I have now received an Elechouse dual motor controller (referred to as the 2nd version on their site) and it works with the sample code from Elechouse. But as I mentioned in a previous forum post I suspect that it is not compatible with your current seg clone code.
> 
> The link for the controller is:
> ...


I've just released v4.3 to support this controller. Let me know if it works.


----------



## Ovaltineo (Jul 18, 2013)

Rjkley said:


> I saw this on the present security Segway. There she performed using iButtons. Integrate or embed it in your Segway clone - your decision. But it will be terribly hurt if it is stolen. And so there is no sense of theft. Who needs idle iron? Or other situation: while you were absent teenager to ride Segway and crippled.


Good point. For users who want this feature, I will add an option to lock the Segway clone when it is turned on or reset. It can then only be unlocked by the CloneConsole Android app. So the only people who can steal your clone are the users in this thread , or those who pick it up and put it in their car/truck .



> By the way, why did you use two gyro? For he that in the control handle provides all the necessary data! A platform that duplicates the longitudinal data.


You can use one or two gyros. See post #481 for an explanation.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Could you tell me why you have made a note on the schematic not to connect the RoboClaw logic ground to the Arduino?


----------



## larshsm (Dec 11, 2013)

Hi ppl. I've followed this thread for some time and have finally build my own clone. I have now come to the point of testing, but are currently haveing some issues. 

Firstly i have to admit i do not know much about arduino programming. I kind of thought I'd just use Ovaltine's program and then "voilat" succsess. But no.

So my setup is like this:
- Arduino UNO
- Homemade dual PWM motor controller (2x2x PWM + ON)
- MPU-6050
- 2x 300W wheelchair motors
- 2x 17Ah battery
- Pot steering

So I follow the instructions in the readme and adjust the program accordingly. Then I do calibrate and then run also as instructed. The problem then is that i simply can't get it to work. I've tried with different versions of the program, and one just gets stuck, one dosent work at all, and the last just gives wierd pwm readings. 

I've hooked up a oscilloscope to the pwm outputs from the arduino, so the motor and motorcontroller is out of the question here. I have also conneted a voltage-divider to the potsteering connections to make sure the potmeter isnt affecting the results.

So what have i missed? Any good advices?

-Lars


----------



## schilli (Jan 1, 2014)

Ovaltineo said:


> Good point. For users who want this feature, I will add an option to lock the Segway clone when it is turned on or reset. It can then only be unlocked by the CloneConsole Android app. So the only people who can steal your clone are the users in this thread , or those who pick it up and put it in their car/truck .
> 
> I am interesting in this tool too!
> 
> You can use one or two gyros. See post #481 for an explanation.


I am interesting in this tool too!


----------



## adamson (Mar 2, 2014)

Ovaltineo should I use this in my project? http://www.thetoolboxshop.com/sw60-...enoid-contactor-continuous-80a-ip66-6958.html


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> Could you tell me why you have made a note on the schematic not to connect the RoboClaw logic ground to the Arduino?


Several people, including myself, have experienced bad glitches when the logic ground is connected. This is because the battery ground and logic ground will form a ground loop if both are connected to the Arduino. At 24V, the spikes from the motor will create a voltage difference between the battery ground and logic ground. This can lockup the Arduino.


----------



## Ovaltineo (Jul 18, 2013)

larshsm said:


> Hi ppl. I've followed this thread for some time and have finally build my own clone. I have now come to the point of testing, but are currently haveing some issues.
> 
> Firstly i have to admit i do not know much about arduino programming. I kind of thought I'd just use Ovaltine's program and then "voilat" succsess. But no.
> 
> ...


Please post your SegwayClone.h, the output of the serial monitor, and a schematic of your controller.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Ovaltineo should I use this in my project? http://www.thetoolboxshop.com/sw60-...enoid-contactor-continuous-80a-ip66-6958.html


Yes, I highly recommend the use of a relay to cut power off to everything. You would need an emergency button (situated on the handle) to switch the relay.


----------



## wired (Nov 24, 2013)

Ovaltineo said:


> I've just released v4.3 to support this controller. Let me know if it works.


Hello Oval,
 Have been testing V4.3 with the PWM SHIELD CONTROLLER using the dual controller from Elechouse.

The test setup for the PWM SHIELD CONTROLLER is as follows:

Freetronics 11 Uno
Freetronics Screw terminal Shield
Elechouse dual motor controller
10 K pot steering
Tilt IMU GY521
2 small printer motors
24 volt power source
Stepdown L2596 set to 11 V DC
SegClone V4.3

Results so far:

motor_max of 30

Using the default motor_max of 30 for the speed the motors just seem to go flat out without any proportional slow down or speed up. The motors do reverse using the steering pot. And when the IMU is tilted too far the motors do not completely stop but rapidly pulse on and off.

With the steering pot slightly off center 1 motor will pulse depending on the left or right setting of the steering pot.

motor_max of 250

Using a motor_max of 250 and rotating the steering pot slowly to the right 1 motor starts to proportionally increase its speed as the steering pot is rotated more. The other motor does not rotate in any direction.

With the steering pot centered and quickly tilting the IMU both motors rotate but then stop.

When the tilt angle is exceeded both motors pulse on and off and do not stop.

At startup with the pot steering centered the buzzer gives a long beep and then stops and then both motors turn on at high rpm and then stop and barely move and then the buzzer gives a constant even beep like the “short short short” for the Motor Limit.

Centrex also has had similar results using his Elechouse dual motor controller and also advises that pin 4 is used for the Led Green Pin in Segwayclone.h and pin 4 for the Right Disable Pin in Motors.h .

The above is no doubt very confusing and contradictory, certainly for me any way as I have no experience in this area, so perhaps you could suggest other tests that I can pursue and provide the results of for a more logical diagnosis.

Thanks,
Darcy


----------



## Ovaltineo (Jul 18, 2013)

wired said:


> Hello Oval,
> Have been testing V4.3 with the PWM SHIELD CONTROLLER using the dual controller from Elechouse.
> 
> The test setup for the PWM SHIELD CONTROLLER is as follows:
> ...


Because of PIN 4 conflict, you should not enable VOLTAGE_LED, or use a different LED_GREEN_PIN when using the PWM_SHIELD_CONTROLLER.

Please try the following sketch and let me know the results. The loop starts from stopped and increases to full forward, then decreases to a stop and increases to full reverse, then decreases to a stop. Let me know how it goes.


----------



## markula (Oct 27, 2013)

Ovaltineo said:


> Yes, I highly recommend the use of a relay to cut power off to everything. You would need an emergency button (situated on the handle) to switch the relay.


But i think is better with a SSR than a mechanical one. 

http://www.ebay.com/itm/1pcs-Solid-...320?pt=LH_DefaultDomain_0&hash=item51a632b660

This is what i use. Can handel up to 60V and 100A. But you have to attach the SSR to the frame or a heatsink. 

http://www.ebay.com/itm/New-Heat-Si...006?pt=LH_DefaultDomain_0&hash=item232c0db846


----------



## Rjkley (Feb 25, 2014)

markula said:


> But i think is better with a SSR than a mechanical one.
> 
> http://www.ebay.com/itm/1pcs-Solid-...320?pt=LH_DefaultDomain_0&hash=item51a632b660
> 
> ...


If it is needed heatsink - will bask and expend energy.
Look at this http://www.ebay.com/itm/AC-230V-400...Electrical_Test_Equipment&hash=item19da2bd9a3 Absolutely not heated and protects against short circuit overload. Sold in any shop electrical goods. There are also at a greater current.


----------



## markula (Oct 27, 2013)

RjklWien You 83216 said:


> If it is needed heatsink - will bask and expend energy.
> Look at this http://www.ebay.com/itm/AC-230V-400...Electrical_Test_Equipment&hash=item19da2bd9a3 Absolutely not heated and protects against short circuit overload. Sold in any shop electrical goods. There are also at a greater current.




You have to se the spesifics. Is ac not dc. Is Allways dc When is battery.


----------



## electricpolo (Mar 15, 2011)

After successfully building an electric car (driven every day & now almost 40,000 electric km), I would like to put forward some of the things I learnt from my build & from other people's builds. After all, a Segway clone is just a 2 wheel electric vehicle.

1. Don't skimp on the motor controller. It is the most critical part of the system.
2. Don't under estimate how much current a small electric motor can draw. The 450W Unite & the 500W Dayton motors can easily pull *100A or more* close to stall!
3. Put a fuse in the battery cable. The fuse needs to be rated for a bit more than the max current draw of BOTH motors. 
4. Heavy duty fuses can be found on eBay - see picture below.
5. Put a DC contactor in the battery cable too. This needs to be rated for the MAXIMUM combined current draw of both motors. 
6. Don't try & use an AC contactor. They might be much cheaper but they will not break a high current DC load when you really need them to.
7. Use a properly rated DC contactor instead. The picture below shows a 200A DC contactor easily found on eBay.
8. Don't ever use an SSR as a main contactor in a critical situation. I have had them fail ON! 
.


----------



## wired (Nov 24, 2013)

Ovaltineo said:


> Because of PIN 4 conflict, you should not enable VOLTAGE_LED, or use a different LED_GREEN_PIN when using the PWM_SHIELD_CONTROLLER.
> 
> Please try the following sketch and let me know the results. The loop starts from stopped and increases to full forward, then decreases to a stop and increases to full reverse, then decreases to a stop. Let me know how it goes.


Hello Oval,
Have not enabled the Led voltage monitor during these tests.

My observations of the MotorShieldTest sketch:

Starts at full speed in forward direction and decreasing to stop.

Starts slowly in forward direction and increasing to full speed.

Stops. Changes direction at full speed to Reverse and decreasing to
stop

Starts slowly in Reverse direction increasing to full speed.

Stops. Changes direction at full speed to Forward and decreasing to
stop.

Starts slowly in Forward direction increasing to full speed.

Stops. Changes direction at full speed to Reverse and decreasing to
stop

Starts slowly in Reverse direction increasing to full speed.

Stops. Changes direction at full speed to Forward and decreasing to
stop.

Not sure what the events are during the change of direction at full speed. Might be a stop and then direction change or just a direction change. Too fast to observe.

Hope this is of some assistance.

Thanks,
Darcy


----------



## Ovaltineo (Jul 18, 2013)

wired said:


> Hello Oval,
> Have not enabled the Led voltage monitor during these tests.
> 
> My observations of the MotorShieldTest sketch:
> ...


Wow! Just as I suspected, this controller uses INVERSE PWM. So a PWM output of 0=full speed and 255=stop. I will change the code to cater for this.


----------



## Centrex (Nov 24, 2013)

Hi Oval
Eagerly await your deliberations, I noted in testing the controller from the serial monitor with increasing numbers the motor slowed. To put you in the picture I am friend of wired (Darcy) and have one of the two controllers he puchased.
I was able to get the controller to perform the way you described by changing the lines
If (speedL<0) to (speed>0) and the same for If(speedR<0) to (speedR<0).

Not particularly good at Arduion sketches but it worked, the other problem is a bit of a stutter when the motors reverse the motors jump a little.

Regards
Cliff


----------



## Centrex (Nov 24, 2013)

Hi Oval
In addition to the previous post I ran the sketch provided by Elechouse on their website. They probably get up to something clever because the motor followed increasing numbers by running faster and slower with decreasing numbers.
Way out my depth.
Regards
Cliff


----------



## Centrex (Nov 24, 2013)

Hi Oval
4.4 appears to have fixed the problem.

More testing tomorrow.

Many thanks I am sure Wired will be pleased.

Cliff


----------



## wired (Nov 24, 2013)

Ovaltineo said:


> Wow! Just as I suspected, this controller uses INVERSE PWM. So a PWM output of 0=full speed and 255=stop. I will change the code to cater for this.


Hello Oval,
Have been running tests with V4.4 on my little test rig and as far as I can tell all is working aok using the Elechouse dual controller. Many thanks for your speedy code amendments to include the Elechouse controller.

Regards,
Darcy


----------



## Ovaltineo (Jul 18, 2013)

I've released v4.4 to fix the PWM_SHIELD_CONTROLLER problem, and also added the Android LOCK feature. It is not compatible with the current release (v1.8) of CloneConsole.

I'm still testing the CloneConsole update. So, stick with v4.3 if you want to use CloneConsole.


----------



## larshsm (Dec 11, 2013)

Ovaltineo said:


> Please post your SegwayClone.h, the output of the serial monitor, and a schematic of your controller.


I can do that on monday when im back at my school, but since the last post i did sort of figure it out. 

A small clip of the testing: https://www.dropbox.com/s/k0bpy476tla2vv6/20140319_181411.mp4

A short while after this testing my power-module failed and got burned. So i am wondering, can in this arduino program the PWM signals overlap?

I tested the powermodule with a single PWM earlier for up to 22A-ish load for a while, and the circuit didnt show any sign of heat or other symptoms. Ofcource it could be the constant on/off currents that kills it, still a bit weird with such a small mechanical load. 

I will make an interlocking circuit for it when i get the time, but it would be nice if i know if that can work. Im kinda running out of mos-fets  Anyways i will get a sabertooth for backup.


----------



## Ovaltineo (Jul 18, 2013)

I've just released v4.5 of the Arduino sketch and v1.9 of CloneConsole to support the remote LOCK/UNLOCK feature. Enable LOCKED_BY_DEFAULT if you want your clone locked when you turn it on. 

You'll hear two regular short-beeps when the clone is locked. For safety, you can only lock or calibrate the clone if the motor output is less than 10% of MOTOR_MAX. The buttons will turn RED if calibrate or lock fails.


----------



## Ovaltineo (Jul 18, 2013)

larshsm said:


> I can do that on monday when im back at my school, but since the last post i did sort of figure it out.
> 
> A small clip of the testing: https://www.dropbox.com/s/k0bpy476tla2vv6/20140319_181411.mp4
> 
> ...


Wow, you didn't use a MOSFET driver like the IR2110. The problem with using discrete components is that it is diffcult to control the switching delays to prevent overlaps. I can see that you don't have any delay circuits (there is no PWM overlap in my program, but there is no delay when switching directions). There is also no over-current or temperature shutdown. From my experience, building your own controller even with a MOSFET driver is difficult and dangerous (especially if used in a Segway - I've got scars to prove it ), plus more expensive (compared with the BTN7960).


----------



## wired (Nov 24, 2013)

Ovaltineo said:


> That's the correct one. They are the same and this one has a heatsink. I recommend a 12v fan blowing on the two motor controllers too.


Hello Oval and other users of the BTN 7960.

I have a question about the BTN 7960 with the heat sink on the bottom of the PCB. It seems that there is a thin film of plastic material between the bottom of the PCB and the heat sink and that the plastic material adheres to the PCB but not to the heat sink. The heat sink is held in position by 2 screws.

Is there a better method of achieving thermal conductivity to the heat sink while still maintaining electrical isolation.


Cheers,
Darcy


----------



## Ovaltineo (Jul 18, 2013)

wired said:


> Hello Oval and other users of the BTN 7960.
> 
> I have a question about the BTN 7960 with the heat sink on the bottom of the PCB. It seems that there is a thin film of plastic material between the bottom of the PCB and the heat sink and that the plastic material adheres to the PCB but not to the heat sink. The heat sink is held in position by 2 screws.
> 
> ...


I'm using it the way it is without a problem. You can add silicon paste on both sides of the film, but I don't know how much more effective it will be.


----------



## emccarron (Mar 23, 2014)

This thread is awesome.

I've been working on one of these for a year +, and frustrated with all the math around the filtering on the 6050, I shelved it. Did a random Google search today and not only is there working code, but with damn near the exact hardware I've had collecting dust!

Dug into your code, and despite needing to modify it a bit to work with a four year old Sabertooth (auto baud requiring an AA hex to set the rate before starting to send it data....) was able to drop this right into my hardware and get it responding properly (albeit needing tuning...) within a few hours.

Kudos to the entire community here.

Any tips on PID tuning? It responds in the proper direction, but there's a good second or two of lag before the motors, for example, reverse when the tilt direction is reversed. 

Thanks!

Ed


----------



## Ovaltineo (Jul 18, 2013)

I'm glad you like this thread. The Android app is a big bonus so I suggest you get a Bluetooth module.

For PID tuning, read post #475 on page 48. I hope the delay is not caused by mechanical slack in your drivetrain.


----------



## emccarron (Mar 23, 2014)

Ovaltineo said:


> I'm glad you like this thread. The Android app is a big bonus so I suggest you get a Bluetooth module.
> 
> For PID tuning, read post #475 on page 48. I hope the delay is not caused by mechanical slack in your drivetrain.


I'm using some power chair motors with almost zero backlash -- I suspect it's something to do with tuning (or the Uno is too slow...) since even suspended, the motors themselves are slow to respond.

I'll have some time to play after work today. I work in industrial automation -- so PID is nothing new to me -- but all my experience is in pumping water, not moving me around.


----------



## Rjkley (Feb 25, 2014)

emccarron said:


> I'm using some power chair motors with almost zero backlash -- I suspect it's something to do with tuning (or the Uno is too slow...) since even suspended, the motors themselves are slow to respond.


I also use chair motors. Necessary to completely eliminate the gap between the gear and the wheel. For this I use the plastic from bottles. Unfortunately backlash worm gear can not be excluded  It is quite large when measured from the outside of the wheel.

In this project and would like to use a brushless motor wheel. Just what he will then deviate from the Segway? Is that price reduced by more than 10 + times  They are certainly more expensive, but the lack of backlash, gearboxes and high reliability.

My ideal looks something like this, but probably with something like a rudder to lean on him
http://www.youtube.com/watch?feature=player_embedded&v=0JOgTKigxGs
The total cost of $ 1,795.00 Unlike Segway


----------



## emccarron (Mar 23, 2014)

Rjkley said:


> Unfortunately backlash worm gear can not be excluded  It is quite large when measured from the outside of the wheel.


These are planetaries. No worm gear. Some old FRACMO motors with integral gearbox and wheel I had sitting around.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Bench testing so far with Nano, 2 x MPU6050, 2 Dayton motors fitted with AMT102 encoders & a 2x60A RoboClaw controller.

Using Clone Version 4.2 (no encoders), I can forward & reverse the motors, see the steering motor effects, stop the motors if I tilt the MPU's too far & change max motor speed.
Motors don't quite stop though bcause there is no feedback yet. Expected on bench test results.

Next, I decided to try using the encoders to control the moter speed. I can successfully do this in either direction with the RoboClaw example sketch that sends the command (35 & 36), the address & the encoder speed.

I then modified Clone 4.2 motors.h to read

//ROBOCLAW_CONTROLLER
// #define MOTOR_MAX 44000 // maximum encoder speed
#define MOTOR_MAX 11000 // 1/4 of maximum speed

#define ROBOCLAW_ADDRESS 0x80

// ROBOCLAW packet serial commands
#define M1_SPEED 35 // M1 Signed Speed Command instead of 32 M1 Signed Duty Cycle Command
#define M2_SPEED 36 // M2 Signed Speed Command instead of 33 M2 Signed Duty Cycle Command



Also tried these two modifications to Motors. First one then the other

void sendCommand(byte command, int param)
{
byte packet[5];
packet[0] = ROBOCLAW_ADDRESS;
packet[1] = command;
packet[2] = param >> 8; // MSB
packet[3] = param & 0xFFFF; // LSB (to increase bit length to 16)
packet[4] = (packet[0]+packet[1]+packet[2]+packet[3]) & 0x7F;
Serial1.write(packet, sizeof(packet));

void sendCommand(byte command, int param)
{
byte packet[4];
packet[0] = ROBOCLAW_ADDRESS;
packet[1] = command;
packet[2] = param;
packet[3] = (packet[0]+packet[1]+packet[2]) & 0x7F;
Serial1.write(packet, sizeof(packet));

End result is that in the serial monitor, I can see the motor output speed changing from -10000 to 10000 along with all the board angle & steer angle changing as I tilt the MPUs.
The motors, however, are not responding as expected. They are staying on a constant 10000 speed. They are both running in one direction & don't stop if I tilt the MPUs too far.

I think the problem is in sending the different command (35 or 36) & parameter (-44000 to 44000) to the controller but is beyond my current abilities to figure out.
Could you please point me in the right direction.


----------



## emccarron (Mar 23, 2014)

Think I found the source of my lag - and I caused it.

Left a testing delay in. I'm on the right track, but think i have the 6050 upside down.
I figured the calibration would handle it, but I'm not sure if there's a sign flip that's causing me grief. It wants to balance, but past a certain point seems to want to run away... More testing after work...


----------



## JBuilder (Feb 12, 2014)

Hi ,
I got an question about basic construction princips for my clone.
Because of the position of my motors and batteries the raw construction without "pilot" is extreme unbalanced. I leveled the contruction with a support structur and did the calibration.
When I started in run mode the clone fails balancing. It only runs away.

In another case I calibrated my clone with the Batteries upright so that it is nearly in balance without driving the motors. In this position it is possible for my clone to balance and I could play with the parameters via bluetooth.

Where is my error in thinking ?
Is it nessessary that the whole construction without pilot ist in balance ?
Bye from my cold basement with my dizzy clone.

24Volt - sabertooth 2x25 - wheelchair motor with gearboxes - arduino mega


----------



## emccarron (Mar 23, 2014)

emccarron said:


> Think I found the source of my lag - and I caused it.
> 
> Left a testing delay in. I'm on the right track, but think i have the 6050 upside down.
> I figured the calibration would handle it, but I'm not sure if there's a sign flip that's causing me grief. It wants to balance, but past a certain point seems to want to run away... More testing after work...


Hey, look at that... Having the hardware mounted correctly makes a difference.

It balances. But like the above poster, it's not statically balanced -- my handlebars lean away from the center of gravity.

I'm guessing it needs to be statically balanced -- since the calibration has no way of knowing to ignore the offset imparted by the handlebars?


----------



## Ovaltineo (Jul 18, 2013)

emccarron said:


> Hey, look at that... Having the hardware mounted correctly makes a difference.
> 
> It balances. But like the above poster, it's not statically balanced -- my handlebars lean away from the center of gravity.
> 
> I'm guessing it needs to be statically balanced -- since the calibration has no way of knowing to ignore the offset imparted by the handlebars?


The calibration will simply remember the "calibration position" as the desired level position. If not statically balanced at this position, the clone will will try to level by moving the motors. This could be enough to make the clone move on its own.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> Bench testing so far with Nano, 2 x MPU6050, 2 Dayton motors fitted with AMT102 encoders & a 2x60A RoboClaw controller.
> 
> Using Clone Version 4.2 (no encoders), I can forward & reverse the motors, see the steering motor effects, stop the motors if I tilt the MPU's too far & change max motor speed.
> ...


I've written the Arduino code to support the Roboclaw with encoders, but the P & D values are so big, it won't work with the CloneConsole Android app. I'll modify it later.
I haven't tested it so I won't put it up on post #1, but give it a go.
Select ROBOCLAW_ENCODER_CONTROLLER instead of ROBOCLAW_CONTROLLER in SegwayClone.h.


----------



## emccarron (Mar 23, 2014)

Ovaltineo said:


> The calibration will simply remember the "calibration position" as the desired level position. If not statically balanced at this position, the clone will will try to level by moving the motors. This could be enough to make the clone move on its own.


Does a 'real' Segway do that? I've seen them with handlebar baskets -- I can't see that staying balanced. It has to depend on the rider to help balance by offsetting any unbalanced load, I assume.

For the life of me, I can't imagine how you'd compensate for a constantly changing center of mass, if it's even possible.

This has been a very fun project to work on -- thanks!


----------



## electricpolo (Mar 15, 2011)

Thanks very much, Oval.
I'll give the encoders another test out later this evening.
Not too concerned about the Android Clone Console app at the moment.


----------



## Ovaltineo (Jul 18, 2013)

emccarron said:


> Does a 'real' Segway do that? I've seen them with handlebar baskets -- I can't see that staying balanced. It has to depend on the rider to help balance by offsetting any unbalanced load, I assume.
> 
> For the life of me, I can't imagine how you'd compensate for a constantly changing center of mass, if it's even possible.
> 
> This has been a very fun project to work on -- thanks!


A rider will instinctively compensate for an unbalanced Segway. If your clone is not statically balanced, just hold the handle while starting it, then hop on. 

If you watch the movie Mall Cop, there is a scene where a Segway moves by itself because it is unbalanced when the rider falls off.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Feedback on 4.6 Encoders. I had a compile error in the pushback even though I hadn't defined it. See attached picture. Tried a few different boards with same error.
I got the sketch to compile by deleting pushback.h & pushback.ino as I am only interested in testing the encoder control at this stage.

Bench testing with no load & no feedback. 
The motors seem to control very well using the encoders via the RoboClaw. I can vary the motor speed & direction right down to crawl. They will change direction really fast also. Only use S1 & S2 - no ground connected.
Encoder control looking really promising & fairly easy to to do.
I can't thank you enough!


----------



## Ovaltineo (Jul 18, 2013)

I've just released v4.7 which fixes the compile bug for the ROBOCLAW_ENCODER_CONTROLLER. I have also re-factored the values of P and D for this controller so it would work with the current version of CloneConsole.

My clone is "under renovation" at the moment so I haven't been able to test this release. I have changed from 16-bit (int) motor variables to 32-bit (long) variables to support the Roboclaw encoder. This affects *all * controllers, so please *bench test* this release on your clone first.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
4.7 on Nano has even finer motor control with the encoders.
Compiles fine with Voltage Check, Voltage LED & Pushback defined.
Has a 'not declared' error when Bluetooth is defined.
See attached pic.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> 4.7 on Nano has even finer motor control with the encoders.
> Compiles fine with Voltage Check, Voltage LED & Pushback defined.
> Has a 'not declared' error when Bluetooth is defined.
> See attached pic.


P & D values are lower for this controller in this release, so it looks like there is finer motor control. You may need to increase this during "road" testing. The pushback values in Pushback.h will also need changing.

I have released v4.8 to fix the compile bug.


----------



## electricpolo (Mar 15, 2011)

Thanks Oval,
Need to catch up with some of the hardware now. Unlikely to do any 'real' tests for a couple of weeks. 
Chassis is all welded up but I need to make up the steering handlebar next as my chassis will statically balance because the motors & batteries sit underneath the axles.


----------



## FlyBoyKB (Jan 9, 2014)

Oval - I'm back to this project. I've found the code won't compile if Bluetooth is defined and your MIN_BATTERY_4 is a decimal (Note it compiles OK if the other MIN_BATTERYs are decimal). e.g. With my mini bot I use a 3S lipo and I'd like to be able to set this value to 9.5. The code sees the value used as both and Int and Double. If it's a big deal I can forego the decimal in MIN_BATTERY_4.


----------



## Rjkley (Feb 25, 2014)

FlyBoyKB said:


> Oval - I'm back to this project. I've found the code won't compile if Bluetooth is defined and your MIN_BATTERY_4 is a decimal (Note it compiles OK if the other MIN_BATTERYs are decimal). e.g. With my mini bot I use a 3S lipo and I'd like to be able to set this value to 9.5. The code sees the value used as both and Int and Double. If it's a big deal I can forego the decimal in MIN_BATTERY_4.


Sorry to interrupt. Only in the Li-Po is necessary to monitor the voltage of each cell. If one bank voltage drops below 3 volts, it can deteriorate. I use in my airplane a whistle as http://www.ebay.com/itm/1-8S-LED-Li...Control_Parts_Accessories&hash=item46161bea18
it can be set for any voltage beep (very strong), can control from 2s to 8s


----------



## Ovaltineo (Jul 18, 2013)

FlyBoyKB said:


> Oval - I'm back to this project. I've found the code won't compile if Bluetooth is defined and your MIN_BATTERY_4 is a decimal (Note it compiles OK if the other MIN_BATTERYs are decimal). e.g. With my mini bot I use a 3S lipo and I'd like to be able to set this value to 9.5. The code sees the value used as both and Int and Double. If it's a big deal I can forego the decimal in MIN_BATTERY_4.


Well spotted! I've just released v4.9 to fix this.




Rjkley said:


> Sorry to interrupt. Only in the Li-Po is necessary to monitor the voltage of each cell. If one bank voltage drops below 3 volts, it can deteriorate. I use in my airplane a whistle as http://www.ebay.com/itm/1-8S-LED-Li...Control_Parts_Accessories&hash=item46161bea18
> it can be set for any voltage beep (very strong), can control from 2s to 8s


Yes, they are very good. I've got two of those for my 3S lipos in series.


----------



## adamson (Mar 2, 2014)

Hi.
I've got problem with one motor.
Going forward two motors work, back just one of them.
When turning left two motors work in different directions, when turning right just one works. What do You think about that?
https://www.youtube.com/watch?v=lAaJJW_4syA
I've got 2 bts 7960, mega, 2 mpu 6050.. and newest v4.9


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Hi.
> I've got problem with one motor.
> Going forward two motors work, back just one of them.
> When turning left two motors work in different directions, when turning right just one works. What do You think about that?
> ...


Double check the connection to the two PWM pins on the motor controller. One of them is probably not connected. Or worse, one of the BTN chips in the module maybe dead. Swap the controllers to confirm this.


----------



## Ovaltineo (Jul 18, 2013)

I've just released v5.0 of the Arduino sketch. 



> v5.0
> Added alarm for I2C error - long beep, short beep, long beep.
> "Calibrate" via CloneConsole is now allowed regardless of motor speed when using USB power only (must have voltage sensor).
> Fixed compile error when using ROBOCLAW_CONTROLLER or SABERTOOTH_CONTROLLER.


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Double check the connection to the two PWM pins on the motor controller. One of them is probably not connected. Or worse, one of the BTN chips in the module maybe dead. Swap the controllers to confirm this.


Yes. One of the BTN chips is dead, I must buy one more and wait for two weeks.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Yes. One of the BTN chips is dead, I must buy one more and wait for two weeks.


Are you buying the whole module or just the chip ($5)? I replaced just the chip -- it was very tricky coz I burnt a couple of traces with my soldering iron (it has to be very hot) but managed to jumper it. It would have been much easier with a hot-air soldering station.


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Are you buying the whole module or just the chip ($5)? I replaced just the chip -- it was very tricky coz I burnt a couple of traces with my soldering iron (it has to be very hot) but managed to jumper it. It would have been much easier with a hot-air soldering station.


I'm buying new whole module, and maybe I'll buy some chips.


----------



## Borc (Mar 12, 2014)

Hi, 

great job Ovaltine and others.

I'm confused with HC-06 connection. In schematics (for Uno with Sabertooth) there is:

D7=TX
D8=RX

in SegwayClone.h

"BLUETOOTH - define this if a HC06 "linvor" bluetooth module is attached to Serial3 (on Mega) or pin 7 RX & pin 8 TX (on UNO)"

Or I'm misunderstanding something.
Anyway, what is the correct connection.

regards


----------



## Gainnear (Oct 22, 2013)

Hello, i have problem
my segway clone is slow repond

http://youtu.be/qgzzpT50UHg

in clip i use KP=0, KD=0
but still slow repond 
do you have the solution?

thx


----------



## electricpolo (Mar 15, 2011)

> I'm confused with HC-06 connection. In schematics (for Uno with Sabertooth) there is:
> 
> D7=TX
> D8=RX


This is how I have hooked it up & it works fine.
Uno D7 to Bluetooth TX
Uno D8 to Bluetooth RX
5v Vcc & Gnd


----------



## Borc (Mar 12, 2014)

Thanks for quick repy !


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> This is how I have hooked it up & it works fine.
> Uno D7 to Bluetooth TX
> Uno D8 to Bluetooth RX
> 5v Vcc & Gnd


The above is correct. 

For the record, D7 is RX on the UNO side, hence it must be connected to TX on the Bluetooth side. D8 is TX on the UNO side, hence it must be connected to RX on the Bluetooth side.


----------



## Ovaltineo (Jul 18, 2013)

Gainnear said:


> Hello, i have problem
> my segway clone is slow repond
> 
> http://youtu.be/qgzzpT50UHg
> ...


_Start with the default values for KP and KD for your controller. For PID tuning, read post #475 on page 48 Higher values=faster response.._


----------



## mariocaptain (Apr 8, 2014)

My first post here, just wanted to say Hi to everyone.

Have spent the last 2 days to read the entire forum and the original thread. This work in progress is great!

I have ordered all the components and can't wait for them to come in about a week. Have already ordered the Sabertooth following recommendation in "Arduino Robotics" but now I regret it. Should have got the MotorClaw  as I do plan to experiment with encoders and onboard battery mornitoring is a huge plus.

I see a lot of improvement can still be possible on the status quote and hope to be able to contribute to this forum. Not a code guru but do have 2 years of experience playing with Arduino in various projects and tons of reading of relevant topics on this subject.

Now the hardware is on its way, will spend the next couple of days to study the code in detail. At first glance I love it that the code is very well organized, thanks OT! you indeed save people months of hard work!

Cheers!

Dave


----------



## andrew81 (Dec 21, 2013)

Hello to all reader, specially Ovaltineo, also for me this is my first post here.

I read all 60 pages post to solve my problems abiut this project but i must ask all opinion because i cannot understand.

My configuration is:
- 2 batteries 12v in series wired to have 24v
- 2 motor 24v 250W
- 1 motor controller saberthoot 2x25
- Arduino Uno
- DC to DC converter
- 1 ITG/MPU 6050 for tilt
- 1 Pot 10K for steering
- 1 Buzzer 5v

I have uncomment in segwayclone source code only pot steering and sabertooth controller, i have upload in calibrate mode, i have wait continuos beeper and after i have upload program in run mode.

My problem is similar to chinemata and uri user:
When i turn on power i listen 2 bip (i think ready signal), but after this, if i tilt my table test also of only + or - 2 degree the motors not move and i listen short short short buzzer (i think signal motor max). My motor in this configuration don't move. 

I have set DIP sabertooth on 128 adress off,off,on,on,on,on and i tried to move motor in packetized serial mode with other example program, motors are ok and also sabertooth is ok.

I ask all to aid me, I maybe wrong connections?

Wait response, thanks and bye.
Sorry for my bad english.
Andrew from Italy


----------



## mariocaptain (Apr 8, 2014)

I am not quite sure I can provide a valid answer to your question, because I am not there yet, I am still in the process of making a table-top model using the code. But any way, since forum a bit quiet, I will take a chance here. From what I can see from your serial parameters, I think its quite logical.

Not sure how you heard the MOTOR_MAX sound, but your serial printout shows that the angle of the board never excess +/- 1 degree, meaning that the board is almost level --> hence the motors do not move. If you look at the motor values in the printout, they are also consistent with board angle. The motor values there seem to be too small to make the motors move.

I think you should first debug the board angle to make sure you mount the IMU correctly (i.e. X changes when you tilt the board and not Y, or you can try by rotating the IMU by 90 degrees). Regardless of other motor parameters, when you move the board, the board angle (in the printout) should change accordingly, and should be much higher (range -90->+90 degrees).

Please correct me if I am wrong, because I have not been where you are now.

Dave Nguyen


----------



## andrew81 (Dec 21, 2013)

Dear Dave, motor speed max are setting to 20 to try code, but sound buzzer short short short is present also if i set speed motor max at 127. 
This sound buzzer (motor limit) start when i move my table test also of 0,5 degree, the alarm change when i tilt about 18 or -15 degree how program stopped for limit angle and sound buzzer change in this type of alarm.
I repeat that motors not move in all condition tried.
Thanks for now.


----------



## mariocaptain (Apr 8, 2014)

Can you confirm that you didn't change anything in the code, except for commenting/uncommenting relevant lines in SegwayClone.h?

Sorry I may not be of help, as I planned to spend this weekend to read the code thoroughly and test with the table top model. But I hope you can debug it. From a glance, these are the lines in SegwayClone.ino that trigger the MOTOR MAX alarm:

// turn on alarm for motor if required
if (motor > (MOTOR_MAX * MOTOR_ALARM_PERCENT/100.0) || motor < -(MOTOR_MAX * MOTOR_ALARM_PERCENT/100.0))
alarmArray[ALARM_MAX_MOTOR]=1;

You can see that MOTOR_ALARM_PERCENT by default is 80. Therefore, MOTOR_MAX * MOTOR_ALARM_PERCENT/100.0
<-> 20 x 80% -> 16

In your printout, there are quite a few values excess 16 --> hence the alarm.

Sorry can't help you further right now, hope this gives you some clues to debug further...

Dave


----------



## andrew81 (Dec 21, 2013)

I tried to change MOTOR ALARM PERCENT into 120 and Sound alarm not start but the great and principal problem is that anything motor not move. I suspect that there is a problem into wire connection about ground logic and ground power, i not understand this, please, can you view image connection?
Thanks


----------



## JBuilder (Feb 12, 2014)

Dear andrew,
I am struggeling with nearly the same configuration too.
It seems for me to be a problem with the sabertooth (Autobaud).

The reference told that only the first byte is responsable for the speed recognition.
This has to be 2 seconds after the sabertooth has been powered on.


During the initmotor methode there are the first bytes send but there is no pause !
-----------

But the peep peep problem you described is the same for me. 
Sometimes there is a Error 4 after some zigzags from my segway an than it is over the sabertooth and the motors are frozen with the last value - very dangerous without kill switch !!


----------



## Ovaltineo (Jul 18, 2013)

I've always said the Sabertooth is a scam and people should not buy it - http://www.diyelectriccar.com/forums/showpost.php?p=370004&postcount=129. The Roboclaw is much better for the same price.


Anyway, you guys have already bought it, so let's see if we can get it working. First, make sure the DIP switch is set correctly.









Second, download and install the DEScribe software (http://www.dimensionengineering.com/info/describe) and configure the Sabertooth to 38400 baud.

Lastly, can you guys please run the test sketch I posted here - http://www.diyelectriccar.com/forums/showpost.php?p=372160&postcount=168? 

Let me know if that works.


----------



## Borc (Mar 12, 2014)

Hi,

I have too problems with Sabertooth 2x25 V2. In Run mode (after calibration) no motors turn and no response of giro movement or pot steering. But sometimes after few minutes one motor start to spin uncontrolled then another and after some time system begin to respond somehow (or maybe not) to code. 
Same if powered from external regulator or Sabertooth 5V out.
DIP switches set correctly, speed in packetized serial set to 38400 baud.
Describe working normally - i guess no damage to controller is done.
Motor test from sketch not working!
Anyone has working item with Sabertooth 2x25 V2?


----------



## Ovaltineo (Jul 18, 2013)

Borc said:


> Hi,
> 
> I have too problems with Sabertooth 2x25 V2. In Run mode (after calibrationI'm juno motors turn and no response of giro movement or pot steering. But sometimes after few minutes one motor start to spin uncontrolled then another and after some time system begin to respond somehow (or maybe not) to code.
> Same if powered from external regulator or Sabertooth 5V out.
> ...


Ok, let us get the test sketch working for now. Can you power on the Arduino after the Sabertooth? I'm just wondering if the Sabertooth needs time to boot.
Also, can you post photos of the connections?


----------



## electricpolo (Mar 15, 2011)

I have a RoboClaw 2x60. On bench testing, it works fine with both serial speed commands and also the encoder speed commands. 
It also has built-in encoder support which is what I am using with AMT102 encoders.
From what I have read, the Sabretooth controllers seem to be a bit problematic.
Perhaps it would be better to scrap the Sabretooth & buy a RoboClaw even if it is more expensive.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> I have a RoboClaw 2x60. On bench testing, it works fine with both serial speed commands and also the encoder speed commands.
> It also has built-in encoder support which is what I am using with AMT102 encoders.
> From what I have read, the Sabretooth controllers seem to be a bit problematic.
> Perhaps it would be better to scrap the Sabretooth & buy a RoboClaw even if it is more expensive.


We won't give up so easily ! It's only difficult because I don't have one to test my code.


----------



## GerryEVO (Oct 28, 2013)

Hello to all, 
my name is Gerardo and I write in this forum for the first time. I also use a sabertooth 2x25 and confirm that you can turn on before or after Arduino. I have already made a segway clone but I'd like to try your setup to get a better result. 
Sincerely, 
Gerardo


----------



## GerryEVO (Oct 28, 2013)

Hello, 
here's my segway clone: https://www.youtube.com/watch?v=ht3QDVwe3j8 
I'd like it better with your help. 
See you soon, 
Gerard.


----------



## mariocaptain (Apr 8, 2014)

GerryEVO said:


> Hello,
> here's my segway clone: https://www.youtube.com/watch?v=ht3QDVwe3j8
> I'd like it better with your help.
> See you soon,
> Gerard.


Hi Gerard, your clone is aready very good! And the build is already near commercial grade. I see that it is self balancing quite well. Any chance you can share the PID control code of it? 

Dave


----------



## mariocaptain (Apr 8, 2014)

There are a couple of things from the balancing theory that still confuse me, despite a lot of googling and reading. Can someone please provide some explanation.

-I understand how the segway clone can make itself balanced around the zero degree point. Put how it keeps moving steadily when the rider leans forward still puzzles me. In my understanding, when the rider leans forward, the board angle will increase, so the PID loop will increase motors power in order to catch up. If it still does not catch up, the PID loop will keep increasing motors power (motor = motor + speed_adjust; in the code) until it finally catches up with the angle change by the rider, making board angle zero --> segway will stop. Which is not the case in reality! So how does it actually work?

- To aid in self balancing when there is no rider, when calibrating do you have to keep the segway clone as close to the angle that it can almost stand on it own as possible (may not necessarily be zero degree - or board parallel with floor - since different builds will have different center of mass)? As I understand, if the center of mass is not in (or very close to) the axle plane, clone will have a hard time trying to balance (no rider) --> since the vehicle already tends to fall quickly at start up, the clone will keep chasing making it going forward instead of standing still. Is that the case? 

P.S. I am still awaiting the HC-06 bluetooth to be able to adjust KD KP on the fly and experiment the second point above on my table top clone. The model currently can't stand on it own pass 1 second 

Dave


----------



## GerryEVO (Oct 28, 2013)

mariocaptain said:


> Hi Gerard, your clone is aready very good! And the build is already near commercial grade. I see that it is self balancing quite well. Any chance you can share the PID control code of it?
> 
> Dave


Hello, 
here is the link where I took the code and the wiring diagram. 
http://www.instructables.com/id/Self-Balancing-Scooter-Ver-20/?ALLSTEPS
Best wishes


----------



## GerryEVO (Oct 28, 2013)

I would like to implement the HC-06 Bluetooth to be able to adjust on the fly on my KD KP balancing code. I kindly ask if someone offers to help me because I was not familiar Arduino. 
Thank you, 
Regards, Gerard


----------



## andrew81 (Dec 21, 2013)

Ovaltineo said:


> I've always said the Sabertooth is a scam and people should not buy it - http://www.diyelectriccar.com/forums/showpost.php?p=370004&postcount=129. The Roboclaw is much better for the same price.
> 
> 
> Anyway, you guys have already bought it, so let's see if we can get it working. First, make sure the DIP switch is set correctly.
> ...


Dear OT, for second point i have not a converter stl-usb that need appear during pc connection, there is the possibility to connect pc to sabertooth using describe software with arduino board for example?
I have try to upload test sketch but result that motor not move, anything move.
I attached image to check my connections in order to found any wire problem.
Thanks for now.


----------



## Rjkley (Feb 25, 2014)

I want to use Arduino Nano for Segway clone (one wheel) with btn7960 and Bluetooth. It is possible, or problems exist for such a decision? On your charts for on roboklav or sabertus you have bluetooth, and for btn7960 no bluetooth


----------



## Borc (Mar 12, 2014)

Ovaltineo said:


> Ok, let us get the test sketch working for now. Can you power on the Arduino after the Sabertooth? I'm just wondering if the Sabertooth needs time to boot.
> Also, can you post photos of the connections?


 
Hi,
here is my "double side" arduino shield routing.
Top
https://plus.google.com/photos/1117...6002241994271155090&oid=111711094936583361889

Bottom
https://plus.google.com/photos/1117...6002241996774374034&oid=111711094936583361889

Attached to arduino:
https://plus.google.com/photos/1117...6002241990655827474&oid=111711094936583361889

https://plus.google.com/photos/1117...6002242018759164546&oid=111711094936583361889

https://plus.google.com/photos/1117...6002242018450454562&oid=111711094936583361889

https://plus.google.com/photos/1117...6002242031261635906&oid=111711094936583361889

Board is connected to 24V via step down converter (11V on Vin). Yesterday routed another board with analog giro ( IDG650/ADXL335)and other code for analog, connected to Sabertooth via simplified serial at 9600 is working perfect (Sabertooth was re-jumped and re-programed to 9600). So I guess Sabertooth is working -or has problem with Packet Serial and arduino is working fine.
Strange is that direct pined (without board) motor test is not working.
Will check again and try to power Sabertooth first.
Friend of mine has model and everything is working fine.

Thanks for help!


----------



## mariocaptain (Apr 8, 2014)

GerryEVO said:


> I would like to implement the HC-06 Bluetooth to be able to adjust on the fly on my KD KP balancing code. I kindly ask if someone offers to help me because I was not familiar Arduino.
> Thank you,
> Regards, Gerard


I have not read OT's bluetooth processing code, but if you can send me your code, I will try to see if I can help you integrating it over the coming weekend.

Dave


----------



## GerryEVO (Oct 28, 2013)

mariocaptain said:


> I have not read OT's bluetooth processing code, but if you can send me your code, I will try to see if I can help you integrating it over the coming weekend.
> 
> Dave


Thank you very much for your help. 
I think these are the variables to be set:
//Variables for power and torque
#define TORQUE 9
#define POWER 0.95
Here is the link to the code I use (Arduino IDE 22 or 23):
http://www.instructables.com/files/orig/F6S/Z50M/GZ0JI60O/F6SZ50MGZ0JI60O.txt
My best wishes,
Gerardo


----------



## Ovaltineo (Jul 18, 2013)

andrew81 said:


> Dear OT, for second point i have not a converter stl-usb that need appear during pc connection, there is the possibility to connect pc to sabertooth using describe software with arduino board for example?
> I have try to upload test sketch but result that motor not move, anything move.
> I attached image to check my connections in order to found any wire problem.
> Thanks for now.


Andrew,

In the test sketch, try replacing
Serial1.begin(38400);
with
Serial1.begin(9600);

Let us know if it works.


----------



## Ovaltineo (Jul 18, 2013)

Rjkley said:


> I want to use Arduino Nano for Segway clone (one wheel) with btn7960 and Bluetooth. It is possible, or problems exist for such a decision? On your charts for on roboklav or sabertus you have bluetooth, and for btn7960 no bluetooth


You can still use Bluetooth as long as you don't enable VOLTAGE_LED. Just replace
#define SOFT_RX_PIN3 7 // connect to bluetooth module TX pin
#define SOFT_TX_PIN3 8 // connect to bluetooth module RX pin
with
#define SOFT_RX_PIN3 5 // connect to bluetooth module TX pin
#define SOFT_TX_PIN3 6 // connect to bluetooth module RX pin


----------



## Ovaltineo (Jul 18, 2013)

Borc said:


> Hi,
> here is my "double side" arduino shield routing.
> Top
> https://plus.google.com/photos/1117...6002241994271155090&oid=111711094936583361889
> ...


Borc,
Please try changing to 9600 baud as per post #615.


----------



## Ovaltineo (Jul 18, 2013)

GerryEVO said:


> I would like to implement the HC-06 Bluetooth to be able to adjust on the fly on my KD KP balancing code. I kindly ask if someone offers to help me because I was not familiar Arduino.
> Thank you,
> Regards, Gerard


It is a HUGE amount of work to write an Android app and integrate it with Bluetooth for your code . But ZERO work if you use my code . Take your pick.


----------



## andrew81 (Dec 21, 2013)

Ovaltineo said:


> Andrew,
> 
> In the test sketch, try replacing
> Serial1.begin(38400);
> ...


Dear OT, i have changed value Serial1.begin from 38400 to 9600 and all 2 motors started with accelleration from 0 to 127 and from -1 to -127.
Test appear ok... I hope that this aid you to tell me where is my problem in segway clone program or in other part configuration.
I wait you to know what you think, thanks for now.


----------



## mariocaptain (Apr 8, 2014)

Ovaltineo said:


> It is a HUGE amount of work to write an Android app and integrate it with Bluetooth for your code . But ZERO work if you use my code . Take your pick.


@Hi Gerard, after studying the code of bluetooth processing by OT, I realize that unfortunately what OT's just said is quite true. To mod your code, you will have to mod it so that it can work with the existing Android app, and the bluetooth.ino also has to be modified so that it works with your variables and functions. This will be quite a lot of work!

@OT, I would like to have your comments on my earlier post. Would really appreciate it. Thanks!

Also, my HC06 arrived today, but I can't seem to pair it successfully with my Galaxy S3. After hours of debugging, I think it should be defective unit. I plan to change to a HC05 in slave mode. OT, can you please confirm that it can work with the Android app so long as I name the HC05 "Segway"? Major difference being HC05 can work in both master and slave modes, and has a broader range of AT commands as far as I can see.

Dave


----------



## Ovaltineo (Jul 18, 2013)

andrew81 said:


> Dear OT, i have changed value Serial1.begin from 38400 to 9600 and all 2 motors started with accelleration from 0 to 127 and from -1 to -127.
> Test appear ok... I hope that this aid you to tell me where is my problem in segway clone program or in other part configuration.
> I wait you to know what you think, thanks for now.


That's great news! I can leave it at 9600, but it would be better if we can switch to 38400 for a slightly better response.

Can you please try the following sketch and let us know the results? This one changes the baud rate from 9600 to 38400 without using the DEScribe software. Can you power-off/power-on a few times and see if it still works?


```
#include <SoftwareSerial.h>

#define SABERTOOTH_ADDRESS 0x80

#define M1_FORWARD    0
#define M1_BACKWARD    1
#define M2_FORWARD    4
#define M2_BACKWARD    5
#define SET_BAUD    15
#define BAUD_38400    4

// software serial pins for non-mega boards
#define SOFT_RX_PIN    5            // connect to S2 pin
#define SOFT_TX_PIN    6            // connect to S1 pin
SoftwareSerial Serial1(SOFT_RX_PIN, SOFT_TX_PIN); // RX, TX

void sendCommand(byte command, int param)
{
    byte packet[4];
    packet[0] = SABERTOOTH_ADDRESS;
    packet[1] = command;
    packet[2] = param;
    packet[3] = (packet[0]+packet[1]+packet[2]) & 0x7F;
    Serial1.write(packet, sizeof(packet));
}

void setSpeedMotor1(int speed)
{
    if (speed >= 0)
        sendCommand(M1_FORWARD, speed);
    else
        sendCommand(M1_BACKWARD, -speed);
}

void setSpeedMotor2(int speed)
{
    if (speed >= 0)
        sendCommand(M2_FORWARD, speed);
    else
        sendCommand(M2_BACKWARD, -speed);
}

void initMotors(void)
{
    Serial1.begin(9600);            // initialize serial port at 9600
    sendCommand(SET_BAUD, BAUD_38400);    // change baud rate to 38400
    delay(200);
    
    Serial1.begin(38400);            // initialize serial port at 38400
    //stop motors
    controlMotors(0, 0);        
}


void controlMotors(int speedL, int speedR) 
{
    setSpeedMotor1(speedL);
    setSpeedMotor2(speedR);
}

void setup()
{
    Serial.begin(115200);
    initMotors();
}

static int speed = 0;
static int increment = 1;
static int count = 0;

void loop()
{
    speed = speed + increment;
    if (speed >= 127)
        increment = -1;
    else if (speed <= -127)
        increment = 1;
    Serial.print("Speed = ");
    Serial.println(speed);
    controlMotors(speed, speed);
    delay(500);
}
```


----------



## Ovaltineo (Jul 18, 2013)

mariocaptain said:


> There are a couple of things from the balancing theory that still confuse me, despite a lot of googling and reading. Can someone please provide some explanation.
> 
> -I understand how the segway clone can make itself balanced around the zero degree point. Put how it keeps moving steadily when the rider leans forward still puzzles me. In my understanding, when the rider leans forward, the board angle will increase, so the PID loop will increase motors power in order to catch up. If it still does not catch up, the PID loop will keep increasing motors power (motor = motor + speed_adjust; in the code) until it finally catches up with the angle change by the rider, making board angle zero --> segway will stop. Which is not the case in reality! So how does it actually work?


Someone has used my code and built a small self-balancing robot (you don't ride it ). When pushed momentarily, it will move, balance and stop. But, if you continually push it, it will keep moving.

The same thing happens on a Segway - you are continually pushing it, hence it keeps moving. With correct P&D values, the PID routine will gently try to balance -- this is not enough to push the rider+platform back into zero angle. With very high P&D values, it will actually pushback the rider+platform to zero angle, stopping the Segway, but it will overshoot and oscllilate badly. Not very useful. The optional "pushback routine" actually try to do this overshoot momentarily.




> - To aid in self balancing when there is no rider, when calibrating do you have to keep the segway clone as close to the angle that it can almost stand on it own as possible (may not necessarily be zero degree - or board parallel with floor - since different builds will have different center of mass)? As I understand, if the center of mass is not in (or very close to) the axle plane, clone will have a hard time trying to balance (no rider) --> since the vehicle already tends to fall quickly at start up, the clone will keep chasing making it going forward instead of standing still. Is that the case?
> 
> Dave


A badly balanced machine is the equivalent of someone continually pushing it, hence, it will move.


----------



## Ovaltineo (Jul 18, 2013)

mariocaptain said:


> Also, my HC06 arrived today, but I can't seem to pair it successfully with my Galaxy S3. After hours of debugging, I think it should be defective unit. I plan to change to a HC05 in slave mode. OT, can you please confirm that it can work with the Android app so long as I name the HC05 "Segway"? Major difference being HC05 can work in both master and slave modes, and has a broader range of AT commands as far as I can see.
> 
> Dave


Hmm, so "linvor" does not appear in your phone as a bluetooth device? Yes, you can use the HC05. It will work with "SEGWAY" or "linvor".


----------



## andrew81 (Dec 21, 2013)

Ovaltineo said:


> That's great news! I can leave it at 9600, but it would be better if we can switch to 38400 for a slightly better response.
> 
> Can you please try the following sketch and let us know the results? This one changes the baud rate from 9600 to 38400 without using the DEScribe software. Can you power-off/power-on a few times and see if it still works?
> 
> ...


Dear OT, i have upload code received but motor not move, anything move.
I tried to upload Segwayclone program and i have change serial1.begin(38400) into 9600 in layer motor. With this modify Program start and from bench test appear funcion correctly. Do you think abiut this?
Thanks for now.


----------



## mariocaptain (Apr 8, 2014)

Ovaltineo said:


> Someone has used my code and built a small self-balancing robot (you don't ride it ). When pushed momentarily, it will move, balance and stop. But, if you continually push it, it will keep moving.
> 
> The same thing happens on a Segway - you are continually pushing it, hence it keeps moving. With correct P&D values, the PID routine will gently try to balance -- this is not enough to push the rider+platform back into zero angle. With very high P&D values, it will actually pushback the rider+platform to zero angle, stopping the Segway, but it will overshoot and oscllilate badly. Not very useful. The optional "pushback routine" actually try to do this overshoot momentarily.
> 
> A badly balanced machine is the equivalent of someone continually pushing it, hence, it will move.


This all makes sense to me know, thanks a lot OT!



Ovaltineo said:


> Hmm, so "linvor" does not appear in your phone as a bluetooth device? Yes, you can use the HC05. It will work with "SEGWAY" or "linvor".


I think the HC06 is defective. I have just managed to get the HC05 to work with the Android app, but app acting a little weird.

This is my experience.

To set up the HC05 (name, baud, password etc) I use this routine instead of the routine in processBluetooth, just to make sure I can check what have been set is right, and since I have the exact breakout board.

Now the weird part is that the app halts right after the first exchange of data at 115200 baud. After some debugging I confirmed that there were no futher request for data from the app. 

I remember reading somewhere that softwareserial is not reliable for such high speed, so I changed to 38400 baud.

This time the app keeps updating for around 2 seconds before it halts.

I decreased further down to 9600 and it worked except the below.

Another weird thing for all speed is that the app halts the first time I run the app, but for 9600 baud, if I make it sleep (back button on android) and revoke the app again then it works. Not a too big deal though.

In all cases, I set No parity and 1 stop bit for the baud of HC05.

OT, you have any idea?


----------



## Ovaltineo (Jul 18, 2013)

andrew81 said:


> Dear OT, i have upload code received but motor not move, anything move.
> I tried to upload Segwayclone program and i have change serial1.begin(38400) into 9600 in layer motor. With this modify Program start and from bench test appear funcion correctly. Do you think abiut this?
> Thanks for now.


OK, it looks like Sabertooth won't change the baud rate to 38400, even though the manual says it can. I will switch the code to use 9600. So what you did is correct - my next release will have the same change.


----------



## Ovaltineo (Jul 18, 2013)

I've just released v5.1 of the Arduino sketch. The only change is switching from 38400 to 9600 baud for the SABERTOOTH_CONTROLLER.


----------



## Ovaltineo (Jul 18, 2013)

mariocaptain said:


> This all makes sense to me know, thanks a lot OT!
> 
> 
> 
> ...


Can you post some pictures? I just want to get an idea how clean/solid your connections are and how far they are from the motors. I'm surprised that it doesn't work even at 38400 baud. I've got a MEGA 2560, so I don't actually use the SoftSerial library. A MEGA clone is only $17 -- I don't know why a lot of people still buy the inferior UNO . If your connections are good, I think switching to a MEGA will fix your problem.


----------



## andrew81 (Dec 21, 2013)

Ovaltineo said:


> I've just released v5.1 of the Arduino sketch. The only change is switching from 38400 to 9600 baud for the SABERTOOTH_CONTROLLER.


Dear Ot, Thanks, thanks very much.
When my clone is ready, i post some photo.


----------



## Borc (Mar 12, 2014)

Hi Ovaltineo and others,

I can confirm that with speed set at 9600 baud and latest code, everything is working fine. 
With setting the Sabertooth (code above without describe) and previous Segway clone code (38400 baud) system is not working, neither latest Segway clone code (9600 baud).
So Sabertooth obviously is changing speed to 38400 baud.
I'm using cheap Arduino Uno clone.
Friend who has working model at 38400 baud is using original Arduino Uno.
Maybe cheap clone is not performing OK at higher speeds?

Setting speed back to 9600 baud on Sabertooth and loading code 5.1 is way to go.

Thanks for help Ovaltineo and others!


----------



## electricpolo (Mar 15, 2011)

*Re: My Clone Progress*

Moved this post about my clone build to a new build thread
http://www.diyelectriccar.com/forums...ild-95729.html


----------



## mariocaptain (Apr 8, 2014)

Ovaltineo said:


> Can you post some pictures? I just want to get an idea how clean/solid your connections are and how far they are from the motors. I'm surprised that it doesn't work even at 38400 baud. I've got a MEGA 2560, so I don't actually use the SoftSerial library. A MEGA clone is only $17 -- I don't know why a lot of people still buy the inferior UNO . If your connections are good, I think switching to a MEGA will fix your problem.


OT, unfortunately I only have 1 phone (the one running Android) right now so I can't take photos/make video of the phone running the app right now, but I suspect that the problem is with serial. I am ordering a Mega, should arrive in 2 days. Will test an let you now the results. If still doesn't work, I will dig further and let you know.


----------



## Centrex (Nov 24, 2013)

Hi Oval
Other than the obvious extra pins etc what makes the mega better for the segclone than the Uno.
The price is certainly good on ebuy.

Just for my education.
Regards
Cliff


----------



## Ovaltineo (Jul 18, 2013)

Centrex said:


> Hi Oval
> Other than the obvious extra pins etc what makes the mega better for the segclone than the Uno.
> The price is certainly good on ebuy.
> 
> ...


The mega has 3 or 4 hardware serial ports vs 1 for the uno. The mega also has more memory. Certainly worth the extra couple of bucks for the clone prices.


----------



## Ovaltineo (Jul 18, 2013)

*Re: My Clone Progress*



electricpolo said:


> Thought I might post some pics of the progress of my clone. Base frame underside is about 90% done.
> First & second pics show the steel base frame, axles, hubs & wheels.
> Third pic shows the motor & drive arrangement. With the toothed belts and after the gearbox mods, the backlash is almost zero. Very good result.
> Fourth pic shows upside down view of motors and the battery layout. Ground clearance is about 110mm at the main part of the motor & about 100mm at the gearbox close to the tyre.
> Still to do the steering & tiller setup.


Really nice!! I've got those motors and can't get rid of the backlash with a chain drive and kid's bike wheels. You don't happen to live in Melbourne, do you ?


----------



## mariocaptain (Apr 8, 2014)

Ovaltineo said:


> Can you post some pictures? I just want to get an idea how clean/solid your connections are and how far they are from the motors. I'm surprised that it doesn't work even at 38400 baud. I've got a MEGA 2560, so I don't actually use the SoftSerial library. A MEGA clone is only $17 -- I don't know why a lot of people still buy the inferior UNO . If your connections are good, I think switching to a MEGA will fix your problem.


OT, here are a few pictures of my table top clone. I think the connections should be clean.

From bottom up:
- Geared motors
- L298N motor driver & MPU-6050
- Uno and Proto Shield
- HC-05

I modified your motor control code to work with the L298N driver.

Everything connected by female-female cable and terminals.

I power both the motor driver and arduino by a 9V adapter. HC-05 is powered by the 5V from Arduino.

My Mega will arrive tomorrow and I will break this thing up to try with Mega and let you know.

On the UNO, not sure how ppl favor the Uno, but for me cuz it uses the DIP 328P, so once I am done with a project, its easy to make a cheap stand-alone UNO (328P) with just a few extra components to replace the UNO, then the UNO can be freed for other experiments.

Dave


----------



## mariocaptain (Apr 8, 2014)

*Re: My Clone Progress*



electricpolo said:


> Thought I might post some pics of the progress of my clone. Base frame underside is about 90% done.
> First & second pics show the steel base frame, axles, hubs & wheels.
> Third pic shows the motor & drive arrangement. With the toothed belts and after the gearbox mods, the backlash is almost zero. Very good result.
> Fourth pic shows upside down view of motors and the battery layout. Ground clearance is about 110mm at the main part of the motor & about 100mm at the gearbox close to the tyre.
> Still to do the steering & tiller setup.


@electricpolo: can you please post a link to the specs of these nice motors? And is there a place on these motors to mount the encoder? since I heard you are using AMT102 encoders. I plan to buy these motors and the encoders too 

Cheers
Dave


----------



## electricpolo (Mar 15, 2011)

Moved this post about Dayton motors backlash to a new build thread
http://www.diyelectriccar.com/forums/showthread.php/electricpolo-segway-clone-build-95729.html


----------



## electricpolo (Mar 15, 2011)

Moved this post about my encoders to a new build thread
http://www.diyelectriccar.com/forums/showthread.php/electricpolo-segway-clone-build-95729.html


----------



## JBuilder (Feb 12, 2014)

Hi to the rest of you.
I did the first "run" with my seggi.
I didn't find out why my combination of 2xmpu6050 and my sabertooth will not work without massive failure (my leg hurts still after a small crash)

So I did it with a poti and -- it works. 
My Seggi is spinning like a devil but doesn't accelerate as fast as can spin.

Something wiht the KD KI KP values i guess - anyone a good idea ?

By for now. 
Tomorrow some pics

Joerg


----------



## Ovaltineo (Jul 18, 2013)

JBuilder said:


> Hi to the rest of you.
> I did the first "run" with my seggi.
> I didn't find out why my combination of 2xmpu6050 and my sabertooth will not work without massive failure (my leg hurts still after a small crash)


Did you bench test it first? Did you check the output with a serial monitor? Post the output. Can you post pics of how the steering sensor is mounted?



> So I did it with a poti and -- it works.
> My Seggi is spinning like a devil but doesn't accelerate as fast as can spin.
> 
> Something wiht the KD KI KP values i guess - anyone a good idea ?
> ...


A video would give us a good indication of the slow response. You definitely need to adjust KP and KD. The android app makes it easy.

-Carmelo


----------



## mariocaptain (Apr 8, 2014)

OT, since you are using the RoboClaw, any plan to incorporate encoders?

I have just finish reading the entire RoboClaw manual and I agree compared to it the Sabertooth is a total rip off . Since the RoboClaw can do encoder processing by itself, and has an internal PID controller, it basically does all the hardwork for us so we can go banking (if thats the word, sorry English not my mother tonge) and ramping.

I actually ordered these motors, used by Chinese "segway":
http://item.taobao.com/item.htm?spm=a230r.1.14.36.PknZ5B&id=35663364548

Still waiting for them to arrive. I can tell motor doesn't have an encoder, and not sure if I can mount one, but in the demo video in the page, the chinese clone performs pretty well up the ramp as well as when on a bank (retarded cam angle btw)

I hope to build something like this  Just to share my thoughts...


----------



## electricpolo (Mar 15, 2011)

You could fit encoders to these motors in the same manner I have done with my Dayton motors. 
You could also have rotary encoders driven by the gearbox output shaft but it would be a bit tricky to setup. Also need a fairly high pulse rate for the gearbox shaft method because the output shaft goes so slowly


----------



## mariocaptain (Apr 8, 2014)

electricpolo said:


> You could fit encoders to these motors in the same manner I have done with my Dayton motors.
> You could also have rotary encoders driven by the gearbox output shaft but it would be a bit tricky to setup. Also need a fairly high pulse rate for the gearbox shaft method because the output shaft goes so slowly


Yeah can't wait to open the motors to see inside. Need to make sure there is actually a place to mount the 8mm hole of the encoder before ordering. You're right, encoder after the gears will have much lower resolution, not worth it.

Btw, thanks for all the info shared earlier.
Dave


----------



## Ovaltineo (Jul 18, 2013)

mariocaptain said:


> OT, since you are using the RoboClaw, any plan to incorporate encoders?


They are already supported. Check the README.


----------



## electricpolo (Mar 15, 2011)

The AMT102 encoders have an adjustable pulse per revolution of between 48 to 2048. They need to be mounted on a flat area at 90 degrees to the motor shaft. The encoder input shaft can be anywhere between 2mm & 8mm or 1/8" to 1/4" & the kit has all the different size sleeves included.

You could try using these on the gearbox output - maybe a wheel running against the gear output shaft or a little chain drive from an RC car. Bit fiddly though. They are not adjustable so you need to buy one with a suitable PPR. The higher PPR ones would have enough resolution for the slow gearbox shaft.

http://www.ebay.com.au/itm/Encoder-...737?pt=LH_DefaultDomain_0&hash=item3cd4205de1
http://www.ebay.com.au/itm/Encoder-...963?pt=LH_DefaultDomain_0&hash=item35d236afab

I looked at both types and my choice was the AMT encoders because I could mount them on the end of the motors out of harms way. 
Encoders are a bit fragile so you can't have them where they may get hit by sticks & the like.


----------



## JBuilder (Feb 12, 2014)

Ovaltineo said:


> Did you bench test it first? Did you check the output with a serial monitor? Post the output. Can you post pics of how the steering sensor is mounted?
> 
> 
> A video would give us a good indication of the slow response. You definitely need to adjust KP and KD. The android app makes it easy.
> ...



First the pictures with the position of the tilt sensor neary the axle.
The steering is only "experimental" but it works.


----------



## Ovaltineo (Jul 18, 2013)

JBuilder said:


> First the pictures with the position of the tilt sensor neary the axle.
> The steering is only "experimental" but it works.


Sorry, I can't see the MPU6050 steering sensor in any of those pictures.


----------



## mariocaptain (Apr 8, 2014)

Does anyone know of something equivalent to the RoboClaw but for BLDC (brushless DC motors)?

I am also considering BLDC to see if they are feasible. Reason being BLDC's can give very good torque at very low speeds.


----------



## mariocaptain (Apr 8, 2014)

Ovaltineo said:


> ... I've got a MEGA 2560, so I don't actually use the SoftSerial library. A MEGA clone is only $17 -- I don't know why a lot of people still buy the inferior UNO . If your connections are good, I think switching to a MEGA will fix your problem.


OT, I confirm that switching to the mega solves the problem of glitchy bluetooth operation. So the problem should be with software serial on Uno.


----------



## electricpolo (Mar 15, 2011)

*Re: ElectricPolo Segway Clone*

More build pics here on a separate thread. 
Expect to maybe give it a bit of test sometime over the weekend.
http://www.diyelectriccar.com/forums/showthread.php?p=386708#post386708


----------



## electricpolo (Mar 15, 2011)

*Re: BLDC Motor Controllers*



> Does anyone know of something equivalent to the RoboClaw but for BLDC (brushless DC motors)?
> 
> I am also considering BLDC to see if they are feasible. Reason being BLDC's can give very good torque at very low speeds.


Have a look at this website for BLDC controllers http://kellycontroller.com/products.php

Don't know whether a BLDC motor or controller can reverse fast enough to keep everything in balance though.


----------



## JBuilder (Feb 12, 2014)

Ovaltineo said:


> Sorry, I can't see the MPU6050 steering sensor in any of those pictures.


I post an new picture, The sensor is in the red rectangle.


----------



## mariocaptain (Apr 8, 2014)

*Re: ElectricPolo Segway Clone*



electricpolo said:


> More build pics here on a separate thread.
> Expect to maybe give it a bit of test sometime over the weekend.
> http://www.diyelectriccar.com/forums/showthread.php?p=386708#post386708


Posted on your thread. Can't wait to see you test drive it, and share with us your experience, especially with PID tuning.
Dave


----------



## electricpolo (Mar 15, 2011)

JBuilder
How is the steering sensor attached to the tiller arm?
From the photo, it looks like it is fixed to the side wall of the base frame.


----------



## JBuilder (Feb 12, 2014)

electricpolo said:


> JBuilder
> How is the steering sensor attached to the tiller arm?
> From the photo, it looks like it is fixed to the side wall of the base frame.


Only the tilt sensor is directly mounted on the mega Board. What you see is the back wall of the base frame. 
I used the same four pins from the tilt mpu to connect the steering mpu (Adress 69) and mounted it half way in on the steering pole. The pole is a little bit elastic and can be bended (correct word?)
Most experiments failed with error 11 or 4 (I think communication problem).
The sabertooth is so silly that the last signal will be executed forever. Even it the full throttle.(very dangerous). Even when I used a klill switch the controller is not reseted to zero. It only stops the motors. But when connected the switch again the motors are full power. I have to think about this problem next time.

For now I am using a poti on top of the steering pole and its ok. I little to sensitiv but it works. 
My plan is to use the "good" connections from the poti for the steering mpu. This way I find out weather the wiring is the problem.

I keep you informed.
Bye Joerg


----------



## JBuilder (Feb 12, 2014)

Hi,
I think a found a situation to reconstruct the errors:

I am using the same wires with are perfect for my poti.

In the 2 mpu configuration with power from usb and my mega everything goes correct. The monitor shows only a small drift for the motor power.

I attach some files.

Callibration OK - 
Run OK - with wheels in the air - 
Run OK with wheels in the air and changing angles and shaking the steering pole 

BUTTTTTTT -switchinh on the sabertooth (with a switch on the 24V)

Errors in the log file.
The Mega has its own power supply.(During Test power from USB)
The sabertooth has its 24V batteries. Frame is Battery Minus
The only Connection between them is the 0V Pin from the sabertooth to a GND Pin of the Mega.

What the hell is going on ? 
Bye to all of you 
Joerg


----------



## Ovaltineo (Jul 18, 2013)

JBuilder said:


> Hi,
> I think a found a situation to reconstruct the errors:
> 
> I am using the same wires with are perfect for my poti.
> ...


I noticed that you are using prototyping wires (with black plastic and small round pins at the end) to connect the Arduino to other components. They are *not* suitable for this application. They can easily come loose and don't make a reliable connection. Use soldered wires if possible or proper connectors with square pins and sockets. For connecting the steering MPU6050, I suggest using a shielded cable. Those motors are generating a LOT of electrical noise. This won't affect the analog signal from a poti, but will easily affect the digital 400kHz signal of the I2C bus used by the MPU6050.

-Carmelo


----------



## emccarron (Mar 23, 2014)

Borc said:


> Hi,
> 
> I have too problems with Sabertooth 2x25 V2. In Run mode (after calibration) no motors turn and no response of giro movement or pot steering. But sometimes after few minutes one motor start to spin uncontrolled then another and after some time system begin to respond somehow (or maybe not) to code.
> Same if powered from external regulator or Sabertooth 5V out.
> ...


I'm using the Sabretooth 2x25. How old is your sabretooth? The older version had different requirements for baud setting -- I've modified the motor init section to pause 2s, then send the autobaud character (AA hex) and carry on from there. It increases the startup delay, but it works.

I'll post the snippet of autobaud code when I get on the right computer in case that will help anyone.


----------



## Borc (Mar 12, 2014)

Hi, 
Sabertooth was received about a month ago - it should be the last version. After setting speed to 9600 baud, works as it should. With 38400 baud - no go. Ordered Arduino Mega to test, since these problems only appear on Uno.


----------



## Borc (Mar 12, 2014)

finished with frame building:
2x 300W motors (210 RPM)
2x 12V 18Ah battery


----------



## mariocaptain (Apr 8, 2014)

Borc said:


> finished with frame building:
> 2x 300W motors (210 RPM)
> 2x 12V 18Ah battery


Nice build!

The two motors are off from the axle, will the board tend to fall in that direction?
Do you have to use some kind of a couterweight on the other side to counterbalance?

Dave


----------



## Borc (Mar 12, 2014)

mariocaptain said:


> Nice build!
> 
> The two motors are off from the axle, will the board tend to fall in that direction?
> Do you have to use some kind of a couterweight on the other side to counterbalance?
> ...


Batteries are set way back to be counterweight on the other side, but still not ideal when stick will be mounted etc...(I will make final adjustments at the end). In free run, it will probably tend to fall in motor direction -front. When loaded, do not undeestimate my 100 kilos balancing weight .
But seriously (maybe question for other forum members too), is there any need to set the bot to balance at free run. 
On the other side, it looks really great....when you fall-off with safety switch still on ....and bot is looking for owner.
Problem with those motors is, if they are set vertical you have no place on board (or you have to make bot wider) if they are mounted in front or back direction, problems are with counterweight.


----------



## adamson (Mar 2, 2014)

My prototype look like:
















It is 70 cm width with wheels.
I'm still waiting for btn7960


----------



## Ovaltineo (Jul 18, 2013)

Borc said:


> Batteries are set way back to be counterweight on the other side, but still not ideal when stick will be mounted etc...(I will make final adjustments at the end). In free run, it will probably tend to fall in motor direction -front. When loaded, do not undeestimate my 100 kilos balancing weight .
> But seriously (maybe question for other forum members too), is there any need to set the bot to balance at free run.
> On the other side, it looks really great....when you fall-off with safety switch still on ....and bot is looking for owner.
> Problem with those motors is, if they are set vertical you have no place on board (or you have to make bot wider) if they are mounted in front or back direction, problems are with counterweight.


It's a pain in the neck if you can't let go of the clone because it will run off by itself. Hence, a balanced clone is ideal. If you mount the motors at the back, the steering pole and batteries can be the counterweight.


----------



## mariocaptain (Apr 8, 2014)

Borc said:


> But seriously (maybe question for other forum members too), is there any need to set the bot to balance at free run.


I would prefer one that balances by itself, cooler to show off . Also it will be easier and feels safer when you get on. And let risk of being run over if kill switch fails (well in my final final version I hope to remove the switch anyway)

The Seg-bot in the book Arduino Robotics does not balance at free run. I think its more of a nice-to-have feature rather than must have for DIY clones.

I think you can make the handlebar reach outside the base, and make the top of the handlebar a bit heavier to counterbalance (top section solid?). Something like this:









My motors and wheels will arrive tomorrow so my clone hopefully will take shape soon after 1 May.

OT, aside from the continuously updated code, any improvements made to the performance of your clone lately, what stage are you at?


----------



## Ovaltineo (Jul 18, 2013)

mariocaptain said:


> (well in my final final version I hope to remove the switch anyway)
> 
> OT, aside from the continuously updated code, any improvements made to the performance of your clone lately, what stage are you at?


I don't think it is a good idea to remove the kill switch. Those MOSFETs could fail in the ON position anytime.

I've upgraded my motors from 300w to 500w. But one of my BTN7960 controllers died during bench testing. So I'm grounded until parts arrive.

In the meantime, I'll be playing with a Pixy camera which can detect colored objects. It will be used for auto navigation of a robot around the house. It can also be used for auto landing of a quadcopter.


----------



## Borc (Mar 12, 2014)

As advised I made a redesign of the frame, so clone is now balanced. Steering stick is just for testing. Motors are mounted at angle that top plate could be placed over them.


----------



## mariocaptain (Apr 8, 2014)

Ovaltineo said:


> I don't think it is a good idea to remove the kill switch. Those MOSFETs could fail in the ON position anytime.


OT, are you saying that the Roboclaw is not that reliable? Cuz I plan to use them in another serious application...



Borc said:


> As advised I made a redesign of the frame, so clone is now balanced. Steering stick is just for testing. Motors are mounted at angle that top plate could be placed over them.


Awesome. I guess you are ready for the code. Let us know the test drive.

My parts have arrived except the Roboclaw and I am having a mechanic build the board to my Sketch up drawing now... should be test driving in about 3 weeks.


----------



## Ovaltineo (Jul 18, 2013)

mariocaptain said:


> OT, are you saying that the Roboclaw is not that reliable? Cuz I plan to use them in another serious application...


I'm not saying that at all. But these controllers use MOSFETs which can fail in the OFF or (much worse ) ON mode. A home-built Segway clone is pretty dangerous, especially if used in public roads/paths, and MUST have a kill switch. It doesn't have the fail-safe mechanisms (everything is monitored and duplicated) that a real Segway has.


----------



## adamson (Mar 2, 2014)

Ovaltineo, do You think, should I buy roboclaw? Is it much better(safer) than bts7960?


----------



## mariocaptain (Apr 8, 2014)

adamson said:


> Ovaltineo, do You think, should I buy roboclaw? Is it much better(safer) than bts7960?


AFAIK, the Roboclaw is far more superior than the BTS7960 and even the Sabertooth, but the BTS7960 is much more affordable than the other two.
If you can afford the Roboclaw then go for it, otherwise you can get the much cheaper BTS7960. For this type of application I much prefer the Roboclaw. Do not get the overpriced Sabertooth. I have a brand new one here unused, but have ordered the Roboclaw and still waiting for it to arrive.


----------



## electricpolo (Mar 15, 2011)

Have some questions as a result of some testing.
If I calibrate the clone in it's static balance (about 3 degree forward tilt) it will stand steady and move forwards & backwards nice & even.
If I calibrate the clone in a horizontal position, it will oscillate through a couple of degrees and not stay steady although it moves forwards & backwards OK. 
I would have expected the clone to balance itself in the calibrated position irrespective of its static balance position.
Have others experienced this oscillating movement?


----------



## mariocaptain (Apr 8, 2014)

electricpolo said:


> Have some questions as a result of some testing.
> If I calibrate the clone in it's static balance (about 3 degree forward tilt) it will stand steady and move forwards & backwards nice & even.
> If I calibrate the clone in a horizontal position, it will oscillate through a couple of degrees and not stay steady although it moves forwards & backwards OK.
> I would have expected the clone to balance itself in the calibrated position irrespective of its static balance position.
> Have others experienced this oscillating movement?


I have been pondering on the same thing for a while and I hope I have got the answer for myself.

I have not yet had a full size clone but do have a table top model. 

My understanding is that the closer the board angle is compared to the clone's true static balance angle (seems to be around 3 deg in your case) when you calibrate, the easier/better the clone will be able to balance itself. Actually for this reason, I am thinking of building some tools to help find the absolute true static balance angle of my clone once it's built since I don't even want my clone to jitter around it's self-balance point (not sure at this point if this can even be achieved though).

The larger this "error", I think the more difficult it will be for the clone to balance. In your second scenario, I think it still manages to stay around the same spot because the difference is small enough, and the PID overshoots a bit so the bot is not moving backward. So my understanding is that if this "error" is large enough, the clone will run away, pretty much the same way when you lean to make it move.

Please correct me if I am wrong.

Any vid to show off?


----------



## electricpolo (Mar 15, 2011)

OK, have done some more reading on Segways and only one commercial version will actually stand up & balance on it's own & this one has pannier bags & a handle bar bag to give it some weight up high.
All the other models do not stand up by themselves and must be held in the balance position for a rider to get on. The mat sensors then detect the rider & away they go.
The oscillating that I was seeing is caused by my machine having almost all the mass below the axle & just the handle bar above the axle. The handle bar simply does not have enough weight to create the inverted pendulum.
I could stop the oscillations by holding the handle bar & when I stood on the machine it would be steady.
Learning more about these things all the time.


----------



## anhxco (Mar 29, 2011)

Hi Oval!

Thank your very much for your hard work.
It's interesting project.
I have tested your code with sensor,currently i haven't motor and motor driver for testing.
I also have little modified your code for MODE_CALIBRATE with press button.
I will share my code for who need.
Thanks again.

Sorry for my bad english.


----------



## mariocaptain (Apr 8, 2014)

electricpolo said:


> OK, have done some more reading on Segways and only one commercial version will actually stand up & balance on it's own & this one has pannier bags & a handle bar bag to give it some weight up high.
> 
> Learning more about these things all the time.


@Electricpolo, you are so right! You startled me that I realize I have never actually seen a Segway balancing on it own, but I took things for granted, plus some wishful and logical thinking...

I have just done some quick reading and right, only the E series has that feature, which is called "e stand". 

Your reasoning about the lack of an adequate inverted pendulum makes much sense to me. I learned that even the E series is not very stable balancing on it own without a rider (jittering around) since it's physically built to work best with a rider. Seems can't be the best of both worlds. See vid here

Thanks for the info! The question is should the motors and PID loop be engaged before the rider steps up (like in OT's code when board angle falls within -2->+2 deg), or should it only start balancing when the rider is already on board?

In any case, it looks like we will only need to have 1 pair of PID values (i.e. for when rider on board), so what should those matt (foot) switches actually do (originally supposed to change PID values), are they supposed to power on the motors?

OT, have you anything to say about all this?

Thanks for any clarification and input!
Dave


----------



## electricpolo (Mar 15, 2011)

My original thinking for the rider detection switches is to simply to adjust the maximum power.
Without a rider, the power would be limited to say 10%. This actually enough to get on the machine & be balanced.
The machine can be moved without a rider but will only move or turn slowly.
When the rider is detected by the switches, the power goes to 100%. 
If the rider steps off or falls off, the power reduces to 10%.


----------



## Ovaltineo (Jul 18, 2013)

I will add provision in the code for a rider sensor. There will be different settings for P, D, and MOTOR_MAX when there is no rider detected.

When there is no rider present, use lower P and D values to avoid oscillation.

My first version of the clone was quite light (about 22 kilos) with 2X300 watt motors, 10 inch wheels and 2X7Ah batteries mounted close to the wheel axle line. I could calibrate anywhere between +5 and -5 degrees from horizontal and it would balance without moving.

My current version is heavy (50+ kilos) with 2X500 watt motors, 16 inch wheels and 2X7Ah batteries mounted away from the wheel axle line. It also has a higher center of gravity. This one is much harder to balance by itself.

So the lesson is, keep the center of gravity low and minimize the weight distribution -- keep motors and batteries close to the wheel axle line.


----------



## Bastelfix (May 6, 2014)

Hello friends! 
congratulations on this great forum and the segway clone project! 
I want to join and have a few questions. 
I want to build the mechanics similar like this:
http://www.open-electronics.org/openwheels-put-the-mechanical-pieces-togheter/

I did not find the thickness of the aluminium base plate. 
how thick would you make the base plate?

Thanks
Sven


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> I will add provision in the code for a rider sensor. There will be different settings for P, D, and MOTOR_MAX when there is no rider detected.
> 
> When there is no rider present, use lower P and D values to avoid oscillation.
> 
> ...


Are You working on rider sensor support?


----------



## Ovaltineo (Jul 18, 2013)

Yes, I will work on it this week.

I finally received by BTS7960 and tested my clone with 2 X 500W motors. I had to adjust the P and D values, but it worked well. I can now go up my hilly street. The problem is that my 2X7Ah SLA batteries are not up to the job. I need to get bigger batteries.

The BTS7960 module I got was slightly different from the old ones I have. The new one has a bigger heatsink and they used silicon grease instead of silicon film. I think it is better and would last longer.


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Yes, I will work on it this week.
> 
> I finally received by BTS7960 and tested my clone with 2 X 500W motors. I had to adjust the P and D values, but it worked well. I can now go up my hilly street. The problem is that my 2X7Ah SLA batteries are not up to the job. I need to get bigger batteries.
> 
> The BTS7960 module I got was slightly different from the old ones I have. The new one has a bigger heatsink and they used silicon grease instead of silicon film. I think it is better and would last longer.


Could You give link to the shop?


----------



## Ovaltineo (Jul 18, 2013)

Ironically, the original one with ALFS-TECH.taobao.com written on the circuit board has a smaller heatsink -- avoid it.

Each item below is the BTS7960B module with bigger heatsink. 

http://www.ebay.com/itm/KDQ14-Doubl...389?pt=LH_DefaultDomain_0&hash=item19e457bbed

http://www.ebay.com.au/itm/Semicond...Electrical_Test_Equipment&hash=item58a996f7eb

http://www.ebay.com/itm/KDQ15-Doubl...769?pt=LH_DefaultDomain_0&hash=item27da28aab1


----------



## adamson (Mar 2, 2014)

I'm going to mount bts7960 like this. Will it be ok?


----------



## albatrillo (Mar 13, 2014)

Hello
I have assembled everything and it works perfectly so far. 
I use a arduino UNO card, x2 btn7960 and x2 mpu6050.

I also have a bluetooth HC06 I want to connect, but I do not know where to connect. Can you update the previous scheme UNO plate btn7960 and bluetooth? 

thanks and best regards


----------



## wired (Nov 24, 2013)

I am using 2 of the 7960's with the bigger heatsink on the bottom of the pcb and have added a smaller heatsink on to the body of the fets. The 2 controllers fit inside a plastic case with two 12 volt mini fans in series mounted on the outside powered from the 24 volts . I have only used this setup for testing so far on smallish motors but hope it might hang together for the 350 watt 24 volt motors I will be using.
Darcy
p.s. I hope the img attachment works !!!!


----------



## Ovaltineo (Jul 18, 2013)

albatrillo said:


> Hello
> I have assembled everything and it works perfectly so far.
> I use a arduino UNO card, x2 btn7960 and x2 mpu6050.
> 
> ...


I have posted new schematic and released v5.2 to support bluetooth with UNO+BTN7960.


----------



## adamson (Mar 2, 2014)

My clone is working now. Thanks Ovaltineo. 
https://www.youtube.com/watch?v=mCIreHKDBzk&feature=youtu.be


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> My clone is working now. Thanks Ovaltineo.
> https://www.youtube.com/watch?v=mCIreHKDBzk&feature=youtu.be


Well done! I love those big wheels - like a real Segway. Have you ridden it yet? The PD values look a bit low. OK on a flat surface but might need a big lean forward to go uphill.


----------



## albatrillo (Mar 13, 2014)

Ovaltineo said:


> I have posted new schematic and released v5.2 to support bluetooth with UNO+BTN7960.


I've connected everything and the bluetooth don't works. 

There seems to be a problem in programming. arduino UNO can not use "serial3" 



Can you check that? thanks

sorry for my english


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Well done! I love those big wheels - like a real Segway. Have you ridden it yet? The PD values look a bit low. OK on a flat surface but might need a big lean forward to go uphill.


Now motor is set to 30. I haven't ridden it yet, but I tried to, motors are set to low. I will increase the PD values.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Now motor is set to 30. I haven't ridden it yet, but I tried to, motors are set to low. I will increase the PD values.


I didn't realize that MOTOR_MAX is low. Maybe PD value are OK after all.


----------



## Ovaltineo (Jul 18, 2013)

albatrillo said:


> I've connected everything and the bluetooth works.
> There seems to be a problem in programming. arduino UNO can not use "serial3"
> 
> Can you check that? thanks


Are you getting a compile error? Can you post it? Also, post your SegwayClone.h.


----------



## markula (Oct 27, 2013)

wired said:


> I am using 2 of the 7960's with the bigger heatsink on the bottom of the pcb and have added a smaller heatsink on to the body of the fets. The 2 controllers fit inside a plastic case with two 12 volt mini fans in series mounted on the outside powered from the 24 volts . I have only used this setup for testing so far on smallish motors but hope it might hang together for the 350 watt 24 volt motors I will be using.
> Darcy
> p.s. I hope the img attachment works !!!!


I think you have to reverse one of the fans. So they dont bought blows into the box and the heat have no place to leave.


----------



## wired (Nov 24, 2013)

markula said:


> I think you have to reverse one of the fans. So they dont bought blows into the box and the heat have no place to leave.


Each mini fan blows air across each controller and exits on the other side of the case via several exhaust holes.


----------



## albatrillo (Mar 13, 2014)

Ovaltineo said:


> Are you getting a compile error? Can you post it? Also, post your SegwayClone.h.


The problem is as follows: 

bluetooth does not work with android application. 
The android system synchronizes well with the HC06 but the LED is flashing continuously and there is no data transmission does the android device. 

I made sure that everything is properly connected. 

I've even tried the bluetooth with other programming apart and serial works correctly.

on the arduino website says: 

http://arduino.cc/en/reference/serial 

"serial3" is only supported for arduino mega 

Arduino UNO only supports "Serial" and the most desirable ports are port 0 and 1. 

if this can not serbir you to resolve the communication failure. 

thanks


----------



## adamson (Mar 2, 2014)

It's almost ok. 
https://www.youtube.com/watch?v=Lq7WDrwUHoc&feature=youtu.be


----------



## Ovaltineo (Jul 18, 2013)

albatrillo said:


> The problem is as follows:
> 
> bluetooth does not work with android application.
> The android system synchronizes well with the HC06 but the LED is flashing continuously and there is no data transmission does the android device.
> ...


OK, so not a compiler error. I know that the UNO doesn't have a hardware Serial3 (that's why I'm surprised you guys still buy them). I'm using SoftSerial library for the UNO, so I can call it whatever I like, including Serial3.

The problem is that the HC06 is using default settings. You need to load and run the Arduino sketch in CALIBRATE_MODE to modify the HC06 settings. Then, you re-load the sketch in run mode. Make sure you pair your Android with the HC06 again - the "linvor" name changes to "SEGWAY" during CALIBRATE_MODE.

Try this and let us know the results.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> It's almost ok.
> https://www.youtube.com/watch?v=Lq7WDrwUHoc&feature=youtu.be


Excellent!! Did you know you can stay on the clone whilst doing a pirouette turn ? You don't need to get off ! The dog loves it obviously!


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Excellent!! Did you know you can stay on the clone whilst doing a pirouette turn ? You don't need to get off ! The dog loves it obviously!


Yes, I know I can do a pirouette turn, but it not working as it should.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Yes, I know I can do a pirouette turn, but it not working as it should.


What is wrong?


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> What is wrong?


Sometimes one motor is locked and it turning itself.
The second: segway don't wont to accelerate, it wants to keep balance.(its hard to make it off balance)
And next: the next bts7960 is broken and works in one direction and I don't know why.
Maybe I'll need roboclaw, but it is expensive.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Sometimes one motor is locked and it turning itself.
> The second: segway don't wont to accelerate, it wants to keep balance.(its hard to make it off balance)
> And next: the next bts7960 is broken and works in one direction and I don't know why.
> Maybe I'll need roboclaw, but it is expensive.


Well, that's why one motor is locked - it wants to go in reverse but the BTS7960 is broken. Fix it and it will fix all your problems above. Swap your BTS modules to confirm it is the chip.

I actually bought a hot air SMD rework station so I can replace the BTS7960 chip with the higher-rated BTS7970 ($7.60 each) when it breaks. I figured it is still cheaper than buying a Roboclaw !


----------



## Ovaltineo (Jul 18, 2013)

I've just released v5.3 to support a RIDER_SENSOR. Connect the sensor/switch to pin 13. Sensor/switch must pull this pin HIGH when rider is ON and pull it LOW when rider is OFF.



> v5.3 Added support for RIDER_SENSOR. Define the RIDER_SENSOR digital input pin, KP_OFF and KD_OFF for your controller in SegwayClone.h.
> Define MOTOR_MAX_OFF for your controller in Motors.h.


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Well, that's why one motor is locked - it wants to go in reverse but the BTS7960 is broken. Fix it and it will fix all your problems above. Swap your BTS modules to confirm it is the chip.
> 
> I actually bought a hot air SMD rework station so I can replace the BTS7960 chip with the higher-rated BTS7970 ($7.60 each) when it breaks. I figured it is still cheaper than buying a Roboclaw !


Could You link me hot air smd station and bts7970? 

What kind of sensor is Rider_sensor?


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Could You link me hot air smd station and bts7970?
> 
> What kind of sensor is Rider_sensor?


I bought a YH-992DA station like this:
http://www.ebay.com/itm/New-2in1-Ho...497?pt=LH_DefaultDomain_0&hash=item3388e48031

and the BTS7970 chips here:
http://www.ebay.com/itm/1PCS-IC-INF...656?pt=LH_DefaultDomain_0&hash=item5406b75788

I meant a rider sensor. A mechanical foot switch or electronic sensor (e.g. photo interrupter) that can be used to detect the presence of a rider. 

For my rider sensor, I am planning to use an infrared LED with an infrared photodiode mounted on opposite sides of the board. If an infrared light hits the photodiode, it means there is no rider. If no light reaches the photodiode, it means there is a rider. This will act like a photo-interrupter switch.

Alternatively, I can mount the infrared LED and photodiode side by side. When no infrared light hits the photodiode, it means there is no rider. If an infrared light bounces (from a foot) and hits the photodiode, it means there is a rider. This will act like a proximity switch.

Other alternatives might be a micro switch or a pressure mat.


----------



## wired (Nov 24, 2013)

Ovaltineo said:


> I bought a YH-992DA station like this:
> http://www.ebay.com/itm/New-2in1-Ho...497?pt=LH_DefaultDomain_0&hash=item3388e48031
> 
> and the BTS7970 chips here:
> ...


I have used a switch that is activated from a foot plate when the rider steps on to the platform. The switch operates a relay that provides the 24 volt power line to the 7960 controllers. The idea being that when the foot switch is released the power relay is deactivated and thus the power to the controllers is removed.

I am sure that there are disadvantages is removing the power to the controllers in this manner but I had to start some where.
Darcy


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> I bought a YH-992DA station like this:
> http://www.ebay.com/itm/New-2in1-Ho...497?pt=LH_DefaultDomain_0&hash=item3388e48031
> 
> and the BTS7970 chips here:
> ...


I'm thinking to buy this http://www.aliexpress.com/item/New-...-Solder-Soldering-Hot-Air-Gun/1554455839.html


----------



## markula (Oct 27, 2013)

Ovaltineo said:


> I bought a YH-992DA station like this:
> http://www.ebay.com/itm/New-2in1-Ho...497?pt=LH_DefaultDomain_0&hash=item3388e48031
> 
> and the BTS7970 chips here:
> ...


If you se in the datasheet the BTS7960 have 32 m Ohm and the BTS7970 has 16 m Ohm so they are more efficient so you can use smaller heat sink and get some longer range with the same battery.


----------



## Ovaltineo (Jul 18, 2013)

Here's a video of me testing my clone with 2 X 500watt motors and 2 x BTN7960 controllers.


http://youtu.be/xB3b1VDaeeo


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Here's a video of me testing my clone with 2 X 500watt motors and 2 x BTN7960 controllers.
> 
> 
> http://youtu.be/xB3b1VDaeeo


Good job.


----------



## Ovaltineo (Jul 18, 2013)

While trying to design a way to mount an infrared rider sensor whilst maintaining an easily removable lid with no wires, I decided I will use a weight sensor instead. A small part of the lid will rest on the weight sensor to detect the presence of a rider.

I ordered this:
http://www.ebay.com.au/itm/HX711-We...Electrical_Test_Equipment&hash=item20dd3a7458

and this:

http://www.ebay.com.au/itm/20kg-Alu...Electrical_Test_Equipment&hash=item2c7ce0bba2


----------



## electricpolo (Mar 15, 2011)

Hi Oval
Where in the code would I invert the state of the Rider_Sensor?
My rider sensors would be HIGH when the rider is OFF & LOW when the rider is ON.
My infrared sensors go LOW when an object is in their path.


----------



## markula (Oct 27, 2013)

I seen this video on Youtube. 

https://www.youtube.com/watch?v=tdhw-MnbbHA

I have found instuctions with code but them all use Sabertoot or others more exspesive motors controllers 100 USD+. 

Eksampel this:
http://www.instructables.com/id/Self-Balancing-Unicycle/?ALLSTEPS

Is it possible to use the Segway code to an unicyle project. Yours code have support for so many variants of motor controllers.


----------



## adamson (Mar 2, 2014)

markula said:


> Is it possible to use the Segway code to an unicyle project. Yours code have support for so many variants of motor controllers.


I'm also interested 
My machine is crazy, I mounted new bts and one motor still don't go back direction. :/
As You can see at the end of the video, it's turning by itself, what is the purpose?
https://www.youtube.com/watch?v=x7UMt9dc5R4&feature=youtu.be
My HC-06 don't cooperate with my few phones. Phone see it, connect, but I can't do anything, hc-06 is flashing in red all the time.


----------



## electricpolo (Mar 15, 2011)

Go back to basics.
Can you make either motor go forwards or backwards with either motor controller on a bench test? (nothing else connected)
Then connect the Arduino, the forward/backward MCU, the motors & motor controllers for a bench test. 
When you gently tilt the forward/backward MCU, do the motors go forward & backward?
What are you using for steering? Pot or MCU?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval
> Where in the code would I invert the state of the Rider_Sensor?
> My rider sensors would be HIGH when the rider is OFF & LOW when the rider is ON.
> My infrared sensors go LOW when an object is in their path.


Just reverse the logic in the function *isRiderOn(void)* in SegwayClone.ino.


----------



## electricpolo (Mar 15, 2011)

Thanks.
Now to get my controller back.


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> I seen this video on Youtube.
> 
> https://www.youtube.com/watch?v=tdhw-MnbbHA
> 
> ...


You can use the same code, just use one wheel - left or right, it doesn't matter. Use MPU6050_X1_STEERING.


----------



## adamson (Mar 2, 2014)

electricpolo said:


> Go back to basics.
> Can you make either motor go forwards or backwards with either motor controller on a bench test? (nothing else connected)
> Then connect the Arduino, the forward/backward MCU, the motors & motor controllers for a bench test.
> When you gently tilt the forward/backward MCU, do the motors go forward & backward?
> What are you using for steering? Pot or MCU?


Yes, I'm using MCU.
Forward work two motors, backward works just one of them (I've connected yesterday other bts and it's the same issue)
Maybe this are some noises from motors?
I'm using mega clone, maybe I'll change it to arduino uno?


----------



## electricpolo (Mar 15, 2011)

Will either motor run backwards & forwards properly when say 6v or 12v power is applied directly to it? No motor controller or anything else.


----------



## adamson (Mar 2, 2014)

electricpolo said:


> Will either motor run backwards & forwards properly when say 6v or 12v power is applied directly to it? No motor controller or anything else.


Yes, when I aply 24v to motors, they run in two directions.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Yes, when I aply 24v to motors, they run in two directions.


Swap the PWM pins on the controller that won't change direction, for example, pins 5 & 6. WARNING: do this only on a bench test! Does it work backwards but not forwards? If so, then one of your PWM connections is not connected properly. Triple check those connections by using a volmeter in continuity mode.

It is also possible that the PWM output on the Arduino itself is dead. Simply select an unused pin and replace it in Motors.h.


----------



## adamson (Mar 2, 2014)

Ok, I got it, motors work ok, forward and backward, one of connections was bad.
But as You see on videos it's turning when it wants to. :/
https://www.youtube.com/watch?v=ELja-V97nIY&feature=youtu.be
https://www.youtube.com/watch?v=JPsx-yeAi4Y&feature=youtu.be

I can't set P D, because my hc-06 doesn't work.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Ok, I got it, motors work ok, forward and backward, one of connections was bad.
> But as You see on videos it's turning when it wants to. :/
> https://www.youtube.com/watch?v=ELja-V97nIY&feature=youtu.be
> https://www.youtube.com/watch?v=JPsx-yeAi4Y&feature=youtu.be
> ...


Steering:
Did you #define MPU6050_X2_STEERING? Did you mount the second MPU6050 sensor on the steering shaft? Can you post pictures please?

HC06:
1. Make sure you #define BLUETOOTH and #define CALIBRATE_MODE. Load the program. This will calibrate your clone and configure the HC-06 so make sure it is level and 24V is powered OFF.

2. Remove #define CALIBRATE_MODE. Load the program.

3. Pair your phone with the HC-06. It's name should appear as SEGWAY.

4. Run CloneConsole app.


----------



## electricpolo (Mar 15, 2011)

Watching your videos I see that your steering seems to be very insensitive. You have to move the tiller a long way for a little response.
Please post some more pics about where the steering MPU is located.
My MPU is mounted on the centreline of the steering shaft and the clone is very responsive. I even had to reduce the steering settings a bit.


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Steering:
> Did you #define MPU6050_X2_STEERING? Did you mount the second MPU6050 sensor on the steering shaft? Can you post pictures please?
> 
> HC06:
> ...


 it's defined mpu_x2_steering, mpu is mounted on steering shaft.
Bluetooth is paired and recognized as HC-06, 
after running cloneconsole yellow screen becomes blue, but I can't set anything.

Connections are rx>>tx and tx>>rx








What is pushback function for?


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> it's defined mpu_x2_steering, mpu is mounted on steering shaft.
> Bluetooth is paired and recognized as HC-06,
> after running cloneconsole yellow screen becomes blue, but I can't set anything.
> 
> ...


With a serial monitor, does the steer angle change as expected?

Did you calibrate with Bluetooth enabled? Unpair the HC06 and do a search. It should come up as SEGWAY.

Pushback is for pushing back when the motor is close to MAX - it is supposed to slow you down.


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> With a serial monitor, does the steer angle change as expected?
> 
> Did you calibrate with Bluetooth enabled? Unpair the HC06 and do a search. It should come up as SEGWAY.
> 
> Pushback is for pushing back when the motor is close to MAX - it is supposed to slow you down.


Bluetooth start working, it connects to the phone. 
Now I'm trying to use it.
Do you think I can steer with one mpu instead of two? And what about wiring?
Serial monitor says after calibration without moving anything:
and cloneconsole withput moving anything.
Ok, I've almost done, it's working on one mpu on the shaft. 
I don't know about it, does cloneconsole support one mpu? I've got connection between phone and seg, but I can't set anything.


----------



## electricpolo (Mar 15, 2011)

Back to your motors again.
When you have 12v or 24v applied direct to the motors, is the forward & reverse speed the same? (neutral timing)
If they don't, you may need to tune them by rotating the brush end of the motor a tiny bit.
I had to fiddle around with both my motors a bit to get them to run at equal speed in either direction.
Many DC motors, depending where they came from, may have been timed to work better (faster) in on direction.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Bluetooth start working, it connects to the phone.
> Now I'm trying to use it.
> Do you think I can steer with one mpu instead of two? And what about wiring?
> Serial monitor says after calibration without moving anything:
> ...


I'm confused with your post. It seems to have been written when steering is not working, and then later you got it working. Which questions are still relevant?


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> I'm confused with your post. It seems to have been written when steering is not working, and then later you got it working. Which questions are still relevant?


Sorry for mess. 
Attached files in previous post was with two mpu.
My seg clone is working almost fine with one mpu now.
It's turning, going forward&backward, sometimes it wants to shake me off.
Cloneconsole connects ok as "segway", but it doesn't read parameters.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Sorry for mess.
> Attached files in previous post was with two mpu.
> My seg clone is working almost fine with one mpu now.
> It's turning, going forward&backward, sometimes it wants to shake me off.
> Cloneconsole connects ok as "segway", but it doesn't read parameters.


Are you running the latest version of CloneConsole and the Arduino sketch?


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Are you running the latest version of CloneConsole and the Arduino sketch?


Yes, clone v 1.9 and v 5.3.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Yes, clone v 1.9 and v 5.3.


After the background turns white, moving the board and the steering doesn't change anything on the CloneConsole?


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> After the background turns white, moving the board and the steering doesn't change anything on the CloneConsole?


Yes, doesn't change anything on the cloneconsole.


----------



## qazwsx000521 (Apr 22, 2014)

adamson said:


> Yes, doesn't change anything on the cloneconsole.


My phone can not use 1.9 5.3


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Yes, doesn't change anything on the cloneconsole.


Make sure you comment out #define CALIBRATE_MODE and keep #define BLUETOOTH uncommented.

```
// #define CALIBRATE_MODE
#define BLUETOOTH
```
If you already did and it doesn't work, can you please post SegwayClone.h? I will try to replicate your problem - might be a bug in the code.


----------



## qazwsx000521 (Apr 22, 2014)

Ovaltineo said:


> Make sure you comment out #define CALIBRATE_MODE and keep #define BLUETOOTH uncommented.
> 
> ```
> // #define CALIBRATE_MODE
> ...


Recommends that you add z axis


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Make sure you comment out #define CALIBRATE_MODE and keep #define BLUETOOTH uncommented.
> 
> ```
> // #define CALIBRATE_MODE
> ...


I'm adding in txt, will it be ok?

Edit, add code:


```
/*
MODE_CALIBRATE        - calibrate the sensors and save the data to EEPROM.  You must level the board, reset the Arduino, and  wait for the continuous tone.
MODE_RUN            - loads calibration data from the EEPROM.  Tone will sound until board is level between +-2 degrees.  Then it is ready to ride.

POT_STEERING        - use a potentiometer on A1 for steering and an MPU6050 for board tilt
MPU6050_X2_STEERING    - use two MPU6050s, one for board tilt and a second one for steering
MPU6050_X1_STEERING    - one MPU6050. It is used to measure board tilt and steering
GY80_STEERING        - one GY80. It is used to measure board tilt and steering

PWM_PWM_CONTROLLER    - use dual pin PWM + enable pin motor controller, eg BTN7960
PWM_DIR_CONTROLLER    - use single pin PWM + direction pin motor controller  
ROBOCLAW_CONTROLLER    - use Roboclaw motor controller.  Roboclaw must be configured for packet serial mode 38400 baud with address 0x80
SABERTOOTH_CONTROLLER    - use Sabertooth motor controller.  Sabertooth must be configured for packet serial mode 38400 baud with address 0x80
PWN_SHIELD_CONTROLLER    - use Elechouse dual-channel motor shield.  http://www.elechouse.com/elechouse/index.php?main_page=product_info&products_id=2179

CHECK_VOLTAGE        - define if voltage sensor (22K + 4.7K voltage divider resistor ) is connected to A3.  22K is in series with battery voltage, 4.7K goes to ground.
                      Battery----22K----A3----4.7K----Gnd

PUSHBACK            - define this if pushback above specified motor output is desired.  Change pushback parameters in Pushback.h.

BLUETOOTH            - define this if a HC06 "linvor" bluetooth module is attached to Serial3 (on Mega) or pin 7 RX & pin 8 TX (on UNO)

TEMPERATURE_SENSORS    - define this if TC74A0 and TC74A2 are attached to I2C bus

LOCKED_BY_DEFAULT    - define this if you want clone to be locked at power-up.  Needs CloneConsole Android app to unlock.

RIDER_SENSOR        - define this if rider sensor/switch is available
*/

/*
Uncomment one MODE below
*/
//#define MODE_CALIBRATE
#define MODE_RUN

/*
Uncomment one STEERING type below
*/
//#define POT_STEERING
//#define MPU6050_X2_STEERING
#define MPU6050_X1_STEERING
//#define GY80_STEERING

/*
Uncomment only if steering left and right are inverted
*/
//#define INVERT_STEERING

/*
Uncomment one CONTROLLER type below
*/
#define PWM_PWM_CONTROLLER
//#define PWM_DIR_CONTROLLER
//#define ROBOCLAW_CONTROLLER
//#define ROBOCLAW_ENCODER_CONTROLLER
//#define SABERTOOTH_CONTROLLER
//#define PWM_SHIELD_CONTROLLER

/*
Uncomment if you want to check battery voltage.  See note above for resistor divider.
*/
//#define VOLTAGE_CHECK

/*
Uncomment if you want LED Voltage indicator.  You need VOLTAGE_CHECK with this.
*/
//#define VOLTAGE_LED

/*
Uncomment if you want Pushback
*/
#define PUSHBACK

/*
Uncomment if you have a HC06 "linvor" bluetooth module
*/
#define BLUETOOTH

/*
Uncomment if you have TC74 temperature sensors - TC74A0 and TC74A2 default addresses in TC74.h
*/
//#define TEMPERATURE_SENSORS

/*
Uncomment if you want the clone to be locked during startup.  It can only be unlocked via CloneConsole Android app.
*/
//#define LOCKED_BY_DEFAULT

/*
Uncomment if you have a rider sensor - sensor must pull this pin HIGH when rider is ON, and pull it LOW when rider is OFF
Initial values are loaded from KP_OFF, KD_OFF, and MOTOR_MAX_OFF.
*/
//#define RIDER_SENSOR    13


#define FAN_PIN            8                // optional output for MOSFET or relay fan switch

#define BUZZER_PIN            12
#define POT_STEERING_PIN    A1                
#define P_PIN                A0                // optional pot for adjusting P value (Proportional)
#define D_PIN                A2                // optional pot for adjusting D value (Derivative)

#ifdef VOLTAGE_CHECK
    #define VOLTAGE_PIN            A3
//    #define VOLTAGE_PIN            A5            // ovaltine's clone uses this
    #define VOLTAGE_DIVIDER        .176        // voltage divider: 4.7K/(22K + 4.7K) = .176
#endif

// The following 9 lines were borrowed/copied from Multiwii
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
  #define PROMINI
#endif
#if defined(__AVR_ATmega32U4__) || defined(TEENSY20)
  #define PROMICRO
#endif
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
  #define MEGA
#endif

#ifdef VOLTAGE_LED
    #if defined(PWM_SHIELD_CONTROLLER)
        #define LED_GREEN_PIN        A0
        #define LED_YELLOW_PIN        5
        #define LED_RED_PIN            6
    #elif ((defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER)) && !defined(MEGA))
        #define LED_GREEN_PIN        4
        #define LED_YELLOW_PIN        5
        #define LED_RED_PIN            6
    #else
        #define LED_GREEN_PIN        9
        #define LED_YELLOW_PIN        10
        #define LED_RED_PIN            11
    #endif
#endif

typedef struct
{
    float x_accel;
    float y_accel;
    float z_accel;
    float x_gyro;
    float y_gyro;
    float z_gyro;

    int x_accel_offset;
    int y_accel_offset;
    int z_accel_offset;

    int x_gyro_offset;
    int y_gyro_offset;
    int z_gyro_offset;

    int x_gyro_offset_min;
    int x_gyro_offset_max;
    int y_gyro_offset_min;
    int y_gyro_offset_max;
    int z_gyro_offset_min;
    int z_gyro_offset_max;

    int address;
} sensorType;


#define    ALPHA 0.97                // used by complementary filter

#if defined(ROBOCLAW_CONTROLLER)
    // use these values if using Roboclaw
    #define KP 3.9                    // proportional constant when rider is ON
    #define KD 1.5                   // derivative constant when rider is ON
    #define STEER_MULTIPLIER 25     // adjust depending on your motor speed
    #define KP_OFF 1.8                // proportional constant when rider is OFF
    #define KD_OFF .75                 // derivative constant when rider is OFF
#endif
#if defined(ROBOCLAW_ENCODER_CONTROLLER)
    // use these values if using Roboclaw with encoder
    #define KP 10.9                    // proportional constant when rider is ON
    #define KD 4.68                   // derivative constant when rider is ON
    #define STEER_MULTIPLIER 546     // adjust depending on your motor speed
    #define KP_OFF 5.45                // proportional constant when rider is OFF
    #define KD_OFF 2.34                 // derivative constant when rider is OFF
#endif
#if defined(SABERTOOTH_CONTROLLER)
    // use these values if using Sabertooth
    #define KP .35                    // proportional constant when rider is ON
    #define KD .15                   // derivative constant when rider is ON
    #define STEER_MULTIPLIER 1.75   // adjust depending on your motor speed
    #define KP_OFF .17                // proportional constant when rider is OFF
    #define KD_OFF .07                 // derivative constant when rider is OFF
#endif
#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER)  || defined(PWM_SHIELD_CONTROLLER)
    // use these values if using PWM
    #define KP .7                    // proportional constant when rider is ON
    #define KD .3                   // derivative constant when rider is ON
    #define STEER_MULTIPLIER 3.5    // adjust depending on your motor speed
    #define KP_OFF .35                // proportional constant when rider is OFF
    #define KD_OFF .15                 // derivative constant when rider is OFF
#endif

#define MAX_ANGLE  18            // adjust depending on your machine
#define MIN_ANGLE  -15            // adjust depending on your machine

#define CALIBRATE_YES    true
#define CALIBRATE_NO    false

#define ACC_FILTER    0.05
#define lowpassFilter(val, change, q) ((1-q) * val + (change * q))

#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER) || defined(PWM_SHIELD_CONTROLLER)
    // bluetooth software serial pins for non-mega boards with PWM controllers
    #define SOFT_RX_PIN3    5            // connect to bluetooth module TX pin
    #define SOFT_TX_PIN3    6            // connect to bluetooth module RX pin
#else    
    // bluetooth software serial pins for non-mega boards with serial controllers
    #define SOFT_RX_PIN3    7            // connect to bluetooth module TX pin
    #define SOFT_TX_PIN3    8            // connect to bluetooth module RX pin
#endif    

#define STEER_OFFSET_DIVIDER    -70.0        // bluetooth remote control steer offset (X) divider.  Higher value makes X movement less sensitive.
#define BOARD_OFFSET_DIVIDER    -70.0        // bluetooth remote control board offset (Y) divider.  Higher value makes Y movement less sensitive.
```


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> I'm adding in txt, will it be ok?
> 
> Edit, add code:


I think the problem is the UNO, it cannot support 115200 baud using SoftSerial . Unfortunately, I cannot switch to 9600 as too much data needs to be sent for each cycle. I suggest switching to an Arduino MEGA if you want to use Bluetooth.


----------



## adamson (Mar 2, 2014)

But I'm using Mega.


----------



## [email protected] (Mar 22, 2014)

Good morning everyone and a special greeting Ovaltineo . "Great job ," my name is fernando , I'm doing my clone segway , I speak Spanish . my English is short.

Agradesco please can help me with my heartwarming project.

Currently I have these parts of my segway :

2 - 500w motors
2 - small motors (Figure 1 )
MPU 2-6050
1 - Arduino UNO
1 - Buzzer
2 - Resistance ( 22k, 4.7k )
3 - led
1 - L298N Dual H Bridge ( photo 2) http://www.ebay.com/itm/Dual-H-Brid...Electrical_Test_Equipment&hash=item3cda8c2898

1 - H 30A Controller ( slide3 ) http://www.ebay.com/itm/3-36V-Dual-...942?pt=LH_DefaultDomain_0&hash=item2a2e24f72e


- First I want to make a prototype with small engines.

questions :

1 - What program settings can serve me ? . Try using ( UNO_BTN7960_2XMPU6050 ( photo 4 ) construction ) , but did not succeed ? Yesterday .

2 - I use this code. Is that correct ?



> /*
> MODE_CALIBRATE - calibrate the sensors and save the data to EEPROM. You must level the board, reset the Arduino, and wait for the continuous tone.
> MODE_RUN - loads calibration data from the EEPROM. Tone will sound until board is level between +-2 degrees. Then it is ready to ride.
> 
> ...








































Thanks in advance ...


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> But I'm using Mega.


Hmmm. Either there is a connection problem from the Mega to the HC06 (triple check those wires) or the HC06 has been damaged (maybe it is 3.3V only and cannot tolerate 5V). I think I have to modify my schematic to level-shift (5V to 3.3V) the TX from the Arduino to the HC06 using a resistor divider. 

Give me a few days to write a test program to see if the HC06 is responding.


----------



## Ovaltineo (Jul 18, 2013)

[email protected] said:


> Good morning everyone and a special greeting Ovaltineo . "Great job ," my name is fernando , I'm doing my clone segway , I speak Spanish . my English is short.
> 
> Agradesco please can help me with my heartwarming project.
> 
> ...


Use PWM_DIR_CONTROLLER and change connections as follows

Pin 9 -> IN1
Pin 10 -> IN2
Pin 3 -> IN3
Pin 11 -> IN4

P.S. This maybe wrong - there are many versions of the L298N module. Give this a go anyway. I think this module may need a new driver and schematic.


----------



## electricpolo (Mar 15, 2011)

Fercho_tech,
Also on the schematic you have supplied, the connections to the Steering MPU6050 are wrong.
On both the MPUs, the connections are to SDA & SCL.
The only difference is the Tilt MPU has AD0 pulled LOW and the Steer MPU AD0 pulled HIGH.
XDA & XCL connections are not used.


----------



## [email protected] (Mar 22, 2014)

Ovaltineo said:


> Use PWM_DIR_CONTROLLER and change connections as follows
> 
> Pin 9 -> IN1
> Pin 10 -> IN2
> ...



Ovaltine Hi, thanks for replying, make the change, but does not work. 

-I put On arduino and the right motor turns. 
When I move the MPU board tilt rotates the left engine, both engines rotate in one direction. 

-When I move the other MPU nothing happens. 

Predunta: 

As is the correct procedure for calibration? 

Greetings.


----------



## electricpolo (Mar 15, 2011)

fercho_tech
Your connections to the steering MPU are wrong. See my previous post. 
This is why the steering MPU does nothing. You will also get an error in the serial monitor.


----------



## [email protected] (Mar 22, 2014)

electricpolo said:


> fercho_tech
> Your connections to the steering MPU are wrong. See my previous post.
> This is why the steering MPU does nothing. You will also get an error in the serial monitor.



Electricpolo Hello, I connect it as in the original scheme (page 1) of Ovaltineo









: Confused:


----------



## [email protected] (Mar 22, 2014)

electricpolo said:


> fercho_tech
> Your connections to the steering MPU are wrong. See my previous post.
> This is why the steering MPU does nothing. You will also get an error in the serial monitor.




Hello ElectricPolo, checking I realized I've always been like this:


----------



## electricpolo (Mar 15, 2011)

This one is correct. 
A couple of the original schematics have a connection error on the steer MPU.
When you start the program & run the serial monitor you should see no errors listed & you will see both boards initialized & their different addresses.
If you get an error & don't see both MPUs, then either a connection is no good or an MPU is faulty. 
You should see board tilt, gyro angle, left & right motor speed, etc.
These change as you tilt the MPUs. 
You could always do a test setup with just 1 MPU, define MPU X1 & run the program. You will find out pretty fast if both MPUs are OK.


----------



## [email protected] (Mar 22, 2014)

electricpolo said:


> This one is correct.
> A couple of the original schematics have a connection error on the steer MPU.
> When you start the program & run the serial monitor you should see no errors listed & you will see both boards initialized & their different addresses.
> If you get an error & don't see both MPUs, then either a connection is no good or an MPU is faulty.
> ...



Hello Electricpolo burnt arduino 1 MPU burned ......


----------



## [email protected] (Mar 22, 2014)

hi, which is a battery charger 24 v recommended.?


----------



## electricpolo (Mar 15, 2011)

Hi fercho_tech,
I had a look at the specs for the H30A controller you have. 
It is way too small for 500 watt motors. It will only handle 15A continuous and only 30A peak. You will burn this out in minutes or even less.
500 watt motors will draw about 25A at their rated load and over 100A at startup under load or at stall.
I have a RoboClaw 2x60A controller which handles 60A continuous & 120A peak & the manufacturers reckon even that is running pretty close to the line.


----------



## [email protected] (Mar 22, 2014)

electricpolo said:


> Hi fercho_tech,
> I had a look at the specs for the H30A controller you have.
> It is way too small for 500 watt motors. It will only handle 15A continuous and only 30A peak. You will burn this out in minutes or even less.
> 500 watt motors will draw about 25A at their rated load and over 100A at startup under load or at stall.
> I have a RoboClaw 2x60A controller which handles 60A continuous & 120A peak & the manufacturers reckon even that is running pretty close to the line.



Electricpolo, I refer to a recharger batteries, excuse my English ....


----------



## [email protected] (Mar 22, 2014)

recharger to recharge the batteries ...


----------



## Ovaltineo (Jul 18, 2013)

[email protected] said:


> Ovaltine Hi, thanks for replying, make the change, but does not work.
> 
> -I put On arduino and the right motor turns.
> When I move the MPU board tilt rotates the left engine, both engines rotate in one direction.
> ...


I have posted v5.4 of the Arduino sketch and a new schematic for the UNO with L298N controller. Let us know if it works or not.


----------



## Ovaltineo (Jul 18, 2013)

Ovaltineo said:


> Hmmm. Either there is a connection problem from the Mega to the HC06 (triple check those wires) or the HC06 has been damaged (maybe it is 3.3V only and cannot tolerate 5V). I think I have to modify my schematic to level-shift (5V to 3.3V) the TX from the Arduino to the HC06 using a resistor divider.
> 
> Give me a few days to write a test program to see if the HC06 is responding.


I have posted new schematics with the resistor divider for the HC06. The test program is coming soon.


----------



## Ovaltineo (Jul 18, 2013)

[email protected] said:


> recharger to recharge the batteries ...


Lots of choices. Search for "battery charger" in eBay. I myself would like a SkyRC Imax B8 which can charge a 24V lead acid battery.


----------



## electricpolo (Mar 15, 2011)

After reading some more, I have decided to use a 3.3V - 5V Logic Level Converter for the HC06. Jaycar have them for $6.95 but you can get them from eBay cheaper if you want.
http://www.freetronics.com/pages/level-logic-level-converter-module-quickstart-guide#.U4bgCigsnHI
These converters take 5V & then supply 3.3V to the module. The converter also ensures any Arduino input from the 3.3V module actually sees 5V.
According to the Arduino CookBook, the translator board is the best method.
A divider can supply 3.3V and the Arduino can also supply 3.3V but the Arduino might not see a high enough voltage at the input pin to go high.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> After reading some more, I have decided to use a 3.3V - 5V Logic Level Converter for the HC06. Jaycar have them for $6.95 but you can get them from eBay cheaper if you want.
> http://www.freetronics.com/pages/level-logic-level-converter-module-quickstart-guide#.U4bgCigsnHI
> These converters take 5V & then supply 3.3V to the module. The converter also ensures any Arduino input from the 3.3V module actually sees 5V.
> According to the Arduino CookBook, the translator board is the best method.
> A divider can supply 3.3V and the Arduino can also supply 3.3V but the Arduino might not see a high enough voltage at the input pin to go high.


Based on the Atmel datasheet, at 5V Vcc, 3.3V input will always be seen a as a "1".


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> But I'm using Mega.


Make sure batteries are disconnected. Load the following sketch and run the Serial Monitor at 115200. Press the reset button on the Arduino. You should get an output like *OKlinvorV1.x*.

```
void setup() {
    Serial.begin(115200);
    Serial3.begin(115200);
    Serial3.print("AT+VERSION");
}

void loop() // run over and over
{
    if (Serial3.available())
    {
            Serial.write(Serial3.read());
    }
}
```
If nothing happens, try this sketch.


```
void setup() {
    Serial.begin(115200);
    Serial3.begin(9600);
    Serial3.print("AT+VERSION");
}

void loop() // run over and over
{
    if (Serial3.available())
    {
            Serial.write(Serial3.read());
    }
}
```
Let me know which sketch gives the desired output. Don't forget to re-load the Segway sketch when finished.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> I have posted v5.4 of the Arduino sketch and a new schematic for the UNO with L298N controller. Let us know if it works or not.



Oval Hello , thank you very much for the schematic and Ver.5.4 . I bought one to Arduino MPU.

I'm with :

1x mpu
1x 10K Potentiometer
1x UNO
1x L298N
1x Buzzer
I have not connected the resisitencias , not led.


Everything is connected with vercion 5.4.
The serial monitor shows me :

*ACCEL : GYRO 0.52 0.00 BOARD ANGLE : 0.64 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.51 0.00 BOARD ANGLE : 0.65 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.49 0.00 BOARD ANGLE : 0.66 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.67 0.00 BOARD ANGLE : 0.65 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.51 0.00 BOARD ANGLE : 0.66 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.62 0.00 BOARD ANGLE : 0.67 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 1.04 0.00 BOARD ANGLE : 0.68 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.80 0.00 BOARD ANGLE : 0.69 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.59 0.00 BOARD ANGLE : 0.66 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.47 0.00 BOARD ANGLE : 0.65 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.65 0.00 BOARD ANGLE : 0.66 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.45 0.00 BOARD ANGLE : 0.64 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.31 0.00 BOARD ANGLE : 0.63 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.60 0.00 BOARD ANGLE : 0.62 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.55 0.00 BOARD ANGLE : 0.63 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.41 0.00 BOARD ANGLE : 0.64 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.84 0.00 BOARD ANGLE : 0.64 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.44 0.00 BOARD ANGLE : 0.64 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.74 0.00 BOARD ANGLE : 0.65 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.88 0.00 BOARD ANGLE : 0.66 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.62 0.00 BOARD ANGLE : 0.65 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 1.00 0.00 BOARD ANGLE : 0.64 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.55 0.00 BOARD ANGLE : 0.64 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : 0.30 GYRO : 2.59 ANGLE BOARD : 0.62 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.69 0.00 BOARD ANGLE : 0.62 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : 1.89 GYRO : ANGLE BOARD -1.73 0.56 STEER ANGLE : 2.58 MOTOR : 29.87 LEFT : 20 RIGHT : 30
*ACCEL : 0.05 GYRO : -2.38 ANGLE BOARD : 0.20 STEER ANGLE : 2.58 MOTOR : 19.94 LEFT : 10 RIGHT : 28
*ACCEL : -2.75 GYRO : ANGLE BOARD -20.58 -1.62 STEER ANGLE : 2.82 MOTOR : -30.00 LEFT : RIGHT -30 : -20
*ACCEL : -8.31 GYRO : -33.60 ANGLE BOARD : -6.25 STEER ANGLE : 2.82 MOTOR : -30.00 LEFT : RIGHT -30 : -20
*ACCEL : -6.86 GYRO : 32.48 ANGLE BOARD : -4.42 STEER ANGLE : 2.58 ENGINE: LEFT 16.33 7 RIGHT : 25
*ACCEL : GYRO -0.33 : -3.75 ANGLE BOARD : -0.47 STEER ANGLE : 2.58 MOTOR : 26.27 LEFT : 17 RIGHT : 30
*ACCEL : -9.61 GYRO : -56.46 ANGLE BOARD : -8.31 STEER ANGLE : 2.58 MOTOR : -30.00 LEFT : RIGHT -30 : -20
*ACCEL : -6.44 GYRO : 48.15 ANGLE BOARD : -4.25 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : 0.31 GYRO : 1.47 ANGLE BOARD : -0.93 STEER ANGLE : 2.58 MOTOR : 22.52 LEFT : 13 RIGHT : 30
*ACCEL : -8.42 GYRO : -71.70 ANGLE BOARD : -8.26 STEER ANGLE : 2.58 MOTOR : -30.00 LEFT : RIGHT -30 : -20
*ACCEL : -4.47 GYRO : 68.03 ANGLE BOARD : -2.98 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : 0.48 GYRO : -12.85 ANGLE BOARD : -1.42 STEER ANGLE : 2.82 MOTOR : 4.47 LEFT : RIGHT -5 : 14
*ACCEL : -9.96 GYRO : -37.05 ANGLE BOARD : -8.74 STEER ANGLE : 2.58 MOTOR : -30.00 LEFT : RIGHT -30 : -20
*ACCEL : -3.16 GYRO : 48.74 ANGLE BOARD : -2.35 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : -0.98 GYRO : -12.05 ANGLE BOARD : -2.14 STEER ANGLE : 2.58 MOTOR : -7.79 LEFT : -16 RIGHT : 1
*ACCEL : -8.68 GYRO : 26.83 ANGLE BOARD : -5.97 STEER ANGLE : 2.58 MOTOR : -25.33 LEFT : RIGHT -30 : -16
*ACCEL : -0.65 GYRO : 10.18 ANGLE BOARD : -1.04 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : 1.99 GYRO : -12.24 ANGLE BOARD : -1.19 STEER ANGLE : 2.58 ENGINE: LEFT 15.38 6 RIGHT : 24
*ACCEL : -4.22 GYRO : -15.60 ANGLE BOARD : -3.96 STEER ANGLE : 2.82 MOTOR : -30.00 LEFT : RIGHT -30 : -20
*ACCEL : GYRO 1.07 -1.10 ANGLE BOARD : -0.47 STEER ANGLE : 2.82 ENGINE: LEFT 19.23 9 RIGHT : 29
*ACCEL : GYRO -0.02 0.00 ANGLE BOARD : -0.59 STEER ANGLE : 2.58 MOTOR : 13.85 LEFT 4 RIGHT : 22
*ACCEL : GYRO 0.03 0.00 BOARD ANGLE : -0.41 STEER ANGLE : 2.58 MOTOR : 7.17 LEFT : RIGHT -1 : 16
*ACCEL : GYRO 0.21 0.00 BOARD ANGLE -0.16 STEER ANGLE : 2.82 MOTOR : 5.23 LEFT : RIGHT -4 : 15
*ACCEL : GYRO 0.44 0.00 BOARD ANGLE : 0.01 STEER ANGLE : 2.58 MOTOR : 5.78 LEFT : RIGHT -3 : 14
*ACCEL : GYRO 0.52 0.00 BOARD ANGLE : 0.17 STEER ANGLE : 2.58 MOTOR : 9.15 LEFT : 0 RIGHT : 18
*ACCEL : GYRO 0.69 0.00 BOARD ANGLE : 0.29 STEER ANGLE : 2.82 MOTOR : 14.41 LEFT 4 RIGHT : 24
*ACCEL : GYRO 0.72 0.00 BOARD ANGLE : 0.35 STEER ANGLE : 2.58 ENGINE: LEFT 19.00 9 RIGHT : 28
*ACCEL : GYRO 0.48 0.00 BOARD ANGLE : 0.40 STEER ANGLE : 2.58 MOTOR : 24.28 LEFT : 15 RIGHT : 30
*ACCEL : GYRO 0.44 0.00 BOARD ANGLE : 0.46 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : 0.28 GYRO : -0.31 ANGLE BOARD : 0.48 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.33 0.00 BOARD ANGLE : 0.45 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : 0.45 GYRO : -0.59 ANGLE BOARD : 0.44 STEER ANGLE : 2.58 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.42 -0.78 ANGLE BOARD : 0.48 STEER ANGLE : 2.82 MOTOR : 30.00 LEFT : 20 RIGHT : 30
*ACCEL : GYRO 0.05 0.00 BOARD ANGLE : 0.32 STEER ANGLE : 2.58 MOTOR : 26.70 LEFT : 17 RIGHT : 30
*ACCEL : 0.34 GYRO : -10.19 ANGLE BOARD : 0.50 STEER ANGLE : 2.58 MOTOR : 26.78 LEFT : 17 RIGHT : 30


It looks so good, but the motors do not move.


----------



## ferchotech (May 29, 2014)

A photo ...













Mi codigo configuracion:


/*
Uncomment one MODE below
*/
//#define MODE_CALIBRATE
#define MODE_RUN

/*
Uncomment one STEERING type below
*/
#define POT_STEERING
//#define MPU6050_X2_STEERING
#define MPU6050_X1_STEERING
//#define GY80_STEERING

/*
Uncomment only if steering left and right are inverted
*/
//#define INVERT_STEERING

/*
Uncomment one CONTROLLER type below
*/
//#define PWM_PWM_CONTROLLER
//#define PWM_DIR_CONTROLLER
//#define ROBOCLAW_CONTROLLER
//#define ROBOCLAW_ENCODER_CONTROLLER
//#define SABERTOOTH_CONTROLLER
//#define PWM_SHIELD_CONTROLLER
#define L298N_CONTROLLER

/*
Uncomment if you want to check battery voltage. See note above for resistor divider.
*/
//#define VOLTAGE_CHECK

/*
Uncomment if you want LED Voltage indicator. You need VOLTAGE_CHECK with this.
*/
//#define VOLTAGE_LED

/*
Uncomment if you want Pushback
*/
//#define PUSHBACK

/*
Uncomment if you have a HC06 "linvor" bluetooth module
*/
//#define BLUETOOTH

/*
Uncomment if you have TC74 temperature sensors - TC74A0 and TC74A2 default addresses in TC74.h
*/
//#define TEMPERATURE_SENSORS

/*
Uncomment if you want the clone to be locked during startup. It can only be unlocked via CloneConsole Android app.
*/
//#define LOCKED_BY_DEFAULT

/*
Uncomment if you have a rider sensor - sensor must pull this pin HIGH when rider is ON, and pull it LOW when rider is OFF
Initial values are loaded from KP_OFF, KD_OFF, and MOTOR_MAX_OFF.
*/
//#define RIDER_SENSOR	13

/*
Uncomment if RIDER_SENSOR above has reverse logic, ie LOW when rider is ON and HIGH when rider is OFF
*/
//#define INVERT_RIDER_SENSOR


//#define FAN_PIN 8	



MOTORS DO NOT MOVE. 

H controller manually checked and well they move. 

Oval >>>>> help ....


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> A photo ...
> 
> MOTORS DO NOT MOVE.
> 
> ...


Please post clear high resolution photos of the L298N and Arduino. I'd like to be able to see how each wire connects between the two.


----------



## electricpolo (Mar 15, 2011)

fercho_tech,
I have noticed that you have both pot steering & MPU x1 steering defined.
You should just have one type of steering defined.


----------



## electricpolo (Mar 15, 2011)

*Re: Rider Sensors*



> Just reverse the logic in the function *riderIsOn(void)* in SegwayClone.ino.


Hi Oval,
I am having trouble reversing the logic to work with my sensors. They are high with no rider & low with a rider.
I was able to change part of the code so that Motor Max worked fine but I can't make KP & KD change.


----------



## ferchotech (May 29, 2014)

electricpolo said:


> fercho_tech,
> I have noticed that you have both pot steering & MPU x1 steering defined.
> You should just have one type of steering defined.




Hello Electric, thanks for your interest. 

Corrected, but still not turning the motor. thanks ..


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Please post clear high resolution photos of the L298N and Arduino. I'd like to be able to see how each wire connects between the two.



Hi Oval, 

Here I send you the photos ... thanks ...


----------



## ferchotech (May 29, 2014)

I've checked with multimeter between the legs of the atmega328 and L298 and everything is OK, 
but the motors do not move.


----------



## adamson (Mar 2, 2014)

> Make sure batteries are disconnected. Load the following sketch and run the Serial Monitor at 115200. Press the reset button on the Arduino. You should get an output like *OKlinvorV1.x*.


Ovaltineo it shows *OKlinvorV1.8* on first sketch and nothing on the second.


```
void setup() {     Serial.begin(115200);     Serial3.begin(115200);     Serial3.print("AT+VERSION"); }  void loop() // run over and over {     if (Serial3.available())     {             Serial.write(Serial3.read());     } }
```


----------



## [email protected] (Mar 22, 2014)

Friends, I think another burned mpu or arduino .... I think that was because it had the arduino with 12V - 2 A, but not sure, I just hope to fix it, the motors do not rotate ...


----------



## Ovaltineo (Jul 18, 2013)

[email protected] said:


> Friends, I think another burned mpu or arduino .... I think that was because it had the arduino with 12V - 2 A, but not sure, I just hope to fix it, the motors do not rotate ...


Is the red LED on the controller ON? 

You didn't follow my schematic - remove the 5V enable jumper on the L298N module and connect 5V to the Arduino. You must definitely do this if your battery is 24V.

Try changing MOTOR_MAX (under L298N section) in Motors.h to 252.

Try the following sketch and let me know if the motors are working.


```
#define MOTOR_MAX        252                // Don't use 255 (100% duty cycle) as MAX for most PWM controllers -- they don't like it

#define LEFT_ENA_PIN    3
#define LEFT_IN1_PIN    11
#define LEFT_IN2_PIN    2

#define RIGHT_ENB_PIN    9
#define RIGHT_IN3_PIN    10
#define RIGHT_IN4_PIN    7

#define    HZ_3906                2


void setPwmFrequency(byte mode) // Works on UNO only
{
    if (mode >=1 && mode <=5)
    {
        // set PWM frequency for pins 9,10
        TCCR1B = TCCR1B & 0b11111000 | mode;
        // set PWM frequency for pins 3,11
        TCCR2B = TCCR2B & 0b11111000 | mode;
    }
}


void initMotors(void)
{
    pinMode(LEFT_ENA_PIN, OUTPUT);        // set left motor pin to output
    pinMode(LEFT_IN1_PIN, OUTPUT);
    pinMode(LEFT_IN2_PIN, OUTPUT);
    pinMode(RIGHT_ENB_PIN, OUTPUT);     // set right motor pins to output
    pinMode(RIGHT_IN3_PIN, OUTPUT);
    pinMode(RIGHT_IN4_PIN, OUTPUT);        

    digitalWrite(LEFT_ENA_PIN, LOW);
    digitalWrite(RIGHT_ENB_PIN, LOW);
    
    digitalWrite(LEFT_IN1_PIN, HIGH);
    digitalWrite(LEFT_IN2_PIN, LOW);
    digitalWrite(RIGHT_IN3_PIN, HIGH);
    digitalWrite(RIGHT_IN4_PIN, LOW);
    
}


void controlMotors(int speedL, int speedR) {
    if (speedL<0) 
    {
        speedL = -speedL;
        digitalWrite(LEFT_IN1_PIN, LOW);
        digitalWrite(LEFT_IN2_PIN, HIGH);
    }
    else
    {
        digitalWrite(LEFT_IN1_PIN, HIGH);
        digitalWrite(LEFT_IN2_PIN, LOW);
    }
    analogWrite(LEFT_ENA_PIN, speedL);

    if (speedR<0) 
    {
        speedR = -speedR;
        digitalWrite(RIGHT_IN3_PIN, LOW);
        digitalWrite(RIGHT_IN4_PIN, HIGH);
    }
    else
    {
        digitalWrite(RIGHT_IN3_PIN, HIGH);
        digitalWrite(RIGHT_IN4_PIN, LOW);
    }
    analogWrite(RIGHT_ENB_PIN, speedR);
}



void setup()
{
    Serial.begin(115200);
    initMotors();
}

static int speed = 0;
static int increment = 10;
static int count = 0;

void loop()
{
    speed = speed + increment;
    if (speed >= MOTOR_MAX)
        increment = -10;
    else if (speed <= -MOTOR_MAX)
        increment = 10;
    Serial.print("Speed = ");
    Serial.println(speed);
    controlMotors(speed, speed);
    delay(500);
}
```


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Ovaltineo it shows *OKlinvorV1.8* on first sketch and nothing on the second.


The good news is that your HC06's serial interface is working fine at 115200.

The bad news is that I haven't got a clue why it is not working with the CloneConsole.

What version of Android is on your phone? Are you able to try another Android phone?


----------



## Ovaltineo (Jul 18, 2013)

*Re: Rider Sensors*



electricpolo said:


> Hi Oval,
> I am having trouble reversing the logic to work with my sensors. They are high with no rider & low with a rider.
> I was able to change part of the code so that Motor Max worked fine but I can't make KP & KD change.


Did you try INVERT_RIDER_SENSOR in v5.4 of the Arduino code?


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> What version of Android is on your phone? Are you able to try another Android phone?


Android 4.2.2, maybe it is a phone problem, I will try another one soon.


----------



## Ovaltineo (Jul 18, 2013)

Ovaltineo said:


> Is the red LED on the controller ON?
> 
> You didn't follow my schematic - remove the 5V enable jumper on the L298N module and connect 5V to the Arduino. You must definitely do this if your battery is 24V.
> 
> ...


I think I've found the problem - the L298N can't handle high frequency PWM. I've just updated the Arduino code to v5.5 to fix it.


```
v5.5
Fixed L298N motor controller code by removing "setPwmFrequency(HZ_3906)" during initialization.
```


----------



## [email protected] (Mar 22, 2014)

Oval Hello thanks for your interest, at this time I'll try 5.5 .. thanks.


----------



## [email protected] (Mar 22, 2014)

I do test the L298N manually, if the pin is not 5 volts, then the motors do not move, repeat tested manually.


----------



## adamson (Mar 2, 2014)

Crash at full speed  https://www.youtube.com/watch?v=5iGbLxFSAYg&feature=youtu.be

Easy ride : https://www.youtube.com/watch?v=pfR13NURWoI


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> I think I've found the problem - the L298N can't handle high frequency PWM. I've just updated the Arduino code to v5.5 to fix it.
> 
> 
> ```
> ...




OVALTINE .. HAPPY, HAPPY .. worked well, you're all a great teacher.

http://youtu.be/KBp23Vl6O5A.

Questions. could inform me on the logic that means?: 


v5.3

#ifdef L298N_CONTROLLER
//	#define MOTOR_MAX 252 // Don't use 255 (100% duty cycle) as MAX for most PWM controllers -- they don't like it
#define MOTOR_MAX *30*
#define MOTOR_MAX_OFF	*30*

v5.4

#ifdef L298N_CONTROLLER
#define MOTOR_MAX *252* // Don't use 255 (100% duty cycle) as MAX for most PWM controllers -- they don't like it
#define MOTOR_MAX_OFF	*100*



Again many thanks for your time and dedication to all of us .


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> OVALTINE .. HAPPY, HAPPY .. worked well, you're all a great teacher.
> 
> http://youtu.be/KBp23Vl6O5A.
> 
> ...


Congratulations ! The PD values need a bit of tuning though.

I usually use a small default value for the MOTOR_MAX, so that novice users won't do too much damage on a full-size Segway, just enough to balance. But the L298N is for small motors and need full power even just to balance. I simply assumed that no one will ever use the L298N as a ride-on Segway - only for a small robot, hence I put in the real max value in there. Actually, for an L298N, I just realized that MOTOR_MAX can be 255. MOTOR_MAX_OFF is actually not used because that is used when a RIDER_SENSOR is defined, which is highly unlikely with the L298N.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Crash at full speed  https://www.youtube.com/watch?v=5iGbLxFSAYg&feature=youtu.be
> 
> Easy ride : https://www.youtube.com/watch?v=pfR13NURWoI


Owww !!! A crash is inevitable if you attempt to reach full speed. You *MUST* wear a helmet and pads when attempting to do this. I know because I shed a fair bit of blood when I had a bad crash . Did the alarm go off just before it crashed? It is supposed to warn you if you reach 80% of MOTOR_MAX. But hold on, you have PUSHBACK enabled. Did it try to push back?

In any case, congratulations! It looks like it is working well. I LOVE those wheels. Can you show close-up photos of your steering mechanism? It looks really good and I'd like to copy it if I can.


----------



## mariov (May 22, 2014)

Hi guys, I'm new to the forum even though i read it from start to end.
I have a chinese clone which is pretty disappointing and underpowered.
I intend to use the structure and see how the new electronics work










I have two questions
I intend to use two 12V batteries in series, and i'm intending to power the Arduino from one of them (12V), but i noticed some of you use a DC DC step down, why?

Second question, the bluetooth is not working, my phone connects but the app is pretty much dead, i can't see the gyros

Thanks


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> Hi guys, I'm new to the forum even though i read it from start to end.
> I have a chinese clone which is pretty disappointing and underpowered.
> I intend to use the structure and see how the new electronics work
> 
> ...


You can use 12V directly, but I'd like to balance the power usage on the two batteries, hence, I recommend using a to DC-to-DC converter.

Are you using an UNO? I've only recently realized that the bluetooth module will only work with a MEGA because I'm using 115200 baud which only works with a hardware serial port. If you are using a MEGA, did you enable BLUETOOTH during CALIBRATE_MODE? You need to do this to configure the HC06. The bluetooth name should show up as "SEGWAY" on your phone.


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Owww !!! A crash is inevitable if you attempt to reach full speed. You *MUST* wear a helmet and pads when attempting to do this. I know because I shed a fair bit of blood when I had a bad crash . Did the alarm go off just before it crashed? It is supposed to warn you if you reach 80% of MOTOR_MAX. But hold on, you have PUSHBACK enabled. Did it try to push back?
> 
> In any case, congratulations! It looks like it is working well. I LOVE those wheels. Can you show close-up photos of your steering mechanism? It looks really good and I'd like to copy it if I can.


There wasn't any alarm, Pushback function is on, but it just stopped working and.... I've just send You PM about steering.

























What does it mean in serial monitor?

```
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
```


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> There wasn't any alarm, Pushback function is on, but it just stopped working and.... I've just send You PM about steering.
> 
> What does it mean in serial monitor?
> 
> ...


I am guessing that the BTS7960 detected over-current or over-temperature. They will stop when this happens.

That output from the serial monitor are just status outputs from the MPU6050. Error = 0 means OK.


----------



## [email protected] (Mar 22, 2014)

Hi, Ovaltine. 

I am in the process of learning. With my segclon .. 

In the following video, the segclon works with the original v5.5. 

http://youtu.be/eu309cuU9yo


It is noted as the segclon moves from one place to another. Increasing your speed, until it falls. 

I searched and combining different values ​​to: 

#define kick_trigger 100 
#define kick_trigger_off 50 
#define kick_max 20
#define kick_slope_up 10 
#define kick_slope_down 1

* KD .3
KP .7
KP_OFF .35
KD_OFF .35 

#define MOTOR_MAX 255
#define MOTOR_MAX_OFF 100 

But segclon still tumbling. According to the video and his great experience, which variable or value, I must change. Thank you very much.


----------



## electricpolo (Mar 15, 2011)

I think the BTS7960 controllers will be working too hard with motors around the 500 watt size.
They will work OK at lower speed & gentle operation but if you have to reverse quickly or go up an incline then they are likely to overcurrent out a lot.
Based on feedback from the RoboClaw manufacturers, even a 2x60A RoboClaw with a 120A per channel limit is running close to the line with 500 watt motors.


----------



## Ovaltineo (Jul 18, 2013)

[email protected] said:


> Hi, Ovaltine.
> 
> I am in the process of learning. With my segclon ..
> 
> ...


Try increasing KP. It may also help if you have more weight at the top (eg battery) and/or taller platform.


----------



## electricpolo (Mar 15, 2011)

My HC-06 bluetooth module is version 2.0. Should I be looking for one with version 1.5 instead?
I am using a Nano & can connect to 2.0 with Android tablet. 
Sometimes it shows KP & KD & sometimes it doesn't. Trying to calibrate via bluetooth makes the app seem to freeze.
On the bench the XY screen seems to do nothing in the serial monitor.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
INVERT_RIDER_SENSOR worked very well.
I have made a small change in the program that lets me use 2 sensors & I can invert the output there as well now.
My sensors don't work properly when connected to the 1 input pin so I have 2 sensor input pins now. 
Also had to change from pin 13. For some reason, it just wouldn't work with my sensors.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Try increasing KP. It may also help if you have more weight at the top (eg battery) and/or taller platform.


Hello Ovalotine .. 

Agrégé 6 batteries AA on the top mast and increase KP 70, 150, 255, but segclon falls faster. I'm trying segir. 


I want to use arduino mega, and use bluethoo, but not if I can use the same pins: 

# ifdef L298N_CONTROLLER 
# define MOTOR_MAX 255 
# define MOTOR_MAX_OFF 100 

# define LEFT_ENA_PIN 3 
# define LEFT_IN1_PIN 11 
# define LEFT_IN2_PIN 2 

# define RIGHT_ENB_PIN 9 
# define RIGHT_IN3_PIN 10 
# define RIGHT_IN4_PIN 7 


I will buy android phone, and I ask: which android firmware, V1.9 supports?. Or phone you recommend that is not too expensive   . 

Again thank you very much for your help.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> My HC-06 bluetooth module is version 2.0. Should I be looking for one with version 1.5 instead?
> I am using a Nano & can connect to 2.0 with Android tablet.
> Sometimes it shows KP & KD & sometimes it doesn't. Trying to calibrate via bluetooth makes the app seem to freeze.
> On the bench the XY screen seems to do nothing in the serial monitor.


The HC-06 firmware is not an issue. I think the Nano has the same limitation as the Uno when it comes to the SoftwareSerial library. They are both unreliable at high speeds. I will re-write the code to use a lower baud rate when using the SoftwareSerial library.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hello Ovalotine ..
> 
> Agrégé 6 batteries AA on the top mast and increase KP 70, 150, 255, but segclon falls faster. I'm trying segir.
> 
> ...


You only need to change KP and KD. Make sure PUSHBACK is not defined. You must slowly change KP and KD. If it gets worse when increasing the value, then try decreasing the value. It will take a lot of iterations to get the right value. A taller platform is easier to balance than a short platform. Imagine balancing a long stick vs a short stick on your palm.

The same pins are used for the Mega. But you may not need the Mega because I am re-writing the code to use a lower baud rate so that bluetooth works with Uno and Nano.

CloneConsole V1.9 should work with Android 2.3.3 and later. I am using an old Google Nexus running 4.4.2.


----------



## electricpolo (Mar 15, 2011)

Is it as simple as changing "AT+BAUD8" to "AT+BAUD7" & changing the baud rate to from 115200 to 56700 in the Bluetooth tab?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Is it as simple as changing "AT+BAUD8" to "AT+BAUD7" & changing the baud rate to from 115200 to 56700 in the Bluetooth tab?


Something like that. I would use 19200 though coz 56700 is still not reliable.


----------



## Ovaltineo (Jul 18, 2013)

I have just released v5.6 of the Arduino code. I have changed bluetooth baud rate to 19200 for non-Mega boards. 

Non-Mega users must first switch to CALIBRATE_MODE to re-program the HC-06 module.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> I have just released v5.6 of the Arduino code. I have changed bluetooth baud rate to 19200 for non-Mega boards.
> 
> Non-Mega users must first switch to CALIBRATE_MODE to re-program the HC-06 module.


Hi OvalTineo, 

Please you confirm the RX and TX pins of bluethoo. for Arduino UNO with L298N. 













> PUSHBACK - define this if pushback above specified motor output is desired. Change pushback parameters in Pushback.h.
> 
> BLUETOOTH - define this if a HC06 "linvor" bluetooth module is attached to Serial3 (on Mega) or pin 7 RX & pin 8 TX (on UNO)
> 
> TEMPERATURE_SENSORS	- define this if TC74A0 and TC74A2 are attached to I2C bus




Thank you..


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi OvalTineo,
> 
> Please you confirm the RX and TX pins of bluethoo. for Arduino UNO with L298N.
> 
> Thank you..


I have updated the schematic on the first post.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> I have updated the schematic on the first post.



Oval Thanks .. I'll try ...


----------



## electricpolo (Mar 15, 2011)

*Re: ElectricPolo Segway Clone Progress*

More build pics including the steering mechanism.
http://www.diyelectriccar.com/forums/showthread.php/electricpolo-segway-clone-build-95729p3.html
My controller has been repaired and is on its way back to me.

On another note. If you are thinking about LiFePo batteries for your clone, I have a source of some hardly used 40Ah Thundersky batteries.
(Australia only though)


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Steering:
> Did you #define MPU6050_X2_STEERING? Did you mount the second MPU6050 sensor on the steering shaft? Can you post pictures please?
> 
> HC06:
> ...


 ..



Hi Ovaltineo.

1. Realizo los pasos anteriores . la pantalla de telefono azul, luedo verde, luego blanca "CONECTED¡"

But I can not modifiar nothing, nothing happens. 










2 - I have also executed serial monitor: 


```
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
Gyro   206
Gyro   213
Gyro   219
Gyro   193
Gyro   212
Gyro   202
Gyro   180
Gyro   205
Gyro   203
Gyro   164
Gyro   198
Gyro   187
Gyro   184
Gyro   197
Gyro   212
Gyro   211
Gyro   200
Gyro   202
Gyro   190
Gyro   170
Gyro   220
Gyro   217
Gyro   188
Gyro   197
Gyro   191
Gyro   234
Gyro   193
Gyro   196
Gyro   186
Gyro   201
Gyro   224
Gyro   198
Gyro   210
Gyro   209
Gyro   153
Gyro   211
Gyro   159
Gyro   207
Gyro   196
Gyro   199
Gyro   172
Gyro   220
Gyro   176
Gyro   192
Gyro   181
Gyro   190
Gyro   194
Gyro   175
Gyro   186
Gyro   180
Gyro   188
Gyro   192
Gyro   210
Gyro   206
Gyro   215
Gyro   213
Gyro   176
Gyro   166
Gyro   179
Gyro   197
Gyro   213
Gyro   187
Gyro   200
Gyro   184
Gyro   187
Gyro   194
Gyro   178
Gyro   205
Gyro   216
Gyro   195
Gyro   214
Gyro   165
Gyro   199
Gyro   191
Gyro   197
Gyro   184
Gyro   207
Gyro   198
Gyro   199
Gyro   180
Gyro   181
Gyro   184
Gyro   206
Gyro   194
Gyro   193
Gyro   183
Gyro   216
Gyro   218
Gyro   172
Gyro   191
Gyro   221
Gyro   199
Gyro   187
Gyro   195
Gyro   169
Gyro   201
Gyro   187
Gyro   222
Gyro   182
Gyro   211
Gyro   201
Gyro   175
Gyro   195
Gyro   191
Gyro   194
Gyro   198
Gyro   207
Gyro   184
Gyro   210
Gyro   179
Gyro   183
Gyro   189
Gyro   192
Gyro   204
Gyro   185
Gyro   201
Gyro   179
Gyro   177
Gyro   178
Gyro   195
Gyro   211
Gyro   212
Gyro   182
Gyro   197
Gyro   195
Gyro   197
Gyro   198
Gyro   192
Gyro   193
Gyro   186
Gyro   177
Gyro   205
Gyro   170
Gyro   172
Gyro   203
Gyro   222
Gyro   209
Gyro   205
Gyro   180
Gyro   169
Gyro   191
Gyro   177
Gyro   194
Gyro   219
Gyro   188
Gyro   179
Gyro   215
Gyro   194
Gyro   201
Gyro   174
Gyro   188
Gyro   190
Gyro   174
Gyro   172
Gyro   189
Gyro   192
Gyro   226
Gyro   184
Gyro   187
Gyro   185
Gyro   195
Gyro   191
Gyro   208
Gyro   203
Gyro   199
Gyro   209
Gyro   179
Gyro   172
Gyro   192
Gyro   210
Gyro   188
Gyro   220
Gyro   183
Gyro   224
Gyro   206
Gyro   176
Gyro   202
Gyro   206
Gyro   198
Gyro   182
Gyro   194
Gyro   222
Gyro   189
Gyro   200
Gyro   201
Gyro   187
Gyro   202
Gyro   186
Gyro   183
Gyro   206
Gyro   167
Gyro   202
Gyro   178
Gyro   200
Gyro   203
Gyro   216
Gyro   178
Gyro   233
Gyro   220
Gyro   176
Gyro   215
Gyro   186
Gyro   219
Gyro   203
Gyro   208
Gyro   206
Gyro   171
Gyro   177
Gyro   218
Gyro   203
Gyro   203
Gyro   153
Gyro   184
Gyro   188
Gyro   204
Gyro   193
Gyro   198
Gyro   220
Gyro   200
Gyro   202
Gyro   202
Gyro   207
Gyro   169
Gyro   190
Gyro   194
Gyro   198
Gyro   202
Gyro   206
Gyro   205
Gyro   204
Gyro   189
Gyro   185
Gyro   202
Gyro   185
Gyro   199
Gyro   183
Gyro   185
Gyro   223
Gyro   230
Gyro   211
Gyro   209
Gyro   183
Gyro   214
Gyro   208
Gyro   181
Gyro   232
Gyro   199
Gyro   196
Gyro   194
Gyro   181
Gyro   206
Gyro   179
Gyro   184
Gyro   177
Gyro   167
Gyro   224
Gyro   190
Gyro   193
Gyro   154
Gyro   224
Gyro   218
Gyro   168
Gyro   181
Gyro   209
Gyro   198
Gyro   186
Gyro   190
Gyro   190
Gyro   205
Gyro   202
Gyro   203
Gyro   176
Gyro   202
Gyro   168
Gyro   209
Gyro   207
Gyro   204
Gyro   200
Gyro   224
Gyro   182
Gyro   182
Gyro   211
Gyro   185
Gyro   197
Gyro   180
Gyro   239
Gyro   205
Gyro   198
Gyro   153
Gyro   181
Gyro   187
Gyro   179
Gyro   199
Gyro   203
Gyro   187
Gyro   181
Gyro   180
Gyro   218
Gyro   197
Gyro   194
Gyro   193
Gyro   197
Gyro   176
Gyro   194
Gyro   190
Gyro   176
Gyro   205
Gyro   208
Gyro   189
Gyro   197
Gyro   168
Gyro   208
Gyro   202
Gyro   187
Gyro   168
Gyro   231
Gyro   199
Gyro   199
Gyro   179
Gyro   191
Gyro   192
Gyro   204
Gyro   188
Gyro   190
Gyro   186
Gyro   215
Gyro   194
Gyro   210
Gyro   190
Gyro   197
Gyro   178
Gyro   188
Gyro   205
Gyro   158
Gyro   176
Gyro   196
Gyro   197
Gyro   200
Gyro   201
Gyro   208
Gyro   222
Gyro   177
Gyro   199
Gyro   183
Gyro   203
Gyro   177
Gyro   214
Gyro   210
Gyro   187
Gyro   195
Gyro   203
Gyro   208
Gyro   199
Gyro   191
Gyro   185
Gyro   181
Gyro   196
Gyro   152
Gyro   193
Gyro   177
Gyro   208
Gyro   170
Gyro   205
Gyro   176
Gyro   182
Gyro   174
Gyro   203
Gyro   209
Gyro   216
Gyro   203
Gyro   177
Gyro   186
Gyro   187
Gyro   214
Gyro   199
Gyro   193
Gyro   208
Gyro   172
Gyro   186
Gyro   205
Gyro   196
Gyro   199
Gyro   208
Gyro   191
Gyro   198
Gyro   152
Gyro   188
Gyro   177
Gyro   173
Gyro   187
Gyro   197
Gyro   191
Gyro   177
Gyro   185
Gyro   212
Gyro   203
Gyro   210
Gyro   192
Gyro   212
Gyro   204
X Accel Offset   483Y Gyro Offset   194Y Gyro Min   152Y Gyro Max   239
```

3 - Photo after executing serial monitor. 










When disconnecting arduino usb, and connect 24v motors no longer move. does nothing.


Note: I have also tested whether run the serial monitor, nor does anything clonconsole.

? That may estra happening ..? 

Thank you ..


----------



## ferchotech (May 29, 2014)

When disconnecting arduino usb, and connect 24v motors no longer move. does nothing.


Note: I've also tried without running the serial monitor. Clonconsole does nothing. 

? That may estra happening ..? 

Thank you ..


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> When disconnecting arduino usb, and connect 24v motors no longer move. does nothing.
> 
> 
> Note: I've also tried without running the serial monitor. Clonconsole does nothing.
> ...


I think you missed step 2 in my instructions.

CALIBRATE_MODE is used to calibrate the gyros and accelerometer in the level position. It is also used to initialize the name and baud rate of the HC06 bluetooth module. If this is the first time you have used this mode, then that explains why your robot will not balance properly in your previous posts.

After you run CALIBRATE_MODE with your robot in the balanced/level position (do not move it until calibration is finished). You must remove/undefine CALIBRATE_MODE and re-upload the Arduino program. This is also known as the RUN_MODE. Make sure you keep the robot in the balanced/level position when loading the RUN_MODE for the first time. That's because it will re-calibrate as soon as you plug in your USB cable.


----------



## Borc (Mar 12, 2014)

With combination Uno/BT I can connect and save parameters P and D. Parameters are applied correctly, but when start Clone Console again, parameters are always 0. Somehow it can not read them, even with latest version.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> I think you missed step 2 in my instructions.
> 
> CALIBRATE_MODE is used to calibrate the gyros and accelerometer in the level position. It is also used to initialize the name and baud rate of the HC06 bluetooth module. If this is the first time you have used this mode, then that explains why your robot will not balance properly in your previous posts.
> 
> After you run CALIBRATE_MODE with your robot in the balanced/level position (do not move it until calibration is finished). You must remove/undefine CALIBRATE_MODE and re-upload the Arduino program. This is also known as the RUN_MODE. Make sure you keep the robot in the balanced/level position when loading the RUN_MODE for the first time. That's because it will re-calibrate as soon as you plug in your USB cable.





Hi Ovaltineo, 

I do all the above procedure ... but nothing happens.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi Ovaltineo,
> 
> I do all the above procedure ... but nothing happens.


With each new release, all the files including SegwayClone.h and Motors.h gets reset to default values. Did you re-apply your changes to them? Can you post your SegwayClone.h?


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> With each new release, all the files including SegwayClone.h and Motors.h gets reset to default values. Did you re-apply your changes to them? Can you post your SegwayClone.h?




```
/*
MODE_CALIBRATE		- calibrate the sensors and save the data to EEPROM.  You must level the board, reset the Arduino, and  wait for the continuous tone.
MODE_RUN			- loads calibration data from the EEPROM.  Tone will sound until board is level between +-2 degrees.  Then it is ready to ride.

POT_STEERING		- use a potentiometer on A1 for steering and an MPU6050 for board tilt
MPU6050_X2_STEERING	- use two MPU6050s, one for board tilt and a second one for steering
MPU6050_X1_STEERING	- one MPU6050. It is used to measure board tilt and steering
GY80_STEERING		- one GY80. It is used to measure board tilt and steering

PWM_PWM_CONTROLLER	- use dual pin PWM + enable pin motor controller, eg BTN7960
PWM_DIR_CONTROLLER	- use single pin PWM + direction pin motor controller  
ROBOCLAW_CONTROLLER	- use Roboclaw motor controller.  Roboclaw must be configured for packet serial mode 38400 baud with address 0x80
SABERTOOTH_CONTROLLER - use Sabertooth motor controller.  Sabertooth must be configured for packet serial mode 38400 baud with address 0x80
PWN_SHIELD_CONTROLLER - use Elechouse dual-channel motor shield.  http://www.elechouse.com/elechouse/index.php?main_page=product_info&products_id=2179
L298N_CONTROLLER	- use L298N motor controller with ENA, IN1, IN2, IN3, IN4, and ENB pins 

CHECK_VOLTAGE		- define if voltage sensor (22K + 4.7K voltage divider resistor ) is connected to A3.  22K is in series with battery voltage, 4.7K goes to ground.
					  Battery----22K----A3----4.7K----Gnd

PUSHBACK			- define this if pushback above specified motor output is desired.  Change pushback parameters in Pushback.h.

BLUETOOTH			- define this if a HC06 "linvor" bluetooth module is attached to Serial3 (on Mega) or pin 7 RX & pin 8 TX (on UNO)

TEMPERATURE_SENSORS	- define this if TC74A0 and TC74A2 are attached to I2C bus

LOCKED_BY_DEFAULT	- define this if you want clone to be locked at power-up.  Needs CloneConsole Android app to unlock.

RIDER_SENSOR		- define this if rider sensor/switch is available. Sensor must pull this pin HIGH when rider is ON, and pull it LOW when rider is OFF

INVERT_RIDER_SENSOR - This will invert the logic of the RIDER_SENSOR. RIDER_SENSOR pin is LOW when rider is ON, and HIGH when rider is OFF
*/

/*
Uncomment one MODE below
*/
//#define MODE_CALIBRATE
#define MODE_RUN

/*
Uncomment one STEERING type below
*/
#define POT_STEERING
//#define MPU6050_X2_STEERING
//#define MPU6050_X1_STEERING
//#define GY80_STEERING

/*
Uncomment only if steering left and right are inverted
*/
//#define INVERT_STEERING

/*
Uncomment one CONTROLLER type below
*/
//#define PWM_PWM_CONTROLLER
//#define PWM_DIR_CONTROLLER
//#define ROBOCLAW_CONTROLLER
//#define ROBOCLAW_ENCODER_CONTROLLER
//#define SABERTOOTH_CONTROLLER
//#define PWM_SHIELD_CONTROLLER
#define L298N_CONTROLLER

/*
Uncomment if you want to check battery voltage.  See note above for resistor divider.
*/
//#define VOLTAGE_CHECK

/*
Uncomment if you want LED Voltage indicator.  You need VOLTAGE_CHECK with this.
*/
//#define VOLTAGE_LED

/*
Uncomment if you want Pushback
*/
//#define PUSHBACK

/*
Uncomment if you have a HC06 "linvor" bluetooth module
*/
#define BLUETOOTH

/*
Uncomment if you have TC74 temperature sensors - TC74A0 and TC74A2 default addresses in TC74.h
*/
//#define TEMPERATURE_SENSORS

/*
Uncomment if you want the clone to be locked during startup.  It can only be unlocked via CloneConsole Android app.
*/
//#define LOCKED_BY_DEFAULT

/*
Uncomment if you have a rider sensor - sensor must pull this pin HIGH when rider is ON, and pull it LOW when rider is OFF
Initial values are loaded from KP_OFF, KD_OFF, and MOTOR_MAX_OFF.
*/
//#define RIDER_SENSOR	13

/*
Uncomment if RIDER_SENSOR above has reverse logic, ie LOW when rider is ON and HIGH when rider is OFF
*/
//#define INVERT_RIDER_SENSOR


//#define FAN_PIN			8				// optional output for MOSFET or relay fan switch

#define BUZZER_PIN			12
#define POT_STEERING_PIN	A1				
#define P_PIN				A0				// optional pot for adjusting P value (Proportional)
#define D_PIN				A2				// optional pot for adjusting D value (Derivative)

#ifdef VOLTAGE_CHECK
	#define VOLTAGE_PIN			A3
//	#define VOLTAGE_PIN			A5			// ovaltine's clone uses this
	#define VOLTAGE_DIVIDER		.176		// voltage divider: 4.7K/(22K + 4.7K) = .176
#endif

// The following 9 lines were borrowed/copied from Multiwii
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
  #define PROMINI
#endif
#if defined(__AVR_ATmega32U4__) || defined(TEENSY20)
  #define PROMICRO
#endif
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
  #define MEGA
#endif

#ifdef VOLTAGE_LED
	#if defined(PWM_SHIELD_CONTROLLER)
		#define LED_GREEN_PIN		A0
		#define LED_YELLOW_PIN		5
		#define LED_RED_PIN			6
	#elif ((defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER)) && !defined(MEGA))
		#define LED_GREEN_PIN		4
		#define LED_YELLOW_PIN		5
		#define LED_RED_PIN			6
	#else
		#define LED_GREEN_PIN		9
		#define LED_YELLOW_PIN		10
		#define LED_RED_PIN			11
	#endif
#endif

typedef struct
{
	float x_accel;
	float y_accel;
	float z_accel;
	float x_gyro;
	float y_gyro;
	float z_gyro;

	int x_accel_offset;
	int y_accel_offset;
	int z_accel_offset;

	int x_gyro_offset;
	int y_gyro_offset;
	int z_gyro_offset;

	int x_gyro_offset_min;
	int x_gyro_offset_max;
	int y_gyro_offset_min;
	int y_gyro_offset_max;
	int z_gyro_offset_min;
	int z_gyro_offset_max;

	int address;
} sensorType;


#define	ALPHA 0.97				// used by complementary filter

#if defined(ROBOCLAW_CONTROLLER)
	// use these values if using Roboclaw
	#define KP 3.9					// proportional constant when rider is ON
	#define KD 1.5   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 25     // adjust depending on your motor speed
	#define KP_OFF 1.8				// proportional constant when rider is OFF
	#define KD_OFF .75 				// derivative constant when rider is OFF
#endif
#if defined(ROBOCLAW_ENCODER_CONTROLLER)
	// use these values if using Roboclaw with encoder
	#define KP 10.9					// proportional constant when rider is ON
	#define KD 4.68   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 546     // adjust depending on your motor speed
	#define KP_OFF 5.45				// proportional constant when rider is OFF
	#define KD_OFF 2.34 				// derivative constant when rider is OFF
#endif
#if defined(SABERTOOTH_CONTROLLER)
	// use these values if using Sabertooth
	#define KP .35					// proportional constant when rider is ON
	#define KD .15   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 1.75   // adjust depending on your motor speed
	#define KP_OFF .17				// proportional constant when rider is OFF
	#define KD_OFF .07 				// derivative constant when rider is OFF
#endif
#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER)  || defined(PWM_SHIELD_CONTROLLER) || defined(L298N_CONTROLLER)
	// use these values if using PWM
	#define KP .7					// proportional constant when rider is ON
	#define KD .3   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 3.5    // adjust depending on your motor speed
	#define KP_OFF .35				// proportional constant when rider is OFF
	#define KD_OFF .15 				// derivative constant when rider is OFF
#endif

#define MAX_ANGLE  18			// adjust depending on your machine
#define MIN_ANGLE  -15			// adjust depending on your machine

#define CALIBRATE_YES	true
#define CALIBRATE_NO	false

#define ACC_FILTER	0.05
#define lowpassFilter(val, change, q) ((1-q) * val + (change * q))

#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER) || defined(PWM_SHIELD_CONTROLLER) || defined (L298N_CONTROLLER)
	// bluetooth software serial pins for non-mega boards with PWM controllers
	#define SOFT_RX_PIN3	5			// connect to bluetooth module TX pin
	#define SOFT_TX_PIN3	6			// connect to bluetooth module RX pin
#else	
	// bluetooth software serial pins for non-mega boards with serial controllers
	#define SOFT_RX_PIN3	7			// connect to bluetooth module TX pin
	#define SOFT_TX_PIN3	8			// connect to bluetooth module RX pin
#endif	

#define STEER_OFFSET_DIVIDER	-70.0		// bluetooth remote control steer offset (X) divider.  Higher value makes X movement less sensitive.
#define BOARD_OFFSET_DIVIDER	-70.0		// bluetooth remote control board offset (Y) divider.  Higher value makes Y movement less sensitive.
```


----------



## Ovaltineo (Jul 18, 2013)

Borc said:


> With combination Uno/BT I can connect and save parameters P and D. Parameters are applied correctly, but when start Clone Console again, parameters are always 0. Somehow it can not read them, even with latest version.


Can you post a picture of the CloneConsole running? If they are zero and you change and save them, does it take effect? If you exit CloneConsole and start again, they go back to zero?


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
During calibration, does the power the motors have to be disconnected?


----------



## ferchotech (May 29, 2014)

Hi Oval. 

Here is a video of the process. 


http://youtu.be/fQ1IM7lNuBw 

What will happen


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> During calibration, does the power the motors have to be disconnected?


For safety reasons, your main switch should be OFF before you plug the USB cable to the Arduino for calibration.


----------



## mariov (May 22, 2014)

Guys any one knows which ports on the mega should connect to S1 and S2 in Roboclaw? 

Thanks

Mario


----------



## Borc (Mar 12, 2014)

Ovaltineo said:


> Can you post a picture of the CloneConsole running? If they are zero and you change and save them, does it take effect? If you exit CloneConsole and start again, they go back to zero?


Yes, It does take effect and are saved to clone. When starting Console again both parameters are back to zero (in Clone Console), but are still saved in clone(will post picture latter). That way I never know their real values.
Setting the parameters should be done extreme carefully, since you can be easily beaten by your own clone (believe me).


Beside that, clone is working great. Really good job Ovaltine!
Thank you.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> When disconnecting arduino usb, and connect 24v motors no longer move. does nothing.


Looking at your video, what you wrote above is misleading and put me in the wrong direction at diagnosing the problem. The motors are clearly moving in the video, right? 

One limitation of the CloneConsole is that you must exit it before turning off your clone. It only connects when launched and will not re-connect if you re-start your clone. 

I think the real problem is what Borc described - P and D are zero. I don't have an UNO and this will take some time to solve.

In any case, I want to know if the XY "joystick" screen is working. 
1. start your clone in run mode and on the floor balancing (you may need to help it with your hands)
2. run CloneConsole. Wait for the screen to turn white. If it won't turn white then Exit, re-start bluetooth and try again.
3. Change to XY screen. 
Does changing the joystick position have any effect on the clone?


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> Guys any one knows which ports on the mega should connect to S1 and S2 in Roboclaw?
> 
> Thanks
> 
> Mario


It's in the README.txt. I will post a schematic soon.


```
To use Roboclaw with a Mega, connect S1 to pin 18 (TX1), and S2 to pin 19 (RX1).
```


----------



## Ovaltineo (Jul 18, 2013)

Borc said:


> Yes, It does take effect and are saved to clone. When starting Console again both parameters are back to zero (in Clone Console), but are still saved in clone(will post picture latter). That way I never know their real values.


The real values would be what they were before you press the save button. The picture will help because I want to see what the other telemetry values are.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Looking at your video, what you wrote above is misleading and put me in the wrong direction at diagnosing the problem. The motors are clearly moving in the video, right?
> 
> One limitation of the CloneConsole is that you must exit it before turning off your clone. It only connects when launched and will not re-connect if you re-start your clone.
> 
> ...



Hi Oval. 

Sorry for not making myself understood. 

"3. Cambiar XY screen. 
Does changing the joystick position have any effect on the clone? "

Answer: XY screen does not change the behavior of the clone.


----------



## Borc (Mar 12, 2014)

Just did some extensive testing. Clone Console sometimes get the right value and sometimes not at all. When saving values, sometimes things go wild and Clone is trying to hurt himself and me (with normal values of P and D component)

Attached pictures - P is set to 0.16 on Clone (on all pictures)
1. not get values at all 
2. after starting application again value is correct (but not sure if correct since clone is not balancing as before. After saving value again Clone go wild and is trying to hurt someone and after put it over max. angle to stop I got some P and D values which I never set ??? Clone is on USB power- since powering the motors is dangerous (last picture 5.)

3. calibrate screen (I have this on LG P970 (android 4.04), on Galaxy S4 mini screen is fine)


Have to say that Clone is working just fine (balancing) with default settings -without tuning, but I would like to tune it to get little faster response from it. 
4. picture - Clone


----------



## ferchotech (May 29, 2014)

Hi Guys. 

My clone is now in arduino mega. and in equilibrium. 

The bluetooth connects clonconsole well. phone screen goes blank. But The clonconsole does nothing. 

Please can you explain: 

As would be the correct operation of the display (X, Y)?. I move my finger on the screen (X, Y), but my clone does nothing. 

Thank you.


----------



## ferchotech (May 29, 2014)

Borc said:


> Just did some extensive testing. Clone Console sometimes get the right value and sometimes not at all. When saving values, sometimes things go wild and Clone is trying to hurt himself and me (with normal values of P and D component)
> 
> Attached pictures - P is set to 0.16 on Clone (on all pictures)
> 1. not get values at all
> ...


Hi Borc. 

Please can you put a video of how it works clonconsole. I tried a lot, but I get no results ... 

Thank you.


----------



## mariov (May 22, 2014)

Thanks!
BTW i used a 3S Lipo (11.1) volts to power the Arduino and the Roboclaw and i fried the Arduino and the steering gyro , thought the Arduino could be powered with up to 12V


----------



## qazwsx000521 (Apr 22, 2014)

Ovaltineo said:


> Yes, it applies for both single and dual boards. I actually have the steering sensor with the X axis pointing down on my clone, but I had to add a different code for that.
> 
> I have been testing single and dual sensors recently. With the current code, the dual sensor is better coz steering and board tilting do not affect each other. With a single sensor, the board dips when I'm turning coz the zero level of the tilt (pitch) is affected. I am going to test a more complicated algorithm that hopefully will address this.


Recommended adding z gyro compensation! Good off-road performance


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi Guys.
> 
> My clone is now in arduino mega. and in equilibrium.
> 
> ...


If you change to a mega, you need to recalibrate coz the Bluetooth needs to use 115200 baud.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> If you change to a mega, you need to recalibrate coz the Bluetooth needs to use 115200 baud.



Hi Oval, 

I am sorry to ask, you mean do the calibration?. 










If so. I if Calibration carried. 

If not. I can please say where I have to change the Bluetooth code? .


- I think I'll buy a phone, because this is Chinese. 

Thank you ..


----------



## electricpolo (Mar 15, 2011)

You are defining both Calibrate & Run modes at the same time in your example.

It should be like this to calibrate
#define MODE_CALIBRATE
//#define MODE_RUN
or like this to run
//#define MODE_CALIBRATE
#define MODE_RUN


----------



## adamson (Mar 2, 2014)

ferchotech said:


> Hi Oval,
> 
> I am sorry to ask, you mean do the calibration?.
> 
> ...


I think this is calibration mode:

```
#define MODE_CALIBRATE
//#define MODE_RUN
```


----------



## adamson (Mar 2, 2014)

Cloneconsole works great on my new phone ASUS zenfone 5.


----------



## electricpolo (Mar 15, 2011)

adamson,
what model Arduino are you using?


----------



## adamson (Mar 2, 2014)

electricpolo said:


> adamson,
> what model Arduino are you using?


 I'm using mega 2560.
Cloneconsole didn't work on my other phone, so in my case it was phone problem.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi Oval,
> 
> I am sorry to ask, you mean do the calibration?.
> 
> ...


Please run the following sketch to configure the HC06 into 115200 baud. Then load the SegwayClone sketch in run mode (MODE_CALIBRATE not defined).


```
void setup()
{
        Serial3.begin(19200);
        delay(2000);
        Serial3.print("AT+BAUD8");
        delay(2000);
}

void loop()
{
}
```


----------



## Ovaltineo (Jul 18, 2013)

I think I know why the CloneConsole doesn't work with the UNO/Nano. At the slower 19200 baud, I think I'm over-running the serial buffer on the HC06 bluetooth module. I need to add some delays in the code. The only thing stopping me from doing that right now is my wife complaining that I'm spending all my weekends on that damn machine !


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> I think I know why the CloneConsole doesn't work with the UNO/Nano. At the slower 19200 baud, I think I'm over-running the serial buffer on the HC06 bluetooth module. I need to add some delays in the code. The only thing stopping me from doing that right now is my wife complaining that I'm spending all my weekends on that damn machine !


Jajjaja......My wife is the same ...


----------



## electricpolo (Mar 15, 2011)

After 19 years married to my beautiful wife, I have learned one thing.
Happy wife, happy life.
I'm in no rush for bluetooth to work with my Nano. It will happen when it happens.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Please run the following sketch to configure the HC06 into 115200 baud. Then load the SegwayClone sketch in run mode (MODE_CALIBRATE not defined).
> 
> 
> ```
> ...





Hi Oval. 

You mean this? 











Display (X, Y) does not work, it does nothing. 

Question:
Display? (X, Y) as? work?

thank you ..


----------



## adamson (Mar 2, 2014)

My son is driving better than me. 
https://www.youtube.com/watch?v=UpjM2H2kSxU


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi Oval.
> 
> You mean this?
> 
> ...


Well, I really wanted you to simply load and run the following sketch on the Mega:


```
void setup()
{
        Serial3.begin(19200);
        delay(2000);
        Serial3.print("AT+BAUD8");
        delay(2000);
}

void loop()
{
}
```
Afterwards, load and run the SegwayClone sketch. In SegwayClone.h, make sure //#define CALIBRATE_MODE has the // at the start of the line. 

Run CloneConsole, can you see if P, D, Turn and Tilt are working?


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Well, I really wanted you to simply load and run the following sketch on the Mega:
> 
> 
> ```
> ...



Hi Oval, 

Procedure performed, but does nothing clonconsole in my clone. 

View video: 

http://youtu.be/_PNUnSBdK6E

Greetings.


----------



## ferchotech (May 29, 2014)

adamson said:


> My son is driving better than me.
> https://www.youtube.com/watch?v=UpjM2H2kSxU



Congratulations, it looks great ...


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi Oval,
> 
> Procedure performed, but does nothing clonconsole in my clone.
> 
> Greetings.


Did you connect the HC06 to TX3 and RX3 on the Mega? They are different from the pins used on the UNO. 

I have added a new program - DetectBluetooth.ino in post #1. Please run it and post the output from the Serial Monitor.


----------



## Ovaltineo (Jul 18, 2013)

qazwsx000521 said:


> Recommended adding z gyro compensation! Good off-road performance


Can you post the algorithm?


----------



## Ovaltineo (Jul 18, 2013)

Borc said:


> Just did some extensive testing. Clone Console sometimes get the right value and sometimes not at all. When saving values, sometimes things go wild and Clone is trying to hurt himself and me (with normal values of P and D component)
> 
> Attached pictures - P is set to 0.16 on Clone (on all pictures)
> 1. not get values at all
> ...



Are you using a Roboclaw or Sabertooth + Bluetooth with an UNO? I have just learned from another member that using two Software Serial ports will not work - this is a limitation of the SoftwareSerial library.

I suggest swapping the UNO with a Mega.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> After 19 years married to my beautiful wife, I have learned one thing.
> Happy wife, happy life.
> I'm in no rush for bluetooth to work with my Nano. It will happen when it happens.



As per my post above, using two Software Serial ports will not work - this is a limitation of the SoftwareSerial library.

I suggest swapping the Nano with a Mega.

I have now removed bluetooth module from the UNO schematics with Roboclaw and Sabertooth.


----------



## Borc (Mar 12, 2014)

Ovaltineo said:


> Are you using a Roboclaw or Sabertooth + Bluetooth with an UNO? I have just learned from another member that using two Software Serial ports will not work - this is a limitation of the SoftwareSerial library.
> 
> I suggest swapping the UNO with a Mega.


I'm using Sabertooth+Bluetooth+Uno. With Galaxy S4 mini I get the right values from time to time (KP=0,35, Kd=0,15) when starting Clone Console.
But when saving values, these are not saved correctly.

Will switch to mega.


----------



## electricpolo (Mar 15, 2011)

What about using an Arduino Due? It is a 32 bit CPU that runs at 84MHz.
Has all the pins we need + multiple hardware serial ports.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> What about using an Arduino Due? It is a 32 bit CPU that runs at 84MHz.
> Has all the pins we need + multiple hardware serial ports.


It won't work without a lot of change in the code. Sorry, but I haven't got time for that. Besides, it is overkill and too expensive for this application. You are better off buying a $17 Mega clone.


----------



## qazwsx000521 (Apr 22, 2014)

Ovaltineo said:


> Can you post the algorithm?


K_gyro_side=1-Turn_Need/80;
balance_speed=K_gyro_side*gyro_side;

speed_output_RH = PWM-Turn_Need+balance_speed
speed_output_LH =-PWM-Turn_Need+balance_speed


PWM_output (speed_output_LH,speed_output_RH);	
}


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Did you connect the HC06 to TX3 and RX3 on the Mega? They are different from the pins used on the UNO.
> 
> I have added a new program - DetectBluetooth.ino in post #1. Please run it and post the output from the Serial Monitor.





Hi Oval, 

I have connected (with respective resistors.) 
TX_bluetooth -> RX_mega. 
RX_bluetooth -> TX_mega. 
see photo 1. 













I do: Detecbluetooth and monitorserial. see photo 2. 













that happen? Thank you ..


----------



## electricpolo (Mar 15, 2011)

Mega on its way now.
Will also give me the extra serial port I need for my LCD.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi Oval,
> 
> I have connected (with respective resistors.)
> TX_bluetooth -> RX_mega.
> ...


Your HC06 is not talking to the Arduino. In the serial monitor, it is supposed to output "*Found bluetooth module at XXXXX*" where xxxxx is the baud rate. 

Previously, did you ever connect the Arduino directly to the HC06 RX without resistors? That was a fault on my schematics. That may have killed the RX interface on the HC06. 

Those clip-in connectors on your Arduino - did they come standard or did you replace them yourself? If you replaced them yourself, maybe a PCB trace got damaged?

Can you replace all occurrences of Serial3 with Serial2 on the DetectBluetooth program? Then connect the HC06 to TX2 and RX2, and run the program. Does it find the HC06? If not, then it is time to buy another HC06.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Your HC06 is not talking to the Arduino. In the serial monitor, it is supposed to output "*Found bluetooth module at XXXXX*" where xxxxx is the baud rate.
> 
> Previously, did you ever connect the Arduino directly to the HC06 RX without resistors? That was a fault on my schematics. That may have killed the RX interface on the HC06.
> 
> ...



Hi Oval. 
Probe with serial2 already, but I produced the same result. 
I think it's time to buy another HC06


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
If I am reading the code correctly for a Mega, the bluetooth goes on TX/RX3 & the RoboClaw goes on TX/RX1. Am I correct?

Seems like a Mega is the only Arduino worth using for this project. Would be much simpler code if it was for one Arduino board only.

Motor controller back any day & a Mega board is on its way.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> If I am reading the code correctly for a Mega, the bluetooth goes on TX/RX3 & the RoboClaw goes on TX/RX1. Am I correct?
> 
> Seems like a Mega is the only Arduino worth using for this project. Would be much simpler code if it was for one Arduino board only.
> ...


Yes, those connections are correct.

Until recently, I thought the non-Mega boards will be okay with the SoftwareSerial library. When I joined this forum, there were a couple of guys with Uno boards, so I changed my code to support them. I didn't have bluetooth support back then, so it was no problem. 

But nowadays, the ability to watch the telemetry and change the PD values using the CloneConsole is indispensable, so you are right, the Mega is really the only board suitable for this project.


----------



## electricpolo (Mar 15, 2011)

To Oval and anyone else that is using the Dayton 500W planetary motors.

Nathan at RoboClaw thinks that these motors have a very large back EMF which caused the problem with my controller. He has made some component modifications to my RoboClaw but has also recommended the following.

Add 0.1uF 250V poly caps across both motor terminals to act as snubbers.
Add two High Ripple capacitors across the battery terminals. These are in addition to the two large capacitors already on the controller and will help deal with the very high ripple current that comes back from these motors.

I have some Panasonic EETED2D821CA 820uF 200V high ripple capacitors left over from my electric car motor controller that are ideal. You can have a pair for $5 including postage if you want. I can post them overseas too for a little more. PM me if you want them.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> To Oval and anyone else that is using the Dayton 500W planetary motors.
> 
> Nathan at RoboClaw thinks that these motors have a very large back EMF which caused the problem with my controller. He has made some component modifications to my RoboClaw but has also recommended the following.
> 
> ...


I'll take a raincheck on those caps.

I've blown the capacitor on one of my BTN7960 controllers. But it wasn't the motor's fault. The capacitor was 1000uf 25V - manifestly inadequate for 24V use. I replaced it with a 330uf 50V and it's fine (so far). I would expect glitching and I2C errors with bad back-EMF snubbing -- I experienced this with my home-made motor controllers. But no glitches with the BTN7960 controllers which I have tested to its limits (until current limiting kicked in).


----------



## mariov (May 22, 2014)

My phone connects but it goes into the white calibrate lock screen, and it stays there.
Anyone experiencing the same?

Thanks

Mario


----------



## electricpolo (Mar 15, 2011)

I've got plenty of the caps left so anytime you want them just let me know.


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> My phone connects but it goes into the white calibrate lock screen, and it stays there.
> Anyone experiencing the same?
> 
> Thanks
> ...


Did you try pressing the UNLOCK button? I am guessing you defined LOCKED_BY_DEFAULT in SegwayClone.h? Remove this if you don't want your clone to lock on startup.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Your HC06 is not talking to the Arduino. In the serial monitor, it is supposed to output "*Found bluetooth module at XXXXX*" where xxxxx is the baud rate.
> 
> Previously, did you ever connect the Arduino directly to the HC06 RX without resistors? That was a fault on my schematics. That may have killed the RX interface on the HC06.
> 
> ...



Hi, Oval 

Change the HC-06, then test with arduino1 and this was good. The arduino mega serial port is not communicating. 

I will replace mega ...

Regards...


----------



## ferchotech (May 29, 2014)

Hi, Oval 

My wheel sprocket 60 teeth.


----------



## electricpolo (Mar 15, 2011)

ferchotech,
Have a look at my build thread http://www.diyelectriccar.com/forums/showthread.php/electricpolo-segway-clone-build-95729.html.
Might be helpful for you with your drive arrangement.
You have to remove as much backlash as possible from the motor armature to the wheel.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi, Oval
> 
> Change the HC-06, then test with arduino1 and this was good. The arduino mega serial port is not communicating.
> 
> ...


That's a big surprise. Did you change the board setting in the Arduino IDE to "Arduino Mega 2560 or Mega ADK"? Did you solder those clip-on connectors yourself?


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi, Oval
> 
> My wheel sprocket 60 teeth.


You may need to get a bigger sprocket.

What's the outside diameter of the wheel and how many watts is the motor? My first clone had 12-inch wheels, 300W motors, and 11:80 sprocket ratio. It was fine on flat ground, but it couldn't go uphill or off-road . It would be a lot worse with bigger wheels and a shorter sprocket ratio.


----------



## ferchotech (May 29, 2014)

electricpolo said:


> ferchotech,
> Have a look at my build thread http://www.diyelectriccar.com/forums/showthread.php/electricpolo-segway-clone-build-95729.html.
> Might be helpful for you with your drive arrangement.
> You have to remove as much backlash as possible from the motor armature to the wheel.



I'll see it.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> That's a big surprise. Did you change the board setting in the Arduino IDE to "Arduino Mega 2560 or Mega ADK"?



Yes, I change it.



```
Did you solder those clip-on connectors yourself?
```

yes, I soldered


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> You may need to get a bigger sprocket.
> 
> What's the outside diameter of the wheel and how many watts is the motor? My first clone had 12-inch wheels, 300W motors, and 11:80 sprocket ratio. It was fine on flat ground, but it couldn't go uphill or off-road . It would be a lot worse with bigger wheels and a shorter sprocket ratio.


Diameter of the wheel: 15"

Motors 500w

Sprocket ratio: 9:60 

Are saying?


----------



## electricpolo (Mar 15, 2011)

Are your motors the geared output type?
What is the max output rpm of your motors?


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Diameter of the wheel: 15"
> 
> Motors 500w
> 
> ...


The sprocket ratio looks a bit short. You're speed on flat will be fast, but it won't be climbing steep hills. Give it a go, and increase to 80-tooth if you need more torque.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Yes, I change it.
> 
> 
> 
> ...



I'm guessing you damaged the PCB trace when you unsoldered the original connectors. These multi-layered PCBs are easy to damage. I would recommend using a stackable protoyping board and soldering your clip-on connectors there.


----------



## ferchotech (May 29, 2014)

electricpolo said:


> Are your motors the geared output type?
> What is the max output rpm of your motors?



Hi electricpolo, 

The maximum speed is 2500 rpm under load.










regards


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> I'm guessing you damaged the PCB trace when you unsoldered the original connectors. These multi-layered PCBs are easy to damage. I would recommend using a stackable protoyping board and soldering your clip-on connectors there.


Hi oval,

I tested continuity between the legs of atmega 2560 and bleutooth, are good .. 

I think it is internal damage atmega 2560.


----------



## mariov (May 22, 2014)

Still couldn't make the bluetooth work, i'm using a mega, according to the scheme in page one i should use rx3 and tx3, but in my case those ports are pretty much dead.
Any words of wisdom appreciated

Thanks

Mario


----------



## electricpolo (Mar 15, 2011)

Just change it a different port say Serial2.
In the Bluetooth Tab, change any instance of Serial3 to Serial2.
Change your wire connections to suit.
Make sure RX goes to TX & TX goes to RX.
Be aware that the bluetooth module is 3.3V & mustn't be connected to 5V either to power it or from an Arduino output. 
You can power it from the 3.3V Arduino output but you should use a resistor divider on the Arduino TX so the module only sees 3.3V.
Alternatively you can use an Arduino level converter. This is the recomended way to connect 3.3V devices to a 5V Arduino.


----------



## electricpolo (Mar 15, 2011)

ferchotech,
I've done a couple of quick calcs about your gear ratio. 
For an approximate top speed of 20km/hr with a little bit left in reserve, you will need a reduction ration around 8.33:1 or maybe even more. 
With your 9 tooth motor sprocket, you will need something like a 75 tooth or 80 tooth wheel sprocket.
Your current ratio of 9:60 is too high & will give you a theoretical top speed of 27 km/hr but you won't have enough torque to get up an incline. You might even have balance problems because the motors may not have enough power to change speed or direction fast enough.


----------



## mariov (May 22, 2014)

I was following the scheme on page one so i was connecting it to 5V and i added the resistors as described. Should i assume i burnt the BT module?
I ordered another anyway 




electricpolo said:


> Just change it a different port say Serial2.
> In the Bluetooth Tab, change any instance of Serial3 to Serial2.
> Change your wire connections to suit.
> Make sure RX goes to TX & TX goes to RX.
> ...


----------



## electricpolo (Mar 15, 2011)

My first one I had connected to 5V like the original schematic. It has always been problematic even after I got the level converter. 
I don't know whether it was due to the module getting a bit fritzed or the (now known) software serial issue with the Nano.
From what I have read, sometimes you get away with it & sometimes you don't.
In any case, I now have a Mega, a level converter & a new bluetooth module.


----------



## mariov (May 22, 2014)

Ok i will buy a level converter i just received a second BT module that i plugged in to the 3.3 V in the mega board so hopefully i didn't fried it.
How do you connect the module, do you follow the schematics resistors wise or is no longer necessary?
Thanks



electricpolo said:


> My first one I had connected to 5V like the original schematic. It has always been problematic even after I got the level converter.
> I don't know whether it was due to the module getting a bit fritzed or the (now known) software serial issue with the Nano.
> From what I have read, sometimes you get away with it & sometimes you don't.
> In any case, I now have a Mega, a level converter & a new bluetooth module.


----------



## electricpolo (Mar 15, 2011)

The resistors are no longer required if you use a level converter.
Use the connection diagram supplied with the level converter.
These gadgets convert the 5V output from the Arduino to a 3.3V input signal for the module & convert the 3.3V module output to a 5V input for the Arduino.


----------



## mariov (May 22, 2014)

I think i'm missing something basic here. When i connect the BT module to rx0/tx0 i see the serial terminal data on the BT terminal on my tablet. So the module is communicating.
When i plug in the module in the RX3/TX3 nothing is coming out, the terminal is dead no data. 
Is there any jumper i need to setup on the mega?

Thanks



electricpolo said:


> The resistors are no longer required if you use a level converter.
> Use the connection diagram supplied with the level converter.
> These gadgets convert the 5V output from the Arduino to a 3.3V input signal for the module & convert the 3.3V module output to a 5V input for the Arduino.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Have a strange thing happening & perhaps you can shed some light on it.
Have the new Mega & have a couple of new MPU6050s from here http://flyduino.net/MPU6050-Break-Out-onboard-33V-reg_1
On these boards a solder bridge is put across A1 or A0 to change the address.

When I do a I2C scan I can see the connected MPU device with the address 0x68 or 0x69 depending on the solder bridge. So far so good.

When I run the clone code with a single MPU connected, configured as a single with the address set at 0x68, in the serial monitor I get the following:
WHO_AM_I : 0, error = 3
PWR_MGMT_2 : 0, error = 3
If the address is changed to 0x69 the message changes to error = 2.

I know what is supposed to happen because I have had the Nano working fine with either one or two el cheapo chinese MPUs.
Any ideas as to why this is happening with the Flyduino boards?


----------



## electricpolo (Mar 15, 2011)

I have connected a cheapie up to the Mega & run the code configured for 1 x MPU. 
The MPU & the serial monitor output works as expected just like on the Nano.
The only difference that I can measure is the SCL & SDA voltage on the cheapies is 3.76V & on the Flyduino the SCL & SDA voltage is 4.85V.
The Arduino is being powered by the USB port.


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> Ok i will buy a level converter i just received a second BT module that i plugged in to the 3.3 V in the mega board so hopefully i didn't fried it.
> How do you connect the module, do you follow the schematics resistors wise or is no longer necessary?
> Thanks



My mistake here I think. I should have specified that the HC-06 should be attached to a baseboard. The baseboard has 5V to 3.3V converter so VCC should be +5V.

This is what it should look like:


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> I think i'm missing something basic here. When i connect the BT module to rx0/tx0 i see the serial terminal data on the BT terminal on my tablet. So the module is communicating.
> When i plug in the module in the RX3/TX3 nothing is coming out, the terminal is dead no data.
> Is there any jumper i need to setup on the mega?
> 
> Thanks


Using the connections as per my schematic, run the DetectBluetooth program with the serial monitor running. Does it find the BT module? If not, change Serial3 to Serial2 (or Serial1) and change the TX/RX ports accordingly. Does it find the BT module?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> I have connected a cheapie up to the Mega & run the code configured for 1 x MPU.
> The MPU & the serial monitor output works as expected just like on the Nano.
> The only difference that I can measure is the SCL & SDA voltage on the cheapies is 3.76V & on the Flyduino the SCL & SDA voltage is 4.85V.
> The Arduino is being powered by the USB port.


From available schematic, SCL and SDA are pulled up to +3.3V on the (el cheapo) GY-521. Surprisingly, from your description, SCL and SDA are pulled up to +5V on the Flyduino. This is above the maximum logic voltage specified in the MPU6050 datasheet ! 

Are you using a logic converter? Because of the built-in +5V to 3.3V regulator, VCC should be +5V and because SCL and SDA are open-drain (open-collector) pins you shouldn't use a logic converter with either of these MPU6050 modules.


----------



## electricpolo (Mar 15, 2011)

No logic converter being used on the Flyduino. The voltage levels I measured are straight off the module. I had it connected exactly the same way as the cheapies.

With the Bluetooth modules, some are 3.3v Vcc & should have a converter. Both mine are this type. Some others can take 5v Vcc but I am not sure about rx input from the arduino.


----------



## mariov (May 22, 2014)

No it doesn't find it, i checked the circuit and i have two different BT modules and none of them are detected

I soldered the new pin, so now the Key pin is the RX pin?
No resistors?

Thanks!



Ovaltineo said:


> Using the connections as per my schematic, run the DetectBluetooth program with the serial monitor running. Does it find the BT module? If not, change Serial3 to Serial2 (or Serial1) and change the TX/RX ports accordingly. Does it find the BT module?


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> No it doesn't find it, i checked the circuit and i have two different BT modules and none of them are detected
> 
> I soldered the new pin, so now the Key pin is the RX pin?
> No resistors?
> ...


No - key pin is not connected. Do not look at the inverted picture - the pins look offset to the right. Use resistors as per my schematic.


----------



## markula (Oct 27, 2013)

I have problems with arduino sotfware. when i upload the program and transfered the code and the LEDs on the arduino nano has stopped flashing rapedly. I get this message: 

Binary sketch size: 9*380 bytes (of a 30*720 byte maximum)
avrdude: verification error, first mismatch at byte 0x0000
0x0c != 0xff
avrdude: verification error; content mismatch


And in the line over; Done uploading. 
Use win 8.1 64. 

But the arduino is still brain dead.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> No logic converter being used on the Flyduino. The voltage levels I measured are straight off the module. I had it connected exactly the same way as the cheapies.
> 
> With the Bluetooth modules, some are 3.3v Vcc & should have a converter. Both mine are this type. Some others can take 5v Vcc but I am not sure about rx input from the arduino.


I think you are better off with the cheapies. They work and are cheaper.


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> I have problems with arduino sotfware. when i upload the program and transfered the code and the LEDs on the arduino nano has stopped flashing rapedly. I get this message:
> 
> Binary sketch size: 9*380 bytes (of a 30*720 byte maximum)
> avrdude: verification error, first mismatch at byte 0x0000
> ...


Did you select Arduino Nano as your board in the IDE? If yes, then I think the flash memory in the nano is defective. Try loading a simple sketch like the blink LED sample program.


----------



## electricpolo (Mar 15, 2011)

Been having a really close look at the Flyduino MPU6050. 
Apart from the voltage regulator, it actually has a level converter built onto the board which is why it is 5V on the SDA & SCL outputs. 
I can measure 3.3V on the chip output pins.


----------



## mariov (May 22, 2014)

Success !, the level converter did the trick, 
thank you Electricpolo and Oval 
moving to next step



mariov said:


> No it doesn't find it, i checked the circuit and i have two different BT modules and none of them are detected
> 
> I soldered the new pin, so now the Key pin is the RX pin?
> No resistors?
> ...


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Been having a really close look at the Flyduino MPU6050.
> Apart from the voltage regulator, it actually has a level converter built onto the board which is why it is 5V on the SDA & SCL outputs.
> I can measure 3.3V on the chip output pins.


Try adding 4.7K pull-up resistors (to +5V) on the SDA and SCL pins.


----------



## electricpolo (Mar 15, 2011)

4k7 resistors didn't work. The Flyduino has 1K pullup resistors on it + the 10K on the Mega itself makes 910 ohms pullup total. Adding the 4K7 dropped the resistance to 750 ohms

I am starting to think these Flyduino boards are a white elephant  because the cheapies work fine.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> 4k7 resistors didn't work. The Flyduino has 1K pullup resistors on it + the 10K on the Mega itself makes 910 ohms pullup total. Adding the 4K7 dropped the resistance to 750 ohms
> 
> I am starting to think these Flyduino boards are a white elephant  because the cheapies work fine.


1K is too small. You can try replacing them with 4K7 if your eyesight is good .


----------



## electricpolo (Mar 15, 2011)

I did exactly that but still no go. I have scrapped them now. Not worth the time. 
Have got a couple of new generic MPU6050s on the way. Problem solved.


----------



## electricpolo (Mar 15, 2011)

Have come across a curious phenomenon with my new bluetooth module.
It's a 3.3V module connected to my new Mega via a level converter.
Running the bluetooth detect sketch finds the bluetooth module with no problem.
I can change the baud rate by defining the baud rate from 9600 to 115200 and back again with no problem & it shows the new baud rate when I rerun the sketch.
Next, I run the clone sketch first in calibrate then run mode. Serial monitor output is as I expect.
When I go to connect bluetooth, the app shows Discovered HC-06 & doesn't connect. For some reason the clone code isn't changing the name.

The original 3.3V bluetooth module connected via the same level converter to my Nano would change the name to SEGWAY & the app would connect. Just wouldn't do anything because of the software serial issue hence the Mega. 
Any ideas?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Have come across a curious phenomenon with my new bluetooth module.
> It's a 3.3V module connected to my new Mega via a level converter.
> Running the bluetooth detect sketch finds the bluetooth module with no problem.
> I can change the baud rate by defining the baud rate from 9600 to 115200 and back again with no problem & it shows the new baud rate when I rerun the sketch.
> ...


I have made the assumption that the HC06 is out-of-the-box. Hence, the name is changed to SEGWAY only at 9600.

Using the DetectBluetooth program, set the speed back to 9600 (this is the out-of-the-box baud-rate setting). Then run the SegwayClone in calibrate mode. Then you can change it back to run mode.


----------



## electricpolo (Mar 15, 2011)

For reasons unknown, the code wasn't renaming the HC-06 module or changing the baud rate either.
I got around it by manually changing the baud rate to 115200 & manually changing the name to SEGWAY.
I reran the clone code & tried to connect my tablet. The Console found 'SEGWAY' & connected straight away. 
All the telemetry is working fine & I could see the remote control screen making changes in the serial monitor.
Changing the P & D settings seemed to work fine & changes saved immediately.
Looking good now.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo,
Good to hear! Any videos yet?


----------



## electricpolo (Mar 15, 2011)

No videos just yet. 
Progress is here http://www.diyelectriccar.com/forums/showthread.php/electricpolo-segway-clone-build-95729p3.html .
I've been working on getting the Mega & the bluetooth working at the moment & I have the code configured for 1 x MPU for the bluetooth bench testing.
Just waiting for the new IMU's to arrive then I'll fit the electronics back in and see what happens. Will take some videos then.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> I'm guessing you damaged the PCB trace when you unsoldered the original connectors. These multi-layered PCBs are easy to damage. I would recommend using a stackable protoyping board and soldering your clip-on connectors there.



Hi Oval, here again .. 

I've released a new mega Aduino. 

Run DetectBluetooth_v1.0 and the result was: see photo 










According to the above is not the fault of the arduino mega, Oval has light that is failing? 
*
Thank you.


----------



## electricpolo (Mar 15, 2011)

Troubleshooting steps.
If it is a 3.3V bluetooth module make sure you use a level converter to connect module to the mega.
If it is a 5V bluetooth module make sure you either use a level converter or a resistor divider on the module RX pin when you connect to the mega.
Connect the level converter to pin 14 (TX3) & pin 15 (RX3) on the Mega.
Make sure RX on module goes to TX on Mega & TX on module goes to RX on Mega.
The DetectBluetooth does work just like it is supposed to.


----------



## ferchotech (May 29, 2014)

electricpolo said:


> Troubleshooting steps.
> If it is a 3.3V bluetooth module make sure you use a level converter to connect module to the mega.
> If it is a 5V bluetooth module make sure you either use a level converter or a resistor divider on the module RX pin when you connect to the mega.
> Connect the level converter to pin 14 (TX3) & pin 15 (RX3) on the Mega.
> ...




Hi, Electricpolo. I have bluetooth 5V.
I connected 1.8K and 3.3K resistors equal to the scheme Oval. 
Rx-Tx 
and
Tx-Rx 
The bluetooh I have tested and is good ... Any idea? .. Thanks


----------



## electricpolo (Mar 15, 2011)

Couple of photos of your test setup would be helpful.
How have you tested the bluetooth module?
See post #763. The sketches there are also very useful for troubleshooting.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> Make sure batteries are disconnected. Load the following sketch and run the Serial Monitor at 115200. Press the reset button on the Arduino. You should get an output like *OKlinvorV1.x*.
> 
> ```
> void setup() {
> ...



Run code. but nothing comes on monitorserial


----------



## electricpolo (Mar 15, 2011)

If you have a new Mega and you have connected the bluetooth module correctly and the sketches don't detect the module, then I would suggest that your bluetooth module is either dead or faulty.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi, Oval
> 
> Change the HC-06, then test with arduino1 and this was good. The arduino mega serial port is not communicating.
> 
> ...


I am quite confused. Did you try a different HC06 and it worked? And your conclusion was that the Mega is defective? As electricpolo said, it seems the HC06 is the problem.


----------



## mariov (May 22, 2014)

I had the same issue, had the correct resistors, no luck, i replaced the resistors with variable ones and experimented with different values +- 5% still no luck, i followed electricpolo advise and bought the level converter and it worked like a charm



ferchotech said:


> Run code. but nothing comes on monitorserial


----------



## electricpolo (Mar 15, 2011)

ferchotech,
Perhaps the RX output of the module is not quite high enough for the Mega to see it as High although in theory it should be fine.
Get a level converter & see what happens. They are pretty cheap and, at this stage, you have nothing to lose.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech,
I've just changed the schematics. I have replaced the resistor divider from 3.3K & 1.8K to 22K and 10K. Give this a try. If it doesn't work, follow electricpolo's advice and get a level converter.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> ferchotech,
> I've just changed the schematics. I have replaced the resistor divider from 3.3K & 1.8K to 22K and 10K. Give this a try. If it doesn't work, follow electricpolo's advice and get a level converter.


Hi everyone .. 

Oval, I think I found the problem: 

I have Bluetooth JY-MCU v1.06, the tx paw bluethooth should put pull-up tx. 

View: 

http://mcuoneclipse.com/2014/03/30/getting-bluetooth-working-with-jy-mcu-bt_board-v1-06/ 

could you please help with the pull-up program for tx. I have not had success. 

Greetings ...


----------



## electricpolo (Mar 15, 2011)

You could always just get one of these http://www.ebay.com.au/itm/151155425672?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649 .
This is where mine came from & they work fine with a level converter (3.3V module).
Perhaps Oval can post where he got his 5V modules from as well.


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi everyone ..
> 
> Oval, I think I found the problem:
> 
> ...


Attach a 10K resistor from Arduino RX3 to +5V.


----------



## mariov (May 22, 2014)

Guys i'm trying to implement the riders switch but is not working for me, I'm using this scheme to pull the pin high. I'm using a 10K resistor, but not working.
Any advice?

Thanks


----------



## mariov (May 22, 2014)

Not quite there yet but this is a video of my prototype http://youtu.be/uAz3cE0D16U
Still trying to tune up the PID


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> Guys i'm trying to implement the riders switch but is not working for me, I'm using this scheme to pull the pin high. I'm using a 10K resistor, but not working.
> Any advice?
> 
> Thanks


You must pull it HIGH when rider is ON and pull it LOW when rider is OFF. Can you post your schematic for the sensor?


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> Not quite there yet but this is a video of my prototype http://youtu.be/uAz3cE0D16U
> Still trying to tune up the PID


Well done! Are you planning to get a pet lizard to drive it ? The PID looks good already. Time to move up to the BIG clone .


----------



## Ovaltineo (Jul 18, 2013)

Ovaltineo said:


> Attach a 10K resistor from Arduino RX3 to +5V.


Alternatively, you can also try adding digitalWrite(15, HIGH) after each Serial3.begin() statement.


----------



## electricpolo (Mar 15, 2011)

Hi mariov


> Uncomment if you have a rider sensor - sensor must pull this pin HIGH when rider is ON, and pull it LOW when rider is OFF
> Initial values are loaded from KP_OFF, KD_OFF, and MOTOR_MAX_OFF.
> */
> #define RIDER_SENSOR 13
> ...


I had similar problems until I changed the line RIDER_SENSOR 13 to RIDER_SENSOR 4 in SegwayClone.h but you can use any unused digital pin you like.
I connected the sensor to pin 4 and voila, the sensor was changing the KP & KD values.

The INVERT_RIDER_SENSOR also works fine. It just depends on you sensor type. 
Mine needed Invert Sensor because they are normally high & go low when a rider is on the clone platform.


----------



## ferchotech (May 29, 2014)

mariov said:


> Not quite there yet but this is a video of my prototype http://youtu.be/uAz3cE0D16U
> Still trying to tune up the PID


looks great, Congratulations


----------



## adamson (Mar 2, 2014)

How should I do external reset button to arduino mega?


----------



## adamson (Mar 2, 2014)

This is how cloneconsole works without lever converter and without resistors
How cloneconsole works: 
http://youtu.be/aMmsMoAEhfc


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> How should I do external reset button to arduino mega?


The button would simply connect reset pin to ground.


----------



## Ovaltineo (Jul 18, 2013)

Ovaltineo said:


> Alternatively, you can also try adding digitalWrite(15, HIGH) after each Serial3.begin() statement.



ferchotech,

Did this or the 10K resistor to RX3 work?


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> ferchotech,
> 
> Did this or the 10K resistor to RX3 work?


Hi Oval 

external R10K: 











But segwayclone not change the name to bluethooth and clonconsole not connected.


----------



## ferchotech (May 29, 2014)

ferchotech said:


> Hi Oval
> 
> external R10K:
> 
> ...



Hi, Oval. 

It worked well ... 

Serial3.begin change to (9600); and éxtito ...


----------



## Ovaltineo (Jul 18, 2013)

It is actually too slow at 9600.

You should load the program with CALIBRATE_MODE defined. This will set the correct baud rate (115200) and set the name to SEGWAY. Afterwards, you can load the program with the CALIBRATE_MODE removed.


----------



## electricpolo (Mar 15, 2011)

ferchotech
I had to change the baud rate and the name manually. For some reason, the code wouldn't do it with my new module. 
After the manual name change it seems to work perfectly with CloneConsole.


----------



## mariov (May 22, 2014)

I'm almost ready to start testing the real clone but i'm unable to implement the rider sensor. This is the circuit i'm using and i tested it in the small scale version and it worked, but not now, not sure what is going on.

I enabled rider sensor but even if i invert there is no difference in the system so something must be wrong even beyond the resistors. Appreciate any help


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> I'm almost ready to start testing the real clone but i'm unable to implement the rider sensor. This is the circuit i'm using and i tested it in the small scale version and it worked, but not now, not sure what is going on.
> 
> I enabled rider sensor but even if i invert there is no difference in the system so something must be wrong even beyond the resistors. Appreciate any help



As electricpolo suggested, try using pin 4 instead of pin 13. 

I have also just released SegwayClone v5.7 and CloneConsole v2.0. The GRAY and WHITE screens will show the RIDER_SENSOR state.


```
v5.7
Added software low-pass filter for voltage sensor.
Added support for HX711 weight sensor.
Added RIDER_SENSOR to telemetry sent to CloneConsole.
Added baud rate detection with bluetooth module.

v2.0
Added RIDER_SENSOR support - screen is GRAY when rider is OFF and WHITE when rider is ON. P and D will be updated to OFF and ON values.
```


----------



## mariov (May 22, 2014)

Cool!, i'm going to try it right away
Thanks for your really talented work


----------



## ferchotech (May 29, 2014)

Hi Oval, hc-06 works great with internal resistors up "digitalWrite (15, HIGH) after each Serial3.begin ()"


----------



## mariov (May 22, 2014)

i wonder why the motors keep on accelerating eventhought everything seems to be well calibrated.

take a look at the serial monitor dump

WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
Try 115200
Found bluetooth module at 115200
ACCEL: 0.03 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.00 MOTOR: 1.01 LEFT: 1 RIGHT: 1
ACCEL: -0.04 GYRO: 0.00 BOARD ANGLE: 0.06 STEER ANGLE: 0.00 MOTOR: 8.24 LEFT: 8 RIGHT: 8
ACCEL: 0.11 GYRO: 0.00 BOARD ANGLE: 0.09 STEER ANGLE: 0.00 MOTOR: 22.87 LEFT: 22 RIGHT: 22
ACCEL: 0.03 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.00 MOTOR: 43.03 LEFT: 43 RIGHT: 43
ACCEL: 0.15 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.00 MOTOR: 67.20 LEFT: 67 RIGHT: 67
ACCEL: 0.24 GYRO: 0.00 BOARD ANGLE: 0.10 STEER ANGLE: 0.00 MOTOR: 88.03 LEFT: 88 RIGHT: 88
ACCEL: 0.31 GYRO: 0.00 BOARD ANGLE: 0.10 STEER ANGLE: 0.23 MOTOR: 107.53 LEFT: 101 RIGHT: 113
ACCEL: 0.10 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.00 MOTOR: 128.19 LEFT: 128 RIGHT: 128
ACCEL: -0.20 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.00 MOTOR: 150.00 LEFT: 149 RIGHT: 149
ACCEL: 0.14 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.00 MOTOR: 171.55 LEFT: 171 RIGHT: 171
ACCEL: 0.20 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.00 MOTOR: 193.47 LEFT: 193 RIGHT: 193
ACCEL: 0.03 GYRO: 0.00 BOARD ANGLE: 0.12 STEER ANGLE: 0.00 MOTOR: 216.17 LEFT: 216 RIGHT: 216
ACCEL: 0.42 GYRO: 0.00 BOARD ANGLE: 0.12 STEER ANGLE: 0.00 MOTOR: 239.74 LEFT: 239 RIGHT: 239
ACCEL: 0.21 GYRO: 0.00 BOARD ANGLE: 0.12 STEER ANGLE: 0.00 MOTOR: 263.12 LEFT: 263 RIGHT: 263
ACCEL: 0.08 GYRO: 0.00 BOARD ANGLE: 0.14 STEER ANGLE: 0.00 MOTOR: 288.15 LEFT: 288 RIGHT: 288
ACCEL: 0.07 GYRO: 0.00 BOARD ANGLE: 0.13 STEER ANGLE: 0.00 MOTOR: 314.39 LEFT: 314 RIGHT: 314
ACCEL: -0.01 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.23 MOTOR: 338.00 LEFT: 332 RIGHT: 343
ACCEL: 0.36 GYRO: 0.00 BOARD ANGLE: 0.09 STEER ANGLE: 0.00 MOTOR: 357.02 LEFT: 357 RIGHT: 357
ACCEL: 0.35 GYRO: 0.00 BOARD ANGLE: 0.07 STEER ANGLE: 0.00 MOTOR: 372.29 LEFT: 372 RIGHT: 372
ACCEL: 0.13 GYRO: 0.00 BOARD ANGLE: 0.07 STEER ANGLE: 0.00 MOTOR: 386.17 LEFT: 386 RIGHT: 386
ACCEL: 0.27 GYRO: 0.00 BOARD ANGLE: 0.07 STEER ANGLE: 0.00 MOTOR: 399.47 LEFT: 399 RIGHT: 399
ACCEL: -0.21 GYRO: 0.00 BOARD ANGLE: 0.10 STEER ANGLE: 0.23 MOTOR: 416.46 LEFT: 410 RIGHT: 422
ACCEL: 0.17 GYRO: 0.00 BOARD ANGLE: 0.12 STEER ANGLE: 0.00 MOTOR: 437.85 LEFT: 437 RIGHT: 437
ACCEL: 0.32 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.00 MOTOR: 460.89 LEFT: 460 RIGHT: 460
ACCEL: -0.14 GYRO: 0.00 BOARD ANGLE: 0.10 STEER ANGLE: 0.00 MOTOR: 480.81 LEFT: 480 RIGHT: 480
ACCEL: -0.03 GYRO: 0.00 BOARD ANGLE: 0.10 STEER ANGLE: 0.00 MOTOR: 500.83 LEFT: 500 RIGHT: 500
ACCEL: 0.06 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.23 MOTOR: 521.51 LEFT: 515 RIGHT: 527
ACCEL: -0.08 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 0.23 MOTOR: 544.05 LEFT: 538 RIGHT: 549
ACCEL: 0.18 GYRO: 0.00 BOARD ANGLE: 0.10 STEER ANGLE: 0.00 MOTOR: 565.35 LEFT: 565 RIGHT: 565
ACCEL: 0.11 GYRO: 0.00 BOARD ANGLE: 0.12 STEER ANGLE: 0.00 MOTOR: 587.19 LEFT: 587 RIGHT: 587
ACCEL: -0.03 GYRO: 0.00 BOARD ANGLE: 0.14 STEER ANGLE: 0.00 MOTOR: 612.87 LEFT: 612 RIGHT: 612
ACCEL: 0.32 GYRO: 0.00 BOARD ANGLE: 0.12 STEER ANGLE: 0.23 MOTOR: 638.76 LEFT: 632 RIGHT: 644
ACCEL: 0.24 GYRO: 0.00 BOARD ANGLE: 0.12 STEER ANGLE: 0.23 MOTOR: 662.41 LEFT: 656 RIGHT: 668
ACCEL: -0.31 GYRO: 0.00 BOARD ANGLE: 0.12 STEER ANGLE: 0.00 MOTOR: 685.50 LEFT: 685 RIGHT: 685
ACCEL: 0.32 GYRO: 0.00 BOARD ANGLE: 0.10 STEER ANGLE: 0.23 MOTOR: 706.94 LEFT: 701 RIGHT: 712
ACCEL: 0.06 GYRO: 0.00 BOARD ANGLE: 0.09 STEER ANGLE: 0.23 MOTOR: 726.24 LEFT: 720 RIGHT: 732
ACCEL: -0.18 GYRO: 0.00 BOARD ANGLE: 0.09 STEER ANGLE: 0.00 MOTOR: 744.06 LEFT: 744 RIGHT: 744
ACCEL: 0.22 GYRO: 0.00 BOARD ANGLE: 0.09 STEER ANGLE: 0.00 MOTOR: 762.85 LEFT: 762 RIGHT: 762
ACCEL: -0.17 GYRO: 0.00 BOARD ANGLE: 0.09 STEER ANGLE: 0.23 MOTOR: 780.90 LEFT: 775 RIGHT: 786
ACCEL: -0.13 GYRO: 0.00 BOARD ANGLE: 0.13 STEER ANGLE: 0.00 MOTOR: 803.23 LEFT: 803 RIGHT: 803


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> Hi Oval, hc-06 works great with internal resistors up "digitalWrite (15, HIGH) after each Serial3.begin ()"


So this works with no external 10K resistor to RX3? If yes, I will add it to the code.


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> i wonder why the motors keep on accelerating eventhought everything seems to be well calibrated.
> 
> take a look at the serial monitor dump
> 
> ...


I have explained this too many times in this thread . This is normal behavior if the wheels are not touching the ground to provide feedback to the PID loop.


----------



## mariov (May 22, 2014)

ok, thanks sorry for the lame question then


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> ok, thanks sorry for the lame question then


No, not your fault. This thread is too long for newcomers to read through. I might start a new thread with an FAQ at the beginning.


----------



## mariov (May 22, 2014)

I'm using pin 4 but it only works if i remove the ground connection, but is unstable, just having my hand close to the switch it enables it, is some sort of field effect.
Also when i step down it stays enabled for a few seconds, so essentially is not working




Ovaltineo said:


> As electricpolo suggested, try using pin 4 instead of pin 13.
> 
> I have also just released SegwayClone v5.7 and CloneConsole v2.0. The GRAY and WHITE screens will show the RIDER_SENSOR state.
> 
> ...


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> I'm using pin 4 but it only works if i remove the ground connection, but is unstable, just having my hand close to the switch it enables it, is some sort of field effect.
> Also when i step down it stays enabled for a few seconds, so essentially is not working


I've just released v5.8 to address your situtation. This relase inverts the RIDER_SENSOR logic, so those using INVERT_RIDER_SENSOR must remove it and vice-versa.

This simplifies the use of a switch as a rider sensor. Simply pull the RIDER_SENSOR to ground when the rider is ON and leave it open when the rider is OFF.


----------



## electricpolo (Mar 15, 2011)

What sort of switch are you using for the sensor?
Plain on/off switch, IR sensor or weight sensor.
My IR sensors (2 of them using pins 4 & 5) have 5V + & - supplied by the Arduino & the output goes to pin 4 or 5. 
Don't have any issues at all & works as expected.
Can you post a schematic and/or some pics so we can see what is going on.


----------



## mariov (May 22, 2014)

Worked like a charm!
Thanks




Ovaltineo said:


> I've just released v5.8 to address your situtation. This relase inverts the RIDER_SENSOR logic, so those using INVERT_RIDER_SENSOR must remove it and vice-versa.
> 
> This simplifies the use of a switch as a rider sensor. Simply pull the RIDER_SENSOR to ground when the rider is ON and leave it open when the rider is OFF.


----------



## mariov (May 22, 2014)

Just tested the clone, worked acceptably good. It seems the parameters are too conservative, when i confronted a minimum slope the motor max alarm triggered and the system just gave in. I'm considering enabling push back. But i wonder how the motor_max number is defined, in my case 1,500 since i have the roboclaw, but the motor was not near max when the alarm triggered.
I will connect and amperimeter to see when the motor is close to it's max amps (10.5A since it is a 250W motor at 24V)


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> Just tested the clone, worked acceptably good. It seems the parameters are too conservative, when i confronted a minimum slope the motor max alarm triggered and the system just gave in. I'm considering enabling push back. But i wonder how the motor_max number is defined, in my case 1,500 since i have the roboclaw, but the motor was not near max when the alarm triggered.
> I will connect and amperimeter to see when the motor is close to it's max amps (10.5A since it is a 250W motor at 24V)


1500 is the maximum power/speed in advanced motor control command for the Roboclaw - it can't go beyond that. What is the size of your wheels and what gear ratio do you have? 250W may not be powerful enough.


----------



## mariov (May 22, 2014)

The wheel diameter is 40cm, the ratio i don't know, yes i know i need bigger motors, but i'm not sure which ones and how big


----------



## electricpolo (Mar 15, 2011)

I think 250W is too small. You will have to gear it down heaps to get enough torque & then your top speed will suffer badly.
Even a 250W motor can pull 80A given the right controller, heavy cables & batteries that can supply the current.
The ratio one of us can help you with.
Are your motors the geared type?
How many teeth does your motor sprocket have?
How many teeth does your wheel sprocket have?
Post a picture or two of your drive train.


----------



## mariov (May 22, 2014)

The thing is that i'm basically replacing the electronics of a chinese clone, here it is. But it seems i will have to start from scratch if i can't use the motors














electricpolo said:


> I think 250W is too small. You will have to gear it down heaps to get enough torque & then your top speed will suffer badly.
> Even a 250W motor can pull 80A given the right controller, heavy cables & batteries that can supply the current.
> The ratio one of us can help you with.
> Are your motors the geared type?
> ...


----------



## electricpolo (Mar 15, 2011)

Which RoboClaw do you have & wha is Ah rating of the batteries?


----------



## mariov (May 22, 2014)

Roboclaw dual 30A and batteries 12Ah, but i have four now, 2 + 2 in parallel, so i have 24Ah




electricpolo said:


> Which RoboClaw do you have & wha is Ah rating of the batteries?


----------



## electricpolo (Mar 15, 2011)

A 250W on 24V motor draws around 10.5A at rated load but can easily draw 80A at stall or close to it.
Your batteries are good for it but I think it was your RoboClaw that cut out, not the clone software.
The software only sends commands out to the controller to go to 100%, 50% or whatever & the alarm will sound when you approach MOTOR_MAX but that is all that it does. 
The clone software only cuts output to the controller if you exceed the maximum board angles.

Your RoboClaw can do 30A continuous & 60A peak. With the current firmware, the controller will cut out if you exceed 60A on either channel.
It will then need to be powered off then back on to reset it.

I have posted a beta version of the new IonMotion software for the RoboClaw that Nathan from Orion Robotics sent me. You can drive the controller from your PC, change the controller parameters and also update the firmware semi automatically.
The new firmware does not cutout the controller at max current but clips the current instead (until thermal overload kicks in)

Note. Don't try using the software to update the firmware using a notebook as it probably wont work. 
IonMotion gets confused when searching for USB ports as most notebooks have an IR port as a USB port. Desktop PC works 100% for the firmware update.
Notebooks work fine when using the software in normal mode though.


----------



## mariov (May 22, 2014)

Thank you!
I will try it tomorrow, it seems it is better to replace it with a dual 60A?.
I'm considering upgrading the motors as well, any recommendation that you can give me?




electricpolo said:


> A 250W on 24V motor draws around 10.5A at rated load but can easily draw 80A at stall or close to it.
> Your batteries are good for it but I think it was your RoboClaw that cut out, not the clone software.
> The software only sends commands out to the controller to go to 100%, 50% or whatever & the alarm will sound when you approach MOTOR_MAX but that is all that it does.
> The clone software only cuts output to the controller if you exceed the maximum board angles.
> ...


----------



## electricpolo (Mar 15, 2011)

Have posted a build update with some more pics http://www.diyelectriccar.com/forums/showthread.php?p=416306#post416306

mariov,
As to whether you need a 2x60A RoboClaw depends. I think you are going to keep maxing out the 2x30A with your 250W motors although the new firmware will help. The 2x60A would give you much greater headroom. 
You would certainly need the 2x60A if you went with bigger motors.

You current motor gearbox arrangement seems pretty good. The big problem would be finding motors that would fit into the gearbox.
If the current motors have a fairly high RPM & gearbox has a fairly high reduction ratio, you may find that they will be OK if you feed them with enough juice.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> So this works with no external 10K resistor to RX3? If yes, I will add it to the code.


Hi, Oval. If confirmed, hc-06 functioning properly UNUSED R-10K external. I'm on vacation ...
Greetings.


----------



## mariov (May 22, 2014)

Tried the new firmware, it improved but still the performance is really poor.
I bought the 2x60A HV, maybe i buy 36 or 48V motors




electricpolo said:


> A 250W on 24V motor draws around 10.5A at rated load but can easily draw 80A at stall or close to it.
> Your batteries are good for it but I think it was your RoboClaw that cut out, not the clone software.
> The software only sends commands out to the controller to go to 100%, 50% or whatever & the alarm will sound when you approach MOTOR_MAX but that is all that it does.
> The clone software only cuts output to the controller if you exceed the maximum board angles.
> ...


----------



## electricpolo (Mar 15, 2011)

Make sure the cables between your batteries and from the batteries to the controller are quite heavy. These cables carry the current for both motors so they need to be double the size of the motor cables. Keep all the cables as short as possible.
See if that makes a difference.


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> Just tested the clone, worked acceptably good. It seems the parameters are too conservative, when i confronted a minimum slope the motor max alarm triggered and the system just gave in.


What do you mean by "gave in"? Did the motors stop and you have to power off/on to reset? Or did it just tip over and recovered when you got it upright? The former means your controller went over peak current and shutdown. The latter means your motors don't have enough power to climb an incline and keep the clone balanced.

I don't think your motor controller is the problem. 40 cm (16-inch) wheels with 250W motors tells me that it won't have enough torque to pull the lid from a yoghurt tub , let alone go up an incline. 

I have 500W motors and haven't been able to trip my 15A (per motor) circuit breakers despite going up a very steep hill.


----------



## Borc (Mar 12, 2014)

The other time I was testing the clone on a slope (quite heavy). With Sabertooth 2x25A V2.0 and geared wheelchair motors (1/24) 300W, I was able to break 30A circuit breaker which is in series with each motor. Strange feeling when one side of the clone just left the position and next second you are 90 degrees off course. I guess that peak power was then around 650W.


----------



## mariov (May 22, 2014)

Just found the specs of a motor that seems the same one and it says it is 350W on 24V and 500W on 36V.
In any case something is not working right when lean forward and gain some some speed (minimal) it produces a grrrrrr sound and tips over and then immediately recovers. I know the motors can perform 10 times better because i have the original chinese electronics and it performs much better.
Checked the cables shortened them as much as possible but nothing really changed.



Ovaltineo said:


> What do you mean by "gave in"? Did the motors stop and you have to power off/on to reset? Or did it just tip over and recovered when you got it upright? The former means your controller went over peak current and shutdown. The latter means your motors don't have enough power to climb an incline and keep the clone balanced.
> 
> I don't think your motor controller is the problem. 40 cm (16-inch) wheels with 250W motors tells me that it won't have enough torque to pull the lid from a yoghurt tub , let alone go up an incline.
> 
> I have 500W motors and haven't been able to trip my 15A (per motor) circuit breakers despite going up a very steep hill.


----------



## electricpolo (Mar 15, 2011)

Have you tried running the motors via the IonMotion software?


----------



## electricpolo (Mar 15, 2011)

Hi Oval
What controllers are you using with the Dayton motors?
Having no end of trouble with my RoboClaw. Just blew up a second time on the bench.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval
> What controllers are you using with the Dayton motors?
> Having no end of trouble with my RoboClaw. Just blew up a second time on the bench.


I'm using 2 X BTS7960 modules. I found out that they are not all the same. The ones I listed on post #684 (reproduced below) are the ones to get. Buy 4 so you have a couple of backups. Also, attach 6cm x 6cm fan to each module.



Ovaltineo said:


> Ironically, the original one with ALFS-TECH.taobao.com written on the circuit board has a smaller heatsink and only 25V capacitor -- avoid it.
> 
> Each item below is the BTS7960B module with bigger heatsink and 35V capacitor.
> 
> ...


----------



## mariov (May 22, 2014)

Yes, but i haven't seen much difference, not really sure what is going on, i will try to measure current tonight, i will connect the amp meter where the fuse goes 



electricpolo said:


> Have you tried running the motors via the IonMotion software?


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> Yes, but i haven't seen much difference, not really sure what is going on, i will try to measure current tonight, i will connect the amp meter where the fuse goes


Please post your Motors.h and SegwayClone.h. It might be just a configuration issue.


----------



## mariov (May 22, 2014)

Ovaltineo said:


> Please post your Motors.h and SegwayClone.h. It might be just a configuration issue.


here are the links to the config files
Thanks


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> here are the links to the config files
> Thanks


Disable PUSHBACK and let us know how it goes.


----------



## mariov (May 22, 2014)

Ovaltineo said:


> Disable PUSHBACK and let us know how it goes.


Disabled push back but not perceivable difference.
Added two batteries in parallel so in theory the batteries can provide up to 24A (2x12Ah) but the system never surpasses 10A
With the Chinese system i blew a 50A fuse when i was riding it in the lawn


----------



## electricpolo (Mar 15, 2011)

Your batteries can supply heaps more than 24A for a short period. 24Ah just means that they can sustain a theoretical 24A discharge for 1 hour or a 1A discharge for 24 hours.

It is sounding like a motor controller problem. The system only tells the controller to go to 400, 750, 1500 or whatever.
In the Serial Monitor, are you seeing the motor output going up to 1500 as you tilt the machine one way, go back to zero as you come back to level & then the motor output going to -1500 as you keep tilting further back?

You can have the actual motors disconnected from the controller or the controller disconnected from the Arduino or just suspend the scooter of the ground a bit while you do this.


----------



## mariov (May 22, 2014)

electricpolo said:


> Your batteries can supply heaps more than 24A for a short period. 24Ah just means that they can sustain a theoretical 24A discharge for 1 hour or a 1A discharge for 24 hours.
> 
> It is sounding like a motor controller problem. The system only tells the controller to go to 400, 750, 1500 or whatever.
> In the Serial Monitor, are you seeing the motor output going up to 1500 as you tilt the machine one way, go back to zero as you come back to level & then the motor output going to -1500 as you keep tilting further back?
> ...


When i check the serial monitor they go up to 1,500 and -1,500 but when all the motors are connected the clone console shows 250 as the maximum.
Just realized I chose "normal" as the battery option, maybe that is the issue? Should i choose lead acid auto?


----------



## electricpolo (Mar 15, 2011)

In the IonMotion software under General Settings, make sure the Battery Cut Off is set to OFF.


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> When i check the serial monitor they go up to 1,500 and -1,500 but when all the motors are connected the clone console shows 250 as the maximum.
> Just realized I chose "normal" as the battery option, maybe that is the issue? Should i choose lead acid auto?


In CloneConsole, MOTOR_MAX is currently scaled to 255. So, 250 is close to maximum motor output. I will display the true value in a future version.

I can only suggest getting a pair of the BTS7960 modules I posted previously. It is driven directly by PWM, so it outputs what it is told.


----------



## mariov (May 22, 2014)

Ovaltineo said:


> In CloneConsole, MOTOR_MAX is currently scaled to 255. So, 250 is close to maximum motor output. I will display the true value in a future version.
> 
> I can only suggest getting a pair of the BTS7960 modules I posted previously. It is driven directly by PWM, so it outputs what it is told.


I replaced the roboclaw 2x30A with the 2x60A and it worked beautifully for 10 minutes, then all of a sudden it stopped working. Checked the error message on the roboclaw, driver error (mosfet burnt)

This is what the basic micro people said

"_Yes. I think you probably will need the HV board. The problem in a Segway like system is the PID will run the motors hard back and forth. You wont see it but it does it even in a well tuned PID. That pulls a lot more current which produces a lot more voltage spike. The spike can kill the mosfet drivers if its over the rating(50v). Send it in and we'll fix the drivers. As long as that's all that happened there wont be any additional charge and we'll upgrade you to the HV(just the price difference)._"


----------



## electricpolo (Mar 15, 2011)

My 2x60A RoboClaw is going back today and they will replace it with the HV version. 
It blew the mosfet drivers the first time then the mosfet drivers and a mosfet the second time.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> My 2x60A RoboClaw is going back today and they will replace it with the HV version.
> It blew the mosfet drivers the first time then the mosfet drivers and a mosfet the second time.


I really thought the Roboclaw was the Rolls Royce of low voltage speed controllers. I hope the HV version solves your problems. It is possible that HV spike is not the problem. I hope they have a built-in delay when switching directions. No delay means the high-side and low-side MOSFETs could be ON at the same time -- this will blow them.

For less than $15 each, the BTS7960 module sounds like a real bargain. I've killed a couple of them before - but those ones had the smaller heat sink and 25V capacitor. The ones with bigger heat sink (+ fan) and 35V capacitor are still going -- and I live in a very steep hill. I guess the BTS7960 is the poor man's Toyota .

I am actually trying to develop a sensorless speed detection for them using the available current sense pin. It will measure the motor current when the PWM is in the OFF stage. This current is proportinal to the motor speed. Sounds easy on paper but very difficult to implement .

For the Roboclaw, I will add temperature reading in a future version. It has a built-in sensor and just needs an API call.


----------



## mariov (May 22, 2014)

electricpolo said:


> My 2x60A RoboClaw is going back today and they will replace it with the HV version.
> It blew the mosfet drivers the first time then the mosfet drivers and a mosfet the second time.


They are replacing mine too, but i have to pay the cost difference


----------



## electricpolo (Mar 15, 2011)

I did a lot of looking around first & opted for the RoboClaw because it seemed to be the Lexus motor controller with encoder support. 
I didn't want to go with the Roboteq controllers. They really are the Rolls Royce with a price to match.
So far, I am less than impressed with the RoboClaw controller given that it has now cost me $265 with the latest return postage. I hope the new replacement one fixes all the issues.
I am seriously considering getting 4 of the BTS7960 module and ganging them in two pairs. The data sheet shows this can be done and it would double the current handling.
OK, doesn't have encoder support but given the problems to date ...


----------



## adamson (Mar 2, 2014)

BTS 7960 with 7970 with fan is working very good in my segclone. Oval I am waiting for your sensorless speed detection.


----------



## mariov (May 22, 2014)

I see that on Ebay the segway motors and gearboxes are not that expensive, i wonder if they need to be connected to a specific electronic circuitry or they could be adapted using the Arduino and roboclaw, the batteries might be an issue, anyone ever considered going that route?


----------



## Ovaltineo (Jul 18, 2013)

mariov said:


> I see that on Ebay the segway motors and gearboxes are not that expensive, i wonder if they need to be connected to a specific electronic circuitry or they could be adapted using the Arduino and roboclaw, the batteries might be an issue, anyone ever considered going that route?


The original Segway motors are 72V brushless DC motors. You need an expensive high voltage BLDC motor controller for this voltage.

You can drive it at reduced voltage, say 24V. There are RC car brushless controllers that maybe suitable. But you'll end up with a slow Segway.


----------



## electricpolo (Mar 15, 2011)

Was just about to post something similar about the motors.
It may be possible to adapt a brushed motor to a Segway gearbox though as long as the speed range was similar to original.
Also getting 72V would be a bit of a problem although it obviously can be done because Segway have.
You would need 6 SLA batteries or 22 Headway type cells in series or make up something yourself using a heap of lithium ion batteries.
The 72V requirement plus the brushless controller add up to something not very practical for a clone.


----------



## rajman2500 (Nov 30, 2013)

Hello guys 
I am Rajneesh from India. I am also interseted in making segway 

clone wheelchair. I am physical disabled.

I have these Equipment
Arduino Mega
1.Mpu 6050
Blutooth Hc-06
Joystick 
Sabetooth 2*60
Motor 2*500 Watt
Wheels 18inch

I want make someting like this video. so i can use it has my 

wheelchair.
https://www.youtube.com/watch?v=XWdBynlOsrg&list=UUSAYc6tQqc3J-X1ox73VYjA



Thanks
Rajneesh


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Have come up with a curious phenomenon with the encoder setup.
If I have 32000 as the encoder motor max, everything looks fine in the serial monitor with the motors varying between 32000 & -32000 with the forward direction being positive numbers.

If I have 33000 as the encoder motor max, the serial monitor shows the motors only going between 32536 & -32563. In addition, the direction is reversed. ie forward is now negative numbers.

If I have 35000 as the encoder motor max, the serial monitor shows the motors only going between 30536 & -30563. Direction reversed. 

If I have 37000 as the encoder motor max, the serial monitor shows the motors only going between 28536 & -28563. Direction reversed. 

If I have 40000 as the encoder motor max, the serial monitor shows the motors only going between 25536 & -25563. Direction reversed. 

Any suggestions apart from perhaps changing the encoder outputs to a lower resolution so the max pulses are less than 32000?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> Have come up with a curious phenomenon with the encoder setup.
> If I have 32000 as the encoder motor max, everything looks fine in the serial monitor with the motors varying between 32000 & -32000 with the forward direction being positive numbers.
> 
> ...


I think there is a bug in the code that will affect anything more than 32768. Try changing *int motorMax* to *long motorMax* in the loop() function. I will fix it in the next release if that works.


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hello guys
> I am Rajneesh from India. I am also interseted in making segway
> 
> clone wheelchair. I am physical disabled.
> ...


It will be difficult for a disabled person to get up and sit on a balancing wheelchair without help. Maybe something like hydraulic stands would be needed to keep it stable until the rider is seated.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,


> Try changing *int motorMax* to *long motorMax* in the loop() function.


Seem like that did the trick. Went right up to 44000 & the serial monitor showed everything as OK. Direction was correct & motors, left & right varied between 44000 & -44000.
My controller has arrived back in the US now. Should have the replacement RoboClaw here in a couple of weeks. 
Hope the new HV one fixes all the issues.
Although I have had some problems with the actual controller, their technical support is first class.


----------



## rajman2500 (Nov 30, 2013)

Ovaltineo said:


> It will be difficult for a disabled person to get up and sit on a balancing wheelchair without help. Maybe something like hydraulic stands would be needed to keep it stable until the rider is seated.


Yes Ovalineo you right. Iam thinking of using two actuators stands to keep it stable.

Thanks
Rajneesh


----------



## silveradoss1 (Sep 21, 2013)

Hi Ovaltineo, 

First off, I would like to thank you for all your hard Work. I have built a clone my self using your code, a pair of 500 watt power chair motors, arduino mega 2560, and dual 6050 , and a pair of the btn7970 motor controllers(68 amp).
To get to the point, would it be possible for you to add coding for the robot power OSMC motor controller. This guy has done something similar if it helps, "https://sites.google.com/site/onewheeledselfbalancing/Home/twin-wheel-self-balancing-skateboard-lightweight-version/code4". I think I'm going to try and use them. 
Thanks again for everything.


----------



## Ovaltineo (Jul 18, 2013)

silveradoss1 said:


> Hi Ovaltineo,
> 
> First off, I would like to thank you for all your hard Work. I have built a clone my self using your code, a pair of 500 watt power chair motors, arduino mega 2560, and dual 6050 , and a pair of the btn7970 motor controllers(68 amp).
> To get to the point, would it be possible for you to add coding for the robot power OSMC motor controller. This guy has done something similar if it helps, "https://sites.google.com/site/onewheeledselfbalancing/Home/twin-wheel-self-balancing-skateboard-lightweight-version/code4". I think I'm going to try and use them.
> Thanks again for everything.


Nice clone! Would you mind posting photos of the internals? I'd like to see ideas on the drivetrain and steering mechanism. It will be a few weeks before I can start looking at this because I'm currently working on a project for a friend. I also haven't finished the sensorless speed detection for the btn79 controller.


----------



## DK_Lex (Jul 17, 2014)

Ovaltineo said:


> Nice clone! Would you mind posting photos of the internals? I'd like to see ideas on the drivetrain and steering mechanism.


I agree with Ovaltineo. That clone looks awesome! I would appreciate the pictures of the internals as well.

What kind of wheels are these? Looks like BMX bicycle rims.

I'd like to build a segway clone myself, but having hard time choosing the wheels/sprockets/tires as I'd like it to be light, look good and resemble segway in some way, not by appearance, but from the standpoint of traction, stability, and speed (which is dependent on size of the wheel).

I think 17 to 20 wheels look the best.

Any advice from these who tried it would be appreciated.


----------



## electricpolo (Mar 15, 2011)

Have a look on this thread about my clone http://www.diyelectriccar.com/forums/showthread.php?p=440153#post440153
May help answer some of your questions and give you some ideas about the drivetrain & the steering.


----------



## silveradoss1 (Sep 21, 2013)

Hear are some more pictures of my work in progress. Just when you think you've got it just the way you want, You come up with the next great Idea. LOL!

The wheels are actually custom old Lester BMX wheel that I found on Ebay. They have a keyed bushing that was very close to fitting my keyed shaft outputs on the wheel chair motors. With a little shaving on the shafts with my mini lathe it was a perfect fit. (Vintage RARE NOS 1980's LESTER Laced Aluminum BMX Bike Wheel Pair OLD SCHOOL NEW) $96 shipped to USA. They still have one pair left as of today.

The steering is made up of a pair of sealed bearings(2"OD x 3/4"ID) and some torsion bushings for a Chevy truck. the design I have now is very nice but kind of Long. My body has the room, Barely.

The other day I came across a Segway leansteer frame shipped for under $100,
so I'm now in the process of adapting it to my clone. Again work in progress.


----------



## electricpolo (Mar 15, 2011)

So much good stuff on eBay in the US. Slim pickings here for things like that & the shipping to over here is $$$


----------



## DK_Lex (Jul 17, 2014)

electricpolo said:


> Have a look on this thread about my clone http://www.diyelectriccar.com/forums/showthread.php?p=440153#post440153
> May help answer some of your questions and give you some ideas about the drivetrain & the steering.


Electricpolo, that thread is in my favorites for a couple of weeks now. Great job sir! Thanks a bunch for sharing your ideas.


----------



## DK_Lex (Jul 17, 2014)

silveradoss1 said:


> Hear are some more pictures of my work in progress. Just when you think you've got it just the way you want, You come up with the next great Idea. LOL!


Thank you for the picts and explanation! Looks awesome. 

Google says Segway tires are 100/65-14. And the best fit is junior motorcycle tires. For these who still wonder, like me.


----------



## silveradoss1 (Sep 21, 2013)

I'm using kenda fire 20" x 3 " tires. They have a cool fire design for the tread.


----------



## markula (Oct 27, 2013)

Hi 

I have problems to fint ut the KP and KD setting. 
Here i have trided KP: 0.7 and KD: 0.47 and i can get it to stop oscilliates. 

What have you set the KP and KD to ? 
I use not rider sensor. 

I have a video that shows the problem. 
https://www.youtube.com/watch?v=kpVuTUv7o4I&feature=youtu.be

I have not installed the bletooth mobile device, is this something that is almost neseserly to set this vaues right ?


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> Hi
> 
> I have problems to fint ut the KP and KD setting.
> Here i have trided KP: 0.7 and KD: 0.47 and i can get it to stop oscilliates.
> ...


In general, you need to decrease KD and/or KP if it oscillates. However, oscillation will also occur if there is a slack in the drivetrain. I can hear clunking when the motor changes direction -- this maybe due to slack in the gear or chain drive. The long, heavy plank in your video can also have an adverse effect to the amplitude of the oscillation.

The bluetooth module + android allows you to change the KP and KD and see the changes immediately. It is infinitely better than changing KP and KD in the source code, compiling, and uploading - you may have to do this 100 times! The bluetooth module will be the best $7 you will ever spend .


----------



## mariov (May 22, 2014)

Guys, 
I'm selling a Roboclaw 2x60A HV (brand new) let me know if you are interested, I abandoned my project since it was very hard to do it in a condo and also i got an incredible deal on eBay and ended up buying an i2


----------



## rajman2500 (Nov 30, 2013)

Hi Ovalineo 
This my segway clone chair i am making. Can you add pot for foward & back function. so that i can use pot joystick to control segway clone.
Thanks 
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovalineo
> This my segway clone chair i am making. Can you add pot for foward & back function. so that i can use pot joystick to control segway clone.
> Thanks
> Rajneesh


I'm not sure how well it will work with a pot for forward & back function. This will be similar to the remote function of the CloneConsole app. Give it a go and let me know if it works.


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo
My bluetooth is not working . I have orderded Logic Level Converter and it will take atleast 20 days 
to come. Only then i can check with cloneConsole app.
Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovaltineo
> My bluetooth is not working . I have orderded Logic Level Converter and it will take atleast 20 days
> to come. Only then i can check with cloneConsole app.
> Thanks
> Rajneesh


I've released v5.9 for you.



> v5.9
> Fixed MAX_MOTOR for Roboclaw with encoder. Added support for forward/backward tilt control by defining POT_TILT_PIN.


----------



## rajman2500 (Nov 30, 2013)

Ovaltineo said:


> I've released v5.9 for you.


Wow Man u are very fast .
I will try new code tomorrow

Thanks
Rajneesh


----------



## electricpolo (Mar 15, 2011)

Hi Oval


> Fixed MAX_MOTOR for Roboclaw with encoder


What has been fixed or changed here?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval
> What has been fixed or changed here?


It's the same fix I told you to try in post #984.


----------



## electricpolo (Mar 15, 2011)

Thanks. Fixed it in my code a while ago.


----------



## adamson (Mar 2, 2014)

Is Steer_multiplier very important setting? (I use btn 7960)
I have drived segway a lot of time with 3.5 but my steer_multiplier is 0.04 (1:25)


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Is Steer_multiplier very important setting? (I use btn 7960)
> I have drived segway a lot of time with 3.5 but my steer_multiplier is 0.04 (1:25)


The steer multiplier adjusts the steering response. A higher value will make it turn with a little steering angle, a lower value will make it require a bigger steering angle.


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Wow Man u are very fast .
> I will try new code tomorrow
> 
> Thanks
> Rajneesh


How did it go?


----------



## rajman2500 (Nov 30, 2013)

Ovaltineo said:


> How did it go?


Sorry Ovaltineo
Still not checked. I will test today. busy with some other work.

Thanks
Rajneesh


----------



## adamson (Mar 2, 2014)

I've changed btn's and that's happening ( both was dead )
http://youtu.be/agtrx749iM8
At the end of film it goes at full speed without ballance and it is all the time.
Before changing btn it worked fine: 
http://youtu.be/ti8S56AqGpc
What do You think about it?


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo
I tried new code. Forward & back function not working with pot. Please check the program.

Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> I've changed btn's and that's happening ( both was dead )
> http://youtu.be/agtrx749iM8
> At the end of film it goes at full speed without ballance and it is all the time.
> Before changing btn it worked fine:
> ...


Do a bench test with the serial monitor going. Can you make the left and right output go negative and positive by tilting back and forth? Are motors going backwards and forwards accordingly?


----------



## adamson (Mar 2, 2014)

Serial monitor shows that everything is fine. Segway works fine for few seconds or minutes and rapidly gets crazy.


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovaltineo
> I tried new code. Forward & back function not working with pot. Please check the program.
> 
> Thanks
> Rajneesh


The center tap of the pot must be connected to A4. Does the platform change angle when you move the pot? Did you uncomment "#define POT_TILT_PIN A4" in SegwayClone.h?


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo
Yes i connected pot A4 and also uncomment "#define POT_TILT_PIN A4" in SegwayClone.h. but still not working

Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovaltineo
> Yes i connected pot A4 and also uncomment "#define POT_TILT_PIN A4" in SegwayClone.h. but still not working
> 
> Thanks
> Rajneesh


 Hmm, I think I found the problem - in SegwayClone.h, change the value of BOARD_OFFSET_DIVIDER from -70 to 1.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Serial monitor shows that everything is fine. Segway works fine for few seconds or minutes and rapidly gets crazy.


When it goes crazy, is the Serial monitor showing correct values?


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo
I have checked my clone with new value (-70 to 1 ) . Now my clone title foward & back but does not move forward or backward but need to test more.

Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovaltineo
> I have checked my clone with new value (-70 to 1 ) . Now my clone title foward & back but does not move forward or backward but need to test more.
> 
> Thanks
> Rajneesh


It will work if you stand or sit on it. A Segway needs a falling motion to move. By itself, it has a low center of gravity and won't "fall" - it will just balance in place. A person will raise the center of gravity and make it "fall" when tilted forwards or backwards.

By the way, you can reverse the direction of the movement by setting BOARD_OFFSET_DIVIDER to -1. You can also make it tilt more by making the value less than 1, e.g. 0.5 (or -0.5). You can reduce the tilt by increasing the value, e.g. 2 (or -2).


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo
There are two problem in my clone
1 Steering on joystick is very senstive 
2 One wheel is little fast (Motor Max 40 Right Wheel is on 40 & Lelft wheel on 38 ) 

Thanks 
Rajneesh


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo
There are two problem in my clone
1 Steering on joystick is very senstive 
2 One wheel is little fast (Motor Max 40 Right Wheel is on 40 & Lelft wheel on 38 ) 

Thanks 
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovaltineo
> There are two problem in my clone
> 1 Steering on joystick is very senstive
> 2 One wheel is little fast (Motor Max 40 Right Wheel is on 40 & Lelft wheel on 38 )
> ...


1. Reduce STEER_MULTIPLIER - see post #1009.
2. I have just released v6.0 to address centering using POT_STEERING. Modify POT_STEERING_ADJUST so that steer angle is zero (in Serial Monitor) when the steering pot is centered.


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo
Thanks for relasing version 6.0 (Modify POT_STEERING_ADJUST) Can u tell me how to modify 

so that steer angle is zero (in Serial Monitor) when the steering pot is centered. 

Thanks
Rajneesh


----------



## markula (Oct 27, 2013)

adamson said:


> I've changed btn's and that's happening ( both was dead )
> http://youtu.be/agtrx749iM8
> At the end of film it goes at full speed without ballance and it is all the time.
> Before changing btn it worked fine:
> ...


'

I have also problem with suddently full throttle forwards. I think you need 1k step down on each PWM signal to ground.


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovaltineo
> Thanks for relasing version 6.0 (Modify POT_STEERING_ADJUST) Can u tell me how to modify
> 
> so that steer angle is zero (in Serial Monitor) when the steering pot is centered.
> ...


Say X is the value of STEER_ANGLE in Serial Monitor when steering pot is centered. Set POT_STEERING_ADJUST to -X*STEER_MULTIPLIER.


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> '
> 
> I have also problem with suddently full throttle forwards. I think you need 1k step down on each PWM signal to ground.


Have you tried doing this and it works? 

I'm still waiting for *adamson* to respond to my question "When it goes crazy, is the Serial monitor showing correct values?" If the answer is YES, then the problem is probably the motor controllers. If the answer is NO, then the problem is probably the Arduino or DC-DC converter.


----------



## adamson (Mar 2, 2014)

I don't know what is wrong. Dc-dc is ok, serial monitor shows good values except full motor speed. And now I've changed also from mega to uno and it is even worse. Maybe it is because I've changed that everything is connected to one 5V pin?


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> I don't know what is wrong. Dc-dc is ok, serial monitor shows good values except full motor speed. And now I've changed also from mega to uno and it is even worse. Maybe it is because I've changed that everything is connected to one 5V pin?


Did you connect logic ground to BTN modules? You should only connect the battery ground, leave the logic ground unconnected.


----------



## adamson (Mar 2, 2014)

Logic ground wasn't and isn't connected.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Logic ground wasn't and isn't connected.


So when it goes full forward/crazy (during bench test), does the tilt angle change when you tilt back in Serial Monitor? Does the motor output change to negative?


----------



## adamson (Mar 2, 2014)

I've changed IMU's today from one to two (all new), I can't check it by serial monitor because it happens only when wheels are on the ground, but there is no reaction when turning left/right and back/foreward.(clone is out of balance)
Sometimes there is a very long beep when it happening.
Maybe I'll try to change dc-dc converter to other power source.
Edit:
I've changed power supply to arduino without any result.
Temperature sensors, voltage divider, bluetooth work fine.
I've got shielded cables to IMU's, temperature sensors and to Bts 7960.
Everything started going wrong when I've replaced destroyed 7960.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> I've changed IMU's today from one to two (all new), I can't check it by serial monitor because it happens only when wheels are on the ground, but there is no reaction when turning left/right and back/foreward.(clone is out of balance)
> Sometimes there is a very long beep when it happening.
> Maybe I'll try to change dc-dc converter to other power source.
> Edit:
> ...


I think one (or both) of the BTN controllers is sending a spike back to the Arduino and causes it to hang. This doesn't occur during a bench test - only when the motors are loaded.

I had the same problem a year ago when I was using my own DIY motor controller. I solved it by using optoisolators and using a separate battery for the Arduino. This is not practical, but can be a last resort.

Anyway, my other suggestion is to buy another pair of BTN controllers. Swap them one at a time to identify and replace the "spiky" BTN controller. 

BTW, I have learned from experience that the more expensive BTN7971 does not really handle more current than the cheaper BTN7960. So, save your money and get the cheaper BTN7960/BTS7960.


----------



## electricpolo (Mar 15, 2011)

Have got the new RoboClaw 2x60A HV controller in place & everything connected up (no encoders at this stage)
On the bench, the machine functions exactly as expected.
I can make the wheels go forwards or backwards or be still if I adjust the handlebar just a little at the balance point. The wheels will respond properly when the handlebar is leaned. The system will shut off if I exceed the max tilt angles & recover as expected when I bring it back to level again.
A couple of times though I did get an Error 4 if I exceeded the rear tilt. Power cycling the Arduino cleared that.

All the following tests were done with no rider. I was standing beside the machine, holding the handlebar.
On the ground though, it is a different story. It will come up to it's level ready point very nicely & just sit there for a little bit.
Sometimes it will start turning on the spot in one direction with no response from the handlebars at all, leaning the handlebar in the opposite direction does nothing & even tilting past the max tilt which should stop everything does nothing either.
Other times, it will suddenly want to go forward or backward with the same no response from the handlebar. Tilting the handlebars in the opposite direction did nothing nor does going to max tilt.

I was able to have the laptop on the machine at the same time to get some screenshots of the serial monitor.
Shows the error numbers just as the machine starts to malfunction.
The only way to stop the machine is to press the kill button to turn off the RoboClaw. The arduino then needs a power cycle to clear the error.
I have tried the earlier versions of the program which were working until the motor controller issues but all do the same thing.

This could be the same issue that adamson is having.
Note. I also have shielded cables for the IMU's & to the RoboClaw. Logic ground not connected to RoboClaw. Shield only connected at Arduino. DC-DC power supply feeds off main battery pack of 26V & supplies Arduino 11V. Arduino 5V powers 2 x IMU's, 1 x bluetooth module & 2 x IR rider sensors.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Have got the new RoboClaw 2x60A HV controller in place & everything connected up (no encoders at this stage)
> On the bench, the machine functions exactly as expected.
> I can make the wheels go forwards or backwards or be still if I adjust the handlebar just a little at the balance point. The wheels will respond properly when the handlebar is leaned. The system will shut off if I exceed the max tilt angles & recover as expected when I bring it back to level again.
> A couple of times though I did get an Error 4 if I exceeded the rear tilt. Power cycling the Arduino cleared that.
> ...


This is definitely a motor noise problem. The noise/spikes get stronger with increased motor load and battery voltage. That's why it doesn't happen on a no-load bench test. Operating at a higher 26V means you'll suffer it more easily than the rest of us on 24V. I bet the problem disappears if you half the voltage to 13V (try it).

Try removing the ground connection from the shield (mine is like this). You should also try re-routing the motor and motor controller wires.

As per my previous post, the guaranteed solution is to use a separate logic battery and optoisolators on the motor controller. But it gets more complicated.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> I've changed IMU's today from one to two (all new), I can't check it by serial monitor because it happens only when wheels are on the ground, but there is no reaction when turning left/right and back/foreward.(clone is out of balance)
> Sometimes there is a very long beep when it happening.
> Maybe I'll try to change dc-dc converter to other power source.
> Edit:
> ...


One more thing, do you use a screw isolator and teflon to isolate your temperature sensor from the motor controller heat sink? You should because the tab on the TC74 is connected to ground!


----------



## electricpolo (Mar 15, 2011)

> Try removing the ground connection from the shield (mine is like this). You should also try re-routing the motor and motor controller wires.
> 
> As per my previous post, the guaranteed solution is to use a separate logic battery and optoisolators on the motor controller. But it gets more complicated.


I'll remove the ground shield connection & reroute the motor controller wires today.
Will look for an isolated DC DC converter as my current one isn't isolated.
Would you mind posting a schematic of how you did the optos. 
Don't mind the complicated - just want it to work.


----------



## electricpolo (Mar 15, 2011)

Did a bit of fooling around today.
Rerouted Arduino/RoboClaw cable well away from any power cables.
I had a Cincon isolated DC-DC converter lying around so that got connected into the system to power just the Arduino & the sensors.
The Arduino & the sensors are now totally isolated from the power circuit.
The RoboClaw is powered by the power circuit. Only S1 & S2 are connected to the Arduino.
Ran tests with Arduino/RoboClaw cable shield both connected to ground & totally disconnected.
Didn't make any difference. See the screenshots.

I am at a loss as to why the system worked before with the 2x60a (until the controller spat the dummy). At least the 2x60a HV is still working.
I am going to go back to a very basic bare bones setup using the Nano & see what happens.


----------



## electricpolo (Mar 15, 2011)

What about a circuit such as this to isolate the ttl lines between Arduino.
This circuit is pretty small & is bi-directional.

Alternatively, could maybe use 2 of these ready made opto breakout boards.
http://www.ebay.com.au/itm/190895630965?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1438.l2649
One in each direction.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Did a bit of fooling around today.
> Rerouted Arduino/RoboClaw cable well away from any power cables.
> I had a Cincon isolated DC-DC converter lying around so that got connected into the system to power just the Arduino & the sensors.
> The Arduino & the sensors are now totally isolated from the power circuit.
> ...


Those errors are from the IMU I2C bus. Did you use optoisolators? I can't see how connecting S1 and S2 would work without a common ground. In any case, refer to the attached circuit for connecting them using optoisolators.

To make sure the two grounds are isolated, use a voltmeter and check for continuity between them - they should not be connected. If they are, then you have a common ground somewhere - maybe the chassis itself.


----------



## electricpolo (Mar 15, 2011)

I also came across this LTC4311 I2C bus accelerator
http://www.linear.com/product/LTC4311
What do you think?


----------



## electricpolo (Mar 15, 2011)

> Did you use optoisolators?


Not yet. That will be next. I was trying things with stuff I had lying around.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> What about a circuit such as this to isolate the ttl lines between Arduino.
> This circuit is pretty small & is bi-directional.
> 
> Alternatively, could maybe use 2 of these ready made opto breakout boards.
> ...


Yes, this will do the trick. You only need one because each module already has 2 channels.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> I also came across this LTC4311 I2C bus accelerator
> http://www.linear.com/product/LTC4311
> What do you think?


Looks good, but I don't think you need this. Use a CRO to see if the signals are already square.

This reminded me, aren't you using a logic converter for the I2C bus? If you are (not actually needed), you must pull up SDA and SCL on the Arduino side. Use 4.7K tied to 5V.


----------



## electricpolo (Mar 15, 2011)

Found a schematic of the eBay ones. Would need two as both channels go in one direction.
No level converter for the I2C sensors. They are 5V versions.
The level converter was for the bluetooth module.
I can put my scope onto the bus but only on the bench test.
Going to get some of the optos you used and make it up.


----------



## electricpolo (Mar 15, 2011)

Managed to do some testing this evening. Haven't got it to work but at least I know now what it isn't!

Tried Nano with the new OpenJumper IMU's. Same result as before.
Tried Nano with the original cheap eBay IMU's. Marginally better. I was able to get slightly more motor power before error & lockup.

Isolated power supply was not in circuit this time. When I connected it, I found that the RoboClaw didn't respond so there must have been a ground connection somewhere that I missed with the Mega.

I think that it is noise of some sort getting into the I2C lines.
The tilt sensor is only 40mm from the controller & the steer sensor is about 60mm.
I also think that the new 2x60a HV is noisier than the original 2x60a controller. The RoboClaw HV is very different, very new design.
The opto isolators will be here in a day or two so I'll be making the S1, S2 isolating circuit as per your schematic.

Remember Thomas Edison's light bulb quote


> I have not failed. I've just found 10,000 ways that won't work.


----------



## JBuilder (Feb 12, 2014)

HI,I had the same problem with the communication when using my seggi with Power to the Motors/sabertooth Controller. No way to correct it. Isolation or another imu . Other settings for ground no effect. Some heavy collisions with my legs and furniture. The seggi hurts. But when i switched to pot steering the problem vanished. 

The tilt sensor never was the problem, which is solded on the breadboard direct mounted on the mega. The sensor for
Steering has some wires this is the difference.

Now i try to adjust the parameters as good as possible. Next i will give the optocopler a Chance. My wheelchair motors have a lot of power so every communication fail might result in a heavy impact.

The rider sensor at this moment is a switch for manual use but very usefull, good work!


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo
This is small video i have made please check it out and tell me what u think.
https://www.youtube.com/watch?v=0NOWxnIs03g&feature=youtu.be
Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

JBuilder said:


> HI,I had the same problem with the communication when using my seggi with Power to the Motors/sabertooth Controller. No way to correct it. Isolation or another imu . Other settings for ground no effect. Some heavy collisions with my legs and furniture. The seggi hurts. But when i switched to pot steering the problem vanished.
> 
> The tilt sensor never was the problem, which is solded on the breadboard direct mounted on the mega. The sensor for
> Steering has some wires this is the difference.
> ...


You are right. Noise can enter the cable that connects the steering IMU. Isolating the power supplies will not work because you still need to connect the ground together. You need to use optocouplers for complete isolation. I hope the shielding on the cable will stop noise transmission by air.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Would it be possible for you to add a temporary piece of debugging code to find out if the program is freezing, not handling an error or just waiting for a reply that never comes?
The RoboClaw tech support would find it very helpful.

This is what I am doing prior to the opto & DC isolation.
Twist the motor power wires and put ferrites on them.
Put ferrites on both sensor cables.
Put a ferrite on Arduino/RoboClaw cable.
Twist the power wires to the Arduino & put a ferrite on it too.
Drain the Arduino/RoboClaw cable shield at the RoboClaw (currently at the Arduino)
Drain the IMU sensor cable shields at the RoboClaw too. (currently at the Arduino)


----------



## mantissa (Jun 30, 2014)

Thank you for the work you and others have put into this code, it's made a huge difference to the viability of my son's diy segway project.....

Right now, with the segway built, he's testing the electronics on the bench with some small dc motors. He's seen that the motor speed changes as the IMUs are titled which is great. He's almost ready to move over to the vehicle itself.

One problem though, which I was hoping someone could comment on...

He was quite keen to use the bluetooth serial link and duly downloaded the cloneconsole app. Two 'phones are able to pair with the device, but the app always crashes (on both 'phones). Now, he doesn't have a 'linvor' module, but it is an HC-05/06 (http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=400698151706&ssPageName=ADME:L:OC:GB:3160) It differs from the ones I have seen mentioned here in that it is a 5V device, so no need for the level shifters, but otherwise seems the same.

I didn't see anyone else mentioning difficulties with the app, so I wondered if there was any info anyone could share about the app crashing? We have Nexus 4 and Moto G handsets and are using the lastest versions of Cloneconsole and Segwayclone. He also ran the bluetooth detect code and that worked fine.

So - module pairs with 'phone. Module is detected by Arduino (Mega). Android app crashes everytime.

Has this been seen before by anyone?

Thanks in advance....


----------



## JBuilder (Feb 12, 2014)

Testride Success,
my first real testride was for me great success. Only one time a fall of my Seggi.
I tried to go fast as it could and the tilt was too big - I have to correct the value. 
Faster as I thought - but no injuries - this time.

I found out that with the actual parameter I do not "trust" my seggi when leaning forward. It feels that it is a little bit "late" when accelarating. (Which parameters" 

And second: the steering is perfect when driving slow , but riding faster the same parameter value is sometimes dangerous. I thought about a speed dependent steering multiplier. 
And the spring are not the best idea , I think about pneumatic springs instead.


https://www.youtube.com/watch?v=PuQW1fKZaUI
https://www.youtube.com/watch?v=PuQW1fKZaUI


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovaltineo
> This is small video i have made please check it out and tell me what u think.
> https://www.youtube.com/watch?v=0NOWxnIs03g&feature=youtu.be
> Thanks
> Rajneesh


Good work! That looks like it is ready to test. 

It needs weight to move forward. Use a 50kg sack of rice (or cement) to start with. You need to make sure it doesn't glitch or hang with load.

If everything works, get someone brave enough to sit on it and test. Make sure you have a BIG RED shutdown button that powers off the battery (via relay).


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> Would it be possible for you to add a temporary piece of debugging code to find out if the program is freezing, not handling an error or just waiting for a reply that never comes?
> The RoboClaw tech support would find it very helpful.
> 
> ...


The output to the SerialMonitor is the debugging code. If it stops, then it is frozen. Communications with the Roboclaw is one way - it sends a command and doesn't wait for a reply (there isn't any). It is impossible to tell if the Roboclaw itself has hang. If you get errors, they are all from the I2C bus.


----------



## Ovaltineo (Jul 18, 2013)

mantissa said:


> Thank you for the work you and others have put into this code, it's made a huge difference to the viability of my son's diy segway project.....
> 
> Right now, with the segway built, he's testing the electronics on the bench with some small dc motors. He's seen that the motor speed changes as the IMUs are titled which is great. He's almost ready to move over to the vehicle itself.
> 
> ...


The bluetooth module is not the problem.

Try turning off the phone and back on. Does it work the first time? 

The app crashes on my phone every now and then. Sometimes it won't connect, especially if I run, exit, and run again. It is best to wait 30 seconds before restarting. I usually restart Bluetooth on the phone to make it work again. But most of the time it works - I have a Nexus 2 with v4.4.2. 

I think the main reason for the problems is that I am using Processing v2.0.3 software. It is a development framework with a lot of graphic libraries built in. It makes it easy to develop Android apps, but I don't have full control of what happens under the framework. It uses a very old version of the Android SDK, which is probably why it doesn't work on some devices.

I will download the latest version of Processing (v2.2.1) and see if that fixes things.


----------



## electricpolo (Mar 15, 2011)

*Re: JBuilder Segway Clone*

The problem with your springs is a twofold mechanical one.
First, you need to move the spring connection point further away from the shaft. See my pictures. My attachment point is about 125mm from the shaft.
Second, your springs look very light for the job. The springs need to be pretty strong. Mine came from a washing machine & supported the drum. You could also use car hood hinge springs.
My spring setup works very well.
Forget pneumatic springs. They won't work in this situation. I tried them first and were a total flop.


----------



## electricpolo (Mar 15, 2011)

> The output to the SerialMonitor is the debugging code. If it stops, then it is frozen. Communications with the Roboclaw is one way - it sends a command and doesn't wait for a reply (there isn't any). It is impossible to tell if the Roboclaw itself has hang. If you get errors, they are all from the I2C bus.


Thanks for that. Perhaps I wasn't clear. The RoboClaw itself isn't hanging but they want to find out if the RoboClaw is the source of the interference that is affecting the Arduino.
I suspect that the RoboClaw is not the issue because a couple of other people have experienced similar noise issues to me.
Will do the noise reduction measures & put the scope on the I2C lines & see what it looks like.
There is also an updated wire library that I am going to try.


----------



## aqmconseils (Jun 22, 2014)

Hi,

I followed this forum for several months. I already read all pages, thanks for all your participation. It is very interresting.
I would like of course to built my own segway. I bought the arduino card, the sabertooth controller ( it was before I found this forum) and the MPU 9050 ( Not 6050 but it seems to work).
I already loaded the software and made some testing and all seems to be ok.
I have an Iphone but may be I will buy a low cost android phone because it seems to be interresting to have this unit to calibrate (PID) the clone.
Now, I am working on the mechanical part.
I would like to have a very design clone. I found an electric golf trolley and I want to have your remarks to know if I can modifiy it easly to adapt the electronic part
What's about motor? May be I will be oblige to change the wheel.
In france, it is diffcult to find low cost gear box and for the price of this trolley, I think that I can use many parts of it.
Sorry for my english.

Waiting for answer.

Good luck for all your projects and special thanks to Ovaltineo.

I give you the link of the golf trolley with specifications in english. It is the same that I find in France (a chineese product of course).
http://www.parcaddy.ca/XR6.html

regards
Thierry


----------



## electricpolo (Mar 15, 2011)

The motors in the golf buggy thing are only 200 watts. Will be very under powered for a segway clone.
Keep looking for motors around the 450 - 500 watt size.


----------



## aqmconseils (Jun 22, 2014)

Thanks for your quick answer

But I saw that many people use 250W motors and I was thinking that 2 motors with 200W each could be enough.


What could be the problems?
I don't want to ride very fast and only on standard sidewalk

Thanks for your help


----------



## electricpolo (Mar 15, 2011)

Won't have enough combined power & motor speed to balance properly.


----------



## electricpolo (Mar 15, 2011)

*Re: Electricpolo Segway Clone*

Looks like I am on the road to success!
I am not going to say 100% just yet but initial tests in the workshop look good.

OK, finished doing the mods to get rid of the I2C errors.
This is what I have done.
Twisted the motor to controller power wires and put ferrites on them close to the motor.
Put ferrites on both IMU sensor cables as close to the Arduino as possible.
Put a ferrite on Arduino/RoboClaw cable as close to the Arduino as possible.
Rerouted the Arduino/RoboClaw cable away from any main power cables.
Twisted the power wires to the DC-DC converter & twisted the power wires from the converter to the Arduino & put a ferrite on it too close to the Arduino.
Drained the Arduino/RoboClaw cable shield & both IMU senser cable shields at the RoboClaw battery negative terminal.

It worked fine on the bench test (12% power) as per before but when I put a load on the tyre with my leg, it kept going this time whereas before it threw an error & froze. 
The waveform on my scope didn't didn't change when I put the load on either.
Next I put it on the floor for the big test (still 12% power just in case).
Balanced great & moving the handlebars forward, backward & leaning side to side was now moving the machine with no I2C errors or lockups.
These are very early tests and I need to do more tests in depth tomorrow but it is looking very promising.
I have the optos to isolate S1 & S2. They will be next as will totally isolating anything Arduino from the power system.

It pretty much confirms my suspicions that the motor cables were radiating noise and the IMU cables were acting like antenna & picking up the noise.
The noise increased with the motor load & interfered with the I2C bus.


----------



## Ovaltineo (Jul 18, 2013)

*Re: Electricpolo Segway Clone*



electricpolo said:


> Looks like I am on the road to success!
> I am not going to say 100% just yet but initial tests in the workshop look good.
> 
> OK, finished doing the mods to get rid of the I2C errors.
> ...


Looks good ! Next step is to use a ballast to simulate the weight of a rider. Make it drive over a half-inch tall piece of wood - be ready to hit that KILL button coz this is were it can go berzerk. I would be standing on a bench while doing this.

For a live test, wear helmet, gloves, boots, and leg armor (used by motorcross bike riders).


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Won't have enough combined power & motor speed to balance properly.


It will work on a very flat path. Maximum speed would be walking pace. It will struggle (stall or fall over) on any incline. You will be disappointed like one member here who bought a Chinese-clone with 250W motors.

I originally used 300W motors but kept burning my BTN motor controllers because they would stall on steep inclines. I replaced them with 500W motors which are faster and can go uphill without stalling.


----------



## electricpolo (Mar 15, 2011)

Already drove over a couple of blocks of wood in the workshop with no ill effects.
For the time being, I've halved the P & D settings too as well as limiting the power.
Going to up the power a little bit & try the bluetooth remote control then on go a couple of bags of sand.
I just walk beside it at the moment and have my finger next to the kill button on the handlebars.
If that is successful, I'll start hooking up the sensors & the other bits one at a time paying a lot of attention to the ground positioning.


----------



## aqmconseils (Jun 22, 2014)

I am a liitle bit confuse with your answers.

It seems that it can work with 2 x 200W motors but I don't understand exactly the problems I could have.
If you can explain me with simple words (I am french) that will be nice.

My idea is to have the same kind of design of the goff trolley I sent before.

In any case, Could you give me a link of of more powerfull tubular planetary gearbox motors I can buy?

I also found some wheels with the motor included such as UUmotor.
http://www.uumotor.com/9-inch-self-balancing-segway-motor-mono-shaft-brushless-350w.html
Has some one test them ?


Sorry for my poor english.


----------



## adamson (Mar 2, 2014)

200W motors will be ok for child (about 30 kg)


----------



## adamson (Mar 2, 2014)

This brusheless motors are great but motor driver is very expensive.


----------



## electricpolo (Mar 15, 2011)

Bit more testing today. Turned the power up to 33% with P set to 3 & D set to 1.
Am getting some I2C errors again but only at higher motor current levels.
Next step will be to opto isolate the S1 & S2 lines & electrically isolate the Arduino.


----------



## aqmconseils (Jun 22, 2014)

I found Two wheelchair gearbox motors with a power of 300w each (24V). I don't find more powerfull motors (500W).

The motors are very huge compared to motors for scooter with the same power. Could you explain me why?


I will review the design of my clone but my question is now about battery.
I am not sure I can use the wheelchair battery because they are very very large and may be they are not working any more.
I can't do any test because I can't walk due to problems with my Back.
I am expecting it will ok next week.
What can of tests, I can do to check if they are still working?

Could you give some technical details to help me choosing others batteries?
What are the different kinds of batteries with advantage and of course disadvantage? (size, wheight, power, and price of course...)?


----------



## Borc (Mar 12, 2014)

@aqmconseils

"The motors are very huge compared to motors for scooter with the same power. Could you explain me why?"

As you said in the first line - they are gearbox motors, with gears inside and around 200 RPM max on output. That mean around 12 Km/h max speed with 8 inch wheelchair wheels. 
Scooter motors are normally geared via chain drive outside of the motor.

Do not forget to disengage brake first on wheelchair motors:
https://www.youtube.com/watch?v=p8_vGv_03Ao


----------



## markula (Oct 27, 2013)

aqmconseils said:


> I found Two wheelchair gearbox motors with a power of 300w each (24V). I don't find more powerfull motors (500W).
> 
> The motors are very huge compared to motors for scooter with the same power. Could you explain me why?
> 
> ...


http://www.ebay.com/itm/MOTOR-PMDC-...11?pt=LH_DefaultDomain_71&hash=item2c74e1b433


----------



## aqmconseils (Jun 22, 2014)

Thanks Roc I already saw this video.

For the ebay link due to legal restriction in countries I can't open it in France

The world is not so open we can imagine


----------



## JBuilder (Feb 12, 2014)

Parameter List:
What about a List of Values of KP and KD from all selfmakers ?

I think the Table should tell about Motor , Controller, KP and KD and Power Voltage.
I am still struggeling with my Seggi. 

PRIDE JET 3 ULTRA motor with gearbox, Sabertooth 2x25 , KP 0,35 , KD 0,15 and 24 Voltage power.

I can collect other datas and will publish them here if you like to do so.


----------



## aqmconseils (Jun 22, 2014)

Hi,

Of course, I am interrested to have your feedback on PID values for your clone.
I will give you mine when my segway will work.

My back is better and the I made some work today.

I made some tests but I think that I have a bad connection with my MPU6050 and it doesn't work any more.

Then I have to buy an other one and then I will buy 2 for the sterring.

I also will buy a mega card to use the bluetooth and may be also the T° sensor.

Before to do that, I have several questions:

Is the bluetooth module working with sabertooth 2x25A? There is no drawing on the first page. What will be the wires connections?.

Can I put the arduino card in the same box with the sabertooth?. I am afraid about excessive heat and interferences. Could you give me your recommendations?

I am using the metal box from the wheechair I bought. Can I also put in it the bluetoooth module?

There are 2 T° sensor in your drawing. Why 2 ? what is the effect of an important Temperature?

Can you show me some pictures with the MPU6050 installed for the main one and also for the sterring? Is it more simple to install the second MPU6050 for the sterring in spite of to install the pot?

What other modules do I need to have the complete functionnalities ?

Waiting for your answer.

Good luck with your projects.

Thanks in advance.


----------



## mantissa (Jun 30, 2014)

Having some issues with CloneConsole still,

Bought a new Android phone to run it on (at least it doesn't crash now!).

Replaced the bluetooth module and have been able to;

See the name change to SEGWAY when running calibrate.
When in run mode, the app connects and goes to a white background (never did that before!), but no changing data on the display.

Can anyone comment on how far I've got? If the display values remain static, could it still be an issue with the bluetooth module, or am I past that stage now? Is 115200 OK for the comms to the the app (via the b'tooth)?

Thanks in advance...


----------



## Ovaltineo (Jul 18, 2013)

mantissa said:


> Having some issues with CloneConsole still,
> 
> Bought a new Android phone to run it on (at least it doesn't crash now!).
> 
> ...


115200 is OK.

I tried to download the latest Processing software but for some reason, it keeps stopping and corrupting the file. I gave up after many tries. In any case, it didn't look like it would fix your problem because they used the same old Android SDK version with that release.

I have also attempted to build my own Android plugin to Processing. But with very little instructions available, I'm finding it difficult and it would take a while to get it done.

Anyway, white background is good. It means that a proper connection between the bluetooth module and the Android is established. I'm quite surprised that the display is not changing though. It is possible that the Arduino is not receiving data properly from the bluetooth module.

Load the DetectBluetooth (see post #1) program on the Arduino. Can it find the bluetooth module?


----------



## Ovaltineo (Jul 18, 2013)

JBuilder said:


> Parameter List:
> What about a List of Values of KP and KD from all selfmakers ?
> 
> I think the Table should tell about Motor , Controller, KP and KD and Power Voltage.
> ...


300W motor + chain drive, 2 X BTN7960, KP=.7 KD=.3, 24V
500W motor with gearbox + chain drive, 2 X BTN7960, KP=.24 KD=.19, 24V

If you don't have a rider sensor, then it is very likely that the KP and KD will cause oscillation without a rider - you'll just need to get used to it. If you reduce them, you'll find it unresponsive when you ride on it.

The best way is to install a rider sensor. This way, you can set KP_OFF and KD_OFF with lower values.


----------



## Ovaltineo (Jul 18, 2013)

> Hi,
> 
> Of course, I am interrested to have your feedback on PID values for your clone.
> I will give you mine when my segway will work.
> ...


There were only 10 max attachments allowed, so I couldn't add more drawings to post #1. I have attached it here.


> Can I put the arduino card in the same box with the sabertooth?. I am afraid about excessive heat and interferences. Could you give me your recommendations?


This is not a good idea, keep them separate for the reasons you cited.


> I am using the metal box from the wheechair I bought. Can I also put in it the bluetoooth module?


No, the metal box will block the bluetooth RF signals.


> There are 2 T° sensor in your drawing. Why 2 ? what is the effect of an important Temperature?


They were meant for monitoring the temperature of 2 X BTN7960 -- they can get pretty hot. For Sabertooth, you can install only 1 if you want to monitor the temperature. For Roboclaw, it has it's own temperature sensor - I will add support when mine arrives.


> Can you show me some pictures with the MPU6050 installed for the main one and also for the sterring? Is it more simple to install the second MPU6050 for the sterring in spite of to install the pot?


Check out electricpolo's pics here. 
http://www.diyelectriccar.com/forums/showthread.php/electricpolo-segway-clone-build-95729.html



> What other modules do I need to have the complete functionnalities ?


You need a DC-to-DC converter (or just tap 12V from one battery). You'll need an emergency switch connected to a high-current relay.


----------



## markula (Oct 27, 2013)

I have just finished a Self balance unicyle. I am using BTN 7960, 600W motor. 

BTS 7960
Current limitation level of 33 A min
BTS 7970
Current limitation level of 50 A min

The problem is in low speed the motor controller dont have enought A.

The driver on the arduino boars ( 74hc244d) have output up to 35mA, and the 7960/70 use max 3 mA.

So is it possible to just solder another bts on the top of the other.
You have to make other changes like:
Maybe change the cap from 1000 uf to 2000 ?
move the terminals since the path in the board is to weak
Some cooling system for the 2 extra bts 7970 

And you have a 100A h brige(4X7970) ?


----------



## electricpolo (Mar 15, 2011)

According to the BTS 7970 datasheet, it is possible to double them up for additional current handling.
A couple of heatsinks may be a wise move too.

Simply putting one chip on top of another would create all sorts of pretty bad thermal issues.


----------



## markula (Oct 27, 2013)

electricpolo said:


> According to the BTS 7970 datasheet, it is possible to double them up for additional current handling.
> A couple of heatsinks may be a wise move too.
> 
> Simply putting one chip on top of another would create all sorts of pretty bad thermal issues.


That just show how to connect it into a H brige (so you can run the motor bought directions) and not a Half-bridge ( just one direction). Thats why it is 2 bts 7970(Half-bridge) to be a H-Brige.


----------



## mantissa (Jun 30, 2014)

Success!

I really don't know what was going on with CloneConsole! (Thanks Oval for looking at the Processing thing, but just to say that it seems unnecessary now!)

With my original BT module, I couldn't get connected using CloneConsole on a NExus 4 and Moto G. So, I bought a Huawei phone which did connect but didn't show any moving data. I then changed the BT module to a 3.3V one (although I do wonder if my original 5V one was indeed rated for 5V interfacing) and used the resistor divider on the input and a 5V pull up on the output. No improvement with CloneConsole on the Huawei. Just out of interest, I went back to the Nexus and Moto - success! Sure, it always crashes on first use, but subsequent attempts eventually connect and it all works! (Quick question, what is the second screen for - with the red circle and slider?) I'm also not convinced that the CloneConsole calibration works either, but who cares, it mostly works and that's good enough for us!

Next success was with the segway itself. My son built this and given his lack of skills and my lack of metal working equipment, we decided to make this a true DIY segway in that it can all be fabricated with a true home DIYer level of kit. All the materials were purchased in B&Q (The UK version of Home Depot) and the only tools used were standard stuff - Cordless drill, Jigsaw etc.

The deck is made from plywood and after salvaging the motors, gearboxes and wheels from a Storm 3 wheelchair, he added;

Arduino Mega
2 X MPU 6050 accel/gyros
Sabertooth 2 X 25A controller
1 X switchmode voltage regulator
Some metal tube for the steering and some metal angle for the steering 'box'.

Some amazingly well written and configurable software from somewhere on the internet 

After having the assembly on a beer crate, we convinced ourselves it was doing what we'd expect (in terms of motor directions etc) before (with MOTOR_MAX set to 20) having a go on the ground. It worked! It's useful having the motor max speed beeper to help you work out what the system is doing here....

Over the course of the next 30 minutes he went from 20, through 60 and finally to 127 (for MOTOR_MAX) and then 'went for it' on our front drive. The video is here https://www.youtube.com/watch?v=gEeilM_gjAg&feature=youtu.be (Those of you who have 'been there' will recognise the motor max beep as he returns [uphill] up the drive - on a subsequent run, I made the mistake of ignoring that beep and went over the front!)

If it wasn't for Ovaltiney (as we call him here) and the body of expertise and opinion and the generous sharing of ideas that goes on round here, my son (who is only 16 by the way, despite his height) would have found it so much harder to achieve his goal of building a DIY segway - so thank you all.

There's still a fair amount to do -

Add voltage monitoring and a charger socket,
Add a T-bar handle to the steering pole
Add rider sensor
Cover or protect the electronics for when 'non-maker' people try it 
Explore the P/D tuning (although it all seems pretty good out of the box, as it were)
Add pushback, or at least look at it.

I notice from CloneConsole that we seem to have everything reversed, forward is backward etc. Given that the imbalance of the build is such that it tilts forward, I am aware that our max forward speed it limited as the motors are already 'loaded' with the need to counterbalance their own weight which is a shame. Before I go looking, there isn't any software limit to the reverse speed is there (since our forward is actually the software backward direction)? Thought I'd check in case we're missing a trick.

I'm happy to put up some build photos if they'd be useful.

Thanks again from a chuffed Dad and Son...


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> I have just finished a Self balance unicyle. I am using BTN 7960, 600W motor.
> 
> BTS 7960
> Current limitation level of 33 A min
> ...


From experience, there is absolutely no difference between these two. Both have max continuous current of 44A. The "current limitation" protection supposedly kicks in earlier on the BTS7960 but I found that some of my BTS7970s are worse. It really depends on particular chips. I have a "stall" test where I put the clone in a gutter with a right angle edge. Some BTS7960s can power over this with no problem, while some BTS7970s can't. So save your money and buy the BTS7960.

What happens when the "current limitation" kicks in? The motor makes a strange high-pitched sound and lose power.


> The problem is in low speed the motor controller dont have enought A.
> 
> The driver on the arduino boars ( 74hc244d) have output up to 35mA, and the 7960/70 use max 3 mA.
> 
> ...


This *might *work.  But it will be very tricky getting thick wires to the legs of the chips and adding a heat sink. You might be better off buying another complete module.


----------



## Ovaltineo (Jul 18, 2013)

mantissa said:


> Success!
> 
> I really don't know what was going on with CloneConsole! (Thanks Oval for looking at the Processing thing, but just to say that it seems unnecessary now!)
> 
> ...


WOW! Congratulations! 

If you rotate your tilt sensor 180 degrees, forward and back will be reversed. In any case, there is no difference in max speed between the two.


----------



## markula (Oct 27, 2013)

Ovaltineo said:


> From experience, there is absolutely no difference between these two. Both have max continuous current of 44A. The "current limitation" protection supposedly kicks in earlier on the BTS7960 but I found that some of my BTS7970s are worse. It really depends on particular chips. I have a "stall" test where I put the clone in a gutter with a right angle edge. Some BTS7960s can power over this with no problem, while some BTS7970s can't. So save your money and buy the BTS7960.
> 
> What happens when the "current limitation" kicks in? The motor makes a strange high-pitched sound and lose power.
> 
> This *might *work. But it will be very tricky getting thick wires to the legs of the chips and adding a heat sink. You might be better off buying another complete module.



Yes. First i thougt somting of the drivetrain slipped. But is motor controller. 
https://www.youtube.com/watch?v=ZTNCQK5_jPM&feature=youtu.be

Solder out cap, and battery and Power connections. Place another custom PCB on the top and get all 4 bts on a line for cooling was my thougt. Something like this:


----------



## Ovaltineo (Jul 18, 2013)

markula said:


> Yes. First i thougt somting of the drivetrain slipped. But is motor controller.
> https://www.youtube.com/watch?v=ZTNCQK5_jPM&feature=youtu.be
> 
> Solder out cap, and battery and Power connections. Place another custom PCB on the top and get all 4 bts on a line for cooling was my thougt. Something like this:


If you are using a custom PCB, then might as well ditch the old board. You MUST use double sided PCB for this because a single side cannot handle the current load. You need lots of through holes to conduct the current and heat. In the end, it will be cheaper and simpler to just buy a complete module for $14.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Just about finished the new shield with full power isolation for the Arduino & opto-isolation for the HV RoboClaw S1 & S2 lines.
I need to isolate the voltage divider between the battery pack & the Arduino.
Do you have any ideas on how to do this?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> Just about finished the new shield with full power isolation for the Arduino & opto-isolation for the HV RoboClaw S1 & S2 lines.
> I need to isolate the voltage divider between the battery pack & the Arduino.
> Do you have any ideas on how to do this?


Do not connect the battery to the voltage divider. We will bypass it entirely because the Roboclaw has an API call to read the battery voltage. There is another API call to get the temperature too.

My Roboclaw is on its way, so I'll be able to test these when it arrives.


----------



## electricpolo (Mar 15, 2011)

Good idea. 
I had forgotten that the RoboClaw could do that.


----------



## Ovaltineo (Jul 18, 2013)

I forgot to answer a previous question about the screen with red circle and slider on the CloneConsole. It is a GPS-based speedometer - in km/h. Unfortunately, it is inaccurate at low speeds but ok above 10km/h. The slider controls the averaging window (alpha coefficient for exponential moving average). A lower value will average more samples over time.

I have plans to release a version of CloneConsole with Farenheit and mi/h units.


----------



## adamson (Mar 2, 2014)

Which Roboclaw 2x60A to buy? HV 300$ or with usb for about 200$?
This cheaper will be ok for segi or not?


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Which Roboclaw 2x60A to buy? HV 300$ or with usb for about 200$?
> This cheaper will be ok for segi or not?


I'm getting the HV. If you look at previous posts by electricpolo and mariov, it looks like the non-HV version is not ok for a Segway clone.


----------



## electricpolo (Mar 15, 2011)

It really depends on your motors but my experience with 2 x 500W Dayton motors is the following:
RoboClaw 2x60a blew up twice. Only lasted a very short time (10 minutes) & spent most of it's short life travelling back to the US for repair. I2C errors were not evident.
Orion Robotics think that there were back voltage spikes were too high for the unit to handle.
RoboClaw 2x60a HV. Has outlasted the 2x60a & I have even been able to ride it a bit. No sign of the previous issues with voltage spikes however there has been a bit of a saga with I2C errors locking up the Arduino.
I have spoken to both Ovaltine & another electronics friend of mine & the general consensus seems to be the following:
The new HV RoboClaw switches at a much higher frequency that is much closer to the the frequency the I2C bus runs at. This is introducing noise into the Ground cables and causes the I2C bus to have errors all the time.

The agreed solution was to use a totally isolated DC DC converter to power the Arduino & the sensors and to use opto isolation between the RoboClaw & the Arduino.
In addition, the I2C shields & the RoboClaw to Arduino shield need to go back to a common point on the RoboClaw.
Optional Extras.
Twist the motor wires & put ferrites on them.
Twist & put ferrites on the power cable to the DC DC converter.
Put ferrites on the I2C cables & the RoboClaw control cable.

Have almost finished the new Auduino shield which should fix these issues.


----------



## adamson (Mar 2, 2014)

Thanks for yours support. So two of the roboclaw options are not ready for segi for now.


----------



## electricpolo (Mar 15, 2011)

The RoboClaw 2x60a HV seems to be the one to use as long as you are prepared to do the isolating bit.
Will post over the next couple of days about mine.


----------



## aqmconseils (Jun 22, 2014)

Hi,

I finished the mechanical part and tried to run my clone.
My configuration is :
Wheelchair motors 2x 250w
Sabertooth 2x25A
Arduino uno
2xMP6050

After 20 to 60s, I got the error =4 
If I remove the sabertooth connection, I have no errors.

The alimentation of the arduino card come from one of the 2 batteries 0-12V

I need your help, Can you explain me what can I do?

Thanks in advance


----------



## Borc (Mar 12, 2014)

I have configuration with Sabertooth 2 x 25, 1x MPU 6050 (pot. Steering), 2 x 300W wheelchair motors, UNO. Power for Arduino comes from Sabertooth (since V2 can provide up to 5V/1A). 
Clone is working fine.


----------



## Ovaltineo (Jul 18, 2013)

aqmconseils said:


> Hi,
> 
> I finished the mechanical part and tried to run my clone.
> My configuration is :
> ...


Try using shielded cable when connecting the MPU6050 to the arduino. Make sure the logic ground is not connected on the Sabertooth, i.e, common ground should be just the battery ground.

If none of these work, then you'll need to isolate the Arduino from the Sabertooth using separate power supply and an optoisolator.


----------



## electricpolo (Mar 15, 2011)

aqmconseils
See post 1095 for other things to do to eliminate I2C bus errors.


----------



## electricpolo (Mar 15, 2011)

Finally got the new shield finished with all the new grounding, opto-isolation for the RoboClaw & the like.
The Arduino is working OK but the motors are not moving.
The RoboClaw status LED 1 is flickering & status LED 2 is not coming on.
LED 1 blinks rapidly when data is being received and LED 2 lights up when the drive stage is active.
Am going to recheck the opto-isolation circuit & put a scope on the input & output side to make sure they are the same.


----------



## mantissa (Jun 30, 2014)

I've had some interesting behaviour with a Sabertooth/Mega/2XMPU6050 configuration...

When the batteries are fully charged, there is a good deal of unexpected actuation of one wheel - we've come to call it 'clonking' 'cos the unexpected movement is accompanied by that sort of noise. We didn't notice this initially since the batteries weren't charged until quite late in the day (as the charger socket was one of the last things to be fitted!).

I tried to deduce what the problem was, but haven't had much luck.

I believe it's an interference issue because any motor noise will be at its greatest when the batteries are at their maximum voltage - that seems reasonable. I don't really get why only one motor seems to be affected more than the other. I wonder if it is the case that when that motor is activated by the software, the resultant motor noise couples into the signal to the Sabertooth (packetised serial) and mucks up the motor drive. What I don't like about this theory though is that why should only one motor seem to be affected? If noise was coupling into the Sabertooth control signal, shouldn't both motors behave strangely?

I considered any asymmetry in the build and noticed that the Emergency stop and rider sensor wires connect to the arduino on one side, closest to the motor that behaves strangely. Perhaps I need to read the documentation on the Sabertooth to see how the Emergency stop input (S2) works in practice. On the face of it, there's no real link I can see.

Our next step was to isolate the Arduino, sensor I/O and MPU6050s from the Sabertooth, using an isolated DC-DC converter and opto-isolators between the Arduino and the Sabertooth. That made a HUGE improvement, but 'clunking' was still present for a short time when the batteries were fully charged. Further experimentation has produced another incremental improvement with the addition of a RC filter on the input to the Sabertooh (S1 packetised serial interface).

This would tend to suggest that it is some sort of corruption of the command interface to the Saberooth, but I still don't see why the effect is more dominant in one motor than the other - I think I need to go off and study the Sabertooth docs more closely.

I did wonder about I2C errors, but hooking up the serial monitor, showed that there were none. I did notice jumps in the Accel and Gyro figures, but it's impossible to determine if they're the cause of a jumpy motor or the consequence! 

I'm just thinking aloud here in the hope that someone might have a thought or two or be able to point out something that I may have missed....

Thanks for reading!

John


----------



## electricpolo (Mar 15, 2011)

Can you post a schematic of the opto-isolator circuit & the rc circuit that you used.


----------



## electricpolo (Mar 15, 2011)

Came across this opto-isolation schematic.
Comments on it anyone?


----------



## mantissa (Jun 30, 2014)

Sure,

As per the diagram included in this post (or attached, not done it yet!) I have used a 4N25 to isolate the TTL level serial output from the Arduino to the Sabertooth, using the 5V supply from the Sabertooth to power the transistor side of the optocoupler. The RC filter is (almost) the most I can get away with without losing the serial signal completely 

The Arduino itself is powered by a Traco isolated DC-DC converter and this, in turn powers the MPU6050 accelerometers and bluetooth interface. We don't have much else interface to the Arduino, other than the rider sensor switch. The dead man's handle input (to the Sabertooth) is also sent to the Sabertooth S2 interface via an optocoupler as we wanted it to be an input to the Arduino as well. I haven't shown that on the diagram as it's less critical, but it uses another 4N25 in O/C mode, pulled up by the S2 input on the Sabertooth.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Came across this opto-isolation schematic.
> Comments on it anyone?


This is way too complicated. My design should work -- I used it on my DIY controller. I will be able to confirm if it works with the Roboclaw this week. I am rebuilding my clone using the Roboclaw and isolation.

Have you looked at the input and output signals using an oscilloscope?


----------



## Ovaltineo (Jul 18, 2013)

mantissa said:


> I've had some interesting behaviour with a Sabertooth/Mega/2XMPU6050 configuration...
> 
> When the batteries are fully charged, there is a good deal of unexpected actuation of one wheel - we've come to call it 'clonking' 'cos the unexpected movement is accompanied by that sort of noise. We didn't notice this initially since the batteries weren't charged until quite late in the day (as the charger socket was one of the last things to be fitted!).
> 
> ...


Are you sure it is not slack in the gearbox of one motor? If it is slack, then it will be most noticeable while balancing when it constantly switches between forward and back. 

If it is noise on the serial line, then it should affect both motors. It maybe a problem within the Sabertooth itself, e.g. faulty MOSFET driver.


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Look forward to your results.
Input & output are similar but not the same on the scope.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> Look forward to your results.
> Input & output are similar but not the same on the scope.


I'm not finished with my Mega daughterboard yet, so I tested with a breadboard. It works for me. Here's the schematic again, with a better layout.


----------



## adamson (Mar 2, 2014)

I've got this optocouplers:








and I can't find any informations about it. So my question is how to connect it between arduino and bts 7960. Can help anyone?


----------



## electricpolo (Mar 15, 2011)

http://www.geeetech.com/wiki/index.php/Opto-isolator_Breakout
This should help you.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> I've got this optocouplers:
> 
> 
> 
> ...


You need two of these for a start. You'll also need an isolated power supply for the Arduino - you cannot use the old DC-to-DC converter.

Take your old DC-to-DC voltage converter and make sure the output is +5V. You need to connect this to +5 of the BTS7960.

Now, for the isolation board. For each BTS7960, connect the two PWMs from the Arduino to IN1 and IN2. Connect the ground from the Arduino to GND. Then connect OUT1 and OUT2 to PWM1 and PWM2 of the BTS7960. Connect HVG to the BTS7960 ground. Connect HV to the +5 of the BTS7960. Finally, connect ENA1 and ENA2 of the BTS7960 to +5 of the BTS7960.

Remember, you don't connect the ground of the BTS7960 or battery to the Arduino. You also don't connect +5 from the BTS7960 or the old DC-to-DC voltage converter to the Arduino. The Arduino must have its own power supply, either through a separate battery or an *isolated *DC-to-DC voltage converter.


----------



## adamson (Mar 2, 2014)

electricpolo and Ovaltineo thanks for yours support.


----------



## electricpolo (Mar 15, 2011)

I have made a second isolator board with the same results of no motor drive.
These are the opto-isolators I used in both cases 
https://au.rs-online.com/web/p/opto...5522677633D4E4F4E45267573743D3831372D32363826
I suspect the opto-couplers I bought are the culprit.
The first scope pic is the opto output to S1.
The second scope pic is the opto input from TX1 before the 220 ohm resistor.
The settings on the scope were left the same for both pictures & the clone was left in the same position.


----------



## revwarguy (Oct 7, 2014)

Hello all,

What great tech you folks are doing! I am in love with the idea of making one of these, am no stranger to arduinos, metal working, motor control, etc.,so I totally get the fun of building them and I know I would have a ball doing so. 

However, I have seen something that disturbs this train of thought. I saw a post where a builder (he completed one, I believe, and used it) said that DIY Segways are just too fragile to use, that you always feel like you're walking on ice, are dangerous, and that they (unlike the brand name Segways) are just not practical to use to get somewhere.

So, my question is to those who have actually built one and ride these, is just how practical are they? I see videos with kids doing it, but I also see the videos where folks are definitely being very cautious with them. Perhaps this is just because they always video their maiden ride?

I do not mean to damper anyone else's enthusiasm here, but I really would like something I can use reliably, regardless of the fun I_ know_ I would have in just building it. I do understand the experimental nature of these things, so I don't mind putting in effort, but I just want to know how practical others have found them to be as a transport.

If the answer is a resounding yes! they are indeed practical, then what is the current thinking on the most reliable way to go - Mega, Sabertooth, MPU6050 (1 or 2 or pot?) with what motors and batteries? 

Also, if the answer is yes, I promise to read the entire thread before asking another question!

TIA,


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> I have made a second isolator board with the same results of no motor drive.
> These are the opto-isolators I used in both cases
> https://au.rs-online.com/web/p/opto...5522677633D4E4F4E45267573743D3831372D32363826
> I suspect the opto-couplers I bought are the culprit.
> ...


Your mechanical workshop is top notch but your oscilloscope is not the best . I was hoping you had a digital oscilloscope. Anyway, did you use the Arduino ground when measuring TX1 and the Roboclaw ground when measuring S1? The second picture (TX1) doesn't look right at all.

The specs on your optocoupler is fine. Can you post pics of your built circuit showing component and underside?


----------



## electricpolo (Mar 15, 2011)

I'm much more mechanically minded & I muddle through electronics. A friend of mine may have a digital scope.
I changed grounds when measuring. Will post pics later today.


----------



## Ovaltineo (Jul 18, 2013)

revwarguy said:


> Hello all,
> 
> What great tech you folks are doing! I am in love with the idea of making one of these, am no stranger to arduinos, metal working, motor control, etc.,so I totally get the fun of building them and I know I would have a ball doing so.
> 
> ...


The straight answer is no - they are not a reliable means of transport. They are inherently unsafe because it needs to balance (you fall off when it can't) and it doesn't really have brakes that you can use when things go wrong. That's why the real Segway is over-engineered to have two of everything, including CPU, motor controllers, and even motor windings -- and they still fail. Even cars don't have this redundancy. 

I've re-built mine three times and I am still not confident that the MOSFETs will fail open and catapult me forward or much worse, fail closed and go haywire. Both cases have happened to me a couple of times! Because of this, I wouldn't use it on the open road. Not yet anyway.

The key is to get a good motor controller. I've been using a pair of cheap BTN7960 modules, but they have been failing at high load. I've now got a Roboclaw HV 2x60. It seems tough but it is electrically noisy. A separate power supply and opto-isolators fixes this. 

Anyway, if the danger doesn't discourage you, I recommend a Mega, HC06 bluetooth module, 2 X MPU6050, Roboclaw HV 2X60, 2 X 12V SLA batteries (at least 18AH each), isolated DC-to-DC converter, and optocouplers. Get wheelchair motors if you can (saves a lot of work on mechanics) -- pancake gearbox are the best coz they don't stick out. Otherwise, 300W to 500W 24V motors are recommended.


----------



## revwarguy (Oct 7, 2014)

Ovaltineo said:


> The straight answer is no - they are not a reliable means of transport. They are inherently unsafe because it needs to balance (you fall off when it can't) and it doesn't really have brakes that you can use when things go wrong. That's why the real Segway is over-engineered to have two of everything, including CPU, motor controllers, and even motor windings -- and they still fail. Even cars don't have this redundancy.


Thanks, Ovaltineo, for the honest and candid reply. I have experienced machine failures of another mode of transport that is also inherently dangerous, needs to balance to succeed, and has many single points of failure - the bicycle. The results we'ren't good there, either, but I still use one once in a while. I had to smile at the reference to "Even cars don't have this" - the modern auto is a rolling cathedral to single points of failure - but I think we might agree they've worked out most of the kinks. (I have a master's degree in aviation systems safety and I used to calculate reliability and failure rates - not trying to blow my horn here, just saying that I get it.)



Ovaltineo said:


> I've re-built mine three times and I am still not confident that the MOSFETs will fail open and catapult me forward or much worse, fail closed and go haywire. Both cases have happened to me a couple of times! Because of this, I wouldn't use it on the open road. Not yet anyway.


The use I have in mind is at an airport - they are sprawling, have lots of paved surface, and they abhor debris on it. I would think this is an ideal environment for the beast to roam. I admit the prospect of being thrown forward onto the pavement is a bit daunting - I read somewhere where one DIY Segway builder named his project the FP-1000, anticipating that he would have to experience a "face plant" that many times! BTW, why isn't a deadman switch to a solenoid across the motor batteries enough to prevent the "go haywire" syndrome - oops, I promised not to ask questions before I finish the thread. 

Ideally, in systems safety science, a System Hazard Analysis would be done first, before design starts, that identifies all the possible hazards and their severity. Then after the initial design, a Failure Mode Effects Analysis would be done to list all the possible causes of failure for each subsystem, down to the components. (Remember in those astronaut movies when something blows up on the spacecraft and the geeks back in mission control start furiously flipping through computer printouts? They are looking through their FMEA and Fault Trees that will list all the possible causes for that particular failure, which tells them which scenario is the most probable, all worked out in advance.)

Failure rate data for components here is going to be hard to get, either theoretical or experiential, and probably no one in the loop is doing actual engineering calculations on loads, etc. Not being judgemental here, I certainly do my share of TLAR engineering on a daily basis. However, anecdotal experience can be revealing over time. When a controller failure occurs, does anyone contact the vendor for a failure mode discussion? Often the vendor is quite interested in that, once you get past warranty/repair issues.



Ovaltineo said:


> The key is to get a good motor controller. I've been using a pair of cheap BTN7960 modules, but they have been failing at high load. I've now got a Roboclaw HV 2x60. It seems tough but it is electrically noisy. A separate power supply and opto-isolators fixes this.


This begs another question about experience with the Sabertooth vs Robo, but that's another question. FWIW, though, I see over in the remote control lawn mower builders circle that they favor the Sabertooth over the Robo for their own experiential reliability reasons, but that is also anecdotal. They have the same problem - they use wheelchair motors and use an arduino for control, etc and they move similar loads.



Ovaltineo said:


> Anyway, if the danger doesn't discourage you, I recommend a Mega, HC06 bluetooth module, 2 X MPU6050, Roboclaw HV 2X60, 2 X 12V SLA batteries (at least 18AH each), isolated DC-to-DC converter, and optocouplers. Get wheelchair motors if you can (saves a lot of work on mechanics) -- pancake gearbox are the best coz they don't stick out. Otherwise, 300W to 500W 24V motors are recommended.


Again, thanks a lot for the info here. Perhaps this is an unnecessary risk for me, but I haven't been scared off quite yet - I think I'll finish the thread! Any other threads/sites/groups you think I should look at? (oops, sorry about that!)


----------



## Ovaltineo (Jul 18, 2013)

revwarguy said:


> The use I have in mind is at an airport - they are sprawling, have lots of paved surface, and they abhor debris on it. I would think this is an ideal environment for the beast to roam.


I don't think you'll have a problem in an airport. My clone suffers heavy load because I live in a steep hill. The surge current is worst when I'm going downhill and trying to "engine brake".


> When a controller failure occurs, does anyone contact the vendor for a failure mode discussion? Often the vendor is quite interested in that, once you get past warranty/repair issues.


The BTN7960 modules I'm talking about are generic $14 controllers I get from eBay vendors based in China. There is no support from them whatsoever.


> This begs another question about experience with the Sabertooth vs Robo, but that's another question. FWIW, though, I see over in the remote control lawn mower builders circle that they favor the Sabertooth over the Robo for their own experiential reliability reasons, but that is also anecdotal. They have the same problem - they use wheelchair motors and use an arduino for control, etc and they move similar loads.


Roboclaw is different. They are based in the US and support is absolutely top-notch. They have examined my custom code and given advice on where it will go wrong. They also try to identify which components would be affected by noise and advice on how to avoid it. Best of all, they will replace/repair busted boards.

I have not heard of anyone singing praises about Sabertooth support or warranty in this thread. Feature-wise, I believe it is an inferior product compared to the Roboclaw - the resolution (+- 128) is very limited (vs +-1500 for Roboclaw), there is no telemetry (voltage, temperature), and there is no support for speed encoders.


----------



## Ovaltineo (Jul 18, 2013)

I have just released v7.0 of the Arduino code. This MAY fix locking issues.


> v7.0
> Added voltage and temperature sensing through Roboclaw serial commands.
> Replaced standard blocking Wire library with non-blocking I2C module. Hopefully, this fixes locking of the Arduino!!!
> Added timeout when waiting for data from Bluetooth interface.
> Added support for WTV020 Voice module on Serial port #2.


----------



## electricpolo (Mar 15, 2011)

Thanks Oval,
I'll give it a try soon. Been really busy & haven't even had the time to get my friend's better scope yet. 
I still want to get the opto-isolating sorted. It bugs me not knowing why it isn't working.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Thanks Oval,
> I'll give it a try soon. Been really busy & haven't even had the time to get my friend's better scope yet.
> I still want to get the opto-isolating sorted. It bugs me not knowing why it isn't working.


Don't worry about the scope. Just post clear closeup pics of the component side and circuit side of your board.


----------



## electricpolo (Mar 15, 2011)

Here is the small opto-coupler test board I made. The one on my Arduino shield is made the same way and give the same pattern on the scope.
TX1 is yellow.
Arduino Gnd is brown.
RX1 is orange.
Arduino 5V is red.
Controller 5V is blue.
S1 is grey.
Controller Gnd is purple.
S2 is white.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Here is the small opto-coupler test board I made. The one on my Arduino shield is made the same way and give the same pattern on the scope.
> TX1 is yellow.
> Arduino Gnd is brown.
> RX1 is orange.
> ...


I don't know if it is just the lighting, but the resistor from TX1 doesn't look like it is 220 ohms. Is it?


----------



## Ovaltineo (Jul 18, 2013)

I've done more testing this weekend of my new Roboclaw 2X60A HV. I get the occassional I2C error (under heavy load), but it doesn't lock anymore with my v7.0 code . So now, I can go high speed and found it a bit fidgety. So, I've modified the code to make it more stable at high speed. I also added another feature that compensates for banked terrain (if you are using 2 X MPU6050). These are now in the new release v7.1.



> v7.1
> Gyro and accelerometer are now both used to compute steering angle (more stable at high speed).
> Added SUBTRACT_BANK_ANGLE option to compensate for terrain banking (available only if using MPU6050_X2_STEERING).


----------



## electricpolo (Mar 15, 2011)

I'll check on that resistor to be sure.
Are you using opto-isolators with 7.0 or 7.1?


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> I have just released v7.0 of the Arduino code. This MAY fix locking issues.


Non-locking code works with bts 7960?  Optoisolation is still needed?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> I'll check on that resistor to be sure.
> Are you using opto-isolators with 7.0 or 7.1?


I am using opto isolators with both. The Roboclaw HV is too noisy without them.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Non-locking code works with bts 7960?  Optoisolation is still needed?


Yes, non-locking code will work with all controllers. You can probably get away without optoisolation with the BTS controllers. Give it a go.


----------



## electricpolo (Mar 15, 2011)

Measured both resistors & they are 220 ohms on TX1 & S2 and 1K on the pull downs.
Can you post a couple of pics of what you have done.


----------



## Ovaltineo (Jul 18, 2013)

Here's my prototype board that plugs on top of the Arduino Mega. 

Underneath the Bluetooth module is a PIC 18F1320 microcontroller which drives the WTV020 sound module. The Mega communicates with this "coprocessor" on Serial port #2. So, in addition to the beeps, I have an audio announcement that says "Max motor", "I2C error", "Max angle", etc.


----------



## electricpolo (Mar 15, 2011)

Now that's getting flashy - a talking clone!!
Still haven't got my isolators sorted.
I changed to Serial2 just in case there was an issue with Serial1 but the wave form was exactly the same.
Tried a couple of other 4N35 optos but still no result.
Am getting my friends better dual channel analogue scope tomorrow which may help.
Also thinking about a Hantek USB digital scope for my laptop to help me see things better.
Is your Arduino running an isolated power supply or are you just isolating the S1 & S2 wires?


----------



## Ovaltineo (Jul 18, 2013)

The Arduino is running off a separate battery until my isolated dc-to-dc power module arrives.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Tried a couple of other 4N35 optos but still no result.
> Am getting my friends better dual channel analogue scope tomorrow which may help.
> Also thinking about a Hantek USB digital scope for my laptop to help me see things better.
> Is your Arduino running an isolated power supply or are you just isolating the S1 & S2 wires?


Instead of your isolated DC-to-DC converter, can you please try a separate 12V battery? Or even try the old non-isolated DC-to-DC converter.


----------



## electricpolo (Mar 15, 2011)

I was going to try exactly that and get back to a stage where it works even with errors. Then go forward 1 step at a time until I find the problem.


----------



## electricpolo (Mar 15, 2011)

Do you think it would be worth adding a Schmitt trigger to the opto output to sharpen up the switching?

My troubleshooting.
I have borrowed a dual channel scope much faster than mine. 
Removed the optos totally, connected TX1 direct to S1, RX1 to S2 & Robo logic ground to Arduino ground.
Yes, I know there is no isolation at all but the Arduino & the RoboClaw are working together again. There are some random I2C errors but no lockups with the new code.
Now onto the opto circuit.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Do you think it would be worth adding a Schmitt trigger to the opto output to sharpen up the switching?
> 
> My troubleshooting.
> I have borrowed a dual channel scope much faster than mine.
> ...


Try changing the 1K resistor to 220 ohms. I think this will switch faster (but draw more current).


----------



## saekeaton64 (Oct 10, 2014)

First I would like to say "Thank You" to everyone who has posted here, Ovaltine you have done a great job with the testing and coding.

I have read through the forum 3-4 times trying to understand everything that has happened since the beginning.

I am also trying to build a clone.
My parts:
1- Funduino UNO
2- MPU-6050'S ( 1 for direction, 1 for steering)
1- Sabertooth 2x25 motor controller
Code v7.1

I have connected the gyros and uploaded the code; everything looks good on the serial monitor. The problem I am having is with the packet serial with the sabertooth. I have changed the address to both 0x80 & 0x81, changed the baud from 9600 to 38400. Nothing works, the motors wont move.

Do I have to make changes to the sabertooth using the describe software?

Any help would be appreciated.


----------



## Ovaltineo (Jul 18, 2013)

saekeaton64 said:


> I have connected the gyros and uploaded the code; everything looks good on the serial monitor. The problem I am having is with the packet serial with the sabertooth. I have changed the address to both 0x80 & 0x81, changed the baud from 9600 to 38400. Nothing works, the motors wont move.


When you change the address and baud where do you do it? In the Sabertooth DIP switch? My Arduino code? Or both? The answer should be "both" or it won't work.

Can you please post a picture of your DIP switch, and SegwayClone.h?

Are you using separate power supplies for the Roboclaw and Arduino? If yes, then you need to connect the grounds together, or use an optoisolator to connect them together.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> OK, I think I have found the problem. I just don't know how to fix it yet.
> Unlike the input, the optocoupler output isn't a reasonably clean square wave.
> The bottom channel is the opto input & the top channel is the opto output.


I found this in my email but not in the thread - it got lost somehow. Can you post the picture again? I think the fix is to replace the 1K with a lower value - try 220 ohms.


----------



## electricpolo (Mar 15, 2011)

I deleted the last post because I wanted to double check the probes first.
Here are the pics with a 4N35 opto.
The first one with the trace at the top is the TX1 output before the 220 ohm resistor. Nice & clean.
The second one with the trace at the bottom is the optocoupler output not connected to the RoboClaw. The pull down resistor is a 330 ohm.
The third picture shows both traces together.
I have also done a short video http://youtu.be/Tci2aK3OAIY
The RoboClaw is quite happy getting the top signal & works fine but doesn't play ball with the bottom signal at all. 
The status LED shows it receiving data but the drive section doesn't start.
I've now got a couple of 6N137 optos to fool around with too.


----------



## electricpolo (Mar 15, 2011)

*Re: Initial Success*

I tried a 4N38 instead of the 4N35 & got a better output trace but still not very clean.
I made up another circuit using a 6N137 opto, hooked it up to the Arduino & the scope. What a difference!!
Input & output were identical and nice & clean. 
I then soldered the S1 lead onto the RoboClaw & hey presto - the wheels started moving.
This is the circuit I made up along with a picture of the scope trace.
I also made another short video here http://youtu.be/qJt5VNfNAic of the scope trace & the wheels responding. 
Getting my hands on a dual trace scope made troubleshooting that much easier.
The motor speed is limited to 20% at the moment.
Tomorrow I'll hookup the laptop & check for I2C errors but I am cautiously very optimistic.
I'll then make up another 6N137 going the other way for the S2 comms back to the Arduino.


----------



## saekeaton64 (Oct 10, 2014)

Problem solved, the DIP switch on the sabertooth is set at (1 & 2 down, then 3-6 up) the baud is set at 9600 and the address at 0x80. The problem was that I didn't have the 0v on the sabertooth connected the the ground of the arduino. Once the ground was connected the motors started working as they should.
Again, thanks.


----------



## Ovaltineo (Jul 18, 2013)

saekeaton64 said:


> Problem solved, the DIP switch on the sabertooth is set at (1 & 2 down, then 3-6 up) the baud is set at 9600 and the address at 0x80. The problem was that I didn't have the 0v on the sabertooth connected the the ground of the arduino. Once the ground was connected the motors started working as they should.
> Again, thanks.


Are you using power supplies or just one? If just one, then that suggests that the Sabertooth has a logic ground that is isolated from the battery ground.

I suggest using a higher baud rate to get a faster response time.


----------



## Ovaltineo (Jul 18, 2013)

*Re: Initial Success*



electricpolo said:


> I tried a 4N38 instead of the 4N35 & got a better output trace but still not very clean.


My white 4N38As work perfectly. There must be a difference between manufacturers. In any case, well done and we expect to see a "maiden voyage" video soon .


----------



## electricpolo (Mar 15, 2011)

Hooked up the laptop to check for I2C errors. They are still there however when the wheels are running at a constant speed or the handle bar is moved gradually or the board tilt changes from positive to negative slowly, there are no errors.
I2C errors only seem to happen when either the handlebar is moved rapidly from side to side or the direction of the wheels changes rapidly from forwards to backwards or the speed increases rapidly.
The I2C errors seem to be something that is unique to the RoboClaw HV. I have emailed the manufacturers to see if they have any suggestions.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hooked up the laptop to check for I2C errors. They are still there however when the wheels are running at a constant speed or the handle bar is moved gradually or the board tilt changes from positive to negative slowly, there are no errors.
> I2C errors only seem to happen when either the handlebar is moved rapidly from side to side or the direction of the wheels changes rapidly from forwards to backwards or the speed increases rapidly.
> The I2C errors seem to be something that is unique to the RoboClaw HV. I have emailed the manufacturers to see if they have any suggestions.



See if you can get a firmware with a much lower (audible) PWM rate (I tried). I didn't insist because I now only get the occassional I2C error when under heavy load - e.g. going up a steep incline or stepped edge. I notice that the placement of wires can increase or almost eliminate the errors.


----------



## Ovaltineo (Jul 18, 2013)

I am now very happy with my clone setup. In the OFF position, my power switch (DPDT) puts the two 12V batteries in parallel and available through a charging plug. I then use a multi-chemistry RC charger set to charge them at 2.5A. The RC charger gets powered by 2 X 40Ah 12 V batteries in parallel. To be totally environmentally friendly, those batteries are charged by 40W + 20 W solar panels in my garage - free electricity . That's the first picture below. The second picture is my 3KW solar panel that powers the whole house -- I never pay electricity bills, I actually get $400/year credit for the excess electricity I put back on the grid .


----------



## electricpolo (Mar 15, 2011)

What firmware version is your HV? I don't care about a PWM whine.
Can you post a photo that shows your Arduino & RoboClaw placement with the wire layout as best as possible so I can compare it to mine.


----------



## Ovaltineo (Jul 18, 2013)

I don't know what version it is - it is stock. I asked for a firmware with a lower PWM frequency but didn't get it.

Here are some pics showing how it is wired. Not very clean but I tried to keep the power lines away from (and perpendicular to) the logic lines (especially the I2C line from arduino to steering MPU6050).


----------



## electricpolo (Mar 15, 2011)

Thanks for the pics. If you hook the RoboClaw up to a computer with their IonMotion software, it will tell you the firmware version number.


----------



## electricpolo (Mar 15, 2011)

*Re: Cautiously Optimistic*

Nathan from Basic Micro felt that it was a pullup too high issue.
Some time ago I had removed the pullup resistors from the OpenJumper MPU's which gave a pullup resistance of 10K (Mega external pullups). I can't remember what values they were (either 2.2K or 4.7K).
I was getting I2C errors with them on the sensors but taking them off didn't really seem to change anything either.
Nathan recommended a total of 1.5K pullup after seeing my wave form. I have put a couple of 1.8K resistors in parallel with the Mega external ones and put them between the SCL & SDA pins & the Arduino 5V pin.
The scope shows a pretty reasonable wave form and a bench test with up to 2/3 full power, rapidly changing forward reverse direction and/or rapidly changing the steering direction produced no I2C errors in the serial monitor.
Previously, there would have been heaps of them.
I am going to do a couple of ground tests tomorrow but I am cautiously optimistic that the problem has been solved by having the right value pullups and having them nice & close to the Mega SDA & SCL lines.
In theory, resistors in parallel can be pretty much anywhere but it seems to make a big difference with an I2C bus in a noisy environment by having pullup resistors at both ends of the wire vs having them only at the Arduino end.


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> I have just released v7.0 of the Arduino code. This MAY fix locking issues.


v7.0
Added voltage and temperature sensing through Roboclaw serial commands. 
Replaced standard blocking Wire library with non-blocking I2C module. Hopefully, this fixes locking of the Arduino!!!
Added timeout when waiting for data from Bluetooth interface.
Added support for WTV020 Voice module on Serial port #2.

It's great idea, I've got wtv020 module and amplifier .
I didn't know what a lot of beeps means. This working module would be very helpfull for me.
Is there wire diagram or arduino library included to segway clone code?


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> I am now very happy with my clone setup. In the OFF position, my power switch (DPDT) puts the two 12V batteries in parallel and available through a charging plug. I then use a multi-chemistry RC charger set to charge them at 2.5A. The RC charger gets powered by 2 X 40Ah 12 V batteries in parallel. To be totally environmentally friendly, those batteries are charged by 40W + 20 W solar panels in my garage - free electricity . That's the first picture below. The second picture is my 3KW solar panel that powers the whole house -- I never pay electricity bills, I actually get $400/year credit for the excess electricity I put back on the grid .


Green energy is great for me. Is it Your own work?


----------



## Ovaltineo (Jul 18, 2013)

*Re: Cautiously Optimistic*



electricpolo said:


> Nathan from Basic Micro felt that it was a pullup too high issue.
> Some time ago I had removed the pullup resistors from the OpenJumper MPU's which gave a pullup resistance of 10K (Mega external pullups). I can't remember what values they were (either 2.2K or 4.7K).
> I was getting I2C errors with them on the sensors but taking them off didn't really seem to change anything either.
> Nathan recommended a total of 1.5K pullup after seeing my wave form. I have put a couple of 1.8K resistors in parallel with the Mega external ones and put them between the SCL & SDA pins & the Arduino 5V pin.
> ...


How did you go with the ground tests? I hope you were wearing a helmet, gloves, and shin pads.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> v7.0
> Added voltage and temperature sensing through Roboclaw serial commands.
> Replaced standard blocking Wire library with non-blocking I2C module. Hopefully, this fixes locking of the Arduino!!!
> Added timeout when waiting for data from Bluetooth interface.
> ...


Its a bit complicated, hence I haven't posted details of the WTV020 module.

The Arduino is not driving the WTV020 directly. The WTV020 library is synchronous and blocking -- I cannot use it with the Segway code which needs to cycle every 10ms. Hence, I have programmed a Microchip 18F1320 microcontroller to handle the WTV020 driver. The Arduino simply sends a one byte command to it (via Serial #2) containing the file number to play. Let me know if you would like to go down this path and I wiill post the schematic and firmware. You would need an 18F1320, a Microchip PIC programmer, and a v1.5 WTV020 module. The WTV020 module itself is fiddly - it works only with certain micro SD cards.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Green energy is great for me. Is it Your own work?


I only installed the 60W solar panels. The 3KW solar panels were installed by a licensed electrician because it is connected to the grid.


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Its a bit complicated, hence I haven't posted details of the WTV020 module.
> 
> The Arduino is not driving the WTV020 directly. The WTV020 library is synchronous and blocking -- I cannot use it with the Segway code which needs to cycle every 10ms. Hence, I have programmed a Microchip 18F1320 microcontroller to handle the WTV020 driver. The Arduino simply sends a one byte command to it (via Serial #2) containing the file number to play. Let me know if you would like to go down this path and I wiill post the schematic and firmware. You would need an 18F1320, a Microchip PIC programmer, and a v1.5 WTV020 module. The WTV020 module itself is fiddly - it works only with certain micro SD cards.


Yes, I'm very interested  I'm buying Pic programmer and 18F1320 right now!


----------



## Ovaltineo (Jul 18, 2013)

Here's the WTV020 schematic and 18F1320 firmware.


----------



## Borc (Mar 12, 2014)

Ovaltine could you post some more information on HX711 weight sensor connection.
I have one from some other project (never finished) and would like to implement it.


----------



## Ovaltineo (Jul 18, 2013)

For HX711, add the following lines to SegwayClone.h

#define HX711_DOUT A7
#define HX711_SCK A6
#define HX711_MIN 50

Your clone would need to have a lid with a small portion of the lid *lightly* resting on the weight sensor. I have a 10 kg weight sensor and I use a double sided tape as a cushion so that the lid is never completely resting on it. Using a serial monitor, watch the weight when there is no rider and when there is a rider. Adjust HX711_MIN so that it is halfway between the two weights.


----------



## Borc (Mar 12, 2014)

Thanks Ovaltine,

will be possible to adjust P and D value based on weight range detected for different raiders (optimal values from table measured before). I can see that clone is clearly more responsive when my son is riding it ( about 70 Kilo difference ).
Or this is just nonsense and there will be problems during the ride ( not wanted complexity).


----------



## Ovaltineo (Jul 18, 2013)

Borc said:


> Thanks Ovaltine,
> 
> will be possible to adjust P and D value based on weight range detected for different raiders (optimal values from table measured before). I can see that clone is clearly more responsive when my son is riding it ( about 70 Kilo difference ).
> Or this is just nonsense and there will be problems during the ride ( not wanted complexity).


I will see if I can get something that will work reliably. The main problem is that the measured weight changes significantly when moving.


----------



## mantissa (Jun 30, 2014)

HI all,

Just wanted to close the loop on an earlier posting that I made when I was bemoaning the strange behaviour we were experiencing with our Segway clone.

When assisting my son with this project, I said early on that when buying key parts for the project, it never made sense to buy just one, always buy three if you possibly can. Of course, for parts that cost a couple of pounds, this is not an issue, but for things like the Sabertooth, that strategy is costly to follow....

Quick recap; while the machine was fully functional, it would also display some strange behaviour on startup, *most* times it was powered up. It would manifest itself as errant 'jerks' coming from the motors being inappropriately driven. To the experienced eye, it seemed like some sort of interference, were it not for the fact that after a minute or two it would usually calm down.

I thought it might be due to the elevated power levels that result from a freshly charged battery stack, but even when not charged between uses it would also occur. I tried speeding up the comms to the Sabertooth from the Mega, no joy. Then it was a case of trying all sorts of anti-interference measures, ranging from looking at wire routing to shielding tape and earth bonding. Isolating the Arduino from the Sabertooth was next, with isolated power converter and opto-isolators in the comms. Still no joy.

Finally, I bit the bullet and bought a replacement for the only the part that we only had one of - the Saberooth. It was fitted and.....everything became lovely and perfect again. I wish I knew what was wrong with the Sabertooth and indeed, how it happened, but for now, I'm just relieved that it's working reliably again.

My son completed this for a project which he can submit for assessment, so now that it is reliable again, it's a huge sigh of relief all round. here's a video that he submitted to support the project submission... https://www.youtube.com/watch?v=Mmv81OG22ew

Many thanks again for all the great work that Ovaltineo and the community here have contributed to this great project. Even when the issues which are aired here aren't relevant to our design, it's always informative and thought provoking to consider what the issues are....


----------



## Ovaltineo (Jul 18, 2013)

@mantissa, you are most welcome and I am glad to have helped in your son's project .


----------



## electricpolo (Mar 15, 2011)

Well, I am just about ready to throw the RoboClaw HV into the bin.
I have full opto isolation between the Arduino & RoboClaw.
Full DC DC isolation to Arduino from battery & RoboClaw.
Ferrites on everything including power wires to DC DC converter. (really need it here)
Pullup resistance of 1.5K close to SCL & SDA. No resistors on the sensors.
All cables shielded & common grounded.
Still get random I2C errors that cause the clone to jerk. The clone recovers almost instantly but it doesn't feel right.
It just doesn't go smoothly like some of the other videos I have seen.
Last thing is to put the sensors & the Arduino in aluminium boxes.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Well, I am just about ready to throw the RoboClaw HV into the bin.
> I have full opto isolation between the Arduino & RoboClaw.
> Full DC DC isolation to Arduino from battery & RoboClaw.
> Ferrites on everything including power wires to DC DC converter. (really need it here)
> ...


Try using 1K (or less) pull up. 

Also, have you tried using the generic MPU6050 that everyone else is using? It has built-in 2K pull-up. I'm using 2 of them, plus an extra 2K external pull-up.


----------



## adamson (Mar 2, 2014)

Oval thanks for Your support about WTV020 schematic and 18F1320 firmware. I'm waiting for parts. 
And what about very slow response when turning left/right. I've dowloaded new 7.1 and when I want to turn right/left there is turn response after few seconds?


----------



## Ovaltineo (Jul 18, 2013)

For those looking at getting an isolated DC-to-DC converter, I bought this and it turned out to be very good and very cheap at US$10.31. Input is 18V-36V and the output is 5V at 1A - more than enough for the Arduino Mega and peripherals. Because it is 5V, it is connected directly to the 5V pin of the Arduino (not the power plug).

http://www.goodluckbuy.com/mdc5-s5c-24v-to-5v-1a-5w-dc-dc-isolated-power-module.html


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Oval thanks for Your support about WTV020 schematic and 18F1320 firmware. I'm waiting for parts.
> And what about very slow response when turning left/right. I've dowloaded new 7.1 and when I want to turn right/left there is turn response after few seconds?


Was the steering response slow with previous versions or only with v7.1? If it was slow with previous versions, just increase STEER_MULTIPLIER in SegwayClone.h - the default value for PWM_PWM_CONTROLLER is 3.5.


----------



## adamson (Mar 2, 2014)

With previous versions everything was fine. I'll try to increase this value.


----------



## electricpolo (Mar 15, 2011)

I've also noticed something odd about the steering in 7.1. Kind of delayed response then it catches up too quickly. Makes the steering very erratic.
Had to more than halve the Steer Multiplier just to make it controllable for the ground test.
Was very smooth previously. Will try 7.0 today. 
Can't try anything earlier as I need the non-locking version.


----------



## silveradoss1 (Sep 21, 2013)

Hey Ovaltineo, 
Have you had a chance to look a adding a motor control module for the robot power OSMC controller. I thought that the simple controllers were working better than any of the smart ones, besides the over current issues. The OSMC is rated at far more amps than I think I'll ever need for my clone. My problem is I'm terrible at writing code.
Any help would be great.
Thanks


----------



## electricpolo (Mar 15, 2011)

Version 7.0 & the steering is OK. Very linear, smooth and very predictable even with default Steer Multiplier.
Version 7.1 is very different. Steering is kind of delayed & then it seems to try & catch up. Default Steer Multiplier value is not good. Needed to at least halve it to make the clone sort of controllable on a ground test with no rider. 

The other day after reassembling everything, there were a lot of I2C errors on a bench test. I noticed that I had forgotten to put a ferrite on the power wires to the DC DC converter. When I clipped the ferrite on, the errors reduced to single random ones.
Nathan at Basic Micro suggested putting 100uF caps on the input & output of the DC DC converter. This seems to have helped a bit more.
He thinks that the problem is conducted noise.
It is almost rideable now.
Going to try lowering the pullups a bit more next.


----------



## electricpolo (Mar 15, 2011)

Have done a couple of tests with the motors set at 600 max.
Lowered pullup to 1.1K then to 820 ohms. Marginal (if any) difference.
Am still getting random I2C errors which make the clone jerk.
It's a whole lot better than it was though.


----------



## Ovaltineo (Jul 18, 2013)

I found a bug in the 7.1 code which wrecked the steering . I didn't see it with my own testing because my steering sensor is mounted vertically (using different axis for gyro) to make it fit in the available space in my clone. I have fixed it in 7.2.

I suggest trying the steering with and without the #define SUBTRACT_BANK_ANGLE option. It will make a difference when driving over banked terrain.

I have also added support for OSMC without MOB. Schematic will follow soon.


```
v7.2
Fixed inverted steering angle gyro and bank angle gyro.
Added support for OSMC (Open Source Motor Controller) without MOB (Modular OSMC Brain) - #define OSMC_CONTROLLER.
Added option for exponential steering response - #define EXPONENTIAL_STEER_DIVIDER
```


----------



## Ovaltineo (Jul 18, 2013)

silveradoss1 said:


> Hi,
> Digikey in the US has a dc/dc converter with a input of 8v-42v with output of 5v at 1 amp for $8.79 and there shipping is pretty cheap.
> 
> http://www.digikey.com/product-detail/en/R-78C5.0-1.0/945-1395-5-ND/2652148



That is actually expensive for a non-isolated converter. The one I mentioned in post #1171 is fully isolated.


----------



## Ovaltineo (Jul 18, 2013)

For anyone wanting to build a unicycle Segway, *markula* has posted an article on instructibles.com - http://www.instructables.com/id/Electric-unicycle-Arduino-DIY. It uses the same code as the ordinary clone.


----------



## electricpolo (Mar 15, 2011)

Ovaltine,
Have I got this syntax right to use RoboClaw command 52 & 53 - signed duty with a fixed acceleration of 50%.

byte packet[6];
packet[0] = ROBOCLAW_ADDRESS;
packet[1] = command;
packet[2] = param >> 8; // MSB
packet[3] = 32767;
packet[4] = param & 0xFF; // LSB
packet[5] = (packet[0]+packet[1]+packet[2]+packet[3]+packet[4]) & 0x7F;
Serial1.write(packet, sizeof(packet));

I could change the acceleration ramp by changing the constant value of packet 3.
Almost have it right now with 66% power (on the bench anyway). Ground test tomorrow.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Ovaltine,
> Have I got this syntax right to use RoboClaw command 52 & 53 - signed duty with a fixed acceleration of 50%.
> 
> byte packet[6];
> ...


Not quite. Try this:

byte packet[7];
unsigned short acceleration=32767;

packet[0] = ROBOCLAW_ADDRESS;
packet[1] = command;
packet[2] = param >> 8; // duty MSB
packet[3] = param & 0xFF; // duty LSB
packet[4] = acceleration >> 8; // accel MSB
packet[5] = acceleration & 0xFF; // accel LSB
packet[6] = (packet[0]+packet[1]+packet[2]+packet[3]+packet[4]+packet[5]+packet[6]) & 0x7F;
Serial1.write(packet, sizeof(packet));

I have added this in the next version.


----------



## Ovaltineo (Jul 18, 2013)

Borc said:


> Thanks Ovaltine,
> 
> will be possible to adjust P and D value based on weight range detected for different raiders (optimal values from table measured before). I can see that clone is clearly more responsive when my son is riding it ( about 70 Kilo difference ).
> Or this is just nonsense and there will be problems during the ride ( not wanted complexity).


I've added the following option in v7.2. Add it to SegwayClone.h.

#define HX711_REFERENCE_WEIGHT 940 // optional weight of rider where static P & D are based on. If defined, P & D are computed proportional to rider's weight


To set the correct value for this parameter, use the weight reported in the serial monitor while you (the heaviest rider) are balancing on the clone. In my case, it is 940. When my son rides the clone, P and D are reduced based on the ratio of his weight/my weight. So that it is not affected by fluctuations while riding, it uses the weight sampled 3 seconds after the rider is detected.


----------



## Borc (Mar 12, 2014)

Thanks Ovaltine, that's great !


----------



## electricpolo (Mar 15, 2011)

Thanks Oval,
The commands 52 & 53 with acceleration may not be needed. Was something to try if other measures didn't work.
Nathan had suggested the possibility of using it to slow the controller speed changes from forward to reverse as it would reduce the spike exponentially although he has said to go no lower than 15000.

It is looking like my error problems are solved (on the bench at least). Ground test maybe today to confirm.
Have been working with Nathan at Basic Micro on troubleshooting. The major difference between yours & mine is mine is all steel whereas yours is substantially timber. My chassis was conducting most of the noise.
The solution so far has been quite simple but getting has been a bit of a trial.

Left the ferrites on the motors because they were too fiddly to take off.
Put 100uF electrotytics across DC DC converter input & output.
Put 1 ferrite on the RoboClaw comms cable really close to the S1, S2 pins.
Chassis was grounded back to the RoboClaw battery negative.
I2C sensor cable shields & the RoboClaw comms cable shield were routed through a small ferrite & grounded back to the negative input of the DC DC converter.
Hey presto, no errors at 66% power bench testing moving board & steering very rapidly.
S3 still needs a pullup resistor as I have had a couple of erroneous e-stops.


----------



## Ovaltineo (Jul 18, 2013)

I new member has found a bug with the UNO schematics. I had XDA and XCL from the steering MPU6050 connected instead of SDA and SCL. I have fixed the schematics. In any case, I recommend using the MEGA if you want to use Bluetooth.


----------



## adamson (Mar 2, 2014)

Ovaltineo, what about files names on sd card? Is it 0101.ad4 and so on? Do you use 2GB card?


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
I've notices that your P & D values for the RoboClaw are .96 & 1.2 respectively instead of the default 3.9 & 1.5.
How are you finding your settings?
Can anyone else using a RoboClaw or Sabretooth post their settings.


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Ovaltineo, what about files names on sd card? Is it 0101.ad4 and so on? Do you use 2GB card?


Here's the zipped file. 0001.AD4 is a startup/test message. I am using 1GB Nokia card. As I've said before, this module does not work with all cards. You will have more luck with an old, slow card than a new card. Check out this discussion http://forum.arduino.cc/index.php?topic=117009.0. Make sure you are using v1.5 module and that you unsolder the 3.3V link and solder the 5V link.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> I've notices that your P & D values for the RoboClaw are .96 & 1.2 respectively instead of the default 3.9 & 1.5.
> How are you finding your settings?
> Can anyone else using a RoboClaw or Sabretooth post their settings.


 The higher default P & D values will probably be OK for those using wheelchair motors. I think you will find that even my P & D values will be too high for your setup. My gearing is higher than yours and my wheels are smaller too. The Sabetooth P & D values will be vastly different because the motor range is -128 to +128 vs -1500 to 1500.


----------



## electricpolo (Mar 15, 2011)

Have done a ground test with the power first at 30% & then at 40% and no errors at all were evident. It is very easy to feel then they happen even though the clone recovers & keeps going.
I am playing with the PD settings and with no rider sensors as yet, I currently have it on 2 & .95. 
It is reasonably responsive but I think it can be better. Certainly need the 2 different settings though.

Only have one thing to check out. When quickly going from forward to stop or reverse, the left hand motor makes a noise very similar to a stepper motor missing steps. I don't think it is the belt because it's pretty tight.
Don't know if the motor controller could cause that sound or if it is a mechanical issue.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Have done a ground test with the power first at 30% & then at 40% and no errors at all were evident. It is very easy to feel then they happen even though the clone recovers & keeps going.
> I am playing with the PD settings and with no rider sensors as yet, I currently have it on 2 & .95.
> It is reasonably responsive but I think it can be better. Certainly need the 2 different settings though.
> 
> ...


It sounds like the motor controller current limiter kicking in. I have experienced this before with the BTN7960 but only when the motor gets stalled. It's weird that it happens when quickly changing directions. Try swapping the motors.


----------



## electricpolo (Mar 15, 2011)

Has your RoboClaw done a similar thing given you use the same motors?

Perhaps it's due to the different batteries. 
LiFePo's have a much higher current capacity than the more common SLA (lead acid) batteries.


----------



## Ovaltineo (Jul 18, 2013)

No, I haven't experienced it with the Roboclaw.


----------



## [email protected] (Mar 22, 2014)

```

```
Hello Oval and community

my progress


----------



## [email protected] (Mar 22, 2014)

I have this hardware


----------



## [email protected] (Mar 22, 2014)

I have this errors,



WHO_AM_I : 0, error = -32
PWR_MGMT_2 : 0, error = -32
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
Try 115200
Found bluetooth module at 115200
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32


monitor serial


----------



## [email protected] (Mar 22, 2014)

Program:


```
/*
Uncomment one MODE below
*/
//#define MODE_CALIBRATE
#define MODE_RUN

/*
Uncomment one STEERING type below
*/
//#define POT_STEERING
#define MPU6050_X2_STEERING
//#define MPU6050_X1_STEERING
//#define GY80_STEERING

//#define EXPONENTIAL_STEER_DIVIDER	7	// turns steering from linear to exponential - this specifies the angle where response is higher than linear

/*
Uncomment only if steer MPU6050 is vertically oriented
*/
//#define STEER_Z_GYRO

/*
Uncomment only if using MPU6050_X2 and you want to compensate for terrain banking
*/
//#define SUBTRACT_BANK_ANGLE		// defining this will subtract board bank angle from steer angle

/*
Uncomment only if steering left and right are inverted
*/
//#define INVERT_STEERING

/*
Uncomment one CONTROLLER type below
*/
#define PWM_PWM_CONTROLLER
//#define PWM_DIR_CONTROLLER
//#define ROBOCLAW_CONTROLLER
//#define ROBOCLAW_ENCODER_CONTROLLER
//#define SABERTOOTH_CONTROLLER
//#define PWM_SHIELD_CONTROLLER
//#define L298N_CONTROLLER
//#define OSMC_CONTROLLER

/*
Uncomment if you want to check battery voltage.  See note above for resistor divider.
*/
//#define VOLTAGE_CHECK

/*
Uncomment if you want LED Voltage indicator.  You need VOLTAGE_CHECK with this.
*/
//#define VOLTAGE_LED

/*
Uncomment if you want Pushback
*/
//#define PUSHBACK

/*
Uncomment if you have a HC06 "linvor" bluetooth module
*/
#define BLUETOOTH

/*
Uncomment if you have TC74 temperature sensors - TC74A0 and TC74A2 default addresses in TC74.h
*/
//#define TEMPERATURE_SENSORS

/*
Uncomment if you want the clone to be locked during startup.  It can only be unlocked via CloneConsole Android app.
*/
//#define LOCKED_BY_DEFAULT

/*
Uncomment if you have a rider sensor - sensor must pull this pin to GND/LOW when rider is ON, and leave it open or HIGH when rider is OFF.
Initial values are loaded from KP_OFF, KD_OFF, and MOTOR_MAX_OFF.
*/
//#define RIDER_SENSOR	8

/*
Uncomment if RIDER_SENSOR above has reverse logic, ie HIGH when rider is ON and LOW when rider is OFF
*/
//#define INVERT_RIDER_SENSOR
```


----------



## [email protected] (Mar 22, 2014)

requested your kind help please. the motors do not move..


----------



## Ovaltineo (Jul 18, 2013)

Double check your MPU6050 connection. Make sure the steer sensor has AD0 connected to +5v.


----------



## electricpolo (Mar 15, 2011)

ferco-tech,
I have a couple of suggestions.
Solder the wires from both IMU's to the Arduino. The plugs you have used will come loose & give you grief.
Shorten the motor wires as much as possible.
Increase the size of your battery cables to where you split off to the 2 controllers. The battery cables should be about double the motor wire size.


----------



## [email protected] (Mar 22, 2014)

Ovaltineo said:


> Double check your MPU6050 connection. Make sure the steer sensor has AD0 connected to +5v.


Hi oval,

You were right, defective cable.

Now I have cloneconsole data and functions. but the motors do not move.

Any ideas ???


----------



## [email protected] (Mar 22, 2014)

electricpolo said:


> ferco-tech,
> I have a couple of suggestions.
> Solder the wires from both IMU's to the Arduino. The plugs you have used will come loose & give you grief.
> Shorten the motor wires as much as possible.
> Increase the size of your battery cables to where you split off to the 2 controllers. The battery cables should be about double the motor wire size.


Hi electricpolo,

Thanks for your interest, I'll make them.

At this time, are not moving me the motors. Any ideas ??


----------



## [email protected] (Mar 22, 2014)

Question:









They are not connected anywhere?


----------



## electricpolo (Mar 15, 2011)

Where are you getting the 5V for the 2 controllers?


----------



## ferchotech (May 29, 2014)

electricpolo said:


> Where are you getting the 5V for the 2 controllers?


Hi Electricpolo, 

They are getting 5v arduino mega (pin 5v)


----------



## Ovaltineo (Jul 18, 2013)

[email protected] said:


> Question:
> 
> They are not connected anywhere?


No, the logic ground is connected internally to the battery ground. Double check your connections to the BTN controllers. 

Did you go through the calibration process? Is the machine level while you are testing? Can you please post the Serial Monitor output?


----------



## [email protected] (Mar 22, 2014)

Ovaltineo said:


> No, the logic ground is connected internally to the battery ground. Double check your connections to the BTN controllers.
> 
> Did you go through the calibration process? Is the machine level while you are testing? Can you please post the Serial Monitor output?


Did you go through the calibration process?
yes

Seriel Monitor:


```
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
Gyro   39
Gyro   30
Gyro   20
Gyro   54
Gyro   54
Gyro   34
Gyro   34
Gyro   62
Gyro   38
Gyro   45
Gyro   35
Gyro   37
Gyro   49
Gyro   37
Gyro   23
Gyro   41
Gyro   46
Gyro   46
Gyro   36
Gyro   56
Gyro   26
Gyro   34
Gyro   40
Gyro   42
Gyro   61
Gyro   36
Gyro   35
Gyro   32
Gyro   62
Gyro   48
Gyro   23
Gyro   36
Gyro   30
Gyro   37
Gyro   62
Gyro   34
Gyro   29
Gyro   27
Gyro   37
Gyro   36
Gyro   26
Gyro   43
Gyro   53
Gyro   50
Gyro   46
Gyro   30
Gyro   41
Gyro   32
Gyro   77
Gyro   43
Gyro   22
Gyro   58
Gyro   45
Gyro   34
Gyro   20
Gyro   49
Gyro   43
Gyro   52
Gyro   52
Gyro   35
Gyro   24
Gyro   56
Gyro   47
Gyro   39
Gyro   21
Gyro   39
Gyro   53
Gyro   52
Gyro   24
Gyro   28
Gyro   27
Gyro   46
Gyro   29
Gyro   44
Gyro   44
Gyro   52
Gyro   36
Gyro   33
Gyro   46
Gyro   40
Gyro   30
Gyro   46
Gyro   39
Gyro   37
Gyro   49
Gyro   22
Gyro   24
Gyro   61
Gyro   42
Gyro   45
Gyro   46
Gyro   14
Gyro   35
Gyro   30
Gyro   56
Gyro   74
Gyro   31
Gyro   55
Gyro   43
Gyro   43
Gyro   35
Gyro   52
Gyro   27
Gyro   35
Gyro   22
Gyro   39
Gyro   53
Gyro   33
Gyro   50
Gyro   46
Gyro   39
Gyro   46
Gyro   52
Gyro   38
Gyro   60
Gyro   34
Gyro   48
Gyro   65
Gyro   48
Gyro   44
Gyro   38
Gyro   47
Gyro   54
Gyro   34
Gyro   34
Gyro   50
Gyro   47
Gyro   16
Gyro   35
Gyro   27
Gyro   28
Gyro   42
Gyro   52
Gyro   13
Gyro   30
Gyro   53
Gyro   49
Gyro   35
Gyro   24
Gyro   29
Gyro   41
Gyro   34
Gyro   48
Gyro   28
Gyro   54
Gyro   35
Gyro   55
Gyro   63
Gyro   26
Gyro   44
Gyro   41
Gyro   45
Gyro   56
Gyro   60
Gyro   54
Gyro   37
Gyro   51
Gyro   45
Gyro   35
Gyro   30
Gyro   61
Gyro   50
Gyro   33
Gyro   47
Gyro   48
Gyro   39
Gyro   44
Gyro   63
Gyro   55
Gyro   69
Gyro   33
Gyro   30
Gyro   36
Gyro   26
Gyro   39
Gyro   50
Gyro   58
Gyro   33
Gyro   52
Gyro   36
Gyro   25
Gyro   60
Gyro   58
Gyro   23
Gyro   29
Gyro   51
Gyro   28
Gyro   45
Gyro   51
Gyro   65
Gyro   52
Gyro   46
Gyro   35
Gyro   28
Gyro   11
Gyro   57
Gyro   58
Gyro   33
Gyro   50
Gyro   47
Gyro   50
Gyro   44
Gyro   32
Gyro   38
Gyro   41
Gyro   26
Gyro   50
Gyro   42
Gyro   39
Gyro   39
Gyro   61
Gyro   29
Gyro   41
Gyro   55
Gyro   44
Gyro   38
Gyro   19
Gyro   30
Gyro   24
Gyro   62
Gyro   14
Gyro   56
Gyro   40
Gyro   24
Gyro   41
Gyro   61
Gyro   38
Gyro   71
Gyro   48
Gyro   36
Gyro   60
Gyro   46
Gyro   36
Gyro   32
Gyro   48
Gyro   50
Gyro   25
Gyro   47
Gyro   42
Gyro   39
Gyro   46
Gyro   23
Gyro   38
Gyro   25
Gyro   29
Gyro   32
Gyro   18
Gyro   52
Gyro   42
Gyro   42
Gyro   47
Gyro   57
Gyro   36
Gyro   52
Gyro   21
Gyro   46
Gyro   19
Gyro   28
Gyro   44
Gyro   34
Gyro   67
Gyro   42
Gyro   36
Gyro   43
Gyro   33
Gyro   46
Gyro   40
Gyro   44
Gyro   30
Gyro   21
Gyro   33
Gyro   58
Gyro   31
Gyro   47
Gyro   9
Gyro   20
Gyro   40
Gyro   30
Gyro   25
Gyro   27
Gyro   70
Gyro   37
Gyro   53
Gyro   70
Gyro   55
Gyro   44
Gyro   32
Gyro   43
Gyro   60
Gyro   34
Gyro   52
Gyro   33
Gyro   38
Gyro   48
Gyro   53
Gyro   34
Gyro   63
Gyro   29
Gyro   25
Gyro   35
Gyro   34
Gyro   65
Gyro   54
Gyro   53
Gyro   53
Gyro   46
Gyro   45
Gyro   42
Gyro   37
Gyro   57
Gyro   46
Gyro   59
Gyro   33
Gyro   41
Gyro   43
Gyro   31
Gyro   65
Gyro   41
Gyro   37
Gyro   48
Gyro   33
Gyro   26
Gyro   42
Gyro   32
Gyro   69
Gyro   32
Gyro   29
Gyro   40
Gyro   38
Gyro   15
Gyro   25
Gyro   45
Gyro   39
Gyro   16
Gyro   29
Gyro   45
Gyro   39
Gyro   55
Gyro   62
Gyro   28
Gyro   35
Gyro   49
Gyro   23
Gyro   49
Gyro   73
Gyro   32
Gyro   44
Gyro   39
Gyro   55
Gyro   39
Gyro   37
Gyro   40
Gyro   26
Gyro   38
Gyro   34
Gyro   29
Gyro   35
Gyro   40
Gyro   47
Gyro   41
Gyro   37
Gyro   27
Gyro   29
Gyro   52
Gyro   51
Gyro   25
Gyro   25
Gyro   46
Gyro   40
Gyro   46
Gyro   28
Gyro   65
Gyro   37
Gyro   29
Gyro   37
Gyro   56
Gyro   44
Gyro   53
Gyro   33
Gyro   61
Gyro   51
Gyro   29
Gyro   28
Gyro   53
Gyro   40
Gyro   21
Gyro   53
Gyro   33
Gyro   41
Gyro   24
Gyro   33
Gyro   31
Gyro   43
Gyro   49
Gyro   62
Gyro   57
Gyro   45
Gyro   61
Gyro   52
Gyro   61
X Accel Offset   1327Y Gyro Offset   41Y Gyro Min   9Y Gyro Max   77
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
Gyro   369
Gyro   398
Gyro   352
Gyro   373
Gyro   373
Gyro   339
Gyro   328
Gyro   339
Gyro   361
Gyro   369
Gyro   367
Gyro   358
Gyro   366
Gyro   365
Gyro   371
Gyro   352
Gyro   356
Gyro   356
Gyro   374
Gyro   348
Gyro   370
Gyro   358
Gyro   381
Gyro   363
Gyro   376
Gyro   334
Gyro   395
Gyro   363
Gyro   358
Gyro   377
Gyro   329
Gyro   355
Gyro   371
Gyro   350
Gyro   351
Gyro   345
Gyro   371
Gyro   364
Gyro   363
Gyro   341
Gyro   359
Gyro   342
Gyro   335
Gyro   345
Gyro   323
Gyro   351
Gyro   370
Gyro   363
Gyro   349
Gyro   343
Gyro   346
Gyro   341
Gyro   347
Gyro   353
Gyro   377
Gyro   362
Gyro   352
Gyro   359
Gyro   383
Gyro   359
Gyro   342
Gyro   369
Gyro   370
Gyro   365
Gyro   398
Gyro   346
Gyro   384
Gyro   341
Gyro   347
Gyro   348
Gyro   349
Gyro   376
Gyro   383
Gyro   357
Gyro   355
Gyro   347
Gyro   346
Gyro   367
Gyro   372
Gyro   374
Gyro   369
Gyro   356
Gyro   352
Gyro   378
Gyro   352
Gyro   354
Gyro   340
Gyro   376
Gyro   334
Gyro   378
Gyro   370
Gyro   368
Gyro   341
Gyro   355
Gyro   333
Gyro   351
Gyro   359
Gyro   369
Gyro   363
Gyro   346
Gyro   363
Gyro   342
Gyro   337
Gyro   383
Gyro   362
Gyro   373
Gyro   372
Gyro   374
Gyro   349
Gyro   346
Gyro   355
Gyro   343
Gyro   355
Gyro   381
Gyro   388
Gyro   374
Gyro   347
Gyro   352
Gyro   343
Gyro   362
Gyro   364
Gyro   358
Gyro   372
Gyro   341
Gyro   359
Gyro   350
Gyro   380
Gyro   346
Gyro   346
Gyro   356
Gyro   363
Gyro   338
Gyro   361
Gyro   367
Gyro   361
Gyro   342
Gyro   363
Gyro   353
Gyro   332
Gyro   369
Gyro   387
Gyro   344
Gyro   336
Gyro   363
Gyro   345
Gyro   358
Gyro   384
Gyro   370
Gyro   375
Gyro   386
Gyro   359
Gyro   333
Gyro   386
Gyro   359
Gyro   340
Gyro   366
Gyro   357
Gyro   362
Gyro   346
Gyro   358
Gyro   350
Gyro   355
Gyro   367
Gyro   344
Gyro   347
Gyro   354
Gyro   365
Gyro   353
Gyro   378
Gyro   375
Gyro   359
Gyro   340
Gyro   331
Gyro   367
Gyro   337
Gyro   376
Gyro   350
Gyro   337
Gyro   345
Gyro   357
Gyro   386
Gyro   342
Gyro   359
Gyro   370
Gyro   355
Gyro   386
Gyro   379
Gyro   357
Gyro   361
Gyro   383
Gyro   401
Gyro   379
Gyro   359
Gyro   337
Gyro   336
Gyro   392
Gyro   367
Gyro   374
Gyro   361
Gyro   362
Gyro   372
Gyro   344
Gyro   356
Gyro   363
Gyro   357
Gyro   369
Gyro   354
Gyro   352
Gyro   343
Gyro   368
Gyro   335
Gyro   348
Gyro   368
Gyro   359
Gyro   349
Gyro   357
Gyro   371
Gyro   370
Gyro   329
Gyro   363
Gyro   385
Gyro   365
Gyro   372
Gyro   362
Gyro   359
Gyro   358
Gyro   376
Gyro   342
Gyro   349
Gyro   355
Gyro   353
Gyro   362
Gyro   362
Gyro   341
Gyro   343
Gyro   354
Gyro   332
Gyro   324
Gyro   348
Gyro   357
Gyro   359
Gyro   358
Gyro   343
Gyro   355
Gyro   349
Gyro   353
Gyro   346
Gyro   372
Gyro   341
Gyro   359
Gyro   363
Gyro   378
Gyro   362
Gyro   370
Gyro   358
Gyro   379
Gyro   364
Gyro   344
Gyro   376
Gyro   360
Gyro   394
Gyro   332
Gyro   380
Gyro   347
Gyro   369
Gyro   361
Gyro   373
Gyro   351
Gyro   363
Gyro   357
Gyro   362
Gyro   383
Gyro   355
Gyro   355
Gyro   335
Gyro   359
Gyro   355
Gyro   358
Gyro   398
Gyro   332
Gyro   343
Gyro   379
Gyro   369
Gyro   386
Gyro   387
Gyro   372
Gyro   369
Gyro   350
Gyro   351
Gyro   347
Gyro   352
Gyro   355
Gyro   354
Gyro   352
Gyro   357
Gyro   350
Gyro   391
Gyro   374
Gyro   339
Gyro   359
Gyro   358
Gyro   356
Gyro   358
Gyro   355
Gyro   381
Gyro   366
Gyro   339
Gyro   374
Gyro   380
Gyro   371
Gyro   348
Gyro   361
Gyro   360
Gyro   375
Gyro   352
Gyro   353
Gyro   359
Gyro   362
Gyro   359
Gyro   364
Gyro   355
Gyro   370
Gyro   363
Gyro   355
Gyro   364
Gyro   355
Gyro   337
Gyro   372
Gyro   371
Gyro   342
Gyro   381
Gyro   372
Gyro   374
Gyro   336
Gyro   350
Gyro   357
Gyro   363
Gyro   368
Gyro   360
Gyro   345
Gyro   342
Gyro   367
Gyro   341
Gyro   344
Gyro   362
Gyro   369
Gyro   362
Gyro   353
Gyro   367
Gyro   335
Gyro   377
Gyro   355
Gyro   356
Gyro   383
Gyro   373
Gyro   352
Gyro   365
Gyro   353
Gyro   372
Gyro   346
Gyro   367
Gyro   335
Gyro   368
Gyro   375
Gyro   352
Gyro   362
Gyro   377
Gyro   360
Gyro   371
Gyro   367
Gyro   381
Gyro   386
Gyro   360
Gyro   354
Gyro   373
Gyro   350
Gyro   347
Gyro   359
Gyro   370
Gyro   364
Gyro   361
Gyro   354
Gyro   349
Gyro   392
Gyro   354
Gyro   378
Gyro   328
Gyro   381
Gyro   356
Gyro   325
Gyro   360
Gyro   356
Gyro   379
Gyro   344
Gyro   367
Gyro   358
Gyro   382
Gyro   360
Gyro   360
Gyro   355
X Accel Offset   1536Y Gyro Offset   359Y Gyro Min   323Y Gyro Max   401
Try 115200
Found bluetooth module at 115200
OKsetname
```


----------



## [email protected] (Mar 22, 2014)

Ovaltineo said:


> No, the logic ground is connected internally to the battery ground. Double check your connections to the BTN controllers.
> 
> Did you go through the calibration process? Is the machine level while you are testing? Can you please post the Serial Monitor output?


Is the machine level while you are testing?

Yes

Can you please post the Serial Monitor output?

In MODE_RUN


```
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
Try 115200
Found bluetooth module at 115200

 ACCEL: 0.40 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.01 MOTOR: -0.14 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.08 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.02 MOTOR: -0.39 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.45 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: 0.03 MOTOR: -0.41 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.24 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.02 MOTOR: -0.22 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.12 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: 0.02 MOTOR: -0.24 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.27 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.02 MOTOR: -0.18 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.13 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.02 MOTOR: 0.12 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.37 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.02 MOTOR: 0.30 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.16 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.01 MOTOR: 0.47 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.19 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.01 MOTOR: 0.70 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.19 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.02 MOTOR: 0.87 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.36 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.04 MOTOR: 1.01 LEFT: 0 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.03 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: 0.02 MOTOR: 1.24 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.24 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.02 MOTOR: 1.61 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.20 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.02 MOTOR: 1.85 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.28 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: 0.01 MOTOR: 2.16 LEFT: 2 RIGHT: 2 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.05 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: 0.01 MOTOR: 2.62 LEFT: 2 RIGHT: 2 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.21 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: -0.00 MOTOR: 3.00 LEFT: 3 RIGHT: 2 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.64 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: 0.00 MOTOR: 3.16 LEFT: 3 RIGHT: 3 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.22 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: -0.01 MOTOR: 3.26 LEFT: 3 RIGHT: 3 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.21 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: -0.01 MOTOR: 3.49 LEFT: 3 RIGHT: 3 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.14 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: -0.01 MOTOR: 3.69 LEFT: 3 RIGHT: 3 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.07 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.02 MOTOR: 3.70 LEFT: 3 RIGHT: 3 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.44 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.01 MOTOR: 3.50 LEFT: 3 RIGHT: 3 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.23 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.01 MOTOR: 3.35 LEFT: 3 RIGHT: 3 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.47 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.02 MOTOR: 2.90 LEFT: 2 RIGHT: 2 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.22 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: -0.00 MOTOR: 2.59 LEFT: 2 RIGHT: 2 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.18 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.00 MOTOR: 2.33 LEFT: 2 RIGHT: 2 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.14 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.01 MOTOR: 1.96 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.14 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.03 MOTOR: 1.69 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.47 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: 0.04 MOTOR: 1.64 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.19 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: 0.02 MOTOR: 1.66 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.01 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.03 MOTOR: 1.78 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.07 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.03 MOTOR: 1.92 LEFT: 1 RIGHT: 2 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.38 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: 0.02 MOTOR: 1.94 LEFT: 1 RIGHT: 2 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.07 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.03 MOTOR: 1.68 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.05 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.03 MOTOR: 1.26 LEFT: 1 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.41 GYRO: 0.00 BOARD ANGLE: -0.02 STEER ANGLE: 0.05 MOTOR: 0.95 LEFT: 0 RIGHT: 1 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.06 GYRO: 0.00 BOARD ANGLE: -0.04 STEER ANGLE: 0.05 MOTOR: 0.55 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.12 GYRO: 0.00 BOARD ANGLE: -0.03 STEER ANGLE: 0.04 MOTOR: 0.06 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.28 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.03 MOTOR: -0.00 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.28 GYRO: 0.00 BOARD ANGLE: -0.01 STEER ANGLE: 0.01 MOTOR: 0.00 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.12 GYRO: 0.00 BOARD ANGLE: -0.00 STEER ANGLE: 0.00 MOTOR: -0.22 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.30 GYRO: 0.00 BOARD ANGLE: 0.01 STEER ANGLE: 0.00 MOTOR: -0.12 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.02 GYRO: 0.00 BOARD ANGLE: 0.00 STEER ANGLE: 0.01 MOTOR: -0.04 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.00 GYRO: 0.00 BOARD ANGLE: 0.02 STEER ANGLE: 0.01 MOTOR: 0.07 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.18 GYRO: 0.00 BOARD ANGLE: 0.03 STEER ANGLE: -0.01 MOTOR: 0.48 LEFT: 0 RIGHT: 0 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0
```

Oval, I appreciate your cooperation.


----------



## Ovaltineo (Jul 18, 2013)

Everything looks good in the Serial Monitor. Double check your connections to the BTN controllers - those ribbon connectors are confusing. Use a voltmeter to make sure you are supplying 24V (maybe your circuit breaker is open). Check that EN1 and EN2 are at 5V level. Use an oscilloscope to make sure that one PWM pin is pulsing while the other PWM pin is at ground level -- they will swap when changing directions.


----------



## ferchotech (May 29, 2014)

Hello oval. btn7960 both came defective. I will buy new.


----------



## ghirotre (Nov 14, 2014)

Hi,
Thanks for your segway clone.
I try to make my clone.
I have some problem, the motor go only one direction.
The 2 mpu is ok and the serial data is perfect.
I use 2 btn7960, i check the setting and is all ok.
I test the 4 pwn from arduino and is ok, and the en is ok.
I suppose is the chip and i change btn on 1 board but the same problem.
Is possibile the problem is the microcontroller on the board?
Now i have buy 1 microcontroller and i try to change.

The question is another.
Is possibile to mount a lcd on the clone with the battery status and other details?

Very thanks


----------



## Ovaltineo (Jul 18, 2013)

ghirotre said:


> Hi,
> Thanks for your segway clone.
> I try to make my clone.
> I have some problem, the motor go only one direction.
> ...


Swap the two PWM pins. The motor should spin in the other direction, otherwise, your BTN is faulty. Don't replace the Arduino - if you think the PWM pins on the Arduino are faulty (unlikely), you can just use different pins by changing Motors.h.

Post a video of what is happening.


----------



## electricpolo (Mar 15, 2011)

I have had a test today using the encoders. Had to back down the default KD settings - very bad oscillations on startup without rider.
Very different sensation as the motor controller adjusts the power over the bumps without having to lean the machine more. 
I think it will be really good after I get the latest bug out of it.
What I think is an intermittent I2C error has crept back in when I use the RoboClaw with encoders. It is not there when I use the RoboClaw standard.
It doesn't do it on the bench test & only does it occasionally when riding but it doesn't recover quite as quickly although this could be due to non tuned PD settings.
I got a couple of small ferrites to put on the encoder cables and I will need to check where the shields terminate too.


----------



## ghirotre (Nov 14, 2014)

Thanks for the answer. 
I have try everything, change pwm Pin, i have made a program to test the bts7960 board, 10 seconds to one direction and 10 to another. 
Then i check the bts7960 board and there is a vary little cut on the board. I connect with a external wire and it is all Ok.
But now i don t want use the bts7960 board because i have a only 16A Motor and the board have a lot of problem. One bts7960 brake and one cut on the board. In the datasheet it is writed 40A....
Now i have buy a roboclow.


----------



## electricpolo (Mar 15, 2011)

How big are your motors in watts?
Makes a very big difference as to which RoboClaw you should get.

Certainly seems that the quality of the BTN7960 controllers leaves a lot to be desired.


----------



## ghirotre (Nov 14, 2014)

I have buy a 15x2 roboclow. 
Motor are 16amp 300w 24v.
I have 2 fuse 15amp on 2 motors.
I see in the sketch that roboclow have a valute of 1500, is it the Max power for the motor?
Because at Max Speed my clone go at 34km/h and it is too fast.


Thanks


----------



## electricpolo (Mar 15, 2011)

You will need the 30 x 2 RoboClaw at an absolute minimum.
The best one is the 2 x 60HV.
You need to lower your gearing ratio which will increase torque to the wheels and lower your top speed.
The clone won't work by having such high gearing & limiting the controller output power to half. You will need as much torque to the wheels as possible and the motors have to respond very quickly.
Change your gear ratios so that at top motor speed the wheels would be doing around 15-18km/hr.


----------



## ghirotre (Nov 14, 2014)

Ok,
Now i have buy a roboclaw 2x30.
For the Speed, the top Speed i have writed is without load.
I don t know how fast is motor with load of 140kg(me+clone, i am little fat).
The motor have 2750rpm without load, if with load it has about 1600rpm the Speed is ok.
I have mount a biggest commercial gear.
If i need to reduce i laser cut a new bigger gear for the wheel.
I want to use my clone in my workshop, now i use bicycle.
Where are You buy the btn board? Because i am from italy i don t find a good shop.
Now i have a 2 roboclaw, 1 2x15, 1 2x30.
I want to modify my lown mower, i want to control it with a ps3 controller.

Thanks


----------



## electricpolo (Mar 15, 2011)

The DC motors in the clones usually lose about 10% in speed from no load to rated load.
If your motor is almost halving in speed, then your motor is grossly underpowered for the applied load.
Because of the total load of 140kg, it is even more important that the motors be geared so that the motors are running at around the rated load speed at the top speed of your clone (15-18km/hr).
If your motors are not powerful enough or the gearing is too high, the clone will not work properly, will not balance very well & trip up over bumps.


----------



## stooge (Dec 10, 2014)

hi,

I'm trying to compile (check) the code using an ide 1.0.1 on linux.
It return this error

EEPROM.ino: In function ‘void writeIntToEEPROM(int, int)’:
EEPROM.ino:8:2: error: ‘EEPROM’ was not declared in this scope

can anyone help me to solve? tnks


----------



## stooge (Dec 10, 2014)

seems related to linux, both 32 and 64 bit.

on win 64 bit and IDE 1.0.1 (no admin) check succesfull


possible fix to linux founded here Issue including EEPROM.h function calls within class

it seems to return no errors


----------



## ghirotre (Nov 14, 2014)

Sorry guy but i have another problem.
I use roboclaw 2x30 board and 2 mpu for board and steering. 
I have try with s3 to gnd for test and in the serial output is all ok.
Then i disconnect s3 to try and in the serial i have sometimes(but often) a i2c error and the motor go at max power. If i reconnect the s3 to gnd there isn t error and Motor stop.
The clone can not stay in balance alone.

Thanks


----------



## ghirotre (Nov 14, 2014)

Today is a great day.
The clone is stable, i try to use but the fuse(15a) is small.
Tomorrow i go to buy a biggest fuse(20a).
The problem was the mpu position, one was under the board and one on the board.
Now i set up a single mpu on the steering pipe and everything is ok.
if it is all ok tomorrow i post a video. 
Thankyou for everything

I have a question, is possibile to use a led instead a buzzer?
I think is possibile, because output is 5v when is high and 0v when is low, of course i put a resistor with led


----------



## electricpolo (Mar 15, 2011)

Yes, you can use an LED with a resistor instead.
You will probably need a bigger fuse than 20A. The fuse will be carrying the current for both motors.
The 2x30 RoboClaw can supply 30A (60A total) to each motor continuously.
S3 is an emergency stop when grounded. You may need a 4K7 pullup resistor on it if you get sudden e-stop errors.


----------



## Ovaltineo (Jul 18, 2013)

Yes, a pullup on S3 is needed - even though there is supposed to be one built-in.


The Roboclaw stopped working when I moved the isolated power supply wires that were too close to the Roboclaw pins. The +5v wire must be inducing a HIGH on S3. Moving the wires left S3 in a floating state. I remembered electricpolo had the same problem so I put a jumper between S3 and +5v and it worked.

The good news is that moving the power supply wires seems to have completely eliminated my I2C errors.


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo 
Dont you think its better to use mbed - LPC1768 then arduino its more stable and more powerfull.

Thanks


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovaltineo
> Dont you think its better to use mbed - LPC1768 then arduino its more stable and more powerfull.
> 
> Thanks


Arduino is for the masses. It is by far the most popular board out there today. The clones are very cheap and easily available. There is no need for a powerful CPU for this application. I could have used Microchip PIC because I get free samples but not everyone has a programmer and you need to build a board.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> I have had a test today using the encoders. Had to back down the default KD settings - very bad oscillations on startup without rider.
> Very different sensation as the motor controller adjusts the power over the bumps without having to lean the machine more.
> I think it will be really good after I get the latest bug out of it.
> What I think is an intermittent I2C error has crept back in when I use the RoboClaw with encoders. It is not there when I use the RoboClaw standard.
> ...


How did you go with the encoders? I was thinking about this the other day and thought that braking or going downhill might be a problem when using encoders. When going downhill, tilting backl will cause the Arduino to apply negative (reverse) motor output. Without encoders, the Roboclaw will happily output a reverse PWM - this will cause an "engine brake" but the motors will still move forwards. With encoders, a reverse output from the Arduino will probably cause the Roboclaw to make sure that the motors are moving in reverse - not a very effective engine brake!

If this is happening, the solution might be to use encoder commands when applying positive (forward) output, and non-encoder commands when applying negative (reverse) output.


----------



## electricpolo (Mar 15, 2011)

I haven't done much since the last test except buy some ferrites (which I promptly lost!) for the encoder cables and ordered some new rider sensors as one of my original ones was faulty.
As the power goes up, I feel that it is really important for safety sake to have the power limited & PD settings lowered whenever a rider is not on the clone.
I was also getting some flexing in the motor mounts so I am looking at making a small alteration there.
Haven't had much time lately to do much in the shed.
Can't comment on the engine braking bit with encoders just yet. I can see your point though. Perhaps it will just be that the clone will need much less backward tilt, if any, when going down hill.
Need to get the I2C errors when using encoders sorted first then I'll be able to find out.


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltineo
Check this site . this guy has made Selfi segway using mbed and there 
lots of information.
https://sites.google.com/site/fitrobots/selfi/manual

thanks


----------



## roscoopc (Oct 14, 2014)

I'm using sabertooth 2x32 for my segway clone and in its settings I can:
-enable regerative braking to recharge batteries;
-enable it and add a resistor to dissipate the regenerative current;
-disable it from settings. 
What is the best choice? 

Happy xmas


----------



## electricpolo (Mar 15, 2011)

My 2 cents worth:
I'd have regen braking to recharge batteries.


----------



## electricpolo (Mar 15, 2011)

Got some new IR rider sensors but I have found that they are just not sensitive enough. I am going to ditch them and use a couple of micro switches under the foot plates instead.
Found the lost ferrites for the encoder cables so I might even get a chance to put them on & try it again.


----------



## cipesokram (Mar 11, 2014)

Hi Ovaltine and others, i have been folowing this forum for quite some time now and i learned a lot just reading questions and answers. 

Last year about this time three collegues made a new years resolution to each build a segway clone. Or at least to try to build one. All three are forum members: borc, istih72 and cipesokram.

With a lot of knowledge drawn from this forum and using code from Ovaltineo we managed to build three clones! Each of us was building a separate one, but we exchanged our little challenges.

Attached is a short video of the "unveiling" our creations:

https://www.youtube.com/watch?v=ZxTHN4_8cBA

All three clones are using old wheelchair motors and wheels, arduino, sabertooth and pot steering. One is using Lipo bateries, one is using old UPS batteries and one is using brand new scooter bateries.

All three are resonable safe and confortable to ride. 

THANKS Ovaltine, you are doing a great job!

Cheers, Marko


----------



## Ovaltineo (Jul 18, 2013)

Well done Marko and friends! It feels good to see people around the world successfully combining their skills and my code .


----------



## adamson (Mar 2, 2014)

Happy New Year!!!


----------



## wsm (Jan 6, 2015)

Hi,

I made a DIY Segway without Adruino and BTS7960.

Have a look to www.ups.bplaced.de

Have fun.


----------



## wsm (Jan 6, 2015)

Can I see your code?

Just to get some ideas.

W.


----------



## rajman2500 (Nov 30, 2013)

Hi 

check small video of testing my diy segway chair
http://youtu.be/QS3EpMaRu8I

Thanks


----------



## Ovaltineo (Jul 18, 2013)

wsm said:


> Can I see your code?
> 
> Just to get some ideas.
> 
> W.


The latest code and schematics can be found in post #1 of this thread.


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi
> 
> check small video of testing my diy segway chair
> http://youtu.be/QS3EpMaRu8I
> ...


Very well done !! Is this using LPC hardware and code or my Arduino code?


----------



## rajman2500 (Nov 30, 2013)

Hi

Iam using Arduino with your code. and thanks for all the help

thanks


----------



## ghirotre (Nov 14, 2014)

Hi all,
Happy new year. 
I post 2 videos.
First video is first try with human, but i have some problem. The gear ratio is not good (top Speed 23km\h)

http://youtu.be/bqWaR9RNAzQ

Then i have change gear ratio (Thanks electricpolo) and it is perfect (top Speed 16 km/h).

http://youtu.be/ve8_84l-Ygc

Thanks to all
Specially ovaltineo and eletricpolo


----------



## Ovaltineo (Jul 18, 2013)

Nicely done!!!


----------



## ghirotre (Nov 14, 2014)

Hi,
A question...
If i power up the roboclaw with 5v by arduino i have less i2c error?
Because i have little problem, when i stay still for about 1/2 minutes the arduino reboot (with a pc connect for debugging i have see that when i still, there are a lot of i2c error).
If i go foward there are less i2c.

Thanks


----------



## rajman2500 (Nov 30, 2013)

Hi

Some more testing video on streets of Delhi
http://youtu.be/1JbroMkGF4I

Thanks


----------



## Ovaltineo (Jul 18, 2013)

ghirotre said:


> Hi,
> A question...
> If i power up the roboclaw with 5v by arduino i have less i2c error?
> Because i have little problem, when i stay still for about 1/2 minutes the arduino reboot (with a pc connect for debugging i have see that when i still, there are a lot of i2c error).
> ...


Not in my experience. But if you power up the Arduino with an isolated power supply and use optocouplers to connect to the Roboclaw, then there will be very little i2c errors.


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi
> 
> Some more testing video on streets of Delhi
> http://youtu.be/1JbroMkGF4I
> ...


Pretty good! But there seems to be a lot of "play" in the steering. Might also need to increase the STEER_MULTIPLIER.


----------



## RonzaGeI (Nov 17, 2014)

Ovaltineo said:


> The latest code and schematics can be found in post #1 of this thread.


Hello Ovaltineo. Nice if put everything on GitHub.


----------



## Ovaltineo (Jul 18, 2013)

RonzaGeI said:


> Hello Ovaltineo. Nice if put everything on GitHub.


I'll do it one of these days when I find the time to learn how to do it .


----------



## RonzaGeI (Nov 17, 2014)

Ovaltineo said:


> I'll do it one of these days when I find the time to learn how to do it .


Congratulations. Great project. Accrue with the cooperation of all


----------



## electricpolo (Mar 15, 2011)

> Originally Posted by *ghirotre*
> _Hi,
> A question...
> If i power up the roboclaw with 5v by arduino i have less i2c error?
> ...


See my various posts about I2C errors & how I went about removing them.
It is a combination of fully isolated power to the Arduino & sensors, shielded cables with common shield point, ferrite cores & grounding steel frame to RoboClaw.


----------



## adamson (Mar 2, 2014)

Ovaltineo could you give me link to wtv020 V1.5, because now I've got a few pieces of V1.0. They are always sending me v1.0 instead of v1.5.


----------



## Ovaltineo (Jul 18, 2013)

Well I've got the same problem. They show a picture of a v1.5 then send a v1.0. I suggest asking the seller first before buying.


----------



## adamson (Mar 2, 2014)

But I'm always asking them before buying.


----------



## nhuynhduc (Jan 21, 2015)

@Ovaltineo

Thanks your post and this is my segway 










https://www.youtube.com/watch?x-yt-cl=84838260&v=By0thCzwExI&x-yt-ts=1422327029

according to you it is not running?


----------



## Ovaltineo (Jul 18, 2013)

It is definitely not working. With the wheels off the ground, watch the output of the Serial Monitor. Tilt the platform forward and back. Does the pitch angle change as expected? Post a picture of how you mounted the gyro board.


----------



## mutai (Dec 22, 2014)

Dear Ovaltineo,

I have a problem with my Android App-it freezes after 1 min or less.
I have a Samsung S3.
The baud rate is 19200 on the HC06.
Any idea?


Thanks in advance,
Eran


----------



## nhuynhduc (Jan 21, 2015)

Ovaltineo said:


> It is definitely not working. With the wheels off the ground, watch the output of the Serial Monitor. Tilt the platform forward and back. Does the pitch angle change as expected? Post a picture of how you mounted the gyro board.


This my gyro board

And this is resulft 


```
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0

 ACCEL: -2.29 GYRO: 0.36 BOARD ANGLE: -0.31 STEER ANGLE: -2.34 MOTOR: -0.26 LEFT: 7 RIGHT: -8 VOLTAGE: 5.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.05 GYRO: 0.40 BOARD ANGLE: -0.88 STEER ANGLE: -6.02 MOTOR: -6.90 LEFT: 14 RIGHT: -27 VOLTAGE: 4.93 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.19 GYRO: 0.53 BOARD ANGLE: -1.36 STEER ANGLE: -8.87 MOTOR: -21.11 LEFT: 9 RIGHT: -52 VOLTAGE: 4.30 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.36 GYRO: 0.46 BOARD ANGLE: -1.66 STEER ANGLE: -10.72 MOTOR: -40.93 LEFT: -3 RIGHT: -78 VOLTAGE: 3.84 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.43 GYRO: 0.34 BOARD ANGLE: -1.84 STEER ANGLE: -11.82 MOTOR: -63.62 LEFT: -22 RIGHT: -104 VOLTAGE: 3.46 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.14 GYRO: 0.06 BOARD ANGLE: -1.96 STEER ANGLE: -12.46 MOTOR: -88.75 LEFT: -45 RIGHT: -132 VOLTAGE: 3.25 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.51 GYRO: 0.32 BOARD ANGLE: -2.04 STEER ANGLE: -12.83 MOTOR: -115.21 LEFT: -70 RIGHT: -150 VOLTAGE: 3.20 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.00 GYRO: 0.30 BOARD ANGLE: -2.09 STEER ANGLE: -13.03 MOTOR: -142.43 LEFT: -96 RIGHT: -150 VOLTAGE: 3.26 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.32 GYRO: 0.61 BOARD ANGLE: -2.10 STEER ANGLE: -13.11 MOTOR: -150.00 LEFT: -104 RIGHT: -150 VOLTAGE: 3.27 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.22 GYRO: 0.12 BOARD ANGLE: -2.10 STEER ANGLE: -13.15 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.12 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.22 GYRO: 0.37 BOARD ANGLE: -2.10 STEER ANGLE: -13.20 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.20 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.29 GYRO: 0.08 BOARD ANGLE: -2.11 STEER ANGLE: -13.24 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.24 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.22 GYRO: 0.21 BOARD ANGLE: -2.14 STEER ANGLE: -13.26 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.09 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.28 GYRO: -0.11 BOARD ANGLE: -2.20 STEER ANGLE: -13.26 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.20 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.42 GYRO: 0.37 BOARD ANGLE: -2.16 STEER ANGLE: -13.24 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.22 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.81 GYRO: 0.40 BOARD ANGLE: -2.20 STEER ANGLE: -13.23 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.15 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -0.99 GYRO: -0.03 BOARD ANGLE: -2.21 STEER ANGLE: -13.29 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.14 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -3.27 GYRO: 0.85 BOARD ANGLE: -2.25 STEER ANGLE: -13.29 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.21 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -1.45 GYRO: 0.00 BOARD ANGLE: -2.27 STEER ANGLE: -13.26 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.24 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.91 GYRO: -0.68 BOARD ANGLE: -2.27 STEER ANGLE: -13.24 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.07 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -1.98 GYRO: 0.29 BOARD ANGLE: -2.24 STEER ANGLE: -13.22 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.17 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.61 GYRO: -0.82 BOARD ANGLE: -2.20 STEER ANGLE: -13.24 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.23 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.07 GYRO: 0.24 BOARD ANGLE: -2.16 STEER ANGLE: -13.28 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.18 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -1.26 GYRO: 0.37 BOARD ANGLE: -2.15 STEER ANGLE: -13.30 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.12 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.11 GYRO: 0.28 BOARD ANGLE: -2.15 STEER ANGLE: -13.29 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.25 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.98 GYRO: 0.85 BOARD ANGLE: -2.17 STEER ANGLE: -13.29 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.23 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -1.81 GYRO: 0.34 BOARD ANGLE: -2.19 STEER ANGLE: -13.32 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.11 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.19 GYRO: 0.24 BOARD ANGLE: -2.17 STEER ANGLE: -13.33 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.18 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.33 GYRO: 0.71 BOARD ANGLE: -2.19 STEER ANGLE: -13.33 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.19 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.19 GYRO: 0.50 BOARD ANGLE: -2.25 STEER ANGLE: -13.24 MOTOR: -150.00 LEFT: -103 RIGHT: -150 VOLTAGE: 3.10 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -1.81 GYRO: 0.79 BOARD ANGLE: -2.19 STEER ANGLE: -13.00 MOTOR: -150.00 LEFT: -104 RIGHT: -150 VOLTAGE: 3.13 TEMP: 0 CURRENT1: 0 CURRENT2: 0

 ACCEL: -2.23 GYRO: 0.76 BOARD ANGLE: -2.09 STEER ANGLE: -12.95 MOTOR: -150.00 LEFT: -104 RIGHT: -150 VOLTAGE: 3.18 TEMP: 0 CURRENT1: 0 CURRENT2: 0
```
ON serial monitor
this is new videos
http://youtu.be/ullKw8eksRU


----------



## RonzaGeI (Nov 17, 2014)

Ovaltineo said:


> I'll do it one of these days when I find the time to learn how to do it .


Is simple
go to
https://github.com/

create the account and load the SW.

Collaboration is live

Hi


----------



## Ovaltineo (Jul 18, 2013)

mutai said:


> Dear Ovaltineo,
> 
> I have a problem with my Android App-it freezes after 1 min or less.
> I have a Samsung S3.
> ...


Unfortunately, my code doesn't seem to be compatible with all Android phones. The Serial profile in the Bluetooth interface seems to be slightly different for some models. This is out of my control because I can only work with the published APIs. I suggest trying a different firmware or phone.


----------



## nhuynhduc (Jan 21, 2015)

@Ovaltineo

This is new fix

Do you think it work ?

http://youtu.be/qpKv-w5Lma0

https://www.youtube.com/watch?v=UEJLQkhIEWQ

Thanks


----------



## electricpolo (Mar 15, 2011)

nhuynhduc
Without a tiller/handlebar it will most likely oscillate unless the PD settings are very small. More likely it will try to rotate the frame around the axle.
I can also hear some slack in your drive train. You need to have the minimal amount of backlash possible for it to work well.


----------



## nhuynhduc (Jan 21, 2015)

I'm trying to run it to adjust the GRYO for attaching them to the car so no need to adjust the rails and chain wheel.

What you have more suggestions for me?

Thanks

This is DIY before https://www.youtube.com/watch?x-yt-ts=1422503916&x-yt-cl=85027636&v=DM3LlZB_0xU


----------



## electricpolo (Mar 15, 2011)

Not following here. 
What does the toy car have to do with a Segway clone?


----------



## nhuynhduc (Jan 21, 2015)

This toy used drill battery


----------



## andeew (Jan 18, 2015)

firstly, I want to say thank you for all the hard work and time invested in creating this resource.
I am in the early stages of designing my clone - I have collected most of the equipment needed and am about to start building the test assembly on a wooden board to debug before I weld a frame etc.
I have attached the circuit I am thinking I need along with the initial code - can someone take a quick look and make sure it seems sensible?
(I know that the power led and switch are missing from the circuit - but I am impatient to get feedback).
Does anyone have any good diagrams of the hubs/bearings they used for the wheel assemblies and the steering - I was thinking about using pillow bearings for both.
There seems to be a lack of details in the posts about the mechanical design/assembly - I saw some posts about the springs to center the steering but not much else - did I miss it in the 100's of pages of posts?


----------



## Borc (Mar 12, 2014)

Andeew,
that voltage divider for battery monitoring on your picture should be in parallel with batteries not in serial. There is serious amount of current flow from batteries.


----------



## electricpolo (Mar 15, 2011)

andreew
Have a look at my separate thread about my machine. There is a lot of mechanical detail there.
Haven't updated it in a little while though. Been pretty busy.
I think that you are better off using a second MPU6050 for the steering. Much more accurate & reliable. If you do use a pot though, make sure it is a really good quality Bourns or similar. Don't use a $2 pot.
You also don't really need the D or P pots. You can change PD in the software & also with the clone console. Once you have it adjusted the way you like you probably won't alter it.
You should also add rider sensor switches of some sort. This will let you have low PD settings & a low max motor speed when there is no rider & higher PD settings & the max motor speed when you get on.
This makes it nice & safe with no rider & responsive & more powerful when a rider is on board.
You should put a level converter between the bluetooth module & the Arduino. While some of the bluetooth modules can be powered by 5V, the RX & TX is only 3.3V. The Arduino TX & RX is 5V. The level converter fixes this properly.
There is no mention of your motor size but from my & other peoples experiences, 350W motors are an absolute minimum. 500W are much better. 
That being the case, your 8Ah batteries will give you a very,very short ride time & you will send them to an early grave. Use 12Ah or 18Ah at a minimum.
Put a 24V contactor in the +ve cable between the batteries & the Sabretooth (but before the voltage divider & the power to the Arduino) Have a separate switch for the contactor & this becomes your main On/Off switch. Closing the eStop on the Sabretooth only electronically stops the controller.


----------



## andeew (Jan 18, 2015)

Borc said:


> Andeew,
> that voltage divider for battery monitoring on your picture should be in parallel with batteries not in serial. There is serious amount of current flow from batteries.


You mean like this?
I also added the segway.h file in case there is any thing that needs to be checked there too.


----------



## Ovaltineo (Jul 18, 2013)

nhuynhduc said:


> This my gyro board
> 
> ON serial monitor
> this is new videos
> http://youtu.be/ullKw8eksRU


That is the wrong way to attach the steer gyro. It will steer whenever it tilts! That's why it is going in circles.

You need a self-centering handlebar that can be tilted left and right. You should attach the steer gyro to the pivot shaft of the handlebar with the x-axis parallel to the shaft. 

You need to have a close look at the other guys builds and learn!


----------



## Ovaltineo (Jul 18, 2013)

andeew said:


> You mean like this?
> I also added the segway.h file in case there is any thing that needs to be checked there too.


Remove the P and D pots and comment out P_PIN and D_PIN from SegwayClone.h. I don't support them anymore. With the bluetooth module, you can change P and D using the Android application.

One end of the voltage divider must be at ground, the other end at 24V. Check my original schematic to see how it should be done.

As electricpolo said, using a pot for the steering is recommended only if you have a good quality pot. A second MPU6050 would be better.

With regards to your earlier remark about not having mechanical detail, you are absolutely right. I can't do those 3D drawings. But from experience, the mechanical bits are the hardest to duplicate - very few has access to a CNC machine, and the available wheels and motors are very different between localities. Besides, anyone attempting this project should have adequate mechanical skills to work out how to drive two wheels with two motors.


----------



## electricpolo (Mar 15, 2011)

> Originally Posted by *andeew
> *Does anyone have any good diagrams of the hubs/bearings they used for the wheel assemblies and the steering - I was thinking about using pillow bearings for both.
> There seems to be a lack of details in the posts about the mechanical design/assembly - I saw some posts about the springs to center the steering but not much else - did I miss it in the 100's of pages of posts?


The thread is essentially about Ovaltine's code to balance a Segway clone and not how to actually build one. 
The mechanics of a Segway or of of any clone are more or less the same. There will be 2 motors, 2 wheels, a drivetrain, a baseframe, a tiller handlebar, batteries, the CPU, 1 or 2 (or more) gyros plus various contactors, switches, etc.
This is where the fun begins. Every builder has different ideas on how to put all these bits together. Googling 'Segway clone' or DIY Segway clone' will bring up lots of examples for you to base yours on.
Unlikely you will find CAD 2D & 3D drawings, construction drawings & exploded assembly drawings. You have to make up your own design depending on your motors, wheels, batteries & other hardware & your available tools.
My photos are on my separate thread & you will find many more on the Internet for inspiration.
As Ovaltine noted previously and many others have found out, you need quite reasonable mechanical skills to build a clone.


----------



## Borc (Mar 12, 2014)

andeew said:


> You mean like this?


No - like this:


----------



## andeew (Jan 18, 2015)

got it - thanks


----------



## nhuynhduc (Jan 21, 2015)

This my project 

https://www.youtube.com/watch?v=L0URzYXsQ2M


----------



## mutai (Dec 22, 2014)

https://www.youtube.com/watch?v=mobtCpOctr0&feature=youtu.be
Success!!!

Yesterday i did my first attempt to ride on my Segway Clone-It was amazing!!!
I have to thank Ovalentino for his great job with the code.
My setup:
-Jazzy wheelchair motors.
-plywood base.
-arduino uno.
-2 MPU6050.
-2 BTN7970.
-Bluetooth module.
Now I know that I want to improve many things-I will update you guys with the progress of the project.
Again- Many thanks for Ovalentino for the Inspiration.

Regards,

Eran


----------



## Ovaltineo (Jul 18, 2013)

nhuynhduc said:


> This my project
> 
> https://www.youtube.com/watch?v=L0URzYXsQ2M


Looking good! Does the steering handle move?


----------



## Ovaltineo (Jul 18, 2013)

mutai said:


> https://www.youtube.com/watch?v=mobtCpOctr0&feature=youtu.be
> Success!!!
> 
> Yesterday i did my first attempt to ride on my Segway Clone-It was amazing!!!
> ...


Well done!!  It certainly looks a thousand times safer and smoother than my first attempt at riding my clone (with the very first version of the firmware) .


----------



## mutai (Dec 22, 2014)

Ovaltineo said:


> Looking good! Does the steering handle move?


Yes! One gyro is on the handle axis.

Eran


----------



## SailorKane (Jan 26, 2015)

Gentlemen, I too am attempting this project. Thanks for this wonderful thread and esp Ovaltines work on the software. I notice that activity here has dropped and I hope I'm not too late to get some advice. I have read all of the posts here and noted important information in the posts. I would like a usable urban segway clone when I'm done. Right now I've built the Phase 1 platform, 500W motors, chain drive to wheels, 2 12ah scooter batteries, tilt control handle. 

Motor Controller: Much discussion here. I have the Saber 2x32 which I bought before reading this thread. I also bought the Chinese BTN 7970 motor controllers. The RoboClaw apparently is "better", but I balk at the price. Which choice is the "best"? Do I need to spring for the roboclaw?

Dimensions: I am considering a platform 18"x18" and 3" ground clearance and platform thickness 5.5-6". Any thoughts?

The android app indicates when a rider is onboard. Which is best way to do that, IR or weight or ?? How to connect that to the Uno or Mega?

Any benefit to encoders? Position encoder or incremental?

Thanks again. Really great project!!


----------



## electricpolo (Mar 15, 2011)

Hi SailorKane,
I have hardly been able to get out to the shed lately to play with my clone. (Several building projects on the go at once)
My opinions.
The RoboClaw 2x60A HV is the best controller of the lot but $$$$.
My platform is 500w x 420d with 100mm ground clearance & is 100mm thick. My wheels are 500mm in diameter.
I tried IR sensors but they didnt work very well. I have gone to microswitches instead. Others have used weight sensors.
I have connected the switches to two digital inputs & modified the code slightly so that both switches have to be closed for the higher rider onboard PD settings & maximum motor power.
When even one switch is off, the code reverts back to the low PD settings so it doesn't oscillate & cuts the power back to 20% for safety.
I can post the relevant section of code if you are interested.
I have incremental encoders on my motors also and have already done a small bit of testing with them & the RoboClaw Encoder code. Initial testing is very positive but I am a bit short of time at the moment.
The RoboClaw HV is the only controller that can be used with encoders.
The benefit to encoders is that for any given board tilt, the speed will be constantly maintained as the controller itself will be varying the power to the motors up inclines & over bumps.
Without encoders, for any given board tilt, the Arduino will be telling the controller to output a certain power level. Assuming the the board tilt remains the same, the actual speed will vary up inclines & over bumps.
In real life though, the rider & the electronics compensate somewhat for this.


----------



## SailorKane (Jan 26, 2015)

Thanks so much for the reply. I think its you great metalwork that lets you keep the thickness so thin. I doubt I can do so well.
I would indeed like to see the code you wrote to detect the person on board.


----------



## roscoopc (Oct 14, 2014)

I have a sabertooth 2x32 and I am planning to add a kangaroo x2 https://www.dimensionengineering.com/products/kangaroo and atm102 encoders... But at this moment I am working to add a beginner switch in the code. 
Thanks to Ovaltineo, Electricpolo and others friends of this forum!


----------



## electricpolo (Mar 15, 2011)

I have some spare AMT 102 encoders for sale if people want them & I can post them anywhere in the world.
Send me a PM & I will get back to you.


----------



## SailorKane (Jan 26, 2015)

Well, making progress. I have the "Phase 1" platform built, on plywood, with 500w motors, chain drive to wheels, batteries, and tilt control column. Also breadboarded the two gyros, Uno, Saber 2x32 with hobby motors. Now trying to do the system integration. I downloaded calibration and then ran the program. It was reading the two gyros just fine. Tilting the board gyro and swinging the tilt gyro side to side produce good results on the serial monitor.

Problem is, I don't think the Uno is communicating with the Sabertooth. I'm using packetized serial. The 2x32 is newer and different than the 2x12 or 2x25. Commands are different. Instead of motor_max of 127, the 2x32 has 2047 and takes a command of M1:-2047 to 2047, where negative numbers are reverse, positive are forward. Device Address was 0x80(not sure about this address), default for 2x32 is 128. Baud rate may be the biggest problem--2x25 will read baud rate from input, 2x12 will accept a command of 1,2,3,4 to represent baud rates (38400 is "4", for instance). The 2x32 defaults to 9600, unless extraordinary measures are taken. Somehow, when I perused the Ovaltine software, I seem to have found two places where baud rates for Saber were different: once for 9600 and later for 38400. 
Is there any help out there for the 2x32? Or do I need to wing it. I'm inclined to change motor.h in the sabertooth controller section. Motor_max to 2047, motor_max_off to perhaps 200. Sabertooth_address to 128. M1_FORWARD to M1, M1_BACKWARD to M1, M2_FORWARD to M2, M2_Backward to M2. Not sure what SET_BAUD15 does, and I think BAUD_38400 (currently set to 4) doesn't do anything in the 2x32. I suspect I would have to find where the motors are commanded to forward and reverse and change the values from 0 to 127, to -2047 to +2047. Not sure where that is. 

Any help that anyone has would be appreciated...... 
It does look like Sabertooth has improved in the 2x32 version. Much higher resolution (4096 values instead of 256), encoder capability with the add-on Kangaroo board, motor shutdown, and some other features (temp, voltage readouts). So I hope to keep the Sabertooth 2x32 controller for this project.


----------



## roscoopc (Oct 14, 2014)

I'm plannig to add a "beginners" switch to my clone that reduce the power of motors to help beginners and kids. I added some line of code copying the "rider_sensor" but I'am not a programmer...  Someone can take a look? Any help is appreciated 


```
boolean riderIsOn(void)
{
#ifdef HX711_DOUT
	return checkHX711();
#elif defined(RIDER_SENSOR)
	int state = digitalRead(RIDER_SENSOR);
	#ifdef INVERT_RIDER_SENSOR
		return (state);
	#else
		return (!state);
	#endif
#else
   
	return (true);
#endif
}

boolean beginnerIsOn(void)                                         // *dm*
{                                                                            // *dm*                 
#ifdef BEGINNER_SENSOR                                          // *dm*
	int state = digitalRead(BEGINNER_SENSOR);               // *dm*
        #ifdef INVERT_BEGINNER_SENSOR                           // *dm*
		return (state);                                 // *dm*   
        #else                                                     // *dm*
                return (!state);                                // *dm*
        #endif                                                    // *dm*
#else                                                           // *dm*
              
	return (true);                                          // *dm*
#endif                                                          // *dm*
}                                                               // *dm*

...............


void setup()
{
	
...............

#if defined(RIDER_SENSOR)	
	pinMode(RIDER_SENSOR, INPUT);
	digitalWrite(RIDER_SENSOR, HIGH);

#endif                                              

#if defined(BEGINNER_SENSOR)	                    // *dm*
	pinMode(BEGINNER_SENSOR, INPUT);            // *dm*
	digitalWrite(BEGINNER_SENSOR, HIGH);        // *dm*

#endif                                              // *dm*


..............

void loop()
{
#ifndef MODE_CALIBRATE
	float board_accel;
	float board_gyro;
	float speed_adjust;
	float yaw_gyro;
	float steer;
	long motorMax;
	float steer_gyro;
	boolean riderOn;
        boolean beginnerOn;                      // *dm*

...............

{
		
                riderOn = riderIsOn();
                beginnerOn = beginnerIsOn();                                     // *dm*   
		pastMicros = currMicros;		                              // reset timer
		board_accel = getBoardAccel();  	                             // get board pitch accelerometer value
		board_gyro = getBoardGyro();	                             // get board pitch (tilt) gyro value
		board_angle = getBoardPitchAngle(board_accel, board_gyro, dt);	// compute board pitch angle


.................



if (riderOn && !beginnerOn)                                       // *dm*
	motorMax = MOTOR_MAX;               		     // *dm*
                                
if (riderOn && beginnerOn)                                         // *dm*
	motorMax = MOTOR_MAX_BEGINNER;  		     // *dm*
                                
else
	motorMax = MOTOR_MAX_OFF;
```


----------



## roscoopc (Oct 14, 2014)

SailorKane said:


> I suspect I would have to find where the motors are commanded to forward and reverse and change the values from 0 to 127, to -2047 to +2047. Not sure where that is.
> 
> Any help that anyone has would be appreciated......
> It does look like Sabertooth has improved in the 2x32 version.


I'am using sabertooth 2x32 with default parameters of Ovaltineo's code and it work great whit 0, 127, baud rate... 
I have kangaroo x2 but I will attempt later to add it. I need to modify the motors shaft with the lathe to install encoder.


----------



## electricpolo (Mar 15, 2011)

What do you want to do with the beginner switch?
Do you want it to say have half motor power & moderate PD settings with the switch ON & full motor power with high PD settings with the switch OFF.
Would the beginner switch operate separate to any rider sensor switches? Rider sensor switches are highly recomended as PD settings that are responsive enough to ride well usually make the clone oscillate with no rider on board.


----------



## roscoopc (Oct 14, 2014)

The 3 options of motor power 

#ifdef SABERTOOTH_CONTROLLER
#define MOTOR_MAX 127
#define MOTOR_MAX_BEGINNER 60
#define MOTOR_MAX_OFF 0

My rider sensor cut the power when you leave the board, and also sabertooth cut the power. There are 2 sensor under the board to stop the clone whitout rider. But it restart, softly, when the board is pressed. I prefer this way...
My idea is to have a simple switch to change the power from 127 to 60 for safe use by kids or beginners. Whitout use the computer to modify the code.


----------



## electricpolo (Mar 15, 2011)

Having the rider sensor cut the power to the board & the Sabretooth will not work at all. You won't be able to get on because the board won't be balancing.
For the board to balance, the Arduino needs to start up, the sensors need to calibrate themselves & in the case of the RoboClaw, there is a slight time delay while it starts up also.
You need a separate main On/Off switch that turns everything on or off. 
The board will then start up and start to balance in Rider Off mode with the low PD settings & the low Motor Max settings.
When you get on, the board is already balancing but the rider sensors will turn on and increase the PD & Motor Max settings.
When you get off, the board will still balance but PD & Motor Max will drop back to the low settings.


----------



## SailorKane (Jan 26, 2015)

roscoopc said:


> I'am using sabertooth 2x32 with default parameters of Ovaltineo's code and it work great whit 0, 127, baud rate...
> I have kangaroo x2 but I will attempt later to add it. I need to modify the motors shaft with the lathe to install encoder.


Help me out here. Sounds like you got the 2x32 Sabertooth to work. What baud rate did you use? Mega or Uno? The Sabertooth defaults to 9600.


----------



## roscoopc (Oct 14, 2014)

Whitout rider my board is always balanced by the weight of the batteries, about 16kg. And when it is on works good whit the rider. 
I use arduino mega, with baud 9600. Tomorrow I will check the dip settings of sabertooth 2x32.


----------



## SailorKane (Jan 26, 2015)

SailorKane said:


> Help me out here. Sounds like you got the 2x32 Sabertooth to work. What baud rate did you use? Mega or Uno? The Sabertooth defaults to 9600.


I read the fine print of the Sabertooth 2x32 and it accepts legacy packetized serial commands. So it is running like the older Sabertooth. My problem was a bad switch setting. It is now running. However, eventually I would like to move to the new commands since they seem a lot more powerful.


----------



## roscoopc (Oct 14, 2014)

I solved my problem with code modified. Just replaced "if" with "else if"


----------



## SailorKane (Jan 26, 2015)

Well. I have my Phase 1 Clone nearly done. 500W motors, chain drive, Sabertooth 2x32 with legacy packetized serial comms, Uno, 2 gyros. No bluetooth, weight sensor, or anything else (yet). I have yet to be brave enough to step on. I found oscillation when using full "P" and "D" parameters (.35 and .15 respectively), so I backed off to .15 and .07, which are the values recommended for Rider Off situation. With .15 & .07 I can grab the handle and walk the clone like a dog. It steers, goes forward and back and seems to balance. I briefly tried to step on, and it is not working hard enough to balance with my weight on. So I'm guessing I need to increase P and D, just before oscillation sets in.

Can someone help: what exactly are the P and D values and what do they do? I don't mind a technical description, since I (used to be) an engineer... Trying to get some insight into how to set them, without just guessing.


----------



## SailorKane (Jan 26, 2015)

As I feared, activity on this thread has decreased a bunch. I got my segway clone just about working. I was standing on it and adjusting the P and D values. However, my wheels are too weak. The axle was 5/16 (8mm) and bent when I stood on the clone. I am trying to find larger wheels, with 12mm axle or larger. I am using chain drive, so need to attach a sprocket to the wheel. I found nice wheels at reasonable cost here:
http://www.amazon.com/Pitmoto-Front...=UTF8&qid=1424713947&sr=8-40&keywords=rim+gy6
I found them be doing a search for GY6 front wheel (13x3.5) in amazon. 

However, it has 3 holes and the spacing of the holes appears to be 55mm, which is the distance between adjacent mounting holes. These are actually for a disk brake rotor. And I can't find a sprocket that has that hole spacing.

So I'm at a standstill. Electricpolo's elaborate wheel assembly is awesome, but way beyond my mechanical capabilities. Without the ability to find a wheel/sprocket combination that can hold a larger tire and half inch axle, I may be done.
Any advice would be greatly appreciated.
Peace.


----------



## Ovaltineo (Jul 18, 2013)

SailorKane said:


> As I feared, activity on this thread has decreased a bunch. I got my segway clone just about working. I was standing on it and adjusting the P and D values. However, my wheels are too weak. The axle was 5/16 (8mm) and bent when I stood on the clone. I am trying to find larger wheels, with 12mm axle or larger. I am using chain drive, so need to attach a sprocket to the wheel. I found nice wheels at reasonable cost here:
> http://www.amazon.com/Pitmoto-Front...=UTF8&qid=1424713947&sr=8-40&keywords=rim+gy6
> I found them be doing a search for GY6 front wheel (13x3.5) in amazon.
> 
> ...


I have posted a short guide in adjusting P & D values in this thread - just search for my posts. You can get a general understanding of them by Googling "PID" too. 

As for the wheels, you have found the same problem that I did. Unless you have a lathe or milling machine, it is quite difficult to make your own drivetrain. I solved this by using 16 inch kids bike wheels - the ones that brake when you pedal in reverse. You need to borrow a welder to fix the sprocket in place.

If you can get hold of wheelchair motors, then it would be easier to find wheels for them.


----------



## electricpolo (Mar 15, 2011)

At a minimum, your axle would need to be 12mm or 1/2" but it really depends on how far it sticks out. Fatter tyres need more stick out which means a thicker axle. Mine stick out 125mm and are 16mm in diameter. I also made them out of stainless steel for extra stiffness. 
The problem with a Segway clone is the axle is supported on one side only whereas the same wheel on a scooter is supported on both sides so the axle can be much smaller.
The drive train & chain also introduces a bending force on the axle in line with the 2 sprockets.
You may have to find a sprocket on ebay like this one and then ask a friend with a lathe & a drill press (or a local machine shop) to machine it to fit your new wheels.
You can also replace the bearings in your new wheels with ones that have a larger inside diameter if you want a thicker axle.


----------



## SailorKane (Jan 26, 2015)

Thanks for the responses, guys. I really appreciate you two taking the time to respond on a project that is probably pretty old to you both by now. It is actually encouraging to me that you had similar problems coming up with wheels. It means that I'm not simply stupid or missing something obvious. It does seem that I will have to engineer something a little more complex.
Thanks for the insight into the axle situation. Phase 1 of my building is simply getting a working plywood platform. I think I'll get real crude for that one and build a frame around the outside of the wheel to support the outside of the axle. That should give me enough support to avoid bending the axle during trials.
For phase 2, a "real" segway clone, I will apparently have to get a sprocket machined with the proper bolt holes and center hole for whatever wheel I pick. The standard bearing for the 13x3.5 wheel I found gives a 12mm axle hole--I'll have to search to see if another bearing with same outside diameter and larger inside diameter can be found. I will also get a long 12mm hardened stainless bolt, install it on my plywood phase 1 clone, support the outside ends on bricks and stand on it to see if it bends. 
For PD tuning, I have read every post on this thread (took a couple days) and found a couple places with some interesting discussion. The best was probably post 475: set D=0, increase P to just short of oscillation, then increase D until it responds quickly. The default values in the software cause immediate oscillation, but remarkably 80% of those values (.30, .13) seem to work well. If the axle hadn't bent I think I would have it by now.
I also took a Segway tour of the local park on Sunday and really enjoyed it, and learned a lot about how real Segways act. That should help in the tuning.
Again, thanks.


----------



## dstamatoiu (Feb 23, 2015)

Hey guys. I been a lurker for a while now. First off, thank you for this code. I am currently receiving all the Parts for my build. As I am getting everything connected I thought it would be cool to add an LCD to the mega. I have a serial lcd from an old project. Now I searched this thread and looked at other but no luck. My coding skill is limited. I was wondering can anyone point me to how I could connect the LCD to show battery voltage and maybe if the clone is ready to go. Thanks


----------



## electricpolo (Mar 15, 2011)

The LCD that I will be using is a Cat's Whisker Textstar. It only needs power, ground & a signal wire. Has inbuilt bar graphs that are easy to use. It's not the cheapest LCD around but it is one of the smartest.
http://cats-whisker.com/web/node/7


----------



## mutai (Dec 22, 2014)

Hi Guys,

Please help- I need a simple drawing of how to connect a microswitch as a rider sensor.

Thanks

Eran


----------



## roscoopc (Oct 14, 2014)

I simply have a on/off button between pin8 and ground. When it is pressed pin8 is connected to ground and Arduino read it as rider on.


----------



## mutai (Dec 22, 2014)

roscoopc said:


> I simply have a on/off button between pin8 and ground. When it is pressed pin8 is connected to ground and Arduino read it as rider on.


Dear roscoopc,

Thank you very much for that- It helped me understand!

Eran


----------



## SailorKane (Jan 26, 2015)

Wow. Success! I fixed my wheels and rode my Phase 1 (plywood) segway around the back porch yesterday for the first time. It takes a great leap of faith to stand on two wheels, esp that were "manufactured" by my two hands, rather than a real manufacturer. So I was pretty tentative, but it ran fine. Motor max was 40 out of 127, so additional trials needed at higher motor power. Thanks for all the help, and now on to phase 2 (a "real" build--not using plywood).

PS: My Phase 2 includes a mega with the sabertooth. There's no schematic for mega/sabertooth, but it looks straightforward. I assume all connections the same as for the Uno, except bluetooth connected to mega's rx3/tx3. True?

Also, the new Sabertooth 2x32 has a better set of commands (though it does accept the legacy commands). You can send it M1:x where x is a number from -2047 to +2047. Or M2: x. To command each motor. You can also Get temperature of each output transistor and Get battery voltage. I believe its close to what the roboclaw does. Is it possible to get some guidance on how to implement these commands?


----------



## roscoopc (Oct 14, 2014)

This is the schematic for mega & sabertooth. It is somewhere in this thread.
The emergency stop for 2x32 is little different. 
Now I am working on encoders and kangaroo x2 but I am interested to specific command for our driver


----------



## SailorKane (Jan 26, 2015)

Thanks for the schematic. It was what I expected. Just got the clone console to communicate with the mega. My steering is inverted. It appears that the console doesn't pick that up.


----------



## Ovaltineo (Jul 18, 2013)

SailorKane said:


> Also, the new Sabertooth 2x32 has a better set of commands (though it does accept the legacy commands). You can send it M1:x where x is a number from -2047 to +2047. Or M2: x. To command each motor. You can also Get temperature of each output transistor and Get battery voltage. I believe its close to what the roboclaw does. Is it possible to get some guidance on how to implement these commands?


I tried looking up the documentation on the new commands - it is pretty bad that I couldn't see how to do it with checksum. The M1 and M2 commands can be done using simple text, but that is not good enough. Roboclaw is light years ahead when it comes to documentation. Give me some time to overcome my frustration with Sabertooth and possibly incorporate their library.


----------



## Ovaltineo (Jul 18, 2013)

SailorKane said:


> Thanks for the schematic. It was what I expected. Just got the clone console to communicate with the mega. My steering is inverted. It appears that the console doesn't pick that up.


There is a flag that inverts the steering, use that. Or maybe your steering gyro is inverted? If not, then swap the left and right motor connections, then invert the motor + and - (not the battery!).


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
Is there a way to slow the transition between MOTOR_MAX & MOTOR_MAX_OFF instead of it being instant when the Rider Sensor goes low (Rider Off)?


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> Is there a way to slow the transition between MOTOR_MAX & MOTOR_MAX_OFF instead of it being instant when the Rider Sensor goes low (Rider Off)?


This should be possible with some code change. Why do you think this is needed? One of the reasons it is instant is for some protection when the rider accidentally comes off.


----------



## electricpolo (Mar 15, 2011)

I was bench testing the new microswitch rider sensors the other day. They work fine with the motor max, kp & kd settings changing as they should.
I noticed that if I let up on the switches with the motors still moving, the clone would suddenly jerk as the RoboClaw immediately cut the power down to 250. 
That started me thinking that perhaps a ramp down rather than a sudden cut may be better. What do you think?


----------



## SailorKane (Jan 26, 2015)

Ovaltineo said:


> There is a flag that inverts the steering, use that. Or maybe your steering gyro is inverted? If not, then swap the left and right motor connections, then invert the motor + and - (not the battery!).


Ovaltine, thanks so much for the reply. I built "Phase 1A" as a proof of concept on plywood and it functioned, except the console tilt was reversed. So I proceeded to "Phase 1B", still of wood, but laid out as I will build the final. Trying now to sort out the Forward-Reverse and Left-Right issues, both with the motors and display. I frankly didn't think of reversing the motors left and right, M1 and M2--great idea.

In Phase 1A, both gyros were pointed forward, with the X axis arrows pointing forward, gyro boards laying flat, M1 is left motor. I had to use the invert-steering flag. In 1B, I oriented the tilt gyro with X axis pointing aft, and took off the invert flag, thinking that would fix the console, but in retrospect that seems to have been a mistake, since I would like to use your feature to subtract board tilt from steering tilt, eventually, to fix the issue of riding on the side of an incline, so I assume both gyros would have to be oriented the same.

You have a variable for bluetooth that I don't understand: "#define STEER_OFFSET_DIVIDER	-70.0 // bluetooth remote control steer offset (X) divider. Higher value makes X movement less sensitive. Negative value reverses the direction."
I have changed this value and it doesn't seem to change anything on the console. Am I interpreting it wrong or using it wrong? The default is -70. I changed it to +700 and it didn't invert the tilt display on the console or seem to change its sensitivity much.

By the way, I love the console. The aircraft-style display is awesome.


----------



## electricpolo (Mar 15, 2011)

Did a few trials today. Don't think that a ramp down from motor_max to motor_max_off is needed. Doesn't jerk on slowdown when there is a bit of a load.
Still got the odd I2C error though.


----------



## Ovaltineo (Jul 18, 2013)

SailorKane said:


> You have a variable for bluetooth that I don't understand: "#define STEER_OFFSET_DIVIDER -70.0 // bluetooth remote control steer offset (X) divider. Higher value makes X movement less sensitive. Negative value reverses the direction."
> I have changed this value and it doesn't seem to change anything on the console. Am I interpreting it wrong or using it wrong? The default is -70. I changed it to +700 and it didn't invert the tilt display on the console or seem to change its sensitivity much.
> 
> By the way, I love the console. The aircraft-style display is awesome.


The STEER_OFFSET_DIVIDER is only used with the remote control screen (XY) - used primarily for the small balancing robots, though it may work on the bigger ride-on clones too.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Did a few trials today. Don't think that a ramp down from motor_max to motor_max_off is needed. Doesn't jerk on slowdown when there is a bit of a load.
> Still got the odd I2C error though.


Yeah, I think what you simulated on the bench is someone getting off (falling off) while the motors are still going pretty fast. An immediate slowdown is probably good in this case.

I also still get the rare I2C error under very heavy load, but there's no jerk or anything so I just ignore it.


----------



## rajman2500 (Nov 30, 2013)

Hi guys
Started work again on Diy Segway chair steering and Stand


----------



## electricpolo (Mar 15, 2011)

I've decided to relocate the motor controller as far away from the Arduino as possible I can separate it by nearly 300mm. 
Currently, my controller is about 50mm away from the Arduino & I suspect this may be the cause of the persistant, random I2C errors.
I read on a couple of robot forums about people having similar issues with motor controllers (not RoboClaw though) and apart from doing everything else I have already done, they moved the Arduino & the controllers as far apart as possible.
The RoboClaw HV seems to be an especially noisy controller.


----------



## roscoopc (Oct 14, 2014)

@electricpolo
Why do you use a 24v motors? Roboclaw hv supporto higher voltage. 
An higher voltage may be decrease the current flux (ampere) over motor wire (ohm law) and reduce noise. Or not?!


----------



## electricpolo (Mar 15, 2011)

When I first started building a clone, only the RoboClaw 2x60A was available & that was what I bought.
I also designed the frame to fit 8 x 40Ah LiFePo cells which give me a nominal 27V.
So yes, 36V motors may be better for the reasons you mentioned plus they are more powerful. Even though I have a RoboClaw HV, I can't physically fit any more of the 40Ah cells.
If I was to start today, I would probably use 36V motors, a RoboClaw 2x60 HV & Headway cells.


----------



## roscoopc (Oct 14, 2014)

Little off topic. I have just purchased the roboclaw 2x60a hv by Orion Robotics (product code R0415)  http://www.orionrobotics.com/RoboClaw-HV-2x60A-Motor-Controller-60V_p_334.html  
Now I discovered the new versions by Ion Motion Control, product code ION415  http://www.ionmc.com/Brushed-DC_c_7.html  also with higher voltage & amperage! 
Take a look!


----------



## SailorKane (Jan 26, 2015)

I bought the Sabertooth 2x32 before reading this forum, so I'm "stuck" with it. But the newest version (which I have) seems to have worked out a lot of the original objections. Its half the price of the Roboclaw HV, has 4096 power increments, with a $20 Kangaroo addon has encoder support, and can also get temp, voltage and current from the controller. And I haven't had any I2C errors or other noise problems. Our software supports only the legacy Sabertooth control, but the device seems to have improved, esp for the price. Am I nuts?


----------



## roscoopc (Oct 14, 2014)

This is a little video of my clone. A lot of beep but it works smooth. 
Special thanks to Ovaltineo, Electricpolo and other friends of this forum.


----------



## ghirotre (Nov 14, 2014)

Hi,
I have add some code for a lcd in segway.ino
I use a mega board and roboclaw so i have free this pin.
I post the code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup()
{
lcd.begin(16, 2); // initialize lcd
lcd.print("Bat:"); // print on lcd
lcd.setCursor(9, 0);	// set position on lcd
lcd.print("Temp:");	// print on lcd
lcd.setCursor(0, 1);	// set position on lcd
lcd.print("Tilt:"); // print on lcd
lcd.setCursor(9, 1);	// set position on lcd
lcd.print("Turn:"); // print on lcd
}

void loop()
{
lcd.setCursor(4, 0);	// set position on lcd
lcd.print(Vf); // print on lcd
lcd.setCursor(14, 0);	// set position on lcd
lcd.print(temp1); // print on lcd
lcd.setCursor(5, 1);	// set position on lcd
lcd.print(board_angle);	// print on lcd
lcd.setCursor(14, 1);	// set position on lcd
lcd.print(steer_angle);	// print on lcd
}

Example
Bat:24 Temp:30
Tilt:2 Turn:3

I test the skecth with the add monday and i will write the result.
I have put a load cell with hx711, but when i compile i have an error:
HX711.ino:2:19: fatal error: HX711.h: No such file or directory
I need to create a file with some setting? or only need this file https://github.com/aguegu/ardulibs/blob/master/hx711/hx711.h?
Or I only need to delete a hx711.h in hx711.ino.

Very thanks


----------



## Ovaltineo (Jul 18, 2013)

ghirotre said:


> Hi,
> I have add some code for a lcd in segway.ino
> I use a mega board and roboclaw so i have free this pin.
> I post the code:
> ...


For HX711, add the attached library to your IDE. Keep us posted with your LCD. I'll add it to the code if it works. Someday, I'll get the chance to publish this in github .


----------



## Ovaltineo (Jul 18, 2013)

roscoopc said:


> This is a little video of my clone. A lot of beep but it works smooth.
> Special thanks to Ovaltineo, Electricpolo and other friends of this forum.


Nice work ! Are the beeps caused by the battery getting low?


----------



## roscoopc (Oct 14, 2014)

Ovaltineo said:


> Nice work ! Are the beeps caused by the battery getting low?


I think i2c error... Verified changing pattern of this alarm to identify them. This beep are ciclic and constant but they don't affect the drive of clone. I use sabertooth & shielded cable. May be a ground loop that make noise?


----------



## SailorKane (Jan 26, 2015)

Awesome!!! More pictures please. What motors are these? Tire size? How did you do your steering arm? Dimensions (width, height, front-to-back, ground clearance)?

My beeper goes all the time as well. I've disconnected it. I also have the sabertooth. So, it may be related to the sabertooth.


----------



## roscoopc (Oct 14, 2014)

I get rid of beeps, I moved the lm 2596 of arduino dc supply far away from sabertooth and motor wire. That's all!

My Mk2 spec:

-4 mm aluminium removable board 420x340 mm
-wheels10" 3.50 from Vespa scooter (diam 420mm)
-htd belt 5M wide 15 mm
-motors my7618 24v 500w x2 modified with atm 102 encoder (like electricpolo)
-pulley ratio 12:1 max speed 16kmh but big torque 
-battery 12v 14Ah x4 = 24v 28A 16kg
-arduino mega, sabertooth2x32, 2xmpu6050
-total weight 41kg


----------



## SailorKane (Jan 26, 2015)

Thank you for the information. I like the belt drive. I'm using chain drive right now. Where did you get the belt pullys and how did you attach the pully to the motors?


----------



## roscoopc (Oct 14, 2014)

SailorKane said:


> Thank you for the information. I like the belt drive. I'm using chain drive right now. Where did you get the belt pullys and how did you attach the pully to the motors?


I bought the motors with 12 teeth htd pinions fitted. Motors, pinions and belt are used for electric scooter. For example http://www.electricscooterparts.com/ But I can't find a big pulley so I made it using ...wood and duct tape! Strange but it work, the soft and long circumference prevent the belt to slips.


----------



## SailorKane (Jan 26, 2015)

roscoopc said:


> I bought the motors with 12 teeth htd pinions fitted. Motors, pinions and belt are used for electric scooter. For example http://www.electricscooterparts.com/ But I can't find a big pulley so I made it using ...wood and duct tape! Strange but it work, the soft and long circumference prevent the belt to slips.


Thanks for the information. I have hunted far and wide. Your motor MY7618 and also the MY1016 are available with belt drive. The MY1020 motors that I have already purchased don't seem to have belt drive available. So if I REALLY want belt drive, I have to machine a motor pulley or change motors. There are motor pulleys that I could drill out, but not sure its worth the effort right now. My biggest problem right now is the trivial stuff. I had purchased some electric scooter 12.5" wheels, but they are too small and I'm putting too much weight on them and they are collapsing. I have the materials for new wheels: a 10"x2.15" hub, Kenda tires on the way (16" diameter), 15mm axles and bearings. Headed to scooter shop tomorrow morning to get them to press in the new bearings. Also working on a new and improved steering arm. Then maybe Phase 1B will be done.

By the way, here is a link to a company that sells a HTD pulley with 72 teeth, for 5m belt, 15mm wide, 12mm bore. They also have 70 tooth, 62 tooth, etc. Not sure if this would help. 
http://sdp-si.com/ss/pdf/80502127.pdf


----------



## Ovaltineo (Jul 18, 2013)

As promised, SegwayClone is now in Github! 

https://github.com/ovaltineo/SegwayClone

Let me know if you want to be a collaborator (contributor).


----------



## chemamata (Oct 20, 2013)

My sincere congratulations.
I have to repair my clone. I had an accident some time ago and I could not do anything for lack of time.
Now back to read you and try to put the bluetoth, not previously had it since.
I said. congratulations


----------



## ghirotre (Nov 14, 2014)

Hi, congratulation.
Sorry for delay but i have a lot of work.
Today i have tested the code for lcd.
It is ok but there is a problem with the value because are numeber with "," .
I modify the code this weekend and i post the correct code and diagram 
Thanks ovaltine


----------



## SailorKane (Jan 26, 2015)

Looks like Dimension Engineering has a simple guide for the commands for the 2x32 Sabertooth, allowing receipt of temp, battery volts, current, and control to +-2047. 
http://www.dimensionengineering.com/software/USBSabertoothArduinoLibrary/html/

Here's the gist of it:


For example, if you open up a terminal at 9600 baud (8-N-1), all of the following are valid commands you can type:

M1: 0
M1: 2047
M1: -2047
M2: 500
M1: GET
M1: GET B
M1: GET C
M1: GET T
M1: SHUT DOWN
M1: START UP


----------



## roscoopc (Oct 14, 2014)

@ghirotre
On LCD display is also possible add the speed of clone? It's possible add a magnet on wheel and add a magnetic sensor that counts the revolutios. Now I'm adding a little cycle computer to do this. Ciao 

@sailorkane
Do you use the emergency stop on sabertooth2x32? On my clone, when they are engaged one wheel is free (like freewheel command) and the other wheel is like as on electric brake. On describe software I don't find anything of wrong... 
The commands for kangaroox2 are the same for the Sabertooth 2x32?


----------



## roscoopc (Oct 14, 2014)

Ovaltineo said:


> As promised, SegwayClone is now in Github!
> 
> https://github.com/ovaltineo/SegwayClone
> 
> Let me know if you want to be a collaborator (contributor).


In SegwayClone 7.3 we must add this line to segwayclone.h ?


```
#define	ALPHA_SLOW 0.997
```
I also have an error if I define SUBTRACT_BANK_ANGLE

```
SegwayClone.ino: In function 'float getBoardBankAngle(float, float, long int)':

SegwayClone.ino:203:29: error: invalid type argument of unary '*' (have 'float')
```
Thanks for your attention


----------



## ghirotre (Nov 14, 2014)

Hi,
this weekend i have made a lot of try.
I have rewrite the symbol on lcd for better seen.
Tomorrow i post a photo to see the symbol i have made.
The code post the battery value, power that is from 0 to 100(I have a sabertooth on clone that i use for test, i don't know if it is ok always (i think it is need to change the value)), the board angle and the turn angle.
For roscoopc:
If you want a real speed you need or an encoder or reed switch, but i think it is best the value that i used in power, because if you put a reed switch on a wheel when you turn the speed is not real (the 2 wheel don't have the same speed).


```
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
byte bat1[8] = { B00110, B11111, B10000, B10000, B10111, B10000, B10000, B11111 };
byte bat2[8] = { B01100, B11111, B00001, B01001, B11101, B01001, B00001, B11111 };
byte turn[8] = { B00000, B11111, B00100, B00100, B00100, B10101, B11111, B10001 };
byte board[8] = { B00000, B00001, B00001, B00001, B00001, B00101, B11111, B00100 };

void setup()
{
		lcd.createChar(0, bat1);	// initialize symbol
		lcd.createChar(1, bat2);	// initialize symbol
		lcd.createChar(2, turn);	// initialize symbol
		lcd.createChar(3, board);	// initialize symbol
        lcd.begin(16, 2);			// initialize lcd
		lcd.write((byte)0);			// print on lcd
		lcd.write((byte)1);			// print on lcd
		lcd.print(":");				// print on lcd
		lcd.setCursor(6, 0);		// set position on lcd
		lcd.print("Power:");		// print on lcd
		lcd.setCursor(0, 1);		// set position on lcd
		lcd.write((byte)3);	 		// print on lcd
		lcd.print(":");				// print on lcd
		lcd.setCursor(9, 1);		// set position on lcd
		lcd.write((byte)2);			// print on lcd
		lcd.print(":");				// print on lcd
}

void loop()
{
		lcd.setCursor(3, 0);		// set position on lcd
		lcd.print(Vf,0); 			// print on lcd
		lcd.print(" ");	        	// print on lcd
        int power;
        power=motor*.787:
		lcd.setCursor(12, 0);		// set position on lcd
		lcd.print(power);        	// print power(max value motor is 127 so 100/127=0,787 so on lcd you see see from 0 to 100) I use sabertooth
		lcd.print("  ");        	// print on lcd
		lcd.setCursor(2, 1);		// set position on lcd
		lcd.print(board_angle,1);	// print on lcd
		lcd.print("  ");  			// print on lcd
		lcd.setCursor(11, 1);		// set position on lcd
		lcd.print(steer_angle,1);	// print on lcd
		lcd.print("  ");			// print on lcd
}
```
Example
[]:24 Power:-100
-:-10.2 +:-10.2


----------



## ghirotre (Nov 14, 2014)

I post 2 photo, 1 it is power on and other it is power from usb
I hope you like symbol


----------



## SailorKane (Jan 26, 2015)

wELL, GOOD NEWS AND BAD NEWS. Good news is that I fixed my wheel issue. Got some excellent 2.15x10 rims from local scooter shop, drilled out some sprockets to fit the didsk brake pattern of the rim, and put some kenda tires on it that are `65" DISAMETER and look really good . aALso installed somesome 15mmID bearings and 15maxles for strength. .heoretical capaciyAPACIy of each ire 400#, so i should be OK. I allso REPLACED THE SCREN DOOR SPRINGS ON MY CONTROL ARM WITHtorsion SPRINGS AND IT LOOKS GOOD AS WELL. Bad new is that I just came out of ICU at local hospital and though I feel fine, my nurologist says I must not have a fall of any kind. Since I feel a fall is possible on my home-made segway, I'll have o put it away fofr now. SInce a major reason for making a clone was to be able to use it, I owonder if anyone has researched he chinese clones, especially Essway and FReego? Hey seem he mos prominent bfrands being advertised. ELse I might be into buying a used I2 real segway. THe new segway prices are insane.


----------



## Ovaltineo (Jul 18, 2013)

roscoopc said:


> In SegwayClone 7.3 we must add this line to segwayclone.h ?
> 
> 
> ```
> ...



Very sorry about that -- I made changes in SegwayClone.h.ovaltineo but forgot to update the generic SegwayClone.h. I've fixed this in v7.4 which I've uploaded to github.


----------



## Ovaltineo (Jul 18, 2013)

SailorKane said:


> Looks like Dimension Engineering has a simple guide for the commands for the 2x32 Sabertooth, allowing receipt of temp, battery volts, current, and control to +-2047.
> http://www.dimensionengineering.com/software/USBSabertoothArduinoLibrary/html/
> 
> Here's the gist of it:
> ...


I have seen this, but this is not good enough. There is no checksum with plaintext serial. So a corrupted packet (happens easily with noisy motors) can cause a glitch and throw the rider off. I'm after the advanced packet serial version of these commands.


----------



## roscoopc (Oct 14, 2014)

Ovaltineo said:


> Very sorry about that -- I made changes in SegwayClone.h.ovaltineo but forgot to update the generic SegwayClone.h. I've fixed this in v7.4 which I've uploaded to github.


Many thanks!


----------



## franpom (Sep 10, 2014)

Hello,
I try to connect my arduino 2560 to a monster motor shield https://www.sparkfun.com/products/10182 but I have no idea how to do relative to the library motor.h.
On this board, i have for one motor :
EN/DIAG
CS
INA
INB
PWM
Can you help me connect this board to use the program?
Thank you for your help.
Franpom


----------



## electricpolo (Mar 15, 2011)

This driver board isn't really practical for anything except models. 
Certainly no good for anything larger.
Maxxed out at 16V means only 1 12V battery & Max current is only 30A & continuous current is only a very meagre 14A.
The data sheet gives no indication about heatsinks but without them, the chips will fry very fast unless you are using little hobby motors.
My suggestion would be to get bigger motor drivers..


----------



## Ovaltineo (Jul 18, 2013)

franpom said:


> Hello,
> I try to connect my arduino 2560 to a monster motor shield https://www.sparkfun.com/products/10182 but I have no idea how to do relative to the library motor.h.
> On this board, i have for one motor :
> EN/DIAG
> ...


This is already supported. Use L298N_CONTROLLER in SegwayClone.h. Connect LEFT_ENA_PIN to PWM, LEFT_IN1_PIN to INA, and LEFT_IN2_PIN to INB. Same goes for RIGHT motor. Don't connect EN/DIAG and CS.

As electripolo said, this may not be suitable for a ride-on Segway. Practical max continuous current is 14A (most probably with a heatsink). With a 12V battery (max is only 16V), max continuous power is 12V x 14A = 268W. This will only be marginally good for flat ground. Without a heat sink, it may not last long.


----------



## Ovaltineo (Jul 18, 2013)

ghirotre said:


> Hi,
> this weekend i have made a lot of try.
> I have rewrite the symbol on lcd for better seen.
> Tomorrow i post a photo to see the symbol i have made.
> ...


Have you already integrated this code into SegwayClone? Do you want to update the repository in gihub?


----------



## ghirotre (Nov 14, 2014)

Sorry for my long delay but i had a lot of work and a lot of problem with my clone...
My arduino mega has broken a serial port number 1 so i have changed it.
Is it possibile into segwayclone.h to put a selection where i select wich serial port to be used?

For lcd, yes i have just add the code to my segway and it is perfect.
If someone want to use i add the code.

Thanks


----------



## telf (Feb 9, 2015)

Thought I might introduce my project to the thread. 
Its obviously a unicycle (pics below) and was first intended to be a physical clone of the Scitech one but with Ovaltineo's code.
I then saw that awesome Russian one with steering and bars so I thought I'd give that a go instead.
I have now finished the frame (minus footpegs). The swivel is from a cut off caster wheel. The main wheel is a 6.5 inch pitbike wheel geared 11/78 from a 500w 24v MY1020 motor.
Batteries are a pair of 12v 18a/h gels. This is heavy but its what I had lying around. Likewise the wheel would be better if larger but $5 from the tip gives me a good starting point.
Electronics will be the standard MPU 6050, Uno R3, BTS7960 and HC-06.
Questions and comments welcome although you don't need to tell me its heavy.........I already know that! 
The top half can unbolt below the swivel if I want to put some other arrangement on.
Thinking of calling it the 'Lunicycle'.

telf


----------



## Ovaltineo (Jul 18, 2013)

telf said:


> Thought I might introduce my project to the thread.
> Its obviously a unicycle (pics below) and was first intended to be a physical clone of the Scitech one but with Ovaltineo's code.
> I then saw that awesome Russian one with steering and bars so I thought I'd give that a go instead.
> I have now finished the frame (minus footpegs). The swivel is from a cut off caster wheel. The main wheel is a 6.5 inch pitbike wheel geared 11/78 from a 500w 24v MY1020 motor.
> ...


Good job so far! I don't want to imagine the damage when that thing falls over !


----------



## andeew (Jan 18, 2015)

After several weeks without touching the project I am back at - my frame is more or less finished. Need to add an extra cross-member for stiffness and the plates for the electronics and springs to center the steering column.


----------



## andeew (Jan 18, 2015)

Need some advice for springs to center steering tiller.
I want to try to keep the springs hidden from view and was considering these potentials.
I was looking at using compression springs but I am concerned that the force needed to center the tiller so close to it's pivot will mean that the springs will need to be extremely stiff and therefore are likely to bend the plate that I would weld to the tiller's pivot?
Has anyone tried anything like this or have some advice?


----------



## electricpolo (Mar 15, 2011)

Have a look at my clone build. There are quite a few pictures there.
I have used tension springs to keep the handle centred. It works very well but the springs do need to be pretty strong.


----------



## wsm (Jan 6, 2015)

Have a look to my page http://ups.bplaced.de how to center steering tiller.

Look for "Lenkung"

W.


----------



## NirPelzman (Feb 8, 2015)

Hi all im new here my name is nir been in the background started my clone 3 months ago with the first order of parts , and thanks to eran mutai from this forum who helped with getting the motors!

i have the following spec:

2x 24v 240w wheelchair motors.
2x 12v 7ah lead acid battery (will upgrade..)
sabertooth 2x25 
2x mpu 6050 
arduino uno R3 replica
dc to dc 

i have finished all the mechanics and wiring and ready to start mess with software and getting it running .. but! i have noticed that i get lower voltage on motor A from the sabertooth (20v) and its failing to spin . i tested the motor directly outside and it runs ok . could the sabertooth be faulty? must mention the dip switches are still like they came didnt change yet . by the way is the setting 9600 baud? what dip switch to change? sorry if this mentioned before im still reading now at post 76....

another question should i place a fuse? if so which one and where? 
and another... in the schematic looks like i should ground the arduino itself?
isnt the ground that goes from the 11v enogh for all the board?

thanks Nir.


----------



## NirPelzman (Feb 8, 2015)

ok got both motors going acording to the address byte configuration of 128.
but steering dosent seem to work when i connect the laptop to the arduino and press serial monitor on 9600 baud it just run letters with no sense and on 115200 baud it gives the following : 

I2C EWHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
WHO_AM_I : 0, error = -32
PWR_MGMT_2 : 0, error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32

ACCEL: 0.52 GYRO: 0.00 BOARD ANGLE: 0.11 STEER ANGLE: 3.26 MOTOR: 0.33 LEFT: -5 RIGHT: 6 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0
I2C Error = -32
I2C Error = -32
I2C Error = -32



i think the steering gyro might be dead ? how do i check this? i saw you used "who am i " command but i dont know how to implement arduino new to me ..


----------



## andeew (Jan 18, 2015)

finally got mine wired up to test but so far no success 
when powered up I can see the feedback from boards for tilt and steering (they seem to change correctly) but I am not getting any power to the motors. Not seeing any errors in serial monitor either - any suggestions for where to start?
Note - bluetooth works but I cannot get the serial monitor to communicate unless I has USB plugged in



Serial monitor sample output


WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
Try 115200
Try 19200
Try 9600
Try 57600
Try 38400
Bluetooth module not found!

ACCEL: 35.04 GYRO: 0.00 BOARD ANGLE: 7.18 STEER ANGLE: 1.08 MOTOR: 20.00 LEFT: 18 RIGHT: 20 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

ACCEL: 34.86 GYRO: 0.00 BOARD ANGLE: 16.65 STEER ANGLE: 2.42 MOTOR: 20.00 LEFT: 15 RIGHT: 20 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

ACCEL: -10.88 GYRO: -25.51 BOARD ANGLE: -2.80 STEER ANGLE: 1.78 MOTOR: -20.00 LEFT: -20 RIGHT: -16 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

ACCEL: -13.76 GYRO: -5.95 BOARD ANGLE: -6.88 STEER ANGLE: -0.42 MOTOR: -20.00 LEFT: -19 RIGHT: -20 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

ACCEL: -15.36 GYRO: 3.69 BOARD ANGLE: -9.91 STEER ANGLE: -2.33 MOTOR: -20.00 LEFT: -15 RIGHT: -20 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

ACCEL: -13.96 GYRO: -1.43 BOARD ANGLE: -11.31 STEER ANGLE: -3.62 MOTOR: -20.00 LEFT: -13 RIGHT: -20 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0

ACCEL: -14.10 GYRO: 2.79 BOARD ANGLE: -12.44 STEER ANGLE: -4.48 MOTOR: -20.00 LEFT: -12 RIGHT: -20 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltine
Can yoy help me with roboclaw 2*60Hv. I have connected my diy segway clone with roboclaw not working
It's working with sabertooth but not with roboclaw.
TX1 direct to S1, RX1 to S2 & Robo logic ground to Arduino ground

Thanks
rajneesh


----------



## Ovaltineo (Jul 18, 2013)

You need to select Mode 7 on the Roboclaw.


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltine
I have selected mode 7, baud 38400bps.State 1 led on and state2 led 2 blinks fast. but nothing happens.
When i connect roboclaw to my computer thru ion motion software i can control both motors .

Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

Baud should be 115200


----------



## rajman2500 (Nov 30, 2013)

Ovaltineo said:


> Baud should be 115200


How u can set baud rate of roboclaw to 115200

Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

Oops, you are right. It should be 38400. Did you select ROBOCLAW_CONTROLLER in SegwayClone.h?


----------



## rajman2500 (Nov 30, 2013)

Ovaltineo said:


> Oops, you are right. It should be 38400. Did you select ROBOCLAW_CONTROLLER in SegwayClone.h?


Yes i have selected ROBOCLAW_CONTROLLER in SegwayClone.h

//#define PWM_PWM_CONTROLLER
//#define PWM_DIR_CONTROLLER
#define ROBOCLAW_CONTROLLER
//#define ROBOCLAW_ENCODER_CONTROLLER
//#define SABERTOOTH_CONTROLLER
//#define PWM_SHIELD_CONTROLLER
//#define L298N_CONTROLLER
//#define OSMC_CONTROLLER

Serial Monitors shows right battery voltage and temp but there is no movement in motors
ACCEL: -0.50 GYRO: 0.00 BOARD ANGLE: -0.13 STEER ANGLE: 1.11 MOTOR: -300.00 LEFT: -300 RIGHT: -272 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 62 CURRENT2: 0

ACCEL: -0.72 GYRO: 0.00 BOARD ANGLE: -0.13 STEER ANGLE: 1.11 MOTOR: -300.00 LEFT: -300 RIGHT: -272 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 25 CURRENT2: 0

ACCEL: -0.74 GYRO: 0.00 BOARD ANGLE: -0.14 STEER ANGLE: 1.09 MOTOR: -300.00 LEFT: -300 RIGHT: -272 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 12 CURRENT2: 12

ACCEL: -0.04 GYRO: 0.00 BOARD ANGLE: -0.13 STEER ANGLE: 1.09 MOTOR: -300.00 LEFT: -300 RIGHT: -272 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 100 CURRENT2: 0

ACCEL: -0.43 GYRO: 0.00 BOARD ANGLE: -0.13 STEER ANGLE: 1.07 MOTOR: -300.00 LEFT: -300 RIGHT: -273 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 12 CURRENT2: 12

ACCEL: -0.26 GYRO: 0.00 BOARD ANGLE: -0.13 STEER ANGLE: 1.07 MOTOR: -300.00 LEFT: -300 RIGHT: -273 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 100 CURRENT2: 0

ACCEL: 0.23 GYRO: 0.00 BOARD ANGLE: -0.13 STEER ANGLE: 1.06 MOTOR: -300.00 LEFT: -300 RIGHT: -273 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 12 CURRENT2: -12

ACCEL: 0.28 GYRO: 0.00 BOARD ANGLE: -0.15 STEER ANGLE: 1.07 MOTOR: -300.00 LEFT: -300 RIGHT: -273 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 37 CURRENT2: 0

ACCEL: -0.02 GYRO: 0.00 BOARD ANGLE: -0.15 STEER ANGLE: 1.07 MOTOR: -300.00 LEFT: -300 RIGHT: -273 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 87 CURRENT2: -12

ACCEL: 0.40 GYRO: 0.00 BOARD ANGLE: -0.14 STEER ANGLE: 1.08 MOTOR: -300.00 LEFT: -300 RIGHT: -272 VOLTAGE: 23.50 TEMP: 35 CURRENT1: 37 CURRENT2: 0


----------



## Ovaltineo (Jul 18, 2013)

Try it with MOTOR_MAX set to 1500.


----------



## Ovaltineo (Jul 18, 2013)

NirPelzman said:


> ok got both motors going acording to the address byte configuration of 128.
> but steering dosent seem to work when i connect the laptop to the arduino and press serial monitor on 9600 baud it just run letters with no sense and on 115200 baud it gives the following :
> 
> I2C EWHO_AM_I : 68, error = 0
> ...


Yes, your steering gyro is not working. Double check your circuit against the schematic. The steering gyro should have AD0 pin connected to +5. Swap the two gyros to check if you think one of them is dead.


----------



## Ovaltineo (Jul 18, 2013)

andeew said:


> finally got mine wired up to test but so far no success
> when powered up I can see the feedback from boards for tilt and steering (they seem to change correctly) but I am not getting any power to the motors. Not seeing any errors in serial monitor either - any suggestions for where to start?
> Note - bluetooth works but I cannot get the serial monitor to communicate unless I has USB plugged in
> 
> ...


The bluetooth is not for the Serial Monitor. It is for controlling the clone with the Android app. You need to set your Sabertooh DIP switches properly. Search this thread for Sabertooth.


----------



## rajman2500 (Nov 30, 2013)

Ovaltineo said:


> Try it with MOTOR_MAX set to 1500.


Tried same result no movement in motors

ACCEL: -1.40 GYRO: -0.53 BOARD ANGLE: -2.35 STEER ANGLE: -0.40 MOTOR: -1500.00 LEFT: -1489 RIGHT: -1500 VOLTAGE: 23.40 TEMP: 36 CURRENT1: 12 CURRENT2: 150

ACCEL: -3.07 GYRO: 0.00 BOARD ANGLE: -2.25 STEER ANGLE: -0.40 MOTOR: -1500.00 LEFT: -1489 RIGHT: -1500 VOLTAGE: 23.40 TEMP: 36 CURRENT1: 0 CURRENT2: 200

ACCEL: -3.45 GYRO: 1.00 BOARD ANGLE: -2.23 STEER ANGLE: -0.41 MOTOR: -1500.00 LEFT: -1489 RIGHT: -1500 VOLTAGE: 23.40 TEMP: 36 CURRENT1: 25 CURRENT2: 200

ACCEL: -1.75 GYRO: 0.00 BOARD ANGLE: -2.34 STEER ANGLE: -0.40 MOTOR: -1500.00 LEFT: -1489 RIGHT: -1500 VOLTAGE: 23.40 TEMP: 36 CURRENT1: 0 CURRENT2: 175

ACCEL: -0.86 GYRO: -1.53 BOARD ANGLE: -2.34 STEER ANGLE: -0.38 MOTOR: -1500.00 LEFT: -1490 RIGHT: -1500 VOLTAGE: 23.40 TEMP: 36 CURRENT1: 50 CURRENT2: 187


----------



## Ovaltineo (Jul 18, 2013)

Try connecting S3 to +5V. There is supposed to be an internal pull-up resistor but it didn't work for me.


----------



## RonzaGeI (Nov 17, 2014)

Hi,
we want a new project to build a free driver.
If you want to place the code on GitHub.
https://translate.google.it/transla...eiclub.it/index.php/progetti/18-driver-1-5-it
Hello
Ronza (Buzzes)


----------



## NovWAY (Jun 16, 2015)

Hi everyone,

I'm trying to run my clone of segway for my master's thesis.

My configuration is:
- 2 brushed motors, power: 1000W each one
- roboclaw 60A HV
- rechargeable battery AGM 18Ah 48V
- MPU6050 (mounted on steering pipe)
- arduino mega 1280

*I have selected:*

Single sensor to measure board tilt and steering angle. You should mount the sensor on the steering shaft. The I2C address for MPU6050 is 0x68 (AD0 low).

I have now added support for the Roboclaw motor controller. The Roboclaw must be configured for Packet Serial mode, address 0x80, 
and 38400 baud.

To use Roboclaw with a Mega, connect S1 to pin 18 (TX1), and S2 to pin 19 (RX1).

When first used, add/uncomment #define MODE_CALIBRATE and load the program to Arduino.

*So, where's my problem?*
The MPU6050 work's fine, on Serial Monitor I see the changing values of angles etc.

But motors don't want to work. I checked the address 0x80 and 38400 baud in program distributed by roboclaw and motors are working fine.
I was searching in SegwayClone files information about pin out for RX/TX.

And only thing I have found it's:
File: Motors.ino there is:

#if defined(ROBOCLAW_CONTROLLER) || defined (ROBOCLAW_ENCODER_CONTROLLER)
#ifndef MEGA
SoftwareSerial Serial1(SOFT_RX_PIN, SOFT_TX_PIN); // RX, TX
#endif

Where's definition that look like that in example for pin out values:
SOFT_RX_PIN = 19
SOFT_TX_PIN = 18 ?

I really have no idea where to find solution. Please for help.

Best regards.


----------



## Ovaltineo (Jul 18, 2013)

The SOFT_RX_PIN and SOFT_TX_PIN are used only if you are not using a MEGA. Try connecting S3 to +5V.

Also can you post your SegwayClone.h and Motors.h?


----------



## NovWAY (Jun 16, 2015)

I tried this already (put 5V on S3) by reading suggestion in this topic. 

Motors.h

```
// MOTOR_LR_RATIO defines the speed ratio between left and right motors.  Should be 1.0 if motor speeds are identical. 
// Should be > 1 (eg 1.1) if left motor is slower and < 1 (eg 0.9) if left motor is faster.
#define MOTOR_LR_RATIO	1.0

#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER) || defined(PWM_SHIELD_CONTROLLER) || defined(L298N_CONTROLLER) || defined(PWM_PWM_15KHZ_CONTROLLER) || defined(OSMC_CONTROLLER)
	// PWM frequency selector
	#define HZ_31250		1
	#define	HZ_3906			2
	#define HZ_488			3
	#define HZ_122			4
	#define HZ_30			5
#endif

#ifdef L298N_CONTROLLER
	#define MOTOR_MAX		252				// Don't use 255 (100% duty cycle) as MAX for most PWM controllers -- they don't like it
	#define MOTOR_MAX_OFF	100				// MOTOR_MAX when rider sensor is OFF

	#define LEFT_ENA_PIN	3
	#define LEFT_IN1_PIN	11
	#define LEFT_IN2_PIN	2

	#define RIGHT_ENB_PIN	9
	#define RIGHT_IN3_PIN	10
	#define RIGHT_IN4_PIN	7
#endif

#ifdef PWM_SHIELD_CONTROLLER
//	#define MOTOR_MAX		252				// Don't use 255 (100% duty cycle) as MAX for most PWM controllers -- they don't like it
	#define MOTOR_MAX		30
	#define MOTOR_MAX_OFF	30				// MOTOR_MAX when rider sensor is OFF

	#define RIGHT_BACKWARD_PIN	11
	#define RIGHT_FORWARD_PIN	3
	#define RIGHT_ENABLE_PIN	2
	#define RIGHT_DISABLE_PIN	4

	#define LEFT_BACKWARD_PIN	10
	#define LEFT_FORWARD_PIN	9
	#define LEFT_ENABLE_PIN		8
	#define LEFT_DISABLE_PIN	7
#endif

#ifdef PWM_PWM_CONTROLLER
	#define MOTOR_MAX		252				// Don't use 255 (100% duty cycle) as MAX for most PWM controllers -- they don't like it
//	#define MOTOR_MAX		30
	#define MOTOR_MAX_OFF	30				// MOTOR_MAX when rider sensor is OFF

	// PWM pins for motor
	#ifdef MEGA	
		#define RIGHT_BACKWARD_PIN	2
		#define RIGHT_FORWARD_PIN	3
		#define LEFT_BACKWARD_PIN	5
		#define LEFT_FORWARD_PIN	6
		#define MOTOR_ENABLE_PIN	7
	#else
		#define RIGHT_BACKWARD_PIN	9
		#define RIGHT_FORWARD_PIN	10
		#define LEFT_BACKWARD_PIN	3
		#define LEFT_FORWARD_PIN	11
		#define MOTOR_ENABLE_PIN	7
	#endif
#endif

#ifdef PWM_PWM_15KHZ_CONTROLLER
	#define MOTOR_MAX		0x3FE			// Don't use 0x3FF (100% duty cycle) as MAX for most PWM controllers -- they don't like it
//	#define MOTOR_MAX		30
	#define MOTOR_MAX_OFF	120				// MOTOR_MAX when rider sensor is OFF

	// PWM pins for motor
	#ifdef MEGA	
		#define RIGHT_BACKWARD_PIN	2
		#define RIGHT_FORWARD_PIN	3
		#define LEFT_BACKWARD_PIN	5
		#define LEFT_FORWARD_PIN	6
		#define MOTOR_ENABLE_PIN	7
	#endif

	// PWM pins for motor using MEGA with broken pins 2&3
	#ifdef MEGA_BROKEN
		#define RIGHT_BACKWARD_PIN	7
		#define RIGHT_FORWARD_PIN	8
		#define LEFT_BACKWARD_PIN	5
		#define LEFT_FORWARD_PIN	6
		#define MOTOR_ENABLE_PIN	4
	#endif
#endif

#ifdef PWM_DIR_CONTROLLER
//	#define MOTOR_MAX		252				// Don't use 255 (100% duty cycle) as MAX for most PWM controllers -- they don't like it
	#define MOTOR_MAX		30
	#define MOTOR_MAX_OFF	30				// MOTOR_MAX when rider sensor is OFF

	// PWM and DIR pins for motor
	#ifdef MEGA	
		#define RIGHT_PWM_PIN		2
		#define RIGHT_DIR_PIN		3
		#define LEFT_PWM_PIN		5
		#define LEFT_DIR_PIN		6
		#define MOTOR_ENABLE_PIN	7
	#else	
		#define RIGHT_PWM_PIN		9
		#define RIGHT_DIR_PIN		10
		#define LEFT_PWM_PIN		3
		#define LEFT_DIR_PIN		11
		#define MOTOR_ENABLE_PIN	7
	#endif
#endif

#ifdef OSMC_CONTROLLER
//	#define MOTOR_MAX		252				// Don't use 255 (100% duty cycle) as MAX for most PWM controllers -- they don't like it
	#define MOTOR_MAX		30
	#define MOTOR_MAX_OFF	30				// MOTOR_MAX when rider sensor is OFF

	// PWM pins for motor
	#ifdef MEGA	
		#define RIGHT_BACKWARD_PIN	2
		#define RIGHT_FORWARD_PIN	3
		#define LEFT_BACKWARD_PIN	5
		#define LEFT_FORWARD_PIN	6
		#define MOTOR_DISABLE_PIN	7
	#else
		#define RIGHT_BACKWARD_PIN	9
		#define RIGHT_FORWARD_PIN	10
		#define LEFT_BACKWARD_PIN	3
		#define LEFT_FORWARD_PIN	11
		#define MOTOR_DISABLE_PIN	7
	#endif
#endif

#ifdef ROBOCLAW_CONTROLLER
	#define MOTOR_MAX		1500
	#define MOTOR_MAX_OFF	250				// MOTOR_MAX when rider sensor is OFF

	#define ROBOCLAW_ADDRESS 0x80

	// ROBOCLAW packet serial commands
	#define M1_SPEED		32
	#define M2_SPEED		33
	#define READ_TEMP		82
	#define READ_VOLT		24
	#define READ_CURRENTS	49
	#define M1_ACCEL		52
	#define M2_ACCEL		53

	//#define ROBOCLAW_ACCELERATION 32767		// optional acceleration, values 0-65535
	
	#ifndef MEGA
		// software serial pins for non-mega boards
		#define SOFT_RX_PIN	5			// connect to S2 pin
		#define SOFT_TX_PIN	6			// connect to S1 pin
	#endif
#endif

#ifdef ROBOCLAW_ENCODER_CONTROLLER
//	#define MOTOR_MAX		40000
	#define MOTOR_MAX		10000
	#define MOTOR_MAX_OFF	10000		// MOTOR_MAX when rider sensor is OFF
 
	#define ROBOCLAW_ADDRESS 0x80

	// ROBOCLAW packet serial commands
	#define M1_SPEED	35
	#define M2_SPEED	36
	#define READ_TEMP	82
	#define READ_VOLT	24

	#ifndef MEGA
		// software serial pins for non-mega boards
		#define SOFT_RX_PIN	5			// connect to S2 pin
		#define SOFT_TX_PIN	6			// connect to S1 pin
	#endif
#endif

#ifdef SABERTOOTH_CONTROLLER
//	#define MOTOR_MAX		127
	#define MOTOR_MAX		20
	#define MOTOR_MAX_OFF	20			// MOTOR_MAX when rider sensor is OFF

	#define SABERTOOTH_ADDRESS 0x80

	// ROBOCLAW packet serial commands
	#define M1_FORWARD	0
	#define M1_BACKWARD	1
	#define M2_FORWARD	4
	#define M2_BACKWARD	5
	#define SET_BAUD	15
	#define BAUD_38400	4

	#ifndef MEGA
		// software serial pins for non-mega boards
		#define SOFT_RX_PIN	5			// connect to S2 pin
		#define SOFT_TX_PIN	6			// connect to S1 pin
	#endif
#endif

#define MOTOR_ALARM_PERCENT 80
```


```
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0

 ACCEL: 0.66 GYRO: 0.00 BOARD ANGLE: 0.10 STEER ANGLE: -0.08 MOTOR: 3.48 LEFT: 5 RIGHT: 1 VOLTAGE: -1.00 TEMP: -1 CURRENT1: 0 CURRENT2: 0

 ACCEL: 1.33 GYRO: -0.38 BOARD ANGLE: 0.33 STEER ANGLE: -0.25 MOTOR: 24.24 LEFT: 30 RIGHT: 18 VOLTAGE: -1.00 TEMP: -1 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.88 GYRO: 0.00 BOARD ANGLE: 0.45 STEER ANGLE: -0.32 MOTOR: 58.25 LEFT: 66 RIGHT: 50 VOLTAGE: -1.00 TEMP: -1 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.60 GYRO: 0.00 BOARD ANGLE: 0.51 STEER ANGLE: -0.39 MOTOR: 96.06 LEFT: 105 RIGHT: 86 VOLTAGE: -1.00 TEMP: -1 CURRENT1: 0 CURRENT2: 0

 ACCEL: 0.67 GYRO: 0.00 BOARD ANGLE: 0.54 STEER ANGLE: -0.43 MOTOR: 137.82 LEFT: 148 RIGHT: 127 VOLTAGE: -1.00 TEMP: -1 CURRENT1: 0 CURRENT2: 0
```
VOLTAGE: -1.00 TEMP: -1 CURRENT1: 0 CURRENT2: 0 This is strange...


----------



## NovWAY (Jun 16, 2015)

Second post, limit up to 10000 characters. 

SegwayClone.h

```
/*
Uncomment one MODE below
*/
//#define MODE_CALIBRATE
#define MODE_RUN

/*
Uncomment one STEERING type below
*/
//#define POT_STEERING
//#define MPU6050_X2_STEERING
#define MPU6050_X1_STEERING
//#define GY80_STEERING

//#define EXPONENTIAL_STEER_DIVIDER	7	// turns steering from linear to exponential - this specifies the angle where response is higher than linear

/*
Uncomment only if steer MPU6050 is vertically oriented
*/
//#define STEER_Z_GYRO

/*
Uncomment only if using MPU6050_X2 and you want to compensate for terrain banking
*/
#define SUBTRACT_BANK_ANGLE			1.0		// defining this will subtract board bank angle from steer angle.  Value (0 to 1) defines how much bank is used.

/*
Uncomment only if steering left and right are inverted
*/
//#define INVERT_STEERING

/*
Uncomment one CONTROLLER type below
*/
//#define PWM_PWM_CONTROLLER
//#define PWM_DIR_CONTROLLER
#define ROBOCLAW_CONTROLLER
//#define ROBOCLAW_ENCODER_CONTROLLER
//#define SABERTOOTH_CONTROLLER
//#define PWM_SHIELD_CONTROLLER
//#define L298N_CONTROLLER
//#define OSMC_CONTROLLER

/*
Uncomment if you want to check battery voltage.  See note above for resistor divider.
*/
//#define VOLTAGE_CHECK

/*
Uncomment if you want LED Voltage indicator.  You need VOLTAGE_CHECK with this.
*/
//#define VOLTAGE_LED

/*
Uncomment if you want Pushback
*/
//#define PUSHBACK

/*
Uncomment if you have a HC06 "linvor" bluetooth module
*/
//#define BLUETOOTH

/*
Uncomment if you have TC74 temperature sensors - TC74A0 and TC74A2 default addresses in TC74.h
*/
//#define TEMPERATURE_SENSORS

/*
Uncomment if you want the clone to be locked during startup.  It can only be unlocked via CloneConsole Android app.
*/
//#define LOCKED_BY_DEFAULT

/*
Uncomment if you have a rider sensor - sensor must pull this pin to GND/LOW when rider is ON, and leave it open or HIGH when rider is OFF.
Initial values are loaded from KP_OFF, KD_OFF, and MOTOR_MAX_OFF.
*/
//#define RIDER_SENSOR	8

/*
Uncomment if RIDER_SENSOR above has reverse logic, ie HIGH when rider is ON and LOW when rider is OFF
*/
//#define INVERT_RIDER_SENSOR

/*
Uncomment if you have a HX711 weight sensor instead of digital RIDER_SENSOR. HX711_DOUT and HX711_SCK define which pins are 
connected to HX711.  If weight is greater than HX711_MIN, then rider is ON, else rider is OFF.
Initial values are loaded from KP_OFF, KD_OFF, and MOTOR_MAX_OFF.
*/
//#define HX711_DOUT	A6
//#define HX711_SCK		A7
//#define HX711_MIN		50
//#define HX711_REFERENCE_WEIGHT 940	// optional weight of rider where static P & D are based on.  If defined, P & D are computed proportional to rider's weight


//#define FAN_PIN			13				// optional output for MOSFET or relay fan switch

#define BUZZER_PIN			12
#define POT_STEERING_PIN	A1				
#define P_PIN				A0				// optional pot for adjusting P value (Proportional)
#define D_PIN				A2				// optional pot for adjusting D value (Derivative)
//#define POT_TILT_PIN	A4				// optional pot for adjusting forward/backward tilt

#ifdef VOLTAGE_CHECK
	#define VOLTAGE_PIN			A3
//	#define VOLTAGE_PIN			A5			// ovaltine's clone uses this
	#define VOLTAGE_DIVIDER		.176		// voltage divider: 4.7K/(22K + 4.7K) = .176
#endif

// The following 9 lines were borrowed/copied from Multiwii
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
  #define PROMINI
#endif
#if defined(__AVR_ATmega32U4__) || defined(TEENSY20)
  #define PROMICRO
#endif
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
  #define MEGA
#endif

#ifdef VOLTAGE_LED
	#if defined(PWM_SHIELD_CONTROLLER)
		#define LED_GREEN_PIN		A0
		#define LED_YELLOW_PIN		5
		#define LED_RED_PIN			6
	#elif ((defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER)) && !defined(MEGA))
		#define LED_GREEN_PIN		4
		#define LED_YELLOW_PIN		5
		#define LED_RED_PIN			6
	#else
		#define LED_GREEN_PIN		9
		#define LED_YELLOW_PIN		10
		#define LED_RED_PIN			11
	#endif
#endif

typedef struct
{
	float x_accel;
	float y_accel;
	float z_accel;
	float x_gyro;
	float y_gyro;
	float z_gyro;

	int x_accel_offset;
	int y_accel_offset;
	int z_accel_offset;

	int x_gyro_offset;
	int y_gyro_offset;
	int z_gyro_offset;

	int x_gyro_offset_min;
	int x_gyro_offset_max;
	int y_gyro_offset_min;
	int y_gyro_offset_max;
	int z_gyro_offset_min;
	int z_gyro_offset_max;

	int address;
} sensorType;


#define	ALPHA 0.97					// used by complementary filter
#define	ALPHA_SLOW 0.997			// used by slow complementary filter


#if defined(ROBOCLAW_CONTROLLER)
	// use these values if using Roboclaw
	#define KP 3.9					// proportional constant when rider is ON
	#define KD 1.5   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 25     // adjust depending on your motor speed
	#define KP_OFF 1.8				// proportional constant when rider is OFF
	#define KD_OFF .75 				// derivative constant when rider is OFF
#endif
#if defined(ROBOCLAW_ENCODER_CONTROLLER)
	// use these values if using Roboclaw with encoder
	#define KP 10.9					// proportional constant when rider is ON
	#define KD 4.68   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 546     // adjust depending on your motor speed
	#define KP_OFF 5.45				// proportional constant when rider is OFF
	#define KD_OFF 2.34 				// derivative constant when rider is OFF
#endif
#if defined(SABERTOOTH_CONTROLLER)
	// use these values if using Sabertooth
	#define KP .35					// proportional constant when rider is ON
	#define KD .15   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 1.75   // adjust depending on your motor speed
	#define KP_OFF .17				// proportional constant when rider is OFF
	#define KD_OFF .07 				// derivative constant when rider is OFF
#endif
#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER)  || defined(PWM_SHIELD_CONTROLLER) || defined(L298N_CONTROLLER) || defined(OSMC_CONTROLLER)
	// use these values if using PWM
	#define KP .7					// proportional constant when rider is ON
	#define KD .3   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 3.5    // adjust depending on your motor speed
	#define KP_OFF .35				// proportional constant when rider is OFF
	#define KD_OFF .15 				// derivative constant when rider is OFF
#endif

#define MAX_ANGLE  18			// adjust depending on your machine
#define MIN_ANGLE  -15			// adjust depending on your machine
//#define MAX_YAW_RATE_RIDER_OFF	45	// max degrees per second (with rider off) change in direction before safety shutdown
//#define MAX_YAW_RATE_RIDER_ON	90	// max degrees per second (with rider on) change in direction before safety shutdown

#define CALIBRATE_YES	true
#define CALIBRATE_NO	false

#define ACC_FILTER	0.05
#define VOLT_FILTER	0.8

//#define lowpassFilter(val, change, q) ((1-q) * val + (change * q)) 
#define lowpassFilter(val, change, q) (val + q * (change - val))

#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER) || defined(PWM_SHIELD_CONTROLLER) || defined (L298N_CONTROLLER) || defined(L298N_CONTROLLER)
	// bluetooth software serial pins for non-mega boards with PWM controllers
	#define SOFT_RX_PIN3	5			// connect to bluetooth module TX pin
	#define SOFT_TX_PIN3	6			// connect to bluetooth module RX pin
#else	
	// bluetooth software serial pins for non-mega boards with serial controllers
	#define SOFT_RX_PIN3	7			// connect to bluetooth module TX pin
	#define SOFT_TX_PIN3	8			// connect to bluetooth module RX pin
#endif	

#define STEER_OFFSET_DIVIDER	-70.0		// bluetooth remote control steer offset (X) divider.  Higher value makes X movement less sensitive. Negative value reverses the direction.

#ifdef POT_TILT_PIN
	#define BOARD_OFFSET_DIVIDER	1.0		// pot tilt board offset divider.  Higher value makes pot tilt movement less sensitive.  Negative value reverses the direction.
#else
	#define BOARD_OFFSET_DIVIDER	-70.0		// bluetooth remote control board offset (Y) divider.  Higher value makes Y movement less sensitive.  Negative value reverses the direction.
#endif

#define POT_STEERING_ADJUST		0	// modify this to get the POT_STEERING angle centered to zero


//#define SERIAL_WTV020			// WTV020 Voice module on Serial port 2
```
The LED Stat1 is blinking very fast.
The LED Stat2 is on.


----------



## Ovaltineo (Jul 18, 2013)

Please try this test program - the motors should go forwards and backwards continuously.


----------



## NovWAY (Jun 16, 2015)

Hmm... so I see the Stat1 LED is on.
Stat2 LED is on.

Motors off.

Here is my working program for my motors, pin out are 18 and 19 (there are only not flipped in my program) for Arduino MEGA.

I found something interesting, when I change:


```
packet[2] = param >> 8;		// MSB
```
to


```
packet[2] = param;		// MSB
```
Motors are going forwards and backwards continuously.

I make same changes in Segway Clone but wheels are spinning with max rpm.


----------



## RickSoares (Mar 4, 2014)

Ovaltine, good morning!!!!
it would be possible to translate the app into Portuguese ? I'm doing a project for course finish what I do and that we may present everyone, it would be interesting words in Portuguese , it would be possible ?
I would show what words to put right




very thks..

att,

Rick Soares


----------



## Ovaltineo (Jul 18, 2013)

Yes, I can translate it to Portuguese. It would be easier in Spanish though - hablo Espanol un poco .


----------



## Ovaltineo (Jul 18, 2013)

NovWAY said:


> Hmm... so I see the Stat1 LED is on.
> Stat2 LED is on.
> 
> Motors off.
> ...


Your modification is wrong - I am 100% sure that there is no mistake in that part of my code.

That test program works but maybe you didn't wait long enough. It takes about 25 seconds before the motors move. With my motors, they move only when speed is > 50. Here's a faster version of that test program.

Anyway, with the SegwayClone program (without your modification), do you see the speed go up to 1500 and still no movement in the motors?


----------



## NovWAY (Jun 16, 2015)

Ok, so when value was near 800, wheels start to move very slowly, so for test I set max value from 800 to 8000 (I know that max is 1500) and wheels were accelerate still up to 8000.

How it's possible that the values higher than 1500 are accepted by roboclaw?

On your original program, motors are stopped when it's 1500 vs your test program (near values 800) motors are starting turning very slowly.

This are weird stuff.


----------



## Ovaltineo (Jul 18, 2013)

NovWAY said:


> Ok, so when value was near 800, wheels start to move very slowly, so for test I set max value from 800 to 8000 (I know that max is 1500) and wheels were accelerate still up to 8000.
> 
> How it's possible that the values higher than 1500 are accepted by roboclaw?
> 
> ...


What version of the Arduino IDE are you using? Windows, Unix, or Mac?


----------



## NovWAY (Jun 16, 2015)

Ovaltineo said:


> What version of the Arduino IDE are you using? Windows, Unix, or Mac?


Windows, Arduino 1.6.5 Hourly Build 2015/06/12


----------



## Ovaltineo (Jul 18, 2013)

NovWAY said:


> Windows, Arduino 1.6.5 Hourly Build 2015/06/12


Your IDE is the same as mine, so I think your Roboclaw might have a different firmware (with a higher resolution on speed). Can you please try this other test program? It uses a different command (speed with acceleration).


----------



## NovWAY (Jun 16, 2015)

Ovaltineo said:


> Your IDE is the same as mine, so I think your Roboclaw might have a different firmware (with a higher resolution on speed). Can you please try this other test program? It uses a different command (speed with acceleration).


With this program there is no reaction on wheels. 
Your theory about resolution on speed can be real.

----

Ok... so got me thinking...

I search once again about firmware. On my roboclaw there is note "V5"

So datasheet for my robo it's:
http://downloads.ionmc.com/docs/roboclaw_user_manual.pdf
"Hardware V4 and Newer"

New values it's:
"The duty value is signed and the range is -32768 to +32767." so not 1500. Now it works fine with "TestRoboClaw".

So question is, if I change the max_speed value in Segway Clone to 32768, it will be all?


----------



## Ovaltineo (Jul 18, 2013)

NovWAY said:


> With this program there is no reaction on wheels.
> Your theory about resolution on speed can be real.
> 
> ----
> ...


Wow! That is a big change. Yes, change MOTOR_MAX and MOTOR_ MAX_OFF (if you are using rider switch which is HIGHLY RECOMMENDED). Your KP, KD, and STEER_MULTIPLIER values should be bigger too. Start with these values:


```
// use these values if using Roboclaw with new firmware
	#define KP 10.9					// proportional constant when rider is ON
	#define KD 4.68   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 546     // adjust depending on your motor speed
	#define KP_OFF 5.45				// proportional constant when rider is OFF
	#define KD_OFF 2.34 				// derivative constant when rider is OFF
```
I think this will fix rajman2500's problem too (if he still follows this thread).


----------



## rajman2500 (Nov 30, 2013)

Ovaltineo said:


> Wow! That is a big change. Yes, change MOTOR_MAX and MOTOR_ MAX_OFF (if you are using rider switch which is HIGHLY RECOMMENDED). Your KP, KD, and STEER_MULTIPLIER values should be bigger too. Start with these values:
> 
> 
> ```
> ...


Yes Ovaltine i am stilling following this thread. I will try after a week.
Going for holidays.


----------



## Tomczyk (Oct 29, 2013)

Hello gentlemen
I am a first time online
I have a question?
Is there a possibility and possibly how to connect the encoder in the case of PWM and PWM Controller if you need to modify the program I'm counting on your help
sorry for the English translator google
Greetings


----------



## Ovaltineo (Jul 18, 2013)

Tomczyk said:


> Hello gentlemen
> I am a first time online
> I have a question?
> Is there a possibility and possibly how to connect the encoder in the case of PWM and PWM Controller if you need to modify the program I'm counting on your help
> ...


I think it is possible, but you are on your own. I don't have a motor with encoder so I wouldn't be able to write the code for you. I suggest using a dedicated CPU to read the encoder, output the PWM, and communicate with the main Arduino. Alternatively, you can get a Roboclaw controller which already supports encoders.


----------



## NovWAY (Jun 16, 2015)

Ovaltineo said:


> Wow! That is a big change. Yes, change MOTOR_MAX and MOTOR_ MAX_OFF (if you are using rider switch which is HIGHLY RECOMMENDED). Your KP, KD, and STEER_MULTIPLIER values should be bigger too. Start with these values:
> 
> 
> ```
> ...


So I have change values, but still got the problem. Motors don't want to turning.

I'm thinking that there's some errors in communication.
For example I don't receive any information about voltage, temp or current from driver.


----------



## Ovaltineo (Jul 18, 2013)

NovWAY said:


> So I have change values, but still got the problem. Motors don't want to turning.
> 
> I'm thinking that there's some errors in communication.
> For example I don't receive any information about voltage, temp or current from driver.


Did you wait for the speed to go beyond 1000?
I forgot to say that you need to run in CALIBRATE_MODE first to set the KP and KD values. Then you can go back to RUN_MODE.

I will update the firmware on my Roboclaw and see if I get the same problems. I probably won't have time until next weekend though.


----------



## bobbieatendido (Jun 30, 2015)

Hi,
I downloaded Zip, opened the SegwayClone.ino, clicked>Sketch>add File;
Alarms.h
EEPROM.h
I2C.h
MPU6050.h
Motors.h
SegwayClone.h
TC74.h

at SegwayClone.h, i changed:

//#define MODE_RUN

And

#define MPU6050_X1_STEERING
#define PWM_PWM_CONTROLLER

Clicked Verify however i get an error. 
May i please ask for help?


===============================================

Arduino: 1.6.5 (Windows 7), Board: "Arduino Uno"

SegwayClone.ino: In function 'float getSteerAngle(long int)':
SegwayClone:246: error: 'getSteerAccel' was not declared in this scope
SegwayClone:247: error: 'getSteerGyro' was not declared in this scope
SegwayClone.ino: In function 'void setup()':
SegwayClone:278: error: 'initMotors' was not declared in this scope
SegwayClone:279: error: 'initAlarm' was not declared in this scope
SegwayClone:304: error: 'initBoardSensor' was not declared in this scope
SegwayClone:306: error: 'initSteerSensor' was not declared in this scope
SegwayClone.ino: In function 'void loop()':
SegwayClone:350: error: 'getBoardAccel' was not declared in this scope
SegwayClone:351: error: 'getBoardGyro' was not declared in this scope
SegwayClone:364: error: 'controlMotors' was not declared in this scope
SegwayClone:378: error: 'controlMotors' was not declared in this scope
SegwayClone:587: error: 'controlMotors' was not declared in this scope
SegwayClone:595: error: 'alarmHandler' was not declared in this scope
'getSteerAccel' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.


===============================================


----------



## NirPelzman (Feb 8, 2015)

Hi all and ovaltine ,

ive made some change to my diy segway and i cant even stand on it now .. 
it shakes right off and even if im not on it . ive noticed this happens when the segway is leveled , when its in an angle forward or back it dosent shake ..
i planned the placement of the batteries so the segway can balance itself without me holding it . 

mentioning the following :

Backlash on motors axel exist a slight one does this relate to the issue?

will add a video if necessery .

Thanks and hope there is a fix for the issue...


----------



## Ovaltineo (Jul 18, 2013)

bobbieatendido said:


> Hi,
> I downloaded Zip, opened the SegwayClone.ino, clicked>Sketch>add File;
> Alarms.h
> EEPROM.h
> ...


When you unzip, all the files should be in SegwayClone directory. Either double click on SegwayClone.ino or run Arduino IDE and File-Open SegwayClone.ino. It should open all the files in separate tabs. No need to add the other files.


----------



## Ovaltineo (Jul 18, 2013)

NirPelzman said:


> Hi all and ovaltine ,
> 
> ive made some change to my diy segway and i cant even stand on it now ..
> it shakes right off and even if im not on it . ive noticed this happens when the segway is leveled , when its in an angle forward or back it dosent shake ..
> ...


Looks like your P and D values are too high.


----------



## NovWAY (Jun 16, 2015)

Ovaltineo said:


> Did you wait for the speed to go beyond 1000?
> I forgot to say that you need to run in CALIBRATE_MODE first to set the KP and KD values. Then you can go back to RUN_MODE.
> 
> I will update the firmware on my Roboclaw and see if I get the same problems. I probably won't have time until next weekend though.


Yes, of course. I have got values even up to 6000.

I made calibrations as one of the first things.
Personally, I think it is a strange problem with communication in both directions.
Look at log:

```
ACCEL: 0.66 GYRO: 0.00 BOARD ANGLE: 0.10 STEER ANGLE: -0.08 MOTOR: 6000 LEFT: 6000 RIGHT: 6000 VOLTAGE: -1.00 TEMP: -1 CURRENT1: 0 CURRENT2: 0
```
There's no information received from roboclaw.

So I'm very interest what will happend after your firmware upgrade.


----------



## NirPelzman (Feb 8, 2015)

Hi ovaltine ,

Thanks and can you be more specific by now im lost.. where do i change these values?

#if defined(SABERTOOTH_CONTROLLER)
// use these values if using Sabertooth
#define KP .35 // proportional constant when rider is ON 
#define KD .15 // derivative constant when rider is ON
#define STEER_MULTIPLIER 1.75 // adjust depending on your motor speed
#define KP_OFF .17 // proportional constant when rider is OFF
#define KD_OFF .07 // derivative constant when rider is OFF

its in this section?


----------



## Ovaltineo (Jul 18, 2013)

NirPelzman said:


> Hi ovaltine ,
> 
> Thanks and can you be more specific by now im lost.. where do i change these values?
> 
> ...


If you have a Sabertooth controller, yes. You will need to keep modifying them until you get the correct values. Alternatively, if you have a bluetooth module, it is much much easier to modify these on the fly with an Android phone.


----------



## NirPelzman (Feb 8, 2015)

Great! thanks works perfectly! so if the diy segway is well balanced this values should be low ? and high if not balanced good enough ?


----------



## Ovaltineo (Jul 18, 2013)

NirPelzman said:


> Great! thanks works perfectly! so if the diy segway is well balanced this values should be low ? and high if not balanced good enough ?


I wouldn't say that as a rule. It really depends on your motor, wheels, balance point, controller -- everything contributes to the dynamics of the machine. Having said that, a well balanced machine probably means it would be easier for the motors to alter the platform angle (+- the balance point) as opposed to an unbalanced machine.


----------



## Ovaltineo (Jul 18, 2013)

NovWAY said:


> Yes, of course. I have got values even up to 6000.
> 
> I made calibrations as one of the first things.
> Personally, I think it is a strange problem with communication in both directions.
> ...


After painstakingly extracting the controller from my clone, I did the firmware upgrade to 4.1.6. I tested without any firmware change and I can see that the motors are not moving, but the temperature and current readings are working. I increased MOTOR_MAX, MOTOR_MAX_OFF as I originally suggested and uploaded the firmware. I tested and noticed that I had to wait a while before the motors started moving. I increased P and D using the android app and it is now working fine. 

In summary, I applied my suggested changes with the new firmware and it worked for me.

What version of the firmware are you using? I am guessing that your Roboclaw takes a long time to respond to "get temperature" and "get current commands" (-1 means timeout), and it gets swamped with these commands that it never gets a chance to process the "control motor" commands. Try commenting out these lines in SegwayClone.ino:

```
#if defined(ROBOCLAW_CONTROLLER) || defined(ROBOCLAW_ENCODER_CONTROLLER)
				Vf = readVoltage();
				Vi = Vf * 100;
				temp1 = readTemperature();
				temp2 = temp1;
				readCurrents();
			#endif
```


----------



## electricpolo (Mar 15, 2011)

Hi Oval,
I'm going to update the firmware on my RoboClaw shortly.
What P & D values did you wind up with after the update?
Had the clone sitting off to the side for a while as I was doing other things.
I've rearranged the location of the controller as far away from the Arduino as possible & had to redo the power cables.


----------



## Ovaltineo (Jul 18, 2013)

electricpolo said:


> Hi Oval,
> I'm going to update the firmware on my RoboClaw shortly.
> What P & D values did you wind up with after the update?
> Had the clone sitting off to the side for a while as I was doing other things.
> I've rearranged the location of the controller as far away from the Arduino as possible & had to redo the power cables.


I changed MOTOR_MAX from 1500 to 32767 (multiply by about 20), so I changed my P and D values by multiplying current values also by 20. P=20 and D=24.


----------



## Ovaltineo (Jul 18, 2013)

bobbieatendido said:


> Hi Oval,
> 
> I tried it, but when i open the SegwayClone.ino, it only opens that file, the other tabs don't open.
> 
> ...


Have a look at post #219 on page 22, maybe that will help. If not, try uninstalling and re-installing the Arduino IDE. You may also want to check on the Arduino forum -- this is a problem with the IDE, not my code.


----------



## NovWAY (Jun 16, 2015)

Ovaltineo said:


> After painstakingly extracting the controller from my clone, I did the firmware upgrade to 4.1.6. I tested without any firmware change and I can see that the motors are not moving, but the temperature and current readings are working. I increased MOTOR_MAX, MOTOR_MAX_OFF as I originally suggested and uploaded the firmware. I tested and noticed that I had to wait a while before the motors started moving. I increased P and D using the android app and it is now working fine.
> 
> In summary, I applied my suggested changes with the new firmware and it worked for me.
> 
> ...


Hi! Good news. I started today with "fresh" program. I downloaded it, make basic changes in PID values, max speed, cut off speed. After that: calibration, run mode and it work!

Now for the first I'm receiving info from robo driver (temp, volt, etc.)

So now it's time for outside tests.  When I finished I will put some photos of my clone. 

I make update for my robo driver, now it's 4.1.6 (the last one).


----------



## BlackCrowBlues (Jun 10, 2015)

Hi Ovaltine,

i'm going to build something like the RoboWell Juno (Google-Translation) for my Youngster.
I will modify the frame for a brushed motor and use a Rosta Rubber Suspension Unit for the connection between the seat and the wheel.

Have you seen the electric brake he is using?
Looks like a good idea. I think i will tinker around with your Pushback function and see what will happen 

By the way: Your code is really well written and easy to understand.


----------



## Ovaltineo (Jul 18, 2013)

BlackCrowBlues said:


> Hi Ovaltine,
> 
> i'm going to build something like the RoboWell Juno (Google-Translation) for my Youngster.
> I will modify the frame for a brushed motor and use a Rosta Rubber Suspension Unit for the connection between the seat and the wheel.
> ...


That's really nice. You may want to look back at old posts on this thread because someone else has done the same project.

Rosta blocks would have been much better than bearings and springs for my steering, but they are so over-priced in Australia ($234 each) so I didn't use them. I couldn't get any discount even though I promised to promote them in this "popular" thread. Their clients here are billion-dollar mining companies so they can charge exorbitant prices.

For the electronic brake, you can #define POT_TILT_PIN and convert *getTiltAngle* to always return a negative number (Change pot = pot - 512 to pot = -pot).


----------



## BlackCrowBlues (Jun 10, 2015)

Ovaltineo said:


> That's really nice. You may want to look back at old posts on this thread because someone else has done the same project.


Tsss... how could i have over read that?



Ovaltineo said:


> Rosta blocks would have been much better than bearings and springs for my steering, but they are so over-priced in Australia ($234 each) so I didn't use them.


Here in Germany they cost me ~20€ each.



Ovaltineo said:


> For the electronic brake, you can #define POT_TILT_PIN and convert *getTiltAngle* to always return a negative number (Change pot = pot - 512 to pot = -pot).


Nice and easy solution. Thank you. 
The E-Bike/Pedelec Brake Lever seems to have 3 pins, so i will try them.


----------



## NirPelzman (Feb 8, 2015)

Hi all ,

getting the segway up and running i have encountered new issues.. maybe you can assit ..

i have a horn installed connected to the 12v coming from the dc2dc and noticed when pressing it while on the move it halts the segway! when only balancing on it back and forth theres no issue and horn dosent affect the machine .. my question does this caoused by drawing to much current ??

another related issue is while cruising today all confident building speed (not very fast)suddenly came to halt and threw me away .. the angle wasnt sharp maybe center of gravity changed when i leaned to much ? is this related to the 127 motor speed ? what is the reason for a motor to halt ?

and one more i noticed at some point when i had the segway on the bench and let the motors run it seem to power back the arduino and the gyro leds blinked .. is this safe for back current to affect the controller? 

sorry for long post ! 

Thanks ,
Nir.


----------



## NirPelzman (Feb 8, 2015)

Little video spining in the house

Outdoors self balancing


----------



## Ovaltineo (Jul 18, 2013)

NirPelzman said:


> Hi all ,
> 
> getting the segway up and running i have encountered new issues.. maybe you can assit ..
> 
> ...


Are you using a car horn? A car horn draws a lot of current and could cause a brownout/reset on the Arduino. You are better off connecting the horn to one of the batteries directly. 

Do you have a beeper connected to the Arduino to play the error codes? It is highly recommended because the error code can tell you what happened. 

Here are some causes of a motor halt:
1. over angle - check your MAX_ANGLE and test it on the bench. Adjust if necessary
2. power brownout (voltage too low) causing the Arduino to reset. Make sure dc2dc has sufficient current output. 
3. power surge from the motors/controller causing the Arduino to hang or reset. I use an isolated dc2dc module and optoisolators for connecting the Arduino to controller.
4. loose connections - solder directly if possible and use good connectors


----------



## NirPelzman (Feb 8, 2015)

Thanks will check all above.

i use the following dc2dc is it isolated ?

and can you mention which optoisolator you use between arduino and controller ? 

Thanks , 

Nir .


----------



## Ovaltineo (Jul 18, 2013)

NirPelzman said:


> Thanks will check all above.
> 
> i use the following dc2dc is it isolated ?
> 
> ...


That module is not isolated. I am using this 24V to 5V module http://www.goodluckbuy.com/mdc5-s5c-24v-to-5v-1a-5w-dc-dc-isolated-power-module.html. I bypass the inefficient internal Arduino 12V-to-5V converter by connecting the output directly to GND and +5V. Alternatively, you can get this 24V to 12V module http://www.goodluckbuy.com/mds5-s12c-24v-to-5v-1a-5w-dc-dc-isolated-power-module.html.

I use 4N38A optoisolators -- see schematic on post #1110 page 111 -- but you can use other ones like 4N25 -- see post #1106.

Here are a couple of cheap controllers which are already opto-isolated. I would have bought them if I didn't have the Roboclaw already.

http://www.goodluckbuy.com/60a-mos-opto-isolated-dual-channel-h-bridge-dc-motor-driver-module.html

http://www.goodluckbuy.com/100a-mos-opto-isolated-dual-channel-h-bridge-dc-motor-driver-module.html


----------



## NirPelzman (Feb 8, 2015)

Thanks ordered the DC2DC but cant find this part 4N38A ... not on digikey aswell..


----------



## Ovaltineo (Jul 18, 2013)

NirPelzman said:


> Thanks ordered the DC2DC but cant find this part 4N38A ... not on digikey aswell..


Get the equivalent 4N35. You can get it from ebay ($2.99 for 10pcs), digikey, mouser.


----------



## NirPelzman (Feb 8, 2015)

great thanks!


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltine' made another video 

Using joystick to control and using sabertooth 2*60

http://youtu.be/9Yedzf5KbK8

Thanks
Raju


----------



## Ovaltineo (Jul 18, 2013)

rajman2500 said:


> Hi Ovaltine' made another video
> 
> Using joystick to control and using sabertooth 2*60
> 
> ...


Excellent!


----------



## rajman2500 (Nov 30, 2013)

Hello ovaltine
I am using roboclaw 2*60hv ver 4.1.7. Now it is working good but iam not getting voltage and temp.

Current Roboclaw Firmware Version

Firmware Changes List
//4.1.7 changes
//Adjusted overcurrent temperature range calculation
//added button swap option to general settings

//4.1.6 changes
//changed pwmcnt to volatile

//4.1.5 changes
//changed read back delay to use timer instead of cycle count

//4.1.4 changes
//modified speed/velocity control in RC/Analog mode.
//changed current chopping to use raw current and chop every PWM cycle
//Removed overcurrent timeout
//Changed overcurrent calculation based on temperatures between 25c and 85c
//Changed maxcurrent reduction calculation based on temperatures between 85c and 100c

//4.1.3 changes
//USB detach/re-attach code updated

//4.1.2 changes
//Changed battery voltages to signed calculation
//Modified battery cutoff settings
//Modified battery auto cell count detect
//Changed SetConfig/GetConfig to set/get bits in ram only. Must use WriteNVM to save all settings from now on.
//Changed checksum calculation on re-set encoder commands

//4.1.1 changes
//Added timeouts on USB while loops. Roboclaw buttons work even if the PC USB port stalls.
//Changed current offset calibration for better accuracy

//4.1.0 changes
//Added new error/warning code. GetErrorStatus command now returns 16bits of data
//Changed encoder re-set command to support values larger than 65535

//4.0.9 changes
//Added max current chopper to elliminate overcurrent error
//Temperature Current ramp down(85C to 100C) based on timer

//4.0.8 changes
//Added individual encoder re-set commands
//Added user settable acceleration config for rc/analog/simple serial modes

//4.0.7 changes
//Added Autotune functions added

//4.0.6 changes
//Changed current sense filter period to 3.3ms

//4.0.5 changes
//Changed CalcPWM to update 300+ times per second(reduces processor over head)
//Changed all analog readings to be updated 300+ times per second
//Changed overcurrent timeout to be 2.56seconds

//4.0.4 changes
//Added gettemp2 command

//4.0.2 changes
//Changed to polled USB communicatiosn so USB can't interfere with motor control interrupts.
//Changed read current to every PWM pulse edge

//4.0.0 changes
//Added USB Bootloader
Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

NovWay had the same problem but mysteriously solved it by reloading the Arduino program. Look at post #1407. Or maybe your RX1 is not connected to S2. Or maybe there is a bug in firmware 4.1.7 - my Roboclaw is on 4.1.6 and it works. I'll upgrade on the weekend and see if it breaks.


----------



## rajman2500 (Nov 30, 2013)

Hi Ovaltine
I am having problem with Arduino mega sometime it work fine but sometime it keeps rebooting.
Can i use Arduino Due i have one spare

Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

The ports on the Due look the same as on the Mega, so it may work. In SegwayClone.h, change the following line from


#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)


to

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__ || __SAM3X8E__)

However, I've had the same problem with a MEGA on a robot I am working on. It turns out that the 12V plug I am using is not quite a snug fit -- it loses contact with vibration and causes a reset. Easily fixed by taping it down.


----------



## Ovaltineo (Jul 18, 2013)

Apologies for not reporting back about the Roboclaw firmware upgrade. I haven't had a chance to do it yet -- I've been busy building a concrete cleaning robot . It is essentially the same as the Segway clone without the balancing code (it has 3 wheels). It will be carrying a high-pressure water jet sprayer. It can be controlled using the same Android app. I am planning to add an autonomous capability to zigzag along a configurable rectangular pattern. I may also add a Pixy camera for navigation.


----------



## rajman2500 (Nov 30, 2013)

Ovaltineo said:


> The ports on the Due look the same as on the Mega, so it may work. In SegwayClone.h, change the following line from
> 
> 
> #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
> ...


Hi Ovaltine
After changing the code there are errors. error rep attacted please take look.
Problem is not 12v plug. My Mega board got wet by accident after that it started giving problems. 
Thanks
Rajneesh


----------



## Ovaltineo (Jul 18, 2013)

Sorry, I now realize there's too much work to make it compatible with the Due .


----------



## rajman2500 (Nov 30, 2013)

Ovaltineo said:


> Sorry, I now realize there's too much work to make it compatible with the Due .


No problem i will get new arduino mega in week.


----------



## Manuel Silva (Jun 20, 2014)

Hello Ovaltine!

I would like to build a segway clone. I have been reading this thread and most of the components are easily find, the most difficult parts for me are the motors.
Can you please let me know what motors the most adequate to build de Segway clone?

Thanks in advance for your help.

Regardes,
Manuel


----------



## adamson (Mar 2, 2014)

Ovaltineo said:


> Apologies for not reporting back about the Roboclaw firmware upgrade. I haven't had a chance to do it yet -- I've been busy building a concrete cleaning robot . It is essentially the same as the Segway clone without the balancing code (it has 3 wheels). It will be carrying a high-pressure water jet sprayer. It can be controlled using the same Android app. I am planning to add an autonomous capability to zigzag along a configurable rectangular pattern. I may also add a Pixy camera for navigation.


Hi Ovaltineo! I also think about something similiar like lawn mower


----------



## BlackCrowBlues (Jun 10, 2015)

I found something of interest for all who use the BTS7960.
The website is from Germany, so if anything in the translation is unclear send me a message.
Modification of the BTS-H-bridges


----------



## RickSoares (Mar 4, 2014)

Hello guys, okay?
I've been through this topic, and these pictures show them that we are starting a project called ALPHAWAY, and I will rely on all the programming of our dear Ovaltineo as passionate about mechatronics, we are doing the job completion based course in Segway, we are practically all assembled, we already have mtas parts, we're painting right now, will some pictures ... but rather wanted to ask a question ... it is necessary to find the center of gravity of the cart?
and another question ... one can handle quite btn placing coolers to cool them ?, hugs ....

What a u thinking about it?


----------



## Ovaltineo (Jul 18, 2013)

That looks nice and solid, but why do you have the frame around the wheels? The edges are dangerous for pedestrians, walls and furniture! It also makes it too wide to go through standard doors.

It helps to have it balanced, but not totally necessary. If it is too heavy on either side, it just won't be able to stay in one place without a rider.

I didn't quite understand your question about the BTN. They need a fan, because they can overheat. Don't use BTN for uphill -- they will burn/short and the machine can go out of control. This happened to me 3 times!


----------



## BlackCrowBlues (Jun 10, 2015)

I've got my Onewheel almost running. Pictures and videos coming soon.
But i have a last little problem. I installed a TC74A0 on my BTS7960 and if i compile it with

```
#define TEMPERATURE_SENSORS
```
 i get not only plausible temperatures, i get also an I2C Error -32 and an annoying beeping...


----------



## RickSoares (Mar 4, 2014)

Ovaltineo said:


> That looks nice and solid, but why do you have the frame around the wheels? The edges are dangerous for pedestrians, walls and furniture! It also makes it too wide to go through standard doors.
> 
> It helps to have it balanced, but not totally necessary. If it is too heavy on either side, it just won't be able to stay in one place without a rider.
> 
> I didn't quite understand your question about the BTN. They need a fan, because they can overheat. Don't use BTN for uphill -- they will burn/short and the machine can go out of control. This happened to me 3 times!


I dont understand what you said about the btn, simply I bought, but I'm too heavy, weight around 145 kilos, then it gets complicated ... here in Brazil only has the btn, I do not think the other, but I could do a drive with mosfet, what u think? will be befitting replace btn by the driver, 100A?


----------



## Ovaltineo (Jul 18, 2013)

BlackCrowBlues said:


> I've got my Onewheel almost running. Pictures and videos coming soon.
> But i have a last little problem. I installed a TC74A0 on my BTS7960 and if i compile it with
> 
> ```
> ...


The code is written to use both TC74A0 and TC74A1 (one for each motor controller). It is giving an error because it cannot find the TC74A1. To fix, just comment out the code for the TC74_ADD2, like this

```
int error1 = TC74_read (TC74_ADD1, &temp1);
//				int error2 = TC74_read (TC74_ADD2, &temp2);
				if (error1)
				{
					temp1 = -1;
					alarmArray[ALARM_I2C] = 1;
					Serial.print(F("I2C Error = "));
					Serial.println(error1,DEC);
				}
/*
				if (error2)
				{
					temp2 = -1;
					alarmArray[ALARM_I2C] = 1;
					Serial.print(F("I2C Error = "));
					Serial.println(error2,DEC);
				}
*/
```


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> I dont understand what you said about the btn, simply I bought, but I'm too heavy, weight around 145 kilos, then it gets complicated ... here in Brazil only has the btn, I do not think the other, but I could do a drive with mosfet, what u think? will be befitting replace btn by the driver, 100A?



I think the BTN will struggle with 145 kilos. If you can make PWM full H-bridge controllers using 100A mosfets, that would be good. But it can get difficult and expensive, it will be better if you can obtain this - http://www.goodluckbuy.com/100a-mos-opto-isolated-dual-channel-h-bridge-dc-motor-driver-module.html


----------



## RickSoares (Mar 4, 2014)

Ovaltineo said:


> I think the BTN will struggle with 145 kilos. If you can make PWM full H-bridge controllers using 100A mosfets, that would be good. But it can get difficult and expensive, it will be better if you can obtain this - http://www.goodluckbuy.com/100a-mos-opto-isolated-dual-channel-h-bridge-dc-motor-driver-module.html



My God! if I could afford I would buy, $ 1 in Brazil is 4.20 reais, my money, and also takes a long time to come ... I'll end up riding a PWM aki same, just do not know where to start mounting, some have viewed project? or will have someone in the forum who already did ???
what u think of using brushless motor? best motor brushed?
encomodar very sorry, but now that stand have to go out! kkk hugs!


----------



## RickSoares (Mar 4, 2014)

RickSoares said:


> My God! if I could afford I would buy, $ 1 in Brazil is 4.20 reais, my money, and also takes a long time to come ... I'll end up riding a PWM aki same, just do not know where to start mounting, some have viewed project? or will have someone in the forum who already did ???
> what u think of using brushless motor? best motor brushed?
> encomodar very sorry, but now that stand have to go out! kkk hugs!



And for me to do small tests, I can use that L298N? as would be the connection? programming change something? Hugs!


----------



## adamson (Mar 2, 2014)

Ovaltineo, this: http://www.goodluckbuy.com/100a-mos-opto-isolated-dual-channel-h-bridge-dc-motor-driver-module.html can be as replacement of BTN ? The code supports this driver? 
Thanks!


----------



## Ovaltineo (Jul 18, 2013)

adamson said:


> Ovaltineo, this: http://www.goodluckbuy.com/100a-mos-opto-isolated-dual-channel-h-bridge-dc-motor-driver-module.html can be as replacement of BTN ? The code supports this driver?
> Thanks!


It is supported by using L298N_CONTROLLER.


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> My God! if I could afford I would buy, $ 1 in Brazil is 4.20 reais, my money, and also takes a long time to come ... I'll end up riding a PWM aki same, just do not know where to start mounting, some have viewed project? or will have someone in the forum who already did ???
> what u think of using brushless motor? best motor brushed?
> encomodar very sorry, but now that stand have to go out! kkk hugs!


Unfortunately, this project needs a bit of cash . Brushless motor and brushless controllers are better, but at this power level, they are much more expensive than brushed.


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> And for me to do small tests, I can use that L298N? as would be the connection? programming change something? Hugs!


For miniature segway, you can use L298N. Specify L298N_CONTROLLER instead of PWM_PWM_CONTROLLER in SegwayClone.h. Connection pins are defined in Motors.h

```
#ifdef L298N_CONTROLLER
	#define LEFT_ENA_PIN	3
	#define LEFT_IN1_PIN	11
	#define LEFT_IN2_PIN	2

	#define RIGHT_ENB_PIN	9
	#define RIGHT_IN3_PIN	10
	#define RIGHT_IN4_PIN	7
#endif
```


----------



## RickSoares (Mar 4, 2014)

Excuse my English, but I have some doubts and must eliminate my mistakes to continue the project.
the libraries I have to install the correct Arduino? I have to change to run the small segway? I not understand what you said to me ...
another question ... appeared mtos errors while checking the Arduino, do these mistakes disappear with the installation of libraries in arduino?
I will first test bench in the small model, then I'll start getting bigger project ... sorry bothering but I need help ... hugs and thank you for strength!


----------



## BlackCrowBlues (Jun 10, 2015)

Ovaltineo said:


> The code is written to use both TC74A0 and TC74A1 (one for each motor controller). It is giving an error because it cannot find the TC74A1. To fix, just comment out the code for the TC74_ADD2


Yes, i found it at the very same evening. 
Another speciality of my vehicel: I have only one motor and no steering. So i set the STEER_MULTIPLIER to 0.0. 

My last problem: If i lean with more pressure forward, the motor reports a max motor alarm and shuts down; immediately.
It didn't have the time to counterbalance the leaning.

I think it is the result of my not so qualified tinkering with the P- and D-Values (and my lack of fine motor skills).

Can you explain the pages and values of your CloneConsole?
Or even better: upload your code to Github?_

I can't thank you enough for all your work. How can i support you?
https://twitter.com/Cr38t1v3Cha0s
_


----------



## homer32 (Aug 10, 2015)

Hello,
I am new to this forum. I am Spain and use google translator. Sorry if there is any phrase that is not understood.

first to thank all forum users Ovaltine especially for the great work he has done.

My intention is to make a clone of Segway, the moment I made a small replica and works quite well, I used the Arduino program that is in the first post.

not if you could adjust a bit P and D . I installed two potentiometers to regulate these signals.

I've used:
1- MPU6050
1-Arduino UNO
Module 1 L298
1-pack of bateries (12V)
2 - geared motors
Bluetooth module 1- H-06

The bluetooth module I have not yet tested the phone, but seems to work the data led on and off quickly.

that improvements could make?
now it holds in balance a little, about 15 seconds. Starts to increase the speed and eventually falls.

leave some links to videos of the tests.

https://youtu.be/Jb1VKtd2kSE

https://youtu.be/4NUwNlaSvk4


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> Excuse my English, but I have some doubts and must eliminate my mistakes to continue the project.
> the libraries I have to install the correct Arduino? I have to change to run the small segway? I not understand what you said to me ...
> another question ... appeared mtos errors while checking the Arduino, do these mistakes disappear with the installation of libraries in arduino?
> I will first test bench in the small model, then I'll start getting bigger project ... sorry bothering but I need help ... hugs and thank you for strength!


You don't need to include any libraries. You must edit SegwayClone.h and comment/uncomment the appropriate motor controller. Please post the errors that you get. Also, post your SegwayClone.h.


----------



## Ovaltineo (Jul 18, 2013)

BlackCrowBlues said:


> Yes, i found it at the very same evening.
> Another speciality of my vehicel: I have only one motor and no steering. So i set the STEER_MULTIPLIER to 0.0.
> 
> My last problem: If i lean with more pressure forward, the motor reports a max motor alarm and shuts down; immediately.
> ...


I don't think it is the MAX_MOTOR alarm because the motors would not stop if this is the case. The motor will stop only if the board pitch exceeds MAX_ANGLE, so you may want to modify this. But it is likely that your P or D values are simply too low.

The first page of CloneConsole is self-explanatory. The page with the red circle is a GPS-based speedometer. You can use it to measure the speed of your machine (while you are riding it). The page with Lock and Calibrate allow you to electronically Lock/Unlock your machine - for safety this only works while stationary. "Calibrate" allows you to calibrate your sensor without reloading the firmware. Finally, the page with the axis is a joystick control for use on small Segway robots (must be top heavy). Sorry, I can't publish the source code for it because I have future plans to use it commercially.


----------



## Ovaltineo (Jul 18, 2013)

homer32 said:


> Hello,
> I am new to this forum. I am Spain and use google translator. Sorry if there is any phrase that is not understood.
> 
> first to thank all forum users Ovaltine especially for the great work he has done.
> ...


Good work! I can see that the robot is heavy on one side, that's why it wants to move to the left than stay in place. Static balance doesn't matter too much on the ride-on Segway, but crucial for small balancing robots. Once you have balanced your robot, fine tune your P and D values more. This is easier using the CloneConsole app than adjusting the pots.


----------



## homer32 (Aug 10, 2015)

ovaltine hello,
I installed the CloneConsole in a tablet of the brand BQ, edison3 model, android version 4.4.2

- Connect the minisegway and properly connected to the tablet, I see how the engines work on the tablet, I change the value of P and D, I give to save (not if stored properly?)

- The second screen feature do? It is to match the address?

- On the third screen the X and Y with the finger will move the vector coming out, but the minisegway does nothing.
This screen is not serious to control the robot mode joystick?

- In the fourth screen are two options: calibrate and block.
If you press calibrate the tablet is stuck and unresponsive.
If you click lock, it appears to block the console.

Other questions?
1- The sensor MPU6050 it's on the second floor of the robot, it would be better to lower it to the first floor that would be closer to the axis of reducing engine?
2- be possible to install an LCD for speed, rpm, settings, etc ..

Thank you.


----------



## blinkers (Oct 5, 2015)

It is possible, if so tell me how?


----------



## RickSoares (Mar 4, 2014)

Ovaltineo said:


> You don't need to include any libraries. You must edit SegwayClone.h and comment/uncomment the appropriate motor controller. Please post the errors that you get. Also, post your SegwayClone.h.











Hello, Boss, I'm sorry ... but I can not understand ...
want to ride the small segway for testing, and learn with the small, then with the great ... I have L298N, only it did not understand where I change the programs, and how do I chamalos in the Arduino ... Arduino is giving many mistakes , I can not identify what it is ....


----------



## RickSoares (Mar 4, 2014)

Boss, problems do not go Arduino ...

follows the list and if you can help me ... I will thank a lot!


```
SegwayClone.ino:29:17: error: I2C.h: No such file or directory
SegwayClone.ino:30:25: error: SegwayClone.h: No such file or directory
SegwayClone.ino:31:20: error: Motors.h: No such file or directory
SegwayClone.ino:32:20: error: Alarms.h: No such file or directory
SegwayClone.ino:33:18: error: TC74.h: No such file or directory
SegwayClone.ino: In function 'void getPD()':
SegwayClone:133: error: 'KP' was not declared in this scope
SegwayClone:134: error: 'KD' was not declared in this scope
SegwayClone:135: error: 'KP_OFF' was not declared in this scope
SegwayClone:136: error: 'KD_OFF' was not declared in this scope
SegwayClone.ino: In function 'float complementaryFilter(float, float, long int, float, float)':
SegwayClone:159: error: 'ALPHA' was not declared in this scope
SegwayClone.ino: In function 'float complementaryFilterSlow(float, float, long int, float, float)':
SegwayClone:167: error: 'ALPHA_SLOW' was not declared in this scope
SegwayClone.ino: In function 'float getBoardPitchAngle(float, float, long int)':
SegwayClone:177: error: 'ACC_FILTER' was not declared in this scope
SegwayClone:177: error: 'lowpassFilter' was not declared in this scope
SegwayClone.ino: In function 'float getSteerAngle(long int)':
SegwayClone:246: error: 'getSteerAccel' was not declared in this scope
SegwayClone:247: error: 'getSteerGyro' was not declared in this scope
SegwayClone:248: error: 'ACC_FILTER' was not declared in this scope
SegwayClone:248: error: 'lowpassFilter' was not declared in this scope
SegwayClone.ino: In function 'void buzzer(float)':
SegwayClone:268: error: 'BUZZER_PIN' was not declared in this scope
SegwayClone:270: error: 'BUZZER_PIN' was not declared in this scope
SegwayClone.ino: In function 'void setup()':
SegwayClone:276: error: 'I2c' was not declared in this scope
SegwayClone:278: error: 'initMotors' was not declared in this scope
SegwayClone:279: error: 'initAlarm' was not declared in this scope
SegwayClone:304: error: 'CALIBRATE_NO' was not declared in this scope
SegwayClone:304: error: 'initBoardSensor' was not declared in this scope
SegwayClone:306: error: 'initSteerSensor' was not declared in this scope
SegwayClone.ino: In function 'void loop()':
SegwayClone:350: error: 'getBoardAccel' was not declared in this scope
SegwayClone:351: error: 'getBoardGyro' was not declared in this scope
SegwayClone:359: error: 'ALARM_LOCKED' was not declared in this scope
SegwayClone:364: error: 'controlMotors' was not declared in this scope
SegwayClone:377: error: 'ALARM_LEVEL' was not declared in this scope
SegwayClone:378: error: 'controlMotors' was not declared in this scope
SegwayClone:397: error: 'BOARD_OFFSET_DIVIDER' was not declared in this scope
SegwayClone:409: error: 'MOTOR_MAX' was not declared in this scope
SegwayClone:411: error: 'MOTOR_MAX_OFF' was not declared in this scope
SegwayClone:420: error: 'STEER_OFFSET_DIVIDER' was not declared in this scope
SegwayClone:440: error: 'STEER_MULTIPLIER' was not declared in this scope
SegwayClone:455: error: 'MOTOR_ALARM_PERCENT' was not declared in this scope
SegwayClone:456: error: 'ALARM_MAX_MOTOR' was not declared in this scope
SegwayClone:459: error: 'MOTOR_LR_RATIO' was not declared in this scope
SegwayClone:473: error: 'MIN_ANGLE' was not declared in this scope
SegwayClone:473: error: 'MAX_ANGLE' was not declared in this scope
SegwayClone:587: error: 'controlMotors' was not declared in this scope
SegwayClone:595: error: 'alarmHandler' was not declared in this scope
```
tks


----------



## Ovaltineo (Jul 18, 2013)

homer32 said:


> ovaltine hello,
> I installed the CloneConsole in a tablet of the brand BQ, edison3 model, android version 4.4.2
> 
> - Connect the minisegway and properly connected to the tablet, I see how the engines work on the tablet, I change the value of P and D, I give to save (not if stored properly?)


It doesn't save P & D? 



> - The second screen feature do? It is to match the address?


This is a GPS speedometer measuring the speed of the phone/tablet. It won't work if your tablet doesn't have GPS.



> - On the third screen the X and Y with the finger will move the vector coming out, but the minisegway does nothing.
> This screen is not serious to control the robot mode joystick?


Hmm, this works with an Arduino MEGA. Maybe the Soft Serial on the UNO doesn't work well. I suggest switching to a MEGA.



> - In the fourth screen are two options: calibrate and block.
> If you press calibrate the tablet is stuck and unresponsive.


Calibrate is the equivalent of doing the #MODE_CALIBRATE. It takes about a minute to do this. The robot must be in equilibrium position and not moving when you use this. 



> If you click lock, it appears to block the console.


Unlock doesn't work?



> Other questions?
> 1- The sensor MPU6050 it's on the second floor of the robot, it would be better to lower it to the first floor that would be closer to the axis of reducing engine?


I don't really know if it is better or not. You should try both.



> 2- be possible to install an LCD for speed, rpm, settings, etc ..


Of course, but you have to write the code yourself.


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> Boss, problems do not go Arduino ...
> 
> follows the list and if you can help me ... I will thank a lot!
> 
> ...


Did you unzip all the code to SegwayClone directory?


----------



## Ovaltineo (Jul 18, 2013)

blinkers said:


> It is possible, if so tell me how?


What is possible?


----------



## blinkers (Oct 5, 2015)

1-UNO R3 CH340
2-MPU6050
1-L298N
H-06 not connected {not configuret}

Have error I2C error = -32

that for an error

Sorry for the my English, I'm from Ukraine


----------



## RickSoares (Mar 4, 2014)

Good day! Master, give me a strength ... I'm not understanding how to connect all ...
Let's do it by steps:

1 - I bought two MPU6050, the HC-06, and the L298N, to start, I have two small engines for oos tests.
2 - I do not understand what to do, only gives compilation error for the Arduino, he does not accept a lot of things, as I had put in the previous post ... I unzipped the files ... I would have to install the libraries?
3 - what is the best version for Arduino in this case?
4 - I do a little, to learn and then move on to bigger ... please help me ... now I'm really very excited ... I know well C programming, and I love electronics ... I picked up this bixo seven heads to play and do my course conclusion work ... please help me ...


----------



## RickSoares (Mar 4, 2014)

ovaltine hello, how are you?
After much pushing, she got compile Segwayclone pro Arduino Mega and pro uno ... but I have 2 questions ....
BLUETOOTH with HC05 is possible? changes something?
and how to fix the error, I2C Error -32? I will not use temperature sensors for now ...
what to do?
Thank you for the help you have given us! a big hug!!!!!

Thks so much!!!!!


----------



## Ovaltineo (Jul 18, 2013)

blinkers said:


> 1-UNO R3 CH340
> 2-MPU6050
> 1-L298N
> H-06 not connected {not configuret}
> ...


Did you connect ADO to +5v in the MPU6050 for steering?


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> ovaltine hello, how are you?
> After much pushing, she got compile Segwayclone pro Arduino Mega and pro uno ... but I have 2 questions ....
> BLUETOOTH with HC05 is possible? changes something?
> and how to fix the error, I2C Error -32? I will not use temperature sensors for now ...
> ...


I don't know if HC05 will work, probably not. I think AT commands don't work unless the KEY pin is enabled. 

Did you connect ADO to +5v in the MPU6050 for steering?


----------



## RickSoares (Mar 4, 2014)

Ovaltineo said:


> I don't know if HC05 will work, probably not. I think AT commands don't work unless the KEY pin is enabled.
> 
> Did you connect ADO to +5v in the MPU6050 for steering?




followed the electronic Scheme making forum , but I did not notice if there teria que Connecting 5V IN AD0 do MPU , shot to do 5v MPU and Connec OR call in parallel?

when I get home I'll send pictures from the mini Segway , I could write the Arduino , now are adjustments to test ... I think today I place to run ... a shame that the bluetooth HC05 does not work, I paid dearly ...




I do not want to use as the TC74 , not meeting paragraph buy aki ...
As I take IT Programming paragraph not give the I2C error too ... 'cause he also the error


tks Ovaltineo


----------



## blinkers (Oct 5, 2015)

Bluetooth change to hc06 work ok.
AD0 connected to +5v
TC74 not use.

Have error 32


----------



## Ovaltineo (Jul 18, 2013)

blinkers said:


> Bluetooth change to hc06 work ok.
> AD0 connected to +5v
> TC74 not use.
> 
> Have error 32


Please post the first page of the Serial monitor output. Also, post some pics of your clone.


----------



## RickSoares (Mar 4, 2014)

Hello Ovaltine, okay?
My friend, sorry be bothering you with the project ... but is that really I am unsure what to do ... this project is very difficult I know that, I thought with my knowledge of electronics and some of the Arduino I could do, but I saw that it's complicated, but now I've found it's complicated I want to do!
I did not understand what to do with the analog input of the Arduino ... AD0, it is to connect the + 5V of the MPU in it? that?
errors that give the i2c is communication error, will be that it may be some sensor? and the positions of the sensors, which put exactly? sorry, but really I took these days to fill u with the project, but the tendency, as I am today is finish it today, of course if you can help me ...
As for Bluetooth, I bought the HC05, was checking out a way to turn it into slave, does the right? thank you
Thank you so much


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> Hello Ovaltine, okay?
> My friend, sorry be bothering you with the project ... but is that really I am unsure what to do ... this project is very difficult I know that, I thought with my knowledge of electronics and some of the Arduino I could do, but I saw that it's complicated, but now I've found it's complicated I want to do!
> I did not understand what to do with the analog input of the Arduino ... AD0, it is to connect the + 5V of the MPU in it? that?
> errors that give the i2c is communication error, will be that it may be some sensor? and the positions of the sensors, which put exactly? sorry, but really I took these days to fill u with the project, but the tendency, as I am today is finish it today, of course if you can help me ...
> ...


AD0 is a pin in the MPU module. In one module (on the board), leave it unconnected. In the other module (for the steering), connect it to +5v. If you know electronics, this should be obvious in the schematic.

With the HC05, you need to change initBluetooth in Bluetooth.ino to set it to slave and set the serial port baud rate to match the HC05. You have to figure this out yourself because I don't have a HC05.


----------



## RickSoares (Mar 4, 2014)

Ovaltine, forgive my ignorance, I think I'm very anxious to run it and saw ... Prototype up and running, I can post a youtube video here?
I will post a video on youtube and now also want to show you guys the project!
Hugs!


----------



## homer32 (Aug 10, 2015)

hello,
for now I do not have smartphone with android, I will buy one soon and will continue with the tests.
I use the tablet does not have GPS.
I will also try Arduino MEGA.
I will tell my progress.


----------



## Paolo68 (Oct 12, 2015)

Hallo,
someone can give me the complete software with Arduino Uno and Sabertooth and two MPU6050?
I am not very practical and I would like to avoid burning something


----------



## Ovaltineo (Jul 18, 2013)

Software location and schematics are on the first page of this thread.


----------



## blinkers (Oct 5, 2015)

Ovaltineo said:


> Please post the first page of the Serial monitor output. Also, post some pics of your clone.


WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0
WHO_AM_I : 0, error = -32
PWR_MGMT_2 : 0, error = -32
Try 115200
Try 19200
Found bluetooth module at 19200
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32
I2C Error = -32

ACCEL: -20.38 GYRO: 0.00 BOARD ANGLE: -4.21 STEER ANGLE: -14.95 MOTOR: -25.82 LEFT: 26 RIGHT: -78 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0
I2C Error = -32
I2C Error = -32
I2C Error = -32


----------



## Ovaltineo (Jul 18, 2013)

blinkers said:


> WHO_AM_I : 68, error = 0
> PWR_MGMT_2 : 0, error = 0


Error = 0 here means that it found the board gyro.



> WHO_AM_I : 0, error = -32
> PWR_MGMT_2 : 0, error = -32


Error = 32 here means it cannot find the steering gyro. Did you connect AD0 to +5V in the steering gyro? If yes, try swapping it with the board gyro to check if this gyro is dead. I think one of the connections is just not soldered properly. Can you post some close-up pictures?


----------



## ghirotre (Nov 14, 2014)

Hi Ovaltine, thanks for your work, withuot your software it is impossible for me make my segwayclone.
I have a question:
Is it possible to make a different P and D when the battery is under set point?
I mean, when the battery is full charge is very responsive, but when battery go under 23v it isn't responsive, so i have thinked to change a p and d when battery go under 23v.

Thanks


----------



## ibanez130 (Jun 28, 2015)

adamson said:


> I'm going to mount bts7960 like this. Will it be ok?


hi, have you diagram about this project? arduino and between to 2xbts7960b


----------



## wsm (Jan 6, 2015)

Hi

there is no thermal contact to the heat sink. 
So you have to modify the module.

Use some thermal compound and have a look to http://ups.bplaced.de/BTS-Modifikation.htm

W.


----------



## ghirotre (Nov 14, 2014)

Hi ibanez130,
I have tried to use the bts7960 (the same on the photo), but after 2 minutes it is broken.
I change the bts7960 chip but i have the same problem.
But i have not try with a fan.
To resolve i have bought a roboclaw 2x30 for my first segwayclone, in the second one i have used a sabertooth 2x32 because here in Italy is more cheap.
The diagram for your board is in the first post.

Dear Ovaltineo, sorry for my contiunuos posting...
But i have a problem with my segwayclone.
Sometimes the clone go at full speed when is still or near to stop.
I see the android app and i see that the board angle sometimes is wrong.
Is possible that the problem is some noise from the motor on the ic2 bus or the gy521 is not good?

Thanks


----------



## ayduvan (Jul 7, 2014)

Thanks Ovaltineo. Good job.
I am so sory about my english.
I think,
Our segway has two diffrent motor driver. when I ride a segway, If one motor driver was out of service. I think, It rotates on its axis. am i right? or not.
what can ı do. Many thanks 

good job.https://youtu.be/2RTmhA5dfC0

Alp from TURKEY


----------



## RickSoares (Mar 4, 2014)

Hello Ovaltine could help me? android application is freely accessible to change? u could give me? I have some ideas to implement, and would like to test with the system that you put.
thank you!

overnight Sunday I'll be taking some pictures of my project and recording a video of the mini prototype I made ...
a question, which the possibility of using a bridge itself h to 100A? I have one already, but do not know how to connect the Arduino and not move on schedule ...
I can only replace the bst?
Hugs


----------



## Ovaltineo (Jul 18, 2013)

ghirotre said:


> Hi Ovaltine, thanks for your work, withuot your software it is impossible for me make my segwayclone.
> I have a question:
> Is it possible to make a different P and D when the battery is under set point?
> I mean, when the battery is full charge is very responsive, but when battery go under 23v it isn't responsive, so i have thinked to change a p and d when battery go under 23v.
> ...


This is possible with some changes to the code. I won't change P and D, but will just make the final left and right motor output inversely proportional to the voltage. It will take me a couple of weekends to play with this.


----------



## Ovaltineo (Jul 18, 2013)

ghirotre said:


> Dear Ovaltineo, sorry for my contiunuos posting...
> But i have a problem with my segwayclone.
> Sometimes the clone go at full speed when is still or near to stop.
> I see the android app and i see that the board angle sometimes is wrong.
> ...


Do you see the incorrect board angle if the motors are disconnected? If yes, then it clearly won't be caused by noise from the motors. If no, then you will probably need an optocoupler between the Arduino and the controller. Search this thread for "optocoupler" to see the diagram.


----------



## Ovaltineo (Jul 18, 2013)

ayduvan said:


> Thanks Ovaltineo. Good job.
> I am so sory about my english.
> I think,
> Our segway has two diffrent motor driver. when I ride a segway, If one motor driver was out of service. I think, It rotates on its axis. am i right? or not.
> ...


Yes, if one side is dead or shorted, then it will spin around. Simply test it with the wheels off the ground to see which side is faulty.


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> Hello Ovaltine could help me? android application is freely accessible to change? u could give me? I have some ideas to implement, and would like to test with the system that you put.
> thank you!
> 
> overnight Sunday I'll be taking some pictures of my project and recording a video of the mini prototype I made ...
> ...


Sorry, the android application is not open source for commercial reasons.
Of course you can use your own controller. If you post the diagram, I maybe able to help you how to use it.


----------



## homer32 (Aug 10, 2015)

ayduvan said:


> Thanks Ovaltineo. Good job.
> I am so sory about my english.
> I think,
> Our segway has two diffrent motor driver. when I ride a segway, If one motor driver was out of service. I think, It rotates on its axis. am i right? or not.
> ...



good job ayduan.
I've seen your video and I think they make a noise engines.
anyone can tell if this noise (buzz) is due to the PWM frequency?
ovaltine have a question for you:
if the PWM frequency select the option controller PWM + DIR engine is approximately 3 kHz?
this can be increased up to 20kHz PWM?
where you can change the Arduino code?
Thank you


----------



## Ovaltineo (Jul 18, 2013)

homer32 said:


> good job ayduan.
> I've seen your video and I think they make a noise engines.
> anyone can tell if this noise (buzz) is due to the PWM frequency?
> ovaltine have a question for you:
> ...



Yes, buzz is from PWM frequency. The two highest frequencies supported by standard Arduino code are 31KHz and 3.9KHz. Nothing in between, unfortunately. If your controller can support 31KHz, then you can simply change initMotors() in Motors.ino from

```
setPwmFrequency(HZ_3906);				// set PWM frequency to 3.906 kHz
```
to 

```
setPwmFrequency(HZ_31250);				// set PWM frequency to 3.906 kHz
```

If you have a MEGA, you can try (not tested) adding the following code at the end of initMotors() to set the frequency to 15KHz.

```
// init 16bit timer 3
		TCCR3B &= ~(1<<WGM33);
		TCCR3B |= (1<<WGM32);
		TCCR3A |= (1<<WGM31); // fast PWM, TOP=0x3FF
		TCCR3A |= (1<<WGM30);


		// init 16bit timer 4
		TCCR4B &= ~(1<<WGM43);
		TCCR4B |= (1<<WGM42);
		TCCR4A |= (1<<WGM41); // fast PWM, TOP=0x3FF
		TCCR4A |= (1<<WGM40);



		TCCR3A |= _BV(COM3B1); // connect pin 2 to timer 3 channel B
		TCCR3A |= _BV(COM3C1); // connect pin 3 to timer 3 channel C
		TCCR3A |= _BV(COM3A1); // connect pin 5 to timer 3 channel A
		TCCR4A |= _BV(COM4A1); // connect pin 6 to timer 4 channel A
```


----------



## homer32 (Aug 10, 2015)

I'll try with the frequency of 31Khz, the driver Mosfet'm building a H-bridge N-channel MOSFET when working properly, I'll upload the file in the forum.
I'm still gathering information on how to do and that works well.


----------



## Speaner (Oct 21, 2015)

Good night friends.
I'm using the code where you remove the comment to perform the actions but I'm getting two errors in the IDE regarding the lack of a "setup" and a "loop". What can it be? Can you help me?
Another thing, I have used only one MPU6050 GY-521, but reading the entire contents of this forum saw that it is more feasible to use two MPU6050 GY-521. The question is, I place a more or less at the level of the wheel axle to the center of the base and another at the bottom of the handlebars where it articulates? Or only one can make it work? The program to use only one GY-521 with BTN7960 control board must enable #define MPU6050_X1_STEERING and #define PWM_PWM_CONTROLLER? From what little I understand of programming there is no drive to the motor? Can help me put this drive?


```
/*
Uncomment one MODE below
*/
//#define MODE_CALIBRATE
#define MODE_RUN

/*
Uncomment one STEERING type below
*/
//#define POT_STEERING
//#define MPU6050_X2_STEERING
#define MPU6050_X1_STEERING
//#define GY80_STEERING

//#define EXPONENTIAL_STEER_DIVIDER	7	// turns steering from linear to exponential - this specifies the angle where response is higher than linear

/*
Uncomment only if steer MPU6050 is vertically oriented
*/
//#define STEER_Z_GYRO

/*
Uncomment only if using MPU6050_X2 and you want to compensate for terrain banking
*/
#define SUBTRACT_BANK_ANGLE			1.0		// defining this will subtract board bank angle from steer angle.  Value (0 to 1) defines how much bank is used.

/*
Uncomment only if steering left and right are inverted
*/
//#define INVERT_STEERING

/*
Uncomment one CONTROLLER type below
*/
#define PWM_PWM_CONTROLLER
//#define PWM_DIR_CONTROLLER
//#define ROBOCLAW_CONTROLLER
//#define ROBOCLAW_ENCODER_CONTROLLER
//#define SABERTOOTH_CONTROLLER
//#define PWM_SHIELD_CONTROLLER
//#define L298N_CONTROLLER
//#define OSMC_CONTROLLER

/*
Uncomment if you want to check battery voltage.  See note above for resistor divider.
*/
//#define VOLTAGE_CHECK

/*
Uncomment if you want LED Voltage indicator.  You need VOLTAGE_CHECK with this.
*/
//#define VOLTAGE_LED

/*
Uncomment if you want Pushback
*/
//#define PUSHBACK

/*
Uncomment if you have a HC06 "linvor" bluetooth module
*/
//#define BLUETOOTH

/*
Uncomment if you have TC74 temperature sensors - TC74A0 and TC74A2 default addresses in TC74.h
*/
//#define TEMPERATURE_SENSORS

/*
Uncomment if you want the clone to be locked during startup.  It can only be unlocked via CloneConsole Android app.
*/
//#define LOCKED_BY_DEFAULT

/*
Uncomment if you have a rider sensor - sensor must pull this pin to GND/LOW when rider is ON, and leave it open or HIGH when rider is OFF.
Initial values are loaded from KP_OFF, KD_OFF, and MOTOR_MAX_OFF.
*/
//#define RIDER_SENSOR	8

/*
Uncomment if RIDER_SENSOR above has reverse logic, ie HIGH when rider is ON and LOW when rider is OFF
*/
//#define INVERT_RIDER_SENSOR

/*
Uncomment if you have a HX711 weight sensor instead of digital RIDER_SENSOR. HX711_DOUT and HX711_SCK define which pins are 
connected to HX711.  If weight is greater than HX711_MIN, then rider is ON, else rider is OFF.
Initial values are loaded from KP_OFF, KD_OFF, and MOTOR_MAX_OFF.
*/
//#define HX711_DOUT	A6
//#define HX711_SCK		A7
//#define HX711_MIN		50
//#define HX711_REFERENCE_WEIGHT 940	// optional weight of rider where static P & D are based on.  If defined, P & D are computed proportional to rider's weight


//#define FAN_PIN			13				// optional output for MOSFET or relay fan switch

#define BUZZER_PIN			12
#define POT_STEERING_PIN	A1				
#define P_PIN				A0				// optional pot for adjusting P value (Proportional)
#define D_PIN				A2				// optional pot for adjusting D value (Derivative)
//#define POT_TILT_PIN	A4				// optional pot for adjusting forward/backward tilt

#ifdef VOLTAGE_CHECK
	#define VOLTAGE_PIN			A3
//	#define VOLTAGE_PIN			A5			// ovaltine's clone uses this
	#define VOLTAGE_DIVIDER		.176		// voltage divider: 4.7K/(22K + 4.7K) = .176
#endif

// The following 9 lines were borrowed/copied from Multiwii
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
  #define PROMINI
#endif
#if defined(__AVR_ATmega32U4__) || defined(TEENSY20)
  #define PROMICRO
#endif
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
  #define MEGA
#endif

#ifdef VOLTAGE_LED
	#if defined(PWM_SHIELD_CONTROLLER)
		#define LED_GREEN_PIN		A0
		#define LED_YELLOW_PIN		5
		#define LED_RED_PIN			6
	#elif ((defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER)) && !defined(MEGA))
		#define LED_GREEN_PIN		4
		#define LED_YELLOW_PIN		5
		#define LED_RED_PIN			6
	#else
		#define LED_GREEN_PIN		9
		#define LED_YELLOW_PIN		10
		#define LED_RED_PIN			11
	#endif
#endif

typedef struct
{
	float x_accel;
	float y_accel;
	float z_accel;
	float x_gyro;
	float y_gyro;
	float z_gyro;

	int x_accel_offset;
	int y_accel_offset;
	int z_accel_offset;

	int x_gyro_offset;
	int y_gyro_offset;
	int z_gyro_offset;

	int x_gyro_offset_min;
	int x_gyro_offset_max;
	int y_gyro_offset_min;
	int y_gyro_offset_max;
	int z_gyro_offset_min;
	int z_gyro_offset_max;

	int address;
} sensorType;


#define	ALPHA 0.97					// used by complementary filter
#define	ALPHA_SLOW 0.997			// used by slow complementary filter


#if defined(ROBOCLAW_CONTROLLER)
	// use these values if using Roboclaw
	#define KP 3.9					// proportional constant when rider is ON
	#define KD 1.5   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 25     // adjust depending on your motor speed
	#define KP_OFF 1.8				// proportional constant when rider is OFF
	#define KD_OFF .75 				// derivative constant when rider is OFF
#endif
#if defined(ROBOCLAW_ENCODER_CONTROLLER)
	// use these values if using Roboclaw with encoder
	#define KP 10.9					// proportional constant when rider is ON
	#define KD 4.68   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 546     // adjust depending on your motor speed
	#define KP_OFF 5.45				// proportional constant when rider is OFF
	#define KD_OFF 2.34 				// derivative constant when rider is OFF
#endif
#if defined(SABERTOOTH_CONTROLLER)
	// use these values if using Sabertooth
	#define KP .35					// proportional constant when rider is ON
	#define KD .15   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 1.75   // adjust depending on your motor speed
	#define KP_OFF .17				// proportional constant when rider is OFF
	#define KD_OFF .07 				// derivative constant when rider is OFF
#endif
#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER)  || defined(PWM_SHIELD_CONTROLLER) || defined(L298N_CONTROLLER) || defined(OSMC_CONTROLLER)
	// use these values if using PWM
	#define KP .7					// proportional constant when rider is ON
	#define KD .3   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 3.5    // adjust depending on your motor speed
	#define KP_OFF .35				// proportional constant when rider is OFF
	#define KD_OFF .15 				// derivative constant when rider is OFF
#endif

#define MAX_ANGLE  18			// adjust depending on your machine
#define MIN_ANGLE  -15			// adjust depending on your machine
//#define MAX_YAW_RATE_RIDER_OFF	45	// max degrees per second (with rider off) change in direction before safety shutdown
//#define MAX_YAW_RATE_RIDER_ON	90	// max degrees per second (with rider on) change in direction before safety shutdown

#define CALIBRATE_YES	true
#define CALIBRATE_NO	false

#define ACC_FILTER	0.05
#define VOLT_FILTER	0.8

//#define lowpassFilter(val, change, q) ((1-q) * val + (change * q)) 
#define lowpassFilter(val, change, q) (val + q * (change - val))

#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER) || defined(PWM_SHIELD_CONTROLLER) || defined (L298N_CONTROLLER) || defined(L298N_CONTROLLER)
	// bluetooth software serial pins for non-mega boards with PWM controllers
	#define SOFT_RX_PIN3	5			// connect to bluetooth module TX pin
	#define SOFT_TX_PIN3	6			// connect to bluetooth module RX pin
#else	
	// bluetooth software serial pins for non-mega boards with serial controllers
	#define SOFT_RX_PIN3	7			// connect to bluetooth module TX pin
	#define SOFT_TX_PIN3	8			// connect to bluetooth module RX pin
#endif	

#define STEER_OFFSET_DIVIDER	-70.0		// bluetooth remote control steer offset (X) divider.  Higher value makes X movement less sensitive. Negative value reverses the direction.

#ifdef POT_TILT_PIN
	#define BOARD_OFFSET_DIVIDER	1.0		// pot tilt board offset divider.  Higher value makes pot tilt movement less sensitive.  Negative value reverses the direction.
#else
	#define BOARD_OFFSET_DIVIDER	-70.0		// bluetooth remote control board offset (Y) divider.  Higher value makes Y movement less sensitive.  Negative value reverses the direction.
#endif

#define POT_STEERING_ADJUST		0	// modify this to get the POT_STEERING angle centered to zero


//#define SERIAL_WTV020			// WTV020 Voice module on Serial port 2
```


----------



## ghirotre (Nov 14, 2014)

Hi Speaner,
The first error that i see it is you uncomment SUBTRACT_BANK_ANGLE, but you need 2 mpu6050 and you select only 1(#define MPU6050_X1_STEERING)
I don' t see other error in the config but it is best wait ovaltineo...
You can test the skecth without SUBTRACT_BANK_ANGLE

In my clone i use always 2 gy521, but i don't use SUBTRACT_BANK_ANGLE.
1 is on the board and the second is on the steering shaft.
The gy521 is mesuring the angle so you can put everywhere on the borad because the angle is always the same. Very important it is the gy521 have right direction.
I THINK that it is the best to have short cables.

Oveltineo I have change the gy521 and it is perfect...
I use the 5v from sabertooth to powerup the arduino, i think it is not good and it is not stable and i have burn the gy521. Now i buy a dc-dc step down isolated.

Thanks


----------



## Ovaltineo (Jul 18, 2013)

Speaner said:


> Good night friends.
> I'm using the code where you remove the comment to perform the actions but I'm getting two errors in the IDE regarding the lack of a "setup" and a "loop". What can it be? Can you help me?


I think you are trying to compile SegwayClone.h only. You must download the zip file, unzip to SegwayClone directory and load SegwayClone.ino.



> Another thing, I have used only one MPU6050 GY-521, but reading the entire contents of this forum saw that it is more feasible to use two MPU6050 GY-521. The question is, I place a more or less at the level of the wheel axle to the center of the base and another at the bottom of the handlebars where it articulates?


Yes, this is the best setup.



> Or only one can make it work? The program to use only one GY-521 with BTN7960 control board must enable #define MPU6050_X1_STEERING and #define PWM_PWM_CONTROLLER?


Yes, it will also work with one. But you must place it at the intersection of the steering axle and wheel axle. Using two is better.



> From what little I understand of programming there is no drive to the motor? Can help me put this drive?


I have no idea what you are talking about .


----------



## mutai (Dec 22, 2014)

Hello Ovaltineo,

I currently building my 2nd segway- In the 1st segway i use 2 wheelchair motors running on 24V via BTN7960 , the problem with the motors was the backlash-it was very jerky.
In my new segway I got 2 wheels with internal 36V motors so I have to get a 36V driver.
my question is: 
can I use this controller?
How many do I need? I think it have 2 motor outputs.
http://www.aliexpress.com/item/30A-dual-H-bridge-motor-driver-module-power-powerful-brake-function-DC-motor-drive-board/32242260682.html?spm=2114.01020208.3.1.OPRk6j&ws_ab_test=searchweb201556_1_71_72_73_74_75,searchweb201644_5,searchweb201560_9
if yes? how to connect it?

Thanks,

Eran


----------



## Ovaltineo (Jul 18, 2013)

mutai said:


> Hello Ovaltineo,
> 
> I currently building my 2nd segway- In the 1st segway i use 2 wheelchair motors running on 24V via BTN7960 , the problem with the motors was the backlash-it was very jerky.
> In my new segway I got 2 wheels with internal 36V motors so I have to get a 36V driver.
> ...


You can use this - you only need 1 to control both motors. Use PWM_DIR_CONTROLLER with the pins defined in Motors.h.

If you can stretch your budget, I would recomment this instead - http://www.goodluckbuy.com/100a-mos-opto-isolated-dual-channel-h-bridge-dc-motor-driver-module.html. Use L298N_CONTROLLER for this one.


----------



## mutai (Dec 22, 2014)

Hi Ovaltine,
Thank you very much for the fast response- I highly appriciate your contrebution to this project.
I will defenetly use your recommendation and buy the item you suggested.
Once again- Thank you very much.
I will send pictures soon.

Regards,

Eran Mutai


----------



## diyelectric (Jun 29, 2015)

Dear Ovaltineo (& Friends), my name is Jay and this is my first post in the forum but I have been following along for several months now while I was getting all the parts. So now I have collected the following:

- Arduino Mega R3

- 2 x Cytron Technologies MD10C ( http://www.cytron.com.my/p-md10c ) motor controllers... one for each motor.

- 2 x 100W Brushed DC Motors from Unite in China (Model MY6812)... I know these are not powerful but I am purposely trying to keep this DIY Segway easily portable and I do not need the top speed to be higher than a light jog (about 6 mph I think). These motors normally used in the Razor E100 scooters.

- Custom made battery pack using about 20 x Samsung 18650's with charge protection controller and I have used a multimeter to test it at roughly 27v on fresh charge. But from the output connector, it goes into a adjustable voltage regulator to bring it to a constant 24v to supply each motor.

- 2 x MPU-6050 IMU

- I also have the LCD, Bluetooth, an Android Phone, and a whole bunch of other Arduino parts that can be used if necessary like the Uno R3, Nano, Pro, Bluetooth PS2 controller, ultrasonic sensors, IR sensors, Heartbeat sensors, Cams, RFID Reader/Writer/Tags, Lasers, Ardumoto Controller, 10K Potentiometers, Lots of various kinds of resistors, buttons, switches, wheelbarrow wheels (foam and rubber), Baby stroller wheels, bicycle sprockets/chains, Thermoelectric coolers, L298N controller (but I think amps too low), and I live next to what you could call electronics and manufacturing "dreamland" (Western Digital, Seagate, TI, cheap welding service shops, CNC services. So safe to say that whatever may be needed, I can probably get it... EXCEPT... Sabertooth or Roboclaw...not only is it too expensive here... I just cannot find it anywhere and I have looked under many rocks.

So thank you all in advance for the help I am sure to receive over time from this forum. But my first question is:

Can I use the Cytron MD10C? (they also have MDD10A which is dual motor control version of the MD10C, but I would prefer not to spend more money if not necessary). Please help me with the right integration... I am so anxious to build and ride my "Ovaltineo DIY Segway"... like YESTERDAY. You're the best! Thank you!


----------



## Ovaltineo (Jul 18, 2013)

diyelectric said:


> - Custom made battery pack using about 20 x Samsung 18650's with charge protection controller and I have used a multimeter to test it at roughly 27v on fresh charge. But from the output connector, it goes into a adjustable voltage regulator to bring it to a constant 24v to supply each motor.


Do you know the power rating of this voltage regulator? Your motors could easily draw 200W peak power when stalled.



> Can I use the Cytron MD10C? (they also have MDD10A which is dual motor control version of the MD10C, but I would prefer not to spend more money if not necessary). Please help me with the right integration... I am so anxious to build and ride my "Ovaltineo DIY Segway"... like YESTERDAY. You're the best! Thank you!


Yes you can use it. Use PWM_DIR_CONTROLLER. If you haven't bought them already, you may want to consider this instead http://www.goodluckbuy.com/60a-high-power-mos-dual-channel-h-bridge-dc-motor-driver-module.html. You only need 1 of these and you can connect your batteries directly without a regulator.


----------



## mutai (Dec 22, 2014)

Dear Ovaltine,

In the original Segway you can set a speed limit to any speed you like (say for new rider 10km/h).
you can actually feel the Segway put the steering bar in your belly once it reaches the speed limit.
My question is: Is it possible to set a speed limit in our Segway clone as well.
If yes? how?

Thanks,

Eran


----------



## Ovaltineo (Jul 18, 2013)

Not quite - for a start, there is no speed sensor on my design. However, you can try enabling PUSHBACK. You can adjust the pushback settings in Pushback.h. It will pushback when the motor output is greater than "kick_trigger". Someone else wrote this bit of code, and I haven't tested it that much but it seems to work.


----------



## RickSoares (Mar 4, 2014)

good morning people!
after some changes, I am sending the new structure pictures, which we are doing ... I believe that in another week already enter with the electronic ...
the program perfectly runs on a prototype, I believe that will not change much in the big one there ...

I hope you all right, miss one month to deliver ... kkk

a big hug and I hope you enjoy the photos ... is getting mto cool ... I'll still paint some parts, but basically that's it ...


----------



## RickSoares (Mar 4, 2014)

structure ready to endure 300kg up ... of course the engine still can not take it ... but in the future I will change ... not yet had money for everything ... I'm bankrolling all alone ...

a big hug...


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> good morning people!
> after some changes, I am sending the new structure pictures, which we are doing ... I believe that in another week already enter with the electronic ...
> the program perfectly runs on a prototype, I believe that will not change much in the big one there ...
> 
> ...


Those hubs and wheels are really nice. Couldn't you put the steering bearing under the deck? Otherwise you'll need a cover to protect the gyro sensor and the wiring - just like the real Segway.


----------



## RickSoares (Mar 4, 2014)

These are the springs that hold the handlebars ... how to put down, the idea was just put on the deck, but make the protection ... already bought the material lack folding yet ...
My problem will be the electronics ... I still do not understand, the electronic scheme that u ... rode the prototype works with flaws ... he does not stabilize in the center ... is ... an engine turning off the other no....
but also not put the pots P and D ... among other things ... but I'm tucking me daki forward ... I believe that by the end of November, estaja 100% clear that with you guys help it would not be possible ...
calibration and run mode works perfectly on mobile? if I want to not put the P and D control potenciomentro and can leave at Mobile?


----------



## Speaner (Oct 21, 2015)

Good afternoon, I tested the code on my Segway Clone and apparently worked well, but I am not able to get him to stop at the equilibrium point. Tilting everywhere it performs well but is not a point where it would tend to balance and just stop?
I can post pictures of my assembly, since I am in doubt whether there is problem with leaving a sensor in the height of the axis of the central wheel on the base and another at the coupling of the steering handlebar, but higher, that is, without being at the level the other sensor. This influences? It is indicated that the two sensors are in the same height?
Before calibration leveled the sensors, but still does not have a point that it reaches "zero" (stop). There's something in the program should I change? I'm using Funduino Mega two GY-521, two BTN7960 ... Oh, he reacts well using the program set for 1 sensor (even though two connected sensors), changing the program to two sensors work improperly and see error -32 the serial monitor. 
Can you help me?


----------



## Ovaltineo (Jul 18, 2013)

Speaner said:


> Good afternoon, I tested the code on my Segway Clone and apparently worked well, but I am not able to get him to stop at the equilibrium point. Tilting everywhere it performs well but is not a point where it would tend to balance and just stop?
> I can post pictures of my assembly, since I am in doubt whether there is problem with leaving a sensor in the height of the axis of the central wheel on the base and another at the coupling of the steering handlebar, but higher, that is, without being at the level the other sensor. This influences? It is indicated that the two sensors are in the same height?
> Before calibration leveled the sensors, but still does not have a point that it reaches "zero" (stop). There's something in the program should I change? I'm using Funduino Mega two GY-521, two BTN7960 ... Oh, he reacts well using the program set for 1 sensor (even though two connected sensors), changing the program to two sensors work improperly and see error -32 the serial monitor.
> Can you help me?


You need to get rid of the error -32 when you enable the two sensors. Is AD0 connected to +5v on the steering sensor? Post a picture of the wiring for the two sensors.


----------



## Speaner (Oct 21, 2015)

Ovaltineo said:


> You need to get rid of the error -32 when you enable the two sensors. Is AD0 connected to +5v on the steering sensor? Post a picture of the wiring for the two sensors.


Ovaltine I had forgotten the AD0, but even calling is not working well, it is not responding to movements. Now I change to a single sensor works great. What can it be?
Have any relation to the array of sensors? They are aligned but at different times ...
As can be seen in the images, a sensor is in the center of the base at the height of the wheel axle and the other as well at the bottom of the handlebars (which engages the base).


----------



## Ovaltineo (Jul 18, 2013)

Speaner said:


> Ovaltine I had forgotten the AD0, but even calling is not working well, it is not responding to movements. Now I change to a single sensor works great. What can it be?
> Have any relation to the array of sensors? They are aligned but at different times ...
> As can be seen in the images, a sensor is in the center of the base at the height of the wheel axle and the other as well at the bottom of the handlebars (which engages the base).


With two sensors enabled, are you still getting error -32? Post close-up pictures of the wiring and orientation of the two sensors.

Also, even if you get it working, you need to calibrate at the point where the machine balances by itself (without power). Otherwise, the balancing code will not be able to hold it steady without moving. Looking at your machine, you need to put your batteries at the back to offset the weight of the steering at the front.


----------



## BlackCrowBlues (Jun 10, 2015)

Ovaltineo said:


> If you have a MEGA, you can try (not tested) adding the following code at the end of initMotors() to set the frequency to 15KHz.
> 
> ```
> // init 16bit timer 3
> ...


Verified it.
It works with a Mega and the BTS7960 Controller.
Sounds much nicer
But didn't solved my problem...
When i lean forward the Controller goes to maximum but the Motor isn't fast enough to compensate it...
Without a driver it seems to work. Seems to be a "hardware" problem.
If i lift the Unicycle and let the wheel run to max, it doesn't looks like over 2000rpm at the motor shaft, not even close. Dammit...
Could it be this stupid but original thin wire to the motor?

Sorry for the monolog


----------



## Ovaltineo (Jul 18, 2013)

BlackCrowBlues said:


> Verified it.
> It works with a Mega and the BTS7960 Controller.
> Sounds much nicer
> But didn't solved my problem...
> ...


What is the value for MOTOR_MAX? Did you try increasing P and D?


----------



## BlackCrowBlues (Jun 10, 2015)

I didn't changed MOTOR_MAX so it is 252 for PWM_PWM_CONTROLLER.
I can see it reach his controller limit via Bluetooth. But the motor isn't fast enough or it doesn't have enough torque.
Gear reduction is 11Z to 68Z (6.18 : 1)
The wheel should make 323 rpm at max speed.
With the 12,5" wheel it should reach 4,76 m/s or 17km/h.


----------



## Ovaltineo (Jul 18, 2013)

I've just released a minor update of CloneConsole to fix scaling of the Calibrate & Lock view. It will now render properly on high-res screens.


----------



## RickSoares (Mar 4, 2014)

ovaltineo, Good Morning!

What does the analog input AD3? I do not know coz place the resistors in series there ... thanks


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> ovaltineo, Good Morning!
> 
> What does the analog input AD3? I do not know coz place the resistors in series there ... thanks


That's a resistor voltage divider to check the main battery voltage. We cannot measure 24V directly (analog input is 5V max), so we divide it by 5.68. You should un-comment VOLTAGE_CHECK if you are using it.


----------



## RickSoares (Mar 4, 2014)

I wonder Ovaltine, the Because the system is not stable, it just turns sideways ... but is not stopped ... or at least swinging forward back and stopped ... It is necessary to use Some potentiometer adjustment or mobile application already enough? What a way to allocate the two sensors, both the Direction As for the stability .... please ... help me ... thank you from ja ... Very difficulties appeared What que agora put any own robo now set up the great and I am allocating the pieces ... but do not know the position of placing sensors exactly ... Little tava Working now the great ... no ... I'm using the btn, Arduino Mega, Two engines dc 350w, hc06 but without STILL Communication

Thank you.. so much!


----------



## BlackCrowBlues (Jun 10, 2015)

Jupp... as i feared it. The motor runs only with 100rpm instead od ~300rpm.
I made a short video: Test run


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> I wonder Ovaltine, the Because the system is not stable, it just turns sideways ... but is not stopped ... or at least swinging forward back and stopped ... It is necessary to use Some potentiometer adjustment or mobile application already enough? What a way to allocate the two sensors, both the Direction As for the stability .... please ... help me ... thank you from ja ... Very difficulties appeared What que agora put any own robo now set up the great and I am allocating the pieces ... but do not know the position of placing sensors exactly ... Little tava Working now the great ... no ... I'm using the btn, Arduino Mega, Two engines dc 350w, hc06 but without STILL Communication
> 
> Thank you.. so much!


Sensors must be aligned such that the X axis is level and pointing to the front of the vehicle. The steering sensor is attached such that it tilts/banks while you move the steering. The board sensor is attached anywhere along the midline of the chassis/board. It measures the pitch of the board.

The android app is the best way to adjust P & D. Google "PID controller" to find out what P & D are for.


----------



## Speaner (Oct 21, 2015)

Good night Ovaltine and other friends, I need your help. I am using the program available here but my Arduino Mega burned , is to use this programming on the Arduino Uno without changes, or if necessary, could say what?

Thank you!


----------



## Ovaltineo (Jul 18, 2013)

That depends on what you've got hooked up. What motor controller are you using? Are you using Bluetooth?


----------



## Speaner (Oct 21, 2015)

Ovaltineo said:


> That depends on what you've got hooked up. What motor controller are you using? Are you using Bluetooth?


Good night Ovaltine, works with Uno, but I'm having a chronic problem, the GY-521 is burning, have burned 2 and in the same place - What lies at the foot of the handlebars.
I have no idea what can be tested on a support with free-wheel and was responding and working perfectly, but put on the floor (without raising it) and ends up burning. The following picture of what is on to see if there is any problem, I am feeding him with 5V coming straight from the 12V battery where before I control with 4 regulators LM7805 in parallel, and measuring out really 5V. Can you tell what might be happening? Has no alternative beyond that GY-521 can I use to control the tilt of the handlebars? I am available in the ADXL345 college, serves for something?
Detail: The GY-521 base did not present any problems, it is always the guidon burning, if you notice in the picture it has a thicker cable feed, can it interfere with something? Can I use a potentiometer on the handlebars to replace this sensor?
Please help me because I have two weeks to try to finalize this project ...


----------



## Speaner (Oct 21, 2015)

Continuing, he had forgotten to mention, see the serial monitor this sensor the values it shows now, and the worst move to the #define option MPU6050_X1_STEERING and does not work the same way ...

The first image is what appears serial monitor the project and the second image is a program to test the GY-521, both have the same value.


----------



## Ovaltineo (Jul 18, 2013)

Speaner said:


> Good night Ovaltine, works with Uno, but I'm having a chronic problem, the GY-521 is burning, have burned 2 and in the same place - What lies at the foot of the handlebars.
> I have no idea what can be tested on a support with free-wheel and was responding and working perfectly, but put on the floor (without raising it) and ends up burning. The following picture of what is on to see if there is any problem, I am feeding him with 5V coming straight from the 12V battery where before I control with 4 regulators LM7805 in parallel, and measuring out really 5V. Can you tell what might be happening?


I can see that you are very good in mechanical aspect but complete reverse in electronics. Your wiring is very poorly done. For example, the blue wire going to SDA on the steering sensor has exposed bare metal. You are also not using standard wiring color codes - black is normally ground, yet you use black to connect AD0 to Vcc (I'm assuming it is Vcc coz I cannot see where it connects to) and yellow to connect Ground. Why are there two wires connected to AD0? The wiring for the steering sensor should have some slack to allow for movement of the handle bar

What do you mean 5V coming straight from 12V battery? You should tap the 5V from the Arduino 5V pin (next to 3.3V pin).




> Has no alternative beyond that GY-521 can I use to control the tilt of the handlebars? I am available in the ADXL345 college, serves for something?
> Detail: The GY-521 base did not present any problems, it is always the guidon burning, if you notice in the picture it has a thicker cable feed, can it interfere with something? Can I use a potentiometer on the handlebars to replace this sensor?


Yes, you can use a potentiometer. +5V on pin 1 of the pot, pin 2(wiper) to A1 of Arduino, pin 3 to Ground. 


```
#define POT_STEERING
//#define MPU6050_X2_STEERING
//#define MPU6050_X1_STEERING
```


----------



## mutai (Dec 22, 2014)

Hello Guys,

My L298N motor controller just arrived- I cannot find a schematic in this thread.
Please help
my controller is: Link

Thanks,

Eran Mutai


----------



## Ovaltineo (Jul 18, 2013)

mutai said:


> Hello Guys,
> 
> My L298N motor controller just arrived- I cannot find a schematic in this thread.
> Please help
> ...


I can't read Chinese/Mandarin, so I'm not 100% sure of this schematic. One thing I'm not sure is if the 5V pin is an input or an output. Use a voltmeter to see if you can measure 5V on this pin. If yes, then leave it disconnected. If not, then it must be an input. If so, connect this to 5V on the Arduino.


----------



## mutai (Dec 22, 2014)

Dear Ovaltine,

Its working! actually I managed to connect it few days ago-But thanks anyway for the schematics.
The 5V is an input to the MCU.
The verified inputs are:
A1 to IN1 (Dir1)
A2 to IN2 (Dir2)
PA to ENA (PWM)

Regards,

Eran Mutai


----------



## raymar23 (Nov 7, 2015)

In the process of fabrication of my own version. Will post pic soon. Thanks for all you have done with this project Ovaltine.


----------



## RickSoares (Mar 4, 2014)

Personally, I'm one doubts ... about the mobile app ... my screen when communicating with Bluetooth, it turns blue ... but shows nothing of the engine, battery voltage ... and does nothing if I change something .... I have to do? I did not understand...


----------



## Ovaltineo (Jul 18, 2013)

Did you pair your phone to the Bluetooth module beforehand? What is the name that comes up during the pairing?


----------



## RickSoares (Mar 4, 2014)

Ovaltineo said:


> Did you pair your phone to the Bluetooth module beforehand? What is the name that comes up during the pairing?



The screen turns blue, and appears HC06
but not change anything ...


----------



## Ovaltineo (Jul 18, 2013)

RickSoares said:


> The screen turns blue, and appears HC06
> but not change anything ...


1. Is it HC06 or HC-06?
2. When you go to your phone's bluetooth settings, do you see HC-06 under paired devices?


----------



## Manuel Silva (Jun 20, 2014)

Hello all!
I have been looking in this thread for the Force Sensitive Resistor part number, to sense the person on the Segway, but I could not find it. 

Can some one please help and let me know the characteristics, part number and supplier of the Force Sensitive Resistor.

Thanks in advance.
Best regards,
Manuel


----------



## Ovaltineo (Jul 18, 2013)

I've just upgraded my Roboclaw firmware from v4.1.6 to v4.1.11 and was surprised that it is not backwards compatible because they changed the checksum from a simple 1-byte checksum to a 2-byte CRC. This means nothing works!

To fix this, I've released version 7.5 of the SegwayClone Arduino code in github. 

There are two new options for the controller ROBOCLAW_CRC_CONTROLLER and ROBOCLAW_CRC_ENCODER_CONTROLLER. Select one of these if your Roboclaw firmware is v4.1.11 or newer.

Those using v4.1.10 or older should continue using ROBOCLAW_CONTROLLER or ROBOCLAW_ENCODER_CONTROLLER. I have increased the timeout for voltage and temperature, so this may fix those with problems with v4.1.7 and later.


----------



## RonzaGeI (Nov 17, 2014)

http://www.ceiclub.it/images/Cariolino/UNO_BTN7960_2XMPU6050.pdf








Upgrade to image
UNO_BTN7960_2XMPU6050.pdf


----------



## Ovaltineo (Jul 18, 2013)

RonzaGeI said:


> http://www.ceiclub.it/images/Cariolino/UNO_BTN7960_2XMPU6050.pdf
> 
> 
> 
> ...


Hi RonzaGeI,
Something is not right with this diagram. I wouldn't connect Vin of Arduino to Vbat. I think this will burn the internal +5v regulator of the Arduino if Vbat is 24V.


----------



## RonzaGeI (Nov 17, 2014)

Oops, now it should be right.
(F5 or Ctrl + R to reload the page)
Hello


----------



## RonzaGeI (Nov 17, 2014)

A schematic and PCB fpr FREE Bridge H
http://www.ceiclub.it/index.php/progetti/22-driver-1-5-en

Hi


----------



## gui (Feb 11, 2016)

hello sir ovaltineo , first at all congratz 4 ur exelent tutotial but unfortanly i couldnt make it work cause im a amateur!! its possible to rearrange the arduino code? ardware is easy but code is headhake. im sry 4 my english as my native language is portuguese. thank u sir 

[email protected]

ps: i dont mind to pay if necessary to some1 who can send me by mail a code to work with these ardware.

arduino uno or mega
sabertooth
2 mpu6050


----------



## Ovaltineo (Jul 18, 2013)

gui said:


> hello sir ovaltineo , first at all congratz 4 ur exelent tutotial but unfortanly i couldnt make it work cause im a amateur!! its possible to rearrange the arduino code? ardware is easy but code is headhake. im sry 4 my english as my native language is portuguese. thank u sir
> 
> [email protected]
> 
> ...


Why do you want to rearrange the code? Do not attempt to do this unless you are a good programmer.

The software already supports a Mega + Sabertooth + 2 x mpu6050. Just download the source zipfile from github (see post #1) and unzip to SegwayClone directory.

The only file you have to modify is SegwayClone.h. You just need to uncomment the #define SABERTOOTH_CONTROLLER and comment/delete #define PWM_PWM_CONTROLLER. You must uncomment $define MODE_CALIBRATE (compile and upload) only when setting up the balance point. You must comment it again (compile and upload) after you've done this.

Let us know what specific errors/problems you get so we can help.


----------



## gui (Feb 11, 2016)

thanks 4 fast replay , ur advice did work well and im closer to setup the code 
language is a bit of barrier but hope u sir untherstand and have a litle patience. i would like to keep this tread alive and post my progress with the build


----------



## gui (Feb 11, 2016)

the code compiles well finaly.
question , do i need to use the POT 4 fine tuning even if is in the code?
i set my sabertooth to 9600 , is this well setup like in this atached file?
thanks


----------



## BillC (Feb 14, 2016)

Regarding the MPU-6050.... is it advantageous to replace it with the MPU-9150? I set-up and ran the 'teapot' and noted the amount of initial axis drift and wonder if that is detrimental to our 'Segway Clone' cause.... I do notice that the MPU-9150 has not been mentioned here at all.

Thanks - and also thanks greatly for all this super information. I'm spending lots of time reading - must get to work on the clone!

Bill C.

I think I can answer my own question - too much fluctuating magnetism near the two electric motors for the MPU-9150's 3-axis digital compass.


----------



## gui (Feb 11, 2016)

how do i install the app in android? dont know how to open that file! i have some wheelchair motors but i decide to order some 750w motors to drive with chain to avoid backlash.


----------



## Ovaltineo (Jul 18, 2013)

gui said:


> the code compiles well finaly.
> question , do i need to use the POT 4 fine tuning even if is in the code?
> i set my sabertooth to 9600 , is this well setup like in this atached file?
> thanks


The POT is optional. Having a bluetooth module with the Android app is the best way to fine tune P & D.

I don't have a Sabertooth, but this looks okay.


----------



## Ovaltineo (Jul 18, 2013)

BillC said:


> Regarding the MPU-6050.... is it advantageous to replace it with the MPU-9150? I set-up and ran the 'teapot' and noted the amount of initial axis drift and wonder if that is detrimental to our 'Segway Clone' cause.... I do notice that the MPU-9150 has not been mentioned here at all.
> 
> Thanks - and also thanks greatly for all this super information. I'm spending lots of time reading - must get to work on the clone!
> 
> ...


The 9150 is overkill for this application. There is drift on a gyro+accelerometer combination only in the z (heading) axis. A compass will fix this drift, but like you said, a compass will not work with the big motors (I've got this problem in my autonomous robot). In any case, the z axis is not used in a Segway, so it has no relevance.


----------



## Ovaltineo (Jul 18, 2013)

gui said:


> how do i install the app in android? dont know how to open that file! i have some wheelchair motors but i decide to order some 750w motors to drive with chain to avoid backlash.


Email the app to yourself and open it on your phone to install it.


----------



## gui (Feb 11, 2016)

the app was very easy to install , just the way u sir told me to do  , but after move the bluetooh file to segwayclone directory , uncoment in segwayclone.h , and compile just got loads off errors! what have i done wrong , before without bluetooh was fine.

Arduino: 1.6.7 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\DetectBluetooth.ino:9:0: warning: "SOFT_RX_PIN3" redefined [enabled by default]

#define SOFT_RX_PIN3 5 // connect to bluetooth module TX pin

^

In file included from C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\SegwayClone.ino:30:0:

sketch\SegwayClone.h:260:0: note: this is the location of the previous definition

#define SOFT_RX_PIN3 7 // connect to bluetooth module TX pin

^

C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\DetectBluetooth.ino:10:0: warning: "SOFT_TX_PIN3" redefined [enabled by default]

#define SOFT_TX_PIN3 6 // connect to bluetooth module RX pin

^

In file included from C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\SegwayClone.ino:30:0:

sketch\SegwayClone.h:261:0: note: this is the location of the previous definition

#define SOFT_TX_PIN3 8 // connect to bluetooth module RX pin

^

In file included from C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\MPU6050.ino:36:0:

sketch\MPU6050.h:114:0: warning: "MPU6050_AUX_VDDIO" redefined [enabled by default]

#define MPU6050_AUX_VDDIO MPU6050_D7 // I2C high: 1=VDD, 0=VLOGIC

^

sketch\MPU6050.h:9:0: note: this is the location of the previous definition

#define MPU6050_AUX_VDDIO 0x01 // R/W

^

In file included from C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\MPU6050.ino:36:0:

sketch\MPU6050.h:518:0: warning: "MPU6050_FIFO_EN" redefined [enabled by default]

#define MPU6050_FIFO_EN MPU6050_D6

^

In file included from C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\MPU6050.ino:36:0:

sketch\MPU6050.h:20:0: note: this is the location of the previous definition

#define MPU6050_FIFO_EN 0x23 // R/W

^

C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\DetectBluetooth.ino: In function 'void setbaud(long int)':

DetectBluetooth:29: error: redefinition of 'void setbaud(long int)'

void setbaud(long speed)

^

Bluetooth:8: error: 'void setbaud(long int)' previously defined here

void setbaud(long speed)

^

C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\DetectBluetooth.ino: In function 'boolean check(long int)':

DetectBluetooth:45: error: redefinition of 'boolean check(long int)'

boolean check(long speed)

^

Bluetooth:31: error: 'boolean check(long int)' previously defined here

boolean check(long speed)

^

C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\DetectBluetooth.ino: In function 'void setup()':

DetectBluetooth:70: error: redefinition of 'void setup()'

void setup() {

^

Pushback:273: error: 'void setup()' previously defined here

C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\DetectBluetooth.ino: In function 'void loop()':

DetectBluetooth:88: error: redefinition of 'void loop()'

void loop() {

^

Pushback:326: error: 'void loop()' previously defined here

In file included from C:\Users\gui\Desktop\SegwayClone-master\SegwayClone\MPU6050.ino:36:0:

sketch\MPU6050.h: At global scope:

sketch\MPU6050.h:621:1: warning: 'typedef' was ignored in this declaration [enabled by default]

};

^

exit status 1
redefinition of 'void setbaud(long int)'

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.


----------



## Uri (Nov 2, 2013)

Hi Ovaltine

I want to build a mini clone

Arduino mega
L293N
HC-06 Bluetooth
MPU

unfortunately I can't find the right schematic at the first page

Could you please help?


Regards

P.S. You are doing a great JOB.
Thank you


----------



## Ovaltineo (Jul 18, 2013)

gui said:


> the app was very easy to install , just the way u sir told me to do  , but after move the bluetooh file to segwayclone directory , uncoment in segwayclone.h , and compile just got loads off errors! what have i done wrong , before without bluetooh was fine.


Do not copy DetectBluetooth.ino to SegwayClone directory. Where did you read that you need to do that? Just uncomment #define BLUETOOTH in SegwayClone.h.


----------



## Ovaltineo (Jul 18, 2013)

Uri said:


> Hi Ovaltine
> 
> I want to build a mini clone
> 
> ...


Here it is.


----------



## Uri (Nov 2, 2013)

Thanx a LoT

Will start work on it soon 

One more question, do I need both MPUs?

Regards


----------



## gui (Feb 11, 2016)

tank you sir for ur advices 
now is time to build and here some first pictures , more soon. 

sould i use the 750w motor with 10 front sprocket and 54 rear sprocket 
OR 350W motors with 11 front sprocket and 74 rear sprocket OR
750w with 10 front sprocket and 74 rear sprocket

the wheels are 12inch from small electric dirt bike.
steering part from a bycicle.
8mm reenforced chain.


----------



## Valenz (Dec 11, 2015)

Hola Ovaltineo, dime si es possible usar (#define L298N_CONTROLLER), con (#define VOLTAGE_LED), com Arduino Mega, no esta en el ultimo esquematico, que publiacaste.

Saludos desde Brazil. .

Parece que sabes un poco de Español..


----------



## fiatromeo (Dec 29, 2013)

Hello, I would like to share its Projects.Ovaltineo thank you very much for the work done

Battary:Li-Ion 36v 10Ah
Power switch:Infineon-BTS50085 2X
Motor: XYD-13A 36v 750W 
Motor driver: ir2184 irfp2907
Wheel:R17 190/50
bluetooth ''setup''
bluetooth audio receiver
WTV020-SD-16P(voice-over speed,low battary,at startup intro sound)

https://www.youtube.com/watch?v=jqfL0SlozDw
https://www.youtube.com/watch?v=Ct-5SsEj36w
https://www.youtube.com/user/fiatromeo/videos?shelf_id=0&sort=dd&view=0


----------



## gui (Feb 11, 2016)

damm , thats freak aweosome  
i wish i could build 1 just like that.


----------



## johnnywheels (Nov 19, 2015)

That leaves my Airwheel X3 segway in the dust! That thing is sweet


----------



## Ovaltineo (Jul 18, 2013)

fiatromeo said:


> Hello, I would like to share its Projects.Ovaltineo thank you very much for the work done
> 
> Battary:Li-Ion 36v 10Ah
> Power switch:Infineon-BTS50085 2X
> ...


It is truly a work of art! I'm glad my project has inspired great works like this.

I was wondering if anyone else used the voice module. It is difficult to get the correct version of this module with an SD card that works. I'm glad you got it working.


----------



## Ovaltineo (Jul 18, 2013)

Valenz said:


> Hola Ovaltineo, dime si es possible usar (#define L298N_CONTROLLER), con (#define VOLTAGE_LED), com Arduino Mega, no esta en el ultimo esquematico, que publiacaste.
> 
> Saludos desde Brazil. .
> 
> Parece que sabes un poco de Español..


Habla Espanol un poco. It is possible, I'll create a new diagram for you.


----------



## Ovaltineo (Jul 18, 2013)

Here's the diagram. You need to grab the latest code (v7.8) from github.


----------



## fiatromeo (Dec 29, 2013)

Ovaltineo thank you for that appreciated my work.


----------



## Verial (Sep 2, 2015)

Hello.
Wanted to thank you for such a good project, I want your basis to make a Segway robot.
There are the following components for the realization of the project.

Arduino mega 2560
regulators L298n 
two gy-521 
motors from toy cars.
The only change is that I need to connect the router with it so far and I am suffering.

I apologize for the bad translation through GOOGLE.


----------



## Valenz (Dec 11, 2015)

Thank Ovaltineo for the new diagram and the V7.8 version.
Gracias Ovaltineo por el nuevo diagrana y la version V7.8.


----------



## Ovaltineo (Jul 18, 2013)

Verial said:


> Hello.
> Wanted to thank you for such a good project, I want your basis to make a Segway robot.
> There are the following components for the realization of the project.
> 
> ...


Router? Did you mean Wifi? I am considering porting this to an ESP8266, specifically the ESP-07.. There is an Arduino IDE for it. It is very cheap, won't need a bluetooth module, and can be configured/monitored through a browser.


----------



## Valenz (Dec 11, 2015)

Hi Ovaltine to monitor 12 volts (#VOLTAGE_LED) have to change the Alarms.h lines as below?

//#define MIN_BATTERY_1 24.0
#define MIN_BATTERY_1 12.0

//#define MIN_BATTERY_2 23.0
#define MIN_BATTERY_2 11.5

//#define MIN_BATTERY_3 22.0
#define MIN_BATTERY_3 11.0

//#define MIN_BATTERY_4 21.0
#define MIN_BATTERY_4 10.5

Muchas Gracias.

Carlos Valenzuela.


----------



## gui (Feb 11, 2016)

HI ovaltineo , here some fotos of my electronics , just check with serial and it give me some errors just like the Bluetooth.
i have uncoment the Bluetooth and also so have the app installed in my android but cant do nothing with the app, it say connected to Bluetooth module but cant controll it.
please mate give me a hand


----------



## Verial (Sep 2, 2015)

In fact, I am experiencing the electronics on the robot layout, this is standing in the corner.
His foundation Segway Uxon
400Watt without motors collector
a motor controller is a problem I can not find suitable for him.
I wanted to ask whether it is possible to program a function of getting up from a lying position?
http://www.youtube.com/watch?v=038e2j9nE3M
Setup via Bluetooth convenient of course but I'm trying to make a graphical application for monitoring the operation of the sensors and motors to computer on Windows 7.
https://geektimes.ru/company/litemf/blog/272010/


----------



## Ovaltineo (Jul 18, 2013)

Valenz said:


> Hi Ovaltine to monitor 12 volts (#VOLTAGE_LED) have to change the Alarms.h lines as below?
> 
> //#define MIN_BATTERY_1 24.0
> #define MIN_BATTERY_1 12.0
> ...


Yes, that looks OK.


----------



## Ovaltineo (Jul 18, 2013)

gui said:


> HI ovaltineo , here some fotos of my electronics , just check with serial and it give me some errors just like the Bluetooth.
> i have uncoment the Bluetooth and also so have the app installed in my android but cant do nothing with the app, it say connected to Bluetooth module but cant controll it.
> please mate give me a hand


The Arduino code can't find your bluetooth module- it is sending an AT command but is not getting an OK reply. 

The way you have connected pins on your prototype board is unconventional - it seems you have soldered it the other way around. I expected to see the copper side facing up, not down. Using a multi-meter, did you check that the TX3 & RX3 pins and the voltage divider resistors are soldered properly?

Also, your HC06 doesn't have a 3.3v regulator, so V should be connected to 3.3v not 5v.


----------



## Ovaltineo (Jul 18, 2013)

Verial said:


> His foundation Segway Uxon
> 400Watt without motors collector


Are you building a ride-on Segway or a remote-control robot? 400w would suit a ride-on Segway.



> I wanted to ask whether it is possible to program a function of getting up from a lying position?


I think if you set MAX_ANGLE = 180 and MIN_ANGLE = -180, it will stand upright when you power it up. But it means the wheels will keep spinning even if it falls over.

If you are writing your own control interface, then all you have to do is make it ignore the MAX_ANGLE/MIN_ANGLE when you press a button.


----------



## Verial (Sep 2, 2015)

https://www.sociallist.net/mini-sigvej-segway-uixon.html
then, from that basis I want to make a robot its just electronics. Now I work on the electronics layout.


----------



## gui (Feb 11, 2016)

thanks for fast replay , after check all the wires , pins , i couldnt make the Bluetooth working so im gona use POT to fine tuning.
the gyros are working great but theres no comunication with sabertooth! i think sabertooth come from factory with baud rate 9600 ( mine last version v.2 ) , i have been reading few times the tread but cause is huge is hard to unstersand all the changes that is made to hardware and code.
i decide to give up from sabertooth as had problems in the past and dont think they r reable!
just order this instead http://www.goodluckbuy.com/100a-mos...dge-dc-motor-driver-module.html?&currency=eur , lets see if i can finish my segway xd



best regards from portugal


----------



## Ovaltineo (Jul 18, 2013)

gui said:


> thanks for fast replay , after check all the wires , pins , i couldnt make the Bluetooth working so im gona use POT to fine tuning.
> the gyros are working great but theres no comunication with sabertooth! i think sabertooth come from factory with baud rate 9600 ( mine last version v.2 ) , i have been reading few times the tread but cause is huge is hard to unstersand all the changes that is made to hardware and code.
> i decide to give up from sabertooth as had problems in the past and dont think they r reable!
> just order this instead http://www.goodluckbuy.com/100a-mos...dge-dc-motor-driver-module.html?&currency=eur , lets see if i can finish my segway xd
> ...


Sabertooth is ok as long as you use a MEGA. You just need to make sure the DIP switches are correctly set - see README.txt. Someone posted a picture of the DIP switch somewhere in this thread. I recommend searching for "Sabertooth".


----------



## gui (Feb 11, 2016)

thank you sir ovaltine , i did read few times , even the tread thats huge and show all developements along few years. theres no comunication with sabertooth . the diagrams r simple and easy to untherstand so i really dont know what is goin on as i do know electronics a bit and the user electricpolo instructions about noise interference so r easy to do! so i will give a try on this new motor controller that u recomended sir ovaltine. i know i will have to do the setup just like the l298n controller and use last code update. i guess we have to wait and see  , but 1 thing its for sure , nothing along this 157 pages could be possible without ur knowlege and patience. THANK U SIR SO MUCH


----------



## Tomczyk (Oct 29, 2013)

Hello boys
* I have a little problem I do not know why I do not want to work a second MPU 6050 monitor shows ERROR = 2 is plugged + 5V to AD0 second zdefinoowane is normally MPU X2 Steering
Currently, tests have only hooked MPU
please help
Regards


----------



## JohanKraczmar (Feb 29, 2016)

Hi guys,
I need help with code because I am not familiar with code.
I have Arduino UNo R3, saberboth 2x25 , MPU 6050, and 10k steering pot.
Can somebody help me with code ?


----------



## Ovaltineo (Jul 18, 2013)

Tomczyk said:


> Hello boys
> * I have a little problem I do not know why I do not want to work a second MPU 6050 monitor shows ERROR = 2 is plugged + 5V to AD0 second zdefinoowane is normally MPU X2 Steering
> Currently, tests have only hooked MPU
> please help
> Regards


Swap the two modules and check which one is returning an error. If the same module is returning an error, then it is probably defective.


----------



## Ovaltineo (Jul 18, 2013)

JohanKraczmar said:


> Hi guys,
> I need help with code because I am not familiar with code.
> I have Arduino UNo R3, saberboth 2x25 , MPU 6050, and 10k steering pot.
> Can somebody help me with code ?


In SegwayClone.h, select the SABERTOOTH_CONTROLLER and POT_STEERING, like this:

#define POT_STEERING
//#define MPU6050_X2_STEERING
//#define MPU6050_X1_STEERING
//#define GY80_STEERING


//#define PWM_PWM_CONTROLLER
//#define PWM_DIR_CONTROLLER
//#define ROBOCLAW_CONTROLLER
//#define ROBOCLAW_ENCODER_CONTROLLER
//#define ROBOCLAW_CRC_CONTROLLER
//#define ROBOCLAW_CRC_ENCODER_CONTROLLER
#define SABERTOOTH_CONTROLLER
//#define PWM_SHIELD_CONTROLLER
//#define L298N_CONTROLLER
//#define OSMC_CONTROLLER


----------



## JohanKraczmar (Feb 29, 2016)

Ovaltineo said:


> In SegwayClone.h, select the SABERTOOTH_CONTROLLER and POT_STEERING, like this:
> 
> #define POT_STEERING
> //#define MPU6050_X2_STEERING
> ...


Thank you for the reply,

I tried to follow your advice, but during compilation is there error, that initmotors is not declared.
Is there any steps which I need to do step by step to calibrate gyro, then upload full code in run mode? Sure that is my mistake but I am trying my best


----------



## remzibi (Mar 8, 2016)

Hello all, my first post, so Hello to everyone.
Well, so nice thread, I just(today) build an small balancing bot, it took me literally one afternoon, using some used and not used PCBs as support/construction chasse. 
One MPU6050 module, one module L298 for motors, two motors for RC car with gear box and quite big backlash. Parts I got very chip few time ago for possible other usage, so fortunate I had a full set.
Software configuration was just for one 6050, no pot, no others. Pushback on.
First run and I was indeed surprised, the bot kept stable  , let say - it is live !!!  . 
Ovaltineo, great work you did with this software.
Now time for me, to add some RC steering ability functions, using standard RC equipment  .
And in near future, to buy bigger motors (BTS7960B already have), and to made Me been an stabilized object  .
Below is the first run movie, not a trick, it just default run after flashing firmware (after calibration) and screw on the wheels.




link

There is not on the movie, but my wife and children was amazed by this bot, as few years ago by quadrocopters  .


----------



## Tomczyk (Oct 29, 2013)

With Ovaltine's
Had damaged MPU Although I do not know why


----------



## Ovaltineo (Jul 18, 2013)

remzibi said:


> Hello all, my first post, so Hello to everyone.
> Well, so nice thread, I just(today) build an small balancing bot, it took me literally one afternoon, using some used and not used PCBs as support/construction chasse.
> One MPU6050 module, one module L298 for motors, two motors for RC car with gear box and quite big backlash. Parts I got very chip few time ago for possible other usage, so fortunate I had a full set.
> Software configuration was just for one 6050, no pot, no others. Pushback on.
> ...


You built this in one afternoon? That is mighty impressive!


----------



## Ovaltineo (Jul 18, 2013)

JohanKraczmar said:


> Thank you for the reply,
> 
> I tried to follow your advice, but during compilation is there error, that initmotors is not declared.
> Is there any steps which I need to do step by step to calibrate gyro, then upload full code in run mode? Sure that is my mistake but I am trying my best


Did you download the ZIP file from Github? When you unzipped it, did it create a SegwayClone directory?
When you open SegwayClone.ino in the Arduino IDE, does it open tabs for each file like in the attached image?


----------



## gui (Feb 11, 2016)

hi , still waiting for the new 100amps motor controller so i just improve my segway base. here some fotos.

750w motors
11 front sprocket
74 rear sprocket

i think this way i have loads of torque.


----------



## remzibi (Mar 8, 2016)

Ovaltineo said:


> You built this in one afternoon? That is mighty impressive!


That true  , if all parts are available, it is only to drill about 20 holes, cut M3 rods for support and use some screws (Arduino's supports are from PC for mainboards) and some cables to connect everything - all of all 4 hours  . 
At last, compiling and flashing - 2 minutes  .

Another question for Poland citizens only, where to get wheels and gears for full size scooter?
Gdzie w Polsce mozna dostac kola, zebatki i silniki pelnowymiarowe ? od skuterow ?


----------



## JohanKraczmar (Feb 29, 2016)

Hi,
thank you for your advice  Yes problem was between chair and keyboard 

So I uploaded proram to arduino, calibrate, and start in run mode. Motors are stil running in -20 percent, this I can see in serial monitor, pot angle is chaning depend of angle, gyro is changing due to board angle, but just there is still -20 on the motors. Some advice ?


----------



## Ovaltineo (Jul 18, 2013)

JohanKraczmar said:


> Hi,
> thank you for your advice  Yes problem was between chair and keyboard
> 
> So I uploaded proram to arduino, calibrate, and start in run mode. Motors are stil running in -20 percent, this I can see in serial monitor, pot angle is chaning depend of angle, gyro is changing due to board angle, but just there is still -20 on the motors. Some advice ?


The steering angle (which is controlled by the POT) is at 60 degrees. It thinks you are trying to do a full right! Make sure you are close to 0 degree steering angle when your steering shaft is in neutral position. The POT should be at the center position when neutral.


----------



## sanja666 (Dec 16, 2014)

Very strongly brakes the wheel. The delay in the turn of the wheel for about 1 second . Tell me where is the problem?
Pro mini 5v 16mHz (328mega)
2x mpu6050
l298


----------



## benn (Feb 2, 2016)

I have a question that maybe someone could help me out with. I downloaded the zip file, however i cannot figure out how to get it in arduino program. I unzipped it and it created a master file. Then i tried to open it in arduino and it is telling me that it cannot open the file. It says it needs to be in a different file format. Do i need to change the file name or folder to get it to transfer into arduino program or am i making a newbie mistake , I am using 1.6.8 if that helps.


----------



## Verial (Sep 2, 2015)

I will try to explain, you must create a separate folder and upload the whole program then run the file SegwayClone and you should load all the libraries.


----------



## benn (Feb 2, 2016)

Thank you, i created a new file and put it into arduino file. Then opened it up in the arduino program. The program is for a saber tooth controller and also uses a pot. I am using two 6050, one for steering and one for pitch. My motor controllers are bts7960'S. How do i go about it, do i delete/uncomment the pot/controller and then upload another library. Sorry this is kind of confusing for me but i do know my way around the computer but this programming is different.


----------



## [email protected] (Mar 22, 2014)

Hello oval .
You've done an excellent job , you are our inspiration.
I would like to ask something very special , would you please could add to the support program for BLDC motors .
Thank you very much


----------



## sanja666 (Dec 16, 2014)

How can I increase the steering reaction ? It responds to long turns I use 2 mpu6050.


----------



## diyelectric (Jun 29, 2015)

Ovaltineo said:


> Do you know the power rating of this voltage regulator? Your motors could easily draw 200W peak power when stalled.
> 
> 
> 
> Yes you can use it. Use PWM_DIR_CONTROLLER. If you haven't bought them already, you may want to consider this instead http://www.goodluckbuy.com/60a-high-power-mos-dual-channel-h-bridge-dc-motor-driver-module.html. You only need 1 of these and you can connect your batteries directly without a regulator.



Good Afternoon Ovaltineo!

I am sorry it has been a while I had to put the project down but now want to finish it. You are correct to have me check the power rating of the DC-DC Stepdown. It is the ICStation.com LM2596S DC Stepdown which I read has a max output of 3A. So now I changed the position of it. I put it between the 24V battery and the Arduino Mega 2560 to stepdown the 24v to 12v for the Mega only. Whereas before it was between the battery and the 2 x MD10C Cytron Motor Drivers. Thank you for saving me a burnout!

1. Since the +/- direct from battery goes into the LM2596 (IN) at 26.7v, can I just split off those 2 wires, before it reaches the LM2596 (IN), and send them over as 24V to the 2 Cytron MD10C Motor Drivers?

2. I have tried to research for hours on how to use the Cytron MD10C's but have come up to a wall and yours/group help. You said to use PWM_DIR_CONTROLLER... and to modify the motors.h file. I got that part. But in motor.h file, it has 

#ifdef MEGA	
#define RIGHT_PWM_PIN 2
#define RIGHT_DIR_PIN 3
#define LEFT_PWM_PIN 5
#define LEFT_DIR_PIN 6
#define MOTOR_ENABLE_PIN	7

On each Cytron MD10C, there is only DIR, PWM, GND available for me to connect to. (http://www.robotshop.com/media/files/pdf2/md10crev2.0usersmanual_2015-07.pdf)

I can assume Your DIR means their DIR. Your PWM is their PWM.

But how to do the MOTOR_ENABLE_PIN?

3. I have the HC-06 Bluetooth Module, but it is not the JY-MCU Linvor. I will try it anyway.

4. I have some 13amp Fuses and fuse holders. If you were going to put them in the schematic to protect the hardware, where would you recommend putting put them? (I was thinking just before the Cytron Motor Driver power IN).

Thank you all!


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> Thank you, i created a new file and put it into arduino file. Then opened it up in the arduino program. The program is for a saber tooth controller and also uses a pot. I am using two 6050, one for steering and one for pitch. My motor controllers are bts7960'S. How do i go about it, do i delete/uncomment the pot/controller and then upload another library. Sorry this is kind of confusing for me but i do know my way around the computer but this programming is different.


Assuming that the files load properly in the Arduino IDE, yes, just uncomment what is appropriate for your setup in SegwayClone.h. Compile and upload the program to your Arduino.


----------



## Ovaltineo (Jul 18, 2013)

diyelectric said:


> 1. Since the +/- direct from battery goes into the LM2596 (IN) at 26.7v, can I just split off those 2 wires, before it reaches the LM2596 (IN), and send them over as 24V to the 2 Cytron MD10C Motor Drivers?


Yes.


> But how to do the MOTOR_ENABLE_PIN?


Your controller doesn't have one (always enabled), so disregard this pin. 



> 4. I have some 13amp Fuses and fuse holders. If you were going to put them in the schematic to protect the hardware, where would you recommend putting put them? (I was thinking just before the Cytron Motor Driver power IN).
> !


Yes, one before each controller.


----------



## Ovaltineo (Jul 18, 2013)

[email protected] said:


> Hello oval .
> You've done an excellent job , you are our inspiration.
> I would like to ask something very special , would you please could add to the support program for BLDC motors .
> Thank you very much


Which controller in particular?


----------



## Ovaltineo (Jul 18, 2013)

sanja666 said:


> How can I increase the steering reaction ? It responds to long turns I use 2 mpu6050.


Increase the value of STEER_MULTIPLIER in SegwayClone.h. There are multiple instances of this constant - replace it in the section that matches your motor controller.


----------



## benn (Feb 2, 2016)

Ok i must be a complete nube or just plain dumb to this library/sketch. I have downloaded the zip and renamed it, copied it and placed into library. Opened a new arduino and opened file from libraries. I do not see how to get the program to run with the 7960 and 6050 on the mega. I understand the uncomment/comment thing but some of the things i am using are not in the program. I may not be doing the files right. Would somebody please help me and i am sorry for bothering yall. I am using the mega, buzzer, two 6050's and two bts7960 driver's. I would like to wire it as the example schematic Ovaltine's has for this set up. Thank you and i have a great day/night.


----------



## benn (Feb 2, 2016)

I think i found the proplem. I looked at the other thread and it says i need to open the segwayclone.ino file. my unzipped file doesnt have that file. Could this be the problem. 

Copied and pasted from previous thread below:

Did you confirm all those nine files are in one directory, and did you click on the 'segwayclone.ino' file to run it?

If you do this (ie. click & open segwayclone.ino from windows explorer) it should bring up it up with all the associated files in the IDE, and from there it should compile. Check across the IDE tabs that it shows "SegwayClone, EEPROM.h, EEPROM, MPU6050.h, MPU6050, Motors.h, Motors, SegwayClone.h" in a row just under where the tick & arrow icons are...

In terms of posting the contents of SegwayClone.h for OT you could just go to that tab in the IDE & copy/paste to the forum - I realise the formatting here will mess it up a little but by doing this you'll confirm first of all that the compiler has the file and it's contents, and OT will get to see for sure what's in it 

in sketch, File > Open, then Navigate to the unzipped SegwayClone folder and select SegwayClone.ino

it will by default open up the rest of the 6 files. if you have MPU6050 folder in your libraries, just relocate MPU6050 folder out of the libraries folder before you verify/upload.


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> I think i found the proplem. I looked at the other thread and it says i need to open the segwayclone.ino file. my unzipped file doesnt have that file. Could this be the problem.
> 
> Copied and pasted from previous thread below:
> 
> ...


Where are you getting the zipped file from? Goto post #1 for the location.


----------



## benn (Feb 2, 2016)

Yes sir that is where i got it. I read another post so i could understand what i was doing wrong. I got it and now can see all the tabs in the program. One question, when i comment out the things i do not use. Do i do it in segwayclone or in the individual files like Alarm and Alarm.h. Thank you everyone for your patients, i plan on starting me a build thread as soon as i can get this under control. Also Ovaltine, i appreciate your time in helping a nube out and replying back. You are one in a million and glad i stumbled onto this site. I have read so much that i want to drop the card down and build some things.


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> Yes sir that is where i got it. I read another post so i could understand what i was doing wrong. I got it and now can see all the tabs in the program. One question, when i comment out the things i do not use. Do i do it in segwayclone or in the individual files like Alarm and Alarm.h. Thank you everyone for your patients, i plan on starting me a build thread as soon as i can get this under control. Also Ovaltine, i appreciate your time in helping a nube out and replying back. You are one in a million and glad i stumbled onto this site. I have read so much that i want to drop the card down and build some things.


You only need to change SegwayClone.h for the calibrate mode, steering, controller, and bluetooth options. For motor-related parameters like MOTOR_MAX, you need to modify Motors.h.


----------



## diyelectric (Jun 29, 2015)

Thanks for the previous answers! Regarding the TC74 Temperature Sensors... is this the correct one:

http://my.rs-online.com/web/p/temperature-humidity-sensors/7386005/

MYR 6.08 is about AUD 2.00 each


----------



## Ovaltineo (Jul 18, 2013)

diyelectric said:


> Thanks for the previous answers! Regarding the TC74 Temperature Sensors... is this the correct one:
> 
> http://my.rs-online.com/web/p/temperature-humidity-sensors/7386005/
> 
> MYR 6.08 is about AUD 2.00 each


I specified one TC74A0 and one TC74A2 - they have different addresses. That one is the TC74A5. That site doesn't seem to have the 5V TC74A2 - they only have the 3.3V version. You can replace TC74A2 with the TC74A5 if you change TC74.h like this.

```
#define TC74_ADD1	0x48		//TC74A0
#define TC74_ADD2	0x4D		//TC74A5
```
If you want two temperature sensors, you'll also need the TC74A0
http://my.rs-online.com/web/p/products/6687313/?sra=p&r=t.


----------



## [email protected]om (Mar 22, 2014)

Ovaltineo said:


> Which controller in particular?



Yes...Oval, I use: 

2 controllers BTN6970, arduino mega and 2 MPU 6050.

Thank you very much


----------



## erdmensch (Sep 18, 2011)

why whistling engines?


----------



## gui (Feb 11, 2016)

DAMM , takes ages to arrive my motor controller !!! wonder when im gonna be able to finish my segway 
goodluckbuy.com/100a-mos-opto-isolated-dual-channel-h-bridge-dc-motor-driver-module.html


----------



## ayduvan (Jul 7, 2014)

Hello,
Please help me,
I want to use stepper motor my new mini clone.Is it possible or not.
Many thanks.



https://www.youtube.com/watch?v=2RTmhA5dfC0


----------



## shartgen (Mar 23, 2016)

Hi there,
im trying to get my segway clone done, the mechanics have already been finished but the arduino is going to make me sick soon  . 
i uploaded a video and hope anyone can help me out. i know, theres a "beep-indicator", but i still can't figure out what to do. 

https://youtu.be/Qkhnx99UUbM


thanks a lot,
steffen

im sorry for my bad german- english


----------



## wsm (Jan 6, 2015)

Melde dich doch mal über www.ups.bplaced.de bei mir.


----------



## Ovaltineo (Jul 18, 2013)

ayduvan said:


> Hello,
> Please help me,
> I want to use stepper motor my new mini clone.Is it possible or not.
> Many thanks.
> ...


You can, but why? Stepper motors are used for positional accuracy but this is not needed in this application. On the other hand, you need two L298N drivers instead of one, and they are more bulky and more expensive than a similar standard motor. They also jerk when moving at low speeds which is not good for a balancing bot. Least of all, they are not set and forget, ie my code expects the motors to keep turning while it is busy doing other things, but the stepper motors require constant attention unless interrupt handlers are used or dedicated co-processor is used (like I did for the WTV020 voice module).


----------



## Ovaltineo (Jul 18, 2013)

shartgen said:


> Hi there,
> im trying to get my segway clone done, the mechanics have already been finished but the arduino is going to make me sick soon  .
> i uploaded a video and hope anyone can help me out. i know, theres a "beep-indicator", but i still can't figure out what to do.
> 
> ...


Sounds like an I2C error (long-short-short). Did you select MPU6050_X2_STEERING or MPU6050_X1_STEERING? What is showing up in the Serial Monitor?


----------



## shartgen (Mar 23, 2016)

Ovaltineo said:


> Sounds like an I2C error (long-short-short). Did you select MPU6050_X2_STEERING or MPU6050_X1_STEERING? What is showing up in the Serial Monitor?


im using one MPU_6050
i uncommented #define MPU6050_X1_STEERING . 
the serial monitor is showing nothing :S


----------



## ayduvan (Jul 7, 2014)

Thanks for your answers.
I want to run brushles motor as the stepper motor. If I change the internal windings of the brushless motors like bipolar stepper motor. I think, may be I can use 2 x hub(e-bike) engine.
Thank you very much.


----------



## shartgen (Mar 23, 2016)

I did it! The i2c error was caused by a broken jumperwire... Everything is working fine now. Going to finish my protoshield next week and upload a video for u guys. 

Thanks a lot ovaltineo! I did great work!


----------



## Ovaltineo (Jul 18, 2013)

ayduvan said:


> Thanks for your answers.
> I want to run brushles motor as the stepper motor. If I change the internal windings of the brushless motors like bipolar stepper motor. I think, may be I can use 2 x hub(e-bike) engine.
> Thank you very much.
> View attachment 59066


I don't understand why you would want to do that. Are you going to build your own controller and write your own controller code? Why don't you just use a BLDC controller?


----------



## [email protected] (Mar 22, 2014)

Ovaltineo said:


> I don't understand why you would want to do that. Are you going to build your own controller and write your own controller code? Why don't you just use a BLDC controller?


Hi ayduvan ... hi oval

I also wish to segway clone with BLDC motors and cotroladores BTN6970. 

I hope the "great oval" can help us with the code.


----------



## Ovaltineo (Jul 18, 2013)

[email protected] said:


> Hi ayduvan ... hi oval
> 
> I also wish to segway clone with BLDC motors and cotroladores BTN6970.
> 
> I hope the "great oval" can help us with the code.


The BTN7960 is a "brushed" motor controller - it cannot be used to drive a BLDC motor. If you can find an affordable high-power BLDC controller with a serial or PWM interface, then I might consider writing code for it.


----------



## Verial (Sep 2, 2015)

Good morning
I'm writing a program to control a brushless motor, my motors from mini Segway, there are MOSFETs p75nf75


----------



## [email protected] (Mar 22, 2014)

Ovaltineo said:


> The BTN7960 is a "brushed" motor controller - it cannot be used to drive a BLDC motor. If you can find an affordable high-power BLDC controller with a serial or PWM interface, then I might consider writing code for it.


Hello Oval...hello Verial
I built example BLDC motor and L298
https://youtu.be/IHmFiu9K9LE


----------



## [email protected] (Mar 22, 2014)

Standard BLDC Motor and L298

https://youtu.be/8dS5K2gQw9c



Verial ...Por favor cuando tenga el codigo ... lo puede compartir?


----------



## benn (Feb 2, 2016)

What clone console are you using for android. I am trying to find it and have used the search function in this forum post. By the way, my clone is almost done and will post a video up when completed in a separate thread, thanks and have a great day.


----------



## Ovaltineo (Jul 18, 2013)

[email protected] said:


> Standard BLDC Motor and L298
> 
> https://youtu.be/8dS5K2gQw9c
> 
> ...


In a way, you are right - an L298 can drive a BLDC motor, after all the L298 has 4 available poles and a BLDC only has 3 poles. But does it work under load at variable speeds without missing cogs? How do you know when to move to the next step without the feedback needed by a proper BLDC controller? 

Even better, please publish the software driver that would work with the SegwayClone.


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> What clone console are you using for android. I am trying to find it and have used the search function in this forum post. By the way, my clone is almost done and will post a video up when completed in a separate thread, thanks and have a great day.


The ClonseConsole zip is attached to the first post of this thread.


----------



## benn (Feb 2, 2016)

Thank you, I have an issue with the motors. I am getting a run off and cannot stop it. I calibrate then go to run mode. It will beep for 4 seconds and the motors will start slow and run up to max. I can turn left and right and see that it will turn but cannot lean back and slow/stop. 

Here's what I am doing.
Calibrate with run mode Uncommented.
Run mode with calibrate Uncommented
My power is on everything when doing this.

I await for a constant beep then do run mode.
It will beep and take off. I am doing this on a table trying to figure it out. 

I do not have a switch wired for rider. Was going to use a push switch to pull to ground when on, if this will work. Anyways back at it, really enjoying the build and cannot wait to ride.
If anybody has any ideas please feel free to make sudgestions. I am using two 6050's.


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> Thank you, I have an issue with the motors. I am getting a run off and cannot stop it. I calibrate then go to run mode. It will beep for 4 seconds and the motors will start slow and run up to max. I can turn left and right and see that it will turn but cannot lean back and slow/stop.
> 
> Here's what I am doing.
> Calibrate with run mode Uncommented.
> ...


You are moving one sensor for the steering and the other sensor for forward & back, right?

In run mode, when you move the tilt sensor forward and back, do you see the ACCEL, GYRO and BOARD_ANGLE change in the Serial monitor? If not, then triple check the wiring of your sensor. Also, swap it with the steering sensor - if it works, then you may have a faulty sensor. A few users here have found that one of their sensors is faulty.


----------



## erdmensch (Sep 18, 2011)

https://www.youtube.com/watch?v=DPEo68AbpYM

here is my Segway clone
Wheelchair motors 24V
2 batteries 12V 15Ah
Arduino Mega
Motor Controller BTS 7960
2 Gyros MPU6050

Can anyone give tips because the engines are too noisy


----------



## Ovaltineo (Jul 18, 2013)

erdmensch said:


> https://www.youtube.com/watch?v=DPEo68AbpYM
> 
> here is my Segway clone
> Wheelchair motors 24V
> ...


That's because the Arduino default PWM frequency is 490Hz. It is easy to switch to 31KHz or 62KHz (both beyond hearing) but the BTS controller has a max frequency of 25KHz. The other alternatives are 3.9KHz and 7.8KHz but these still make a high pitched sound.

20KHz to 25KHz would be ideal but impossible to achieve with the ATmega without messing up the millisecond timer needed by the application. The best I can achieve is 15KHz, but I have not thoroughly tested it.

Please try replacing #define PWM_PWM_CONTROLLER with #define PWM_PWM_15KHZ_CONTROLLER. Do a bench test before riding it. Let us know if it works.


----------



## erdmensch (Sep 18, 2011)

Ovaltineo said:


> That's because the Arduino default PWM frequency is 490Hz. It is easy to switch to 31KHz or 62KHz (both beyond hearing) but the BTS controller has a max frequency of 25KHz. The other alternatives are 3.9KHz and 7.8KHz but these still make a high pitched sound.
> 
> 20KHz to 25KHz would be ideal but impossible to achieve with the ATmega without messing up the millisecond timer needed by the application. The best I can achieve is 15KHz, but I have not thoroughly tested it.
> 
> Please try replacing #define PWM_PWM_CONTROLLER with #define PWM_PWM_15KHZ_CONTROLLER. Do a bench test before riding it. Let us know if it works.


No get errors when compiling with pushback
where can I enter 7,8kHz


----------



## benn (Feb 2, 2016)

Ovaltineo said:


> You are moving one sensor for the steering and the other sensor for forward & back, right?
> 
> In run mode, when you move the tilt sensor forward and back, do you see the ACCEL, GYRO and BOARD_ANGLE change in the Serial monitor? If not, then triple check the wiring of your sensor. Also, swap it with the steering sensor - if it works, then you may have a faulty sensor. A few users here have found that one of their sensors is faulty.



I think you are correct. Last night i got to looking at wiring to tilt sensor and i am now soldering the wires directly to it. I know one mistake i made was how it was facing. i had x to front but the arrow was pointing sideways. I calibrated and ran it to see, it was working but beeping irregularly. This is telling me that i am not making good contact. Thank you so much for your help and hopefully i will be uploading a video shortly.

P.S. i am reading every comment on this thread again, at page 56 now. It is amazing how much information i have missed


----------



## Ovaltineo (Jul 18, 2013)

erdmensch said:


> No get errors when compiling with pushback
> where can I enter 7,8kHz


Oops, missed a few constants. Please add these to SegwayClone.h.

```
#if defined(PWM_PWM_15KHZ_CONTROLLER)
	// use these values if using PWM
	#define KP 2.8					// proportional constant when rider is ON
	#define KD 1.2   				// derivative constant when rider is ON
	#define STEER_MULTIPLIER 14		// adjust depending on your motor speed
	#define KP_OFF 1.4				// proportional constant when rider is OFF
	#define KD_OFF .6 				// derivative constant when rider is OFF
#endif
```
I had another look at the code and it looks like I've already changed the PWM frequency to 3.9KHz. Also, changing to 7.8KHz requires coding like the 15KHz.


----------



## benn (Feb 2, 2016)

Ok, got an issue. I loaded the test program with just the motors hooked up and am not getting any movement. i am getting information from the serial screen and have tried two megas. What goes wrong with the 7960's. I hope both havent took a crap out on me because it will be two weeks before i get another set.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> In a way, you are right - an L298 can drive a BLDC motor, after all the L298 has 4 available poles and a BLDC only has 3 poles. But does it work under load at variable speeds without missing cogs? How do you know when to move to the next step without the feedback needed by a proper BLDC controller?
> 
> Even better, please publish the software driver that would work with the SegwayClone.



I'm riding the system with BTN7960. 
I'll post the results when finished.


----------



## erdmensch (Sep 18, 2011)

https://www.youtube.com/watch?v=R2nZYL7kajQ


Many many thanks
now it's working


----------



## erdmensch (Sep 18, 2011)

Ovaltineo said:


> Oops, missed a few constants. Please add these to SegwayClone.h.
> 
> ```
> #if defined(PWM_PWM_15KHZ_CONTROLLER)
> ...


Many many thanks
now it's working

https://www.youtube.com/watch?v=R2nZYL7kajQ


----------



## Ovaltineo (Jul 18, 2013)

erdmensch said:


> Many many thanks
> now it's working
> 
> https://www.youtube.com/watch?v=R2nZYL7kajQ


Is that with 15KHz? The pitch sounds much lower than your previous video with the 3.9KHz frequency. Is it quieter?


----------



## erdmensch (Sep 18, 2011)

Ovaltineo said:


> Is that with 15KHz? The pitch sounds much lower than your previous video with the 3.9KHz frequency. Is it quieter?



yes you are right I have the frequency divided by 2 that was wrong!

setPwmFrequency(HZ_31250/2); // set PWM frequency to 31250/2 = 15625 kHz (divide by 2 when using TOP=0x3FF)


Now it is quiet!

many thanks for everything


----------



## benn (Feb 2, 2016)

benn said:


> Ok, got an issue. I loaded the test program with just the motors hooked up and am not getting any movement. i am getting information from the serial screen and have tried two megas. What goes wrong with the 7960's. I hope both havent took a crap out on me because it will be two weeks before i get another set.


I went ahead and ordered a roboclaw 60A motor driver. Can someone post up the schematic for wiring using a mega with blue tooth please. I am going to redo everything and would like to run the wires. Also i have read in the thread about using resistors, is this right. The blue tooth is somewhat confusing because i read that some say use resistors and some say you do not need to. I am at page 91 and reading up til my first post. Thanks ovaltine and others for a wealth of knowledge. Have a great day.


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> Ok, got an issue. I loaded the test program with just the motors hooked up and am not getting any movement. i am getting information from the serial screen and have tried two megas. What goes wrong with the 7960's. I hope both havent took a crap out on me because it will be two weeks before i get another set.


Which test program? Did you connect the pins used by the program? I thought you already got the motors working with SegwayClone, it's just the forward/back sensor not working?


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> I went ahead and ordered a roboclaw 60A motor driver. Can someone post up the schematic for wiring using a mega with blue tooth please. I am going to redo everything and would like to run the wires. Also i have read in the thread about using resistors, is this right. The blue tooth is somewhat confusing because i read that some say use resistors and some say you do not need to. I am at page 91 and reading up til my first post. Thanks ovaltine and others for a wealth of knowledge. Have a great day.


The schematics are in post #1. You should use resistors.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> In a way, you are right - an L298 can drive a BLDC motor, after all the L298 has 4 available poles and a BLDC only has 3 poles. But does it work under load at variable speeds without missing cogs? How do you know when to move to the next step without the feedback needed by a proper BLDC controller?
> 
> Even better, please publish the software driver that would work with the SegwayClone.



Hello Oval...

BTN7960 engine running

https://youtu.be/hlvUBrRK-vA

I'll post the logic which is in asembler microchip

The three motor windings with three half-bridges work H.


----------



## ferchotech (May 29, 2014)

The code is written continuously causes the motor to rotate .... to change the direction of rotation must reverse the sequence.

Code

https://goo.gl/photos/8dUswLXiK6dqn4Dy8


----------



## ferchotech (May 29, 2014)

This is a graphic example of the sequence.

https://goo.gl/photos/FrXtPL147Hg9vzBE9

Regards


----------



## ferchotech (May 29, 2014)

I will include Hall effect sensors to perform better motor control. these can also be used in the future to perform the speed control


----------



## erdmensch (Sep 18, 2011)

erdmensch said:


> yes you are right I have the frequency divided by 2 that was wrong!
> 
> setPwmFrequency(HZ_31250/2); // set PWM frequency to 31250/2 = 15625 kHz (divide by 2 when using TOP=0x3FF)
> 
> ...


https://www.youtube.com/watch?v=hL6fblZJgLg


----------



## Ovaltineo (Jul 18, 2013)

ferchotech said:


> The code is written continuously causes the motor to rotate .... to change the direction of rotation must reverse the sequence.
> 
> Code
> 
> https://goo.gl/photos/8dUswLXiK6dqn4Dy8


This is very basic. It will not work with the variable speed & variable load requirements of a balancing robot.


----------



## Ovaltineo (Jul 18, 2013)

erdmensch said:


> https://www.youtube.com/watch?v=hL6fblZJgLg


Nice and quiet !


----------



## benn (Feb 2, 2016)

Ovaltineo said:


> Which test program? Did you connect the pins used by the program? I thought you already got the motors working with SegwayClone, it's just the forward/back sensor not working?


I did have it working but i pulled the wiring out and redid it. When i went back together i shorted a 5 volt vcc on steering input and back fed ground through dc/dc step down to sensors and motor drivers. I corrected and ran the test program that was posted for someone on here to test motors. It was using the same pins. In the serial monitor it was showing it going up in value and down in value. The only other thing i did was shorting the motor wires coming out of the drivers from 18 inches to 4 inches. I am getting 5 volts to controller and 24 from batteries. However i cannot get any power out of driver and do not have an oscilloscope to test for signal, why i tested with other megas. I just figured i shorted out something in the motor drivers  So i read that you like the roboclaw controller, so i bought the 2x60.

The wiring i seen on page on that had the roboclaw was for uno not mega.


found the code, this is what i tested with on page 35, post number 349.


----------



## ferchotech (May 29, 2014)

Ovaltineo said:


> This is very basic. It will not work with the variable speed & variable load requirements of a balancing robot.



A great day for you. Thank you very much for answering and thank you very much for your time.

Yes, This is very basic.... I am a beginner programmer that's why I ask for your valuable help.

I wanted to show how the BLDC motor controller works with the BTN7960.

This video engine.
https://youtu.be/z5CPiOWv-8Y


----------



## ferchotech (May 29, 2014)

Hello friend Ovaltine's

Looking at Google I found the following interesting arduino code to handle BLDC motors in handling holl effect sensors and the regenerative voltage is included.

http://m.instructables.com/id/BLDC-Motor-Control-with-Arduino-salvaged-HD-motor/?ALLSTEPS

Regards


```
/*
 * BLDC_congroller 3.1.1
 * by David Glaser
 *
 * The 3.x series of programs is for the ST L6234 3-Phase Motor Driver IC
 * 
 * Runs a disk drive motor clockwise
 * With regenerative braking
 * Motor speed and braking is controlled by a single potentiometer
 * Motor position is determined with three Hall-Effect sensors

 * The Arduino receives outputs from 3 hall sensors (pins 2,3,4) 
 * and converts their combination to 6 different commutation steps
 * PWM outputs on pins 9,10,11, at 32 kHz (corresponding to EN 1,2,3 respectively
 * 3 DO on pins 5,6,7 (IN 1,2,3)
 * Analog in 0 is connected to a potentiometer to change the PWM duty and change
 * between motoring and regenerative braking.
  * 0-499: braking
  * 500-523: coasting
  * 524-1023: motoring
  * There are many lines commented out that were used for debugging by
  * printing various values to the serial connection. 
 */
 
int HallState1; //Variables for the three hall sensors (3,2,1)
int HallState2;
int HallState3;
int HallVal = 1; //binary value of all 3 hall sensors

int mSpeed = 0; //speed level of the motor
int bSpeed = 0; //braking level
int throttle = 0; //this variable is used with analog in to measure the position of the throttle potentiometer

void setup() {
  pinMode(2,INPUT);    // Hall 1
  pinMode(3,INPUT);    // Hall 2
  pinMode(4,INPUT);    // Hall 3
  
// Outputs for the L6234 Motor Driver
  pinMode(5,OUTPUT);   // IN 1 
  pinMode(6,OUTPUT);   // IN 2
  pinMode(7,OUTPUT);   // IN 3     
  pinMode(9,OUTPUT);   // EN 1
  pinMode(10,OUTPUT);  // EN 2 
  pinMode(11,OUTPUT);  //  EN 3
   
   
  //Serial.begin(9600); //uncomment this line if you will use the serial connection
  // also uncomment Serial.flush command at end of program.

/* Set PWM frequency on pins 9,10, and 11
// this bit of code comes from 
http://usethearduino.blogspot.com/2008/11/changing-pwm-frequency-on-arduino.html
*/  
  // Set PWM for pins 9,10 to 32 kHz
  //First clear all three prescaler bits:
  int prescalerVal = 0x07; //create a variable called prescalerVal and set it equal to the binary number "00000111"                                                       number "00000111"                                                      number "00000111"
  TCCR1B &= ~prescalerVal; //AND the value in TCCR0B with binary number "11111000"

  //Now set the appropriate prescaler bits:
  int prescalerVal2 = 1; //set prescalerVal equal to binary number "00000001"
  TCCR1B |= prescalerVal2; //OR the value in TCCR0B with binary number "00000001"
  
  // Set PWM for pins 3,11 to 32 kHz (Only pin 11 is used in this program)
  //First clear all three prescaler bits:
  TCCR2B &= ~prescalerVal; //AND the value in TCCR0B with binary number "11111000"

  //Now set the appropriate prescaler bits:
 
  TCCR2B |= prescalerVal2; //OR the value in TCCR0B with binary number "00000001"//First clear all three prescaler bits:
  
}
//MAIN LOOP OF THE PRGROM
void loop(){
  
   //time = millis();
  //prints time since program started
  //Serial.println(time);
  //Serial.print("\n");
  
  throttle = analogRead(0); //value of the throttle potentiometer
  mSpeed = map(throttle, 512, 1023, 0, 255); //motoring is mapped to the top half of potentiometer
  bSpeed = map(throttle, 0, 511, 255, 0);    // regenerative braking on bottom half of pot
  //mSpeed = 100; //used for debugging

  HallState1 = digitalRead(2);  // read input value from Hall 1
  HallState2  = digitalRead(3);  // read input value from Hall 2
  HallState3  = digitalRead(4);  // read input value from Hall 3
  //digitalWrite(8, HallState1);  // LEDs turned on when corresponding sensor is high - originally used for debugging
  //digitalWrite(9, HallState2);
  //digitalWrite(10, HallState3);
   
  HallVal = (HallState1) + (2*HallState2) + (4*HallState3); //Computes the binary value of the 3 Hall sensors

  /*Serial.print("H 1: "); // used for debugging
  Serial.println(HallState1);
  Serial.print("H 2: ");
  Serial.println(HallState2);
  Serial.print("H 3: ");
  Serial.println(HallState3);
  Serial.println(" ");
  */
  
  //Serial.println(mSpeed);   
  //Serial.println(HallVal);   
  //Serial.print("\n");   
  
  // Monitor transistor outputs   
  //delay(1000);   
  /*T1 = digitalRead(2);
  //T1 = ~T1;
  T2 = digitalRead(4);
  //T2 = ~T2;
  T3 = digitalRead(5);
  //T3 = ~T3;
  Serial.print(T1);
  Serial.print("\t");
  Serial.print(T2);
  Serial.print("\t");
  Serial.print(T3);
  Serial.print("\n");
  Serial.print("\n");
  Serial.print(digitalRead(3));
  Serial.print("\t");
  Serial.print(digitalRead(9));
  Serial.print("\t");
  Serial.println(digitalRead(10));
  Serial.print("\n");
  Serial.print("\n");
  //delay(500);
  */

// Commutation for Motoring
// Each binary number has a case that corresponds to different transistors being turned on
// Bit Math is used to change the values of the output
// For tutorial on bitmath with the Arduino: http://www.arduino.cc/playground/Code/BitMath
// PORTD contains the outputs for the IN pins on the L6234 driver
// that determine whether the upper or lower transistor of each phase is used
// The outputs for the EN pins are controlled by the Arduino command analogWrite, which
// sets the duty of the PWM (0 = OFF, 255 = ON or throttle value that is controlled by the potentiometer).

  if (throttle > 511){
      switch (HallVal) 
       {
        case 3:
          //PORTD = B011xxx00;  // Desired Output for pins 0-7 xxx refers to the Hall inputs, which should not be changed
          PORTD  &= B00011111;
          PORTD  |= B01100000;  // 

          analogWrite(9,mSpeed); // PWM on Phase A (High side transistor)
          analogWrite(10,0);  // Phase B off (duty = 0)
          analogWrite(11,255); // Phase C on - duty = 100% (Low side transistor)
          break;
        case 1:
          //PORTD = B001xxx00;  // Desired Output for pins 0-7
          PORTD  &= B00011111;  // 
          PORTD  |= B00100000;  // 

          analogWrite(9,mSpeed); // PWM on Phase A (High side transistor)
          analogWrite(10,255); //Phase B on (Low side transistor)
          analogWrite(11,0); //Phase B off (duty = 0)
          break;
        case 5:
          //PORTD = B101xxx00;  // Desired Output for pins 0-7
          PORTD  &= B00011111;  //
          PORTD  |= B10100000;

          analogWrite(9,0);
          analogWrite(10,255);
          analogWrite(11,mSpeed); 
          break;
        case 4:  
          //PORTD = B100xxx00;  // Desired Output for pins 0-7
          PORTD  &= B00011111;
          PORTD  |= B10000000;  // 

          analogWrite(9,255);
          analogWrite(10,0);
          analogWrite(11,mSpeed);
          break;
        case 6:
        //PORTD = B110xxx00;  // Desired Output for pins 0-7
          PORTD  &= B00011111;
          PORTD = B11000000;  // 

          analogWrite(9,255);
          analogWrite(10,mSpeed);
          analogWrite(11,0);
          break;
        case 2:
          //PORTD = B010xxx00;  // Desired Output for pins 0-7
          PORTD  &= B00011111;
          PORTD  |= B01000000;  // 

          analogWrite(9,0);
          analogWrite(10,mSpeed);
          analogWrite(11,255);
          break;
       }  
     }
     
   // Commutation for Regenerative Braking
   // PORTD (Outputs for IN pins on L6234) pins are always low so only the
   // lower transistors on each phase are used
   // upper transistors are always off during regen. braking.
   else{
          //PORTD = B000xxx00;  // Desired Output for pins 0-7
            PORTD  &= B00011111;
            PORTD  |= B00000000;  //
          switch (HallVal) 
         {
          case 3:
            analogWrite(9,bSpeed);
            //analogWrite(9,0);
            analogWrite(10,0);
            analogWrite(11,0);
            break;
          case 1:
            analogWrite(9,bSpeed);
            analogWrite(10,0);
            analogWrite(11,0);
            break;
          case 5:
            analogWrite(9,0);
            analogWrite(10,0);
            analogWrite(11,bSpeed);
            break;
          case 4:  
            analogWrite(9,0);
            analogWrite(10,0);
            analogWrite(11,bSpeed);
            break;
          case 6:
            analogWrite(9,0);
            analogWrite(10,bSpeed);
            analogWrite(11,0);
          break;
        case 2:
          analogWrite(9,0);
          analogWrite(10,bSpeed);
          analogWrite(11,0);
          break;
       }
   }   
   //time = millis();
  //prints time since program started
  //Serial.println(time);
  //Serial.print("\n");
  //Serial.flush(); //uncomment this if you will use serial port for debugging
}
```


----------



## erdmensch (Sep 18, 2011)

erdmensch said:


> Many many thanks
> now it's working
> 
> https://www.youtube.com/watch?v=R2nZYL7kajQ


Hello,
I now have bluetooth uncommented, now it no longer works.
I can add the code pwm_pwm_15khz?

#if defined(PWM_PWM_CONTROLLER) || defined(PWM_DIR_CONTROLLER) || defined(PWM_SHIELD_CONTROLLER) || defined (L298N_CONTROLLER) || defined(L298N_CONTROLLER)
// bluetooth software serial pins for non-mega boards with PWM controllers
#define SOFT_RX_PIN3	5 // connect to bluetooth module TX pin
#define SOFT_TX_PIN3	6 // connect to bluetooth module RX pin
#else	
// bluetooth software serial pins for non-mega boards with serial controllers
#define SOFT_RX_PIN3	7 // connect to bluetooth module TX pin
#define SOFT_TX_PIN3	8 // connect to bluetooth module RX pin
#endif


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> The wiring i seen on page on that had the roboclaw was for uno not mega.


You are right. There is a limit on the number of attachments per page, so I have now removed one of the zip files and replaced it with the Mega+Roboclaw diagram.


----------



## Ovaltineo (Jul 18, 2013)

erdmensch said:


> Hello,
> I now have bluetooth uncommented, now it no longer works.
> I can add the code pwm_pwm_15khz?
> 
> ...


Are you using a MEGA or UNO? The PWM_PWM_15KHZ_CONTROLLER is designed to work only with a MEGA. You don't need the software serial pins for the Bluetooth module if you have a MEGA.


----------



## erdmensch (Sep 18, 2011)

Ovaltineo said:


> Are you using a MEGA or UNO? The PWM_PWM_15KHZ_CONTROLLER is designed to work only with a MEGA. You don't need the software serial pins for the Bluetooth module if you have a MEGA.


 I use the Mega, but for Bluetooth Uncomment
has he no longer balanced.


----------



## benn (Feb 2, 2016)

Thank you for the wiring of the Mega and Roboclaw Ovl. I see where LB_MB+ and LB_MB- are showing connecting together in the schismatic on the Roboclaw, is this correct? Thank you for your time.

Nevermind i found and printed the user Manuel, it says to connect them so it uses the power from battery's to power up controller. I am excited, it will be here today and hopefully, fingers crossed, i will be up and running by tomorrow.


----------



## Ovaltineo (Jul 18, 2013)

erdmensch said:


> I use the Mega, but for Bluetooth Uncomment
> has he no longer balanced.


Does it work if you use PWM_PWM_CONTROLLER?

Can you post the first page of the Serial monitor output? I want to see if it finds the Bluetooth module.

Can you post a video of what is happening?


----------



## erdmensch (Sep 18, 2011)

Ovaltineo said:


> Does it work if you use PWM_PWM_CONTROLLER?
> 
> Can you post the first page of the Serial monitor output? I want to see if it finds the Bluetooth module.
> 
> Can you post a video of what is happening?


yes it works by using PWM_PWM_CONTROLLER


----------



## benn (Feb 2, 2016)

Ok i need some advise please. I now have the tilt working, backwards (tilt forward but motors run in reverse and one is slower then the other) but working. However i cannot get the steer 6050 sensor to work. I have tripled checked wiring connections and it is like it is not responding. The robo claw status 1 light is flickering and status 2 is staying lit. I have tried it using only one sensor to control both steering and tilt but cannot get the steer to work. I am confused because i had this working before with the 7960's but i believe i have developed a ground loop or picking up noise. I hope i am not being a problem posting and asking to many questions. Does the orange writing below have anything to do with this?


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> Ok i need some advise please. I now have the tilt working, backwards (tilt forward but motors run in reverse and one is slower then the other) but working. However i cannot get the steer 6050 sensor to work. I have tripled checked wiring connections and it is like it is not responding. The robo claw status 1 light is flickering and status 2 is staying lit. I have tried it using only one sensor to control both steering and tilt but cannot get the steer to work. I am confused because i had this working before with the 7960's but i believe i have developed a ground loop or picking up noise. I hope i am not being a problem posting and asking to many questions. Does the orange writing below have anything to do with this?


What OS are you using and what version of the Arduino IDE are you using? No one else has reported these compile errors, but they are valid errors. I think they can be ignored, as long as the compilation continues.

The I2C errors would be caused by incorrect wiring of both 6050 sensors. Or they may both be faulty.

For the motor controller, select ROBOCLAW_CRC_CONTROLLER if ROBOCLAW_CONTROLLER doesn't work.


----------



## benn (Feb 2, 2016)

Ovaltineo said:


> What OS are you using and what version of the Arduino IDE are you using? No one else has reported these compile errors, but they are valid errors. I think they can be ignored, as long as the compilation continues.
> 
> The I2C errors would be caused by incorrect wiring of both 6050 sensors. Or they may both be faulty.
> 
> For the motor controller, select ROBOCLAW_CRC_CONTROLLER if ROBOCLAW_CONTROLLER doesn't work.



I am using 1.6.8 Arduino/windows 7 and selected ROBOCLAW_CRC_CONTROLLER, the other ROBOCLAW_CONTROLLER didnt respond.

The wiring to the both sensor is correct and have checked and replace the steer sensor with three others. Maybe since i changed to the roboclaw i have developed noise or ground loop interfering with the communication. Kind of confused lol, but it is still fun and challenging.


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> I am using 1.6.8 Arduino/windows 7 and selected ROBOCLAW_CRC_CONTROLLER, the other ROBOCLAW_CONTROLLER didnt respond.
> 
> The wiring to the both sensor is correct and have checked and replace the steer sensor with three others. Maybe since i changed to the roboclaw i have developed noise or ground loop interfering with the communication. Kind of confused lol, but it is still fun and challenging.


Strange - I'm using the same OS and IDE version but don't get those errors.

Noise and grouond loops will not be an issue until your motors are running usually under heavy load. Even then, errors will be rare, not continuous like you have. Did you try tilting the steering sensor in all directions? Is AD0 connected to Vcc? Post close up pictures of all connections in the Arduino and the sensors. Also, post a video of what you are doing.


----------



## benn (Feb 2, 2016)

Yes sir, i will get the information uploaded tonight. I just finished my room i was working on. I moved all my gear and computer into it last night. Thank you for your help and will make a detailed video and take some closeups tonight.


----------



## ferchotech (May 29, 2014)

ferchotech said:


> Hello friend Ovaltine's
> 
> Looking at Google I found the following interesting arduino code to handle BLDC motors in handling holl effect sensors and the regenerative voltage is included.
> 
> ...



Hello... Oval


Engine running ARDUINO UNO, BTN 7960

https://youtu.be/mxWeNZI2W1U


----------



## sanja666 (Dec 16, 2014)

Ovaltineo how to limit speed without losing torque ? when the pwm 252 lost resistance and Segway falls .. 20 km.h rate it frightens


----------



## benn (Feb 2, 2016)

Oval i am sorry i haven't posted pictures nor a video yet. I was about to do it yesterday and went over my wiring one more time. I unplugged my steer sensor vcc and it showed power still until ground was disconnected. I think i am going to redo the wiring and only use one sensor 6050. Do i wire it without vcc to ADO and then select x1 steer? Also i my roboclaw is not the HV it is just a 60A and my dc-dc step down is not the isolated one.

Have a great day and thank you for helping with your support.


----------



## Ovaltineo (Jul 18, 2013)

sanja666 said:


> Ovaltineo how to limit speed without losing torque ? when the pwm 252 lost resistance and Segway falls .. 20 km.h rate it frightens


The MAX_MOTOR alarm would have triggered at 80% power - do you have a buzzer? If you ignore it, you can also enable the PUSHBACK option.


----------



## Ovaltineo (Jul 18, 2013)

benn said:


> Oval i am sorry i haven't posted pictures nor a video yet. I was about to do it yesterday and went over my wiring one more time. I unplugged my steer sensor vcc and it showed power still until ground was disconnected. I think i am going to redo the wiring and only use one sensor 6050. Do i wire it without vcc to ADO and then select x1 steer? Also i my roboclaw is not the HV it is just a 60A and my dc-dc step down is not the isolated one.
> 
> Have a great day and thank you for helping with your support.


Yes, connecting AD0 to Vcc is needed only on the 2nd sensor. You don't need it if you select MPU6050_X1_STEERING.

The non-HV Roboclaw is good up to 34V, it is perfectly OK if using 24V batteries. The isolated dc-dc step down and optoisolators are recommended only if you are experiencing EMF noise related issues like intermittent I2C errors under load.


----------



## sanja666 (Dec 16, 2014)

Ovaltineo said:


> The MAX_MOTOR alarm would have triggered at 80% power - do you have a buzzer? If you ignore it, you can also enable the PUSHBACK option.



There is a buzzer there are children  ..

How to set up Pushback?
Something wrong with it.
How Pushback working?
I rewrote Motors.h .. maybe because of this problem?


----------



## Paolo68 (Oct 12, 2015)

Hi,
i have a problem.
My config is Arduino Uno, 2xgyro and Sabertooth.
All seem to work well in the serial monitor but motors running at 24V also if i set MOTOR_MAX=5.
Sabertooth is well configured at 9600 on-off-on-off-on-on
If i move the tilt gyro, the motors running for a very short time at 18V or less, then return to 24V and It does not follow what is written in "left_motor" and "right_motor"
Any idea?
Thanks.

P.S. All parameters in serial monitor work well and "LEFT" and "RIGHT" show exactly what the motor have to do but the output of Sabertooth work between 24 and 18V and never change direction (polarity) even if "LEFT" and "RIGHTt" change sign.
This is the serial signal http://imgur.com/mxDVRoE to S1 of Sabertooth. In S2 there is a switch for Emergency stop but doesn't work...


----------



## Ovaltineo (Jul 18, 2013)

sanja666 said:


> There is a buzzer there are children  ..
> 
> How to set up Pushback?
> Something wrong with it.
> ...


Somebody else wrote the Pushback routine. It works by pushing back further than equilibrium, causing the platform to tilt back and brake. Have a loot at Pushback.h - the settings are explained there. Modify it to suit the changes you made to Motors.h.


----------



## Ovaltineo (Jul 18, 2013)

Paolo68 said:


> Hi,
> i have a problem.
> My config is Arduino Uno, 2xgyro and Sabertooth.
> All seem to work well in the serial monitor but motors running at 24V also if i set MOTOR_MAX=5.
> ...


Your DIP switch doesn't look right. Look at post #223 at page 23. Just ignore the baud rate at 38400, it should be 9600.


----------



## Novo (Apr 24, 2016)

Hello Ovaltine
I hope your still watching this thread once in awhile. Yes very late to the game but thought I would try my hand at a Segway clone build for my Daughter who want's one. 
I picked up on your earlier threads in Mizlplix postings and seized on your last code posting from there. I just found this thread so I haven't had time to look for updates to your code as yet. 
Like most amateurs, I purchased my components before I researched proven code like yours. I don't see a need to reinvent the wheel, much smarter people like your self out there. 
I Purchased;
1 X Arduino Mega 2560 R3
2 X MPU-5060
2 X 12vdc 12ah Batteries
2 X 300w 24 volt motors
2 X E300 Scooter rear drive Tires, chains and sprockets
1 X 12vdc cooling Fan
1 X Lm7805 "step down voltage for Arduino"
1 X Power switch
1 X Dual motor driver board "Link to driver board below, I know your very familiar with other components above"

http://www.ebay.com/itm/3-36V-10A-P...662854?hash=item3a857cf806:g:kJ8AAOxyYTRSaKbr

I loaded and compiled the last code you posted under Mizlplix"s thread and "Full disclosure" I'm better at following along with code then writing it. I understand the basic's and see there's a problem for me based on the motor driver board I purchased. My board's description is some what hard to follow but it appears the Direction pins are looking for "I assume a HIGH/LOW input and the speed looks like straight forward PWM. 
Your code is setup for direction based on four pins "2" "3" "5" and "6". 
Is it possible for you to take a look at the link above and see if you concur with my conclusion about the HIGH/LOW input for Direction? If that's correct, then it should be a fairly easy for me to change code to correct for Direction. If you see a problem with anything I purchased or any other problems with the driver board Please don't hesitate to speak your mind. 
I wouldn't mind hearing about any improvements you've made along the way either. 
Thank you in advance. Hope your still listening.


----------



## Ovaltineo (Jul 18, 2013)

Novo said:


> Hello Ovaltine
> I hope your still watching this thread once in awhile. Yes very late to the game but thought I would try my hand at a Segway clone build for my Daughter who want's one.
> I picked up on your earlier threads in Mizlplix postings and seized on your last code posting from there. I just found this thread so I haven't had time to look for updates to your code as yet.
> Like most amateurs, I purchased my components before I researched proven code like yours. I don't see a need to reinvent the wheel, much smarter people like your self out there.
> ...


Look at post #1 of this thread. You will see where to get the latest code and schematics. You'll want to use the PWM_DIR_CONTROLLER.


----------



## Novo (Apr 24, 2016)

You are awesome!! 
Thank you for replying. 
Grabbed your updates from Github and getting started on matching code to my equipment. Love all the addons, very nice job! 
Thank you for posting, I know it's allot of work. 
People like my self really appreciate your hard work!


----------



## Novo (Apr 24, 2016)

Hello again Ovaltine
You may have a wiring schematic posted some where but I haven't come across it as yet. 
My question is about the two MPU6050's. I'm assuming you have them hooked up to the two separate SDA/SCL pins on either end of the Mega and the ADO's on each of the MPU6050's hooked up with one to Gnd and one to 5 / 3.3v to get the 0x68 and 0x69 addresses? 
Thanks


----------



## Novo (Apr 24, 2016)

Never mind Ovaltine  Uh Duh 
I'm having trouble staying logged in so I couldn't see the wiring diagrams you posted. 
Every time I change pages or look at an attachment I have to log in again to the forum. Must be something wrong with my settings. 
Keeps me from seeing pic's and doc's unless I log in every time.


----------



## Novo (Apr 24, 2016)

Hello Ovaltine

I actually have a legitimate question this time. 
I wrote a little test sketch for the motors because I was getting motor movement when I shouldn't be in your sketch. 
I wanted to verify the Motor board was working as expected with out any other influence. 
Just as in your wiring diagram, I left the "logic" ground off on your sketch and mine. When the Dir pin called for HIGH the motors work perfectly, however when the Dir pin called for LOW, Both motors turned on and it ran the motors up erratic.
Once I connected the Logic ground it ran as expected. 
I know you have a reason for leaving the logic ground off but is there away around this or will damage ensue to the Board or my Body? 
. 
The test Sketch is below:
int motor1 = 9;
int motor1dir = 10;
int motor2 = 11;
int motor2dir = 12;
void setup() {
pinMode(motor1, OUTPUT);
pinMode(motor1dir, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(motor2dir, OUTPUT);
digitalWrite (motor1dir, LOW);
digitalWrite (motor2dir, LOW);
analogWrite (motor1, 0);
analogWrite (motor2, 0);

}
void loop() {
digitalWrite (motor1dir, HIGH);
digitalWrite (motor2dir, HIGH);
for (int motor1Value = 0 ; motor1Value <= 252; motor1Value += 5) {
analogWrite(motor1, motor1Value);
delay(300);
}
for (int motor1Value = 252 ; motor1Value >= 0; motor1Value -= 5) {
analogWrite(motor1, motor1Value);
delay(300);
}
for (int motor2Value = 0 ; motor2Value <= 252; motor2Value += 5) {
analogWrite(motor2, motor2Value);
delay(300);
}
for (int motor2Value = 252 ; motor2Value >= 0; motor2Value -= 5) {
analogWrite(motor2, motor2Value);
delay(300);
}
digitalWrite (motor1dir, LOW);
digitalWrite (motor2dir, LOW);
for (int motor1Value = 0 ; motor1Value <= 252; motor1Value += 5) {
analogWrite(motor1, motor1Value);
delay(300);
}
for (int motor1Value = 252 ; motor1Value >= 0; motor1Value -= 5) {
analogWrite(motor1, motor1Value);
delay(300);
}
for (int motor2Value = 0 ; motor2Value <= 252; motor2Value += 5) {
analogWrite(motor2, motor2Value);
delay(300);
}
for (int motor2Value = 252 ; motor2Value >= 0; motor2Value -= 5) {
analogWrite(motor2, motor2Value);
delay(300);
}
}


----------



## Ovaltineo (Jul 18, 2013)

I'm trying to avoid a ground loop, but it's not required if you are not getting glitches. It is possible that your controller has isolated logic ground (e.g. optoisolated) in which case, you really must connect the logic ground.


----------



## Paolo68 (Oct 12, 2015)

Ovaltineo said:


> Your DIP switch doesn't look right. Look at post #223 at page 23. Just ignore the baud rate at 38400, it should be 9600.


Thank you very much, it works now.
That 38400 draws me in error...


----------



## Novo (Apr 24, 2016)

Hello *Ovaltine

*Thank you for the response. 
After preforming a few test on my motor driver board I saw some funky responses "or lack there of" that lead me to take a closer look at what I purchased. When I claimed it ran perfect before that's true except it was at much lower voltages/AMP's and motor size. I tested it this time with the actual one's I'm going to use @ 24vdc. 
The board claims a 10A standard run amps and 30A peak. That's under rated for what were trying to achieve so I scraped this board and purchased two of your original BTN7960's. 
Should be here in a few days and should also make this go allot soother. 
Based on your drawings I will be omitting the ground to the controller board since you seem to have no problems doing so. 
Let you know how it goes in a few days. 
Thanks again.


----------



## Novo (Apr 24, 2016)

Hello Ovaltine 

I'm at the point of testing the motors direction, speed, tilt forward/backward and steering. 
To start with I tested the pwm output from the Mega on pins 7, 6, 5, 3, and 2 using leds on each output. 
Pin 7 was constant High state and 6,5,3,2 worked great when moving the MPU6050 board for tilt. 
You could even see the MPU6050 for steering was making the led brighter or lower depending on the turn angle. 
So I'm certain were getting pwm output.

I then hooked up the pwm pins, enable pins and 5vdc pin to the two BTN7960's boards.
The Battery's voltage to both BTN7960's is 25.7vdc. 

I turned on the power from battery's to BTN's and put 12vdc to the Mega.
I'm getting no output to the motors when moving the MPU's and yet I know were getting all the pwm outputs from the mega. 
I have one concern about the BTN7960 board hookup. There is no real documentation that comes with the boards although there pretty straight forward. 

My concern is the nomenclature to the left of the 8 header pins reads right to left, VCC/GND.....R-is/L-is.....R-en/L-en.....Rpwm/Lpwn 
Does the 8 header pins also relate to the nomenclature left to right?? 
I started thinking maybe its not right to left and I have them wrong.
Also are all the enable pins suppose to be HIGH all the time?? 

Those are the only things I can think of that might be wrong. bought both boards on ebay but I cant imagine both would be bad. 

I've attached a few pic's of the lay out so far and one of the BTN7960 so you can see the nomenclature I'm referring to. 

If you wonder what the orange things are attached to the wheels. I scraped the scooter wheels "way too small" and purchased 13" wheels from Harbor Freight. I needed a way to attach the sprockets I already had to the new wheels, so I designed and 3D Printed my own drive hubs. Surprisingly they are very strong.

Thanks in advance


----------



## Novo (Apr 24, 2016)

Well I think I found my answer to the pins on the BTN7960. 
I attached the schematic I found to this board. 
It shows the pin attachments and pin numbers for them, so yes it reads right to left. 
I have it hooked up correctly and yes I see now enable needs a HIGH output in-order to stay on. 
So I have no idea at the moment why I can't get the motors to move. 
If you have any other suggestions please let me know. 
Thanks


----------



## Bastien (May 23, 2014)

*Powerful Motor & Controller*

Hi Oval,

I've built a 24v brushed 500w Segway and it works a treat but lacks the power of the real thing. 

I'd like to try and build a more powerful version but I'm struggling to find a controller that will do the trick. 

I was thinking of using this controller 

and this motor 

Will this work or can you see any issues? Or would you have a better recommendation for motor & controller to match the 2.2hp motors on the segways. 

Kind Regards and thank you for your amazing work!!!


----------



## Ovaltineo (Jul 18, 2013)

Novo said:


> Well I think I found my answer to the pins on the BTN7960.
> I attached the schematic I found to this board.
> It shows the pin attachments and pin numbers for them, so yes it reads right to left.
> I have it hooked up correctly and yes I see now enable needs a HIGH output in-order to stay on.
> ...


Where did you tap the ground and 12V for the Arduino? The BTN motor supply and the Arduino must have a common ground. It is possible that you've tapped the Arduino ground and 12V from the wrong battery.


----------



## Ovaltineo (Jul 18, 2013)

*Re: Powerful Motor & Controller*



Bastien said:


> Hi Oval,
> 
> I've built a 24v brushed 500w Segway and it works a treat but lacks the power of the real thing.
> 
> ...


That controller won't work. Get a Roboclaw HV 2X60A http://www.ionmc.com/RoboClaw-HV-2x60A-60VDC-Motor-Controller_p_12.html. That motor looks OK.


----------



## Novo (Apr 24, 2016)

Hello Oval

Not sure how I missed your last reply. Sorry I Didn't responded. 
I did find my last problem "I was sold two bad BTN7960's" 
Couldn't believe they were both bad till I found a schematic of the board and checked the I/O of each component.
Turns out both boards had a bad SN74AHC244 chip. 
I figure they where returns the seller tried to pass on to me.

Anyways I have two working BTN7960's now. I tested them on the bench with isolated power supply's using your actual sketch and they worked perfect. 

I installed all the components in the Clone's box with the only difference of course being two Sealed 12vdc 12mha battery's as power supply for everything.
My setup looks exactly like the schematic you drew using the Mega and BTN's with the exception of BT and TC74 I don,t have. 

I created a step down power supply using a L7812cv and two 0.1uf caps across input and output of 7812 to ground. I'm getting 12.03vdc out and using this to supply Arduino and a CPU case fan that runs all the time to keep the BTN's cool.

Not sure why I thought it would be a good idea, but I put a switch on the 24vdc supply and 12vdc. "One switch could have done the job" 

After everything was installed, I turned on the 24v switch "not 12v yet" and noticed the Arduino lit up but CPU fan did not. 
I then turned on the 12v switch and the CPU fan came on, after a few seconds the Arduino went off, fan continued to run. 
I shut everything off and felt around on the components for heat. 
The 7812 burnt my fingers it was so hot and the two control chips SN74AHC244 on the BTN's were very warm. 

Total time on was only 6 seconds or so. 
The built in 5vdc circuit on Arduino is burnt up and best I can tell everything else survived. 
Even the 7812 which was super hot survived. 

I didn't have the logic ground hooked up to the BTN's But of course the 24v ground is hooked up to the Arduino via the 7812 supply. 
So the Arduino found a power source through the BTN's or resistor divider. 
The MPU's, Battery LED's and buzzer only get power from the Arduino so they can't be the source.
Do you think the 12v switch is causing the problem? Every thing is wired exactly like your schematic other than the switch.
LOL just afraid of burning up a bunch of Arduino's before I locate the problem. 
Let me know if you need some other info.


----------



## Ovaltineo (Jul 18, 2013)

Novo said:


> Hello Oval
> 
> Not sure how I missed your last reply. Sorry I Didn't responded.
> I did find my last problem "I was sold two bad BTN7960's"
> ...


I don't know how you got power in the Arduino with the 12V switched off. My guess is that there is a wiring mistake. Posting photos of the wiring at key points will be helpful. 
I wouldn't recommend a passive regulator like 7812 to drop the voltage from 24V to 12V -- you are doubling the power draw to produce heat. You can get a cheap switching regulator for under $5. Or just tap the 12V from the first battery. You may want to tap the fan's ground and 12V from the 2nd battery to balance the load.


----------



## Novo (Apr 24, 2016)

*Hello again Ovaltine

Sorry for the slow reply's. 
I've had to work at this casually for weeks now "to many other obligations getting in the way. 
I really don't know what I might have wired incorrectly but the damage was to all of the 5vdc logic. 
Ive replaced the entire Mega board, the I/O logic chips on both BTN,s and the steering MPU was damaged.

I've reconnected everything and trying to test it on the bench before I reinstall back in the segway clone. 

I'm getting an error I've never seen before and can find a reference to it. 
When opening the Serial monitor it reads as follows: 
WHO AM I : 68 error = 0
PWR MGMT 2 : error = 0
*
*WHO AM I : 0 error = -32
PWR MGMT 0 : error = -32
I2C error = -32
**I2C error = -32
**I2C error = -32
**I2C error = -32
**I2C error = -32
**I2C error = -32
ACCEL: 31.17 GYRO: 0.00 BOARD ANGLE: -2.93 STEER ANGLE: -22.12 MOTOR: -23.02 LEFT: 54 RIGHT: -100 VOLTAGE: 0.00 TEMP: 0 CURRENT1: 0 CURRENT2: 0
**I2C error = -32
**I2C error = -32
**I2C error = -32

It appears the Steering MPU is still not working but I completely replaced it. 
Is that what the error means that it cant find/see the steering MPU?

Thanks again 

*


----------



## Ovaltineo (Jul 18, 2013)

Novo said:


> *Hello again Ovaltine
> 
> Sorry for the slow reply's.
> I've had to work at this casually for weeks now "to many other obligations getting in the way.
> ...


Yes, something is faulty with the steering MPU. Swap it with the board MPU to see if it is the MPU or wiring that's incorrect.


----------



## Novo (Apr 24, 2016)

LOL What a disaster.

Somehow the steering spring managed to cut just one wire to the steering MPU and the wire jacket held on just enough I couldn't detect it. 
Thank you for confirming it was the MPU. 
Ok fixing that problem and testing this afternoon. I will report back if all is ok and show a wiring diagram before firing it up in the seg clone. 

Thanks again


----------



## Verial (Sep 2, 2015)

please correct the wiring diagram brushless motors.

this is one phase of the motor


----------



## shartgen (Mar 23, 2016)

i burned both of my BTN driver last week, so i decided to buy a Sabertooth(2x32A) dual driver.
first tests with breadboard were pretty good. since the day i soldered everything up it doesn't work anymore and i can't figure out whats wrong.
even on the ground, feels like the sabertooth isn responding at all. the green LED is blinking non stop.

heres the monitor output and pictures
https://www.dropbox.com/s/i5e3tmkezsugbwa/Output Seg.pdf?dl=0


would be great if anyone can help me out 

steffen


----------



## balldacan (Jun 21, 2016)

Hello friends!
congratulations on this great forum and the segway clone project!
I want to join

Thanks from Italy


----------



## shartgen (Mar 23, 2016)

hi there, i got everything working now (movement, bluetooth, voltage check/led, tftBATTERIE). 

the only problem is, it feels like my clone doesn't have enough torque to move with a rider on it.
2x MY1016B4M6 350W DC 24V Motors
Sabertooth 2x32A Dual
2x Rotek 12V 20Ah AGM Batterie
does anyone know how to fix this? 


a video of my clone 
https://youtu.be/oWdzmK--UAY


----------



## ghirotre (Nov 14, 2014)

Hi,
But what is it your gear?
With the same motor i have to need 1:15 gear.
You need gear for max speed around 15km/h
The gear change if you change the wheel


----------



## shartgen (Mar 23, 2016)

Hi
It's 10 to 24teeth (1:2,4?), wheel diameter is 380mm.


----------



## ghirotre (Nov 14, 2014)

The motor have 2750rpm so you reduce of 2.4.
2750:2.4 = 1145rpm at wheel
Your wheel diameter is 380mm so you circonference is 380*3.141=1193mm
So your max speed is 1193*1145=1.365.985mm/m
mm/m to km/h = 1.365.985/1.000.000 * 60 = 81 km/h
It is impossibile you have a right torque.
To go at max speed at 15.5km/h you need 216rpm at wheel so 2750/216=12.7gear
You need to reduce about 12.7.
You tell me that the diameter is 380mm but i mean the outside diameter, all the calculations it is with 380mm outside diameter


----------



## shartgen (Mar 23, 2016)

it is the outside diameter of each wheel. well, didn't thought about the right gear before. gonna order some new sprockets (1:9,85) for 20km/h max


where did u get your sprockets?
thanks a lot


----------



## ghirotre (Nov 14, 2014)

I think only 9.85 is not good, you need almost 11.
I draw and laser cut my sprocket.
I have a gear 1:15 . To make this gear a i have to do a 2° reduction

This is my first segway clone, now i have made 4 segway clone

https://www.youtube.com/watch?v=ve8_84l-Ygc


----------



## Ovaltineo (Jul 18, 2013)

Hi Shartgen,

Yes, listen to ghirotre. Anyone who cuts his own gear knows what he's talking about . I have 2X500w motors and gear them to max 15km/h in order to climb the steep hill I live in. You will end up burning the brushes on your motors, or your Sabertooth if you gear it at 20km/h or higher.


----------



## JMD (Sep 7, 2016)

Hey Ovaltine,

I've decide to attempt a one wheeled version of your segway clone. unfortunatly I am having issues with getting any voltage out from the motor controller. Here is what i'm using: Ardunio Nano, BTN7960, MPU6050 and 36v from two lipos. The serial monitor is reading fine and i have checked continuity of all my wires and there are not issues there. do you have any ideas as to why this is happening?

Cheers,

JMD


----------



## sudhakar_yg (Sep 15, 2016)

Hi Ovaltine,
Appreciate your effort in sharing the detailed info on building segway clone along with source code.

I am trying to build a mini model of same using MultiWii SE board (Atmega328 + MPU6050 +HMC5883L + BMP085 + FTDI) with L298N motor driver.

I have checkedout Ver 7.8 code from https://github.com/ovaltineo/SegwayClone

As per readme, I uncommented the L298N motor driver in SegwayClone.h file & tried to compile the code. But getting error " exit status 1 - redefinition of 'void initMotors()'" in Motors.ino file.

I tried changing the motor driver to others listed (Sabertooth, Roboclaw) in SegwayClone.h & also tried with other Arduino boards, but still getting same error. 

While I comment all the motor drivers & compile, I am able to compile successfully.

Just wanted to understand if anybody else been getting same error while compiling, Am I doing anything wrong while compliling? Are there any fixes available for same.

Thanks in advance!

Cheers
Sudhakar


----------



## fiatromeo (Dec 29, 2013)

Hello friends! Ovaltineo thanks again for the project.https://www.youtube.com/watch?v=OFN2Hlz78J4


----------



## Ovaltineo (Jul 18, 2013)

JMD said:


> Hey Ovaltine,
> 
> I've decide to attempt a one wheeled version of your segway clone. unfortunatly I am having issues with getting any voltage out from the motor controller. Here is what i'm using: Ardunio Nano, BTN7960, MPU6050 and 36v from two lipos. The serial monitor is reading fine and i have checked continuity of all my wires and there are not issues there. do you have any ideas as to why this is happening?
> 
> ...


Ah, it's been a while since I checked this forum. Do you have common ground between the Arduino and the BTN7960?


----------



## Ovaltineo (Jul 18, 2013)

sudhakar_yg said:


> Hi Ovaltine,
> Appreciate your effort in sharing the detailed info on building segway clone along with source code.
> 
> I am trying to build a mini model of same using MultiWii SE board (Atmega328 + MPU6050 +HMC5883L + BMP085 + FTDI) with L298N motor driver.
> ...


You must comment out #define PWM_PWM_CONTROLLER before uncommenting another controller.


----------



## Ovaltineo (Jul 18, 2013)

fiatromeo said:


> Hello friends! Ovaltineo thanks again for the project.https://www.youtube.com/watch?v=OFN2Hlz78J4


This is the best looking mono-wheel implementation that I've seen!  I've seen your other post with pics in it, but they don't show the gear/motor setup. Would you mind posting close-up pics of how the motor drives the wheel? Can you do sharp turns with this or just big radius turns?


----------



## fiatromeo (Dec 29, 2013)

Thank you for the appreciation .Radius turns of 1.5-2 meters.
https://www.youtube.com/watch?v=XMoEn9x_VuM


----------



## Ovaltineo (Jul 18, 2013)

That is an ultra cool work of art!


----------



## fiatromeo (Dec 29, 2013)

https://www.youtube.com/watch?v=XMoEn9x_VuM


----------



## wiroon (Nov 24, 2016)

Ovaltineo said:


> The BTN7960 is a "brushed" motor controller - it cannot be used to drive a BLDC motor. If you can find an affordable high-power BLDC controller with a serial or PWM interface, then I might consider writing code for it.


Hi OT, this is my first time here. What are yr opinions on these:

A. 300W_MOTOR CONTROL_SS08
http://uk.rs-online.com/web/p/processor-microcontroller-development-kits/9106867/

B. DC 12-36V 20A 500W Brushless Motor Controller Motor Balanced Car Driver Board
http://www.ebay.com/itm/DC-12-36V-2...342532?hash=item36018e6284:g:aa4AAOSwDV1XQ9AH

C. 12V 24v 30A brushless DC motor controller power high current motor driver board
http://www.ebay.com/itm/12V-24v-30A...464294?hash=item1eae403ca6:g:iPsAAOSwjwlXA42P

THKS for yr time.
WIROON


----------



## wiroon (Nov 24, 2016)

Ovaltineo, I am sorry if my question has offended you in anyway. I am HIGHLY respect your contribution to this society and believes all folks agreed with me. I quoted your respond as per [email protected] because unless there is a suitable controller and my question is purely “your opinions” on the controller, NOT asking you to write any code which I am sure you are highly capable of. To get start with a controller blindly without reasoning its appropriateness is simply an insane.

And I wish to apologise to all of you if my question has frozen the dynamic of this society.


----------



## gui (Feb 11, 2016)

hi everyone been follow this a long time , read a few times all the pages and today i decide to build my prototype.

here the first test : https://youtu.be/RHpuOcsCGfw

using 2 x 750w 36v dc brushed motors
11 and 74 sprockets with chain
arduino mega
100 amp h bridge ( works like l298)
18,2 v 12amps lipo battery

still under developement but i couldnt do it without OVALTINEO tutorial.

many thanks from portugal


----------



## gui (Feb 11, 2016)

sup guys , i notice the tread is almost dead and is a lame cause there are plenty of persons who only could build this clone segway thanks to this tread and specialy to ovaltineo.

btw i wonder if really worth using encoders in termac? i wish i could use with l298 h-bridge.

thanks


----------



## gui (Feb 11, 2016)

hi , is there someone who can help me to reduce the motors buzz? is a bit loud and annoying! im using the 100amps h-bridge from china and works like a l298n but it supports max 65khz so is there a way to be more eficient cause i dont think the motors will like the low pmw frequency. btw i use mega also.

come on guys , lets keep this thread alive

thanks


----------



## JRoque (Mar 9, 2010)

gui said:


> hi , is there someone who can help me to reduce the motors buzz?


Hi there. I've been away far too long and I'm no longer qualified to help anyone but let me shoot in the dark:

1- Do you have a scope or frequency counter that can measure the Atmel chip PWM output?

2- 65kHz is way too high, IMHO. If the Atmel driver is fine, see if the motor provides it's own PWM clock and cut it to ~25kHz.

3- Did you make any modifications to the firmware that would cause the PWM frequency to change? 

4- Did you select the right options for Atmel chip and motor driver?

5- Any options, switches, etc on the motor controller itself that would be related to this?

6- On the first page of this thread, there's a reference: "Fixed L298N motor controller code by removing "setPwmFrequency(HZ_3906)" during initialization." that seems to be what you're looking for.

Regards,
JR


----------



## gui (Feb 11, 2016)

hi JR thanks for replay but after so long i decided to buy a roboclaw 2x60a , not the hv cause wasnt avaiable in europe!

im building a weelchair segway just like rajan cause there arent so many diy of that for disabled persons , im not the case.

best regards


----------



## remzibi (Mar 8, 2016)

remzibi said:


> Hello all, my first post, so Hello to everyone.
> Well, so nice thread, I just(today) build an small balancing bot, it took me literally one afternoon, using some used and not used PCBs as support/construction chasse.
> One MPU6050 module, one module L298 for motors, two motors for RC car with gear box and quite big backlash. Parts I got very chip few time ago for possible other usage, so fortunate I had a full set.
> Software configuration was just for one 6050, no pot, no others. Pushback on.
> ...


----------



## remzibi (Mar 8, 2016)

Finally I finished my device, made for learning.
https://www.youtube.com/watch?v=W-VJjBsHrPQ





This is a first one, soon will be next one - much better.


----------



## piotrek5301 (Sep 18, 2017)

Hi!

I am also trying to build my own Segway clone and I have a few questions. Is a BTS7960 motor controller suitable for 500W 24V motor? Or should I consider something different. The second question is: can I put a SoftPWM library into Ovaltine's code to reduce motor inrush current?


----------



## freetones (Sep 21, 2017)

That's awesome!


----------



## bobbieatendido (Jun 30, 2015)

Hi, i tried to make this project way back 2015 and failed. i'd like to try again.
Im copying UNO_BTN7960_2XMPU6050_Bluetooth.png but with 1 motor only.
trying to make it a unicycle using this guide:

https://www.instructables.com/id/Electric-unicycle-Arduino-DIY/

I'll try the comment:

Segwayclone.ino file. Then you will get a lot of windows. Under segwayclone.h start by calibrate.
/*
Uncomment one MODE below
*/

//#define MODE_CALIBRATE
//#define MODE_RUN

And you have to use:

#define MPU6050_X1_STEERING
#define PWM_PWM_CONTROLLER

hopefully i can make it work!
i dont know if this thread will still be active but hopefully there are people still able to help out!

thanks!!


----------



## ghirotre (Nov 14, 2014)

Hi Oveltineo,
You can post or send me a suorce for the app?
Because i want to use with my new phone (note 8) and it don't work.
The app start normally and connect to segway clone and then stop working.
Thanks


----------



## segway (Jul 24, 2018)

Hi Ovaltine,
Are you still around?
ElectricPolo


----------



## andreafanaci (Nov 12, 2019)

Hello Ovaltine. I would like to know how to connect the wtv020 in arduino mega.
thank you
Andre
Sao Paulo
BRAZIL


----------

