0

Capacitive Touch Shield Arduino Yun Unable to Use Digital In
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Capacitive Touch Shield Arduino Yun Unable to Use Digital In

by ekwoodbrey on Thu Jul 25, 2019 11:43 pm

Think I might have run into a problem with the Capacitive Touchscreen library https://www.adafruit.com/product/1947 . I had it working with code running on the UNO without issue (including the beam break sensors https://www.adafruit.com/product/2168). I then moved to the YUN for ethernet support, which required me to jumper the 3 pads and cut the other 3 pads for SPI/ICSP. The display works correctly (touch as well) when just the display is connected to the YUN (with no additional connections). When I add an input to a digital pin (beam break sensor) the program fails to run (still uploads). As soon as I remove the beam break sensor inputs, it runs correctly. The beam break sensors work on the Yun as long as I only do tft.begin() and not additionally ts.begin(). I had the beam break sensors on pins 2 and 3 for both the Uno and then Yun.

ekwoodbrey
 
Posts: 10
Joined: Tue Nov 15, 2016 4:44 pm

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by adafruit_support_bill on Fri Jul 26, 2019 5:41 am

Please post some photos of your connections and jumper modifications. And also please post the code you are using.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by ekwoodbrey on Fri Jul 26, 2019 2:02 pm

I have commented out the touch portion of the code which is what is currently working (albeit no touch controls). Also, sorry about the messy code lol. Current connections:

TX - Bridge/Serial
RX - Bridge/Serial
2 - beambreakin
3 - beambreakout
4 - breambreakinled
5 - TFT backlight
6 - beambreakoutled
7 - relay
8 - NeoPixels
9 - TFT
10 - TFT
11 - TFT
12 - TFT
13 - TFT

A0 - BeamSenseInPin
A1 - BeamSenseOutPin
A2 - BeamSenseDetectPin
A3 - NC
A4 - NC

https://1drv.ms/u/s!Aj-jC988qcQokBNk-_f ... q?e=4mLrr0

Also, on a side note, are these displays able to run continuously (my display has faded). I was planning on ordering another one if I could get this to work and have it (turn off/cycle RGB at specific intervals). Thanks.

Code: Select all | TOGGLE FULL SIZE
#include "SPI.h"
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_FT6206.h"
#include <SPI.h>
//#include <SD.h>
#include <SharpIR.h>


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

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 8

#define NUM_LEDS 8

#define BRIGHTNESS 50

#define BeamSenseInPin A0
#define BeamSenseOutPin A1
#define BeamSenseDetectPin A2

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);

String readString;

Adafruit_FT6206 ts = Adafruit_FT6206();

#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);



//Time before door will close in seconds.  Normally 20
const int shortwait = 10;
//Time before door sensors shut down during closing cycle in seconds.  Normally 10
const int shortcountdown = 10;



//Close = 1
//Auto = 2
//Open = 3
int desired = 2;
//Light on/off
boolean lightstatus = true;
//light mode.  1 = white, 2 = red, 3 = green
int light = 1;
//Door open/closed.  If door is false, door is closed
boolean door = false;
//Tells if door is in closing cycle
boolean closing = false;
//Tells if door is closed
boolean closed = true;
//Pin numbers
const int relay = 7;
const int beambreakinled = 4;
const int beambreakoutled = 6;
//Times pet has gone through door
int count = 0;
//To keep count near right side of display
int countLength = -1;
//RFID accepted = True
boolean RFID = false;

boolean RGBMode = false;
int RGB = 1;


SharpIR BeamSenseIn(BeamSenseInPin, 430);
SharpIR BeamSenseOut(BeamSenseOutPin, 430);
SharpIR BeamSenseDetect(BeamSenseDetectPin, 20150);
int BeamSenseInState = 1000;
int BeamSenseOutState = 1000;
int BeamSenseDetectState = 1000;


long wait = shortwait * 1000;
long countdown = shortcountdown * 1000;

const int beambreakin = 2;
const int beambreakout = 3;
int beambreakinstate = 1;
int beambreakoutstate = 1;

void setup() {
  // put your setup code here, to run once:
//Console.begin(9600);


//Bridge.begin();


tft.begin();
tft.setRotation(1);
//ts.begin();
pinMode(relay, OUTPUT);
pinMode(beambreakinled, OUTPUT);
pinMode(beambreakoutled, OUTPUT);
pinMode(beambreakin, INPUT);
digitalWrite(beambreakin, HIGH);
pinMode(beambreakout, INPUT);
digitalWrite(beambreakout, HIGH);

Serial.println("Catdoor v3.0");


//pinMode(BeamSenseIn, INPUT);



resetBtn();
long wait = shortwait * 1000;
long countdown = shortcountdown * 1000;
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show();
}

