How to make a usb connector. We create the simplest usb device for communicating with our program. We organize automatic connection of the device

When cassette recorders and CD players appeared, cars began to be equipped with car radios. But with the development of radio electronics, USB flash drives appeared, which completely replaced other media. They do not take up much space, you can record a large number of music files on them, while during the trip the music will not be interrupted by off-road driving. How to make a USB port (adapter) for regular radio tape recorders with your own hands is described in this article.

[ Hide ]

Guide on how to make a USB input in the car radio

Almost all modern cars are equipped with a car radio. Many drivers do not want to change it to a new Chinese device in order to get a USB input. In order to be able to listen to music from a USB flash drive, you need to connect a USB adapter to the head unit (the author of the video is oleg ko).

Preparation

It will not take much time, but you need to have some knowledge of radio engineering and be able to use a soldering iron. First of all, you need to purchase an MP3 player that can read flash drives and memory cards. It is important that it has a headphone output. This is necessary in order to be able to capture the audio signal.

You can use the FM trimmer, which is equipped with an audio output. The advantage of the trimmer is that it comes with a remote control.


Stages

Having bought a suitable device with an audio output, and having prepared the necessary tools, you can get to work.

The connection consists of the following steps:

  1. We take out the device and remove the tape drive mechanism or CD-drive from it.
  2. We solder the positive power wire from the player to the radio contact. After switching on, a voltage of 9 or 12 V should appear.
  3. For an MP3 player, you need to include a voltage converter from 12 volts to 5 volts in the circuit. The trimmer has it built in.
  4. To connect sound, you need to take a shielded wire and connect it to the audio output of the player. If there is no such wire, then you need to find a preamplifier on the board, it is to it that the wire that we need goes.
  5. We find the output of the audio signal on the microprocessor. We solder the capacitors, and in their place we give an audio signal from the player.
  6. Now install the MP3 player board. When doing this, be careful not to avoid a short circuit.
  7. You can make a USB input a hole on the panel where discs or cassettes were inserted.
  8. Buttons for controlling the player are displayed to the control keys located on the front panel.
  9. Next, it remains to collect its staff in place.

Now you can listen to music from digital devices through a DIY USB port. To do this, turn on the TAPE or AUX mode. Tracks are controlled either using the buttons on the panel, or with the remote control if an FM trimmer was used.

Conclusion

Advantages of connecting a USB adapter to the radio:

  • easy to install;
  • the flash drive is devoid of the disadvantages of playing CDs when the laser burns out and there are problems with playing discs;
  • many files are placed on the USB flash drive, they are easy to update and supplement;
  • the recording is played in the quality in which it was recorded;
  • you can use a standard device;
  • The USB input does not take up the cigarette lighter.

Thus, connecting a USB port is not difficult. The main thing is to be able to use a soldering iron and understand at least a little in electronics.

By connecting your adapter for flash drives in the car radio, you can save on buying a new device equipped with a USB adapter.

Let's start with the minimum:
include 18f2455 -- library for used MK
--
enable_digital_io() -- switch all inputs to digital mode
--
alias button is pin_B7 -- since we have a button connected, declare it
pin_B7_direction = input -- the button works for us at the entrance
--
-- one line - and we have everything you need to work with USB CDC
include usb_serial -- usb library
--
usb_serial_init() -- --initialize USB CDC
forever loop-- main loop, runs continuously
usb_serial_flush() -- usb update. This procedure does all the necessary
-- actions to maintain connection with PC
end loop

After compiling this code, writing the resulting HEX file to the MK using a bootloader and starting the device, you can observe how a new device is defined in the system: Virtual com-port.

Now that the device is already working, let's teach it to communicate.

To read the received byte there is a function usb_serial_read( byte ) :boolean. If there is a received byte, it stores it in the specified variable and returns true, otherwise returns false.

There is a procedure to send a byte usb_serial_data. It is disguised as a variable, so to send a byte, it is enough to assign it the value of the byte being sent.

Let's declare a byte-sized variable before the main loop, in the main loop we will check for the presence of received bytes, and send them back if there are any.

include 18f2455
--
enable_digital_io()
--
alias button is pin_B7
pin_B7_direction = input
--
--
include usb_serial
--
usb_serial_init()
var byte ch -- declare a variable
forever loop-- main loop
usb_serial_flush()
if(usb_serial_read(ch)) then-- if a byte is received, it will be written to ch
usb_serial_data=ch -- send the received byte back
end if
end loop

