Go Down

Topic: Cat toy (2 servos) - how to handle data (Read 593 times) previous topic - next topic

michael_x

Quote
for which there is no room...

... and no way of run time error handling.

Agreed, no new nor malloc().

Or:
Do that inside a function which has defined a local byte blocker[300]; variable.
Anyone volunteer to test if malloc() really works ok when it reaches stack ?

Or:
Test if that pointer remains unmodified at run time

Or:
Any other suggestion ...

zoomkat

Simple two servo test code. You can defeat the arduino auto reset with a 100 ohm resistor, and make a simple repeating batch file to operate the servos via the pc serial port.

Code: [Select]

// zoomkat 11-22-10 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550

#include <Servo.h>
String readString, servo1, servo2;
Servo myservo1;  // create servo object to control a servo
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(6);  //the pin for the servo control
  myservo2.attach(7);
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(1); 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
      Serial.println(readString); //see what was received
     
      // expect a string like 07002100 containing the two servo positions     
      servo1 = readString.substring(0, 4); //get the first four characters
      servo2 = readString.substring(4, 8); //get the next four characters
     
      Serial.println(servo1);  //print to serial monitor to see results
      Serial.println(servo2);
     
      int n1 = servo1.toInt();
      int n2 = servo2.toInt();
     
      myservo1.writeMicroseconds(n1); //set servo position
      myservo2.writeMicroseconds(n2);
    readString="";
  }
}

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

zoomkat

Below is the looping batch file you can test with when the arduino auto reset is defeated. Copy the code, paste in notepad, and save on the desktop as servoloop.bat. This is set for comport 3 at 9600 bps. Double click (or right click and run) the servoloop.bat file to run.

Code: [Select]

@echo off
mode com3:9600,N,8,1 >nul
echo moving servos
echo 07001500 > com3
echo 8 second delay
ping -n 9 127.0.0.1 >nul
echo 22000700 > com3
echo 5 second delay
ping -n 6 127.0.0.1 >nul
echo 15001500 > com3
echo 5 second delay
ping -n 6 127.0.0.1 >nul
echo 09001800 > com3
echo done
echo Did it work?
pause
servoloop.bat
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up