4” display on arduino uno

The circuit I described in post #11 already mentions 1N4007 diodes for flyback.
The mosfet is effectively a low side switch and must be specified as a logic level type.

Thanks that’s what I used. I soldered all parts for the 2 solenoids control. I added 2 leds for status. I’ll send a picture from my laptop.
I’ll check the new driver too and post my progress :). Once again thanks a lot.

MHotchin I installed the adafruit and your library. I get the test very nice.
Love your funny comments on this board :slight_smile:
I should have asked before.
still playing around with it to understand. the example for the better pressure gave me errors.

this is more or less what i want to do. i got 2 motor controllers 12V and a power 12v to 5v and they work perfect.
i try to write a code without the display. that equation is not cleaned up but i will once i get this working. then i will try to get data on a my display. im curious which are the exact pins necessary for the 4" display.

int solInRed = 3;
int solOutBlue = 2;
int delayHP= 100;
int intervalPressure=2.0; //MINUTES
int targetPressure=2.0; //PSI
int cyclesPressure=30; //REPEAT #
unsigned long SEC = 1000L;
unsigned long MIN = SEC * 60;

void setup() {
  Serial.begin(9600);              
  pinMode(solInRed, OUTPUT);
  pinMode(solOutBlue, OUTPUT);     
}
void loop()
 {
  int sensorVal=analogRead(A5);
  for(int i; i<cyclePressure+1; i++) 
  {
  float voltage = (sensorVal*5.0)/1024.0-0.47;
  float pressurePsi = ((3.0*((float)voltage-0.45))*1000000.0)/10e5*14.5038;
  Serial.println("Pressure = " + String(pressurePsi) + " psi");

  digitalWrite(solInRed, HIGH);
  Serial.println("RED ON");

  //monitor rise to pressurized level
  while(pressurePsi<targetPressure)
  {
  Serial.println("Pressure = " + String(pressurePsi) + " psi");
  }
  
  digitalWrite(solInRed, LOW);
  Serial.println("RED OFF");

  delay(intervalPressure * MIN);

  digitalWrite(solOutBlue, HIGH);
  Serial.println("BLUE ON");

  //monitor depressurize to atmospheric pressure
  while(pressurePsi=currentPressure)
  {
   for(int j; j<3; j++)
   {
   currentPressure=pressurePsi
   }
   Serial.println("Pressure = " + String(pressurePsi) + " psi");
  }
  
  digitalWrite(solOutBlue, LOW);
  Serial.println("BLUE OFF");
  
  delay(intervalPressure * MIN);
 }
}

horyup:
im curious which are the exact pins necessary for the 4" display.

In addition to the SDI pins, the shield uses:

	constexpr unsigned int LCD_CS = 10; //  LCD Chip Select
	constexpr unsigned int LCD_BL = 9;  //  LCD Backlight
	constexpr unsigned int LCD_RST = 8;  //  LCD Reset
	constexpr unsigned int LCD_DC = 7;  //  LCD Data/Control

	constexpr unsigned int TP_CS = 4;
	constexpr unsigned int TP_IRQ = 3;
	constexpr unsigned int TP_BUSY = 6;

	constexpr unsigned int SD_CS = 5;

So pins 3 through 10 inclusive. The code does NOT use TP_IRQ or TP_BUSY currently, but does set those pins to INPUT_PULLUP. I suspect those would be more useful if you needed to put the CPU into a sleep state and wake it in response to the touch screen.

On an UNO, 11,12 and 13 are used for SPI. So, not much available for other uses.

It also uses 5V, RST and GND from the power connector.

The Shield code does not use SD_CS, but exposes it so that the sketch writer can use it themselves to read the SD card.

I need 2 digital and one analog for the solenoids and the pressure sensor, respectively. So no chance to use the display? Can I use the 1 and 2? Is there any issue? Or I should switch to my arduino mega?

A Mega would be better if you think the project will grow in the future. That said, I think you can use the analog pins as digital, so you could go that route. The shield doesn't use any analog pins.

The biggest problem with this shield is that it covers everything on a Uno-sized board. A Mega leaves easy access to a lot of pins for experimenting. If you could find a Uno with no headers on it, you could add your own so that the analog pins come off the bottom of the board, or use right angle header pins for easy side access.

I've also seen Uno boards with an extra set of holes, so it has the headers but you can add extra connectors where needed.

