Circuits and devices on microcontrollers. Simple clock on Attiny2313 microcontroller

This microcontroller-based device allows you to draw text and simple graphics in the air. In English-language literature, these devices are called POV or FlyText. The operating principle of the device is based on the inertia of our vision. The electrical circuit diagram consists of a microcontroller, 8 LEDs, a pair of resistors and two AA batteries. Even a novice radio amateur can assemble this device. The device is small in size.



Unlike most similar schemes, this scheme can update images via the com port without updating the firmware of the AVR ATtiny2313 microcontroller. There is no need to compile the firmware for the microcontroller each time for a specific text or picture, but simply transfer it through the computer’s com port using a special program.

The picture or text that will be drawn in the air is stored in the non-volatile memory of the microcontroller EEPROM. The update occurs by flashing this non-volatile memory. You just need to launch the program for drawing and transferring pictures to the device and connect the device itself to draw in the air.

The circuit board is very simple and so small that it attaches directly to the AA battery panel.

<

This is what the program looks like for editing text, graphics and transferring to a device.

Working with the program is quite simple. To edit a picture, just click on the pixel matrix, and then connect the device and reflash the EEPROM memory. The circuit can be connected to a computer via a USB-to-UART adapter or based on interface converter chips or .

Then select the desired com port number and press the "Upload" button.

Here is the location of the connection legs.

The program for the AVR ATtiny2313 microcontroller was written using AVR Studio and WinAVR. The computer program is written under Microsoft Visual C# 2010 Express. The printed circuit board was drawn in Eagle Cadsoft and everything you need in the archive is available via .


Also often viewed with this scheme:

ATtiny2313 air drawing device

This microcontroller-based device allows you to draw text and simple graphics in the air. In English-language literature, these devices are called POV or FlyText. The operating principle of the device is based on the inertia of our vision.

The electrical circuit diagram consists of an ATtiny2313 microcontroller, 8 LEDs, a pair of resistors and two AA batteries. Even a novice radio amateur can assemble this device. The device is small in size.

Unlike most similar schemes, this scheme can update images via the com port without updating the firmware of the AVR ATtiny2313 microcontroller. There is no need to compile the firmware for the microcontroller each time for a specific text or picture, but simply transfer it through the computer’s com port using a special program.

The picture or text that will be drawn in the air is stored in the non-volatile memory of the microcontroller EEPROM. The update occurs by flashing this non-volatile memory. You just need to launch the program for drawing and transferring pictures to the device and connect the device itself to draw in the air.

The circuit board is very simple and so small that it attaches directly to the AA battery panel.


This is what the program looks like for editing text, graphics and transferring to a device.

Working with the program is quite simple. To edit a picture, just click on the pixel matrix, and then connect the device and reflash the EEPROM memory. The circuit can be connected to a computer via a USB-to-UART adapter or based on FT232R or MAX232 interface converter chips.

Then select the desired com port number and press the "Upload" button.

Below is the location of the connection legs.

The program for the AVR ATtiny2313 microcontroller was written using AVR Studio and WinAVR. The computer program is written under Microsoft Visual C# 2010 Express. The printed circuit board was drawn in Eagle Cadsoft and download everything you need in the archive below.

I needed a thermometer for the incubator, and since I already have a thermostat, I will only make the thermometer itself. In my case, I will use a 3-digit rather than a 4-digit indicator. Let's talk a little about the digital indicators themselves. The seven-segment indicator consists of seven indication elements (segments), which are individually turned on and off by the power supply. By including them in different combinations, you can create images of numbers from them. In modern indicators, LEDs are made in the form of segments, so LED indicators have an extremely simple shape - the fewer different LEDs, the cheaper the device. Segments are designated by letters from A before G. The eighth segment is a point. Here are the parameters of the indicator that is used in the thermometer:

  • Maximum forward voltage (at current 20 mA):.....2.5 V
  • Maximum forward current: .....25-30 mA
  • Maximum reverse voltage: .....5 V
  • Reverse current (at 5V): .....10 µA
  • Power dissipation: .....150 mW
  • Maximum pulse forward current: .....140-160 mA
  • Operating temperature range: .....-40…+85°C

Now let's start making the thermometer itself. Let's study the circuit diagram.

To make it we will need:

