Shop OBEX P1 Docs P2 Docs Learn Events
javelin servos and NES — Parallax Forums

javelin servos and NES

DorlingDorling Posts: 32
edited 2007-05-10 10:58 in General Discussion
Hi All,

I am try to run two servos both are Hitec HS-475 HB. My program at the moment is simple the Nintendo NES key turn the servos.

The problem is that when a key is pressed on the NES it needs to turn one of the servo which it try to do but it doesn't continue running any code until the servo get to the correct position and it can take a long long to get there. Why is this and how can i fix this? I am trying the servo at 6v.

Many Thanks

Jonathan smile.gif

ServoControl.java
import stamp.core.PWM;
import stamp.core.CPU;

import stamp.peripheral.gamecontrollers.nintendo.NES;

public class ServoControl {

  private static PWM baseServo = new PWM(CPU.pin12,173,2304);
  private static PWM shoulderServo = new PWM(CPU.pin13,173,2304);

  private static int clock = CPU.pin2;
  private static int strobe = CPU.pin1;
  private static int data = CPU.pin0;
  private static NES nes = new NES(data, clock, strobe);

  public static void main() {

    while (true) {
      System.out.print("DEBUG: ");
      System.out.println(nes.getButtons());
      if(nes.getLeft()){
        baseServo.update(220,2304);
      }else if(nes.getRight()){
        baseServo.update(130,2304);
      } else{
        baseServo.update(173,2304);
      }
      if(nes.getUp()){
        shoulderServo.update(220,2304);
      }else if(nes.getDown()){
        shoulderServo.update(130,2304);
      } else{
        shoulderServo.update(173,2304);
      }
        CPU.delay(100);
    }

  }
}





NES.java
package stamp.peripheral.gamecontrollers.nintendo;

import stamp.core.CPU;

public class NES {

  private int dataPin, clockPin, strobePin;

  private int buttonData = 255;

  public NES(int dataPin, int clockPin, int strobePin) {
    this.dataPin = dataPin;
    this.clockPin = clockPin;
    this.strobePin = strobePin;
    CPU.setInput(dataPin);
    CPU.writePin(clockPin, false);           // initialize for high pulses
    CPU.writePin(strobePin, false);          // initalize for high pulse
  }

  public int getButtons() {
    CPU.pulseOut(1, strobePin);             // load inputs
    buttonData = CPU.shiftIn(dataPin, clockPin, 8, CPU.PRE_CLOCK_MSB);                        // return loaded data
    return buttonData;
  }

  public boolean getA(){
    return ((buttonData & 0x80) !=  0x80);
  }
  public boolean getB(){
    return ((buttonData & 0x40) != 0x40);
  }
  public boolean getSelect(){
    return ((buttonData & 0x20) != 0x20);
  }
  public boolean getStart(){
    return ((buttonData & 0x10) != 0x10);
  }
  public boolean getUp(){
    return ((buttonData & 0x08) !=  0x08);
  }
  public boolean getDown(){
    return ((buttonData & 0x04) != 0x04);
  }
  public boolean getLeft(){
    return ((buttonData & 0x02) !=  0x02);
  }
  public boolean getRight(){
    return ((buttonData & 0x01) != 0x01);
  }


}





p.s. When I try to upload my java file he said that they are "* You cannot upload files that use MIME type : text/java.". How do you get round this?

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-03-21 00:43
    You should be able to attach a java file to your posts.
    Otherwise contact forum support.

    The PWM.update() does return immediately after writing new settings.
    It does not wait until the position is reached.
    In your code,

    ······if(nes.getLeft()){
    ········baseServo.update(220,2304);
    ······}else·if(nes.getRight()){
    ········baseServo.update(130,2304);
    ······}·else{
    ········baseServo.update(173,2304);
    ······}

    if no key is pressed, the servo is moved to center position (bold).
    In other words, the moment you release the key, the servo returns
    to its center. I don't think that is your intention.


    regards peter
  • DorlingDorling Posts: 32
    edited 2007-03-21 11:03
    Peter many thanks for your reply.

    That is my intention that only to be left or right while the key is held down. But the code pauses until the servo as reached the position. I can tell this because no debug info is send to the debug windows.

    It works great when only 1 servo is connect just not two of them. For my Project I need 7 servo connect where 2 of them will work in parallel so that i only need 6 VP. Maybe there the circuit needs more power?

    Many Thanks

    Jonathan
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-03-21 11:35
    Yes, I would try to get a more powerful supply for the servos
    and see if that makes a difference.

    regards peter
  • DorlingDorling Posts: 32
    edited 2007-05-10 10:58
    It turn out that using a independent power supply worked.

    Do I need a smoothing capacitor, If so how do i work out which value and type?

    Many Thanks

    Jonathan
Sign In or Register to comment.