Week 14:

Networking & Communication

Context

Embedded communication is the process of sending information between two MCUs or from one circuit to other. For a communication to happen there needs to be a transmitter and a receiver. Communication may be in one direction or in both directions, there are different classifications according to this, but the basic classification is Synchronous and Asynchronous communication.

Synchronous

Sender and receiver use the same clock signal. An example is Serial Communication, where we needed to fix the baude rate for boards to communicate with eachother.

Asynchronous:

Sender provides a synchronization signal to the receiver before starting the transfer of each message. And example of this is i2c and SPI where there is a CLK maintains the clock signals.

Synchronous data transfer timing diagram - Source
Asynchronous data transfer timing diagram - Source

This week's Objective

For this week, I wanted to challenge myself with a networking project. I wanted to use all the networking protocols available to me in one assignment. So I'll be using the following protocols;

  • SPI
  • i2c
  • Serial

First Objective:

Interface the ADXL345, an i2c accelerometer which works on 3.3v, transfer the accelerometer data using nrF24L01 modules which use SPI communication. I'll have to design a board that works on 3.3v which will be convinient to work with these components.

Second Objective:

Recieve the accelerometer data using another nrF24L01 module, and send it to another board using i2c.

Third Objective:

Recieve Data using i2c, and writing it on Serial so I can see it on the Serial Monitor.

The Board's I'll be Using

Features:

  • Atmega328p 8MHz running on 3.3v
  • Onboard Devices: nrF24L01, ADXL345
  • Hardware i2c and Serial pinouts
Download Eagle Project Files

Features:

  • Atmega328p 20MHz running on 5v
  • Seperate 3.3v power for nrF24L01
  • Seperate power management for MG995 Servos using LM2940
  • Control Circuit for 12v LED strips using N-Mosfets
  • Onboard Devices: nrF24L01, connecting port for HC-05
  • Hardware i2c and Serial pinouts
Download Eagle Project Files

Features:

  • Atmega328p 20MHz running on 5v
  • Seperate High Current Power management for Addressable LED strips
  • Hardware i2c and Serial pinouts
  • Pinouts for ESC to drive a BLDC motor
  • Pinouts for Optical Encoders on Interrupt pins
Download Eagle Project Files

Board 1: Passing accelerometer data through nrF24L01+

Target Board

I designed the board around the ADXL345 and the nRF240L01. As they required 3.3v power and we dont have logic level shifters at the lab, I used an atmega328p with an 8MHz resonator to run at 3.3v. I kept a seperate AMS1117 to power the nRF240L01 module as I read that they get a bit fussy if proper power is not supplied.

I used Sparkfun's ADXL345 breakout board as a reference for interfacing the ADXL345 chip. I tied pin 7 with VCC which enabled i2c mode and added noise filtering capacitors of 0.1uF and 10uF near the chip.

The board can be run on battery power as the voltage level needs to be just above 3.3 to work.

Download Eagle Project Files

ADXL345 interfacing

->Checking if Accelerometer is Detected:

Since this was the first time I soldered a component without any legs, I wanted to check if my accelerometer was being detected as an i2c device, so I used the i2c Scanner code from Arduino Playground and it seemed to be getting detected at addres 0x53.




Reading Accelerometer Data:

To read the accelerometer data, I used the Sparkfun ADXL345 Library. It had many smart features like tap, double tap, activity, inactivity and freefall detection. But for now, I'll just be using the following methods to get the x,y,z data.

Important LibraryFunctions Used





nRF240L01 Interfacing

Transmitting an array of 3 integers Using the RF24 Library

For the nRF240L01 modules, I used the RF24 library. I followed this youtube video to use the 'getting started' example to write my own code to transmit an integer array of size 3.

The code has two parts, the transmit part and the recieve part. This board will be using the transmit part.

Important LibraryFunctions Used





Final Code for Board 1:

Transmitting ADXL345 data using nrF24L01(merging both of the codes)

Board 2: Recieving the data and passing it through i2c

Target Board:

I designed this board for our upcoming machine design project.
It has an nRF240L01 module connected on the SPI bus, header pins for the i2c bus, FTDI pinout and a connector for an HC-05 module which I will be using for this week's group work.

It has power management circuitry to drive two high current MG995 servos using LM2940 regulators. It also has two NDS355AN N- mosfets to control two 12v LED strips.

I used a double sided FR1 board to make this board and used the copper on the other side as a common ground plane. This helped me reduce the number of jumper resistors and also provided great thermals.

Recieving Accelerometer Data through nRF240L01

Important LibraryFunctions Used







Sending an integer array through i2c (Master side)

Final Code for Board 2

Board 3: Recieving i2c data and Writing it on Serial Monitor

Target Board:

I'll just be using this board I made during the output week to read the data over i2c and print it on my Serial monitor. All details about this board can be found here.

Recieving data from i2c bus: (slave side) and printing it on serial

Hero Shots

Learning Outcomes

  • I learnt how to use the nRF240L01+ modules.
  • I learnt power management for 3.3v components on a 5v board.
  • I learnt how to use the widely used RF24 library
  • I learnt how to network between multiple protocols like i2c, serial and rf using RF24.