• Guest
HabraHabr
  • Main
  • Users

  • Development
    • Programming
    • Information Security
    • Website development
    • JavaScript
    • Game development
    • Open source
    • Developed for Android
    • Machine learning
    • Abnormal programming
    • Java
    • Python
    • Development of mobile applications
    • Analysis and design of systems
    • .NET
    • Mathematics
    • Algorithms
    • C#
    • System Programming
    • C++
    • C
    • Go
    • PHP
    • Reverse engineering
    • Assembler
    • Development under Linux
    • Big Data
    • Rust
    • Cryptography
    • Entertaining problems
    • Testing of IT systems
    • Testing Web Services
    • HTML
    • Programming microcontrollers
    • API
    • High performance
    • Developed for iOS
    • CSS
    • Industrial Programming
    • Development under Windows
    • Image processing
    • Compilers
    • FPGA
    • Professional literature
    • OpenStreetMap
    • Google Chrome
    • Data Mining
    • PostgreSQL
    • Development of robotics
    • Visualization of data
    • Angular
    • ReactJS
    • Search technologies
    • Debugging
    • Test mobile applications
    • Browsers
    • Designing and refactoring
    • IT Standards
    • Solidity
    • Node.JS
    • Git
    • LaTeX
    • SQL
    • Haskell
    • Unreal Engine
    • Unity3D
    • Development for the Internet of things
    • Functional Programming
    • Amazon Web Services
    • Google Cloud Platform
    • Development under AR and VR
    • Assembly systems
    • Version control systems
    • Kotlin
    • R
    • CAD/CAM
    • Customer Optimization
    • Development of communication systems
    • Microsoft Azure
    • Perfect code
    • Atlassian
    • Visual Studio
    • NoSQL
    • Yii
    • Mono и Moonlight
    • Parallel Programming
    • Asterisk
    • Yandex API
    • WordPress
    • Sports programming
    • Lua
    • Microsoft SQL Server
    • Payment systems
    • TypeScript
    • Scala
    • Google API
    • Development of data transmission systems
    • XML
    • Regular expressions
    • Development under Tizen
    • Swift
    • MySQL
    • Geoinformation services
    • Global Positioning Systems
    • Qt
    • Dart
    • Django
    • Development for Office 365
    • Erlang/OTP
    • GPGPU
    • Eclipse
    • Maps API
    • Testing games
    • Browser Extensions
    • 1C-Bitrix
    • Development under e-commerce
    • Xamarin
    • Xcode
    • Development under Windows Phone
    • Semantics
    • CMS
    • VueJS
    • GitHub
    • Open data
    • Sphinx
    • Ruby on Rails
    • Ruby
    • Symfony
    • Drupal
    • Messaging Systems
    • CTF
    • SaaS / S+S
    • SharePoint
    • jQuery
    • Puppet
    • Firefox
    • Elm
    • MODX
    • Billing systems
    • Graphical shells
    • Kodobred
    • MongoDB
    • SCADA
    • Hadoop
    • Gradle
    • Clojure
    • F#
    • CoffeeScript
    • Matlab
    • Phalcon
    • Development under Sailfish OS
    • Magento
    • Elixir/Phoenix
    • Microsoft Edge
    • Layout of letters
    • Development for OS X
    • Forth
    • Smalltalk
    • Julia
    • Laravel
    • WebGL
    • Meteor.JS
    • Firebird/Interbase
    • SQLite
    • D
    • Mesh-networks
    • I2P
    • Derby.js
    • Emacs
    • Development under Bada
    • Mercurial
    • UML Design
    • Objective C
    • Fortran
    • Cocoa
    • Cobol
    • Apache Flex
    • Action Script
    • Joomla
    • IIS
    • Twitter API
    • Vkontakte API
    • Facebook API
    • Microsoft Access
    • PDF
    • Prolog
    • GTK+
    • LabVIEW
    • Brainfuck
    • Cubrid
    • Canvas
    • Doctrine ORM
    • Google App Engine
    • Twisted
    • XSLT
    • TDD
    • Small Basic
    • Kohana
    • Development for Java ME
    • LiveStreet
    • MooTools
    • Adobe Flash
    • GreaseMonkey
    • INFOLUST
    • Groovy & Grails
    • Lisp
    • Delphi
    • Zend Framework
    • ExtJS / Sencha Library
    • Internet Explorer
    • CodeIgniter
    • Silverlight
    • Google Web Toolkit
    • CakePHP
    • Safari
    • Opera
    • Microformats
    • Ajax
    • VIM
  • Administration
    • System administration
    • IT Infrastructure
    • *nix
    • Network technologies
    • DevOps
    • Server Administration
    • Cloud computing
    • Configuring Linux
    • Wireless technologies
    • Virtualization
    • Hosting
    • Data storage
    • Decentralized networks
    • Database Administration
    • Data Warehousing
    • Communication standards
    • PowerShell
    • Backup
    • Cisco
    • Nginx
    • Antivirus protection
    • DNS
    • Server Optimization
    • Data recovery
    • Apache
    • Spam and antispam
    • Data Compression
    • SAN
    • IPv6
    • Fidonet
    • IPTV
    • Shells
    • Administering domain names
  • Design
    • Interfaces
    • Web design
    • Working with sound
    • Usability
    • Graphic design
    • Design Games
    • Mobile App Design
    • Working with 3D-graphics
    • Typography
    • Working with video
    • Work with vector graphics
    • Accessibility
    • Prototyping
    • CGI (graphics)
    • Computer Animation
    • Working with icons
  • Control
    • Careers in the IT industry
    • Project management
    • Development Management
    • Personnel Management
    • Product Management
    • Start-up development
    • Managing the community
    • Service Desk
    • GTD
    • IT Terminology
    • Agile
    • Business Models
    • Legislation and IT-business
    • Sales management
    • CRM-systems
    • Product localization
    • ECM / EDS
    • Freelance
    • Venture investments
    • ERP-systems
    • Help Desk Software
    • Media management
    • Patenting
    • E-commerce management
    • Creative Commons
  • Marketing
    • Conferences
    • Promotion of games
    • Internet Marketing
    • Search Engine Optimization
    • Web Analytics
    • Monetize Web services
    • Content marketing
    • Monetization of IT systems
    • Monetize mobile apps
    • Mobile App Analytics
    • Growth Hacking
    • Branding
    • Monetize Games
    • Display ads
    • Contextual advertising
    • Increase Conversion Rate
  • Sundry
    • Reading room
    • Educational process in IT
    • Research and forecasts in IT
    • Finance in IT
    • Hakatonas
    • IT emigration
    • Education abroad
    • Lumber room
    • I'm on my way

