We’re talking about organizing and maps! Join us on Open Call on May 11 to kick-off this topic and then every Tuesday through June. Click here for call-in details!

# Prototyping with Raspberry Pi and Arduino

by limako | 17 Sep 20:23

I'm beginning to build a prototyping rig for students to use for learning how to build open science instrumentation. My thought is that most instruments students might build will use either a Raspberry Pi or Arduino-like device as the platform/data logger. My thought was to have students learn how to set up, secure, and use a raspberry pi via ssh -- and then use the raspberry pi to program an Arduino via the command line. There's a steep learning curve for starting out, but it will encourage students to learn the foundational skills with the command line that, in the long run, will make it much easier to support and interact with their instruments.

This is my first attempt at setting this up.

I installed a fresh image of Raspbian Buster

On fresh disk image:

touch /boot/ssh
vim config.txt (add clause for display I have hooked up to watch it boot)


After booting:

sudo apt-get install vim
vi .inputrc ("set editing-mode vi")
sudo vim /etc/hostname (set hostname)
sudo vim /etc/hosts (set raspberrypi to hostname)
sudo apt-get update
sudo apt-get upgrade
sudo raspi-config (expand file-system)
sudo reboot


Then set up ldap authentication:

sudo apt-get install libpam-ldapd libnss-ldapd
sudo vim /etc/nslcd.conf (add browse user)
sudo visudo (add "[username] ALL=(ALL) PASSWD: ALL" for all admin users including "pi")
sudo reboot


Then install our firewall script:

scp pifire.sh (our firewall script)
sudo vim rc.local (to start firewall -- probably should move to networking/pre-up)
sudo reboot


Then create environment for prototyping

sudo apt install arduino-core
sudo apt install arduino-mk


Now I can create a folder for each .ino file, create a Makefile in that directory with the following settings:

ARDUINO_DIR   = /usr/share/arduino
ARDMK_DIR = /usr/share/arduino
ARDUINO_LIBS =
BOARD_TAG    = uno
MONITOR_PORT = /dev/ttyACM0
include /usr/share/arduino/Arduino.mk


And then type "make" and "make upload" to build and upload the executable to a connected arduino.

And I found a snippet of python I could use to get data via the serial monitor:

#!/usr/bin/python
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
while 1:
if(ser.in_waiting >0):
line = ser.readline()
print(line)


It's a start. I'm still not sure how adaptable this will be for students to work with other arduino-like devices (e.g. Adafruit Feather)

### 7 Comments

I’m intrigued by the idea that students should “learn the foundational skills with the command line that, in the long run, will make it much easier to support and interact with their instruments.” I haven’t used the command line much since the 1980s when some clever developments (the mouse, the graphical user interface) made computing accessible to everyone precisely because using the command line was no longer necessary. (The command line is that blinking cursor where you must enter a precise and inscrutable string of characters [the command] to tell a computer what to do next.)

What are the advantages of using the command line? Developing with Arduino does not require use of the command line. Much open science instrumentation has been created in the Arduino environment and the spiffy code editor and debugger in the Arduino IDE seems like a good place for students to start supporting their open science hardware.

The Raspberry Pi has processing capabilities in excess of Arduinos and is generally supported via a command line interface. If a particular project requires the power of a Raspberry Pi then the command line might be the only option. I consider this to be a serious obstacle to adopting the Raspberry Pi and have never used one. This has not obviously restricted my development of open science hardware that is described in my fifty-some notes at Public Lab about Arduino. Using a Raspberry Pi to program an Arduino seems like adding a layer of unneeded complexity (the R Pi) in order to produce an Arduino-based device.

Is there a valid justification for subjecting students to the command line? What type of open science instrumentation requires a Raspberry Pi instead of an Arduino? How much will open science instrumentation be limited by eschewing the command line?

Chris

Is this a question? Click here to post it to the Questions page.

Thank you, @cfastie, for your thoughtful questions.

I think Arduinos and Pis represent two useful ecosystems for building instruments/data loggers and it's useful for students to learn both. The Arduino is great for low-power, single-threaded applications especially where you need analog inputs. But it doesn't come with any way to record or transmit data -- or even a clock to know when data are collected. A Raspberry Pi needs more power and isn't single-threaded, but it comes with a network stack and can use it to keep a clock set correctly and to transmit data. And, although it doesn't have analog inputs, it can connect to digital sensors over serial interfaces. So it's probably worth having some familiarity with both ecosystems.