We compile, hold down the button, distort the power, launching the bootloader, change the firmware, launch it.
The device was detected in the system again, now we need software in order to test the operation of the device.

While we do not have our own, we use a ready-made terminal: I used the RealTerm program.
We open the port with the desired number and send the data.


And we get back what we sent. So everything is working as it should.

Soft

So, our microcontroller can receive bytes and immediately send them back. Now let's write our own software to communicate with it (I will use Delphi).

We create a new project, scatter the necessary components in the form:
SpinEdit1 - to specify the port number
Button1 - to establish a connection
Button2 - to break the connection
SpinEdit2 - to enter a byte in decimal form
Button3 - to send a byte
Memo1 - to display received information.

As mentioned above, you need to work with the com port in the same way as with a regular text file: using the CreateFile, WriteFile and ReadFile functions.

In order not to go into details, let's take a ready-made library for working with a com port: ComPort.

We hang the necessary task on each button and get the final code:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics , Controls, Forms,
Dialogs, StdCtrls, Spin,ComPort;

type
TForm1 = class(TForm)
SpinEdit1: TSpinEdit;
Button1: TButton;
Button2: TButton;
SpinEdit2: TSpinEdit;
Button3: TButton;
Memo1:TMemo;
procedure OnRead(Sender: TObject; ReadBytes: array of Byte );
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
(Private declarations)
Port: TComPort;
public
(Public declarations)
end;

var
Form1: TForm1;
num: integer;
implementation

Procedure TForm1.Button1Click(Sender: TObject);
begin
Port:= TComPort.Create(SpinEdit1.Value, br115200); // create a connection
Port.OnRead:= OnRead; //create a stream for reading the received data
Button2.Enabled:= true ; //activate the connection close button
end;

Procedure TForm1.Button2Click(Sender: TObject);
begin
Port Free; //close the connection
Button2.Enabled:= false ; //disable the button
end;

Procedure TForm1.Button3Click(Sender: TObject);
begin
if Button2.Enabled then Port.Write();
end;

Procedure TForm1.FormDestroy(Sender: TObject);
begin
if Button2.Enabled then
Port Free;
end;

Procedure TForm1.OnRead(Sender: TObject; ReadBytes: array of Byte );
var
i:integer;
begin
for i:= Low(ReadBytes) to High(ReadBytes) do //pass through the array of received bytes
begin
Memo1.Text:= Memo1.Text + "." +InttoHex(ReadBytes[i],2); //add its HEX value to the window
inc(num); //count the number of received bytes
end;
if num > 10 then start
Memo1.Lines.Add("" ); //transfer line
num:=0;
end;
end;

We start, establish a connection, send bytes:

So our simplest terminal is ready to work with the simplest usb device.

As you can see, reading and writing are dynamic arrays of bytes.

By processing the received information, it is possible to draw up the necessary exchange protocol suitable for the current task.

include 18f2455
--
enable_digital_io()
--
alias button is pin_B7
pin_B7_direction = input
--
--
include usb_serial
--
usb_serial_init()
var byte ch
var byte i -- declare second variable
forever loop-- main loop
usb_serial_flush()
if(usb_serial_read(ch)) then-- if the byte is received, perform the necessary actions
case ch of -- iterate over the byte number
0 : usb_serial_data = 0xff
1 : usb_serial_data = Button -- send button state
OTHERWISE block-- if something else is received
for 16 using i loop-- send 10 bytes of data
usb_serial_data = ch +i -- ch to ch+15
end loop
end block
end case
end if
end loop

Additional features

If you stop there, you get a regular article with a detailed description of an example of using the library, of which there are enough on the web. Therefore, I will add a little more in-depth information.

Simplify sending data

Sending information one byte at a time is not always convenient. The library can be very useful print. It contains procedures for sending data of all possible lengths in all possible formats: byte, hex, dec, bin, boolean, which can simplify the output of data in the program.
>include print
...
vardword data
print_dword_hex (usb_serial_data , data )

The name of all commands can be found in the library file.

Waiting for connection to PC

If before starting the main cycle of the microcontroller it is necessary to first establish a connection with the PC, then you can add the lines before it
while(usb_cdc_line_status() == 0x00) loop
end loop

Bind the port number to the device

