tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Tue Jan 14, 2014 11:37 am

The easiest way to test the connection is to use the Arduino IDE to download the 'BLINK' sketch to the Arduino in the 'normal' way.
Have you programmed an Arduino in this manner before? If not look at Magpy Issue 7 page 4. This explains how to do it.

Are you using a powered hub? The Pi cannot usually supply sufficient power to drive the Arduino as well from its USB port. I've use the Pimoroni hub and power supply which works very well.

http://shop.pimoroni.com/products/pihub#.UtUhjrWYZhE


Let me know how you get on.
Tony Goodhew

Sertok
Posts: 4
Joined: Tue Jan 14, 2014 8:37 am
Location: Germany

Re: Using an Arduino as a slave I/O board

Tue Jan 14, 2014 12:43 pm

Thanks for your fast answer!

I'm using a hama usb hub to power up both boards. I've already found some recessions pointing out its low energy level. Perhaps that's really my problem, but that can easily be fixed ;)

I haven't programmed the Arduino yet. Coupling the raspi and the arduino was meant to be my first step :?
From there on i've got some books waiting for me.

Since i'm not new to programming per se and since i've read a bit about the Arduino IDE... i guess i'll have another feedback ready, as soon as i'm back from work.

Kind regards,
Sertok

tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Sat Jan 18, 2014 7:38 pm

Unfortunately several of the files/sites on the Web used in setting up a Nanpy SD card have been updated or changed. I have written a modified set of instructions and tested them. This this a 2 page Word document which I will happily email to you if you send me a private email message request.

The new version uses Nanpy vers 0.8 which appears to have many more libraries included.

Have fun with the new version.

Tony

Sertok
Posts: 4
Joined: Tue Jan 14, 2014 8:37 am
Location: Germany

Re: Using an Arduino as a slave I/O board

Sat Jan 18, 2014 10:07 pm

The new version worked, thanks again :)
Kind regards,
Sertok

McCann
Posts: 1
Joined: Wed Jan 22, 2014 10:46 pm

Re: Using an Arduino as a slave I/O board

Wed Jan 22, 2014 10:58 pm

Hi everybody,

I have done this tutorial step by step, but i'm stuck with one error:

pi@raspberry ~ $ cd nanpy-master
pi@raspberry ~/nanpy-master $ cd firmware
pi@raspberry ~/nanpy-master/firmware $ export BOARD=uno
pi@raspberry ~/nanpy-master/firmware $ make
make: *** No targets specified and no makefile found. Stop.
pi@raspberry ~/nanpy-master/firmware $

I have put the whole extracted directory 'nanpy-master' from my usb flashdrive to directory /home/pi, so all the files should be there. Also I've tried Arduino IDE to program my Arduino UNO rev3, and it works fine. Can anybody help me? I googled for solution, but found nothing. Thank you in advance.

Sertok
Posts: 4
Joined: Tue Jan 14, 2014 8:37 am
Location: Germany

Re: Using an Arduino as a slave I/O board

Thu Jan 23, 2014 6:39 am

Hello McCann,

i had the same problem and Tony updated his script already. (you can pm him for the new one)
The nanpy-master doesn't work at the moment. We used nanpy-0.8 in combination with setuptools-0.6c11-py2.7.egg and pyserial-2.7.tar.gz.

Worked for me. Like i said, Tony just updated his documentation (his last comment in this thread).
Kind regards,
Sertok

Patterson.Taylor.III
Posts: 1
Joined: Mon Feb 17, 2014 6:51 pm

Re: Using an Arduino as a slave I/O board

Mon Feb 17, 2014 8:13 pm

I would love to get a copy of the updated instructions, but I just made my account and cannot PM tony.

tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Tue Feb 18, 2014 9:33 am

Patterson.Taylor.III wrote: I just made my account and cannot PM tony.
PM is a Personal Message. Just click on my name and follow the links. Alternatively email me on arduinolink@gmail.com and I will send the instructions and examples sheets.

Tony

mirc3a91
Posts: 8
Joined: Sat Mar 01, 2014 7:22 pm

Re: Using an Arduino as a slave I/O board

Mon Mar 17, 2014 3:53 pm

Sertok wrote:Hey Tony!

