| Communication Protocols |
Few microcontroller applications are as pervasive and practical and as Communication. Our ICS3U curriculum introduces ACES to a subset of 6 Arduino-compatible Communication Protocols (Wi-Fi, for one, is left to you to explore at home as the RSGC firewall does not make it easy to investigate). Another communication protocol you may wish to explore involves the transmission of data through light using simple LEDs. E. McAuliffe (ACES '18, McMaster '22) made it the focus of his brilliant (MacGyver-inspired) Medium ISP (the Photophone) in Grade 11. He documented his project on his personal blog. Unfortunately, the original video of the project was posted under the College's account and is lost (like so many other irreplaceable student gems).
| Wired | Wireless |
| UART: Universal Asynchronous Receiver/Transmitter (Serial Rx/Tx) eg. Serial, Monitor, Plotter, SoftwareSerial, Processing, GPS |
RF: Radio Frequency (with Nordic's nRF24L01) eg. ACES Breakout |
| SPI: Serial Peripheral Interface eg. Morland Bargraph (74HC595), MCP4231 (Digital Pot) |
IR: Infrared 1. Proximity Sensing with (IR Emitter/Photodiode matched pair) 2. Data Communication with TSOP2138 (38kHz) and TSOP32240 (40kHz) eg. |
| I2C: Inter-Integrated Circuit eg. TC74, DS1307 RTC, 24-Color Bargraph |
BT: Bluetooth (Wireless UART) with the HC-05 Transceiver eg. |
Bluetooth (Wireless UART) with the HC-05 Transceiver
We finish up our ICS3U look at Arduino-Compatible Communication protocols by returning to where we began weeks ago, with the Arduino's UART. However, this time, we're exploiting it wirelessly, under the Bluetooth (2.4GHz radio) banner.
Given the complexity of the pairing sequence of the Bluetooth protocol this introduction will limit itself to Arduino⇆Arduino communication. Motivated students are encouraged to explore Arduino⇆Laptop and Arduino⇆Android Phone pairings.
As is the custom of the Serial UART protocol between two devices, the roles of master and slave must be established. These roles, together with a few other parameters, must be written into the RAM of the devices prior to the pairing. This is accomplished by entering AT COMMAND Mode and entering the required values. AT Command References appear below.
Although there are a few blogs out there with plenty of detailed backround information, I found this terrific video got right to the point of successfully pairing up two HC-05s.
How to Pair HC-05 Bluetooth Modules
Github: BT Confirmation sketches discussed in class
Additional References
IC Datasheet and AT Command Manual: EGBT-045MS/EGBT-046S
Martyn Currey Tutorials
Self-Reflection (2019 02 18)
Bluetooth-capable devices are, generally, expensive. 
IR Sensing with 940nm 5mm Emitter/PhotoDiode Matched Pair
For the first of a few IR investigations you are asked to examine the use of the 5mm LED matched Emitter/Photodiode pair (940 nm) provided in your Session 6 Supplementary Parts kit. These components can be employed to detect interruptions and tuned to detect the proximity of an object.
From personal experience I caution you to be aware of the inconsistency of the lens colours and vocabulary surrounding these devices, resulting on blogs and videos that are confusing, misleading and, occasionally, incorrect. This problem is so acute I hestiate recommending any links as I haven't found a single one that accurately employs correct interpretation. The root of the problem, in my opinion, is two-fold. First 3 mm and 5 mm LEDs of any wavelegnth, typically do not have part numbers silk screened on them so datasheets are not accessible. Secondly, there are not enough DIYers in the world willing to spend the time to explain the correct fundamentals to other DIYers in a format and language they understand.
The photodiode can also be called the detector. However, I would hesitate calling the photodiode a receiver as that term should be reserved for the device in part two of this investigation, consisting of more complex internal componentry.
Task 1. Break beam (Basic Digital; No Code/MCU)

For this intial task you are simply going to monitor the voltage fallng and rising as a result of breaking the IR signal between the emitter and the photodiode.Task 2. Proximity Sensing (Analog; MCU)
Watch this illuminating video explanation of the circuit you are asked to create.analogRead() to have the Arduino translate the reading into a numerical distance and either report it to Serial Monitor or throw it up on an LCD.IR Data Communication with GP1UX511QS (35m)
The graph (below, left) is of a data signal modulated upon a carrier wave. Demodulation can separate the carrier frequency from the data (below, right) using mathematics (FFT). Source: Adafruit Learning- FFT Fun with Fourier Transforms
SBProjects: IR Control Theory (A Must Read)
Ken Shirriff:
Sparkfun: IR Communication (with Supporting Video Tutorial)
The majority of the IR protocols from NEC, Philips, Sharp, etc. center on 38kHz, far enough outside the frequency band of ambient IR sources like the sun, flames and other common light sources to avoid signal noise issues. Sony's SIRC protocol differs and is centered on 40kHz. For a project you may wish to pursue simply ask me for an IR Receiver for either frequency.
Task.

Possible Project Considerations:
RF: Radio Frequency Communication (with Nordic's nRF24L01)
AVR Foundations: pp. 85-88
Web Reference: Arduino Wireless Communication
Kevin Darrah: nRF24L01+ Arduino Communication
Video Review: nRF24L01+ Options
Inspiring Project: DIY Arduino RC Transmitter
So here's what I've learned from my research and preparation for this introduction to RF (presented in an order that should make sense)
The unlicensed radio frequency band open to the Industrial, Scientific and Medical (ISM) Communities operates within the 2.400GHz to 2.525GHz range of the electromagnetic spectrum. (This 4G technology is about to be supplanted by 5G in which the next generation of devices will exploit the 6GHz frequency band)
I've written a matched pair of CHANNEL numbers on the backs of the breakout boards. Insert your nRF Appliance into your Arduino and find your partner. Designate one partner as the Transmitter (Tx) and place a trim pot in PC0 to PC2 as shown below. The other platform is the Receiver (Rx) and should have a Morland Bargraph inserted in PC0-PC4 as shown.
I2C: Inter-Integrated Communication
AVR Foundations: pp. 90-93
Reference: Arduino Wire Library
Gammon: Two-Wire Peripheral Interface
Video Tutorial Example: TC74 (Start at 54s)
Whereas the SPI protocol requires an extra SS pin for every additional slave device, the I2C protocol only requires two pins (in total) to communicate to up to 128 devices. Imagine an 8-pin ATtiny85 controlling up to 128 other devices! One pin is a clock line for synchronous support and the other pin is the data line. These two pins are Serial Clock (SCL) and Serial Data (SDA), respectively. Conveniently, the pins are broken out on the UNO on both sides of the Arduino. SCL and SDA share the Analog A5 and A4 pins and the two pins closest to the Reset button if the analog pins are required for other purposes.

Philips Semiconductor (now NXP of the Netherlands) developed the technology in 1982. Since I2C is a trademark, manufacturers of devices must pay a license fee to use the term. Microchip (formerly ATMEL) and other manufacturers get around the fee by calling their devices TWI (Two-Wire Interface) but they're 100% compatible.
The key to this highly-leveraged, efficient strategy is that the I2C bus acts like a street with devices having addresses on that street. Addresses are set by the manufacturer and impressed within the device. Let's focus on one such I2C/TWI device: The TC74 Digital Thermal Sensor. Open the TC74 datasheet and look at the ordering information on page 13, presented as an excerpt below. Embedded systems designers have the responsibility of ensuring their shared devices have unique addresses on the I2C bus. The TC74 device you have been provided with is the TC74A0-5.0VAT in the TO-220-5 package so it has an I2C bus address of B1001 000 or 0x48.

In the previous investigation of SPI, you were introduced to the concept of digital sensors having internal RAM, typically organized into byte-sized registers. For example, to set the wiper position of Potentiometer 0 of the MCP4231 you write a specific value to RAM address 0x00. Similarly, I2C/TWI devices have internal RAM storage that requires programming skill to manipulate. Grade 11 ACES are free to use the Wire Library to make this programming easy. Grade 12 ACES will program these devices directly in Assembly.
Chapter 4.0 of the TC74 Datasheet (p. 8) discusses the device's RAM organization. From the excerpt below, it can be seen that (read-only) address 0x00 holds the temperature data to be read. Read/Write Register 1 can be programmed to configure the device for certain optimized performance capabilities.

Using the key provided in the image of the TC74 depicted to the right, wire the device to your Arduino.
SPI: Serial Peripheral Interface
AVR Foundations: pp. 82-83
Reference: Nick Gammon on SPI
As a reminder, almost any activity performed by native MCU hardware resources is going to be faster than software emulation. So, it is no surpirse that the ATmega328P MCU's built-in hardware SPI device offers extremely fast, full duplex, wired communication between similarly-compatible components (by way of contrast, the ATtiny84 and 85 offer a compliant USI feature that requires partial software support for SPI). As the image to the right depicts, four wires are required to connect the master to a slave (if response from the slave is not required, the MISO wire can be eliminated). Should your MCU master wish to communicate with multiple slave devices, and extra SS line is required for each. The master pulls only one SS line low at a time to exchange data.
At this point in the course, you have, possibly unknowingly, used the SPI concept, twice. The most direct use of the actual SPI hardware was invoked when you used your Pocket AVR programmer to reflash the bootloader to your Arduino using the ISP header (the ISP pins are 1-MISO, 2-5V, 3-SCK, 4-MOSI, 5-RESET, 6-GND). The second (simulated) SPI concept is invoked whenever you use the shiftOut() function. This activity employs clock (SCK), data (MOSI), and latch (SS) pins.
Finally, if you find value in video explanations of Arduino concepts, here's a decent one:
Serial Programming Interface and here's its Supporting Tutorial.
| SPI with Morland Bargraph V3 | SPI with MCP4231 (Dual) Digital Potentiometer |
|---|---|
![]() |
![]() |
We're going to explore SPI on two different prototypes depicted above. You have a Morland Bargraph V3 for the first investigation and have been given an MCP4231 digital potentiometer for the second.
You've been provided with a hard copy of the code for both projects in the Word document, SPILibraryExamples.docx. The code is also available on our GitHub: https://github.com/rsgcaces/AVRFoundations/tree/master/D_DESIGN_ENGINEERING_PROJECT
Task 1.
Insert your Morland Bargraph V3 appliance into your Arduino as shown. The SPI-compatible pin arrangement makes this connection the easiest ever.Task 2.
The goal of this investigation is to capture and confirm the varying voltage on Potentiometer 0's Wiper pin (P0W). We won't be using Potentiometer 1.UART: Universal Asynchronous Receiver/Transmitter (Serial Rx/Tx)
AVR Foundations: Serial Monitor. pp. 10-11
Reference: U(S)ART: Universal (Synchronous) Asynchronous Receiver/Transmitter
PART 1. AUTONOMOUS ARDUINO
Basic Concept
Serial Communication involves the 'orchestrated' exchange of single bits, in sequence, between devices.On Your Arduino (ATmega328p)
The ATmega328P has only 1 hardware UART system onboard. The Arduino Mega2560 has 4.Using the Serial Monitor
| Adafruit's V3 Ultimate GPS Breakout | GPS Output: Online Decoder |
|---|---|
![]() |
![]() |
![]() |
|
Examples
File > Examples > Serial > SimpleRead.pde
PART 2. INTER-ARDUINO SERIAL COMMUNICATION
Part 2 opens the door to a wide-range of projects involving inter-MCU communication. We start with the simplest form of information exchange between two Arduino UNOs using their builtin hardware UART peripherals that you have been exploiting from the beginning. In this introductory confirmation of the 328p's serial communication capabilities you and your partner will set up a CLIENT/SERVER platform.
Task 2A. CLIENT-SERVER COMMUNICATION
Rx pin of one device is connected to the Tx pin of the other.
With its Rx/Tx pins engaged, the CLIENT must use his AVR Pocket Programmer as shown to upload the SerialClient code using Sketch>Upload Using Programmer (programming through the ISP header avoids the Rx/Tx interference caused by the USB-Serial cable)ServerEchoShiftBar and upload it to the SERVER (the CLIENT code can remain as is, transmitting H, L, H, L, ...). If all is well, you should see the binary ASCII values of H and L alternating on the display (other displays you might eventually consider are your Reed Matrix appliance or even a 7-segment display).Task 2B. PEER-PEER COMMUNICATION
The ATmega328p's limitation of only one hardware UART peripheral poses a challenge if two ACES want to have a chat through their respective Arduino IDE's Serial Monitor. Fortunately, a software solution to the problem is available in the form of the SoftwareSerial Library that can take over any pair of digital pins for UART emulation of Rx/Tx serial communication. In the configuration below, the hardware serial UART on pins 0 and 1 are used for local Serial Monitor use and pins usescrossed with the partner's software serial UART on pins 11 and 10. A common ground is maintained.
SerialMastermind game available for downloading, testing, and confirmation of peer-peer serial communication between UNO users.