0

I want to communicate over serial to another device (dfplayer) and also set the microcontroller into sleep mode.

The ATtiny85 does not have a hardware serial pin so I need to use a virtual serial (like SoftwareSerial.h)

I've googled a lot and tried a lot of things but it basically seems to come always to the same problem. SoftwareSerial (or NeoSWSerial) do not work with avr/sleep. Something to do with interrupts,

NeoSWSerial.cpp.o (symbol from plugin): In function NeoSWSerial::read()': (.text+0x0): multiple definition of __vector_2' .pio\build\attiny85\src\main.cpp.o (symbol from plugin):(.text+0x0): first defined here

AltSoftSerial won't work because it requires a 16bit timer which the ATtiny does not have__

Is there anything I can do about this?


What I actually want to do

Connect 6 buttons with 6 different resistors to a single ADC pin of the controller. When a button is pressed wake up the device /if necessary), read the ADC value, pick a track based on that value and then play the track on the dfplayer.

After a while, if no button is pressed, put the dfplayer and the mcu to sleep. And that's why I need the mcu at all. You can't set the dfplayer to sleep or wake it up without serial


Update:

I confused SPI and Serial indeed. I need to use serial communication

I want to send and receive packages. Send: InitCommand, Receive: PlayerInitialized / InitializationFailed. And so on.Well it's some hex codes of course but you get the point I think

My flow should basiclly look like this:

boot/wakeup // <-- this is where I need the interrupt, don't I?
read adc value
pick track number based on adc value
send PlayTrack command to DFPlayer
delay x ms
send Sleep command to DFPlayer
go back to sleep

But the issue is in the combination of the Sleep and SoftwareSerial library. It's not the interrupt that is an issue. At least not yet

6
  • You've mentioned SPI and ADC - where does serial come into this?
    – Nick Gammon
    Commented Jul 22, 2023 at 0:57
  • The DFPlayer uses Serial. I'm not sure where SPI is coming into this. Perhaps the poster is confused about what SPI is.
    – Delta_G
    Commented Jul 22, 2023 at 1:26
  • Are you getting stuff from dfplayer, or sending stuff to it? If you are sending it to the player, I don't see where the interrupts are needed.
    – Nick Gammon
    Commented Jul 22, 2023 at 2:45
  • @NickGammon I updated my post to answer your question. Thank you
    – boop
    Commented Jul 22, 2023 at 10:26
  • @Delta_G I updated my post to clarify the situation. Thanks
    – boop
    Commented Jul 22, 2023 at 10:26

2 Answers 2

0

Thanks to @Delta_G I was able to figure out a solution.

I took the source files of the SoftwareSerial library from github and copied it to my project. I renamed it so it wont give any conflicts. I then continued to comment out the interrupts in the cpp file and took care of calling handle_interrupt from my program. I also had to remove the inline keyword from the handle_interrupt function

I've posted my modified files on github.

0

boot/wakeup // <-- this is where I need the interrupt, don't I?

Is the interrupt to detect that you have pressed one of the buttons? If you have that then you shouldn't need to use a timer to wake up.

If you connect your buttons with resistors in such a way that any button at all will send at least 0.6Vcc (ie. 3V upwards for a 5V system) then that could be configured to generate an interrupt (a rising interrupt). So you might set up the resistors so the buttons send 3.2V, 3.5V, 3.8V, 4.1V, 4.4V and 4.7V. That gives you six different voltages and they are all high enough to be considered "high" on a digital pin. Then make that pin generate the interrupt and also do the ADC reading on it once you wake up.

Then you can put the processor into a deep sleep until a button is pressed. While the track is playing you might also set up a watchdog timer interrupt so that you can wake up and check if it is time to put the player to sleep as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.