The Arduino machine, controlled by an Android device via Bluetooth, is the application code and mk (part 2)

About the first part of


 
In the first part, I described the physical part of the design and only a small chunk of code. Now consider the software component - the Android application and the Arduino sketch.
 
 
First, I will give a detailed description of each moment, and at the end I will leave the links to the whole project + video of the result, which should you disappoint cheer.
 
github.com/IDolgopolov/BluetoothWorkAPP.git . There the code without comments, therefore it looks much cleaner, less and easier.
 

Sketch Arduino


 
Android application is dismantled, written, understood and then it will be easier. I'll try to consider everything step by step, and then I'll give a link to the full file.
 

The variables are


 
First, let's look at the constants and variables you need.
 
#include
//reassign the bluetooth input pin
//do not have to take it out while filling the sketch onto the board
SoftwareSerial BTSerial (? 9);
//turn and speed pins
int speedRight = 6;
int dirLeft = 3;
int speedLeft = 11;
int dirRight = 7;
//pins of the engine turning the wheels
int angleDirection = 4;
int angleSpeed ​​= 5;
//a pin to which plus pieces are attached, defining the rotation
//the detailed technology is described in the first part of
int pinAngleStop = 12;
//here we will write the values ​​
String val;
//rotation speed
int speedTurn = 180;
//the pins that define the rotation
//table and descriptions of the system in the first article
int pinRed = A0;
int pinWhite = A1;
int pinBlack = A2;
//variable for the time
long lastTakeInformation;
//variables indicating that
will now be read. boolean readAngle = false;
boolean readSpeed ​​= false;

 

The setup () method is


 
In the setup () method, we set the parameters of the pins: they will work on the input or output. Also, we will establish the speed of communication between the computer and the Arduinka, the bluetooth with the Arduinka.
 
    void setup () {
pinMode (dirLeft, OUTPUT);
pinMode (speedLeft, OUTPUT);
pinMode (dirRight, OUTPUT);
pinMode (speedRight, OUTPUT);
pinMode (pinRed, INPUT);
pinMode (pinBlack, INPUT);
pinMode (pinWhite, INPUT);
pinMode (pinAngleStop, OUTPUT);
pinMode (angleDirection, OUTPUT);
pinMode (angleSpeed, OUTPUT);
//this speed is relevant only for model HC-05
//if you have a different version of the module, see the documentation
BTSerial.begin (38400);
//this speed is constant
Serial.begin (9600);
}

 

