1

I have installed the Arduino IDE 2:1.0.5 on my Raspberry Pi3 under Raspbian and am using a cobbler breakout which provides a nice breadboard. On that breadboard I have installed an Arduino Nano to do analog voltage readings, which it then communicates back to the Rpi3 via the USB serial port which shows up as /dev/ttyUSB0 on the Rpi3.

This port opens as a regular file in Python for further processing such as adding a date & time stamp (obtained by an NTP server) and saving the results to a data file that is displayed in gnuplot 4.6.

PiBerry

You'll notice I am using 3.3 Volts for the fan to keep it quiet, and the two wires heading up to the top go to the voltage source I am monitoring. If you look closely you can see the voltage divider circuit.

Here is today's solar plant voltages which this thing tracks. The block at the bottom means the inverter was on. Green means the battery bank is full.

PV Battery Bank

Anyway, it turns out that the same serial connection is supported by the Rpi Arduino IDE for programming.

Rather than programming the Nano on a laptop and constantly having to unplug/replug it on the breadboard my goal is to use Rpi Arduino IDE for programming.

So I moved all my sketches over from the Arduino IDE on the laptop to the Rpi.

But

.... then every time I start the Rpi IDE it throws error messages for all the sketches that have underscores in their names. Turns out the Rpi version will only allow alphanumeric directory names. I have a couple dozen sketches and this is not productive. It requires clicking OK for every directory it skips - which turns out to be all of them.

So my question is: What can I do about this?

  • 2
    Perhaps you could spell out which op sys you installed on your Raspberry Pi, and which IDE version is installed. – James Waldby - jwpat7 Jan 29 '17 at 23:38
  • 1
    Just a little comment: arduino IDE version 1.0.5 is quite old.. Maybe it's worth updating to 1.8.1 (you can't use apt, though; just go on the Arduino download page and download the ARM version (I think) – frarugi87 Feb 6 '17 at 15:12
  • Ah, I see 1.8.1 there. And yes, I had used apt-get install to do this in the first place. Not sure I have the know-it-all to do it another way. Meanwhile, it is working great. I love being able to reprogram my units that are outside and far away without having to bring them back in to the laptop and risk bending pins, etc. I can do updates with almost no downtime. – SDsolar Feb 6 '17 at 19:05
1

To fix this problem I came up with the following procedure which takes out all the underscores from the directories & filenames and capitalizes each word instead.

First, I copied all my sketches and libraries (from my documents/arduino directory) to a USB flash drive.

The Rpi Arduino IDE creates a sketchbook directory upon install, so I

Copied the libraries folder to ~/sketchbook/libraries

Copied the sketches folder to ~/sketchbook/AMSsketches

Then I wrote a custom script that is copied to my home directory on the Rpi, which can be obtained here as a text file (use Chromium or wget to copy it to the file ~/AMS2Rpi) - Here is the link: http://calttc.net/AMS2Rpi

which contains this code:

#! /bin/bash
#
#  AMS2Rpi - Converts MS Arduino IDE Sketch names to RPI Arduino IDE Sketch names
#
#                  SDsolar      2017-01-29
#
#  Reason:    Arduino IDE on MS inserts underscore characters in file & directory names
#             Arduino IDE on Rpi rejects all but alphanumeric characters
#
#  Solution:  Remove all but alphanumeric characters 
#             and capitalize each word in the names
#
#  Usage:  
#    Install Raspbian Arduino IDE 2:1.0.5 on the Raspberry Pi 3
#    Use a USB flash drive to copy sketches and libraries from the MS-based Arduino IDE
#      On the Rpi, copy the libraries directory to ~/sketchbook/libraries
#      On the Rpi, copy the sketches directory to ~sketchbook/AMSsketches
#    Copy this script to your home directory as AMS2Rpi using Chromium
#    cd
#    chmod +x AMS2Rpi
#    ./AMS2Rpi    (This will take some time)
#    cat /tmp/AMS2Rpi | grep "AMSsketches" >~/AMSRpiQ
#    chmod +x ~/AMS2RpiQ
#    ~/AMS2RpiQ
#    Open the Rpi Arduino IDE 
#
#  Alternatively, if you have a lot of sketches you might want to
#    change the "mv -i" below to "mv" 
#    and cat it into AM2SRpiX above
#    so you don't need to answer "y" for every rename.
#
#  Props to Marco Fioretti for his article at http://www.techrepublic.com/blog/linux-and-open-source/how-to-remove-weird-characters-from-file-and-directory-names-automatically/
# ---------------------------------------------------------------------
rm -f /tmp/AMS2R*
cd $1
find .  | awk '{ print length(), $0 | "sort -n -r" }' | \
        grep -v '^1 \.$' | cut -d/ -f2- > /tmp/AMS2Rpi_1