void resetBtn()
{
tft.fillRect(0,0,320,240, ILI9341_BLACK);
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK);
//purple
tft.fillRect(0,0, 100, 40, 0xB476);
tft.fillRect(210, 80, 30, 10, 0xB476);
tft.fillRect(250, 80, 30, 10, 0xB476);
tft.fillRect(210, 100, 30, 5, 0xB476);
tft.fillRect(250, 100, 30, 10, 0xB476);
tft.setCursor(4, 9);
tft.println("Reset");
//blue
tft.fillRoundRect(0, 50, 100, 40, 14, 0x9CDF);
tft.fillRect(0, 50, 100, 20, 0x9CDF);
tft.fillRect(50, 70, 50, 20, 0x9CDF);
tft.fillRect(100, 80, 80, 10, 0x9CDF);
tft.setCursor(4, 59);
tft.println("Light");
//Red
tft.fillRoundRect(0, 100, 100, 40, 14, 0xBB2C);
tft.fillRect(50, 100, 50, 20, 0xBB2C);
tft.fillRect(0, 120, 100, 20, 0xBB2C);
tft.fillRect(100, 100, 80, 10, 0xBB2C);
tft.fillRect(290, 80, 30, 10, 0xBB2C);
tft.setCursor(4, 109);
tft.println("Close");
//yellow
tft.fillRect(0, 150, 100, 40, 0xECC6);
tft.fillRect(190, 80, 10, 10, 0xECC6);
tft.fillRect(190, 100, 10, 10, 0xECC6);
tft.fillRect(290, 100, 30, 10, 0xECC6);
tft.setCursor(14, 159);
tft.println("Auto");
//orange
tft.fillRect(0, 200, 100, 40, 0xE48D);
tft.setCursor(14, 209);
tft.println("Open");

if (desired == 1){
  closeBtn();
}
if (desired == 2){
  autoBtn();
}
if (desired == 3){
  openBtn();
}
lightBtn();


}


void RGBFunction(){
  switch(RGB){
    case 1:
    tft.fillRect(0,0,320,240, 0xF800);

    break;

    case 2:
    tft.fillRect(0,0,320,240, 0x07E0);

    break;

    case 3:
    tft.fillRect(0,0,320,240, 0x001F);

    break;

  }
 
  RGB++;
  if(RGB>3){
    RGB = 1;
  }
}



void lightBtn()
{
  if (lightstatus == false){
    tft.fillRoundRect(120, 20, 40, 40, 20, ILI9341_BLACK);
  }
  if (lightstatus == true){
    tft.fillRoundRect(120, 20, 40, 40, 20, 0xECC6);
  }
}

void closeBtn()
{
  tft.fillRect(120, 130, 180, 90, ILI9341_BLACK);
  tft.setTextSize(6);
  tft.setTextColor(0xECC6);
  tft.setCursor(125, 150);
  tft.println("Close");
}

void autoBtn()
{
  tft.fillRect(120, 130, 180, 90, ILI9341_BLACK);
  tft.setTextSize(6);
  tft.setTextColor(0xECC6);
  tft.setCursor(145, 150);
  tft.println("Auto");
}

void openBtn()
{
  tft.fillRect(120, 130, 180, 90, ILI9341_BLACK);
  tft.setTextSize(6);
  tft.setTextColor(0xECC6);
  tft.setCursor(145, 150);
  tft.println("Open");
}

void countDisplay()
{
  if (count > 9999){
    count = 1;
  }
  if (count <= 10){
    countLength = -1;
  }
  if (count >= 10){
    countLength = -2;
  }
  if (count >= 100){
    countLength = -3;
  }
  if (count >= 1000){
    countLength = -4;
  }
  //Serial.println(countLength);
  countLength = countLength * 32 + 300;
  //Serial.println(countLength);
  tft.setCursor(countLength, 20);
//  setTextWrap(false);
  tft.fillRect (160, 20, 160, 42, ILI9341_BLACK);
  tft.print(count);
 
}



