I think you meant…
“To be sure, to be sure” - with an Irish accent.
I shall do exactly that on the morrow. Everything is happening out in the shed and it is damn cold out there right now.
According to the video, val1 seems to track left and right movement nicely. Val2, for forward and back, not so much, although curiously, it seems ok at the neutral position.
Given that val1 seems to influence val2, it could be a wiring issue or perhaps the joystick is faulty. Do you have another one to test?
Hi,
Forward and Back produce no changes.
Left and right change both val1 and val2.
Almost as though only val1 is connected and val2 is adc delay.
Thta is why on my last code I got the program to read twice each channel.
@doonie, do the values change when you move fwd/back, which ones?
When you move left/right what values move.
This is with the latest code in post #31.
Tom...
![]()
It seemed to me that val1 was giving plausible values for left and right in the video based on what @doonie was explaining he was doing. ~512 in the middle and variation between close to zero one way and close to 1023 for the other.
Val2 by contrast, had no pattern I could make sense of.
Ao neutral = 2.5v
Fwd = 4.99
Bwd = 5.4
Left = 2.5
Right = 2.5
A1 neutral = 2.5v
Fwd = 2.5
Bwd = 2.5
Left = 5.4
Right = 5.0
It reads as follows
Setup complete
without moving the joystick I get
Joystick1 value 510 Joystick2 value 460
Just watching to see what happens,
JS1 remains constant JS2 slowly reducing by 1 digit
Fwd returns no change to either
Bwd returns no change to either
Left returns 0 and 76-77
Right returns 1023 and 915-917
Hi, thanks mate
You should have something like this.
Ao neutral = 2.5v
Fwd = 4.99
Bwd = 0.0
Left = 2.5
Right = 2.5
A1 neutral = 2.5v
Fwd = 2.5
Bwd = 2.5
Left = 5.4
Right = 0.0
Your sweeps on each appropriate channel should be approx 0.0 to 5.0V.
The 2.5 central for both is correct.
The fact that neither signal goes to 0.0V, makes me think you do not have a gnd connection to the joystick.
Tom...
![]()
But he is using an UNO
All seems so retro
Naturally, I checked and there was an earth issue but not the joystick. The main earth on L298n where it earths the 7.4 battery and also connects to gnd on the Arduno had broken so I fixed it. Also minutely checked as much as possible and found that pins IN1 and IN2 were wrong so I corrected that. Unfortunately made no differences. I have a second joystick so I swapped it over, no difference.
What should I be using?
Ever the optimist, I found this
and this
sketch_sep22b.ino (2.9 KB)
I altered the wiring to suit and tested the sketch but it fails and says I have a stray#
Hi,
The proplem is all the line numbers have been copied over into to sketch, the compiler does not like it.
Where did you get the code from?
Found it, try this
/* Arduino DC Motor Control - PWM | H-Bridge | L298N
Example 02 - Arduino Robot Car Control
by Dejan Nedelkovski, www.HowToMechatronics.com
*/
#define enA 9
#define in1 4
#define in2 5
#define enB 10
#define in3 6
#define in4 7
int motorSpeedA = 0;
int motorSpeedB = 0;
void setup() {
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop() {
int xAxis = analogRead(A0); // Read Joysticks X-axis
int yAxis = analogRead(A1); // Read Joysticks Y-axis
// Y-axis used for forward and backward control
if (yAxis < 470) {
// Set Motor A backward
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// Set Motor B backward
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Convert the declining Y-axis readings for going backward from 470 to 0 into 0 to 255 value for the PWM signal for increasing the motor speed
motorSpeedA = map(yAxis, 470, 0, 0, 255);
motorSpeedB = map(yAxis, 470, 0, 0, 255);
}
else if (yAxis > 550) {
// Set Motor A forward
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
// Set Motor B forward
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
// Convert the increasing Y-axis readings for going forward from 550 to 1023 into 0 to 255 value for the PWM signal for increasing the motor speed
motorSpeedA = map(yAxis, 550, 1023, 0, 255);
motorSpeedB = map(yAxis, 550, 1023, 0, 255);
}
// If joystick stays in middle the motors are not moving
else {
motorSpeedA = 0;
motorSpeedB = 0;
}
// X-axis used for left and right control
if (xAxis < 470) {
// Convert the declining X-axis readings from 470 to 0 into increasing 0 to 255 value
int xMapped = map(xAxis, 470, 0, 0, 255);
// Move to left - decrease left motor speed, increase right motor speed
motorSpeedA = motorSpeedA - xMapped;
motorSpeedB = motorSpeedB + xMapped;
// Confine the range from 0 to 255
if (motorSpeedA < 0) {
motorSpeedA = 0;
}
if (motorSpeedB > 255) {
motorSpeedB = 255;
}
}
if (xAxis > 550) {
// Convert the increasing X-axis readings from 550 to 1023 into 0 to 255 value
int xMapped = map(xAxis, 550, 1023, 0, 255);
// Move right - decrease right motor speed, increase left motor speed
motorSpeedA = motorSpeedA + xMapped;
motorSpeedB = motorSpeedB - xMapped;
// Confine the range from 0 to 255
if (motorSpeedA > 255) {
motorSpeedA = 255;
}
if (motorSpeedB < 0) {
motorSpeedB = 0;
}
}
// Prevent buzzing at low speeds (Adjust according to your motors. My motors couldn't start moving if PWM value was below value of 70)
if (motorSpeedA < 70) {
motorSpeedA = 0;
}
if (motorSpeedB < 70) {
motorSpeedB = 0;
}
analogWrite(enA, motorSpeedA); // Send PWM signal to motor A
analogWrite(enB, motorSpeedB); // Send PWM signal to motor B
}
Tom...
![]()
It was on a pdf. I had to copy it from that. I will go through the sketch and remove all the numbers and dots. I'll be back.
We have some success, both motors work although not as planned. It's all a bit confusing. I have it hooked up to a grabber thing and what I expect to happen doesn't. I'll hook up a couple of small dc motors with tape on the shaft and do a deep report. Probably tomorrow now, my brain is quite fogged and I need a bex and a lie down.
Awesome help, thanks so much.
BEX needs a cuppa tea first.
Bex!! Bee Eeee Exxx Bex!! (Radio Add)
Bex Powders
Bex Powders were a compound analgesic that comprised aspirin (420mg), phenacetin (420 mg) and caffeine (160mg), also known as APC. It was the first APC product marketed in Australia and the most popular. Bex Powders were produced from the 1920s in South Australia by Beckers Pty Ltd. [1]
Beckers moved to Sydney in the 1960s and in 1964 was based at the corner of Campbell and Crown Streets, Sydney.
Bex Powders were commonly taken by dissolving the powder in water or a cup of tea. The packaging claimed a Bex would relieve ‘Headache, Neuralgia, Rheumatism, Sciatica, Lumbago...Influenza and Cold in early stages’.
I can remember them in a little slotted dispenser on the wall of my grandfathers general store.
Tom...
![]()
(Jeez I'm OLD!!!!!)
Things haven't improved. Bex was a fail. Set up with two small dc motors to do tests and now there is such a small amount of volts actually getting to the motors that all they do is miew at me. Not enough to show up on the multi meter as a number above 1.
Never give up. Take smaller bites. So I found this
and this
int motor1pin1 = 2;
int motor1pin2 = 3;
int motor2pin1 = 4;
int motor2pin2 = 5;
void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
delay(1000);
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);
delay(1000);
}
Simple diagram, simple code.
Result. smack on target as usual. Zip. Nada. not a sound, not a movement.
So I tried another one, even simpler. Nada. OK, something is seriously wrong so I replaced the arduino, tried again. Nada. Replaced the L2984N, nada. Even tested the motors, working fine.
Looking for a new hobby.
Here is the last diagram
and
sketch_sep23c.ino (1.5 KB)
For info.
I hope that 9V PP3 battery has nothing to do with your project ?!
Where’s the Arduino getting its supply from ?




