Can't get Coburn's code for Buzz Wire Game to compile

My 10 year-old grandson and I are both new to Arduino. I want to prepare a project to do with him for Christmas, and I found Joe Coburn's Buzz Wire Game on Make Use Of from 9/21/16.

It looks like something he could get into and we could do together, but I can't get the code he posted to work.

He refers to pitches.h and I followed the instructions for creating a new tab and copying in the code. But when I compile, I get an error "No such file or directory", even though I see it in the Arduino\BuzzWire folder along with BuzzWire.ino.

He also gives instructions for bringing in and editing TM1637.cpp. The editing is to expand the numbers and letters that can be displayed. However, I'm also getting an error on this, both with and without the edits. When he explains the editing he says to edit .cpp and not .h, but the code includes the line "#include <TM1637.h>" and that's where the error occurs.

I am working from the Arduino Starter Kit and I've already ordered the additional items needed for this project, but I'm hoping someone can help me with the coding.

Thanks!

  • Jeff

Read the how to use this forum sticky to see how to post code and error messages. It will go a lot faster if you know and follow the guidelines.

Then post the code that you are having trouble with and the entire text of the error message(s) and we can help.

Which Arduino board are you using?

groundFungus:
Read the how to use this forum sticky to see how to post code and error messages. It will go a lot faster if you know and follow the guidelines.

Then post the code that you are having trouble with and the entire text of the error message(s) and we can help.

Which Arduino board are you using?

Thanks, groundFungus. Sorry for not providing enough information. I had read "How to Post", but I was trying to summarize and get direction before dumping all the code. I'm using an Arduino Uno (from the Starter Kit). [And now, after I had added all the code, I got the forum error "Exceeding 9000 characters". I'm not really sure what is needed in order to isolate the problem, but I'm minimizing it now. Please let me know what is needed.]

I had posted the full code from Coburn's project instructions, but below are just the first few lines, which are getting the errors. I'm also posting the error messages for pitches.h, and the code for TM1367 (which it says is installed when I search for it in Manage Libraries).

The first few lines of Coburn's code for the project:

#include <TM1637.h> // include display library
#include <pitches.h> // include pitches

TM1637 *_display = new TM1637(12, 13); // create display object, 12 = CLK (clock), 13 = D10 (data)

// etc. ...

When I compile Coburn's code, the first line returns the error:

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Uno"

BuzzWire:1:47: error: TM1637.h: No such file or directory

compilation terminated.

exit status 1
TM1637.h: No such file or directory

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

When I rem that line out and recompile, the second line returns this error:

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Uno"

BuzzWire:2:40: error: pitches.h: No such file or directory

compilation terminated.

exit status 1
pitches.h: No such file or directory

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Should I also include the code for pitches.h and TM1637.cpp?

I followed the instructions in the Joe Coburn's Buzz Wire Game page that you linked and get the same errors. I installed the TM1637 library through the library manager. In the TM1637 library folder are TM1637Display.h (and TM1637Display.cpp) instead of the TM1637.h file that the program is #including. I believe that that is the source of the error.

OK, I got it to compile, but cannot test. Here is what I did.

Since the library downloaded from the library manager did not seem to be the right one I started looking for an alternative. The page mentioned that the library was written by Seeed so I looked there. There is a library for the TM1637 there. Download the zip file of the library form this page. Once downloaded, go to Sketch, Include Library, Add Zip Library. Click that and navigate to where the downloaded zip file is. Double click the
Seeed_Grove_4Digital_Display_g-master.zip file and it will be installed.

If you have not, copy the pitches.h file into a tab in your program in the IDE and name the tab pitches.h.
Change the line #include <pitches.h> to #include "pitches.h".

The program should compile. If successful, make the changes to the .ccp file and try again. The TM1637.cpp file will be in the Seeed_Grove_4Digital_Display_g-master folder in the libraries folder (not a TM1637 folder like the page says).

Wow! Thanks very much. I haven't tried it yet, but I will do so tomorrow and report back.

  • Jeff

Those are excellent and clear instructions, groundFungus. This worked perfectly! Many thanks.

I have not built the circuit yet, but I'm expecting the components I need to arrive today so hopefully all will go well.

Again, thanks! This is my first posting, so I don't know how the "karma" feature works, but I'm going to try it now.

  • Jeff

Thank you for the feedback. If you have trouble with the project once you get the parts, I will be glad to help.

Well, I don't know if this should be a new thread, but I'm building the circuit now and just realized the starter kit has an LCD display but the project uses a 7-segment display. Coburn specifically references a Seeed model which won't ship until December 23rd and will cost $20 to arrive in 1-3 days, or $5 to arrive in 10-28 days after that.