>>> 4-digit seven-segment indicator 1 piece
>>> 0.1 microfarad ceramic capacitor 1 pc.
>>> Electrolytic capacitor 100 uF 16V (10 is possible)
>>> Resistors 100-200 ohm 0.125 W 8 pcs.
>>> Microcontroller AtTiny2313 1 pc.
>>> Panel 20 legs 1 pc.
>>> Sensor DS18B20 1 pc.
>>> Wires, soldering iron, golden hands))

Having collected all the necessary radio components, we will begin manufacturing a microcontroller thermometer. Solder resistors to the indicator.

We supply power - and you're done! All that remains is to flash the microcontroller. Firmware is possible. The archive contains two firmwares, for a common cathode and for a common anode.

To flash this MK we need . How to do it, see the link. Open PonyProg (If you have the programmer from the article above) and upload the firmware. When uploading the firmware, do not forget to press the button " READ"We set the fuses as in the photo below:

Also one of the important factors: when setting fuses, do not forget to press the " READ" (Read). And save the firmware, remove the microcontroller from the programmer and insert it into the device.

We supply power to the circuit - and voila! Everything is working. There is no printed circuit board for the circuit, since due to its simplicity there is no point in drawing it; the circuit consists, roughly speaking, of five radio components. Not counting resistors, because it’s generally easier to solder them there. A video of this temperature sensor in operation can be seen below:

How the ATTINY thermometer works

The device is really so simple that it is perfect for novice controllers, as the first practical project on AtTiny. I was with you Boil.

Discuss the article THERMOMETER ON ATTINY

The device of this article is working with SD cards. The topic is old and quite hackneyed, but the use of SD cards is worth writing about it again.
In general, SD cards (SDC, SD Card) have many advantages and are very simple and convenient to use in small embedded projects. A number of factors contribute to this:
- a very simple interface for interacting with the card (implemented via SPI);
- high operating speed (the microcontroller is capable of transferring data from an SD card at a speed close to 10 Mbit/s);
- low power consumption (literally a couple of milliamps - no more);
- small sizes;
- availability and low cost.
SD cards have virtually no drawbacks (except, perhaps, for their initialization procedure :)).

1. Introduction.

I called the device described in this article SD Card Talking Device. A little pretentious ;), but the name makes it clear that this is a talking device. It is intended for voicing your projects. In short, it works as follows: numbered sound files are recorded on the SD card, which the device plays at your command. The scope of application is quite wide - warning systems, toys, robots, smart home, etc. The dimensions of the device are quite modest (it could be smaller, but I deliberately chose the ATtiny2313 microcontroller, which is cheaper and easier to get). I tried to place the main emphasis on simplicity and maximum functionality.
Looking ahead, let's see what should happen in the end:

Is such a device useful? Then let's collect!

2 Memory card.

The device uses an SD memory card. I have already written about the reasons for this choice, but I will only add that SD cards are becoming almost the standard memory card for mobile devices. Even manufacturers who fanatically promoted/are promoting their type of memory cards are slowly starting to use SD cards. The reason for such popularity was probably the low price of these cards. For amateur devices, the SD card is, in fact, the only card suitable for use, and the reason for this is the simple interface for working with it.

The SD card has come a long way in evolution and has several options for its implementation (MMC - as an SD card option, SD ver1, SD ver2, SDHC, SDXC). The procedure for communicating with the card is simple and universal for all types of cards, but putting it into operation (initializing the card) is a rather ambiguous and confusing process, with ritual “jerking” of the card, sending empty “dummy” commands and other incomprehensible things (in short, dancing with tambourines required:)). The specification for the SDC protocol itself describes the initialization process in quite some detail, which is understandable; there are a lot of card manufacturers, each with their own hardware, with their own characteristics... What am I getting at? - I tried to make the initialization procedure as universal as possible, but be prepared for the fact that some cards will not work. Therefore, if something is not going well with your device, try another memory card - this may be the reason.

This device supports SD cards up to 2 GB in size. Everything higher (SDHC and SDXC) is not supported.
It makes no difference for the device what form factor the card is (SD, MiniSD or MicroSD), but you must connect it correctly, according to the card pinout.

3 File system.

