Go Down

Topic: [Solved] Dragino Yun shield v2.3 and ttyATH0 "serial" connection (Read 265 times) previous topic - next topic

sqNick

Hi again :)
Im trying to connect linino and AVR leonardo in python program using Robin2 metod:

http://forum.arduino.cc/index.php?topic=319151

But have some problem with  "Resetting 32u4 on Yun"
Code: [Select]


def setupSerial(serPort, baudRate):


if GD.arduinoBoard == 'Leonardo':
print "Resetting Leonardo"
GD.ser = "x"
GD.ser = serial.Serial(serPort, 1200)
GD.ser.rtscts = True
time.sleep(0.5);
GD.ser.close();
print "Waiting 12 secs for Leonardo reset process to complete"
time.sleep(12);


if GD.arduinoBoard == 'Yun':
print "Resetting 32u4 on Yun"
fData = []
fData.append(["18",   "/sys/class/gpio/export"])             # make GPIO18 available
fData.append(["high", "/sys/class/gpio/gpio18/direction"])   # set pin 18 as output
fData.append(["1",    "/sys/class/gpio/gpio18/value"])       # Set pin 18 high
fData.append(["0",    "/sys/class/gpio/gpio18/value"])       # Set pin 18 low
fData.append(["18",   "/sys/class/gpio/unexport"])           # close out GPIO18

try:
for fd in fData:
with open(fd[1], "w") as f:
f.write(fd[0])
except Exception as Ex:
print "Exception "
print type(Ex)
sys.exit()
print "Waiting 2 secs for Yun reset process to complete"
time.sleep(2)


print "Trying to Open Serial Port"
GD.ser = "x"
GD.ser = serial.Serial(serPort, baudRate)
if GD.arduinoBoard != 'Yun':
GD.ser.rtscts = True # seems essential to guarantee a clean start
if GD.arduinoBoard == 'Other':
print "Waiting 10 secs for Uno reset process to complete"
time.sleep(10);
print "Serial port " + serPort + " opened  Baudrate " + str(baudRate)

waitForArduinoB()


I think that that the problem is dragino+Leonardo != Arduino Yun and becouse of that i cant reset the Leonardo...

i can run this program (SimpleDemo.py) in very strang solution and dont know why... and how can i fix it spending 2 days on it and need help ;/

to run it i must:
1. edit GD.arduinoBoard ="Leonardo"
2. run the python program (without succes)
3  reuploud the skech
4  edit GD.arduinoBoard ="Yun"
5  run the python program again and it works

I spend 2 days on... but dont know where i can find any info ;/
I think that the problem is restart Leonardo from pythom program of dragino shield but have no idea how to doo that...


ShapeShifter

I think that that the problem is dragino+Leonardo != Arduino Yun and becouse of that i cant reset the Leonardo...
Correct!

According to the Dragino web site:
Quote
Basically, Yun Shield + Leonardo equally to the official Arduino Yun
This is a bit of an oversimplification - a Yun Shield paired with a Leonardo has basically the same functionality as the official Yun, but they are not identical. There are some differences in the hardware, and in the software. That means that software that was written for the official Arduino Yun may run on the Yun Shield, or it may need modification if it runs into one of these differences. Resetting the '32U4 processor is one of those differences.

The official Yun has a script you can run from the command line to reset the '32U4 processor. It is at /usr/bin/reset-mcu and contains:
Code: [Select]
#!/bin/sh

echo 18 > /sys/class/gpio/export
echo "high" > /sys/class/gpio/gpio18/direction
echo 1 > /sys/class/gpio/gpio18/value
echo 0 > /sys/class/gpio/gpio18/value
echo 18 > /sys/class/gpio/unexport

Does this look familiar in the code you posted? What this is doing is setting up the Linux processor's GPIO18 as an output, and then pulsing the line high then low. This causes the '32U4 (and the sketch running on it) to reset.

On the official Yun, GPIO18 from the Atheros processor triggers the '32U4 reset. But looking at the Yun Shield schematics, Dragino chose instead to use GPIO20. On the Yun Shield, GPIO18 goes through a level shifter and becomes the SPI SCK signal - so this is a good hint that trying to use SPI on the Linux side to talk to the Leonardo will also not work without some changes (think downloading a new sketch using the Linux processor.)

You probably just need to change the GPIO references from 18 to 20 in your code to make it work. But to be sure, take a look if your Yun Shield has a similar reset_mcu script, and see what's inside it. You should be able to just insert that into your code above to make it work. (The best way to do it is create a new GD.arduinoBoard settings for 'Yun Shield'.)

