Arduino uno sketches don't work on Arduino yun

I Made some skatches thath work fine o Arduino uno board but if i tre to ru them on my Arduino yun i get an error message or, in some cases, they start but they le ave some parts of the codes.
Some help?
Thanks in advance.

I haven't noticed this case, if you want to post your code perhaps the collective knowledge on this forum could help.

One thing that is different about the Yún is the assignment of I/O pins to ports. If the sketch address ports instead of digitalWrite(). etc. it could fail. Also the number of interrupts are different.

I don't completely understand the way a program can identify the processor. If you could write code:
if ( processorIsUno() )
do uno stuff
else if ( processorIsYún() )
do yún stuff
It would be great.

Anybody know how to processorIsYún()?

The processor type is handled by a compile time define, here is an example from Bridge.cpp

#ifdef __AVR_ATmega32U4__
// Leonardo variants (where HardwareSerial is Serial1)
SerialBridgeClass Bridge(Serial1);
#else
SerialBridgeClass Bridge(Serial);
#endif

This is done at compile time to keep gcc from barfing on code that is not appropriate for the architecture, for example using PORTA will cause problems if you try to compile for the Due.

Noblepepper, thanks. It looks like Leonardo and Yún have the same pinouts so that would work fine. I don't need to distinguish between the two boards. But I suppose that if one did, one could test

#idfef Bridge

Or something like that.

Well, the question was about processor so I only answered that, and yes the Leonardo and Yun use a 32U4. If you look at the output of the IDE when checking a sketch you can see all the defines which are:

-DF_CPU=16000000L -DARDUINO=155 -DARDUINO_AVR_YUN -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8041 -DUSB_MANUFACTURER= -DUSB_PRODUCT="Arduino Yun"

So if you want to know you have a Yun you would look for ARDUINO_AVR_YUN, actually checking this caused me to notice that AVR_ATmega32U4 is NOT defined at compile time, it must be buried somewhere in the header files (*.h). You can learn a lot by looking at how the libraries that come with the IDE do things.

In general, it seems a lot of people don't seem to realize that there are differences between the Uno (and Mega2560 for that matter) and the Yun, which is based on the Leonardo, using a different Atmel AVR CPU...

If people have problems getting things to run on a Yun that used to run (or are said to be running) on an Uno, they should always first check if there is any hint on getting the same stuff working on a Leonardo board. I think that would probably cut the amount of problems reported with the Yun in half... :wink:

Ralf