Hi, Habr. Probably every person has old cell phones lying around. The battery died, the screen was scratched, just tired.
In some cases, such an “old” phone is a rather advanced device. For example the former daughter of the SonyEricsson Z310i - java, bluetooth, camera, gprs. Why not use it to fulfill your old childhood dream - a radio-controlled machine with a camera on board? And here several circumstances came together: a phone was lying around, a broken machine from somewhere without a remote control took shape, a younger son grew up, an article came to Habré, a website was found on the Internet.
So, the algorithm:
user P presses buttons on T1 cell phone
T1 transmits commands via bluetooth
the machine carries on itself a T2 cell phone, which receives them and transmits them via the audio channel (wired hands-free) to the microcontroller
MK, in turn, recognizes the commands and controls the engines, light bulbs and all the rest.
T2 shoots what is happening on camera and transmits it back to T1,
T1 transmits the resulting image via optical communication.
????
P rejoices
')
Tools and materials
An order went to one of the stores, and after a while I became the owner of the STM32L-DISCOVERY debugging board, a mock-up board, an L293D engine driver, and any split-wire trivia. As a first step, the broken suspension of the machine was sealed, the engines checked, their consumption measured. Documentation for a board, a processor and L293D is found on the Internet. IAR was selected as IDE.
Actions by hands
Naturally, all the stages of MK programming were completed - to blink, write something of your own on the LCD, to buzz. A tester, a children's electronic designer, and an old oscilloscope were very helpful for debugging peripherals. In general, writing code on the mic consists mostly of tasting and combining standard examples. The next stage is to prepare a board, solder the driver of the engine and try real control. Along the edges of the MK board, almost all of his legs are pulled out onto fairly long pins with a standard pitch of 2.5 mm, and up and down. To connect on weight, PBS-6 connectors were used. The finished device on the typewriter itself is a piece of a mock-up board with the same connectors, i.e., a self-made shieldboard. And here the driver of the engine is connected, and we already blink an incandescent bulb from the designer. Now we solder the power to the connector under the GND and EXT_5V legs. It is very successful that the power and control legs stand diagonally - the boards stick well together on just two connectors. Solder the battery pack, the wires to the motors (it's funny that they can be confused - reprogramming the controller is easier than unraveling the wiring). A small program - and now the blind and deaf machine goes back and forth, and performs a turn in 12 receptions.
Command
After a brief googling and thoughtful looks in the oscilloscope, the simplest decision was made - the commands are encoded with sinusoidal signals of different frequencies. From the side of the phone, the frequencies are generated by playing the WAV stream 8bit, mono, 8kHz sampling. The sampling frequency dividers were selected as command frequencies, i.e. 160, 200, 250 ... 2000 Hz. Thus, at this stage, we have 9 teams, of which 7 are used for movement (forward, backward, forward-left, backward-right ... stop). To measure the frequency on the side of the MC, a timer, interrupt and comparator are used. The negative input of the comparator is switched to the internal reference voltage of 0.3 V (Vref / 4), the comparator output is set to trigger an interrupt when the leading edge of the pulse passes. The 16-bit timer counts 8 MHz frequency pulses. At the time of the interruption, the timer counter value is read and compared with the previous count. In case of detection of 5 approximately identical impulses in a row, the team is considered to be accepted. In order for the machine to stop in the event of exit from the reception area, the telephone-console periodically transmits zero bytes in between the commands. If the phone receiver does not receive any commands for about 200 ms, the motors are turned off.
And on this joyful note, problems begin.
It turned out that the selected phone does not support bluetooth from under java. another half-dead phone, the SonyEricsson C702, is so overwhelmed with the Achh in the upper frequencies that the commands are not recognized. The third phone - my main Samsung B2100 - has an incredible number of bugs in java, which is almost impossible to work with. The camera on the C702 manages to produce some incredible size photos, which are then long and tediously transmitted via bluetooth. In addition to all this, when debugging the sound reproduction scheme, I unsuccessfully poked the oscilloscope probe into the board. The cheerful light and a trickle of smoke made me say goodbye to the MK board, but it turned out that everything was not so bad. I just burned the diode in the power supply circuit of the programmer and one of the outputs of the MK. Now, for firmware and debugging of the program, it is necessary to connect not only USB, but also battery power, and the burned out output had to be re-soldered to a free working pin.
As a result, adjustments were made to the initial idea - the voltage in the sound path is compared with the ground, and the photos taken from the camera are clamped in JPEG 100 * 160 pixels before transmission.
Sound path, lead and lights
The presence of a DAC controller and a fairly large amount of flash memory (128kb) suggested that you can teach the machine to speak. To do this, we wrote down 2 wave files with the little boy and added them to the program. I had to record sounds on my wife’s netbook with Windows XP, because standard means of seven can not record a WAV file in PCM 8bit. (by the way, tell the program to simplify the conversion of sound files). To enhance the sound, a K174un24 chip is used, the sound is output to 2 8 ohm 1W speakers.
As a final touch, finger batteries were replaced with a 6V 4.7Ah lead battery. In parallel, the main engine was soldered white LEDs as headlights. The machine has acquired "patsansky" xenon, the mass and dynamics of this jeep, the drawdown of the suspension and the roar of the engine.
And the project is over.
The machine can move around by a team, takes pictures and speaks in an inhuman voice. This project was my first step into the world of artisanal robotics, which brought me together with wonderful people and re-taught me how to hold a soldering iron in my hands. However, the continuation of this project will not be, because the initial idea itself is not very justified.
Platform j2me demonstrated all its inherent wretchedness.
Despite the seemingly unified and branched api, the preponderance of bugs and shortcomings in implementations does not allow to use all the inherent capabilities. The security system always requests access to phone resources. On the control panel, you can put up with it, but on a typewriter - it interferes terribly. Processing and transferring even small images takes an insane time - about 5 seconds. Talking about the transfer of video or images in any real time does not make sense.
Iron
The L293D chip is very convenient to use, but, unfortunately, it is made on bipolar transistors, and at a supply voltage of 5-6V, half of the battery energy is spent on heating the global space. Well, inexpensive machine from the supermarket is not a good mechanical platform.
Realizing all this, I decided to stop the development of the project, and the first step was followed by the second one - Wi-Fi, cameras and more advanced electronics.