Hi everyone, I hope this is the correct place to post this?I'm sorry if it isnt i will delete if needed.
So my daughters power wheels controller went out and i had motor controller sitting for a rc mower project. Anyways thought i'd try my hand at an arduino as a controller. Got someone on fivver to do some code for me as im not any good at it yet. i got everything wired up to spec 13.07v from battery, sabertooth 2x60 seems to be working order no error lights, but when i power up system my switch for fwd,ntl,rvs, changes the speeds? and the motor constantly runs without pedel being pushed. I will post code if anyone can give me advice it would be appreciated.Use code tags to format code for the forum
#include <SoftwareSerial.h>
#include <SabertoothSimplified.h>
SoftwareSerial SWSerial(NOT_A_PIN, 11); // RX on no pin (unused), TX on pin 11 (to S1).
SabertoothSimplified ST(SWSerial); // Use SWSerial as the serial port.
const int forward_pin=3;
const int backward_pin=2;
void setup()
{
SWSerial.begin(9600);
pinMode(forward_pin,INPUT_PULLUP);
pinMode(backward_pin,INPUT_PULLUP);
}
void loop()
{
int Speed=analogRead(A0);
int F=digitalRead(forward_pin);
int B=digitalRead(backward_pin);
int dir=0;
int power=0;
if (F==0 && B==1)
{
dir=1;
power=map(Speed,0,1023,64,127);
ST.motor(1, power);
delay(20);
power=power+128;
ST.motor(1, power);
delay(20);
}
else if (F==1 && B==0)
{
dir=2;
power=map(Speed,0,1023,1,64);
ST.motor(1, power);
delay(20);
power=power+128;
ST.motor(1, power);
delay(20);
}
else if (F==1 && B==1)
{
dir=0;
ST.motor(1, 64);
delay(20);
ST.motor(1, 192);
delay(20);
ST.motor(1, 0);
delay(20);
}
//1 is full reverse, 64 is stop and 127 is full forward.
//128 is full reverse, 192 is stop and 255 is full forward.
}
maybe thats my problem,sabertooth said i could power arduino off the 5v of motor controller to
vin arduino, while i use the 5v on arduino to operate pedal.but now that you said that if i need 5v for pedal...how is arduino being powered?proly underpowered?
roger that, so im thinking then i need a dedicated 5v power source for arduino and i can then use the 5v of sabertooth to complete the pedal system? does sound correct? since vin is "in" power only not a output like 5v correct?
If the controller has a 5v output pin, this can be used to power the UNO 5v pin; just avoid plugging a PC USB cable into the UNO when the controller is connected to the UNO 5v pin.
i can do that. I have no need for usb in this project. so the problem most likely lies in my code then,or the pedal i have is faulty and not sending right signals.
Always comment your lines of code with good descriptions.
Does this example work ?
// Software Serial Sample
// Copyright (c) 2012 Dimension Engineering LLC
// See license.txt for license details.
#include <SoftwareSerial.h>
#include <SabertoothSimplified.h>
SoftwareSerial SWSerial(NOT_A_PIN, 11); // RX on no pin (unused), TX on pin 11 (to S1).
SabertoothSimplified ST(SWSerial); // Use SWSerial as the serial port.
void setup()
{
SWSerial.begin(9600);
}
void loop()
{
int power;
// Ramp from -127 to 127 (full reverse to full forward), waiting 20 ms (1/50th of a second) per value.
for (power = -127; power <= 127; power ++)
{
ST.motor(1, power);
delay(20);
}
// Now go back the way we came.
for (power = 127; power >= -127; power --)
{
ST.motor(1, power);
delay(20);
}
}
I haven't analysed the schematic of an arduino Uno. From ESP8266 / ESP32 it is very common that between USB-5V and Vin there is a protection schottky-diode (voltage-drop across diode 0,2V) to stop current flowing from Vin into USB.
And the Arduino does not have such a protection-diode?
If not you could add one externally.
It is a known example that should move the motor back and forth.
We often use a basic sketch (that has been proven to work in the past) which confirms our hardware is properly connected; if the sketch works, we can conclude our wiring is okay.
This example can be compared to a sketch that doesn’t work to help us find programming problems.
We can modify this basic sketch, a bit at a time, which hopefully prevents errors in our code generation.
this is a video i sent to my fiverr guy,hes not really helpful honestly,might pay someone on here to redo code if need be.but this is the problems i am having.