Thanks for your detailed post. I've already read it in MagPi#15 and tried it out yesterday.
Sadly it won't work (different releases, etc.). Since i'm really fresh to the raspi and arduino, i'm already at my limit.

Here's what i did:
- I downloaded and installed setuptools-2.1 => no errors
- I downloaded and installed pyserial-2.7 => no errors
- I installed the Arduino GUI => no errors
- I downloaded and unpacked Nanpy
- I connected my Arduino Uno R3 to my Raspberry Pi Model B and it powered up (both are connected via USB-hub)

I'm able to use "export BOARD=uno", but wether "make" nor "make boards" works.
Is there a way to test the serial connection between the Arduino board and the raspi? My guess is, that this is the real problem.

I'm really new to this, so please excuse "dumb questions" with obvious answers :)
I've already tried for 4 hours without any visible progress :?
I have the exact same problem as Sertok...please help

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Using an Arduino as a slave I/O board

Tue Mar 18, 2014 9:14 pm

tonygo2 wrote: This this a 2 page Word document which I will happily email to you if you send me a private email message request.
Tony
Rather than request it, is it not possible just to post it?

Thanks.

tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Wed Mar 19, 2014 8:40 am

As requested:

Using Nanpy to connect your RPi to an Arduino

Preparing the SD card – Version 3 – 18th Feb 2014 – by Tony Goodhew

You a need a 4 GB class 4 card (slow). Copy the latest version of Raspbian Wheezy onto it and expand the root partition. Reboot the Pi.
It’s best to do sudo apt-get update and sudo apt-get upgrade now. The second takes some time!

Install setuptools
You need python setuptools to install nanpy on your card. This is not in the current distribution. You can download it from the Web.

Start Midori and type in the URL box https://pypi.python.org/pypi/setuptools ... #downloads

Scroll down to the Linux instructions and then on to downloads. We want the file:
setuptools-0.6c11-py2.7.egg
Click on it and you will be asked to open or download. Click on SAVE. It downloads very quickly.

Close Midori and you should see the egg file in the pi directory.

Open the LX Terminal and type in:
sudo sh setuptools-0.6c11-py2.7.egg
This is a very quick installation.

Install pyserial
Using Midori go to https://pypi.python.org/pypi/pyserial
Download pyserial-2.7.tar.gz
Make a temp folder and move the downloaded file into it.
Using LXTerminal
cd temp Change to the temp directory
gunzip pyserial-2.7.tar.gz to unzip it
tar –xvf pyserial-2.7.tar to untar it
cd pyserial-2.7 move into the new folder
sudo python setup.py install to install it

Your Pi can now use serial communication

Install the Arduino software
Type ‘startx’ to start the GUI.
Open the LX Terminal.
Type in the the following command:
sudo apt-get install arduino
Answer ‘Y’ when asked if you want to continue. This installation takes some time…..
You can now program your Arduino from the Arduino IDE.

Install Nanpy
The next step is to download the nanpy files:

Using your Midori navigate to https://pypi.python.org/pypi/nanpy
and download nanpy-v0.8.tar.gz. This downloads the zipped directory. Now unzip it.
gunzip nanpy-v0.8.tar.gz # To unzip it
tar –xvf nanpy-v0.8.tar # To untar it

This works very hard, scrolls the screen for some time and creates a new folder called nanpy-0.8.

Open the LX Terminal and navigate to the firmware directory in nanpy-v0.8.
Connect your Arduino via a USB cable to the Pi.
cd nanpy-0.8
cd firmware
export BOARD=uno
(Type ‘make boards’ for a full list)
make
make upload
This also takes some time…….

This RED section loads the Arduino part of nanpy into the Arduino. You may need to do it again if you corrupt the part of nanpy now in the Arduino or if you program it from the Arduino IDE.

cd .. Move back to nanpy-0.8 directory
sudo python setup.py install

This adds the RaspPi part of nanpy to Python2 and only needs to be done once. You can now use the Arduino as an I/O board for the Pi. This adds 19 extra I/O pins – 6 can be used for 10-bit analog inputs(range 0-1023) and 6 as PWM outputs (range 0-255). (Do not use pins 0 or 1 – Tx and Rx to Pi.)

Testing

