In Part Two of this blog series, I’ll focus on setting up our RPMA DevKit and getting the Arduino understood.
Back in Part One of my blog series, I set an Arduino Yún to take readings from a DHT11 temperature + humidity sensor and shared the Arduino sketch I threw together to make it all work. Just a heads up: I realize now that sending characters over a serial connection to represent these numerical values isn’t super efficient. Smart people would have known to send them over in bytes or something like that. For my simple project, ASCII characters are going to be just fine.Set Up the Serial Cable
First thing’s first, I knew I would have to configure the RPMA DevKit board to receive/transmit serial transmissions and forward those on to Intellect. The files & scripts included in the Starter Pack downloadable make this a pretty easy process. First, I slipped the FTDI serial-to-usb cable we provide with the development kit onto the host serial interface on the DevKit board. It’s the row of five male pins next to the DC power jack on the board. Then the USB business end plugs into your PC or Mac. You’ll probably have to install the drivers — we’ve included them for Linux/Mac OS X/Windows in various flavors (32-bit/64-bit) but it can’t hurt to check FTDI’s website for a newer version. The drivers we provide work great on my Mac running the macOS Sierra public beta.
Another valuable bit of information you’ll need is the ID or com port for the USB cable’s serial connection. In Windows Device Manager, it’ll come up as something like “COM5” and on a Mac or other UNIX-based machine, you’ll need to run a console command to retrieve the port name. Using the console of your choice (I’m using Terminal.app), punch ls /dev/tty.* into the command line and hit return.
Basically, we told the console to list anything in the /dev directory whose name starts with tty. It generates a list of items that match that criteria. In my case, the FTDI cable shows up as /dev/tty.usbserial-FTFMFMP8. Your cable will come up with a similar, but not identical name. Copy and paste this somewhere handy. Replace /dev/tty.usbserial-FTFMFMP8 in all my examples below with your serial cable’s identifier.Install Python & pyserial
The RPMA DevKit configuration scripts are all written in Python, a handy and nearly universal programming language. It’s super extensible (meaning you can supplement its capabilities with add-on modules and the like) and pretty much cross-platform compatible. By default, the Python installation included with your Mac or Linux-based PC (Windows users will have to use the Python 2.7.9 installer we’ve included in the starter pack) won’t be able to communicate over a serial connection. We fix that by installing a module called pyserial that enables serial communication. Pretty cool! Installers are included in the starter pack, or you can grab the latest version here.
Windows adds one more complexity here. You’ll need to add the Python directory C:\Python27 to the Windows “PATH” variable. Get the low-down on how to do that here.First Exercise: Get Device Status
Okay, so now we have the serial cable plugged into our computer and development board. Python is installed along with pyserial. We know the serial port name or ID. Let’s run one of our included Python tools and have it execute a command. In your console, change directory to the python_tools folder under your model of rACM (mine is racm_1.4.6). On a Mac or in Linux, punch in ‘cd’ followed by the correct path. In my case that reads like “cd /Users/mgibbons/Desktop/rACM/racm_1.4.6/python_tools/”. Next, run the following command to get a status report on your RPMA DevKit board:
We’re basically telling our computer to use ‘python’ to execute the script ‘host_app_ctrl.py’ to connect to our serial device (in my case ‘/dev/tty.usbserial-FTFMFMP8’) and send the command ‘GET_DEVICE_STATUS’. For whatever reason, I sometimes have to send this command a couple of times before it actually works. What you’ll end up with is something like what you see below.
It’s displaying the configuration of every pin on the RPMA DevKit board and some important identifiers like node ID (each RPMA module has a unique identifier straight from the factory).Configure the RPMA DevKit
Now that we’re all set up, we’re going to configure our DevKit to accept serial communications over its application interface (those two rows of fourteen parallel pins) and pass the messages on to Intellect, our cloud-based platform. There’s an easy way to do this, and a hard way. I’m all about easy ways, and for my purposes the easy way is the right way.
While still in the appropriate python_tools directory, enter the following command:
python host_app_ctrl.py -d /dev/tty.usbserial-FTFMFMP8 SET_FIELD_CONFIG /Users/mgibbons/Desktop/rACM/rACM_Config_Files/host_app_field_cfg_serialPort.txt
The tail end of that command is going to change depending on your own computer and where you have the starter pack files located. We’re telling the python script ‘host_app_ctrl.py’ to grab that ‘host_app_field_cfg_serialPort.txt’ file and use it to configure the RPMA DevKit board. Your exact file path will differ from mine.Wire Them Up
Now that the RPMA DevKit is configured for serial, we can actually hook up the Arduino. I’ve been told that you should unplug everything from power for this step, or whenever you plug/unplug anything to an Arduino or other board. Sometimes I’m lazy or forget, but luckily I haven’t caused any fires yet.
You’ll need to connect just three wires between the Arduino and rACM to get this going. One wire from Arduino RX (pin 10 in my case) to rACM TX (Pin 9. Top row. Third from left.). Another wires goes from Arduino TX (pin 11 on my Yún) to rACM RX (Pin 7. Tow row. Fourth from left.). The final wire functions as a ground and goes from Arduino ground pin to pin 1 on the rACM board (Upper-right-most pin). Basically with the RX/TX wires you’re flipping the connection: Arduino’s transmit (TX) goes to rACM receive (RX) and vice versa.
Power everything back up. Provided smoke hasn’t started pouring out of places it shouldn’t, the Arduino board is now transmitting temperature and humidity values over its serial connection to the RPMA DevKit board every five minutes. The DevKit will in turn wirelessly pass those values on to Intellect.
In Part Three of my short idiot’s guide, I get into how I used our included Python scripts to grab the latest data from Intellect, parse into something palatable, and pass that data to the AT&T M2X platform.