I see several advantages to learning the command line. In part, it's a lowest-common denominator. It requires a much smaller operating-system footprint and uses much less memory of the device. You can easily interact with it securely over the network -- even over a slow or unreliable connection. And if something isn't working correctly, the command line, via single user, may be your last, best chance to fix things or recover data.

I also see it as a way to manage the complexity of BYOD student computers. Students bring a vast array of different kinds and ages of computers. Having students only require an ssh connection from their computer to do all of their programming means that they can do the programming anywhere, they don't need display hardware or keyboards for the Raspberry Pi. (This summer, I spent hours helping a student set up a workflow to program an Adafruit Feather using an HP laptop that had weird, platform-specific issues.)

We've used Raspberry Pis a lot for instruments and data loggers that can be plugged into power and have ethernet because it simplifies getting data in and out. And you can log in remotely to check functionality and make adjustments. Not having to go touch devices is wonderful. And I believe that a lot of instruments students will make for the course will be laboratory instruments -- or, at least, will be accessible over the network.

So, "Is there a valid justification for subjecting students to the command line?" Well, I think so. I've taught any number of students over the years who had told me that one of the most useful things they learned from me was to become facile with the command line: that it opened doors and possibilities that they hadn't realized were there. The command line, far from being "that blinking cursor where you must enter a precise and inscrutable string of characters" is language: a nuanced and flexible way to specify and capture what you want the computer to do. A GUI, by comparison, is a kind of cave-man interface: point and grunt, point and grunt, point and grunt. :-)

Thanks again for your questions! I look forward to continuing the dialog!

Is this a question? Click here to post it to the Questions page.

That's really useful information. I can see the advantage of having every scientific instrument accessible on the web or network. Being able to remotely log onto each instrument and update code or change parameters opens up important possibilities.

I also like the idea that programming and interacting with an instrument requires only an SSH connection (whatever that is) which is apparently easy to have on any computing device. Setting up and maintaining the Arduino IDE on your computer (with board definitions and libraries) can be a big project. Doing this for every student's computer could be an obstacle. Although I assume those Arduino board definitions and libraries are going to be needed if your goal is to "use the raspberry pi to program an Arduino via the command line." Does that mean that some form of the Arduino IDE will be installed on each Raspberry Pi? I guess I don't really understand the architecture you're proposing or what workflows will be possible.

While most Arduinos are not connected to a network, they can be. ESP boards have integrated Wi-Fi which allows remote two-way communication with the board. It is straightforward to send sensor data from the ESP to a local server or to the web, so there is no need for a clock or local storage (timestamps are provided by the server which saves all the data).

ESP boards generally cost 10% of the price of a Raspberry Pi board. If some of the shortcomings of Arduino disappear, the remaining benefits of Raspberry Pi have to be central. I get the impression you think they are.

Chris

Is this a question? Click here to post it to the Questions page.

I had originally installed only the arduino "core" package which has the compiler and library stuff to work with arduinos. I tried installing the raspbian arduino IDE package, but it's pretty old, so I downloaded and installed the newest arduino IDE. It turns out, that they've lately added a bunch of command-line functionality!

You can run the graphic package on the Raspberry Pi (rather than only interacting with the command line). You can even run it via X-windows, so that would be another way students could do the programming on their personal computer without having to be connected directly to the arduino.

There are a bunch of ways you can network arduinos (e.g. hats with radios or wifi or ethernet). And for some projects, students might want to learn how to do that.

And, as my new note indicates, the Raspberry Pi can be the server! (e.g. running a webserver in this case). ssh (secure shell) is useful not only to allow you securely connect to the raspberry pi, but you can also tunnel other kinds of connections, so you don't have to expose services to the internet where attackers can poke at them.

Reply to this comment...

I wanted to share something that was shared on Open Call that I thought might be of interest to you @limako, It's called the Nerves-Project and uses the Elixir language (Ruby-inspired, not object oriented language, more functional). The platform is designed to allow you to write code, flash to your hardware, and be up and running and is compatible with Arduino and RPis, as well as other systems that can run Linux. It also includes some software to allow for over-the-air updates to your system without having to plug it back in, which is awesome for tools that may be set up in a place that you don't have easy access to. They have a monthly meetup on Wednesdays, more info on that here. I'm not an expert on this myself, but thought it sounded cool and was worth sharing.

Thanks! I'm sorry I've been AWOL from the open call meetings. My class is actually starting next week and, with the pandemic, I've been having to adjust to teaching the class remotely. I'll check it out. And I hope to check in with everyone soon.

Best of luck with your class this semester, can't wait to hear how it goes!

Reply to this comment...

Login to comment.