If you leave everything as it is, the system will allocate the first free port number for each new connection. And that means you have to keep an eye on it.
To prevent this from happening, you need to assign a unique serial number value to the device before connecting the usb library:
The number can be of any length and contain various characters.
const byte USB_STRING3=
{
24 , -- array length
0x03 , --bDescriptorType
"0" , 0x00 ,
"1" , 0x00 ,
"2" , 0x00 ,
"3" , 0x00 ,
"4" , 0x00 ,
"5" , 0x00 ,
"6" , 0x00 ,
"7" , 0x00 ,
"8" , 0x00 ,
"9" , 0x00 ,
"X" 0x00
}

Change the device name to your own

You can change the name of the device visible in the system before installing the drivers by declaring an array with the name, like the serial number, this must be done before connecting the USB library.
const byte USB_STRING2=
{
28 , --
0x03 , --bDescriptorType
"D", 0x00 ,
"e", 0x00 ,
"m", 0x00 ,
"o", 0x00 ,
" " , 0x00 ,
"B", 0x00 ,
"o", 0x00 ,
"a", 0x00 ,
"r", 0x00 ,
"d", 0x00 ,
" " , 0x00 ,
"=" , 0x00 ,
")" 0x00
}

But alas, after installing the drivers, the device will change its name to the one specified in the .inf file, so we will change the name there too


DESCRIPTION="Demo CDC"

We organize automatic connection of the device

Alas, there are no direct ways to complete this task, so you have to contrive.

First of all, you need to assign a unique manufacturer and product value to your device in order to easily identify it among hundreds of other standard CDC firmware.
VID and PID are given out for money, so let's go along the path of the Chinese: quietly take ourselves obviously free values.

Firmware:
Two variables must be declared in the firmware before connecting the USB library

const word USB_SERIAL_PRODUCT_ID = 0xFF10
const word USB_SERIAL_VENDOR_ID = 0xFF10

Instead of FF10, you can insert any two words (2 bytes). The final result is contained in the attached archive.

Drivers:
Since the drivers are not designed for our combination of VID and PID, we will add our values ​​to the .inf file manually:


%DESCRIPTION%=DriverInstall, USB\VID_FF10&PID_FF10


%DESCRIPTION%=DriverInstall, USB\VID_FF10&PID_FF10

Soft:
To catch device connection / disconnection events, we will connect the ComponentUSB library. I do not consider it necessary to explain every line: all changes can be seen in the attached project.

Result

It’s hard to see in the screenshot, but the send button is active only when there is a connected device, and every 50ms the program sends a request to get the button state (which, however, is wrong, because the button press should be processed on the MK).

As you can see, organizing data exchange between MK and PC via USB is not the most difficult task. The resulting connection can be used not only for final purposes: it is also suitable for debugging a program. After all, sending the results of calculations, the current states of registers and variables to a computer is much clearer than blinking a pair of LEDs in Morse code.

And finally: I advise you to look into the source code of the mood lamp. There you can find a pretty good option for processing received data to organize a convenient exchange protocol.

In this article, I will describe several ways to make a bootable USB flash drive for free and without much effort:

Let me explain why I chose these three options, so:

The advantages of creating a bootable USB flash drive using the UltraISO program is that even in the trial (free) mode, this program will help you create a bootable USB flash drive without any problems and it also has many different functions. Cons (if they can be considered as such) is that it needs to be downloaded and installed, the installation process itself consists in pressing the Next button 4 times. In my opinion, the ideal third-party solution for creating a bootable USB flash drive for Windows XP, 7, 8.

Creating a bootable USB flash drive using the utility from Microsoft - USB / DVD Download Tool, the advantage of this method is that without special skills and abilities, thanks to a few mouse clicks, you get a bootable USB flash drive. Minus - an official (downloaded from the Microsoft website) ISO image of the operating system is required, otherwise the utility may not accept your ISO image and refuse to write it to a USB flash drive, or it will give an error when creating the image (I personally encountered such problems, which is why I consider it necessary to indicate them ).

And finally, creating a bootable USB flash drive using the Windows 7 command line. A big plus of this method is that you don’t need to install anything, but simply by entering a few commands, get a bootable USB flash drive with Windows XP, 7, 8. I don’t even know the disadvantages of this method ... probably only in its ugliness, since all commands are executed on the command line.

So, to create a bootable USB flash drive, you will need:

1 Flash drive with a capacity of at least 4 Gb (everything must be deleted from the flash drive, as it will be formatted)

2 ISO system image

3 BIOS, which will allow you to start the installation from a USB flash drive

4 Image creation utility (UltraISO, USB/DVD Download Tool)

If you have all this, then let's get started:

Create a bootable USB flash drive using UltraISO.

First of all, download the latest version UltraISO .

After that, start the installation of the program, click "Further"

We agree with the license agreement

Choose or leave the default installation location of the program

After that, the UltraISO program will open, click "File-Open"

Choose an ISO image of the system, in this example Windows 8 will be used

After that we press "Boot-Burn Hard Disk Image..."

In the next window, select the device on which the image will be written and click "Record".

After that, a warning window will appear stating that everything will be deleted from the flash drive, click "Yes".

The recording process will then start and last for a few minutes.

After the process of writing to a USB flash drive is completed, it becomes bootable.

In this article, I will describe several ways to make a bootable USB flash drive for free and without much effort:

Let me explain why I chose these three options, so:

The advantages of creating a bootable USB flash drive using the UltraISO program is that even in the trial (free) mode, this program will help you create a bootable USB flash drive without any problems and it also has many different functions. Cons (if they can be considered as such) is that it needs to be downloaded and installed, the installation process itself consists in pressing the Next button 4 times. In my opinion, the ideal third-party solution for creating a bootable USB flash drive for Windows XP, 7, 8.

Creating a bootable USB flash drive using the utility from Microsoft - USB / DVD Download Tool, the advantage of this method is that without special skills and abilities, thanks to a few mouse clicks, you get a bootable USB flash drive. Minus - an official (downloaded from the Microsoft website) ISO image of the operating system is required, otherwise the utility may not accept your ISO image and refuse to write it to a USB flash drive, or it will give an error when creating the image (I personally encountered such problems, which is why I consider it necessary to indicate them ).

And finally, creating a bootable USB flash drive using the Windows 7 command line. A big plus of this method is that you don’t need to install anything, but simply by entering a few commands, get a bootable USB flash drive with Windows XP, 7, 8. I don’t even know the disadvantages of this method ... probably only in its ugliness, since all commands are executed on the command line.

So, to create a bootable USB flash drive, you will need:

1 Flash drive with a capacity of at least 4 Gb (everything must be deleted from the flash drive, as it will be formatted)

2 ISO system image

3 BIOS, which will allow you to start the installation from a USB flash drive

4 Image creation utility (UltraISO, USB/DVD Download Tool)

If you have all this, then let's get started:

Create a bootable USB flash drive using UltraISO.

First of all, download the latest version UltraISO .

After that, start the installation of the program, click "Further"

We agree with the license agreement

Choose or leave the default installation location of the program

After that, the UltraISO program will open, click "File-Open"

Choose an ISO image of the system, in this example Windows 8 will be used

After that we press "Boot-Burn Hard Disk Image..."

In the next window, select the device on which the image will be written and click "Record".

After that, a warning window will appear stating that everything will be deleted from the flash drive, click "Yes".

The recording process will then start and last for a few minutes.

After the process of writing to a USB flash drive is completed, it becomes bootable.

USB flash drive- a common device that everyone who has a personal computer at home probably has. There are a wide variety of flash drives available today. As a rule, they have a plastic or metal case, although there are more original options. But what to do if the case of your flash drive is damaged or for some reason ceased to suit you, but you do not want to buy a new one? In this article, we will show you how to replace the old plastic or metal case of your flash drive with a new wooden case.

How to make a case for a flash drive?

In order to make a wooden case for a flash drive, we need the following tools:

USB flash drive without case.

Piece of wood.

Drill or other drilling device.

Sandpaper.

Silicone.

Clips, 2 pcs.

Pencil.

Let's start making!

1. First, determine the size of the case you need and use a saw to cut a rectangle of the appropriate size from a piece of wood using the marked marks.

3. Using a drilling device, cut non-through holes in the large and medium pieces of wood and a through hole in the smallest piece. The holes should be sized to easily fit and hold the USB stick. In the middle part, which will serve as a lid, small gaps should be made inside the hole so that the lid can close tightly and open easily.

4. Insert the USB flash drive into the through hole of the small piece so that the connector sticks out on one side and the rest of the flash drive is on the other. If the flash drive does not sit tightly in the hole, fix it with silicone.

5. Now stick the protruding long part of the flash drive into the hole of the largest piece, after applying hot glue to both parts and using a press, glue them into one case. It is necessary to use a press so that both parts are tightly fastened together, and after grinding, no gaps are visible between them.

6. Now carefully sand the entire body with sandpaper to give it a neater and smoother look. You can also cover the case with paint or varnish. Our original wooden flash drive is ready!