Phase 4
Communication test - |Week 8|
Establish communication between Matlab and Arduino
Send the Deep learning object classification result to Arduino
Test RF communication between Matlab and Arduino
Establish communication between Matlab and Arduino
Send the Deep learning object classification result to Arduino
Test RF communication between Matlab and Arduino
Here, we will establish communication between a laptop and an Arduino UNO using APC220 radio communication module as shown in the figure below. According to the manufacturer, DFRobot, “APC220 is a highly versatile and low power radio solution that is easy to setup and integrate into any project requiring a wireless RF link.”
The APC220 module data sheet has the following basic specifications shown below. Setting up the APC220 module is much easier than the traditional Bluetooth module and it is almost a plug and play device. However, it requires a TTL to USB converter to connect the APC220 module to the laptop. The good news is, two RF modules and one TTL to USB converter come together in one package.
To perform a communication test, after connecting the radio modules, we send test signals from a laptop to Arduino that turns an LED on when signal “1” is received, blink twice when “2” is received, and turn off when “3” is received from Matlab.
We need one APC220 module for the PC and another one for each Arduino's. In order to connect the APC220 module to the PC, we will use the USB to TTL converter that comes in kit. We bought the APC220 module from DFROBOT company and the shipping list includes:
• APC220 module (2 units)
• Antenna for radio communication (2 units)
• USB to TTL Converter (1 unit)
Working frequency: 420 MHz to 450 MHz
Power: 3.5-5.5V
Current: < 25-35mA
Working temperature: -20℃~+70℃
Range: 1200m line of sight (1200 bps)
Interface: UART/TTL
Baud rate: 1200-19200 bps
Receive Buffer: 256 bytes
Size: 37mm × 17 mm × 6.6mm
After connecting the radio modules as shown in figure 1 above, the following test code can be used in Arduino IDE to turn ON an LED when signal “1” is received, blink twice when “2” is received, and turn off when “3” is received from Matlab.
// APC220 Radio Module Test on Arduino Uno ==
// By team OCS ==
int ledPin = 12; // LED connected to PIN 12
int value = 0; // variable for reading Serial Value
void setup() {
pinMode(ledPin, OUTPUT); // initialize LED pin as output
Serial.begin(9600); // From APC220 datasheet, Baud Rate=1200-19200 bps
}
void loop() {
// LED control
if (Serial.available() > 0) {
value = Serial.read(); // Read data received from matlab
if (value == 1) { // Turn on
digitalWrite(ledPin, HIGH); // turn LED on
delay (2000);
digitalWrite(ledPin, LOW); // turn LED off
}
if (value == 2) { // Blink twice
digitalWrite(ledPin, HIGH); // turn LED on
delay (2000);
digitalWrite(ledPin, LOW); // turn LED off
delay (500);
digitalWrite(ledPin, HIGH); // turn LED on
delay (2000);
digitalWrite(ledPin, LOW); // turn LED off
}
if (value == 3) { // Turn OFF
digitalWrite(ledPin, LOW); // turn off
}
}
}
Then, using the following Matlab code shown below, we have send transmission signal to check for any other connected device, then connect the APC220 module to laptop with the same baud rate as Arduino, and finally transmit the test signals "1, 2, and 3” with two seconds of interval. Then, we observed the LED responding to the RF communication, and this concludes the communication test phase.
% RF COM TEST by == team OCS ==
clear all
close all
% close all open PORTS
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
% serial object
%ar = arduino ('COM5', 'Mega2560'); % to write directly onto GPIO
ar = serial ('COM1','BaudRate', 9600); % create a serial object "ar"
fopen (ar); % open the serial PORT
% --- send signal ---
for i = 1:3
fprintf(ar, i); % Send "1, 2, or 3 " over the UART port to Arduino
pause (2); % 2 sec delay
end
Like a Bluetooth device, the APC220 is also connected to TX/RX pin of the Arduino. The drawback of this connection is that during code uploading, Arduino tries to use the same TX/RX port and the Arduinno code cannot be uploaded while the RF module is in use. Due to this, it is required to unplug the APC220 module from Arduino before uploading a code. In order to alleviate this problem, we can use Arduino Mega instead of Uno. The Arduino Mega has three additional serial ports: Serial1 on pins 19 & 18 , Serial2 on pins 17 & 16 , and Serial3 on pins 15 & 14 .
Moreover, as it is shown in figure 4 below, the connection between the APC220 and the Arduino UNO is through jumper wires which can create loose connections and transmission loss. To solve these problems, we have designed a PCB that will serve as communication shield for Arduino Mega 2560 as shown in the figure below. The PCB is designed in Eagle CAD and printed by JLCPCB company. We have also done visual test, continuity test, and soldering.
This shield will be stacked on top of Arduino Mega as shown in figure 5 and it can connect APC220 module or Bluetooth, MaxSonar rangefinder, ultrasonic sensor, and three more sensors with 5V, GND, and signal pin outs for future projects.
Before
After