Networking and Communication

Hello from the other side!

Assignment

This week's assignment was to demonstrate 2 microcontrollers communicating over wired or radio connection.


Materials and Software Used

Arduino Unos, Arduino/C, nRF24 module, servo motor, LEDs


Background

Having two microcontrollers communicate with each other is highly useful in remotely controlling actuators and output devices. When looking at the bigger picture, it is imperative in controlling robots, setting up a home automation system, monitoring sensor data, etc.

I first connected two microncontrollers using universal asynchronous receiver-transmitter (UART), which takes bytes of data and transmits the individual bits in a sequenctial fashion. Asynchronous means that the data is transferred without the need of an external clock signal. This minimizes the number of wires required for connection and I/O pins. It is therefore widely used in everyday electronics that include GPS, Bluetooth, or serial LCDs.

For both of my circuits, I wired my microncontrollers together using the RX, TX pins.A serial bus consists of two wires -- one from the sending data (TX) and another for receiving (RX). Therefore, the RX pin on the receiver should be connected to the TX pin on the transmitter and the RX pin on the transmitter should be connected to the TX pin on the receiver. Since I make one solely the receiver and one just a transmitter, the serial interface was simply a half-duplex in that communication means serial devices take turns sending and receiving.


Hello Received!

Since I couldn't get my SAMD board to work (and kind of forgot tha I could have used the feather this whole time) I decided to use two Arduino boards that I had made sure to obtain in the scramble to leave campus. I followed the tutorial here (https://iot-guider.com/arduino/serial-communication-between-two-arduino-boards/) to learn the basics of getting two Arduno Unos to communicate with each other through the pins.

Essentially, the transmitting Uno board would send out the string, "Hello" and the receiving Uno would print this out in its serial monitor, along with the string, "received." This simple project made me realize that I could have probably done this on an LCD display but since I didn't have on, I stuck to the serial monitor for this assignment.


Arduino Circuit for Hello Tutorial


Image

Code for the Transmitter


Image

Code for the Receiver


Image

Serial monitor prints of "Hello Received"


Image




Using Radio Communication to Light a Bulb!


Using the nRF24L01+ transceiver module, I was able to make the Uno boards communicate with each other wirelessly. The module is designed to operate in 2.4 GHz worldwide ISM (Industrial, Scientific, and Medical) frequency band, which is one of the bands reserved internationally for the use of unlicensed low-powered devices, and uses GFSK modulation for data transmission.

The operating voltage is from 1.9-3.6V but the logic pins are 5V tolerant, so it can be connected to the Uno without any converter. They are the most common modules used because of their low current draw (26 microamps in standby mode and 900 nanoamps at power down mode).

The transciever module communicate over a 4-pin SPI. The SPI bus uses a concept of a Master and Slave. In this exmaple, the Arduino is the Master and the radio module is the slave. This module uses an on-board antenna that allows for a more compact version of the breakout. The smaller antenna means a lower transmission range, allowing for communication with over a 100 meters in distance (without walls...).

centered image

****I think a lot of credit probably goes to my friend Meghan for this idea. I am no owner of this and thank her wholeheartedly for saving me some time the night before.



centered image

Using this pinout diagram, I hooked up the module to the Uno board using male head wires to the following pins in order from left to right, top to bottom: 3.3V, digital 10, digital 11, (right one left empty); GND, digital 9, digital 13, and digital 12.

I then set this up in Arduino with the following code:


Transmitting Board Code

centered image

Transmitting Board

I wired up the module to the same I/O pins on both the transmitter and receiver boards

Image

Receiving Board

Image

As you can see in the code to the left, radio.begin(); initiated the radio module signal and radio.openWritingPipe(address) set up the address where the data was being sent. The radio.stopListening(); command set up the module as the transmitter and the radio.startListening(); set up the receiving module.

Receiving Board Code

Image

Botton Wiring on the Sending Board


Image

LED Wiring on the Receiving Board


Image

Transmitting Board Loop

centered image

Using these loops, I then created two button states: one High and one Low. When the button was pressed (i.e. state=HIGH), the radio module would write this text and send it over to the receiver which would read the data with its radio module and determine which state the button was in with an if statement. This conditional, when true, would then turn the pin connected to the LED on HIGH if the button was pressed, thus allowing current to flow through the LED to light it up!

Receiving Board Loop

I wired up the module to the same I/O pins on both the transmitter and receiver boards

Image


centered image



Let's Move!


Using the same steps in the previous activity, I made a button-operated servo motor that would rotate up to 120 degrees repeatedly.

When the button was pushed, the conditional on the receiving side would write to the servo motor, causing it to rotate. This was quite simple, especially after the much of the struggle involved in trying to figure out the code for the button-operated LED was in the past. This did, however, give me an idea to do the same with DC motors (say driving a tiny robot) that could be remotely operated. Maybe to bring me water. Or a snack. From the couch to the kitchen (yeah it's about to wind down to those times...).

Sending Board Code

Image

Receiving Board Code

Image
centered image