Homemade usb cable. Homemade portable mp3 player USB, microSD. Layout and programming

It was used:

1. Cardboard box from household appliances;
2. Copper wires from old electronics;
3. 2 speakers from old computer speakers;
4. Keyboard from an old cell phone;
5. Rechargeable battery from an old cell phone;
6. Switch ();
7. 4 self-tapping screws;
8. Battery charging module ();
9. Mp3 player without case ();
10. Decorative film on an adhesive base;
11. Hot glue, super glue, electrical tape.

From tools:

1. Pliers;
2. Scissors;
3. Stationery knife;
4. Screwdriver;
5. Glue gun;
6. Soldering iron (very convenient);
7. Third hand.


Making a player

We cut the cardboard into paired pieces, 4 pieces of each size.
1.4cm x 8cm, 3.6cm x 7.6cm;
2.4cm x 6.5cm, 3.6cm x 6.1cm;
3. 6.5cm x 8cm, 6.1cm x 7.6cm.

And glue them together. This will add rigidity to the structure.


Electronics that will be used in homemade products.


Cheap mp3 player with USB and microSD connectors (). Powered by 5v or 3.7v from a battery. A 3W signal amplifier is already built into it. A voltage regulator is also built in. Power connection via microUSB and two terminals for the battery.


Lithium battery charging module 18650 on TP4056 5V 1A with micro USB interface (). It is suitable for charging batteries from cell phones.


Philips 1100mAh rechargeable battery. Pulled out of a broken phone.


Speakers from old computer speakers.


Recently ordered good quality switches () for table lamp repair. Just one left.


And a few buttons from the keypad of a broken phone.


We cut out a place for the speaker to sit tightly in place.


We glue the base of the case, the side wall with hot glue and try on the future location of the battery.

We glue it on the inside with hot melt glue for reliable bonding.


Considering the future placement of the charge module.
The charge module and battery will be located in the housing of the second column. In the case of the first speaker, the player board and control buttons will be located.


Cut out the holes for USB and microSD connectors on the top of the case.


We solder the standard buttons from the player board. We will place them on the same upper part of the case for easy control.

We solder the wires to the buttons. I took 4 pairs of wires of different colors, so that later it would be more convenient to solder on the player's board.


We take a decorative film on an adhesive basis (I still have a black one) and glue the parts of the case with it.


It should look like this.


Cut a hole for the button on the upper part of the first column and place the control button there.


We fix it on the reverse side with hot melt glue for reliability.


We do the same with the rest of the buttons. The 2 upper buttons will be responsible for switching tracks and volume, lower left play / pause, and lower right track repeat button.

It turned out something like this.



Now you can solder the wires from the buttons to the player board.


Fill the soldering points with hot glue to securely fix the wires. You can collect them in a heap and wrap them with electrical tape so that they do not get in the way.


Observing the polarity, we solder one pair of wires from the charging module to the battery.


We fasten the speakers to the case with self-tapping screws and fix the self-tapping screws on the back with hot melt glue.


We glue the upper part of the case and fix the charging module with hot melt glue for reliability.


We make slots for the wires going to the first column, fix them with hot glue from the inside and check the operation of the module before attaching the back of the case.


We twist the wires of the two speakers and solder them to the player board, observing the polarity.


We solder the power wires to the player board and to the switch. Observe polarity!


We fix the loose parts and wires inside with hot glue. We check the operation of the player before attaching the back of the case.


To fix the speakers to each other and protect the wires, we glue a wide strip of decorative film on both sides.

The result is a book-shaped design, which gives stability and an unusual appearance to this homemade product.





We glue the buttons from the keyboard of the old phone with super glue. Be careful not to fill the control buttons with glue.


You can start the test.


Indication.



USB stick reads well. Music plays loudly. At maximum volume, there is a wheezing of the speakers, but the average volume is quite enough for listening.
Battery life 1100mAh for about 2-3 hours at medium volume when playing from USB media, but energy remains for playback from microSD cards. With microSD cards it will work 2-3 times longer, since the power is consumed at 3V, instead of 5V.

I want to tell you about my small weekend project, highlight the difficulties that I had to face, future plans and get advice from more experienced Habrayuser. The format of the article is a survey, so to speak, at a gallop across Europe. If there is interest, I will go through the separate parts in more detail.

The operation of the device can be briefly described as follows:

Electret microphone → Max9812 amplifier → STM32F103 microcontroller → Software detection of sound presence → Sound encoding in Speex → Sending via ESP8266 to the server → PHP script for receiving data and processing into an Ogg sound container. Who cares, please, under cat.

Why is all this necessary?

The very idea of ​​the device came to me for the birth of my daughter. In the future, I want to make some kind of a baby monitor: I plugged it into an outlet next to a crib, and you watch a TV show in another room, then hop - a push notification came to the phone and you can listen to what is happening there. But on the implementation of the last points, I have more questions than answers. More on that later.

