Go Down

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


for which there is no room...

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

Agreed, no new nor malloc().

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 ?

Test if that pointer remains unmodified at run time

Any other suggestion ...


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() {
  myservo1.attach(6);  //the pin for the servo control
  Serial.println("servo-test-21"); // so I can keep track of what is loaded

void loop() {

  while (Serial.available()) {
    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
      int n1 = servo1.toInt();
      int n2 = servo2.toInt();
      myservo1.writeMicroseconds(n1); //set servo position

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


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 >nul
echo 22000700 > com3
echo 5 second delay
ping -n 6 >nul
echo 15001500 > com3
echo 5 second delay
ping -n 6 >nul
echo 09001800 > com3
echo done
echo Did it work?
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up