Arduino Rocket launcher code issues after updating the code with updated refs.

I am building the arduino rocket launcher shown here

I have the required sparkfun 7 segment serial display as seen here Using the Serial 7-Segment Display - learn.sparkfun.com

it is setup to use the UART, single line serial connection to communicate with an Arduino Uno. I took the code that is uploaded on the website and attempted to modify it with the references to the updated Arduino libraries. From what I read the NewSoftSerial.h library is out of date and must be replaced with SoftwareSerial.h. I have replaced the references

I am going to attach my modified code here and then I will show the changes I made to it.

I will also show the original code.
You’ll notice the references to the NewSoftSerial.h library. and the term (BYTE)
mySerialPort.print(0x10,BYTE); //turn on the colon “:”.

This has been replaced with mySerialPort.write(0x10); //turn on the colon “:” in the attached .ino file.

The problem is When I upload the code I get random flashing numbers on the 7 segment display. The display is unstable.
**What is wrong with the code? I get no errors when compiling. **
What am I doing wrong? :confused:
**The code below is the old code referencing an out of date library. :o **
```
**/*RocketLauncher
ROCKET LAUNCHER CONTROLLER.
Arduining.com  05 Jan 2012 (hardware implemented version)

-A count-down TIMER is implemented.
-The potentiometer is used to set the TIMER.
-Two Push-Buttons: “ARM” to set the counter and “GO” to start the counter.
-Display: Sparkfun’s Serial 4 Digit 7-Segment Display . COM-09766 (RED).
-NewSoftSerial library is used to avoid random commands to the display
during program downloading.
*/
#define FuseTIME      1500  //Fuse current duration in milliseconds.

#include <NewSoftSerial.h>  //Usinf the NewSoftSerial library.

#define Fuss    7          //Pin connected to the Fuse relay.
#define GoButt  6          //Pin connected to the GO button.
#define ArmButt  5          //Pin connected to the ARM button.
#define BuzzPin  4          //Connected to the Speaker.
#define TXdata  3          //Conneted to Rx of the Display.
#define RXdata  2          //not used in this project
#define SetPot  0          //Analog Pin connected to the Pot.

NewSoftSerial mySerialPort(RXdata,TXdata);

void setup(){
  pinMode(TXdata,OUTPUT);
  pinMode(RXdata,INPUT);
  pinMode(Fuss,OUTPUT);
  pinMode(ArmButt, INPUT);        // set “ARM” button pin to input
  pinMode(GoButt, INPUT);        // set “GO” button pin to input
  digitalWrite(Fuss,LOW);        //OPEN the fuse circuit.
  digitalWrite(ArmButt, HIGH);    // turn on pullup resistor
  digitalWrite(GoButt, HIGH);    // turn on pullup resistor
  mySerialPort.begin(9600);
  delay(10);                      //Wait for Serial Display startup.
  mySerialPort.print(“v”);        //Reset the display.
  mySerialPort.print(“z”);        //Brightness Control.
  mySerialPort.print(0x40,BYTE);  //3/4 Intensity.
  mySerialPort.print(“w”);        //Decimal Point Control.
  mySerialPort.print(0x10,BYTE);  //turn on the colon “:”.
}

int  DownCntr;                    // down counter (1/10 Secs.)
int  Go=0;                        // Stopped

//================================================================
void loop(){
  if(!digitalRead(GoButt)||!digitalRead(ArmButt)){
    Go=0;                        //ABORT!!!
    tone(BuzzPin, 440, 1500);
    delay(1500);
  }

if(Go==0){
    WaitARM(); 
    WaitGO();
  }
  ShowTimer();
  if (DownCntr > 50){
      if (DownCntr % 10 ==0)tone(BuzzPin, 1000, 50);  //Tone every second.
    }
  else if (DownCntr % 2 ==0)tone(BuzzPin, 1000, 50);  //Tone every 1/5 second.

if (DownCntr ==0){
    //------------------ ROCKET LAUNCH! --------------------
    tone(BuzzPin, 440, FuseTIME);  //Launch audible signal
    digitalWrite(Fuss,HIGH);      //CLOSE the fuse circuit
    delay(FuseTIME);
    digitalWrite(Fuss,LOW);        //OPEN the fuse circuit.
    //------------------------------------------------------
    Go=0;
    }
  while (millis()% 100);        //Wait until the next 1/10 of second.
  delay(50);
  DownCntr–;
}

//----------------------------------------
void WaitGO(){
  ShowTimer();
  while(digitalRead(GoButt));
  Go=1;
  delay(20);
  while(!digitalRead(GoButt));  //Debounce GO button.
}

//------------------------------------------------------
void ReadTimer(){
  DownCntr = map(analogRead(SetPot), 0, 1023, 5, 60);
  DownCntr*=10; 
}
//------------------------------------------------------
void ShowTimer(){
  String seconds = String (DownCntr, DEC);
  while(seconds.length()<3)seconds= “0” + seconds;    //format to 3 numbers.
  mySerialPort.print(seconds);                        //Write to Display.
  mySerialPort.print(" ");                            //Last digit off.
}

//------------------------------------------------------
void WaitARM(){
  while(digitalRead(ArmButt)==1){
    ReadTimer();
    mySerialPort.print(" ");    //Turn Off Digits.
    delay(50);
    ReadTimer();
    ShowTimer();                  //Show Digits.
    delay(150);
  }

Go=0;
  ShowTimer();
  tone(BuzzPin, 2000, 150);
  delay(200);
  tone(BuzzPin, 2000, 150);
  delay(200);
  tone(BuzzPin, 2000, 150);

delay(20);
  while(!digitalRead(ArmButt));  //Debounce ARM button.

}**
```
Rocketlauncher.ino (3.94 KB)