The device uses cards with the FAT16 file system. This system is ideally suited for devices like ours, as it is simple and easy to implement (FAT12 and FAT32, in principle, are also not difficult to implement, but this is impractical due to the lack of any advantages compared to FAT16).

There are no special requirements for formatting the card - it can be formatted in any available device. Standard Windows formatting is quite suitable for these purposes.

For the device to operate correctly, sound files located on the SD card must meet certain requirements:
a) The file format must be uncompressed WAV.
The file parameters are as follows:
- Bitrate - sampling frequency (Frequency) - 32000 Hz;
- Number of channels (Channels) - 1 (mono);
- Sample size - 8 bits.
Another possible reduction is WAV PCM 8U

b) The file must be named in a special way. In order for the device to know which file is the first, second, third, etc. The first character of the file name must be a capital letter of the Latin alphabet (the rest of the name, like the file extension, is ignored).
For example, the following file names would be correct:
A_Lai_dog.wav - first track
B-This is the second track.wav - the second track
With Warning! Error!.wav - third track

c) To use additional features of the device, files can be located in two folders named “1” and “2”. The device has a switch for selecting the active folder, that is, the same command to start playback can play tracks from folder “1” or “2”, depending on the level on the switching input (a kind of selection of the sound scheme - a very useful thing!) . If one of the folders (or both) does not exist, the files are played from the root directory.

You can store any other files along with audio tracks, provided that they do not create conflicts with their names (it is better to put them in a separate directory, then you will not have to pay attention to how they are named there).

d) Due to the small amount of SRAM on the ATtiny2313, it is impossible to create a buffer for pre-reading data, so data from the file is directly output for playback. Accordingly, there is no way (there is not enough time) to search for file fragments using the FAT table. In other words, the files written to the card must not be fragmented.

In fact, this is not a big problem, since any operating system always tries to write the file as a whole piece, and as long as you have space on the card, any actions with the files (deleting, copying, renaming) will not affect their integrity. If you have a very small card or you have filled a large card to capacity, in order to be sure of the integrity of the files, simply copy them to your computer’s hard drive, format the card and return the files back.

4 Scheme. Printed circuit board.

The device diagram is as simple as possible. In fact, apart from the microcontroller itself and the SD card, there is nothing in it. For myself, I made a signet for SMD components, since I plan to use this device in a place with limited dimensions. If the dimensions are not critical for you, you can assemble the circuit on a breadboard in the DIP version. In the case of a breadboard, assembling the device will take you, at most, 15 minutes. The permissible supply voltage for an SD card is from 2.7 to 3.6 volts. The microcontroller also works normally in this interval, so there is no need to use any matching components. I checked the operation of the entire device with a power supply of 5 volts - everything worked fine, but I do not recommend doing this on an ongoing basis, since different cards may react differently to excess voltage. I used an adapter as a microSD cardholder, soldering it directly to its contacts. If you need smaller dimensions, it is better to use a real cardholder for microSD.

To flash the microcontroller firmware, the same connector is used as for the SD card, so you will have to think about how to connect the programmer to it (I specially made an adapter).

After the board is soldered, you can flash the microcontroller.

A small gallery of the finished device:




A small nuance regarding the scheme.
When installing an SD card into a cardholder (connecting the card to a power source), a current surge is created and, accordingly, a voltage drop in the circuit (it seems that significant capacities are being charged in the card at this time). The drawdown is so significant that the microcontroller resets. I use this to start the card initialization procedure (installing the card restarts the microcontroller and the first thing the firmware does is search for and initialize the card). If you do not reset the microcontroller when installing a card (a powerful power supply or large smoothing capacitors), then you need to take care of the reset button in the circuit for manually resetting the microcontroller (this is if you plan to “hot” change cards).

5 Device operation.

As I wrote above, working with the device is very simple: copy the correctly named tracks to the SD card, insert the card into the cardholder, the device will automatically find the card, turn on the green LED - that’s it, the device is ready to play the tracks. Now you just need to select and start playing the track in the way that suits you best.

5.1 Device buttons and their actions.