I could solder the wires on the board and offer the support for the shield. So I can use 2 analogs for the solenoids? That would be great. I only need high/low. Thanks!

I use a0,2,4 extra pins soldered on the display shield. A4 for pressure, 0 for inlet solenoid and 2 for outlet.
I have a problem that the while loop (I tried do-while as well) don’t close the inlet. And I pressurize the system to more than the target. Restart. Is too much pressure so I see inlet on then off and then outlet on which remain opened not detecting with the loop that is to be closed after depressurization happened. Is clearly my miss understanding of the conditional loop events. Please be kind and help. I’m close :)) thanks

/*
 Name:    pressure.ino
 Created: 2020-02-15
 Author:  Horia
 Thanks to 6v6gt and MHotchin using Waveshare4InchTftShield
*/
unsigned long intervalPressure=0.8; //MINUTES
unsigned long targetPressure=20.0; //PSI
float ressurePsi=0.0;
int cyclesPressure=3.0; //REPEAT #
int i=0;
unsigned long SEC = 1000L;
unsigned long MIN = SEC * 60;
unsigned long currentPressure=0;
#include <Arduino.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Waveshare4InchTftShield.h>
// 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
namespace
{
  Waveshare4InchTftShield Waveshield;
  //  Provide an alias so I don't have to search-and-replace all the code below.
  Adafruit_GFX &tft = Waveshield;
  //  This is all copied from the original 'Waveshare _ILI9486' project.
  unsigned long testFillScreen();
  unsigned long testText();
  unsigned long testLines(uint16_t color);
  unsigned long testFastLines(uint16_t color1, uint16_t color2);
  unsigned long testRects(uint16_t color);
  unsigned long testFilledRects(uint16_t color1, uint16_t color2);
  unsigned long testFilledCircles(uint8_t radius, uint16_t color);
  unsigned long testCircles(uint8_t radius, uint16_t color);
  unsigned long testTriangles();
  unsigned long testFilledTriangles();
  unsigned long testRoundRects();
  unsigned long testFilledRoundRects();
  uint16_t color565(uint8_t r, uint8_t g, uint8_t b)
  {
    return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3);
  }
}

void setup() {
  Serial.begin(9600);
  while (!Serial);
  SPI.begin();
  Waveshield.begin();
  tft.setRotation(4);
  tft.setTextSize(2);
  tft.fillScreen(WHITE);
  tft.setTextColor(BLACK);
          
  pinMode(A0, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A4, INPUT);
}
void loop()
 {
  int sensorVal=analogRead(A4);
  for(i; i<3; i++) 
  {
  tft.setTextColor(BLACK);
  tft.println("Cycle no. = " + String(i+1) + " of " + cyclesPressure);
  int sensorVal=analogRead(A4);
  float voltage = (sensorVal*5.0)/1024.0;
  float pressurePsi = (((3.0*((float)voltage-0.47))*1000000.0)/10e5)*14.5038;
  tft.println("Pressure = " + String(pressurePsi) + " psi");

  digitalWrite(A0, HIGH);
  tft.setTextColor(RED);
  tft.println("RED ON");
  
  //monitor rise to pressurized level
  do {
   delay(50);
  int sensorVal=analogRead(A4);
  float voltage = (sensorVal*5.0)/1024.0;
  float pressurePsi = (((3.0*((float)voltage-0.47))*1000000.0)/10e5)*14.5038;
  } while(pressurePsi < targetPressure);
  
  digitalWrite(A0, LOW);
  tft.println("RED OFF");

  delay(intervalPressure * MIN);

  digitalWrite(A2, HIGH);
  tft.setTextColor(BLUE);
  tft.println("BLUE ON");
  
  //monitor depressurize to atmospheric pressure
   //>=
  do {
   for(int j; j<3; j++)
      {
       int sensorVal=analogRead(A4);
       float voltage = (sensorVal*5.0)/1024.0;
       float pressurePsi = (((3.0*((float)voltage-0.47))*1000000.0)/10e5)*14.5038;
       currentPressure=pressurePsi;
       delay(50);
      }
  } while(pressurePsi >= currentPressure);
  
  digitalWrite(A2, LOW);
  tft.println("BLUE OFF");
  
  delay(intervalPressure * MIN);
 }
}

It worked like a charm!!! Thanks guys!!! I leaned a lot. I will try to learn more by doing the GUI and maybe touchscreen for setting up parameters.