void fullWhite() {

  if (lightstatus == true){
 
    for(uint16_t i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, strip.Color(0,0,0, 255 ) );
    }
      strip.show();
}
else if (lightstatus == false){
  fullDark();
}
}

void whiteGreen() {
 
    for(uint16_t i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, strip.Color(0,255,0, 128 ) );
    }
      strip.show();
}

void whiteRed() {
 
    for(uint16_t i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, strip.Color(255,0,0, 128 ) );
    }
      strip.show();
}

void fullDark() {
 
    for(uint16_t i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, strip.Color(0,0,0, 0 ) );
    }
      strip.show();
}





void loop() {
  // put your main code here, to run repeatedly:

/*
  if (ts.touched()){
    TS_Point p = ts.getPoint();
    //p.x = map(p.x, 0, 240, 240, 0);
    p.y = map(p.y, 0, 320, 320, 0);
    int y = p.x;
    int x = p.y;

    if(RGBMode == false){


      if (y <= 40 && x > 100 && x < 180){
        RGBMode = true;
      }






     
     
      if (x <= 100 && y <= 40){
      resetBtn();
      count = 0;
    }
    if (x <= 100 && y >= 50 && y <= 90){
     
      if (lightstatus == true){
        lightstatus = false;
      }
      else{
        lightstatus = true;
      }
      lightBtn();
      //Serial.println(lightstatus);
    }
    if (x <= 100 && y >= 100 && y <= 140){
      closeBtn();
      wait = shortwait * 1000;
      countdown = shortcountdown * 1000;
      desired = 1;
    }
    if (x <= 100 && y >= 150 && y <= 190){
      autoBtn();
      closed = false;
      desired = 2;
    }
    if (x <= 100 && y >= 200 && y <= 240){
      openBtn();
      wait = shortwait * 1000;
      countdown = shortcountdown * 1000;
      closed = false;
      desired = 3;
    }


     
    }
    else{
      RGBMode = false;
      resetBtn();   
    }
   

  }
 
 
 
  if(RGBMode == true){
    RGBFunction();
    }

*/

 


  BeamSenseInState = BeamSenseIn.distance();
  BeamSenseOutState = BeamSenseOut.distance();
  BeamSenseDetectState = BeamSenseDetect.distance();
  //Serial.println(BeamSenseInState);
  //Serial.println(BeamSenseOutState);
  //Serial.println(BeamSenseDetectState);

  if (BeamSenseInState < 0){
    BeamSenseInState = 1000;
  }
  if (BeamSenseOutState < 0){
    BeamSenseOutState = 1000;
  }
  if (BeamSenseDetectState < 0){
    BeamSenseDetectState = 1000;
  }

 


 


 




  if (closed == false){

  digitalWrite(beambreakinled, HIGH);
  delay(25);
  beambreakinstate = digitalRead(beambreakin);
  delay(25);
  digitalWrite(beambreakinled, LOW);

  //Serial.println("beambreakinled");
  //Serial.println(beambreakinstate);
 
 
  digitalWrite(beambreakoutled, HIGH);
  delay(25);
  beambreakoutstate = digitalRead(beambreakout);
  delay(25);
  digitalWrite(beambreakoutled, LOW);

  //Serial.println("beambreakoutled");
  //Serial.println(beambreakoutstate);

  }
  else{
    delay(100);
  }




      //while (Serial.available() > 0)
      //{
      //delay(3);
      //char c = Serial.read();
      //if (('0' <= c) && (c <= '~')){
      //readString += c;
      //}
      //}

      //if (readString != ""){
      //Serial.println(readString);
      //}

      //if (readString == "5FC6DD56007E30010000000000u" || readString == "6BB60E49729D30010000000000"){
      //  Serial.println("Success");
      //  RFID = true;
      //}
      //readString = "";






  //Opens Door
  if (desired == 3){
    //Serial.println("Open!");
    long wait = shortwait * 1000;
    long countdown = shortcountdown * 1000;
    digitalWrite(relay, HIGH);
    closed = false;
    closing = true;
    door = true;
    light = 1;
  }

  //Auto Door
  if (desired == 2){
  if (beambreakinstate == LOW || BeamSenseInState < 50 || BeamSenseDetectState < 100 || BeamSenseOutState < 26 || RFID == true || (beambreakoutstate == LOW && (closing == true || door == true))){
    wait = shortwait * 1000;
    countdown = shortcountdown * 1000;
    //Serial.println("Section 1");
    if (closing == true){
      digitalWrite(relay, HIGH);
      closed = false;
      light = 3;
    }
  }
  //Initial Door activation
  if (door == false && (beambreakinstate == LOW || BeamSenseInState < 50 || BeamSenseDetectState < 100 || BeamSenseOutState < 26  || RFID == true)){
    //Serial.println("Section 2");
    digitalWrite(relay, HIGH);
    door = true;
    closed = false;
    //Serial.println("Opening");
    light = 3;
  }
 
  else if (door == true && wait <= 0 && (beambreakinstate == HIGH || beambreakoutstate == HIGH)){
    digitalWrite(relay, LOW);
    //Serial.println("Section 3");
    //Serial.println("Closing Countdown");
    //Serial.println(countdown);
    closing = true;
    closed = false;
    countdown = countdown - 100;
    light = 2;
   
    if (countdown <= 0){
      //Serial.println("Section 4");
      door = false;
      closed = true;
      closing = false;
      wait = shortwait * 1000;
      countdown = shortcountdown * 1000;
      //Serial.println("Door Closed.  Desired = ");
      //Serial.println(desired);
      light = 1;
      count = count + 1;
      countDisplay();
    }
  }
  else if (door == true){
    //Serial.println("Section 5");
    wait = wait - 100;
    //Serial.println("Counting down");
    //Serial.println(wait);
    closed = false;
  }
  }







  //Close Door
  if (closed == false && desired == 1){
    if (beambreakinstate == LOW || BeamSenseInState < 50 || BeamSenseDetectState < 100 || BeamSenseOutState < 26  || RFID == true || (beambreakoutstate == LOW && (closing == true || door == true))){
    wait = shortwait * 1000;
    countdown = shortcountdown * 1000;
    if (closing == true){
      digitalWrite(relay, HIGH);
      closed = false;
      light = 3;
    }
  }
  if (door == false && (beambreakinstate == LOW || BeamSenseInState < 50 || BeamSenseDetectState < 100 || BeamSenseOutState < 26  || RFID == true)){
    digitalWrite(relay, HIGH);
    door = true;
    closed = false;
    //Serial.println("Opening");
    light = 3;
  }
  else if (door == true && wait <= 0 && (beambreakinstate == HIGH || beambreakoutstate == HIGH)){
    digitalWrite(relay, LOW);
    //Serial.println("Closing Countdown");
    //Serial.println(countdown);
    closing = true;
    closed = false;
    countdown = countdown - 100;
    light = 2;
   
    if (countdown <= 0){
      door = false;
      closed = true;
      closing = false;
      wait = shortwait * 1000;
      countdown = shortcountdown * 1000;
      //Serial.println("Door Closed.  Desired = ");
      //Serial.println(desired);
      light = 1;
    }
  }
  else if (door == true){
    wait = wait - 100;
    //Serial.println("Counting down");
    //Serial.println(wait);
    closed = false;
  }
  }


  switch (light) {
  case 1:
    fullWhite();
    break;
  case 2:
    whiteRed();
    break;
  case 3:
    whiteGreen();
    break;
  }


  RFID = false;

 
  if(BeamSenseInState < 50){
    Console.println("BeamSenseIn Activated");
    Console.println(BeamSenseInState);
  }
  if(BeamSenseDetectState < 100){
    Console.println("BeamSenseDetect Activated");
    Console.println(BeamSenseDetectState);
  }
  if(BeamSenseOutState < 26){
    Console.println("BeamSenseOut Activated");
    Console.println(BeamSenseOutState);
  }
 





}
Attachments
Catdoor6Yun.ino
(12.28 KiB) Downloaded 12 times
Last edited by adafruit_support_bill on Fri Jul 26, 2019 3:33 pm, edited 1 time in total.
Reason: Added code in-line