Perhaps someone will see another use for such a craft, but I assure you that the device is not created for the purpose of secretly obtaining information (Article 138.1 of the Criminal Code of the Russian Federation) and any such attempt will be prosecuted by law.

I ask you not to immediately criticize the idea itself, I need to work with sound and Wi-Fi in another project, which I am still thinking about. And this is a separate piece, implemented as an independent device.

Frame

According to the “Design first” principle, I began to think in what construct to make the device. In search of ready-made cases on Ali, I stumbled upon cases for usb with a hole for the cable and thought to myself that this was ideal - the microphone would take the hole, and somehow we would shove the rest.

Only now I didn't want to order 10pcs for $ 5 and started looking for options. As a result, I ordered a USB-RS485 adapter in exactly the same case for $ 0.84. And the adapter itself will come in handy at work, otherwise Bolids, costing 1.5 thousand rubles, go away as a consumable.

We buy everything you need

First, while getting acquainted with the subject area of ​​the upcoming hack, I came across the article Speech Recognition on STM32F4-Discovery. There I read about the Speex codec and its use on microcontrollers. I confess, this is my first experience with STM microcontrollers.

So, we order the most common debugging with the STM32F103C8T6 microcontroller, the St-link v2 debugger to it, we finish it on our knees and you can already live. According to rough estimates, the resources of STM32F103C8T6 should have been enough, but speex is very gluttonous, and the HAL drivers themselves are not so compact, in the total memory for all the libraries it turned out to be not enough. The final device is STM32F103CBT6 with twice the amount of flash.

Secondly, you need a microphone. The first line in our search is the microphone module with the max9812 amplifier, and in addition to a handful of more miniature microphones of standard size 6050 (after all, we already have a case with a hole for this microphone to fit in).

Thirdly, you need to pick up a wi-fi module, and one that fits into the purchased case. The choice was made for a miniature ESP-03 with a ceramic antenna and several pieces of ESP-12 for prototyping.

Layout and programming

In STM32CubeMX, we quickly assemble the necessary peripherals and move on, in the process of work you will still have to often return to Cuba. The main thing here is to write code in specially designated places / * USER CODE * / and then the new generation of the project will not affect what has already been written.

Sampling of the ADC goes through DMA on a timer trigger at a frequency of 8 kHz into two circular buffers of 160 samples, one buffer is equal to 20 ms. I faced such a moment that I did not know and lost time at this: DMA continues to work at the breakpoint of the debugger, while both the HT (half transfer) and TC (transfer complete) flags are set, and the buffers are always full.

I didn't figure it out with the Speex library right away, the controller constantly crashed into HardFault. It turned out that there were simply not enough stack and heap sizes. Found an Application Note from Silicon Labs with a description of the necessary resources for encoding / decoding, at the end of the article there is a link. Set the values ​​with a small margin CSTACK 0x800 and HEAP 0x1600. At the output of encoding, we get a frame size of 20 bytes. We collect them in packages for sending.

The Esp8266 module can accept a maximum of 2048 bytes of data at a time. Send command format: POST header + data. I limited the size of the data packet to 1800 bytes (90 frames, 20ms each).

Data reception was done in PHP. I was ashamed to upload the code, especially since this is my first OOP experience in my life. Please do not hate, this is not my area, you better teach me how to do it correctly. The essence of the script is to take data from php: // input, form a header, calculate the necessary checksums and save everything to the Ogg file (either add the old one or create a new one). But I have a creepy feeling that accepting audio via POST requests is very stupid ...

A question to the community: what do you recommend for the server side? In the future, I want to receive a stream of audio in real time. I personally have a slight desire to get to know Node.js.

Schematic diagram and PCB layout

I drew the schematic and layout in the free version of Eagle CAD, since the board size is small. Here they are. No comments.

Ordering boards

The boards were ordered from the American OSH Park. What is remarkable about this service is that the price is based on the size of the board ($ 5 per square inch), and delivery is free. In addition, you can load the .brd file from Orel to the site and there is a preview, you do not need to transfer it to Gerber.

It turned out 3 boards for $ 3.35. For a prototype, this is more profitable than overpaying the Chinese $ 15 for unnecessary 10 pieces. There are still mountains of unnecessary boards from other projects lying around at home. And besides, all this came in a branded bag with sweets inside. A trifle, but nice. There was no track number, it was received 40 days from the date of order. There were 10 days in production (from December 29 to January 9, perhaps the holidays somehow affected the timing).

I was satisfied with the quality of the boards. 8 mil tracks. Transitional 13 mil. The boards came with gilding, the layer of the mask relative to the areas is even everywhere.

Build and setup

