mwyld
April 7, 2022, 10:56am
1
Hi I am very new to ardunio and trying to get my geared motor to work.
I am using the following code:
#include <Encoder.h>
Encoder myEnc(14,12);
int E1 = 4;
int M1 = 5;
void setup() {
Serial.begin(115200);
delay(800);
startMotor();
}
void startMotor() {
int potValue=700;
int mappedVal = map(potValue-512,0,512,0,255);
analogWrite(E1, mappedVal);
digitalWrite(E1,HIGH);
analogWrite(M1, mappedVal);
}
void loop() {
}
and I am getting the following output in the serial monitor
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00043b70
~ld
motor: CHIHAI GM4632-370 DC 12V 30RPM High torque Turbo Encoder Motor Worm Geared Motor Reducer Motor Sale - Banggood UK-arrival notice-arrival notice
driver: https://www.amazon.co.uk/gp/product/B07F9LH4PJ/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1
any point in the right direction would be helpful!
mwyld
April 7, 2022, 10:59am
2
It doesn't look as if you posted all your code.
mwyld
April 7, 2022, 1:01pm
4
Apologies I missed the E1 and M1 variables, I've updated the code above
Hi, can't see any loop function in your code.
The stack trace means your sketch crashed the CPU.
mwyld
April 7, 2022, 1:19pm
7
It's there, I was just removing any code that would seem unnecessary, I've added it back in to the code above.
mwyld
April 7, 2022, 1:21pm
8
It seems to only crash on this line
Encoder myEnc(14,12);
What would that mean? Something wrong with the wiring on those pins?
One problem, declaration in setup ().
mwyld
April 7, 2022, 1:23pm
10
Ok so move this line into setup?
Encoder myEnc(14,12);
I'll give it a go now
Nooooo... When did I say to do that?
mwyld
April 7, 2022, 1:26pm
12
Okay, which declaration needs to go into the setup? Sorry I'm relatively new to this
Opposite. It needs to be removed from setup. Do you know what a declaration is?
Just call the function
mwyld
April 7, 2022, 1:31pm
15
So move the function that calls the startMotor() into the loop() instead?
Maybe ensure it only gets called once
mwyld
April 7, 2022, 1:32pm
17
Can you provide an example?
Sure, any C program that calls a function. You were so close, just remove the void key word. That is what makes it a declaration.
mwyld
April 7, 2022, 1:37pm
19
I think that was a typo in my code, I didn't actually have the void bit when calling that function. I've updated the code above.
--> I've hit the max number of replies for a new user?! How strange <--
I've redacted the code to help reduce the noise in the ticket.
I see you edited the original post to change the line in question. Please never do that, it makes nonsense of the replies.
Also, are you telling me that the code you posted is not the same as the code that produces the error? That would be very misleading. As would “ redacting the code". Please spend some time reading the forum rules.
Your post privileges will be granted in 24 hours.