Experiment #4: Inter-Microcontroller Serial Communication
Introduction
Since the plan is to use one microcontroller to handle the infra-red command system and another to act as the central control unit, some method needs to be found to enable the microcontrollers to commuicate with each other.
The first method considered was serial communication using software serial libraries. This experiment was used to investigate the viability of such a system. An Arduino Uno clone was chosen to stand in for the central control microprocessor while two different microcontrollers were tested as possible candidates for the infra-red command microcontroller:
- An ATtiny85
- An Arduino Nano clone
Since the design envisaged that serial communication would be one way, from the infra-red command microcontroller to the central controller, the experiment only tested communication in that direction. The sending microcontroller sends a start up message over serial and then flashes a LED in a loop, transmitting the state of the LED to the receiving microcontroller. The results were then sent from the receiver to a serial monitor and inspected visually.
Circuits
The circuits used for the different microcontrollers were slightly different and are described separately.
Circuit With ATtiny85
This circuit used a LED and current limiting resistor.
ATtiny85 Pin | Attached to | Notes |
---|---|---|
PB1 | LED anode | Couple LED cathode to GND via 470Ω resistor |
PB2 | Uno pin 10 | ATtiny's nominated serial TX pin to Uno's nominated RX pin |
GND | Uno GND pin | Common ground |
VCC | Uno 5V pin | Power for ATtiny taken from Uno |
Power was supplied to the Uno via its USB port.
Circuit With Arduino Nano
This circuit used the Nano's internal LED, so no physical connections were required for the LED.
Nano Pin | Attached to | Notes |
---|---|---|
3 | Uno pin 10 | Nano' nominated serial TX pin to Uno's nominated RX pin |
GND | Uno GND pin | Common ground |
For completeness, the Nano's pin 2 (nominated as RX) could be coupled to the Uno's pin 11 (nominated as TX), which would enable the Uno to transmit to the Nano. Since the communication was one-way these pins were left un-connected.
The microcontrollers were powered separately, each via their own USB ports.
Code
All the code used in this experiment is available from the cahamo/diorama
project on GitHub, in the research/serial-tests
directory. The code was developed in C++ using PlatformIO. There are three separate programs, each in its own sub-directory. The programs are as follows.
Serial receiver
The code that stands in for the central controller can be found in copy-softserial-to-serial-uno.cpp
.
This is the code to be run on Arduino Uno. It simply copies serial data received on pin 10 to its hardware serial port, for viewing on a serial terminal. The Arduino Serial
library is used to send data to the terminal while the SoftwareSerial
is used to receive data from the sending microcontroller.
Serial transmitters
The Arduino Nano and the ATtiny that were tested as transmitters each have their own code. They use different software serial libraries to achieve similar outcomes. The code is:
nano-serial-test.cpp
for the Arduino Nano. It uses theSoftwareSerial
library.attiny-serial-test.cpp
for the ATtiny85. It uses theATtinySerialOut
library.
Results
- Using the Nano to transmit data was mostly successful. The data sent from the Nano was received cirrectly by the Uno. However, an occasional spurious character was displayed on the terminal immediately after the programs started.
- When using the ATtiny85 all data received by the Uno was garbled beyond recognition. On researching the problem it was found that many ATtinys have clocking problems when transmitting over serial. At attempt was made to callibrate the ATtiny to overcome the problem, but this failed. Further investiagtion was not carried out.
Conclusion
Although using the Nano to transmit was largely successful, the introduction of an occasional unexpected character in the received data means that any production system using serial to tranmit command data would need to include some significant error checking.
However, the main problem is that the ATtiny85 proved unusable. This is unfortunate because the ATtiny is the preferred microcontroller to be used for the infra-red command subsytem.
Consequenly it is not proposed to adopt serial as the means of communication between microcontrolers. Other options should be investigated.
Back to Central Control page | Main project page