Hi everyone.
I'm very much a newbie but have spent the last 3 days cramming and it hasn't helped so..........
I have put a Rev1 motorshield onto an UNO Rev3.
Tried to get the following simple sketch to work:
[code]//Motor Shield 1-Channel DC Motor Demo
//by Randy Sarafan
//For more information see:
//https://www.instructables.com/id/Arduino-Motor-Shield-Tutorial/
//*************************************************************/
void setup() {
Serial.begin(9600);
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
}
void loop(){
//forward @ full speed
Serial.println ("start");
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed
delay(3000);
Serial.println ("stop");
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(1000);
//backward @ half speed
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 123); //Spins the motor on Channel A at half speed
Serial.println ("reverse");
delay(3000);
digitalWrite(9, HIGH); //Eengage the Brake for Channel A
delay(1000);
Serial.println ("end");
}
Yes, SORRY. I read all the "how to use this forum" stuff but I still can't work out how to use the code tags. Blame it on age (I do).
BUT, it gives you the details.
Code uploads, serial monitor runs through all the "printlns" but I get no output from ANY of the motor pins on the shield.
Tried another UNO, same thing.
Swapped the 293 chips on the shield, no joy.
I only tried this sketch from instructables because I was getting no joy from my own code.
Does it simply mean I've got a dead shield OR am I missing something obvious??????
Yes, motor works OK at anything from about 3V up including 12Volt
And yes, I have 12V DC to the power terminals, UNO powered via USB (Power link on the shield removed)
The other question, NO that is not my board.
I have an original Version 1 with the 2 L293 chips, long discontinued by Arduino, I know, but don't want to toss it.
It is from DK Electronics, if that helps at all.
I've tried shifting to M3 and M4 and have swapped the L293 chips.
Nothing seems to work. Just the power light.
No error messages and the program loops quite happily.
Good luck with the hunt, Tom.
I'd appreciate if you would give it a run.
I've also tried it with the "instructables" single motor and 2 motor codes.
This time of the year it's going to take forever to get a replacement board too.
Hi Tom,
Genius!!
Thanks very much, works like a charm and has taught me about 2 way serial as well. I hate being the newbie, 20 to 30 years ago I was in your position, but all with the then popular 6502 chips.(Atari)
Of course now I want to substitute my own code and to do that I would really like to understand what the .h files really are.
Arduino IDE won't open them and nothing else makes much sense, so can you give me a pointer please.
A number of links will come up showing you how they work and how to make your own.
For the driver board you have, I would be sticking with that Adafruit library.
If you look in Examples and find that library example, you can see how it works with the many code examples.
Hi Tom,
Yeah. Been through that various times but didn't really glean useful info about just running a single motor.
But I'm stupid for not trying to use a simple text editor.
Obviously too basic an idea for my mighty brain!
Thanks once again Tom. More Karma has been added.
I assume the line " if (Serial.available() > 0)" will just sit and wait forever until the serial monitor comes online??? Can't see what else but have found amazingly little detailed info on that.
Also, do I think correctly that after the switch/case statement you loop back to await the next serial input and that is the end of the void loop() statement. ? Can't believe that after honestly quite a lot of research (in obviously the wrong places) I hadn't come across that possibility EVER!
PLENTY of posts saying "NEVER use GOTOs, you'll create spaghetti code" etc.
I'm assuming that this example of switch/case/break is the equivalent of the old BASIC if/then/goto (or maybe "gosub"). And that all the routines such as forward/reverse/brake etc. are basically the equivalent of subroutines?? Seems to make sense.?
Again the arduino reference is amazingly unhelpful and forum questions don't really seem to address it too well.
Have transferred bits of your brilliant code to my program but don't have a very deep understanding of it yet.
Unless you object strenuously, I'm going to finish my sketch and post it here so you (and others) can point out all the things I did wrong and all the shortcuts that would be possible etc. etc.
aussiewill:
Hi Tom, me again. More basic questions.
I assume the line " if (Serial.available() > 0)" will just sit and wait forever until the serial monitor comes online??? Can't see what else but have found amazingly little detailed info on that.
Yes, it checks the serial in buffer, if empty it returns the value of "0", if there is any data in it, it returns the value "1"
and goes through the SerialRead process.
Also, do I think correctly that after the switch/case statement you loop back to await the next serial input and that is the end of the void loop() statement.
Yes, when the switch/case has finished it automatically loops back to the start of the void loop().
It keeps looping but because "Serial.available()" is "0" until the buffer has something in it, it jumps around the "SerialRead".
This code only accepts one character, not a many character type command.
Switch/case is a much more efficient way of the if..else.. if.. nesting, and is easier to read and debug.
You will notice this line.
if (inByte != oldinByte)
It checks to see if the last command has changed.
If it hasn't then it does not do the switch/case, this just makes the loop more efficient and stops the monitor screen from continually updating.
Only just now on re reading the post did I notice your comment about starting on a Z80.
Is my memory correct that that was the teensy weensy Sinclair Z80?? And I bet you never had so much fun!
My very first one was a cobbled together (by someone else) affair with a hexadecimal input pad and, 2K of RAM and NO way to store, not even tape.
Enter the code straight in-enter code-enter code-enter and so on.
The only thing it could do really was sound a buzzer or if you literally had all day, you could make it sound like a siren.
Wore thin quite quickly. A real dead end.
Then the Atari came out and that was it for me. First Basic, then 6502 programming, then I developed replacement OS chips that allowed breaking into programs etc.
Hardware enhancements such as memory expansions, quadrupling disk drive IO and various other gadgets.
Ah, those were the days, I actually knew what I was doing then.
My machine code was taught on the Z80 evaluation board, I still have one I got from local UNI when they were surplus to their requirements.
Tape recorder backup and S100 bus.
But before then, High School, HPBasic on these cards.
You would mark your instructions with 2B pencil.
The computer we used was 50kms away, so cards were dispatched on bus first day, loaded and run the next at an "Institute of Advanced Education"as they called them then, third day it came back on bus.
The you looked to see if it ran, or didn't, if you had made any cad errors.
Frustrating but to keen teenagers it was top technology.
Hi Tom,
Wow, THAT was doing it the hard way!
How many cards would it take to achieve even a basic instruction?
I remember early computers running entirely on punchcards, but I also remember there'd be a huge stack in the card reader for even simple operations.
I think you need to be congratulated for your perseverance!