So I have two questions:

  1. Could I adapt Coburn's code to the LCD display (with the understanding that I'm a know-nothing beginner)?

  2. Could I use this Adafruit model from Amazon, which will be here Saturday for free through Prime? And if so, is this description enough to indicate I'm likely to be able to connect it as Coburn describes:

Amazon:
I2C Backpack (Requires Soldering) that allows the display to be driven with just 4 pins!
Setup guide and Arduino libraries available from Adafruit

To clarify the situation, I'm trying to complete this project and test it now, so I can take it apart and redo it with my 10-year old grandson as a Christmas activity. There is a third option regarding the display: It's not essential to the project, so I could skip it for now and add it in later if the project goes well with my grandson.

  1. Could I adapt Coburn's code to the LCD display (with the understanding that I'm a know-nothing beginner)?

I have looked at the code and believe that it will not be terribly difficult to modify the code to use an LCD. The first challenge is to get the LCD to work by itself and display data that you hard code (the "hello world" example, for example).

Can you post photos of the LCD from the starter kit so that I know what we are working with? Front and back sides?

How to post images.

Here goes ...

OK, that is a "standard" 1602 display. Can you install the hd44780 LCD library? Use the library manager like you did with the TM1637 library. Once the library manager window is open select displays in the Topic drop down and enter hd44780 in the Filter box. Select and install the hd44780 by Bill Perry library.

Looking at the photo of the front of the LCD, pin 1 is on the top left and pin 16 on the right. The LCD is right side up in the photo. Plug the LCD into your breadboard and wire the LCD as follows.

Uno pin LCD pin
ground 1
Vcc(5V) 2
see below1 3
11 4
to ground 5
12 6
7-10 not connected
4 11
5 12
6 13
7 14
Vcc(5V) 15
see below2 16

1 tie pin 3 of the LCD to ground through a 1K resistor. This sets the contrast.
2 Tie pin 16 of the LCD to ground through a 220 to 470 Ohm resistor. This sets the backlight.

I will put some test code in the next post.

Here is the test code. This has been tested on my Uno with a 1602 16x2 LCD with 4 pin interface.

//Modified hd44780 library (by Bill Perry) "hello world" example.  Mod by C. Goulding

#include <hd44780.h>
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header

const int rs = 11, en = 12, db4 = 4, db5 = 5, db6 = 6, db7 = 7; // for all other devices

hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{
   lcd.begin(LCD_COLS, LCD_ROWS);
   // Print a message to the LCD
   lcd.print("Hello, Jeff!");
}

void loop() {}

I think I have it wired correctly, but when I upload I get this error:

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Uno"

Sketch uses 3148 bytes (9%) of program storage space. Maximum is 32256 bytes.
Global variables use 108 bytes (5%) of dynamic memory, leaving 1940 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "\\.\COM3": The system cannot find the file specified.


Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I see it's looking for COM3, but I'm using a different UNO for this and my computer automatically sets it up as COM4. I can't see where to change that.

Here is the wiring as I set it up. I've tied pins 4, 6, 11, 12, 13, and 14 to keep them out of the way and show the Grounding pins (1, 3, 16) and the Power pins (2 and 15). Pin 3 has a Brown/Black/Red resistor (1k) and pin 15 has a Red/Red/Brown (220).

