Skip to content

13. Networking and communications

Assignments:

Individual assignment:

  • Design, build, and connect wired or wireless node(s) with network or bus addresses.

Group assignment:

  • Send a message between two projects.


This week was a great opportunity for me to test the different communication I need for my puzzle box final project.

Final project - first electronic integration

Integration test

Before going into more details into networking and communications in the following sections, let me introduce here the first electronic integration tests I performed for my puzzle box final project, with the main PCB that I designed this week. A last PCB that will handle 2 puzzles is missing in this first integration, but its behaviour is simulated by 2 wires connected to +5V for a few seconds indicating that the corresponding puzzles have been solved.

This video is interesting in the sense that it presents i2c communication between the main PCB and the LCD and SPI communication between the main PCB the RFID reader.

Note : This integration features the DNA keypad that I designed in the Molding and Casting week, and the countdown PCB that I made during the Output devices week.

PCB design

I designed the main PCB for my puzzle box final project in such way to allow easy connections of multiple and various peripherals. In order to do so, I have simply added pads on my design to solder header pins. If needed, and for a cleaner integration in my final project, I still have the possibility to desolder the header pins and solder wires directly into the PCB instead.

Here are some screenshots of my design in Eagle software :

Main PCB all Main PCB traces
Puzzle box main PCB - Eagle Puzzle box main PCB (traces export) - Eagle

Then I could laser cut the PCB :

PCB before soldering
Puzzle box main PCB - before soldering

Note : Given the difficulties I faced for cutting out my previous PCB in the FR4 1.6mm thick copper plate, this time I applied the following laser settings for the cut out:

  • type : CO2
  • speed : 10%
  • power : 100%
  • frequency : 100
  • repetition : (cycles of 10 repetitions, then lifting up the laser bed of a few 0.x mm) x 3

And finally soldered components :

PCB after soldering
Puzzle box main PCB - completed

Main issues

During this first electronic integration tests, I faced several difficulties, some are solved, others not :

Unsolved issues

1 - The solenoid activation (that requires an important current consumption of about 800mA) often makes my microcontroller ATmega328P reset or generate other perturbations in the system, which is annoying as the main program believes that the game restart from scratch altough some puzzles have already been solved, or some functionalities are lost such as the LCD display, or the countdown. Currently I am not sure about the root cause of this problem, but I suspect a voltage drop at solenoid activation. When searching on the internet I found this very interesting article about AVR reset conditions, which stipulates that there are four sources of reset :

  • Power-on Reset : The Microcontroller (MCU) is reset when the supply voltage is less than the Power-on Reset threshold (VPOT).
  • External Reset : The MCU is reset when a low level is present on the RESET pin for longer than the minimum pulse length.
  • Watchdog System Reset : The MCU is reset when the Watchdog Timer period expires and the Watchdog System Reset mode is enabled.
  • Brown-out Reset : The MCU is reset when the supply voltage VCC is less than the Brown-out Reset.

I plan to perform some analyzis with the oscilloscope in the weeks to come. One possible reason I see at the moment is that the ATmega328P pins that control the solenoids are set as inputs (because the information to open the solenoids comes from another PCBB). I will try to modify my code and set them as outputs pins and check whether the reset issue still occur or not. Ideally I would have liked to allocate two separate pins for each solenoid : 1 pin as input from the other PCB to knwo when the solenoid must be opened, and 1 pin as output to physically control the solenoid, but unfortunately due to a lack of pins available on my microcontroller I designed it the way it is now.

In the video below, one can notice that the system goes back to puzzle 1 and the countdown is paused after that the 2nd solenoid lock mechanism is opened.

2 - Another issue I faced is related to SPI communication with 2 RFID readers in parallel. Although I had validated my program (with some unexplained instabilities at power up) with an Arduino setup (see SPI communication section below), integrating 2 RFID readers in my main PCB was not stable at all, and even sometimes led my RFID readers to not being able to read the tags UID for a while. Surprinsingly, those RFID readers could for example work normally the day after… The issue may come from both RFID readers sending information at the same time or one of them not releasing the Slave Selection chanel as expected.