I haven't figured it out yet, but the Esp-03 module practically does not pick up a signal, which is strange given the presence of a ceramic antenna and the distance to the phone (which acts as a wi-fi distributor at work) within half a meter, while the module heats up noticeably. When the phone is brought up close, it begins to detect the network and connects to it. To order a new one or what could be the matter?

Future plans

1. Modify the VAD (Voice Activity Detection) algorithm to a more adequate one.
2. Check the ability to play sound on the phone.
3. Make it possible to configure remotely. Now this is implemented by the server response (Settings = 40,2000,10,), where the sensitivity of the current VAD algorithm is set (the signal should exceed 2000 buboc 40 times) and the recording duration in seconds.

Final option

Costing
$ 2.03 - ESP-03 module
$ 2.13 - STM32F103CBT6 microcontroller
$ 0.39 - 6050 microphones
$ 1.12 - mic module with MAX9812 and harness
$ 0.84 - USB-RS485 converter (case + usb type A male)
$ 0.50 - NCP3335A 3.3V regulator

Total: $ 7.01 (~ 420 rubles) per device.

Prices may vary due to recent events on Ali. The price does not include the programmer and loose products.

Thank you for the attention!

Write your questions and suggestions in the comments. Contact or telegrams are also allowed, the nickname is the same everywhere.



I had the following connectors at my disposal: a USB socket designed for installation in a printed circuit board and an 80 cm piece of cable with a USB plug at the end.


Initially, I tried to make a flexible extension cord from a 4m AV cable, but the attempt was unsuccessful. When I inserted the flash drive into this cable, the OS "said" that the device is not working properly.



So, it was decided to use a twisted pair cable, especially since I had several pieces of a network Ethernet cable left over from the days of distributing the Internet through a local network. The network cables turned out to be of the lowest quality, since they did not have any screens. Each piece of cable had four twisted pairs in plastic insulation. Judging by the color and hardness of the veins themselves, they were made of some kind of copper alloy, similar to brass.

To transmit the signal and power in the USB2.0 format, at a distance of up to 5 meters, only two twisted pairs are enough. The remaining twisted pairs can be omitted.


However, if the resistance of the cable cores is high, and the device connected to the end of the cable consumes a significant current, then you can start up the power supply via two or even three twisted pairs at once.


Let's take a closer look at this point.

For example, if the current consumed by a USB device is 400mA, and the resistance of one pair is 2 Ohms (both ends), then the resistance of the USB device will be:


5 / 0,4 = 12,5 (Ohm)


In this case, the voltage drop across the cable will be:


5 * 2/ (12,5 + 2) ≈ 0,69 (Volt)


Which, of course, is a bit too much.


But, if you use three pairs at once:


2 / 3 ≈ 0,67 (Volt)

5 * 0,67/ (12,5 + 0,67) ≈ 0,25 (Volt)


Then the voltage drop on the cable will decrease and will no longer be so critical.

About pinout (pinout) of USB plugs and sockets

The picture shows the pinout of the USB 2.0 socket and plug.


Any of the four available twisted pairs can be used to transfer data (+ Data and –Data).


To connect the power, you can use any of the three remaining twisted pairs or all three pairs connected in parallel.


How to secure a USB jack to a rigid network cable

The assembly of my cable was somewhat complicated due to the fact that I had at my disposal not a USB cable socket, but a socket for printed circuit boards.


I had to first isolate the contacts from the back of the case.


And then from the bottom wall of the case (shown in the photo above).

For a not very rigid cable, for example, consisting of only two twisted pairs, you can use this method of attaching the socket to the cable.


First, using sewing threads, we attach a piece of PVC tube (cambric) to the cable. The end of the thread can be secured with molten rosin. We make two longitudinal cuts on the cambric and cable insulation.


It should look something like this. The formed "petals" should be arranged in the form of a cross.


You can then solder the ends of the twisted pairs to the corresponding pins.


We attach the "petals" to the body of the nest with sewing threads. We fix the end of the thread with rosin.

Now you can refine the nest by putting on a heat shrink tubing or covering it with plastic (from a pistol).

But, I only had a very rigid cable, so the mount had to be made more serious.


First, I wound a copper wire with a diameter of 1.3 mm around the end of the cable. Then I soldered the ends of this wire to the side walls of the USB socket.


To give additional rigidity to the structure, I covered the junction of the cable with the USB socket with low-temperature hot melt glue.



To give a more fine-looking shape and improve the appearance of the connector, I covered it with a heat-shrink tube. V

Attention! During the shrinking of the tube, hot melt glue may seep through the slots and into the interior of the socket. To prevent this, you can insert a spacer between the tube and the housing of the socket, or a plug into the socket. Then you don't have to pick out the hot melt glue from the nest.