The Arduino really needs to be connected via a powered USB hub so that it does not take too much power from the RPi. (NB All sensors & outputs add to the current drain.)

On your Arduino connect an LED in series with a resistor (about 330 Ohms for protection) between pin 10 and ground. The longer lead of the LED, the anode, goes towards pin10 and the shorter, the cathode, towards GND. Pin 10 allows PWM (Pulse Width Modulation) – marked with ‘~’.

From LXED start LXTerminal and type: sudo idle
(With sudo you can run the program from the Run menu in Idle)
Click on File, then New window. Then type in the following program into the new window:

#!/usr/bin/env python
# LED with 330 Ohm resistor on Pin 10 to GND
# Tony Goodhew – 17 Feb 2014
from nanpy import Arduino
from nanpy import serial_manager
serial_manager.connect('/dev/ttyACM0') # serial connection to Arduino
from time import sleep

LED =10 # LED on Arduino Pin 10 (with PWM)
Arduino.pinMode(LED, Arduino.OUTPUT)

print"Starting"
print"5 blinks"
for i in range(0,5):
Arduino.digitalWrite(LED, Arduino.HIGH)
sleep(0.5)
Arduino.digitalWrite(LED, Arduino.LOW)
sleep(0.5)

print"Changing brightness of LED"
bright = 120 # Mid brightness
Arduino.analogWrite(LED, bright)
Arduino.digitalWrite(LED,Arduino.HIGH) # Turn on LED

for i in range(0,200):
bright = bright + 8
if (bright > 200): # LED already full on at this point
bright = 0 # Minimum power to LED
Arduino.analogWrite(LED, bright) # Change PWM setting/brightness
sleep(0.10)

Arduino.digitalWrite(LED,Arduino.LOW) # Turn off LED
print"Finished"

Save and run the program from the idle menu.

Problem: If you pull the USB cable out of the Arduino while the Pi is controlling it you may need to re-boot the Pi before it will re-connect. You may also need to re-do the red instructions at the bottom of page 1 if the firmware gets corrupted.

Thanks to Andrea Stagi for the Nanpy. See MagPi – issue 8, page 12

Please let me know how you get on with this guide. Report errors or problems to: arduinolink@gmail.com

tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Wed Mar 19, 2014 8:48 am

If you would like a copy of the examples (too long to post), please request from: arduinolink@gmail.com

Regards

Tony Goodhew

User avatar
scruss
Posts: 3800
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Using an Arduino as a slave I/O board

Wed Mar 19, 2014 12:12 pm

Any reason not to use the python-serial and python-setuptools that are in the Raspbian repos? It would cut a lot of these steps down to one apt-get line.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Wed Mar 19, 2014 2:48 pm

They should work but when I started this they were missing.

Tony

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Using an Arduino as a slave I/O board

Wed Mar 19, 2014 11:37 pm

Thanks very much Tony,

Sorry my last post was a bit terse, had bad day

User avatar
scruss
Posts: 3800
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Using an Arduino as a slave I/O board

Thu Mar 20, 2014 2:12 am

tonygo2 wrote:They should work but when I started this they were missing.
python-serial was in the repo when I wrote about pyFirmata for MagPi #7 (?) in 2012.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Thu Mar 20, 2014 8:19 am

As it stands I know it works. If you want to try another way please try it and let us all know.

Regards

Tony

User avatar
scruss
Posts: 3800
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Using an Arduino as a slave I/O board

Fri Mar 21, 2014 12:07 am

Yeah, it works using the stock modules. So does Firmata, though, and it's been around for much longer and used many more places.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Fri Mar 21, 2014 8:13 am

You are being more than a bit pushy.

They both work. Leave the choice to those who want some help. You like Firmata and I like Nanpy.

Regards

Tony

User avatar
chrisryall
Posts: 155
Joined: Wed Nov 27, 2013 11:45 am
Location: Wirral UK
Contact: Website

Re: Using an Arduino as a slave I/O board

Fri Mar 21, 2014 8:49 am

Does NanPy have any documentation? I've googled quite a lot and only found "version x is out!" stuff and a few examples. whereas what I was after was a list of methods, properties and how to use them.

tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Fri Mar 21, 2014 9:31 pm

