Go Down

Topic: ATtiny and tone() (Read 14472 times) previous topic - next topic

Mixe

Jan 13, 2017, 09:08 am Last Edit: Jan 13, 2017, 11:02 am by Mixe
Hi all

I've been trying to get the tone() function to work on an ATtiny45. It won't happen. When I search for info I find all these threads about how well it works, and even though I copy their sketches they won't produce sound on mine.

I use a small piezo connected to pin 1. The code is really simple:

Code: [Select]

#define PIEZO 1

void setup(){
pinMode(PIEZO, OUTPUT);
}

void loop(){
tone(PIEZO,500);
delay(1000);
noTone(PIEZO);
delay(1000);
}


Like that. Not a sound. Naturally I tried the piezo on an UNO, and that works fine. I also tried the piezo with another tone library (http://w8bh.net/avr/TrinketTone.pdf) and that worked. But it uses delays, so I can't have it. It would interfere with the other code I need to run on the chip.

I use an UNO as ISP, and the board settings are downloaded from board manager. I get no complaints from the compiler when I call tone(), so it seems to be included. I've tried both 1 and 8 MHz.

Any ideas? I'm lost.


Mixe

Ok, not a lot of answers. But I found the error myself and thought I'd share it so noone else needs to spend several days on this.

The ATtiny core provided in the board manager is faulty. The tone() function is included but doesn't work. When I installed an older ATtiny core it works just fine!

Installing that was a bit of a hassle for me though, since the install instructions in the "ReadMe" file are obsolete. I'm on mac, and had to find the library folder/Arduino15  etc to manually insert the board profiles into the existing boards.txt. Probably a piece of cake for someone more at ease under the hood than me.

Does anyone know who you contact about a found error in the cores provided by the boards manager? 

pert

The ATtiny core provided in the board manager is faulty.
Which one? Before you were able to install the core via Boards Manager you had to add a URL to File > Preferences > Additional Boards Manager URLs. Don't you think it would have been helpful to specify which URL you used?

Does anyone know who you contact about a found error in the cores provided by the boards manager?  
The author of the core. I can't tell you who that is because you didn't specify which Boards Manager URL you used. I can tell you who you should not contact about the issue, the Arduino IDE developers who have nothing to do with that 3rd party core other than being kind enough to allow 3rd party hardware packages to be installed via Boards Manager. This despite the fact that 3rd party hardware cuts into the sales of Arduino's products which support the development of the Arduino IDE. Now they have to deal with support requests for these cores. For this reason I would recommend you to close your issue report:
https://github.com/arduino/Arduino/issues/5848
unless you have determined that this is absolutely a bug with the Arduino IDE or Arduino AVR Boards core, which I really doubt.

DrAzzy

#3
Jan 14, 2017, 05:45 pm Last Edit: Jan 14, 2017, 05:46 pm by DrAzzy
Which core? On my core, I haven't touched tone() since I got it working off the fancy timer1, so I'm pretty sure it works. If it's my core, and it doesn't work, that's something i should be made aware of so I can fix it

On my core, use pin 4 fit best results with tone, btw - though I remember testing it on the scope with both pin 4 and someven other pin
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Mixe

#4
Jan 15, 2017, 10:59 pm Last Edit: Jan 16, 2017, 09:25 am by Mixe
Ok, I downloaded version 1.02 of attiny by David A. Mellis. Is that yours?

And I will naturally close my issue report. I started that for lack of better advice- and, I might add, in an attempt to be helpful.

uxomm

Ok, I downloaded version 1.02 of attiny by David A. Mellis. Is that yours?
It is https://github.com/SpenceKonde/ATTinyCore
Always decouple electronic circuitry.

DrAzzy

#6
Jan 16, 2017, 04:25 am Last Edit: Jan 16, 2017, 04:27 am by DrAzzy
Huh, I thought he had gotten that working... I thought i remember that coming up a while back

Mine is this one https://github.com/SpenceKonde/ATTinyCore

ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

pert

Here's the damellis/attiny tone() issue report:
https://github.com/damellis/attiny/issues/21
The problem is that damellis/attiny references the arduino:arduino core, it doesn't include its own implementation of tone(). The arduino:arduino core's tone() doesn't work on ATtiny85. That would have been understandable before the ATtiny85 based Gemma was added as an official Arduino board but now it does constitute a bug, which has been reported:
https://github.com/arduino/Arduino/issues/3519
So everyone involved is aware of this issue but nobody seems to be motivated to do anything about it. Luckily we have DrAzzy's excellent ATTinyCore to save the day! I recommend you to use that core instead of the much less capable damellis/attiny.

Mixe

#8
Jan 16, 2017, 08:19 am Last Edit: Jan 16, 2017, 09:24 am by Mixe
Thanks for the info! Beeing a relative newbie, I followed a tutorial on how to get the ATtiny:s from board manager. In a perfect world that core should have a warning when included by the  Board Manager until issues are solved. Or just remove the reference to the Arduino tone(),  so you'll at least get an error when compiling. But then again, I'm not capable of doing that myself, and in a world of open source you probably shouldn't ask people to do stuff you're not doing yourself.

Anyway, thanks for the info and advice. I have now found a fully working core. Unfortunately, this costed me precious evenings when trying to get a prototype working for a crucial demonstration.

pert

maybe that core should be removed from Board Manager until issues are solved?
You're misunderstanding how Boards Manager works. There are several official Arduino cores(AVR. SAM, SAMD) and also some Arduino certified packages(e.g. Edison, Galileo, Curie) always available for installation via Boards Manager. Those companies pay a licensing fee to be "Arduino Certified". Originally official and certified cores were all that was available via Boards Manager. Next, Adafruit figured out how to hack the Arduino IDE to make it possible to install the esp8266 core via Boards Manager. Soon after that Arduino opened Boards Manager up to make it super easy for users of the Arduino IDE to install and update 3rd party hardware packages via Boards Manager, which previously had required a slightly more complex manual installation process and didn't have update notifications. So now anyone who wants to make their hardware package installable via Boards Manager can easily do so. All the user needs to do is add the URL to their JSON file to File > Preferences > Additional Boards Manager URLs. When you followed the tutorial that's what you did, maybe you forgot about it. Without that URL damellis/attiny would not be available via Boards Manager. So if you want to remove the "attiny by David Mellis" entry from Boards Manager, just remove that URL(https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json) from your preferences. Arduino has no control over what URLs the user adds to their preferences. It's worth spending a bit of time researching the available options and auditing your choice before deciding on a 3rd party hardware package because there is definitely a lot of variation in the quality of them. If you had clicked the "More info" link in the "attiny by David Mellis" Boards Manager entry and then done a search for tone in the issue tracker you would have quickly seen that tone() is not currently supported by that package.

damellis/attiny is a very simple project because it references the Arduino AVR Boards core. This made it easy to write and less effort to maintain than a project like ATTinyCore, which includes its own core. damellis/attiny still works well for many uses but not having its own core does impose limitations in that any necessary core modifications must be pushed to the Arduino AVR Boards core. I think the Arduino developers would be happy to merge a pull request that adds ATtiny85, etc. support to tone(), someone just needs to make the effort to submit the pull request. damellis/attiny was good in its day and many people are still using it but now we have very actively maintained superior core provided by the hard work of DrAzzy.

I'm actually the person who added Boards Manager installation support to damellis/attiny. It was the first project I did this for right after that capability was added to the Arduino IDE because at that time I was using damellis/attiny and was unaware of ATTinyCore so I thought it would be a useful contribution to the Arduino community. Since then David Mellis has made it the official installation method for the project and it's actually a little tricky to do a manual installation of it now.

silly_cone

DrAzzy, do you have plans to update your core to allow use of the tone() function?

I tried manually adding the core the OP linked to, but I ran into a slew of compiler errors.

The totality of the code is:

Code: [Select]
void setup() {
 pinMode(4, OUTPUT);
}

void loop() {
  tone(4, 2000);
}


So I'm pretty sure it has to do with broken pathways.  I've already removed the old core, so I don't have the errors handy, but does anyone know if there are detailed instructions for manually installing new cores for IDE 1.6.9?

DrAzzy

#11
Feb 06, 2017, 11:12 pm Last Edit: Feb 06, 2017, 11:13 pm by DrAzzy
My core supports tone() - if it's not working, that's news to me.
Last I checked on the tiny85 with a simple test sketch (something like what you have), the code compiled and produced output at the specified frequency (verified with the scope, with both the hardware timer pin, and a different pin using the interrupt).

Since you're using 1.6.9, make sure that LTO is disabled in the tools menu - the new compiler version that supports it came with 1.6.11 (specifically, AVR boards 1.6.13 is what brings the new compiler version - It comes with IDE version 1.6.11) - if you have that enabled on a version that doesn't support it, nothing will compile.

Assuming that doesn't fix it, please post the full text of any and all error messages.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

silly_cone

Hi DrAzzy, I'm still not having any luck with the piezo, unfortunately.  There are no compiler errors or anything that pop up.  The errors I mentioned above were from using the Tiny Core and I'm pretty sure it had to do with broken directory pathways for accessing the compiler.

I'm using your core (Attiny Core by Spence Konde from the link you gave above) version 1.1.2, and I've tried several combinations of clock speeds still to no avail.  Currently, I have Timer1 set to CPU, Clock is 8 MGHz internal, BOD and LTO both disabled.  I've tried using pins 0, 1, 2, and 4.  And I've tried several attiny85 chips as well.

The piezo I'm using tests fine when plugged into a nano.  But all I get from the attiny is a single small click right when its powered on.  When I plug an LED into the pins and send it a PWM signal, the LED lights up like it should.  The only way I'm able to get any sound of the piezo at all is to send it a PWM signal of ~250 or less.  Then it buzzes, but its not a very clean sound.

Mixe

That sounds exactly like the errors I got when I was using David A Mellis' ATtiny core. Are you sure you are using the right core? The one I got to work was this one.
Not without some hiccups though- I too get error messages when compiling, but that's just phrase confusement and the compiler seems to correct it automatically. They look like this:
Code: [Select]

Board arduino:avr:attiny85at1 doesn't define a 'build.board' preference. Auto-set to: AVR_ATTINY85AT1


It  should be easy enough to change the faulty preference phrase, but it works and I haven't bothered.




silly_cone

I uninstalled the Damellis core both from the preferences and the board manager.  It no longer appears anywhere in the program.  The Spence Konde ATTiny Core is the only one that shows up.

I'll go back and try the other Tiny Core from here and see if I can get past those error codes (they do look the same as what I was getting).  What did you do to correct them?  And I apologize if you already covered this in a previous post.

Go Up