14. Networking and communications¶
This week I Designed a network of 2 nodes and also created a way of addressing the nodes via a Smartphone over Bluetooth.
Connection Setup¶
- The main Idea of my assignment was to use the Attiny board that was previously designed and manufactured as the first node and Arduino Uno as the Second node. with the help of a smartphone and App designed in the application programming week, I used the HC06 Bluetooth module, to send different numbers like 1 for node 1 and 2 for node 2 and the respective nodes would blink and Send a message via Bluetooth that says which node it is.
- As shown in the image below The ATtiny is connected to the hardware serial port of the Arduino Uno and the Bluetooth is connected to pin numbers 10 and 9 and Communicates using Software Serial Communication.
Connection Setup
Programming¶
-
As shown in the code of Node 2 the Bluetooth module Communicates using Software serial communication named serial (notice that hardware serial is Serial with capital ‘S’) hence the difference. When a message (in our case address) is sent via Bluetooth, Node 2 checks if the address is ‘2’ then it corresponds to its address and responds by Lighting the LED for 2 sec as well as sending a message to the Bluetooth saying “This is Node 2”. The message gets printed on the smartphone’s screen. However, If the address sent is not ‘2’ then Node 2 forwards the Address to Node 1 (as shown in the code). When it Reaches at Node 1 if the address is ‘1’ then Node 1 Lights up the LED for 2 sec and forwards a message “This is Node 1” to Node 2 which as seen from the code also sends it to the Bluetooth in order to be printed on the smartphone’s screen. This is achieved by using the String Variable Text which has been put in a for loop in order to combine all characters sent by Node 1 ( Notice that here Hardware serial is used which doesn’t interfere with the Software serial of the Bluetooth). The characters are converted from decimal to Characters by using the Typecast char() .
-
Finally, the Message gets printed via bluetooth by using serial.print(Text) (notice the small ‘s’ as the bluetooth uses Software Serial).
Codes for Node1 and Node2
Output¶
- The output is as shown in the video below.
Group work¶
In the group assignment we did communication between Node-RED and ESP8266s by using MQTT communication protocol. Detailed Group documentation can be found here.