The loop () method and the additional functions


 
In a recurring loop () method, data is read. First, consider the main algorithm, and then the functions involved in it.
 
  
void loop () {
//if at least unread bytes are
if (BTSerial.available ()> 0) {
//read the last unread byte
char a = BTSerial.read ();
if (a == '@') {
//if it is @ (randomly chosen by me symbol)
//zero the variable val
val = "";
//indicate that now we consider the speed
readSpeed ​​= true;
} else if (readSpeed) {
//if it's time to read the speed and the byte is not equal to the lattice
//add a byte to val
if (a == '#') {
//if the byte is equal to the grid, the speed data is over
//output to port monitor for debugging
Serial.println (val);
//indicate that the speed is no longer read
readSpeed ​​= false;
//transfer the received speed to the ride function
go (val.toInt ());
//zero the val
val = "";
//exit the loop to read the next byte
return;
}
val + = a;
} else if (a == '*') {
//begin to read the angle of rotation
readAngle = true;
} else if (readAngle) {
//if the lattice, then finish reading the angle
//not yet a lattice, add the value to val
if (a == '#') {
Serial.println (val);
Serial.println ("-----");
readAngle = false;
//pass the value to the rotation function
turn (val.toInt ());
val = "";
return;
}
val + = a;
}
//get the time of the last data reception
lastTakeInformation = millis ();
} else {
//if there are no unread bytes, and there were not more than 150 milliseconds
//muffle the engines
if (millis () - lastTakeInformation> 150) {
lastTakeInformation = 0;
analogWrite (angleSpeed, 0);
analogWrite (speedRight, 0);
analogWrite (speedLeft, 0);
}
}
}

 
We get the result: from the phone we send bytes in the style of "@ speed # angle #" (for example, the typical command "@ 200 # 60 #" .This cycle is repeated every 100 milliseconds, since on the android we set this interval of sending commands. there is no sense, since they will start to become in the queue,and if done longer, the wheels will start to move in spurts.
 
 
All the delays through the delay () command, which you'll see later, are not matched by physical and mathematical calculations, but by empirical means. Thanks to all the exposed ditches, the car travels smoothly, and all teams have time to work (currents have time to run).
 
 
In the cycle, two side functions are used, they accept the received data and force the machine to go and spin.
 
    void go (int mySpeed) {
//if the speed is greater than 0
if (mySpeed> 0) {
//go ahead
digitalWrite (dirRight, HIGH);
analogWrite (speedRight, mySpeed);
digitalWrite (dirLeft, HIGH);
analogWrite (speedLeft, mySpeed);
} else {
//and if less than ? then backwards
digitalWrite (dirRight, LOW);
analogWrite (speedRight, abs (mySpeed) + 30);
digitalWrite (dirLeft, LOW);
analogWrite (speedLeft, abs (mySpeed) + 30);
}
delay (10);
}
void turn (int angle) {
//supply current to plus of the angle determinant
digitalWrite (pinAngleStop, HIGH);
//give a delay so that the current can be established
delay (5);
//if the angle is 150 or more, turn to the right
//if 30 and less, then left
//the interval from 31 to 149 is left for the movement straight
if (angle> 149) {
//if white is closed, but black and red are open
//means the extreme position is reached, it is impossible to turn on further
//exit the function via return
if (digitalRead (pinWhite) == HIGH && digitalRead (pinBlack) == LOW && digitalRead (pinRed) == LOW) {
return;
}
//if the check for the maximum angle is passed
//spin the wheels
digitalWrite (angleDirection, HIGH);
analogWrite (angleSpeed, speedTurn);
} else if (angle ? if (digitalRead (pinRed) == HIGH && digitalRead (pinBlack) == HIGH && digitalRead (pinWhite) == HIGH) {
return;
}
digitalWrite (angleDirection, LOW);
AnalogWrite (angleSpeed, speedTurn);
}
//remove power
DigitalWrite (pinAngleStop, LOW);
delay (5);
}
.
.
 
Turn, when the android sends data that the user clamped the angle of 6? 9? 12? it is not necessary, otherwise you can not go straight. Yes, it might not be worthwhile to send a command from the android to a turn if the angle is too small, but it's somehow clumsy in my opinion.
 

The results of sketch


 
The sketch has only three important steps: reading the command, processing the rotation restrictions and applying current to the motors. Everything, sounds simple, and in performance is easier than easy, although it was created long and with blunts. The full version of the sketch is github.com/IDolgopolov/AgroArduinoF .
 

Eventually


 
A full inventory of several months of work is over. The physical part is dismantled, the software part is even more so. The principle remains the same - turn to incomprehensible phenomena, we will understand together.
 
And the comments under the first part are interesting, advised a mountain of useful advice, thanks to each.
 

Video of the result


 

It may be interesting

  • Comments
  • About article
  • Similar news
This publication has no comments.

weber

Author

29-09-2018, 15:22

Publication Date

Development / Development of robotics

Category
  • Comments: 0
  • Views: 318
Arduino. The project "Robot car
The machine on Arduino, controlled with
As we GLK into the autopilot converted
TOTAL of 3 months: An alternative to
Arduino for beginners. Part 2
Arduino controller with temperature
Write a comment
Name:*
E-Mail:


Comments
I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article...Adsense Safe Traffic
Today, 14:50

jacksonseo

Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up. 123 movies
Today, 12:11

Legend SEO

Cảm ơn vì đã chia sẻ bài viết này. Tôi rất vui khi thấy bài viết tuyệt vời này.https://skribblio.co/
Today, 04:38

gm massi melissa012021


Can I find someone to write my paper for me free? At our cheap for-pay academic help service with writers across all subjects. Discover more about us here.
write a paper online free
Yesterday, 19:45

nushra45

Pretty nice post. I  just stumbled upon your weblog and wanted to say that I have really enjoyed  browsing your blog posts. After all I’ll be subscribing to your feed and I  hope you write again soon!  soaptoday
Yesterday, 17:35

Legend SEO

Adv
Website for web developers. New scripts, best ideas, programming tips. How to write a script for you here, we have a lot of information about various programming languages. You are a webmaster or a beginner programmer, it does not matter, useful articles will help to make your favorite business faster.

Login

Registration Forgot password