ekwoodbrey
 
Posts: 10
Joined: Tue Nov 15, 2016 4:44 pm

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by adafruit_support_bill on Fri Jul 26, 2019 3:40 pm

You have beam-break pins defined in two different ways:
First as analog pins
Code: Select all | TOGGLE FULL SIZE
#define BeamSenseInPin A0
#define BeamSenseOutPin A1
#define BeamSenseDetectPin A2

and then as digital pins
Code: Select all | TOGGLE FULL SIZE
const int beambreakin = 2;
const int beambreakout = 3;

You use the first set of definitions to initialize the Sharp library. And the second definition to set pin modes.

Which pins are you using?
And also please post a link to the specs for the sensor you are using. If this is a typical IR beam break sensor, you don't need to use that many pins to control it.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by ekwoodbrey on Fri Jul 26, 2019 3:45 pm

The 3 beam sense pins are for analog IR distance sensors and the 2 beambreak sensors are the digital beam break sensors. The 2 beam break sensors are next to the door frame so when the door is almost closed it will activate those. The 3 IR distance sensors are the main way to activate the opening sequence of the door from a distance (1 on the outside of the door and 2 on the inside).

Also, it was working on the UNO correctly, just not the Yun, due to the tsbegin(); part.

ekwoodbrey
 
Posts: 10
Joined: Tue Nov 15, 2016 4:44 pm

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by adafruit_support_bill on Fri Jul 26, 2019 4:00 pm