I gave it a quick try to investigate what was going on with a logic analyzer, but I have not managed yet to configure it properly to observe the signals I want. I decided that I would spend more time on this issue if I have time in the end, but at the moment I don’t want to make my RFID readers out of order and simply replaced my puzzle that was supposed to use 2 RFID readers by a single RFID reader and this way it works fine.

Solved issues

1 - In the beginning 2 buttons of my keypad puzzle were not working with this PCB although they were all working fine during my previous tests with Arduino. After analysis, I understood that it was due to the fact that those buttons were mapped to pins 7 and 8 of my ATmega328P microcontroller which can be used as digital input/output but which are primarily dedicated to connecting an external Crystal oscillator as can be seen on the pinout diagram hereunder :

ATmega328P pinout
ATmega328P pinout

In order to make those pins available as digital outputs, I had to install the MiniCore configuration on my Arduino IDE. For further information, please refer to this tutorial.

2 - Finally, now that I was integrating my countdown PCB with my main puzzle box PCB, I had to modify slightly my coutdown program. Indeed, instead of being a simple coutdown that starts when the microcontroller is powered on, I now wanted to control the start/stop of the countdown from the main PCB, using dedicated GPIOs on the 2 microcontrollers. This forced me to review the way I handle the countdown update. This seemed pretty simple to me, and I was confident in the new code I generated but unfortunately the results were not the ones expected. I rapidly understood that the problem was linked to the variable types assigned in my program (int, long, unsigned long, etc) but after trying almost every combination possible, I could still not obtain the result I was looking for. After almost a day of investigation, I eventually got the answer on this forum. In a formula I was using to perform simple time conversions from minutes, seconds, milliseconds; I needed to add a “L” after some numbers to convert them into “long int”. To keep track of it, the correct formula is the following :

unsigned long total_time_left_restart = ((min_left * 60L) + sec_left)*1000L;

I2C communication

I want to integrate in my final project a LCD (Liquid Crystal Display) that will be used as a feedback for players. It will both to give help messages if needed while progressing through the game, and also would be part of a puzzle that requires player to enter a particular sequence on a keypad.

I already had the opportunity to work on a first Arduino version of the program for the puzzle mentioned above, using a standard LCD controlled via the 16 connection pins :

After reading this Sparkfun I2C tutorial, I was conviced that this technology would be really interesting to implement in my puzzle box, especially as it can allow to multiply the number of sensors connected to the board without requiring any addition GPIO of the microcontroller. Indeed this serial protocol simply requires 2 wires : SDA (data) and SCL (clock), and uses devices addresses to let the controller commmunicate with the peripherals as can be seen on the diagrams below extracted from the mentioned tutorial.

I2C connections
I2C connections diagram

I2C diagram
I2C - signals diagram

Thus I decided to order several of the additional electronic module that allows i2c communication with the LCD.

Once this module received, I read a few tutorials among the many that we can find on the internet to establish the i2c communication between my Arduino and the LCD. One interesting question was how to determine the address to talk to the LCD over I2C, and I got the answer by looking at [this tutorial]. As indicated, some I2C interfaces have pins/pads (usually labelled A0-A1-A2) that can be connected together or not with the consequence of modifying the address. The default address seems to always be 0x27 (no pads connected) ; the table below summarizes the possible addresses and how to set them :

Address A0 A1 A2
0x27 NOT connected NOT connected NOT connected
0x26 connected NOT connected NOT connected
0x25 NOT connected connected NOT connected
0x24 connected connected NOT connected
0x23 NOT connected NOT connected connected
0x22 connected NOT connected connected
0x21 NOT connected connected connected
0x20 connected connected connected

As I was at home when I received those modules with no soldering iron at disposal, I created a simple Arduino program that sends a different text to be displayed for 3 different I2C addresses. With two idencital LCD connected in my setup, I could confirm that when establishing connections on A0/A1/A2 pins in accordance with the addresses I set, I could see the text changing on the LCD (see video below) :

Following this test, I brought minor changes to my Arduino program that controls the DNA access code puzzle (presented in the beginning of this section), and achieved a successful result. Note : in the video below, the puzzle also integrates the custom DNA keypad I produced in the molding and casting week as well as a servomotor that will act as a lock mechanism in my puzzle box.