Hold on!! I went into Device Manager and deleted COM4, refreshed, then deleted COM3, and rebooted. That cleared the ports and set up COM3 for this test. (So does Arduino require COM3? I'm using Windows 10.)

And it worked! "Hello, Back-at-you!" (I feel funny calling you groundFungus ... feels almost like an insult. :confused: )

So now I need to replicate these connections in my Buzz Wire project and replace Coburn's display code with your code, right?

You have been very patient with me and very much appreciate it. I'm hoping you are willing to bear with me a little longer because my initial tests with the project setup did not go that well. I want to bring this display in then retest and I might need to ask a couple more questions.

Many thanks,

  • Jeff

Glad to know that the LCD works.

You choose the com port in the Tools menu. Click on Ports and the port that the Uno is connected to will show and can be selected.

It is a bit more complicated than just replacing a few lines to put the LCD in place of the 7 seg. display. The data was written to the TM1637 a digit at a time, but with the LCD you can write the line at a time. Use the setCursor() function to place the cursor on the character position and line that you want to write to. Give me a little time and I will get started and post code later.

Here is the code with the TM1637 stuff removed and the LCD stuff inserted. Note that I had to change one pin as there was a conflict between one of the buzzers and the LCD. Changed the buzzer to pin 8. See comment in code. Don't forget to copy the pitches.h file into a tab. The #include is already fixed. Code tested to the extent that I can without building the entire circuit. You now have a lot more flexibility in terms of what you can display.

#include <hd44780.h>
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
#include "pitches.h" // include pitches

const int rs = 11, en = 12, db4 = 4, db5 = 5, db6 = 6, db7 = 7; // for all other devices

hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;

// music
int songState = 0;

int melody[] =
{
   NOTE_F4, NOTE_E4, NOTE_D4, NOTE_CS4,
   NOTE_C4, NOTE_B3, NOTE_AS3, NOTE_A3,
   NOTE_G3, NOTE_A3, NOTE_AS3, NOTE_A3,
   NOTE_G3, NOTE_C4, 0,

   NOTE_C4, NOTE_A3, NOTE_A3, NOTE_A3,
   NOTE_GS3, NOTE_A3, NOTE_F4, NOTE_C4,
   NOTE_C4, NOTE_A3, NOTE_AS3, NOTE_AS3,
   NOTE_AS3, NOTE_C4, NOTE_D4, 0,

   NOTE_AS3, NOTE_G3, NOTE_G3, NOTE_G3,
   NOTE_FS3, NOTE_G3, NOTE_E4, NOTE_D4,
   NOTE_D4, NOTE_AS3, NOTE_A3, NOTE_A3,
   NOTE_A3, NOTE_AS3, NOTE_C4, 0,

   NOTE_C4, NOTE_A3, NOTE_A3, NOTE_A3,
   NOTE_GS3, NOTE_A3, NOTE_A4, NOTE_F4,
   NOTE_F4, NOTE_C4, NOTE_B3, NOTE_G4,
   NOTE_G4, NOTE_G4, NOTE_G4, 0,

   NOTE_G4, NOTE_E4, NOTE_G4, NOTE_G4,
   NOTE_FS4, NOTE_G4, NOTE_D4, NOTE_G4,
   NOTE_G4, NOTE_FS4, NOTE_G4, NOTE_C4,
   NOTE_B3, NOTE_C4, NOTE_B3, NOTE_C4, 0
};

int tempo[] =
{
   8, 16, 8, 16,
   8, 16, 8, 16,
   16, 16, 16, 8,
   16, 8, 3,

   12, 16, 16, 16,
   8, 16, 8, 16,
   8, 16, 8, 16,
   8, 16, 4, 12,

   12, 16, 16, 16,
   8, 16, 8, 16,
   8, 16, 8, 16,
   8, 16, 4, 12,

   12, 16, 16, 16,
   8, 16, 8, 16,
   8, 16, 8, 16,
   8, 16, 4, 16,

   12, 17, 17, 17,
   8, 12, 17, 17,
   17, 8, 16, 8,
   16, 8, 16, 8, 1
};

// non blocking setup
// free play
unsigned long previousMillis1 = 0; // time words last changed
const long interval1 = 1500; // interval between changing

// music
unsigned long previousMillis2 = 0; // time last changed
const long interval2 = 100; // interval between notes

int displayStatus = 0; // keep track of what's displayed
int mode = 0; // keep track of game mode -- change to 0 or 1 for different modes

bool countdown = false;

unsigned long previousMillis3 = 0; // time last changed
const long interval3 = 1000; // interval between countdown
int count = 20; // challenge mode timer

void setup()
{
   // put your setup code here, to run once:
   pinMode(9, INPUT); // setup circuit
   pinMode(10, OUTPUT); // setup buzzer 1
   pinMode(8, OUTPUT); // setup buzzer 2  // had to change this pin. conflict with LCD
   pinMode(2, INPUT); // setup button

   lcd.begin(LCD_COLS, LCD_ROWS);
   lcd.print("BUZZ REAADY");
   delay(1000);
   lcd.clear();
}

void loop()
{
   // put your main code here, to run repeatedly:
   if (mode == 0)
   {
      // challenge mode
      if (digitalRead(2) == HIGH)
      {
         delay(25);
         if (digitalRead(2) == HIGH)
         {
            countdown = true; // stop the countdown
         }
         else
         {
            countdown = false; // stop the countdown
         }
      }
      if (countdown)
      {
         showCountdown(); // advance countdown
      }
   }
   else
   {
      // free play
      toggleFreePlay();
   }
   if (digitalRead(10) == HIGH)
   {
      delay(25);
      if (digitalRead(10) == HIGH)
      {
         while (digitalRead(10) == HIGH)
         {
            buzz(11, NOTE_B0, 1000 / 24);
         }
      }
   }
   else
   {
      sing();
    }
}

void showCountdown()
{
   // countdown the time remaining
   unsigned long currentMillis = millis(); // current time
   if (currentMillis - previousMillis3 >= interval3)
   {
      previousMillis3 = currentMillis;
      --count;
      showNumber(count);
      if (count == 0)
      {
         // game over
         countdown = false;
         count = 20;
         // reset countdown
         // buzz 3 times
         buzz(11, NOTE_B0, 1000 / 24);
         delay(100);
         buzz(11, NOTE_B0, 1000 / 24);
         delay(100);
         buzz(11, NOTE_B0, 1000 / 24);
      }
   }
}

void showNumber(int number)
{
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("-- ");  
  lcd.setCursor(7,0);
  lcd.print(number);
  lcd.print(" --");
}

void toggleFreePlay()
{
   // scroll between words without blocking
   unsigned long currentMillis = millis(); // current time
   if (currentMillis - previousMillis1 >= interval1)
   {
      previousMillis1 = currentMillis;
      if (displayStatus == 1)
         showPlay();
      else
         showFree();
   }
}

void showPlay()
{
   // write "PLAY" to the display
   lcd.clear();
   lcd.setCursor(6,0);
   lcd.print("PLAY");
   displayStatus = 2;
}

void showFree()
{
   // write "Free" to the display
   lcd.clear();
   lcd.setCursor(6,1);
   lcd.print("FREE");
   displayStatus = 1;
}

void buzz(int targetPin, long frequency, long length)
{
   /* Buzzer example function by Rob Faludi
      http://www.faludi.com
      https://gist.github.com/AnthonyDiGirolamo/1405180
   */
   long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
   //// 1 second's worth of microseconds, divided by the frequency, then split in half since
   //// there are two phases to each cycle
   long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
   //// multiply frequency, which is really cycles per second, by the number of seconds to
   //// get the total number of cycles to produce
   for (long i = 0; i < numCycles; i++) // for the calculated length of time...
   {
      digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphragm
      delayMicroseconds(delayValue); // wait for the calculated delay value
      digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphragm
      delayMicroseconds(delayValue); // wait again for the calculated delay value
   }
}

void sing()
{
   // play the song in a non blocking way
   unsigned long currentMillis = millis();

   if (currentMillis - previousMillis2 >= interval2)
   {
      previousMillis2 = currentMillis;
      int noteDuration = 1000 / tempo[songState];
      buzz(10, melody[songState], noteDuration);
      int pauseBetweenNotes = noteDuration;
      delay(pauseBetweenNotes);

      // stop the tone playing:
      buzz(10, 0, noteDuration);

      ++songState;
      // start song again if finished
      if (songState > 79)
      {
         songState = 14; // skip intro
      }
   }
}

Have fun, Charlie.

Outstanding! I'm looking forward to trying this, Charlie. I've done a good deal of coding in VBA for Excel, but never in C++ (or any other language). I'm getting a bit of education about C++ and circuits both.

jjeffh:
I'm getting a bit of education about C++ and circuits both.

And that's all part of it: you start by just trying to get something done because you have a result in mind, which looks dead simple because it's all written in a book, and learn stuff along the way too. (Although my kids are both engineers in their 20s (fire and electrical, respectively*), no grandkids here yet. I guess my days of Christmas projects have still to come.)

*Just had a thought about that: if one's sparks cause a fire, we should be safe.

Kudos to groundFungus for the way he handled this thread. Certain other members could learn from that....

Thanks, ardy_guy and Jeff.

Jeff, as you go along with learning you will see that the circuit could use some small improvements. The push button switch could be wired to ground and use the internal pullup resistor instead of the external pull down and wand could be wired the same without the voltage divider. That is, the course wired to ground and the wand to a digital input with the internal pullup. The logic for the push button and the wand would need to be adjusted for active low logic.

ardy_guy:
... Kudos to groundFungus for the way he handled this thread. ...

Hear! Hear!

groundFungus:
Jeff, as you go along with learning you will see that the circuit could use some small improvements. The push button switch could be wired to ground and use the internal pullup resistor instead of the external pull down and wand could be wired the same without the voltage divider. That is, the course wired to ground and the wand to a digital input with the internal pullup. The logic for the push button and the wand would need to be adjusted for active low logic.

I'm afraid all that just zinged right over my head. I'm still working on what ardy-guy called the "dead simple" stuff: copying directly out of the book and hoping something works.

I haven't started yet today, but in my tests yesterday the Monty Python theme Coburn programmed in played fine, but when I touched the wand and course leads, I didn't get a buzz, which is the point of the project.

And regarding the Monty Python theme, much as I like it, the circuit tweak that occurred to me was a way to turn it on and off, or at least subdue it. Coming out of that little piezo it kind of grates after a while. (Not to mention it clearly bothered my cat!)

I'll be starting over today with the new code to see what I get. Wish me luck!

BTW, the lesson in how to use the 2 line LCD display really gives me something I think I can play with with Chance (the grandson) aside from this project.