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
}
}
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.
/**
* 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 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
}
}
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.
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.
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!
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?
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
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
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!
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.
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.
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?
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
Comments
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
}
}
I want to see your bt1Pin and bt2Pin and circumferenceArray
definitions as well. There must be a problem with those.
regards peter
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
}
}
}
Thanks Johnny
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
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
Johnny
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?
Johnny
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
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
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
Somehow pins 11 and 12 appear to interact on each other, perhaps one of them
is internally damaged.
regards peter
Johnny
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
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?)
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
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