Pages: 1 [2]   Go Down
Author Topic: I need help with serial comands.  (Read 981 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26488
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have no idea - I don't have your hardware, but if you're going to use it, you need to tell it which "device" it has to work on.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Greenville, SC
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Nearly everything is too good to throw out.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, I removed exitSafeStart(); from
Code:
{
  mySerial.begin(19200);
  delay(5);
  mySerial.print(0xAA, BYTE);
 exitSafeStart();
}
And that fixed that issue. Was that the wrong thing to do? I am not sure what function that line was doing.  This is the code so far that completes the verifying without errors. Do you see anything that stands out to you? At this point in time I'm only guessing on what some of these lines of code are doing.
Code:
#include <NewSoftSerial.h>

#define rxPin 3 // pin 3 connects to SMC TX (not used in this example)
#define txPin 4 // pin 4 connects to SMC RX

NewSoftSerial mySerial = NewSoftSerial(rxPin, txPin);

// pululu codes
#define NEWCMD 0xAA
#define EXITSAFESTART 0x03
#define FORWARD 0x05
#define REVERSE 0x06

// device id's
 uint8_t Motor1 = 10;
 uint8_t Motor2 = 13;


void exitSafeStart(uint8_t device)
{
  mySerial.print(NEWCMD, BYTE);
  mySerial.print(device, BYTE);
  mySerial.print(EXITSAFESTART, BYTE);
}


void setMotorSpeed(uint8_t device, int speed)
{
  mySerial.print(NEWCMD, BYTE);
  mySerial.print(device, BYTE);

  if (speed < 0)
  {
    mySerial.print(REVERSE, BYTE); // motor reverse command
    speed = -speed; // make speed positive
  }
  else
  {
    mySerial.print(FORWARD, BYTE); // motor forward command
  }
  speed = constrain(speed, 0, 3200);  // speed should be a number between 0 to 3200
  mySerial.print((unsigned char)(speed & 0x1F), BYTE);
  mySerial.print((unsigned char)(speed >> 5), BYTE);
}

void setup()
{
  mySerial.begin(19200);
  delay(5);
  mySerial.print(0xAA, BYTE);

}

void loop()
{
  //int speed = analogRead(A0) * 6 - 3072;  // use an LDR or potmeter or ...
  setMotorSpeed(Motor1, 3200); // full-speed forward
  delay(1000);

 // int speed = analogRead(A1) * 6 - 3072;
  setMotorSpeed(Motor2, -3200); // full-speed reverse
  delay(1000);
}




Logged

Greenville, SC
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Nearly everything is too good to throw out.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

They are pololu simple motor controllers. http://www.pololu.com/docs/pdf/0J44/simple_motor_controllers.pdf. They can be given device numbers by setting them up in their internal firmware. I currently have them numbered 1 and 2. they can be set up to any number from 1-127. page 60 in that link.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
At this point in time I'm only guessing on what some of these lines of code are doing.
Connect the hardware, upload the code, and see what happens. Much faster than asking people who don't have the hardware that you have.
Logged

Greenville, SC
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Nearly everything is too good to throw out.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay I'm trying to understand, this code

 
Code:
void exitSafeStart(uint8_t device)
{
  mySerial.print(NEWCMD, BYTE);
  mySerial.print(device, BYTE);
  mySerial.print(EXITSAFESTART, BYTE);
}


is executed at exitSafeStart(); here
Code:
void setup()
{
  mySerial.begin(19200);
  delay(5);
  mySerial.print(0xAA, BYTE);
exitSafeStsrt();
  }

Am I correct about that?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26488
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Am I correct about that?
No, you are about as incorrect as it is possible to be.
First, you have no function "exitSafeStsrt();" defined, so the compiler will complain.
Second, assuming it was a typo, and meant to be "exitSafeStart();", you still haven't given it a value for "device", so you will still get the compiler complaining, though about something different.

You can default the value of "device" (though the Arduino may not like the some placements of the definition), which allows you to omit the value of "device":
Code:
void exitSafeStart(uint8_t device = 0) //if you omit the argument, it will default to whatever value you specify here
{
  mySerial.print(NEWCMD, BYTE);
  mySerial.print(device, BYTE);
  mySerial.print(EXITSAFESTART, BYTE);
}
« Last Edit: April 04, 2011, 02:15:51 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Greenville, SC
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Nearly everything is too good to throw out.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, I really have no clue what I'm doing.
Logged

Pages: 1 [2]   Go Up
Jump to: