User avatar
Onira
Posts: 237
Joined: Tue Oct 02, 2012 6:24 pm
Location: Poland

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

Thu Feb 19, 2015 1:59 pm

I see...

so I need to create a file named playlist.txt with my favourite streams, right?

The code you shown is not working...

Code: Select all

try
is try a code?

Code: Select all

avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /tmp/build4896435538512032639.tmp/sketch_feb19a.cpp -o /tmp/build4896435538512032639.tmp/sketch_feb19a.cpp.o 
sketch_feb19a.cpp:1:6: error: invalid preprocessing directive #!
sketch_feb19a.cpp:7:45: warning: character constant too long for its type [enabled by default]
sketch_feb19a.cpp:14:9: error: #error = sys.exc_info()[0]
sketch_feb19a.cpp:15:9: error: invalid preprocessing directive #print
sketch_feb19a.cpp:27:13: error: invalid preprocessing directive #set
sketch_feb19a.cpp:30:30: warning: character constant too long for its type [enabled by default]
sketch_feb19a.cpp:36:16: error: invalid preprocessing directive #get
sketch_feb19a.cpp:42:25: error: invalid preprocessing directive #client
sketch_feb19a.cpp:68:16: error: invalid preprocessing directive #sleep
sketch_feb19a.cpp:69:15: error: invalid preprocessing directive #time
sketch_feb19a.cpp:72:7: error: invalid preprocessing directive #set
sketch_feb19a.cpp:74:5: error: stray ‘#’ in program
sketch_feb19a.cpp:76:21: error: empty character constant
sketch_feb19a.cpp:83:7: error: invalid preprocessing directive #set
sketch_feb19a.cpp:88:7: error: invalid preprocessing directive #listening
sketch_feb19a.cpp:101:7: error: invalid preprocessing directive #receiving
sketch_feb19a.cpp:105:14: error: invalid preprocessing directive #print
sketch_feb19a.cpp:111:14: error: invalid preprocessing directive #print
sketch_feb19a.cpp:3:1: error: ‘import’ does not name a type
Cogito ergo sum

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Thu Feb 19, 2015 5:42 pm

the code is all one python program, it uses the playlist.txt file as data to add streams to the mpc daemon.
try: and except: are error handling in python.
You try some python code, if the section of code fails python goes to the except section to do error handling.
For example if it fails when you try to use the arduino the first time, instead of getting a whole mess of errors, you just get a simple error message and the program can continue or exit as you have decided in your program.
Hope this makes sense?
The idea is to load the arduino with nanpy and forget about that, and drive it with the python on the PI.
RichR

P.s. that error message is one I haven't seen before. Can you describe how you got it? It looks like you are running it in the arduino ino ide?

User avatar
Onira
Posts: 237
Joined: Tue Oct 02, 2012 6:24 pm
Location: Poland

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

Thu Feb 19, 2015 5:51 pm

Yes I ran it in Arduino IDE from RPi
and when I click upload button I get this error.

So how should I upload it if not via IDE?
Cogito ergo sum

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Thu Feb 19, 2015 6:31 pm

Here's what you should have.
An arduino running Nanpy,
with on the Raspberry Pi, a python program controlling the mpc daemon and outputting the internet radio to the speakers

RichR
diagram.png
diagram.png (16.68 KiB) Viewed 5682 times

User avatar
Onira
Posts: 237
Joined: Tue Oct 02, 2012 6:24 pm
Location: Poland

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

Thu Feb 19, 2015 8:46 pm

okay... my mistake ;)
I made a file richradio.py and playlist.txt
now I have

Code: Select all

$ python richradio.py
  File "richradio.py", line 2
    import os, sys, threading, time, socket
    ^
IndentationError: unexpected indent
$
Cogito ergo sum

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Thu Feb 19, 2015 9:19 pm

Probably going off topic with this.
The error message means you have a space or tab that shouldn't be there. Python uses the indent level to structure code. (Very important) - C uses brackets, so you have to switch 'eyes' to look at it.
That line is the line in error and the up arrow points at the error ^
Look at your code (you didn't type it all in I hope?) Copy and paste saves a lot of errors.
When I try other people's stuff, I always rely on their typing.

RichR
p.s. Most people stare at error messages (in shortened tech speak) and go "computerblind". You have to read the message and say to yourself : what the *** does it mean!

User avatar
Onira
Posts: 237
Joined: Tue Oct 02, 2012 6:24 pm
Location: Poland

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

Thu Feb 19, 2015 9:50 pm

Well I did that in X forwarding opening IDLE and pasting your code
all spaces are same so I need to look and think ;)

Thank you for you patience


EDIT
IDLE helped me to verify every line and when the code seemed to be fine,
when running code I got

Code: Select all

$ python richradio.py 
Traceback (most recent call last):
  File "richradio.py", line 4, in <module>
    from nanpy import ArduinoApi, SerialManager, Lcd
ImportError: cannot import name ArduinoApi
am I missing something not being installed?
Cogito ergo sum

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Thu Feb 19, 2015 11:54 pm

Looks like it either isn't finding arduinoapi or the whole nanpy library. Did you do this bit in install? Also if you are using the older version of nanpy it might not yet have that module.

tar -xvf nanpy-v0.9.2.tar.gz
cd nanpy
sudo python setup.py install


RichR

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Sat Feb 21, 2015 10:57 pm

I noticed that they published a new version of Nanpy (0.9.3) - so I updated one of my arduino uno's with the new firmware.
Nanpy 0.9.3 (!)
On Linux on Raspberry Pi, (or Mac) with Arduino IDE installed:
Web browser.
search for Nanpy, locate https://pypi.python.org/pypi/nanpy
click the green Download button. It takes you down the page.
Download both files:-
nanpy/nanpy-0.9.3.tar.gz
nanpy-firmware-0.9.3.tar.gz
Bookmark the page, you might want to read it! Close the browser.

Start a terminal screen on your pc.
rename (mv) the old nanpy-firmware directory to nanpy-firmware-0.9.2 or whatever.

cd to your Downloads directory where your newly downloaded files shoud be waiting.

in your terminal screen enter:

tar -xvf nanpy-firmware-0.9.3.tar.gz

files are unpacked into a new directory (nanpy-firmware-0.9.3). In that directory you can read the file README.md with a texteditor. It tells you how to configure. (Wrong directory) Note, you are probably already in the right one if you read that readme file.
To configure, in your terminal screen:

cd nanpy-firmware-0.9.3
./configure.sh

In your sketchbook, rename (mv) the old Nanpy directory to Nanpy-0.9.2 (or whatever)

now copy the new Nanpy directory from the nanpy-firmware directory into your Arduino sketchbook.

The readme says:-

(Copy Nanpy directory under your "sketchbook" directory,
start your Arduino IDE,
open Sketchbook/Nanpy,
select "Upload".)

