Arduino Remote Management
Bob Cowdery G3UKB discusses the RaspberryPi versa Arduino hardware and how to manage an Arduino remote from the operating position.
Bob Cowdery G3UKB discusses the RaspberryPi versa Arduino hardware and how to manage an Arduino remote from the operating position.
I’ve built a number of projects using both the Arduino and the RaspberryPI (RPi). In that time I’ve come to realise the benefits and drawbacks of each device.
When an Arduino-based project is deployed it tends to be in a box somewhere, maybe at the end of the garden or up a mast or simply not convenient to a computer. In order to program and debug an Arduino, a USB connection to a computer running Windows or Linux is required. Having become a little tired of lugging a laptop around the garden I decided to implement a remote management node.
Quick Comparison
This isn't exhaustive and is my personal preference for where I use each device.
The RPi is a computer running a full operating system based on one of the Linux distributions. Initially the RPi-1 was pretty slow so a little patience was required. The RPi-2 was a big step up, being a quad-core device, and is very usable. The Rpi-3 mainly added WiFi and slightly faster CPU. The latest device as of writing, the Model 3 B+, clocks faster and has much improved network throughput should this be important. All have a variety of I/O capability. These are the GPIO (General Purpose I/O) pins and provide digital inputs and outputs. There is PWM (Pulse Width Modulation), I2C and various other modes available. All in all, it’s enough to drive motors and anything requiring a modest amount of digital I/O. However, it’s still a computer with an operating system sucking out power. You can hook into interrupts but the interrupt latency may not be particularly low or consistent. In practice, I prefer to use this device for higher level programming using predominantly Python and more recently 8th and Erlang (two RPi friendly languages).
The Arduino, of which there are many variants, is a microcontroller. Programming is in C++ using a simple but effective Integrated Development Environment (IDE). Programming is almost onto the bare metal so although the CPU capability is way less than the RPi, it’s no slouch. On the larger boards such as the Mega 2560 there is an abundance of I/O including analogue, which is lacking on the RPi. Interrupt latency is very low so making it ideal for low level work where accurate timing is critical. This is usually my choice for an embedded controller.
Multiple add-on boards are available for both but, of course, at extra cost and complexity.
Working Together
The RPi is easy to access remotely using SSH, Remote Desktop (RDP), VNC or even Team Viewer providing it has a network connection, which can be either wired or WiFi. The Rpi-3 has built in WiFi but also has an on-board antenna that it is possible but not easy to replace with an external antenna. This unfortunately means a fairly short range. If you have or can procure an RPi-2, then an external WiFi dongle with a decent antenna will give a much better range. That said, because the RPi can be accessed remotely and has an internet connection, it makes a good management node.
The Arduino requires a USB connection for program upload and debug. The USB connection also supplies power to the Arduino. Provided the RPi has a capable power supply (2.5A recommended) it can easily supply the required current to the Arduino.
Packaging an RPi with the Arduino makes it easy to manage the Arduino from any computer on the network. The way I do this is to put all my projects on GitHub and only update the Arduino firmware from my main computer. I commit the changes to GitHub and then via the RDP or VNC connection pull the changes down to the RPi. There is a version of the Arduino IDE (admittedly an older but perfectly adequate version) that can be installed on the RPi. Once the changes have been pulled down I load the file into the Arduino IDE and upload to the Arduino.
If there is a need to debug the Arduino code, then I find it easier to make a copy of the file on the RPi, add any debugging statements required and then upload the copy. Debugging is then carried out using the IDE serial monitor and when fixed, the changes can be incorporated in main code and another cycle performed.
Adding Video
Sometimes, when the project has mechanical bits and pieces, motors, actuators and the like with lumps of metal in motion, it’s comforting to be able to see what’s going on from the remote operating position. Adding a camera to the RPi is pretty trivial and arranging to stream the video back to the operating position is equally trivial. I prefer to do this with one of the approved RPi cameras and VLC Media Player.
Getting it all Together
- Get the latest version of Raspbian on your RPi and run the usual
> sudo apt-get update
> sudo apt-get dist-upgrade - Later versions of Raspian come with RealVNC installed although it needs to be enabled via ‘Raspberry Pi Configuration’. Earlier versions will need either RealVNC or xrdp installing. Recently I’ve found that RDP does not play well with the later Raspbian releases and it always seemed to have problems with UK keyboard mapping. VNC is now the preferred method and works extremely well. However, if you prefer RDP then:
> sudo apt-get install xrdp - I prefer to give my RPi's a static address because computer names don't always resolve and you don’t want to be chasing DHCP addresses.
> sudo nano /etc/dhcpcd.conf
Add to the end of the file:
interface eth0
static ip_address=192.168.1.nnn/24
static router=192.168.1.254 (or whatever your router is)
static domain_name_servers=192.168.1.254 - You can then dispense with keyboard and mouse and connect from your main computer.
- Install ‘git’ if you want to clone stuff from GitHub
> sudo apt-get install git - Install the Arduino IDE
> sudo apt-get install arduino
Install VLC if you will be using a camera
> sudo apt-get install vlc
See the URL below for setting up streaming using VLC. However, in brief, create a file vlc.sh containing the line below and make it executable.
raspivid -o - -t 0 -hf 640 -h 360 -fps 25 | cvlc -vvv stream:///dev/stdin –sout ‘#rtp{sdp=rtsp://:8554}’ :demux=h254
Install VLC on your main computer and connect to the network stream at the IP address of your RPi. Don't forget to plug in your camera module the correct way around because the connector isn’t keyed and also use ‘Raspberry Pi Configuration’ to enable the camera.
The screen grab, Fig. 1, shows the remote desktop of an RPi running under Windows10 with the Arduino IDE running, git showing the project files are up to date and the VLC script has also been run and seen a connection from 192.168.1.106.
https://raspberrypi.stackexchange.com/questions/23182/how-to-stream-video-from-raspberry-pi-camera-and-watch-it-live
This article was featured in the December 2018 issue of Practical Wireless