1 Like

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :)

1 Like

Good job on the attempt to post the code. Most folks just post it as a regular part of their post. Just edit your post and change the "quote" tags to "code" tags.

1 Like

Hi, I would suggest you forget that code for the moment. You write some code just to get the display working with the revised newer softserial setup that you are using.

Tom... :)

1 Like

TomGeorge:
Hi,
I would suggest you forget that code for the moment.
You write some code just to get the display working with the revised newer softserial setup that you are using.

Tom… :slight_smile:

That part is done. The display works flawlessly using UART protocol…
Yes, I also changed the quote to a /code tag as well…

Did you have a look at the .ino attached? shall I post this too?

#define FuseTIME      1500  //Fuse current duration in milliseconds.
#include <SoftwareSerial.h>  //Call the SoftwareSerial library.

#define Fuse     7          //Pin connected to the Fuse (your LED or igniter)
#define GoButt   6          //Pin connected to the GO button
#define ArmButt  5          //Pin connected to the ARM button
#define BuzzPin  4          //Connected to the buzzer
#define TXdata   3          //Conneted to Rx of the Display
#define RXdata   2          //not used 
#define SetPot   0          //Analog Pin connected to the Potentiometer

SoftwareSerial mySerialPort(RXdata,TXdata);

void setup(){
  pinMode(TXdata,OUTPUT);
  pinMode(RXdata,INPUT);
  pinMode(Fuse,OUTPUT);
  pinMode(ArmButt, INPUT);        // set "ARM" button pin to input
  pinMode(GoButt, INPUT);         // set "GO" button pin to input
  digitalWrite(Fuse,LOW);         // OPEN the fuse circuit.
  digitalWrite(ArmButt, HIGH);    // turn on pull up resistor 
  digitalWrite(GoButt, HIGH);     // turn on pull up resistor 
  mySerialPort.begin(9600);
  delay(10);                      // Wait for Serial Display start up
  mySerialPort.print("v      // Reset the display
  mySerialPort.print("z      // Brightness 
  mySerialPort.write(0x40);       // 3/4 Intensity
  mySerialPort.print("w      // Decimal Point Control
  mySerialPort.write(0x10);       // turn on the colon ":"
}
int  DownCntr;                    // down counter (1/10 Secs)
int  Go=0;                        // Stopped
void loop(){
  if(!digitalRead(GoButt)||!digitalRead(ArmButt)){
    Go=0;                         // Stops the countdown
    tone(BuzzPin, 440, 1500);
    delay(1500);
  }
  if(Go==0){
    WaitARM();  
    WaitGO();
  }
  ShowTimer();
  if (DownCntr > 50){
      if (DownCntr % 10 ==0)tone(BuzzPin, 1000, 50);  // Beeps every second
     }
  else if (DownCntr % 2 ==0)tone(BuzzPin, 1000, 50);  // Beep goes faster

  if (DownCntr ==0){
    tone(BuzzPin, 440, FuseTIME);  // Launch tone
    digitalWrite(Fuse,HIGH);       // CLOSE the fuse circuit
    delay(FuseTIME);
    digitalWrite(Fuse,LOW);        // OPEN the fuse circuit
         Go=0;
    }
  while (millis()% 100);          // wait for a moment
  delay(50);
  DownCntr--;
}

void WaitGO(){
  ShowTimer();
  while(digitalRead(GoButt));
  Go=1;

delay(20);
  while(!digitalRead(GoButt));    //  Debounce the GO button
}
void ReadTimer(){
  DownCntr = map(analogRead(SetPot), 0, 1023, 5, 60);
  DownCntr*=10;  
}
void ShowTimer(){
  String seconds = String (DownCntr, DEC);
  while(seconds.length()<3)seconds= "0" + seconds;     // format to 3 numbers
  mySerialPort.print(seconds);                         // Write to Display
  mySerialPort.print(" ");                             // Last digit switched off
}
void WaitARM(){
  while(digitalRead(ArmButt)==1){
     ReadTimer(); 
     delay(50);
     ReadTimer(); 
     ShowTimer();                   
     delay(150);
  }
  Go=0;
  ShowTimer();
  tone(BuzzPin, 2000, 150);
  delay(200);
  tone(BuzzPin, 2000, 150);
  delay(200);
  tone(BuzzPin, 2000, 150);

  delay(20);
  while(!digitalRead(ArmButt));   // Debounce the ARM button
}
1 Like

Well, your mixture of using and not using curly brackets has me confused. So, I can only imagine your Arduino is too.

1 Like

Hi,

mySerialPort.print("v      // Reset the display
  mySerialPort.print("z      // Brightness 
  mySerialPort.write(0x40);       // 3/4 Intensity
  mySerialPort.print("w      // Decimal Point Control

You might have some problems here for a start. Where are the ) for each of the mySerialPort statements?

You need to do an Auto Format. In the IDE press CTRL-T.

You will then see any mismatched brackets and missing ;.

Tom.. :)

1 Like

When I do this no errors in the format are detected. though now an error 2:29 occurs now when I try to verify the code.

Rocket_Launcher_updated_2 2:29 : error expected ‘;’ before ‘mySerialPort’
MySerialPort.write(0x10); // turn on the colon “:”

^

exit status1

Yes I fixed the missing brackets.

#define FuseTIME      1500  //Fuse current duration in milliseconds.
#include <SoftwareSerial.h>  //Call the SoftwareSerial library.

#define Fuse     7          //Pin connected to the Fuse (your LED or igniter)
#define GoButt   6          //Pin connected to the GO button
#define ArmButt  5          //Pin connected to the ARM button
#define BuzzPin  4          //Connected to the buzzer
#define TXdata   3          //Conneted to Rx of the Display
#define RXdata   2          //not used 
#define SetPot   0          //Analog Pin connected to the Potentiometer

SoftwareSerial mySerialPort(RXdata, TXdata);

void setup() {
  pinMode(TXdata, OUTPUT);
  pinMode(RXdata, INPUT);
  pinMode(Fuse, OUTPUT);
  pinMode(ArmButt, INPUT);        // set "ARM" button pin to input
  pinMode(GoButt, INPUT);         // set "GO" button pin to input
  digitalWrite(Fuse, LOW);        // OPEN the fuse circuit.
  digitalWrite(ArmButt, HIGH);    // turn on pull up resistor
  digitalWrite(GoButt, HIGH);     // turn on pull up resistor
  mySerialPort.begin(9600);
  delay(10);                      // Wait for Serial Display start up
  mySerialPort.print("v")      // Reset the display
  mySerialPort.print("z")      // Brightness
  mySerialPort.write(0x40);       // 3/4 Intensity
  mySerialPort.print("w")      // Decimal Point Control
  mySerialPort.write(0x10);       // turn on the colon ":"
}
int  DownCntr;                    // down counter (1/10 Secs)
int  Go = 0;                      // Stopped
void loop() {
  if (!digitalRead(GoButt) || !digitalRead(ArmButt)) {
    Go = 0;                       // Stops the countdown
    tone(BuzzPin, 440, 1500);
    delay(1500);
  }
  if (Go == 0) {
    WaitARM();
    WaitGO();
  }
  ShowTimer();
  if (DownCntr > 50) {
    if (DownCntr % 10 == 0)tone(BuzzPin, 1000, 50); // Beeps every second
  }
  else if (DownCntr % 2 == 0)tone(BuzzPin, 1000, 50); // Beep goes faster

  if (DownCntr == 0) {
    tone(BuzzPin, 440, FuseTIME);  // Launch tone
    digitalWrite(Fuse, HIGH);      // CLOSE the fuse circuit
    delay(FuseTIME);
    digitalWrite(Fuse, LOW);       // OPEN the fuse circuit
    Go = 0;
  }
  while (millis() % 100);         // wait for a moment
  delay(50);
  DownCntr--;
}

void WaitGO() {
  ShowTimer();
  while (digitalRead(GoButt));
  Go = 1;

  delay(20);
  while (!digitalRead(GoButt));   //  Debounce the GO button
}
void ReadTimer() {
  DownCntr = map(analogRead(SetPot), 0, 1023, 5, 60);
  DownCntr *= 10;
}
void ShowTimer() {
  String seconds = String (DownCntr, DEC);
  while (seconds.length() < 3)seconds = "0" + seconds; // format to 3 numbers
  mySerialPort.print(seconds);                         // Write to Display
  mySerialPort.print(" ");                             // Last digit switched off
}
void WaitARM() {
  while (digitalRead(ArmButt) == 1) {
    ReadTimer();
    delay(50);
    ReadTimer();
    ShowTimer();
    delay(150);
  }
  Go = 0;
  ShowTimer();
  tone(BuzzPin, 2000, 150);
  delay(200);
  tone(BuzzPin, 2000, 150);
  delay(200);
  tone(BuzzPin, 2000, 150);

  delay(20);
  while (!digitalRead(ArmButt));  // Debounce the ARM button

}
1 Like
mySerialPort.print("w")      //
1 Like

I’m not sure what

mySerialPort.print("w")      //

is supposed to accomplish. This changes nothing.

I tried the auto format and this does nothing to the code.

1 Like

I was pointing out the source of your compilation error

1 Like

This results in a

Rocket_Launcher_updated_2 2:29 : error expected ';' before 'mySerialPort' MySerialPort.write(0x10); // turn on the colon ":"

1 Like

In reply #8 I pointed out the source of the compilation error.

1 Like

Seoul_lasers: I'm not sure what

mySerialPort.print("w")      //

is supposed to accomplish. This changes nothing.

I tried the auto format and this does nothing to the code.

Put the ; at the end of the line

1 Like

Hi,

Rocket_Launcher_updated_2 2:29 : error expected ‘;’ before ‘mySerialPort’
MySerialPort.write(0x10); // turn on the colon “:”

Read it.

EXPECTED “;” BEFORE ‘mySerialPort’

The next line then tells you BEFORE which line,

So BEFORE

this line in your code

MySerialPort.write(0x10);     // turn on the colon  ":"

is your error.

The statement BEFORE is,

mySerialPort.print("w")      //

Now what did the error message say was missing?

Tom… :o :o :o :o :o :o :o
[sarcasm] HINT: “;” [/sarcasm]

1 Like

Well, thanks for the sarcasm. :roll_eyes:

I was trying to fix an out of date code utilizing an incorrect library.

I was hoping someone would explain the error as I am still learning the language. Hopefully the new code works.

However, I managed to compile the original without errors despite the , missing ; so go figure. The display is messed up however and flipping around random characters.

Thanks again... I think I'll go elsewhere next time. I don't appreciate being trolled.

1 Like

Hi, Missing ; is common, we all do it. It is a case of getting to interpret the errors.

An error is usually cited, then the next valid line is quoted to act as marker, they also quote a line number.

As you can see, if you get in the habit of laying out your code and using AutoFormat as you write your code you can minimise errors as you go.

You can consider AutoFormat as a sort of basic compiler error detector, lol.

Tom.. :) PS. Did you go through the rest of your code? There are quite a few missing } and extra {} that will be disrupting code flow.

1 Like