Motor command via Serial prob

i need to command motors to start and stop via the serial line.   but i upload the code and they both just come on?  wont go off or enything.  they are small so for thesting i jush atached them to the pins and ground heres the code:

 

 

 

 

int message = 1;
int M1P =  5;
int M2P =  6;
int M1 = 0;
int M2 = 0;

void setup()
{
  pinMode(M1P, OUTPUT);
  pinMode(M2P, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  {
  if (Serial.available() > 0)
  message = Serial.read();
}{
  if (message == ‘R’);
  digitalWrite(M1P, HIGH);
}{
  if (message == ‘r’);
  digitalWrite(M1P, LOW);
}{
  if (message == ‘L’);
  digitalWrite(M2P, HIGH);
}{
  if (message == ‘l’);
  digitalWrite(M2P, LOW);

}
}

You defined message as an

You defined message as an integer but seem to be using it as a char or string. My guess is that’s why they just stay on. It’s an int defined as one and the character changes can’t affect it after. Try changing that.

If that doesn’t work try using softSerial library to setup a second COM port. Send commands via that port and use the default port as a serial monitor.

Try that and write here if you are still stuck.

i dont know how to do that

i dont know how to do that can you explane?

I am with Gonzik.

Your first line should be something like:

char message;

if you can get away with declaring a variable without also initializing it. Otherwise,

char message=‘l’; or char message=‘r’;

should work. I honestly don’t know C well enough to say for sure.

As Gonzik said

http://www.arduino.cc/en/Serial/Read

 

Returns

the first byte of incoming serial data available (or -1 if no data is available) - int

 

message is a byte but you are comparing it with a ascii char ‘R’

 

instead of ‘R’ … try comparing it with 82   82 is ascii ‘R’

 

http://www.ascii-code.com/ 

 


 

sorry …

I don’t know why I said that earlier…
A few suggestions - your scope operators { & } are not necessary 
Also if you are going to test message as a char you should define it as a char

 

 

char message = 1;
int M1P = 5;
int M2P = 6;
int M1 = 0;
int M2 = 0;

void setup()
{
pinMode(M1P, OUTPUT);
pinMode(M2P, OUTPUT);
Serial.begin(9600);
}

void loop()
{
if (Serial.available() > 0)
{
message = Serial.read();

  if (message == 'R');
        digitalWrite(M1P, HIGH); 
  
  if (message == 'r');
    digitalWrite(M1P, LOW);
      
  if (message == 'L');
    digitalWrite(M2P, HIGH);

  if (message == 'l');
    digitalWrite(M2P, LOW);  
}

}

You all missed the lack of motor driver…

You should not be running motors directly off of the pins on the microcontroller! It is possible that you may have already fried something! --Test with a LED, my friend --or get a transistor for that motor!

Thanks!

Yep, I saw the code and got excited… but leave it to CTC to get to the root of the issue…

Max current from the pin will be about 40 ma… enough current for about 2 regular LEDs and not much more…

**Alright - **

Chris showed his complete Awesomeness by reading carefully and pointing out what should have been obvious to us all !  Ting !

Now, I would like to know another “Awesome” thingy, which may be obvious to all…(except me)

How the HECK did you Breathit, make all your code so pretty ?!?!  

I thought there might be a code module now in LMR - but looking at the source it does not appear to be the case, because I would expect just a <class=code> and the implementation done with css.

I can make my code format correctly with carriage returns, spaces, and tabs with a <pre> tag…  but how did you do the syntax highlighting !!!

I am your grasshopper…

Ok i will make the changes

Ok i will make the changes and use LEDs to test and get back with you guys if it works.

And GroG to make you code look good,

enter the arduino envirement and select all code then right click it and select “copy HTML”.

come to LMR and select HTML in the coments box, paste code there.   DONE!

It No Work

it dosint work now nothing hapens the Test LEDs dont come on or enything

Fried.

You have probably fried the pins that were connected to the motor. If you are lucky, you only lost those pins and not the whole chip. If you can still sync, it is a good sign. Test these pins with a simple blink program and also try your original test program on a couple different pins.

Its Not The Motor!!!

I know this for 2 resons -  the motors are very small (ive driven much biger motors on this board)  and i wrote all the pins high and used a led and 330ohm rissistor to test thim so shut up about the f-ing motors!!!

Wow, that is not the correct way to go.

"Shut up about the f-ing motors" is not they way you ask for help. This fact is usually taught by parents to children.

And you have lost my help.

Don’t bite the hand that helps you…

Chris is very experienced with robot building, so he is talking from experience…  He and I have damaged chips from over sinking current from them.  Do you know what this means?

In a previous post you stated, “it dosint work now nothing hapens the Test LEDs dont come on or enything” and now you are saying 

i wrote all the pins high and used a led and 330ohm rissistor to test".  So now they are working with the LEDs?  Can you post the code you are using to test, if you have a question about that?

You need to be as clear as possible when stating your problem, if you really want help.  Add pictures or diagrams if you can.

Also, since you helped me with that great formatting tip, I will let you in on a tip/trick I use.  Most browsers are spell checking capable. A little squiggly line appears for misspelled words, you just right click and choose the correct spelling.  It adds to the clarity of your statements.

GroG

 

 

Christ what an attitude

Christ what an attitude problem. I was going to offer a possible solution but I don`t think I will now.