7/29/19 – Serial Communication with a Radio Module

Today, we were instructed to use an output device we haven’t used before. I decided to use a radio module since that’s the last main part of my final project I haven’t addressed yet.

I wanted to use a radio module to communicate from the Arduino on the glove to the Arduino on the car when it receives a certain signal. It only needs to be a one-way communication loop since the car won’t give any readings back, so the code is relatively simple.

After Rob showed the output devices in the lab, he showed me a simple radio module I could use to do serial communication between two Arduinos. The module was the NRF24L01 radio module. Box Module After finding a diagram of which pins were which, it was relatively easy to hook up. Relatively is the key word, you just have to be really really careful. I used pin to socket wires to wire up the RF modules. diagram table first attempt at wiring The setup was also pretty simple. I had whichever Arduino I wanted to read the signals from hooked up into my computer’s port, and then the other Arduino was hooked up to a 5V battery. Whenever I wanted to download each iteration of the code I had to switch around the downloading cables, which was a hassle, but it worked. Setup

Rob also showed me the documentation of his work with the same modules, so I used his example code as a starting point. It took me a while to figure out where I would insert my own actions and code into the example, but after cross-referencing my old magnetic sensor code, I figured it out. First, I put in the global variables from my magnetic sensor code outside the setup and loop, then put the averaging function into my void loop(). I set the averaged variable value to sensorAve. In the original code after the byte called data was sent over, it did data++. Instead of that, I had a few if() statemements based on my 3 main categories of readings (completely touching, close, and far away) that send out a different numbered byte from 1-3 depending on the reading. Eventually, I’ll make it so the byte being read gets fed into a switch case that does different movements of the car depending on the number. My code setup: setup

At first, the transmitting side of things seemed to work – it was getting readings and saying that it sent the data successfully. The little TX LED was also blinking on the Arduino, so I thought nothing was wrong.

However, the receiving side just wasn’t working or receiving anything. I kept on trying to send simpler things or make the LED blink when it received data, but still nothing was showing up on the serial monitor. Then, I tried using my receiver with Rob’s preexisting radio module parts, and that worked with the receiver, so we realized the problem was actually on the transmitting side. It was able to recieve the potentiometer values for the servos just fine: hahaha fillerrrrrrr Upon closer inspection of my code, I saw that the “sent” text was actually normally part of the loop, and I made some simple modifications so that the “sent” text would only show up on the serial monitor when data was actually sent. Then, I looked at the wires I had plugged into each pin on the transmitting side, and I realized that I had actually plugged in two of the wires into the wrong pins. The RX/TX worked perfecly after that, so I guess I learned my lesson today: BE CAREFUL WHEN PLUGGING IN WIRES!!!!!!!! Setup final

You can download my final RX/TX code here: rx tx

Next, my goal is to actually drive motors with switch cases and code from this RX/TX communication. After I get that to work, I just need to move all my components onto a protoboard, add in another magnetic sensor, and make everything cleaner with wiring and electronics and the hardware. I’m excited!!