If you compile the sketch you will see that it is half its former size. Hmm?
Go back to your Nanpy that is now in your sketchbook. Save a copy of the cfg.h file and open it in a text editor.
Decide which of the include lines you want, and change the 0 at the end to a 1. (Hint, compare with the old one? You are on your own here, but in mine I changed everything in the top section except stepper, tone and eeprom (my guess, as there is no description, BUT you can read the code using the Arduino IDE!! A bit cryptic, but it might be the best documentation you will get.)
Compile again in the IDE and the size is much more... Go for an upload? That seemed to work.
RichR

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Sun Feb 22, 2015 11:03 am

I removed keypress.py from the previous post. Here's kradio.py - it includes LCD instructions. Note where the lcd gets set up:

Code: Select all

#!/usr/bin/python
import os, sys, threading, time, socket
from nanpy import ArduinoApi, SerialManager, Lcd

arduinoDevice = '/dev/ttyAMA0'
arduinoTimeout = 2
arduinoPin = 14
pollingFrequency = 0.1
serverPort = 2727
serverConnections = 1
receiveBuffer = 64

# connect to arduino board
try:
	connectionObj = SerialManager (device = arduinoDevice, timeout = arduinoTimeout)
	arduinoObj = ArduinoApi(connection=connectionObj)
        lcd = Lcd([8,9,4,5,6,7],[16,2], connection = connectionObj)
	print "Hardware: Connected to Arduino!"
except:
	error = sys.exc_info()[1] # get the error message
	print "Hardware: Error connecting to Arduino: %s" % error
	sys.exit()

# set up server for listening to keypresses
serverObj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# reuse the same port if script reloads before it's released
serverObj.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
	serverObj.bind(('',serverPort))
	print "Server: bound to port:", serverPort
except:
	error = sys.exc_info()[1]
	print "Server: bind to port failed server failed: %s" % error
	sys.exit()

# start listening for connections
try:
	serverObj.listen(serverConnections)
	print "Server: listening!"
except:
	error = sys.exc_info()[1]
	print "Server: unable to listen: %s" % error
	sys.exit()

# define the background thread which polls the hardware
class MonitorKeypress(threading.Thread):
	def __init__(self):
		threading.Thread.__init__(self)
		self.keyValue = None
		
	def run(self):
		# set up socket connection for sending keypressess
		clientObj = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
		try:
			clientObj.connect(('localhost',serverPort))
			print "Client: connected to server on port:", serverPort
		except:
			print "Client: Keypress client failed to set up socket :("
			sys.exit()

		while True:
			try:
				value = arduinoObj.analogRead(arduinoPin) # get the keypress voltage
				if value == 1023:
					if self.keyValue is not None:
						self.keyValue = None
						# client.send("None")
				elif value < 100:
					if self.keyValue is not "Right":
						self.keyValue = "Right"
						print "Client: sent 'Right'"
						clientObj.send("Right")
				elif value < 150:
					if self.keyValue is not "Up":
						self.keyValue = "Up"
						print "Client: sent 'Up'"
						clientObj.send("Up")
				elif value < 330:
					if self.keyValue is not "Down":
						self.keyValue = "Down"
						print "Client: sent 'Down'"
						clientObj.send("Down")
				elif value < 510:
					if self.keyValue is not "Left":
						self.keyValue = "Left"
						print "Client: sent 'Left'"
						clientObj.send("Left")
				elif value < 750:
					if self.keyValue is not "Select":
						self.keyValue = "Select"
						print "Client: sent 'Select'"
						clientObj.send("Select")
			except:
				error = sys.exc_info()[1]
				print "Hardware: Error reading keyboard: %s" % error
				print "Client: sent 'Error'"
				clientObj.send("Error")
				break
				
			# sleep to preserve CPU cycles
			time.sleep(pollingFrequency)
			
# set up thread for polling the hardware and sending them to the server
hardware = MonitorKeypress()
hardware.setDaemon(True)
hardware.start()

# accept connections
(connectionObj, detailsArray) = serverObj.accept()
print "Server: client connected:", detailsArray[0], ", port:", detailsArray[1]

st = 1
maxst = 9
volume = 75

lcd.printString(16*" ", 0, 0)
lcd.printString(16*" ", 0, 1)

# run 'forever' (unless 'Error' is sent)
while True:
    msg = connectionObj.recv(receiveBuffer) # please don't trust this input to be *nice*
#    key = channel.recv(32)
    if msg == "Error": # exit
                print "Oh no! Something bad happened :("
                break
    elif msg == "Up":
#        print "Volume Up"
         volume = volume + 5
         if volume > 90: volume = 90
         os.system("mpc volume " + str(volume))

    elif msg == "Down":
#        print "Volume Down"
        volume = volume - 5
        if volume < 10: volume = 10
        os.system("mpc volume " + str(volume))

    elif msg == "Select":
        os.system("mpc clear")
        os.system("mpc add <playlist.txt")
        os.system("mpc playlist")
        os.system("mpc play 1")
        os.system("mpc volume " + str(volume))
        lcd.printString("station " + str(st), 0, 0 )

    elif msg == "Left":
        st = st - 1
        if st < 1: st = 1
        os.system("mpc play " + str(st))
        lcd.printString("station " + str(st), 0, 0 )

    elif msg == "Right":
        st = st + 1
        if st > maxst: st = maxst
        os.system("mpc play " + str(st))
        lcd.printString("station " + str(st), 0, 0 )
It isn't perfect, but it works (using nanpy 0.9.2 python on Pi and 0.9.3 firmware on Uno). Playlist is the same simple list as I posted before.
RichR
p.s. That indent on the lcd setup line looks wrong because my son uses tabs and I used spaces!! Change my spaces to a single tab if you are 'offended'. :roll:

User avatar
Onira
Posts: 237
Joined: Tue Oct 02, 2012 6:24 pm
Location: Poland

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

Tue Feb 24, 2015 3:28 pm

When I click 'select' I get the radio reset to station 1 but LCD doesn't change

Code: Select all

Client: sent 'Select'
volume: 50%   repeat: off   random: off   single: off   consume: off
http://stream.kgnu.net:8000/KGNU_live_high.mp3
mms://wmlive.bbc.co.uk/wms/england/lrstoke
http://stream2.hippynet.co.uk:8067/
http://wwoz-sc.streamguys.com/wwoz-hi.mp3
http://sj128.hnux.com
http://simplexstream.com:8506
mms://ysj00ms01s0.aliant.net/CJCB
http://208.92.54.5:80/CFMJAMAAC_SC
http://mp1.somafm.com:8800
http://stream.kgnu.net:8000/KGNU_live_high.mp3
[playing] #1/9   0:00/0:00 (0%)
volume: 50%   repeat: off   random: off   single: off   consume: off
http://stream.kgnu.net:8000/KGNU_live_high.mp3
[playing] #1/9   0:00/0:00 (0%)
volume: 50%   repeat: off   random: off   single: off   consume: off
There is no ON/OFF button :(

and if I turn radio script ON and exit from console it freezes after about 15 - 20 seconds and radio plays but arduino remote doesn't work anymore...
Cogito ergo sum

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Tue Feb 24, 2015 5:09 pm

8-) Impressed! - I thought you had given up! You have got a lot further than before.
1. Check the spec of your lcd, does it use the same pins Lcd([8,9,4,5,6,7],[16,2] as the Cheapo Sainsmart I have? This maybe why you don't get anything on screen. BUT also I haven't done much with things on screen yet. If you look at the code towards the end, after run forever (asif!!) you can see what I did for each button. (Not much yet) - It IS still very primitive. (But hey! Nanpy working is a big step.)
2. have you tried up and down ( volume change) buttons?
3. There is a LOT I don't like about this lcd panel for radio idea - I think Nanpy is better suited to be driving hardware bits like servos and led's and steppers (ROBOTs?). I still think the LCD is a waste of the Ardy, better to have a screen and buttons on your PI? It's whatever you prefer?
When you exit from your PI console, that kills the Python program that is talking to Nanpy. Therefore the connection stops working. The Arduino sits waiting for guidance.... mpd is a PI daemon so carries on running (you can actually reboot PI and it will start up again playing the same station..Also you can switch off the Arduino and mpd doesn't care.
So what you have is good as far as we got.
RicR

User avatar
Onira
Posts: 237
Joined: Tue Oct 02, 2012 6:24 pm
Location: Poland

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

Tue Feb 24, 2015 5:24 pm

I'm stubborn ;)

I think that screen IS working because I have
  • station 1
I was so doing with previous code

Code: Select all

python radio.py & exit
and it WAS working all the time ('til it crashed)
Cogito ergo sum

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Tue Feb 24, 2015 6:17 pm

Polling those buttons without eating up all the processing time was important to me. It would have been a lot easier than using threaded code and sockets if we had had interrupts from them. Note, it wasn't easy. I started programming a long time ago and object programming is almost an alien concept to me!! Lots of trial and error. My son did a lot (most) of the fancy stuff. Note that it helps to be stubborn. He went out and bought his own Pi :lol:

What do you think each of those buttons should be doing, and what would you like to see on the panel?
Let's try to get there. (I had a clock working (sort of) at one point, but it was very iffy due to the polling.)

The playlist system could do with a better design, too. Perhaps someone else out there has some ideas, too?

RichR
p.s. did you use the uart, or change the tty device to USB? If uart, I hope you used a level shifter.

User avatar
Onira
Posts: 237
Joined: Tue Oct 02, 2012 6:24 pm
Location: Poland

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

Tue Feb 24, 2015 8:43 pm

I use standard connecting Arduino via USB to my hub so it is on /dev/ttyUSB0 (I changed in the code to make it work)
the previous code had select doing on/off
and left/right were switching the stations
there was nothing for up/down but even if there was no code for 'em they were switching stations
stations were added via mpc add [url] so I don't know if it is possible for the LCD just to display station info

I did it from http://www.instructables.com/id/Arduino ... net-Radio/ :)
Cogito ergo sum

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Sat Feb 28, 2015 8:29 pm

re lcd, you can change the last (while true ) section as you wish, each button has an action there, each following an elif..... I don't think you will get exactly the functionality you want. I created a single ruby script web page to do the job (which doesn't use arduino).
re: Nanpy (0.9.3) the interface has changed slightly, so it is best to use the new library. Also in the firmware, if you need to use soft_reset, you need to include watchdog (or it will complain about it being missing). I thought watchdog was a device I don't have! The following code includes 2 alternating led's and 2 servos. Note where the code invokes the connection, for if you want anything but the default serial. You would need this to drive 2 Arduinos. I think my soft_reset works now, too. You seem to need this with servos.

Code: Select all

#!/usr/bin/python
import sys, traceback
from time import sleep
from nanpy import ArduinoApi, SerialManager
from nanpy import Servo
from nanpy.arduinotree import ArduinoTree

try:
   conn = SerialManager(device='/dev/ttyAMA0', timeout= 2 )
   a = ArduinoApi(connection=conn)
except:
   print "failed to connect to Arduino"
   sys.exit(0)

a.pinMode(2, a.OUTPUT)
a.pinMode(3, a.OUTPUT)

try:
   servo_9 = Servo( 9, connection = conn )
   servo_a = Servo(10, connection = conn )
except:
   print "error in servo connection"
   sys.exit(0)

def soft_reset():
   tree = ArduinoTree(connection = conn)
   tree.soft_reset()

while True:
   try:
      a.digitalWrite(2, a.HIGH)
      a.digitalWrite(3, a.LOW)
      servo_9.write(90)
      servo_a.write(0)
      sleep(1)

      a.digitalWrite(2, a.LOW)
      a.digitalWrite(3, a.HIGH)
      servo_9.write(0)
      servo_a.write(90)
      sleep(1)

   except KeyboardInterrupt:
       a.digitalWrite(2, a.LOW)
       a.digitalWrite(2, a.LOW)
       soft_reset()
       print
       print "program stopped"
       sys.exit(0)

RichR

User avatar
Onira
Posts: 237
Joined: Tue Oct 02, 2012 6:24 pm
Location: Poland

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

Wed Mar 04, 2015 6:37 am

Is that re lcd an answer for me?
Cogito ergo sum

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Wed Mar 04, 2015 2:43 pm

Re : Lcd (Onira, yes, sort of) - this is only my opinion, but... The radio mpd runs in the pi, and doesn't need the nanpy lcd to work. The script to use the nanpy lcd won't get the same functionality as a specifically designed radio because it is not directly in control of the pi (the pi is in control). The nanpy lcd does have its uses, but more as an information screen. If you want a well defined radio function, you would need to put an lcd panel and buttons directly on the PI. (Again, my opinion.)
But, If you want to go further with the Nanpy lcd I will still help where I can.
RichR
p.s. On Nanpy, there is another thread under troubleshooting (getting nanpy to work)
p.p.s. The web page solution uses virtually no resources on the pi with the radio (just the mpc/mpd), and very little on the controlling machine (web server). Both systems are still available for other stuff.

hansltel
Posts: 5
Joined: Tue Mar 17, 2015 10:40 pm

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

Tue Mar 17, 2015 10:49 pm

I've installed the v 0.93 software to connect a RPI to an Arduino. I followed the instructions and the only thing I had to change was to make configure.sh executable. So the installation instructions are allmost monkey proof ;)

I started the Adruino Ide on my RPI and started a simple sketch to blink a led at pin 13. This worked very well.

I started a Python program on my RPI with the same purpose, to blink a led at pin 13, but the program returned with the following error:
Traceback (most recent call last):
File "/home/pi/pythonscripts/arduino-test1.py", line 8, in <module>
Arduino = ArduinoApi(connection=connection)
File "/usr/local/lib/python2.7/dist-packages/nanpy/classinfo.py", line 22, in getinstance
connection.classinfo = ClassInfo(connection)
File "/usr/local/lib/python2.7/dist-packages/nanpy/classinfo.py", line 59, in __init__
ls = [self._arr.name(i) for i in range(self._arr.count)]
File "/usr/local/lib/python2.7/dist-packages/nanpy/memo.py", line 20, in __call__
value = self.func(*args)
File "/usr/local/lib/python2.7/dist-packages/nanpy/arduinoboard.py", line 57, in wrapper
return fconv(func(self, *args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/nanpy/arduinoboard.py", line 125, in wrapper
return _call(cls_name, 0, call_pars, connection=connection)
File "/usr/local/lib/python2.7/dist-packages/nanpy/arduinoboard.py", line 47, in _call
ret = return_value(connection)
File "/usr/local/lib/python2.7/dist-packages/nanpy/arduinoboard.py", line 16, in return_value
return connection.readline().replace('\r\n', '')
File "/usr/local/lib/python2.7/dist-packages/nanpy/serialmanager.py", line 98, in readline
raise SerialManagerError('Serial timeout!')
SerialManagerError: Serial timeout

The code I'm using is:
from nanpy import ArduinoApi
from nanpy import SerialManager

connection=SerialManager()
Arduino = ArduinoApi(connection=connection)

from time import sleep

LED =13
Arduino.pinMode(LED, Arduino.OUTPUT)

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

print"Finished"

I hope this is a know problem and someone knows the answer.

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Wed Mar 18, 2015 7:19 pm

The error message is telling you it hasn't seen the arduino. Is it plugged into the default USB port? You may have to use the connection in the same way as I did when I used the serial port. Otherwise, make sure your arduino is on port ttyama0.
RichR

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Wed Mar 18, 2015 7:24 pm

Hang on, I just reread your post! By running the simple sketch, you will have downloaded it to your arduino! It will have overwritten nanpy.
What is probably happening is that nanpy isn't responding. It isn't there.
Take a look at my diagram a few posts back.
RichR

hansltel
Posts: 5
Joined: Tue Mar 17, 2015 10:40 pm

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

Wed Mar 18, 2015 11:09 pm

Hi Rich, thanks for your reaction.

I saw your diagram. That's indeed the way I'm working.

I reloaded the nanpy.ino after the blink sketch. That can't be the problem.

The connection can't be the probem because a sketch worked via the Arduino Ide.

I tried to change to another usb port but here is happening a strange thing. When I look in the Arduino IDE I have three times the TTYACM0 and once the TTYACM1. After every change I restarted my RPI and the Arduino.

However it's still not workign and I can still use some advice.

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Thu Mar 19, 2015 2:30 pm

hansltel,
I haven't used the nanpy through usb, I went straight to the serial uart pins (through a level shifter). I had a lot of problems in the connection=conn area, guessing at what the code would need to look like. Hence my posts that included that TTYama0 port (the uart), to try to help anyone else using non-default ports... I am hoping some of the guys who do use usb may spot the issue....
I would guess that having the three TTYACM0 ports are due to you having a usb hub to power your arduino? I suspect the problem lies somewhere around here.
What version of Pi are you using (and which os), and which arduino model?
I have never seen proof that nanpy detects the port for you, tho' they say it does. I suspect that if you aren't on the default port for whatever reason, the nanpy python prog won't see it.
When the sketch gets downloaded to the arduino, what port does it say it is using?
RichR
p.s. although talking about earlier versions of nanpy, there is some relevant stuff in the early pages of this thread.

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

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

Thu Mar 19, 2015 3:07 pm

hansltel,
More thoughts: when you downoaded the nanpy sketch to the arduino, had you edited the cfg.h file? They changed this from 0.9.2 to 0.9.3 - so that where before everything was selected, now nothing is selected. You need to change nearly everything so that the 0 is a 1 at the end of the line.
Also, you noted you had to change the permissions of configure? Something isn't right there. I didn't need to do that. I used the user pi to download, and to run the sketch.
RichR

hansltel
Posts: 5
Joined: Tue Mar 17, 2015 10:40 pm

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

Thu Mar 19, 2015 10:32 pm

Hi Rich,

thanks again for you advice!!!!

The IDE uploads the sketches to TTYACM0. I'm using an external power supply for the Arduino because I want to control a step motor.

I'm using a RPI B+, Arduino Uno and Python 2.7.

I didn't change the cfg file. I'm very busy the comming days so I hope I'm able to try this in the weekend.

I will keep you informed!

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