The brains of my robot - Arduino, the first experience
I was always visited by the idea of making an Arduino- based robot, and one morning my colleague says - “It would not be bad to buy an Arduino controller for ...”, I certainly knew about him not by hearsay, and it all started. We do "Arduino CAR"!
')
Where to get?
Based on the fact that in Rostov-on-Don, and I just didn’t hear about the Arduino platform in one store, I ordered everything online.
As it turned out cheaper to buy everything in China through ebay, but there is a big minus - a very long time. Delivery of the order from Hong Kong more than a month.
The second option to take in our homeland, delivered in a week - two, but a little more expensive. I use the Amperka store, here the choice is not great, but there is everything you need to get started. And a good quality product (in a box with brand labels, as it should be), unlike a Chinese brother.
What to take?
My advice - decide on the goal, then order, otherwise you can take a surplus.
My goal is to remotely control a moving platform using a PC.
Immediately advice - do not put complex tasks, if you are just starting, or break the goal into more simple tasks.
I decided to simplify the task - I need the platform to go around the room and not crash into the walls.
For my first robot, I ordered:
Arduino New Version Mega 2560 Starter Package Kits - this is the so-called start package, which includes the controller itself and related materials. I took a set with an LCD display, but for the first project it was possible to get along with Uno .
Motor Drive Shield L293D for Arduino Duemilanove Mega / UNO - Power module for controlling engines.
Arduino Sensor Shield V5.0 - module for connecting sensors, and peripherals.
Arduino Sharp IR Sensor - GP2Y0A21YK0F - infrared range finder.
The Arduino Robot Platform All-Wheel-Drive 4 Wheel Chassiss is a fully powered platform with electric motors.
Where to begin?
The Internet is teeming with articles on how to work and program under Arduino. I did not go deep, I decided to start with simple things:
I downloaded the software from the official site: a driver for connecting the controller and a development environment with a compiler.
I wrote the first program using the online directory (kernel and library functions). At the same time I had to remember the basics of the programming language "C".
I connected and flashed the controller. The procedure is quite simple if you use the Arduino development tool .
How to collect?
Everyone decides for himself how to do and where to start, I know one thing - you need to solder the wires qualitatively!
For the assembly will need: head, hands and a little knowledge in electrical engineering.
The simplest thing is to assemble the platform, solder the circuits, install the controller board on board, then it is more difficult.
Be careful when connecting peripherals to the controller or expansion cards.
For example, I was faced with the fact that the pinout on the expansion board (Sensor Shield) did not coincide with the sensor with a range finder and LCD display, or rather the connectors fit perfectly and the polarity does not match. If the polarity is not observed, you can simply burn the equipment.
Many things come with development experience.
For example, I ran into the problem of connecting an LCD display to a serial port.
Rather, there were no problems, the display worked, but when the display is connected, the controller cannot be flashed because the port is busy (for a long time it was impossible to understand why the firmware is not flooded).
Mega 4 hardware serial ports, it would seem that it is easier, switch the display to the second, but it was not there, the expansion card I used does not capture the necessary pins on the controller.
As a result, I connected the LCD to the analog port and used the library to work with the software serial connection.
How to program?
Well, here the taste and color of comrades is not. Everything depends on the task.
I will not tell you how I did it, I will describe only a few moments.
In order for your program to work, the controller only needs to see two functions — it is the initialization of the controller (executed at startup) and the function of the main loop. The simplest example can be found here .
Next, I ran into the problem of reading data from the sensor - range finder.
When reading data, at each iteration of the cycle, different values of the signal came at the same distance.
It turned out that the sensor transmits a signal to an analog port with a certain amplitude and sometimes at the time of reading the data the value turned out to be different from the normal one, because the iteration was a failure. I had to write the function of reading from the sensor, so that I could take several readings in a row, and then weed out the erroneous values and bring everything to the arithmetic average.