Using the TDA 7052 as Amplifier

The LM386N-1 I used before worked well, but has some disadvantages. There was a hearable distortion in the sound and I needed more amplification to create the required loudness.

I found the TDA 7052 chip, which was formerly produced by Philips, but now by NXP semiconductors. It contains everything required for an amplifier. You just have to supply power, the input signal and there are two outputs to connect the 8Ω speaker.

The updated schema looks like this:

Amplifier 2

I also added a trimmer to adjust the volume of the output. The value of the trimmer is missing in the schema. I used a 47kΩ trimmer, but a 10kΩ trimmer will work fine as well.

The Cat Protector Project

If you own a cat, you know even if your cat is well brought-up, laws are only valid as long you are at home or even in the same room. The goal of this project was to create a small device, which detects movement in protected areas (e.g. tables) and speak your usual phrases in your voice to the cat.

I documented a working prototype of the project in the hope to share some knowledge and give some ideas how certain details can be solved. It contains schemes for all hardware parts and a detailed description of all software parts, including a minimal implementation of a SD card access.

Please feel free to ask, if you do not understand a part, or if you have any suggestions where to extend the documentation or clarify parts.

Jump directly to the start page of the project documentation here:

How and Why to Avoid Preprocessor Macros

While most naming conflicts in C++ can be solved using namespaces), this is not true for preprocessor macros.

This post is outdated. You will find an updated version here:
How and Why to Avoid Preprocessor Macros

Macros can not be put into namespaces. If you would try to declare a new class called Stream, but somewhere in a header you include would be a macro called Stream, things would break. While compiling your code, the preprocessor would simply replace the Stream in your class Stream { declaration. You could get a really confusing error message, and it would take time and energy to find the actual problem.

Especially people developing software for controllers, often overuse macros for almost everything. They believe it will save RAM, speed up the code or make it more flexible. Often none of these three things are true. Actually each additional macro is a risk for name conflicts and makes the code less readable. You should reduce the use of macros to the absolute minimum, and especially avoid macros in your header files.

Continue reading How and Why to Avoid Preprocessor Macros

How and Why to use Namespaces

Namespaces are a feature of C++ which address the problem of name conflicts. There is a “global” namespace, where everything lives which was declared without namespace. Especially the Arduino environment declares a huge amount of variables and constants there, so it is a good practice to put everything you write in a own namespace. Namespaces are only used while compile time, and they do not use any memory at runtime nor make they run your program slower.

In my case I choose the namespace lr which stands for Lucky Resistor. Everything I declare in this namespace is accessible trough the :: operator which you probably already know from function definitions.

Continue reading How and Why to use Namespaces