I've published a set of instructions in The Magpi Magazine - issues 15, 16 and 17. If you send me an email to arduinolink@gmail.com , I will email you the documentation with circuits, photos and code.

Regards

Tony Goodhew

User avatar
chrisryall
Posts: 155
Joined: Wed Nov 27, 2013 11:45 am
Location: Wirral UK
Contact: Website

Re: Using an Arduino as a slave I/O board

Fri Mar 21, 2014 10:31 pm

Thank you for that. I'd been appraised of the magpi articles by the "friendly disagreement" above and have yesterday downloaded all the pdf's they are excellent!

Working through the portfolio now and have found Andrea's article in issue 8. Nampy is presumably moving on at its own pace, with formal documentation doing the same, (albeit rather slower)?

Thanks again for the pointer to your own articles, will hopefully get to them over the weekend :)

User avatar
bigdog
Posts: 3
Joined: Mon Apr 28, 2014 5:21 am
Location: Chicago

Re: Using an Arduino as a slave I/O board

Sun May 04, 2014 11:02 pm

Hey Tony,

Great write up. Unfortunately the firmware is no longer located in the nanpy-master file so these instructions are no longer good. They made a separate github file for it. I was able to download it from its new location. I am having an issue with makefile.

I change directory to the firmware. I type "export BOARD=uno" (no quotes), but when i type "make" I get this output.
make: *** makefile: Is a directory. Stop.

Do you have any clue of what the problem may be, any hep would be appreciated. BTW, you are very correct when you say the documentation on this is very limited. Thanks to you I have a better understanding.

tonygo2
Posts: 93
Joined: Sun Aug 28, 2011 2:50 pm
Location: Leicester, UK

Re: Using an Arduino as a slave I/O board

Mon May 05, 2014 1:26 pm

Look earlier in this forum to 19th March 2014 where I posted the updated instructions. These get over the problem. If you would like a set of examples please send me a private message with your email address and I will email them to you. Unfortunately this forum does not allow email attachments.

Tony Goodhew

User avatar
bigdog
Posts: 3
Joined: Mon Apr 28, 2014 5:21 am
Location: Chicago

Re: Using an Arduino as a slave I/O board

Wed May 07, 2014 8:24 am

Thank you for the examples you emailed Tony,

I have followed everything in your updated instructions, but keep getting that error. Its a different error than the one posted here by a another user. Maybe im not following correctly. In the part called "Install Pyserial" you are using Midori and the LX Terminal. Then in the next part called "Install Arduino" you have us type in "startx" to get to the GUI. Correct me if im wrong but in order to use Midori and the terminal (as in the previous step) don't you already have to be in the GUI. So why would we have to type "startx" (for the following step). Maybe i'm wrong but I am referring to the Pi desktop as the GUI.

Also the Nanpy 0.8 does not exist. And the new 0.9 does not come with the firmware (so its a separate download) so shouldn't that part of the instruction read more like this?

Install Nanpy
The next step is to download the nanpy files:

Using your Midori navigate to https://pypi.python.org/pypi/nanpy
and download nanpy-v0.9.tar.gz . This downloads the Nanpy-master zipped directory. Now unzip it.
gunzip nanpy-v0.9.tar.gz # To unzip it
tar –xvf nanpy-v0.9.tar # To untar it

This works very hard, scrolls the screen for some time and creates a new folder called nanpy-master.

Now go back to https://pypi.python.org/pypi/nanpy
and download nanpy-firmware-v0.9.tar.gz . This downloads the Nanpy-firmware-master zipped directory. Now unzip it.
gunzip nanpy-firmware-v0.9.tar.gz # To unzip it
tar –xvf nanpy-firmware-v0.9.tar.gz # To untar it

This creates a new folder called nanpy-firmware-master.

I wasn't sure so I moved the nanpy-firmware-master folder into the nanpy-master folder:
mv nanpy-firmware-master nanpy-master

Open the LX Terminal and navigate to the firmware directory in nanpy-master.
Connect your Arduino via a USB cable to the Pi.
cd nanpy-master
cd nanpy-firmware-master
export BOARD=uno (Type ‘make boards’ for a full list)
make
make upload This also takes some time…….

Return to “Interfacing (DSI, CSI, I2C, etc.)”