Go Down

Topic: DUE reset with LCD screen (Read 339 times) previous topic - next topic

ribbonman

Nov 01, 2018, 12:48 am Last Edit: Nov 01, 2018, 12:51 am by ribbonman
Hi,
I added an LCD screen to my DUE project and have a problem with having to hit the reset button on power up to get the screen to show my coded buttons.

I added a resistor to the DUE when I first bought to alleviate this problem per numerous threads on google and on the forum and all has worked well for the past year until I added the screen.

The code runs without the screen but the buttons on the screen are going to add variables to the code to make it run different patterns.

Is there a way to code in a reset so I don't have to hit the reset button all the time?

Can I buy a DUE that doesn't have the problem of the added resistor?

Any help is appreciated.

This is the screen https://www.adafruit.com/product/1651
I have it using ICSP and pins 8,9,10

ard_newbie

#1
Nov 01, 2018, 06:07 am Last Edit: Nov 01, 2018, 06:47 am by ard_newbie
To access all pins when there is a shield above the DUE, there is the Mega Screw Shield (works for DUE too) at http://www.crossroadsfencing.com/BobuinoRev17/



BTW, a small capacitor betweeen the reset pin and a Gnd pin solves the issue.

ribbonman

To access all pins when there is a shield above the DUE, there is the Mega Screw Shield (works for DUE too) at http://www.crossroadsfencing.com/BobuinoRev17/



BTW, a small capacitor betweeen the reset pin and a Gnd pin solves the issue.
I do have a screw shield that I'm using, similar to this one but same functionality.

What size capacitor do you suggest?

I followed the resistor instructions from an extensive thread on this forum to get it to work the first time but didn't see anything about adding a capacitor, is there one for a capacitor?

Just asking because I'm pretty new to electronics.

Thanks for the help.



ribbonman

I updated my board with the resistor and capacitor and the LCD screen now comes up when power is turned on but now I have a hall sensor that keys all the movement of my steppers that doesn't seem to be working on power up.

I have to hit the reset button and hold it for a few seconds to get the controller to read the sensor for some reason.

In the serial window on startup the hall sensor(it counts turns) shows going to 1 because the magnet is off the sensor but doesn't count any more turns than that until I hit the reset button as explained above.

Anyone have any thoughts at where to look.

ard_newbie


Does the hall Sensor works properly if connected alone on the board ?

ribbonman

#7
Nov 08, 2018, 03:27 pm Last Edit: Nov 08, 2018, 05:09 pm by ribbonman
Does the hall Sensor works properly if connected alone on the board ?
It worked before I added the LCD screen & resistor/capacitor.

I uploaded a sketch without the code for the LCD screen and had to press the reset button after upload to get the controller to see the hall sensor, once reset is pressed it works properly. The same thing happens when I add the LCD screen, I have to hit reset for the hall sensor to work. I have 4 other hall sensors inputing to the controller that don't have a problem(they work on power up without any problems).

Adding the resistor and Capacitor allows the LCD screen to launch with no problems as it didn't before without a reset.

I also get a com error when trying to upload a sketch now, I connect the serial cable to upload and then I have to hit the reset button for a few seconds before I can upload a sketch.

ard_newbie


Post a full sketch with the "faulty" hall sensor alone.

ribbonman

#9
Nov 11, 2018, 10:31 pm Last Edit: Nov 11, 2018, 10:40 pm by ribbonman
I have bought an authentic Arduino.cc made in Italy and started to test it to see how it reacted to different sketches.

1. the new board doesn't have a problem with uploads, it erases itself and uploads a new sketch without        having to manually erase and reset before upload like the other board(I didn't have to manually erase old clone board before adding cap/resistor).

2. After uploading sketch or power on to the authentic board the LCD screen doesn't launch without pressing reset button.

3. I tried adding the resistor to T3 Mosfet to alleviate problem on LCD with authentic board and then had to do manual erase and reset to upload sketches from that point on and had to reset after power off/power on cycle.

4. I also tried the cap/resistor cure on the post you referenced earlier and ended with the same problems that the Mosfet cure had with uploads and power on's.

5. I also tried to flash the 16u2 on the old clone board but just kept getting verification errors and not sure if it flashed or not but symptoms persist still.

6. If I upload the blink without delay sketch on either board it always works after cycling the power on and off, so maybe my problem isn't with the boards.

I can upload the code but not sure exactly what you are looking for, I will add the code for the hall sensor without any screen or motor code which is what I think you are looking for.
Code: [Select]

int staplercounter = 0;
int staplercurrentState = 0;
int staplerpreviousState = 0;
int staplerSensor = 47;

void setup() {

  pinMode(staplerSensor, INPUT_PULLUP);
  Serial.begin(9600);

void loop() {

  counter();

staplercurrentState = digitalRead(staplerSensor);   //set state for movement

void counter() {
    staplercurrentState = digitalRead(staplerSensor);     //used to time all events
    if (staplercurrentState != staplerpreviousState) {    //check the count and add 1
      if (staplercurrentState == 1) {
        staplercounter = staplercounter + 1;
         Serial.println(staplercounter);
      }
    }
    staplerpreviousState = staplercurrentState;
  }


ribbonman

Here is the full code in case you have a question about how it is used.

Code: [Select]

#include <AccelStepper.h>
#include <SPI.h>
#include <Wire.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_STMPE610.h"

AccelStepper stapler(AccelStepper::DRIVER, 3, 4);
AccelStepper roserotate(AccelStepper::DRIVER, 12, 13);
AccelStepper gantry(AccelStepper::DRIVER, 5, 6);
AccelStepper carriage(AccelStepper::DRIVER, 7, 11);

// Default values for Adafruit shield v2.
#define STMPE_CS 8
#define TFT_DC 9
#define TFT_CS 10

Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

// Assign human-readable names to some common 16-bit color values:
#define   BLACK   0x0000
#define   BLUE    0x001F
#define   RED     0xF800
#define   GREEN   0x07E0
#define   CYAN    0x07FF
#define   MAGENTA 0xF81F
#define   YELLOW  0xFFE0
#define   WHITE   0xFFFF

#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000

// Rotations 0,2 = portrait  : 0->USB=right,upper : 2->USB=left,lower
// Rotations 1,3 = landscape : 1->USB=left,upper  : 3->USB=right,lower
byte rotation = 1; //(0->3)
const byte _numBtns = 3;

Adafruit_GFX_Button btn[_numBtns];
int btnColor[8] = {RED, GREEN, CYAN, BLUE, MAGENTA, YELLOW, WHITE, BLACK};

TS_Point p;
int x, y;

//VALUES FOR BUTTON
const int button = 2;            // pin button is on
int val = LOW;                     // current button state
int old_val = LOW;
int buttonstate = LOW;
unsigned long previousMillis;

//DELAY FOR LCD SCREEN
unsigned long previousmillis3;
const unsigned long pause = 300;


//VALUES FOR TURNING STAPLER 4 TURNS(using stapler hall Sensor) plus delay the start
int staplercounter = 0;
int staplercurrentState = 0;
int staplerpreviousState = 0;
int staplerSensor = 47;

//VALUE FOR PAUSING ROSETTE TURN
unsigned long previousMillis2;
const unsigned long interval = 210;

//VALUE FOR GANTRY MOVE
int gantryin = 46;
int gantryout = 43;
int gantryhome = 0;
int gantryfinish = 0;

//VALUE FOR CARRIAGE MOVE
int carriagebottom = 45;
int carriagetop = 44;
int carriagehome = 0;
int carriagefinish = 0;

//VALUES FOR VARIABLE STEPS
int start_steps = 0;
int staples = 0;

void setup() {
  pinMode(button, INPUT_PULLUP);
  pinMode(staplerSensor, INPUT_PULLUP);
  pinMode(gantryout, INPUT_PULLUP);
  pinMode(gantryin, INPUT_PULLUP);
  pinMode(carriagetop, INPUT_PULLUP);
  pinMode(carriagebottom, INPUT_PULLUP);

  Serial.begin(115200);

  tft.begin();
  ts.begin();
  if (!ts.begin()) {
    Serial.println("Couldn't start touchscreen controller");
    while (1);
  }
  tft.setRotation(rotation);
  tft.fillScreen(BLUE);
  // x coordinate of 100 doesn't seem right, but it works.
  btn[0].initButton( &tft, 75, 60, 100, 50, BLACK, btnColor[0], BLACK, "4", 2 );
  btn[0].drawButton(false);
  btn[1].initButton( &tft, 75, 130, 100, 50, BLACK, btnColor[1], BLACK, "5", 2 );
  btn[1].drawButton(false);
  btn[2].initButton( &tft, 75, 200, 100, 50, BLACK, btnColor[2], BLACK, "6", 2 );
  btn[2].drawButton(false);
 
  
  gantry.setMaxSpeed(10000.0);
  gantry.setAcceleration(15000.0);
  carriage.setMaxSpeed(10000.0);
  carriage.setAcceleration(15000.0);
  stapler.setMaxSpeed(10000.0);
  stapler.setAcceleration(10000.0);
  roserotate.setMaxSpeed(1000);
  roserotate.setAcceleration(1000);
  previousMillis = millis();
  previousMillis2 = millis();

  // Homing();

}

void loop() {
  /////VALUES FOR LCD SCREEN
  /////////////////////////////////////////////////////////////////////////////////
  if (!ts.bufferEmpty()) {
    p = ts.getPoint();
    switch (rotation) {
      case 0:
        x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
        y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
        break;
      case 1:
        // p.x, p.y reversed //
        x = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
        y = map(p.x, TS_MAXX, TS_MINX, 0, tft.height());
        break;
      case 2:
        x = map(p.x, TS_MAXX, TS_MINX, 0, tft.width());
        y = map(p.y, TS_MAXY, TS_MINY, 0, tft.height());
        break;
      case 3:
        // p.x, p.y reversed //
        x = map(p.y, TS_MAXY, TS_MINY, 0, tft.width());
        y = map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
        break;
      case 4:
        x = map(p.x, TS_MAXX, TS_MINX, 0, tft.width());
        y = map(p.y, TS_MAXY, TS_MINY, 0, tft.height());
        break;
      case 5:
        // p.x, p.y reversed //
        x = map(p.y, TS_MAXY, TS_MINY, 0, tft.width());
        y = map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
        break;
    }

    while (ts.touched()) {
      if (btn[0].contains(x, y)) {
        Serial.println("Button 1 hit.");
        invertBtn(0);
      }
      if (btn[1].contains(x, y)) {
        Serial.println("Button 2 hit.");
        invertBtn(1);
      }
      if (btn[2].contains(x, y)) {
        Serial.println("Button 3 hit.");
        invertBtn(2);
      }
    }
  }
  if (btn[0].contains(x, y)) {
    start_steps = 3;
    staples = 4;
  }
  else if (btn[1].contains(x, y)) {
    start_steps = 4;
    staples = 5;
  }
    else if (btn[2].contains(x, y)) {
    start_steps = 5;
    staples = 6;
  }
  /////////////////////////////////////////////////////////////////////////////////
  starter();
  counter();

  gantryhome = digitalRead(gantryin);
  gantryfinish = digitalRead(gantryout);
  carriagehome = digitalRead(carriagebottom);
  carriagefinish = digitalRead(carriagetop);
  staplercurrentState = digitalRead(staplerSensor);   //set state for movement

  if (buttonstate == HIGH && gantryhome == HIGH && staplercounter < start_steps) {

    gantry.move(50);                                 //move to sensor for stapling
    gantry.setSpeed(2500);
  }


  if (buttonstate == HIGH && carriagehome == HIGH && staplercounter < start_steps) {

    carriage.move(-50);                         //move to sensor for stapling
    carriage.setSpeed(2000);
  }


  if (buttonstate == HIGH && staplercounter >= 1) {

    if ( (millis() - previousMillis2) >= interval) {
      roserotate.move(-45);
      roserotate.setSpeed(700);
      previousMillis2 = millis();

      if (staplercounter >= staples) {
        roserotate.setSpeed(0);
      }
    }
  }

  if (buttonstate == HIGH && gantryhome == LOW) {
    stapler.setSpeed(-6000);
  }

  ///////////////////////////////////////////////////////////////////////////////

  if (staplercounter >= staples && gantryfinish == HIGH) {          //Slide gantry back to start position

    stapler.setSpeed(0);                      //turn stapler motor off

    gantry.moveTo(-50);
    gantry.setSpeed(2500);

    if (staplercounter >= staples && carriagefinish == HIGH) {          //Slide carriage back to start position

      carriage.moveTo(50);
      carriage.setSpeed(2000);


      buttonstate = LOW;                   //reset button
      staplercounter = 0;                    //reset counter for next button push
      staplercurrentState = 0;               //reset state for next button push
    }
  }
  stapler.runSpeed();
  gantry.runSpeedToPosition();
  carriage.runSpeedToPosition();
  roserotate.runSpeedToPosition();
}

void starter() {
  if ( (millis() - previousMillis) >= 50) {    //state machine for button & debounce
    val = digitalRead(button);
    if ((val == LOW) && (old_val == HIGH)) {
      buttonstate = HIGH;
    }
    previousMillis = millis();
    old_val = val;
    //Serial.println(buttonstate);
  }
}
void counter() {
  staplercurrentState = digitalRead(staplerSensor);     //used to time all events
  if (staplercurrentState != staplerpreviousState) {    //check the count and add 1
    if (staplercurrentState == 1) {
      staplercounter = staplercounter + 1;
      Serial.println(staplercounter);
    }
  }
  staplerpreviousState = staplercurrentState;
}
void Homing() {
  digitalRead(staplerSensor);

  if (staplerSensor == HIGH) {
    stapler.move(-5);
    stapler.setSpeed(100);
    staplercounter = 0;
  }
}
void invertBtn (byte btnHit) {
  btn[btnHit].drawButton(true);
  delay(300);
  // normal
  btn[btnHit].drawButton(false);
}


ribbonman

I think I got it figured out.

After deciding that maybe the problem wasn't with the Due I searched for LCD screen not launching with the due and found a thread on the forum discussing the issue. Some genius with electronics stated that the LCD screen needs more time to initialize than the controller allows it to do and put a delay at the top of the setup and see if that allows the screen to launch. I have tried that and it seems to have worked so I will continue to test it to make sure it is truly the fix for me.

Here's the thread Screen fix

ribbonman

That did the trick, set a delay(300) at the top of the setup and everything runs great without adding anything to the board.
Thanks for the help ard_newbie.

Go Up