You may be looking at a memory problem. The Yun has slightly more SRAM than an UNO. But it also has substantially more overhead for the ethernet interface.
http://learn.adafruit.com/memories-of-an-arduino

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by ekwoodbrey on Fri Jul 26, 2019 4:04 pm

Hmm, does the IDE not show the storage and dynamic memory correctly if the Yun is selected, or is a baseline for a standard Arduino such as an UNO? At verification it shows that 93% of program storage space is used but only 36% of dynamic memory.

ekwoodbrey
 
Posts: 10
Joined: Tue Nov 15, 2016 4:44 pm

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by adafruit_support_bill on Fri Jul 26, 2019 4:25 pm

Hmm, does the IDE not show the storage and dynamic memory correctly

That number is misleading to say the least. By definition, since it is "dynamic" can't be captured in a single number. And what the IDE shows is only the static part of the dynamic memory allocation - i.e. global variables declared at file-scope.

Once you start running your code, the stack will definitely grow. And the heap will also grow if there is any dynamic memory allocation. Since you are dealing with displays and ethernet communication, there will be buffers.

https://learn.adafruit.com/memories-of- ... y#sram-5-5

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by ekwoodbrey on Fri Jul 26, 2019 4:41 pm

I have created a simple/small test program which is also unable to run when I uncomment the ts.begin(); function so I don't think it would be a memory issue in this case.

Code: Select all | TOGGLE FULL SIZE
#include "SPI.h"
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_FT6206.h"
#include <SPI.h>

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif


Adafruit_FT6206 ts = Adafruit_FT6206();

#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

const int beambreakin = 2;
const int beambreakout = 3;

int beambreakinstate = 1;
int beambreakoutstate = 1;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

 

  tft.begin();
  tft.setRotation(1);
  //ts.begin();

  pinMode(4, OUTPUT);
  pinMode(6, OUTPUT);

  digitalWrite(4, HIGH);
  digitalWrite(6, HIGH);

  pinMode(beambreakin, INPUT);
  pinMode(beambreakout, INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  beambreakinstate = digitalRead(beambreakin);
  beambreakoutstate = digitalRead(beambreakout);

  if (beambreakinstate == LOW){
    Serial.println("Beam Break In");
    }

  if (beambreakoutstate == LOW){
    Serial.println("Beam Break Out");
    }

    //if (ts.touched()){
    //  Serial.println("Touchscreen Activated");
    //}
    delay(100);
 

}
Attachments
AdafruitTSTest.ino
(1.16 KiB) Downloaded 11 times
Last edited by adafruit_support_bill on Sat Jul 27, 2019 7:38 am, edited 1 time in total.
Reason: Added code in-line

ekwoodbrey
 
Posts: 10
Joined: Tue Nov 15, 2016 4:44 pm

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by adafruit_support_bill on Sat Jul 27, 2019 8:18 am

The issue is a pin conflict with the i2c bus on the Yun. I2C on the Yun is pins D2 and D3. Calling begin on the touch screen calls wire.begin() - which initializes the i2c bus on pins 2 and 3.
https://store.arduino.cc/usa/arduino-yun

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by ekwoodbrey on Sat Jul 27, 2019 4:48 pm

Thanks! Just had to move those from digital 2 and 3 to analog pins (since all the rest of the digital ones were used) and everything is working correctly now.

ekwoodbrey
 
Posts: 10
Joined: Tue Nov 15, 2016 4:44 pm

Re: Capacitive Touch Shield Arduino Yun Unable to Use Digita

by adafruit_support_bill on Sat Jul 27, 2019 7:50 pm

Good to hear. Thanks for the follow-up.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.