sqNick

Men thx alot u 3rd time give me good advice... i found this file and do the changes and its restart my mcu now but its not the main problem i think ;/ because its still not working ;/ without this solution that i write upper ;/
I will write different scenario with trying to run this program:


1. edit GD.arduinoBoard ="Leonardo"
2. run the python program (without success)
3  reuploud the skech
4 edit GD.arduinoBoard ="Yun"
5 run the python program again and it works
6 exit(ctrl+c) try to run again - dont work
7  reuploud the skech -try tu run - dont work
8 edit GD.arduinoBoard ="Leonardo" -dont work
9 edit GD.arduinoBoard ="Yun" - dont work
10 reuploud the skech - dont work
11 edit GD.arduinoBoard ="Leonardo" -dont work
12 reuploud the skech -try to run and program stop with (IOError)
13 edit GD.arduinoBoard ="Yun" - Finaly WORKS...

in every scenario when i write "dont work" program try to send "<Python ready>" but cant read the back anser "<Arduino is ready>.

i think that when i try to run it with GD.arduinoBoard ="Leonardo" python must save some "IO scenario" or something like that... i dont understand it... and dont know what should i do ;/

ShapeShifter

This is the first time that I'm looking at Robin's code that you are trying to run, so I'm no expert on it. But it doesn't seem to make any sense to use anything other than "GD.arduinoBoard = "Yun" - anything else seems like a waste of time and effort.

It appears that GD.arduinoBoard is used by the Python setupSerial() function to determine how to reset the Arduino processor and set up the serial port. Knowing that Robin is intending to develop the Python code on a PC, and later run it on the Yun, helps figure out what he's trying to accomplish in that function:
  • GD.arduinoBoard = 'Leonardo' - This opens the serial port, asserts RTS/CTS, and closes the serial port.  When this sequence is performed on a USB serial port that is connected to the microUSB connector on a Leonardo (or official Yun board) that will cause the '32U4 processor that runs the sketch to reset. Note that even though the Yun Shield may be stacked on top of a Leonardo, it is not connected through the micro USB interface, so performing this operation on your board accomplishes nothing.
  • GD.arduinoBoard = 'Yun' - This sets up GPIO18 as an output from the Linux processor, and then pulses it high then low. This causes the Yun's '32U4 processor to reset. This code makes sense on an official Yun board, but not with a Yun Shield. Changing it to use GPIO20 should allow it work with your Yun Shield
  • GD.arduinoBoard = 'Other' - This skips both of the reset sequences above, and simply delays for 10 seconds to give you a change to manually press the target board's reset button.

The moral of the story here is that this definition is a way to specify the reset sequence of the Arduino board, and is intended to be changed when you are switching between running the Python code on a PC that is connected to the Arduino using a USB cable, or when running the code on the Linux processor of a Yun. It is not intended to indicate what type of board a Yun Shield might be stacked upon.

I don't understand your problem. Several times in this last post you state that it works. So what is the issue? It sounds like you are concerned that it doesn't work when GD.arduinoBoard is Leonardo? If that's the case, then don't worry about it - it's not supposed to work at that time.

So, set GD.arduinoBoard to Yun, and fix it to use GPIO20. Then leave it that way. Don't keep trying to go back and forth between settings unless you are switching between running the Python code on your PC and on the Yun Shield.

If you are still having other problems, please be a little clearer on what you are expecting to happen and what is actually happening.

sqNick

Thx for answer and sorry if i cant cleary specify my problem... This program works only on solution thats i typing upper. Its normaly dont work and im dont know why ;/


Quote
Several times in this last post you state that it works. So what is the issue? It sounds like you are concerned that it doesn't work when GD.arduinoBoard is Leonardo? If that's the case, then don't worry about it - it's not supposed to work at that time.
In sytuation if i have set the board as "Yun" and for exemple power up all(restart both processors) and try to run program its never works ;/

Im know that my eanglish is not good and i cant be vary clear but if u can pleas analise step 6.
Quote
5 run the python program again and it works
6 exit(ctrl+c) try to run again - dont work
Somthing that allow me run this program(read from serial in python) - is first try tu run it "as Leonardo"  reupload skech and run its "as Yun"- and its only way







sqNick

i back to older version of firmware - dragino2-yun-common-v2.0.7-squashfs-sysupgrade and everything is good :)


Go Up