Yun: read all pins

Hi, I’m attempting to read all the digital inputs on the Yun. I am having no luck finding a way to pin map on the YUN. Below is the working code for the UNO (you all helped me out tremendously):

String Select;
String readString;

byte portB;
byte portD;
int portBD;

  
void setup() 
    {
      Serial.begin(9600);
      DDRD = B00000000; //2-7 inputs
      
      while (!Serial)
          {; // wait for serial port to connect. Needed for native USB port only
          }
      
    }
  

void loop() {


portBD = ( ( (uint16_t)(PINB & 0b00111111) <<8) | (uint16_t)(PIND & 0b11111100) ) >>2;
    
    switch (portBD) 
        {
        case 1793: Serial.println(Select); break;
        case 1794: Serial.println(Select); break;
        case 1796: Serial.println(Select); break;
        case 1800: Serial.println(Select); break;
        case 1808: Serial.println(Select); break;
        case 1824: Serial.println(Select); break;
        case 1856: Serial.println(Select); break;
        case 1920: Serial.println(Select); break;
        case 4001: Serial.println(Select); break;
        case 4002: Serial.println(Select); break;
        case 3840: Serial.println(Select); break;
        case 4003: Serial.println(Select); break;
        case 4004: Serial.println(Select); break;
        case 4005: Serial.println(Select); break;

        default: Serial.println(portBD); break;
        }
}

Would you be able to help out?

Thank you very much!

Which is EXACTLY why I always tell people to use the standard digitalWrite() and digitalRead() functions. You’ve got some very smart code there, which is tightly coupled to the exact processor you were using. Now you have a different processor and all the things you “learned” doing that are now useless.

If you learn digitalWrite() and its friends, then your code will work on all Arduinos and a huge variety of Arduino-like processors. A Teensy, ESP8266, whatever - they all work with the standard functions.

Hi, I’m attempting to read all the digital inputs on the Yun.

That statement makes no sense. You don’t ever want to read “all the inputs”. Some inputs aren’t connected to pins on the board. Some inputs are used for other purposes like serial communications. Some can be used in some special modes, like external-clock mode and they don’t make any sense in normal mode. Reset can also sometimes be used as an input.

First define what inputs you really want:

#define NUM_INPUTS 18
const int InputsToRead[NUM_INPUTS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, A0, A1, A2, A3, A4, A5, A6}

Then you have an array that you can easily iterate to cover all the required inputs. If things get rearranged in the next version of the hardware - like you swap pins 2 and 12, then just swap them in this array and the rest of the code doesn’t know there is a difference.

Isn't the Arduino side of the Yun the same as a Leonardo?

...R

I’m attempting to use read the input of every pin with the method proposed.

#include <Bridge.h>
#include <Console.h>
#include <BridgeClient.h>
#include <BridgeServer.h>
#include <SPI.h>

// Initialize the client library
BridgeClient client;

const int inputRead[INPUTS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, A0, A1, A2, A3, A4, A5, A6};
                                           //{0, 1, 2, 3, 4, 5, 6, 7,   8,  9,  10, 11, 12, 13, 14, 15, 16, 17};

void loop
{
while (digitalRead(inputRead[5]) == HIGH)
  {select = array[10]; Serial.println(select);}

}

I have the same while loop for all the other pins that work fine, but with pin7 once set to HIGH, stays high indefinitely.

Is pin7 being used in a similar fashion as pin 0 and pin 1? I can’t seem to us all the available pins as inputs as I had hoped to.

Thank you for your help.

I believe I found out why... pin7 is passing data between AR9331 mega32u4...

My project requires 18 p ins but it seems the maximum i/o pins you can use while utilizing bridge library and serial monitor is 17. I'll attempt to not use the serial monitor, maybe I can squeeze one more input.

cheelo007:
I believe I found out why... pin7 is passing data between AR9331 mega32u4...

Perhaps if you had asked your question in the Yun section of the Forum someone would have told you that immediately.

You can click Report to Moderator and ask to have your Thread moved.

...R