I tried to make the device as functional as possible, so a lot of microcontroller legs are used for operating mode switches (this makes the device resemble a hedgehog :)). If you don’t need any function, just leave your leg “hanging” in the “air”.
Switch action:
- “Monster” - allows you to slow down (2 times) the playback of the track - creating the effect of a low voice. The switch works “on the fly” - the speed changes upon switching;
- “Helium” - speeds up the playback of the track (by 1/3) - creating the effect of a high-pitched voice. The switch works on the fly;
- “Repeat” if this switch is shorted to ground, the selected track will play endlessly (until the switch is opened). This can be useful, for example, if you need to create a certain sound background - the sound of rain, a burning fire, the murmuring of a stream...;
- “Select / Play” button that starts the track for playback (description below);
- “Select track” - setting the number of the track being played (description below);
- “Dir1 / Dir2” - select a sound scheme (description below).

5.2 Start playback.

There are three ways to start playing a specific track:
- by sending a capital letter of the Latin alphabet via UART, playback of the file containing this letter at the beginning of the name immediately begins;
- if using “Select track” the file number is selected (binary code 0001=”A”, 0010=”B”, etc. 1 - leg is closed to the ground, 0 - “hanging” in the “air”), then the “Select / Play” button will start the corresponding file for playback;
- if nothing is selected using “Select track” (0000 - legs “hang” in the “air”)), then by pressing the “Select / Play” button a certain number of times, we launch the corresponding track (1 time = “A”, 2 times =”B”, etc.).

5.3 Sound schemes.

A very useful feature is the function of selecting one of two sound schemes. This means that the “Dir1 / Dir2” switch selects the folder on the card from which the track will be played.

There are a lot of applications: messages in Russian and English (educational toys), children's and adult voices, noises of flowing water and burning fire, cat/dog, good and evil policeman :), calming/invigorating sounds and a bunch of other similar options.

For example, you need your device to be able to communicate in a male and female voice. It is implemented like this:
- create two sets of messages, respectively, in the female and male version;
- file numbering for both options is the same. Don’t forget that the device “sees” only the first letter in the file name, so you can make the names more understandable for yourself, for example, “S_Waiting for command_male.wav” and “S_Waiting for command_female.wav” are quite correct;
- copy the set of men’s messages into folder “1”, and the women’s messages into folder “2”.
Now, depending on the state of the “Dir1 / Dir2” switch, the same command will play tracks from the “male” or “female” folder.

5.4 Indication of device operation.

Since Teeny2313 has very few legs, and almost all of them are used for switches, I had to sacrifice a normal indication, and in return attach something NOT normal. To indicate different operating modes, only one leg of the microcontroller is used, to which two LEDs are connected - red and green (or whichever you prefer). The different operating modes of the device are indicated by a specific color code:
- red LED flashes - there is no SD card or its type is not supported by the device;
- the red LED is on - the SD card is supported and has been successfully initialized, but the card is not formatted in FAT16;
- the green LED is on - the SD card has been successfully initialized, the required file system has been found and the device is ready to play the track - waiting for a command;
- green LED flashes - the device is playing a track;
- green lights up, red lights up briefly, green lights up again - track not found;
- green lights up, goes out briefly and turns green again - the track selection key is pressed.

5.5 Debugging information.

To make it easier to find problem areas (if the device does not want to work), I duplicated each initialization stage in the program with messages via UART. After each successful step, the corresponding character is sent to the UART:
- “S” - (Start) the microcontroller peripherals are initialized normally;
- “C” - (Card Init) The SD card is initialized normally and is supported;
- “F” - (FAT Init) FAT system supported;
- “1” - (No 1 Dir) there is no folder “1” reading will be carried out from the root directory;
- “2” - (No 2 Dir) there is no folder “2” reading will be carried out from the root directory;
- “R” - (Ready) the device is completely ready - awaiting the command to start the track;
- In addition, each time a track is started, the capital letter of the track name is transmitted to the UART.

6 Tracks for dubbing your devices.

6.1 Converting tracks

If you didn’t find anything suitable in the library above, then you can get the necessary tracks on the Internet (there are many special sites for musicians and video editing, where large libraries of sounds have already been collected), in game installations (often gameplay sounds are divided into tracks and put into a separate folder). You can also cut sound effects from films and music compositions. The found tracks need to be converted into a format that the device supports. Let me remind you that the file format must be uncompressed WAV. 32000 Hz, 1 channel, 8 bit (WAV PCM 8U)
Any music editor is suitable for converting to this format, or, if you just need to convert a track without editing it -