Shop OBEX P1 Docs P2 Docs Learn Events
It doesn't println? - Page 2 — Parallax Forums

It doesn't println?

2»

Comments

  • PlaneTeeRPlaneTeeR Posts: 100
    edited 2006-06-09 15:35
    The last main you send, so:

    static void main() {
    Format.printf("ApplicationFCv2\n");
    while (true) {
    if (!CPU.readPin(bt1Pin)){
    circumferenceIndex = (circumferenceIndex+1)%9; //support for 9 wheel sizes
    circumference = circumferenceArray[noparse][[/noparse]circumferenceIndex];
    System.out.println(circumference);
    if (!CPU.readPin(bt2Pin)) {
    System.out.println("pin2 is low");
    }
    CPU.delay(10500); //wait 1 second
    }
    if (!CPU.readPin(bt2Pin)){
    break;
    }
    }
    tSpeed.mark();
    tLcd.mark();
    while (true) {
    clk.update(); //update realtime clock
    if ((speed = sen.poll()) == 0) clk.stop(); //poll sensor, stop clock if no speed
    else clk.start();
    calculateDistance(); //update distance by integrating over time
    if ((speed != 0) || tLcd.timeout(1000)) updateLcd(); //update display immediately if speed > 0, else once per second
    }
    }
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-09 16:27
    That is not your whole main class.
    I want to see your bt1Pin and bt2Pin and circumferenceArray
    definitions as well. There must be a problem with those.

    regards peter
  • PlaneTeeRPlaneTeeR Posts: 100
    edited 2006-06-10 21:00
    This is the whole class:

    package fietsv3;
    import stamp.core.*;
    import stamp.peripheral.display.lcd.serial.BPI216;
    import stamp.util.text.*;
    import stamp.math.*;

    /**
    * Main Application
    *
    * @version 1.0 01-06-06
    * @author Johnny Kuiper
    */

    public class ApplicationFCv2 {

    //define used resources - I/O pins, VP's and main objects
    final static int LCDPIN = CPU.pin15;
    final static int senPin = CPU.pin14;
    final static int ledPin = CPU.pin13;
    final static int bt1Pin = CPU.pin12;
    final static int bt2Pin = CPU.pin11;


    static final int[noparse]/noparse circumferenceArray = {15,16,17,18,19,20,21,22,23};
    static int circumference = 20; //standard
    static int circumferenceIndex;

    static Timer tPulse = new Timer();
    static Timer tClock = new Timer();
    static Timer tLcd = new Timer();
    static Timer tSpeed = new Timer();
    static Clock clk = new Clock(tClock);
    static Sensor sen = new Sensor(senPin,ledPin,tPulse,circumference);
    static Uart txOut = new Uart( Uart.dirTransmit, LCDPIN, Uart.invert,Uart.speed9600, Uart.stop1);
    static DisplayFormat df = new DisplayFormat(txOut);

    //define global variables
    static int dstm = 0;
    static int dstKm = 0;
    static int speed;

    static void calculateDistance(){
    int time = tSpeed.passedMS();
    tSpeed.mark();
    int distance = Travel.distance(speed,time); //0.1m units
    dstm += distance;
    while (dstm >= 10000) { //dstm is in 0.1 m units so 10000 equals 1000 m
    dstKm++;
    dstm -= 10000;
    if (dstKm == 10000) dstKm = 0; //wrap from 9999 to 0000
    }
    }

    static int calculateAverage(){
    return Travel.average(dstKm*100+(dstm/100),(60*clk.chronoH+clk.chronoM)*60+clk.chronoS);
    }

    static void updateLcd() {
    tLcd.mark();
    Format.printf("realtime = %s\n",df.formatChrono(clk.chronoH,clk.chronoM,clk.chronoS));
    Format.printf("distance = %s km\n",df.formatDistance(dstKm,dstm));
    Format.printf("speed = %s km/h\n",df.formatSpeed(speed));
    }

    static void main() {
    Format.printf("ApplicationFCv2\n");
    while (true) {
    if (!CPU.readPin(bt1Pin)){
    circumferenceIndex = (circumferenceIndex+1)%9; //support for 9 wheel sizes
    circumference = circumferenceArray[noparse][[/noparse]circumferenceIndex];
    System.out.println(circumference);
    if (!CPU.readPin(bt2Pin)) {
    System.out.println("pin2 is low");
    }
    CPU.delay(10500); //wait 1 second
    }
    if (!CPU.readPin(bt2Pin)){
    break;
    }
    }
    tSpeed.mark();
    tLcd.mark();
    while (true) {
    clk.update(); //update realtime clock
    if ((speed = sen.poll()) == 0) clk.stop(); //poll sensor, stop clock if no speed
    else clk.start();
    calculateDistance(); //update distance by integrating over time
    if ((speed != 0) || tLcd.timeout(1000)) updateLcd(); //update display immediately if speed > 0, else once per second
    }
    }

    }
  • PlaneTeeRPlaneTeeR Posts: 100
    edited 2006-06-10 21:02
    Peter, I can't test it anymore, i don't know why, the serial connection gives an error (IDE-0010). I think my BOE is damaged.

    Thanks Johnny
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-10 21:15
    This is indeed strange: according to your code, the last part of main()
    should only execute if bt2pin is·low. And it is not low otherwise
    the text "pin2 is low" would be printed when pressing bt1pin.
    I wonder if this is a compiler bug?
    Lets rewrite the code but maintain its logic.
    Replace the part
    while (true) {
    if (!CPU.readPin(bt1Pin)){
    circumferenceIndex = (circumferenceIndex+1)%9; //support for 9 wheel sizes
    circumference = circumferenceArray[noparse][[/noparse]circumferenceIndex];
    System.out.println(circumference);
    if (!CPU.readPin(bt2Pin)) {
    System.out.println("pin2 is low");
    }
    CPU.delay(10500); //wait 1 second
    }
    if (!CPU.readPin(bt2Pin)){
    break;
    }
    }

    by
    while (CPU.readPin(bt2Pin)) {
    · if (!CPU.readPin(bt1Pin)){
    ··· circumferenceIndex = (circumferenceIndex+1)%9; //support for 9 wheel sizes
    ··· circumference = circumferenceArray[noparse][[/noparse]circumferenceIndex];
    ··· System.out.println(circumference);
    ··· if (!CPU.readPin(bt2Pin)) {
    ····· System.out.println("pin2 is low");
    ··· }
    ··· CPU.delay(10500); //wait 1 second
    · }
    }

    and see if it now works.
    If bt2Pin has a pullup resistor as you said, the above while loop
    will only exit if you press bt2pin.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-10 21:20
    IDE error 10:
    Error communicating over the serial port (corrupt packet $%2.2X): The received data was corrupted. Verify serial cable connection

    The chance your BOE is damaged is very small. Check your serial cable for loose connections
    and check your power supply. Are you using batteries then try fresh batteries.

    regards peter
  • PlaneTeeRPlaneTeeR Posts: 100
    edited 2006-06-11 20:02
    I checked the cable, tried another cable, used an acdc adaptor instead of batteries. It didn't make any change, but suddenly after 1 day i checked again and now it works??? Very strange! I'm going to try the new code tomorrow!

    Johnny
  • PlaneTeeRPlaneTeeR Posts: 100
    edited 2006-06-12 09:34
    I've tested the new code, this is the output:

    ApplicationFCv2
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    ApplicationFCv2
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    16
    pin2 is low
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    speed = 000.00 km/h
    distance = 0.00 km
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    16
    pin2 is low
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    16
    pin2 is low
    17
    pin2 is low
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    16
    pin2 is low
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2
    16
    pin2 is low
    17
    pin2 is low
    18
    pin2 is low
    speed = 000.00 km/h
    distance = 0.00 km
    ApplicationFCv2

    I had to push fast and very short to get a result. Maby my connection is wrong, when i push the button the diode on the BOE stops burning, is this always? Or must i connect it different?
  • PlaneTeeRPlaneTeeR Posts: 100
    edited 2006-06-12 09:36
    This is how i connect the button.



    Johnny
    217 x 189 - 5K
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-12 12:34
    The output shows that pin2 is low from the start.
    The button is connected in the correct way.
    I suspect you have a normally closed button,
    or at least used the normally closed contacts.
    Remove the button from your setup and find out (use ohmmeter)
    which two contacts give very high impedance when
    not pressing and give 0 ohm impedance when pressing.
    That are the contacts you must use.

    You say the BOE led turns off when pressing the button?
    are you sure the 10k resistor is correctly wired? It sounds like
    shortcircuiting the 5V to gnd.

    regards peter

    Post Edited (Peter Verkaik) : 6/12/2006 12:38:03 PM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-12 12:50
    I really think you have a wire problem.

    Remove both button setups, including
    the resistors and wires to VDD and GND.
    Then rewire the resistors as pullups. Do not connect the buttons.
    Then run the code. The first while loop should
    never exit, eg. the program must not start.

    From that point setup button 1 again.
    Then you see circumference change when pressing button 1.
    The program must never start.

    From that point, setup button 2 again.
    Now you should be able to start the program by pressing button 2.

    regards peter

    Post Edited (Peter Verkaik) : 6/12/2006 12:56:15 PM GMT
  • PlaneTeeRPlaneTeeR Posts: 100
    edited 2006-06-13 17:50
    I tested it, and when i have no buttons on the bord it never starts the program, when i add button 1 it starts! Even if the second button is not installed! This is really strange! I tried a different button, but same problem. When i only put the second button on the bord it sometimes normally starts the program but sometimes it shows the first setting of the circumference :S.

    The diode on the BOE is of when i press the button, but i connected it correctly as you saw in the diagram. I don't know what it is!

    Johnny
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-13 18:04
    Can you try two other pins for the buttons, like pins 6 and 7?
    Somehow pins 11 and 12 appear to interact on each other, perhaps one of them
    is internally damaged.

    regards peter
  • PlaneTeeRPlaneTeeR Posts: 100
    edited 2006-06-14 20:43
    This doesn't solve the problem, with other pins the same·problem occures.

    Johnny
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-14 21:08
    That is really strange.
    Try the attached button test program.
    It only contains the code to test the 2 buttons.
    See if that works.
    It uses pins 11 and 12. Change to your current setup.

    regards peter
  • PlaneTeeRPlaneTeeR Posts: 100
    edited 2006-06-16 09:42
    The first time i pushed the parameterPin twice then the modePin a few times, this is what i got:

    Button test
    mode = 1
    circumference = 18
    mode = 2
    circumference = 19

    When i first pushed the parameterPin there was nothing on display the second time it printed mode and circumference!

    Johnny

    (The diode on the BOE still stops burning when i push it, can i connect the buttons in another way?)
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-16 10:13
    I did the button test on my javelin using pin0 and pin1.
    Here is my output

    Button test
    circumference = 18
    circumference = 19
    circumference = 20
    circumference = 21
    circumference = 22
    mode = 1
    mode = 2
    mode = 0
    mode = 1
    mode = 2
    mode = 0
    mode = 1
    mode = 2
    circumference = 23
    circumference = 24
    mode = 0

    I press a button until something is printed, then release the button
    (if you release the button too soon, the press is not detected due to the 1 sec wait)
    modePin and parameterPin operate independant as they should.

    I have 4.7k pullup resistors (10k is ok too).
    So the program works.
    Which means your wiring is incorrect
    or your javelin is damaged in some way.
    Make sure your wiring is as specified below.
    Do you have another javelin to test?

    5V o---[noparse][[/noparse]4k7]---+---o pin0
    ·············· |
    ·············· / button1 normally open
    ·············· |
    ·············· 0V

    5V o---[noparse][[/noparse]4k7]---+---o pin1
    ·············· |
    ·············· / button2 normally open
    ·············· |
    ·············· 0V
    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-16 10:55
    I checked the BOE (serial version) schematic.
    If the BOE led goes off when you press the button
    that means VDD gets shorted to VSS, which makes me
    suspicious about your 10k resistor (I assume you wired as your picture in an earlier post)
    If this is a 10 ohm resistor the effect is the same.
    Measure those resistors with a multimeter!

    Edit: once VDD is shorted (during button press) the voltage level at the pins also
    become low which explains why both buttons appear pressed.
    The javelin is powered from Vin and thus keeps working, sensing both pins low.

    regards peter

    Post Edited (Peter Verkaik) : 6/16/2006 10:59:17 AM GMT
Sign In or Register to comment.