All posts by Lucky Resistor

A New Library for Meggy Jr RGB

I planed to create a game as a gift and use the really great Meggy Jr RGB platform for it. See the picture above, it’s a great game machine powered by the ATmega328P (buy it here). You can use the Arduino IDE to program it.

After assembling the device, I played a little bit around with the provided library — but was a bit disappointed by the library. This is a game device after all, but the library lack in my opinion some important things a game library need.

So I wrote a new library from scratch, using the provided schema and documentation (you can see the printed out schema in the background of the picture). Sometimes its better to start from scratch and learn from the mistakes of other libraries.

Today I release the first version of the library at GitHub here: https://github.com/LuckyResistor/LRMeggyJr. It has a proper API documentation and a few examples. I release this early, but hope to improve the documentation and add examples while I develop the actual game.

Download the release v1.2 as a ZIP

Continue reading A New Library for Meggy Jr RGB

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: http://luckyresistor.me/cat-protector/

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 at compile time, and they do not use any memory at runtime or make 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