Everyone knows that any electronic device can be connected to a computer using a standard USB cable. Thus, using a laptop or personal computer, you can connect various devices with each other, for example, printers, cameras, smartphones and data storage devices (flash drives and external hard drives).

What is OTG?

Is there a way to do without a computer? Quite simply, a lot of adapters under the general name OTG cable have appeared on the market for a long time. Their cost varies from a few dollars to a dozen or even two. However, their difference from simple data cables is so insignificant that you can easily make an OTG cable with your own hands. For example, from the remains of old and adapters.

So, first we need to decide what we need an OTG cable for. Powering another device from the battery may be needed in the absence of power outlets nearby, for example, on trips or hiking trips, but this option is not the most efficient. We need to immediately decide whether we will connect two specific devices permanently to each other or whether it is better to make a universal OTG cable with our own hands to use any USB devices, like a store one. It's also best to check right away if your device is capable of supporting such connections.

Tools and safety technology

When working with cables you will need:

    insulation stripper;

    nippers or side cutters (remember the saying: "measure 7 times - cut 1"), an extra solder on the cable will worsen the quality of communication between devices and increase the resistance in general, which will affect the loss of data or the impossibility of charging due to the resistance of the conductor;

    soldering iron, solder and flux; at the end of the article we will look at how you can do without this device.

Remember the safety measures when working with a soldering iron. This device is dangerous due to its high temperature not only during operation, but also for several minutes after being turned off. Protect the work surface of the table from the ingress of molten tin or rosin. Protect exposed skin from touching hot parts of the soldering iron.

What is what?

To begin with, it is worth making out which contacts in the plugs and sockets are for what, since in the mini and micro versions there is 1 pin more than in the connectors of the universal serial bus. So, the first pin is standardly marked with red insulation inside the wire, designed to supply voltage. The second and third pins, marked with white and green insulation, are for data transmission. The fourth black pin is zero or ground, paired with the first supply wire. In mini and micro USB, such functions are assigned to the fifth, last pin, and the fourth is a marking or identifier. It is designed to feed connection information to the device and is not connected anywhere in the data cables.

The simplest option

First of all, we will consider the option of connecting two specific devices, for example, a tablet computer and a camera. Since both of them have 5-pin sockets, be it micro or mini USB, you just need to carefully solder the corresponding wires together. 2 unnecessary data cables with matching plugs will do. You need to cut them and strip the wires from the insulation, and then connect them according to color differentiation, that is, black with black, yellow with yellow, and so on. Each connection must be isolated from the others with hot melt glue or at least electrical tape. When such a cable is connected to the devices, a dialog menu will appear on the screens, where you will need to select which of the devices will be the main one in this mini-network. You can forcibly designate the main and secondary devices in the cable itself. To do this, in the plug of the main device, you need to connect the 4th and 5th contacts, and in the other plug, simply do not connect the 4th contact to any one. Thus, the device will automatically determine itself as the master in the connection, since the marker contact will show the presence of a connection, while on the second device it will be "empty".

For a variety of devices

Consider the option of how to make a universal OTG cable with your own hands. In addition to the micro- or mini-USB plug, depending on the device, we need a USB connector. You can take it from old motherboards, cut it off from a USB extension cable, or disassemble a USB splitter (the so-called USB hub). The latter option is preferable, since it will allow you to connect several peripherals to the main device at once, like to a computer. The connection sequence is the same as above, the main device is forcedly indicated on the device plug in the same way, connecting the 4th and 5th pins. The figures clearly show the connection diagram of the pins in the connectors and plugs.

Connected to power supply

Some devices are characterized by increased power consumption, which leads to a quick discharge of the battery of the main gadget, be it a smartphone or tablet. In this case, the do-it-yourself OTG cable can be improved by adding a power cable with a USB plug for the power adapter. For this, you can use the remnants of the data cable from which the micro- or mini-USB plug was previously cut off. The connection is made on two current-carrying contacts, black and red, ignoring the data wires. It should be remembered that over long distances the resistance of the wire reinforced with solder joints will reduce voltage and amperage, so using long cable runs will most likely not allow you to achieve a stable connection between devices. Use approximately 20-30 cm of cable for each plug and connector to avoid breaks and interruptions in the connection.

Finally, I would like to mention how to assemble an OTG cable with your own hands without a soldering iron. The assembly principle is the same as described above, however, the wire connections are made in slightly different ways. Here are two of them:

    Solder paste contains powdered solder and flux and does not require a soldering iron. Such a paste is applied to the parts to be joined and heated with an ordinary lighter.

    There are compounds without the use of high temperatures at all. The so-called adhesive tape locks are connectors for low-current systems with a special contact that cuts into the wires using a clamping device, pliers for example.

Whatever you decide to do with your own hands, remember that cutting the cables is not a warranty case and such cables cannot be replaced.