Note: More information (sketches, source code, etc) about those programming activities can be found in this section of my final project page.


SPI communication

For my final project I want to integrate an access control puzzle using RFID modules.

Many websites present the RFID technology, and a lot of makers use them for their Arduino projects. To get started I have mainly been through this RFID tutorial (in french), and this RFID tutorial (in english). Also I have read the Arduino MFRC522 Library documentation, which was really useful to me.

RFID (Radio Frequency IDentification) system consists of two main components : - a transponder usually in the form of a card or tag. - a transceiver also known as interrogator/reader.

The RFID reader consists of a Radio Frequency module and an antenna which generates high frequency electromagnetic field. On the other hand, the tag is usually a passive device, meaning that it doesn’t contain any power supply. Instead it contains a microchip that stores and processes information, and an antenna to receive and transmit a signal. To read the information encoded on a tag, it must be placed in close proximity to the RFID reader (within few centemeters). The reader generates an electromagnetic field which causes electrons to move through the tag’s antenna and subsequently powers the tag’s chip. Once powered, the tag’s chip responds by sending its stored information back to the reader in the form of another radio signal. This so called backscatter, is detected and interpreted by the reader which then sends the data out to a computer or a microcontroller.

As usual, I started by testing a first version of my access control using Arduino environment. I decided to make the RFID module and the Arduino exchange data using the SPI protocol (Serial Peripheral Interface). This Sparkfun SPI tutorial was of a great help to understand how this protocol works, and as a summary here below are presented 2 diagrams extracted from this tutorial :

SPI connections
SPI connections diagram

SPI signals
SPI - signals diagram

Fritzing sketch of the electronic assembly :

RFID Fritzing
RFID access control - Fritzing skecth

Material :

  • Arduino Uno (x1)
  • Breadboard (x1)
  • Jumper wires
  • LED green (x1)
  • LED red (x1)
  • 220 resistors (x2)
  • RFID MFRC522 13.56MHz (x1)
  • RFID tags/cards (as many as you want)

Following this first test, I noticed that all cards could be read by the RFID reader, however only one tag out of five could be read. After some searches on the internet I realized that many persons already observed a similar behaviour due to poor quality of cheap RFID readers copies, such as the ones I may have bought. One of the solution suggested was to power the RFID readers with 5V instead of 3.3V, which I tried and it worked perfectly fine for me. I know that this solution is definitely not ideal but as in my application the RFID readers will only be powered for a relatively short amount of time, I hope that they will not get damaged.

Once I had managed to work with one RFID reader, I could extend my tests to using 2 RFID readers in parallel which corresponds to the situation I would like for my final puzzle box.

As can be seen in the video, the behaviour is the following :

  • Only one tag is authorized per RFID reader.
  • If both tags are presented within a close interval of time to their corresponding RFID readers, the green LED turns ON, access is authorized.
  • If a tag is presented to a RFID reader for which it is not authorized, the red LED turns ON, access is denied.
  • If only one tag is presented to its corresponding RFID reader, the yellow LED turns ON, access is denied but it indicates to the user that this tag corresponds to this RFID reader.

Note: At this stage I am facing an issue that I do not understand. Indeed, I need to power ON/OFF several times my Arduino Uno so that both RFID readers work simultaneously. I will investigate more on this issue later on if I have time.

RFID 2 readers Fritzing
RFID access control with 2 readers - Fritzing skecth

Material :

  • Arduino Uno (x1)
  • Breadboard (x1)
  • Jumper wires
  • LED green (x1)
  • LED red (x1)
  • LED yellow (x1)
  • 220 resistors (x3)
  • RFID MFRC522 13.56MHz (x2)
  • RFID tags/cards (as many as you want)

Group Assignment

For the group assignment we have established an I2C communication between 2 of our PCBs. The microcontroller set as “Controller” was requesting inputs from the “Peripheral” that was fitted with an ultrasonic distance sensor. The results were then displayed by the “Controller” on a LCD, itself connected over i2C.

Group assignment
I2C communication with a microcontroller and a LCD

Additional information can be found in our group page.

Source files

The source files of the work presented in this week assignment are available for download here :