touch /tmp/AMS2Rpi_2
while read line
  do
  BASE=`basename "$line"`
  NEWBASE=`basename "$line" | perl -e '$N = <>; chomp ($N); $N =~ s/[^a-zA-Z0-9.]//g; $N =~ s/_+/_/g; $N= lc($N); $N =~ s/_([a-z])/_.uc($1)/eg; print ucfirst($N);' `
  if [ "$BASE" != "$NEWBASE" ]
  then
  OLDPATH=$(echo "$line" | sed -r 's/([^a-zA-Z0-9./_-])/\\\1/g')
  DIR=$(dirname "$line" | sed -r 's/([^a-zA-Z0-9./_-])/\\\1/g')
  echo "mv -i $OLDPATH $DIR/$NEWBASE" >> /tmp/AMS2Rpi_2
  fi
done </tmp/AMS2Rpi_1
rm -f /tmp/AMS2Rpi_1
mv /tmp/AMS2Rpi_2 /tmp/AMS2Rpi
exit

Then set it to executable and run it:

cd
chmod +x AMS2Rpi
./AMS2Rpi

When it is finished, I filter out just the directory I want (VERY IMPORTANT):

cat /tmp/AMS2Rpi | grep "AMSsketches" >~/AMS2RpiQ

(You can look at that file to verify it before running it)

chmod +x ~/AMS2RpiQ
~/AMS2RpiQ

Cleanup if you wish:

rm /tmp/AMS2R*
rm ~/AMS2RpiQ

Now the Arduino IDE on the Rpi opens cleanly and all my sketches are there.

Problem solved. It works great.

  • 2
    This reminds me of a programmers' joke I read some time ago, which said "a programmer is someone who takes one month to develop a program which automates a one hour task" ;) – frarugi87 Jan 30 '17 at 9:00
  • 2
    That's pretty good. I would only add that the retired ones are the worst. ;-) – SDsolar Jan 30 '17 at 19:34
0

Turns out there are two easier answers if you are willing to do it manually.

You can use the Windows-based IDE to load each sketch then save them with an allowable name, before transferring them.

So, instead of going through the program, just do it by hand - this is best if you don't have too many, or if you are very patient.

Or jump in with both feet: use your USB flash drive to just move your libraries and sketches to the appropriate directories under sketchbook.

libraries go to ~/sketchbook/libraries
sketches go to ~/sketchbook/sketches
Go into the IDE preferences and tell it to look into ~/sketchbook/sketches

Manually rename any directories in both directories so they only have alphanumeric characters in the subdirectory names

The Rpi version of the Arduino IDE has no problem with filenames with underscores. It is just the directories it rejects if they are not strictly alphanumeric. But it really prefers that the files have the same names as the directories.

Each library must be added to the IDE using the 
IDE menu Sketch..Import Library..Add Library

It stores them somewhere else in the IDE's guts.

  • I might add that this works fine unless you have 40 sketches and libraries that are being ignored due to this error. – SDsolar Jul 8 '17 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.