It is much easier to develop a program using Python rather than C/C++
It is much easier to develop a program on a PC rather than on the Linux side of a Yun.
It is much easier to do the “heavy lifting” using Python and on the Linux side of the Yun rather C/C++ than on the Arduino side.
When I first heard of the Yun I assumed it would be like a Raspberry Pi with WiFi and an Arduino but without sound and graphics. And it is. But the way it is presented by the Yun developers you would be forgiven for thinking it was a Linux attachment for an Arduno rather than an Arduino attachment for Linux.
It is easy to write a combination of Python and Arduino code that works on a PC connected to an Uno and which will run with little or no change on a Yun.
The only change neeeded for the Arduino code is to change from Serial to Serial1
And on the Yun the Python code connects to the Arduino side via /dev/ttyATH0 rather than /dev/ttyACM0 (or COMxxx on Windows)
The attached ZIP file includes the Python and Arduino code containing a minimal example.
When you extract the ZIP file on your PC it will create a directory called SimpleDemo.
It contains a file called SimpleDemo.ino which should be uploaded to the Arduino side of the Yun
The complete directory should be uploaded to the Linux side of the Yun. The file SimpleDemo.ino is not needed on the Linux side, but it won’t do any harm.
With very few changes (all noted in the comments) the code will also work on a PC connected to an Uno, Mega or Leonardo
In this note I am using Python because I am familiar with it. I like Python because most code runs unchanged on Linux, Mac or Windows. You can use other programming languages on the Yun and much of what I say applies to them all.
In most Linux systems a user does not have full ROOT privileges for obvious security reasons, although s/he can temporarily acquire the extra privilieges when required.
Because the Yun is only intended to be a single user system the normal user is called ROOT and has all of the privileges to destroy everything on the system
Out-of-the-box the Yun uses /dev/ttyATH0 for communication using the Bridge library and that needs to be disabled to allow Python to use that serial connection.
The file /etc/inittab contains a line
which needs to be commented out (so it looks like this)
and the the Yun needs to be restarted.
I have also attached two short Python programs that will make this change (and undo it) if you don’t want to edit /etc/inittab yourself. These programs are in pythonBridgeDisable.zip.
If you want to check the contents of a text file on a Linux system it is as simple as
In spite of the fact that the Yun comes with Python installed the developers did not provide any convenient way to upload Python programs to the Yun. However the process is not at all complicated. A Python program is just a text file, or a collection of text files.
When you connect to the Yun using SSH your terminal ONLY has access to the Yun. For copying files to the Yun you must obviously have access both to the Yun and the to PC that contains the files. That is what the program scp (Secure CoPy) is for. (I believe there is WINscp for Windows users).
To use SCP you need to open a terminal on your PC (not the terminal you may be using for SSH) and call scp from it - for example
scp myFile.txt root@192…:/mnt/sdxxxxxx
will copy the file “myFile.txt” to the directory /mnt/xxxxxxxx
You will notice that when you run scp it will ask you for the password for your Yun.
If you want to copy a directory and all of its files the command is only slightly different
scp -r myDirectory root@192…:/mnt/sdxxxxxx
the “-r” tells it to copy recursively
For the SimpleDemo program the command will be
scp -r ./SimpleDemo email@example.com:/root
assuming your terminal is open at the Directory that contains the directory called SimpleDemo
and, of course, you need to use the correct IP address
I am assuming you will create and upload Arduino sketches using a PC connected to the Yun via the small USB connector.
SSH (standing for Secure SHell) is a standard way for securely controlling a Linux PC via the command line over an internet connection. SSH is already installed on the Yun and will also be installed on Linux PCs. The puTTY terminal program can be used to make an SSH connection from Windows (and Linux).
To connect to the Yun with SSH the command is
It will ask you for the Yun password
When you have connected using SSH you can run programs and do all the usual things that you could do if your screen was directly connected to the Yun.
cd SimpleDemo # to change to the project Directory
python SimpleDemo.py # to run the program
As usual, comments and corrections will be welcome.
And it would be very helpful if a kind Windows user could try it and add any necessary additional info.
SimpleDemo.zip (89.1 KB)
pythonBridgeDisable.zip (1.1 KB)