📜 ⬆️ ⬇️

Bluetooth controlled machine

I have long wanted to introduce my son into programming, but how to do it?
Gone are the days when they studied in BASIC and Pascal. I tried to show him TurboPascal - even something seemed to be starting to turn out, but somehow it didn’t get any further ...

I decided to make the next attempt when I met Scratch, the children's design language. It is not even a language - it is a tool for creating scripts by dragging “blocks” on the screen and connecting them with each other. Now it went better. The child was able to make even some simple game. But you need to move on?


')
In order to somehow diversify the “programming”, I thought up to make a typewriter, but so that its behavior could be controlled from a computer by a program on Scratch . That is, so that the child could somehow program the logic of the behavior of the machine.

In the Scratch programming environment itself, there seems to be even means for this: apparently somewhere there are special ScratchBoard or SesorBoard boards connected to the computer via the serial port.



This ScratchBoard board can send the values ​​of some sensors to the computer (four analog sensors A, B, C, D, a light sensor, a sound sensor, a button, etc.). Commands to one motor can be sent from the computer to the board: "on" / "off", the direction "there" / "back" and power from 0 to 100. The program (script) for controlling the motor in Scratch can look, for example, like this:



Something like Lego cubes - you connect different blocks and you get a program. The child may well master.

Actually there was an idea to make something moving, but controlled from the Scratch program.

Immediately there are several problems. The first problem - how to connect a moving machine with a computer - the wires are clearly not suitable. The second problem is that the connection should be in the form of a “serial port”, because Scratch only understands this way. The third problem, you need to know the data transfer protocol in both directions. The fourth problem - how to control the machine if Scratch knows only one motor? Fifth ... Well, enough to list the problems! Need to solve them!

1. Purchased a Bluetooth module LMX9838. This chip is good because when it is energized, it is immediately ready for operation and you can immediately establish a connection in the form of a virtual serial port from a computer. Two problems are solved immediately - wireless communication and COM-port. How to solder this module to the scarf can be read here . The BGA chip is all bottom pins, but fortunately most of the legs are not used. If you turn the chip and solder wiring on top, it greatly simplifies the work. The result is such a module:



2. With the help of Google, I found the description of the Scratch protocol on some Japanese website. Now you can get to know him better yourself, already in Russian .

3. Took the charge "Mars Rover" - this is such an "electronic designer" on the Alter FPGA. I made and sewed into the FPGA a project that implements a serial transceiver and receives and sends data using the Scratch protocol, controls the motors. Even connected to the board "Mars Rover" connected two photo-transistors - these will be the "eyes" of the machine. I sent them down to the ground. Planned that the machine would move on a white sheet of paper, on which, for example, some obstacles will be drawn. Actually, these sensors give the values ​​“dark” or “light”, and I transmit them to Scratch, as readings of the sensors “C” and “D”.



4. To control the two motors, it was decided to use such a parameter as “power”. Scratch language scripts can set the “power” motor connected via ScratchBoard. I decided so. If the power is zero, then the first motor can work, and the second is not. If the power is 50, then both motors can work. If the power is set to 100, then the second motor can work, but not the first one. Certainly not entirely elegant, but some way out. They turn on at the command “motor on” and turn off at the command “motor off”.

Well, that's all.
The entire machine assembly looks something like this: two motors on a platform with a caterpillar drive, a “Mars Rover” board, optical sensors-eyes, a Bluetooth module. On a large piece of paper we draw a figure of eight with black gouache (and so that it dries).

A child makes a program on Scratch - something like this:



Then we turn on the machine, establish a Bluetooth connection between the computer and the machine. And run the Scratch program: The typewriter moves along the strip, and this logic is set by our Scratch program!



PS: The very next day a thought occurred to me. There is a machine with Bluetooth. Can you manage it from a cell phone? By evening, the Java program for my nokia was ready!



I wrote it using the Sun Wireless Toolkit. You can read more about this project here . There is also a java program source.

Source: https://habr.com/ru/post/113079/


All Articles