Week 14. Networking and communications.

Assignment of this week is to design and build a wired &/or wireless network connecting at least two processors

Internet of Things (IoT) - the concept of the computer network of physical objects ("things"), equipped with built-in technologies to communicate with each other or with the environment, which considers the organization of such networks as a phenomenon that can rebuild the economic and social processes, are excluded from the of the actions and operations need human intervention.

In this case it will be interesting to do my robot blue-tooth driving

For communication with the Bluetooth module will use SoftwareSerial. This will give us an opportunity to connect Bluetooth module to virtually any microcontroller pins.

Now we need to physically connect a Bluetooth module to the board Arduino. Module HC-05 has the 4th contact (they were signed on the motherboard). Two of them - the power module. They connect to the standard power supply + 5V on the board Arduino. The other two - a bus UART interface: RX and TX, responsible for transmitting and receiving data. Contact RX must be connected to pin on the Arduino, which have a function TX, TX and pin to pin on the Arduino, having a function RX.

The code sketch, there are two definitions of pins connected to the module Bluetooth. Find the line of code. They just determine which pins will be used when configuring SerialSoftware:
#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3

So contact RX Bluetooth module connect to pin 3 board Arduino, and the contact TX - 2 to pin boards.

Now you can fill in the source code to the microcontroller.

I use bluetooth HC-05, because It has the opportunity to fill in the Arduino sketch, without turning off the unit by RT-TX pins.

Specification bluetooth module HC-05:

Connecting the bluetooth module HC-05 to Arduino

VCC - +5v (+5 volt)
GND - GND (ground)
RX - TX (arduino pin)
TX - RX (arduino pin)
LED - (don't use)
KEY - (don't use)

After connection you see the blinking of blue LED on the module with a frequency of about 4 times per second without pause, this display module enabled without any connections to any device. Now we turn to the settings of phones bluetooth (I use the phone FLY IQ446 with android 4.1.2)

For electronic design I use the program cold FRITZING. This program has user friendly interface and very useful at designing of breadboards.

Turn on bluetooth on your phone and search for new bluetooth device, find the device with the name of HC-05 and connected to it at the password prompt, enter PIN 1234

After a successful connection to the Arduino IDE go and write a simple sketch to send data to the arduino to your phone via bluetooth module.

int cnt = 0; // register

void setup() {

Serial.begin(9600); // port initialization

}

void loop() {

cnt++;

Serial.print("Hello BB from Arduino! Counter:"); // output of inscription

Serial.println(cnt); // derive the value of the counter on new line

delay(1000); // wait one second

}

Loading sketch into Arduino and then go to the phone and install the program to display data received via bluetooth. Download the app from Google Play application Bluetooth Terminal and install on your phone.

There will appear the window during starting the application^

Open the settings menu and select Connect a device – Secure (it marked red in the picture)

Choose our bluetooth module HC-05.

A window appears displaying the data that we arduino sends phone.

Addition

In my task I use two microcontroller boards: Arduino and my circuit board with Attiny.

For programming Attiny 2313A-SU I use Arduino ISP.

Here is code:


#include
#include
#include
#define output(directions,pin) (directions |= pin) // set port direction for output
#define input(directions,pin) (directions &= (~pin)) // set port direction for input
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 « bit)) // test for bit set
#define bit_delay_time 102 // bit delay for 9600 with overhead
#define bit_delay() _delay_us(bit_delay_time) // RS232 bit delay
#define half_bit_delay() _delay_us(bit_delay_time/2) // RS232 half bit delay
#define input_port PORTB
#define input_direction DDRB
#define input_pin (1 « PB4)
#define input_pins PINB
#define serial_port PORTB
#define serial_direction DDRB
#define serial_pin_out (1 « PB2)
void put_char(volatile unsigned char *port, unsigned char pin, char txchar) {
//
// send character in txchar on port pin
// assumes line driver (inverts bits)
//
// start bit
//
clear(*port,pin);
bit_delay();
//
// unrolled loop to write data bits
//
if bit_test(txchar,0)
set(*port,pin);
else
clear(*port,pin);
bit_delay();
if bit_test(txchar,1)
set(*port,pin);
else
clear(*port,pin);
bit_delay();
if bit_test(txchar,2)
set(*port,pin);
else
clear(*port,pin);
bit_delay();
if bit_test(txchar,3)
set(*port,pin);
else
clear(*port,pin);
bit_delay();
if bit_test(txchar,4)
set(*port,pin);
else
clear(*port,pin);
bit_delay();
if bit_test(txchar,5)
set(*port,pin);
else
clear(*port,pin);
bit_delay();
if bit_test(txchar,6)
set(*port,pin);
else
clear(*port,pin);
bit_delay();
if bit_test(txchar,7)
set(*port,pin);
else
clear(*port,pin);
bit_delay();
//
// stop bit
//
set(*port,pin);
bit_delay();
//
// char delay
//
bit_delay();
}
int main(void)
{
/* Replace with your application code */
DDRB |= 1«3;
bool down = 0;
while (1)
{
if(PINB & 1«3 > 0 && !down){
down = true;
put_char('1');
}else if(PINB & 1«3 == 0){
down = false;
}
ORTB|= 1«4;
PORTB|= down«5;
_delay_ms(500);
PORTB|= 0«4;
PORTB|= 0«4;
_delay_ms(500);
}
}

Here is video

When I press button LED ups and send to port "1".

Archive with program is here.