ZappBots wishes a warm welcome to everyone.

Especially our visitors from
Savage///Circuits and Parallax!!!


Please take a look our new forums, we hope you register and become an active user.

The ZappBots forums are being run on phpBB 3.1.4 software which is different then the vBulletin used on the Savage///Circuits and Parallax forums.
Therefore, things look and work a little different, especially creating posts and uploading images / attachments.


The important thing is we have a place toTalk, Learn and Showcase our projects.

SOLVED - DigiSpark Tone() Statement

This is the place to talk about Arduino Boards and their clones
User avatar
Granz
Member
Member
Posts: 130
Joined: Sun May 31, 2015 2:37 pm
Location: Pittsburgh, PA, USA, Terra, Sol, Andromeda Arm, Milky Way Galaxy, Milky Way Cluster, Local Universe
Contact:

SOLVED - DigiSpark Tone() Statement

Postby Granz » Fri Feb 02, 2018 9:33 pm

I posted this on the DigiSpark forum, but thought that I might ask here too, in case anyone here might have an idea:

I'm having troubles with the tone() statement.

My circuit is just connecting a speaker to an I/O pin, and then through a resistor to ground:
Image
Image
(Sorry about the flipped image, not sure why the forum software wants to put it upside-down.)

When I upload the sketch (I hate that term, when I upload the program), I get no sound:

Code: Select all

//A sketch to demonstrate the tone() function

//Specify digital pin on the Arduino to which the positive lead of the speaker is attached.
 int SpkrPin = 0;

void setup() {
    pinMode(SpkrPin, OUTPUT);
} //close setup

void loop() {

  tone(SpkrPin, 2000);

//  digitalWrite(SpkrPin, HIGH);
//  delay(2);
//  digitalWrite(SpkrPin, LOW);
//  delay(2);

}


I have tried with and without the pinMode() statement, and have also added a digitalWrite() statement to initially set the pin high (and low) - I saw someone somewhere say that you needed that.

When I uncomment the digitalWrite() statements to toggle the I/O pin, and comment out the tone() statement, I get a tone. Changing the delay() statements works as expected. The scope (connected to the green line on the schematic) shows: (BTW, thanks for the 'scope Jason, it has come in handy.)
Image

In addition, I have tried all 6 of the I/O pins, none of them give a tone (all show 0V on my scope, except for P5, which shows constant high.)
Image
When I switch to an Arduino Uno, I get the tone from the speaker, using either the digitalWrite, or the tone() statements.

Does anyone have any ideas where I am going wrong?
Last edited by Granz on Sat Mar 10, 2018 5:22 am, edited 1 time in total.
Art G. Granzeier III, President
GranzTronix
http://projects.granzeier.com
Helping to Build a Better Engineer

User avatar
Granz
Member
Member
Posts: 130
Joined: Sun May 31, 2015 2:37 pm
Location: Pittsburgh, PA, USA, Terra, Sol, Andromeda Arm, Milky Way Galaxy, Milky Way Cluster, Local Universe
Contact:

Re: DigiSpark Tone() Statement

Postby Granz » Sat Mar 10, 2018 5:21 am

For closure:

PeterF, over on the Digistump forum (http://digistump.com/board/index.php/topic,2857.0.html) was able to give me an answer that worked. It turns out that on the Digispark, the tone() function only sets up the tone. To actually hear it, you need to have a delay. Apparently, the full-sized Arduino plays tones in the background, but this does not work on the Tiny85 (the controller for the Digispark.)
Art G. Granzeier III, President
GranzTronix
http://projects.granzeier.com
Helping to Build a Better Engineer

User avatar
zappman
Administrator
Administrator
Posts: 115
Joined: Wed May 06, 2015 12:31 am
Contact:

Re: DigiSpark Tone() Statement

Postby zappman » Sat Mar 10, 2018 11:17 am

Granz wrote:For closure:

PeterF, over on the Digistump forum (http://digistump.com/board/index.php/topic,2857.0.html) was able to give me an answer that worked. It turns out that on the Digispark, the tone() function only sets up the tone. To actually hear it, you need to have a delay. Apparently, the full-sized Arduino plays tones in the background, but this does not work on the Tiny85 (the controller for the Digispark.)


Thanks for this info, as I may be getting some Digistump Tiny85 boards.
Image
butlh ghajbogh nuv'e' yIHo'.
Admire the person with dirt under his fingernails.

User avatar
Granz
Member
Member
Posts: 130
Joined: Sun May 31, 2015 2:37 pm
Location: Pittsburgh, PA, USA, Terra, Sol, Andromeda Arm, Milky Way Galaxy, Milky Way Cluster, Local Universe
Contact:

Re: DigiSpark Tone() Statement

Postby Granz » Sat Mar 10, 2018 5:40 pm

zappman wrote:...Thanks for this info, as I may be getting some Digistump Tiny85 boards.

Glad I could help. They really are pretty cool little things. I love that they plug directly into the USB port (or a USB extension cable.)
Art G. Granzeier III, President
GranzTronix
http://projects.granzeier.com
Helping to Build a Better Engineer


Return to “Arduino Boards”

Who is online

Users browsing this forum: No registered users and 1 guest