4” display on arduino uno

Hi guys,
I have an arduino uno r3 with 4” display from waveshare (they have skematics on the website) I need one analog pin for a pressure sensor and 2 digital for 2 solenoid actuators. The analogs are not used by the display, but it seems all digital ones are used.

Obviously I’m new, and I try to learn while doing. I hope to find someone who can help me.
All the best!

You can use spare analog pins as digital pins (but not the other way round and not A6 or A7 on the Nano).
It is also not advisable to use D0 or D1 which are used by the serial port.
Post a link to the display you have purchased.

Thank you for helping!

Should I try to use d1 d2 for the solenoids and a1 for pressure?

I got a sketch with pressure and I want to display the value and status of each solenoid. For the solenoids I did a 12v circuit to power on proper voltage.

It is a bit difficult to be completely sure from all the scraps of documentation referred to by the link you supplied:

However, it looks like the display has two modes of operation, a parallel mode (uses lots of pins) or a Serial mode (uses only the standard SPI pins - Miso, mosi, clock and chip_select)

Anyway, you should divide the problem in two parts. Part 1 to get the display (and touch screen if you are using that) working. Aim to use SPI mode because it minimizes pin usage. Part 2 is getting the solenoid working.

Your schematic for the solenoids is drawn in a rather unconventional manner so I have only glanced over it. But in principle, you are controlling two 12 volt solenoids with 2 arduino digital pins and that is a straightforward task. Which software did you use, incidentally, to create the schematic ?:

Everycircuit on iPad. It doesn’t know mosfet (or I didn’t find it), therefore I detail the equivalent circuit.

Ok so what are you saying is that by properly selecting the dip switches I can free some pins. :slight_smile: I have no clue how to do that and I hope the examples work in that mode. I’ll try to get some sketches and see if is doable.
Thanks a lot again.

The dip switches are to the right at icsp I guess this means I only use the 6 icsp pins?

I don't see the DIP switches marked in the schematic, if this is the correct schematic, that is :

Can you find any more documentation ?

Pic is too big 2.3mb wait please

https://forum.arduino.cc/index.php?topic=548380.0

Waveshare 4” in arduino forum I’ll do some reading of that.

The picture makes it clearer. I was wrong about the parallel mode of operation. You don’t have access to that. The dip switches appear to be marked on the schematic as Header3x2. If the socket marked icsp on the screen matches up with the icsp header on the uno when the screen is plugged into the uno headers, then I don’t understand the purpose of dip switches.

You can see which pins are in use by matching connectors cn2,cn3,cn4 and cn5 to an Arduino Uno pinout. You can use the spare analog pins as digital pins as I said earlier. From a quick glance, it appears that all the analog pins and d0, D1 and d2 are free, which is as you said.

If you are not using the sd card or touch screen, you can free some more pins.

Step is to get the screen working with the supplied library. Can you provide a link to the solenoids?

I will send you the code too if you can help me. I modify lcd_show example from the display website.
Unfortunately for number display it shows integer only converted to a string. I wanted one digit too :(. Also I connected to A1 for a pressure sensor (5v 3 wires) and it doesn’t show the updates as it should) I will waste more time on this myself, if I can’t make it work I’ll ask for help :).

Post the code here, either between code tags or, if it is too big, as a file attachment.

The solenoid is 12v 14watt. You simply need an n-channel logic level mosfet e.g. FQP30N06L and a fly back diode e.g. 1n4007, a say 10k gate pull down resistor and a say 220 ohm gate series resistor. Also, of course, an adequate 12 volt power supply.

Show how you have wired the pressure sensor. You probably need 1 resistor for it so the pressure sensor and resistor form a potential divider with the analog pin at the mid point.

For pressure transducer I connected to A1, 5V, GRND, directly. Practically splitting those pins.
In the code I read the A1 then in loop I post the value calculated with an eq. From a webpage for similar sensor. The number display only show the integer part. I’ll send you the files and draw a diagram.
The solenoids should never work (open) at same time. Practically out-solenoid closed, pressurize up to a level then close in-solenoid, keep for 10 min, then out-solenoid open, keep for 10 min and repeat this cycle a number of times.
On the display I need pressure level, in- and out- solenoid status, cycle count i/n.

Hi,

I try to write this. 3 lines for pressure, solenoid-in, solenoid-out.
it runs but it shows only the integer part of the pressure. I don't think its sensing the pressure.
I connected, as I wrote before, 5v, grnd (next to the 5v), A1 to the pressure transducer. but I guess the display also use the 5 v.
when I run a test code with that equation (without display) I noted some changes in pressure, but not now.

beside this 3 lines, I want to be able to cycle few times (5) pressurizing, wait, depressurizing, wait and repeat.

I hope I get some guidance. thanks a lot.

pressure_Show.zip (35.5 KB)

The display content:
Current pressure: +8. Bar
In-solenoid: CLOSED
Out-solenoid: CLOSED

OP's code (.ino) :

#include "DEV_Config.h"
#include "LCD_Driver.h"
#include "LCD_GUI.h"

void setup()
{
  System_Init();
  Serial.begin(9600);
  Serial.println("4inch TFT Touch Shiled LCD Show...");  
  Serial.println("LCD Init...");
  LCD_SCAN_DIR Lcd_ScanDir = SCAN_DIR_DFT;  
  LCD_Init( Lcd_ScanDir, 100);
  char closed_stat='CLOSED';
  Serial.println("LCD_Clear...");
  LCD_Clear(LCD_BACKGROUND);

  Serial.println("LCD_Show...");
  GUI_Show();
}

void loop()
{
  int sensorVal=analogRead(A1);
  float voltage = (sensorVal*5.0)/1024.0;
  float pressure_bar = ((3.0*((float)voltage-0.45))*1000000.0)/10e5;
  if(pressure_bar<0)
  {
  GUI_DisString_EN(300, 80, "-", &Font20, LCD_BACKGROUND, BLACK);
  }
  else
  {
  GUI_DisString_EN(300, 80, "+", &Font20, LCD_BACKGROUND, BLACK);
  }
  Serial.println (pressure_bar);
  GUI_DisString_EN(315, 80, "   ", &Font20, LCD_BACKGROUND, BLACK);
  GUI_DisNum(315, 80, pressure_bar, &Font20, LCD_BACKGROUND, BLACK);
  GUI_DisString_EN(345, 80, ".", &Font20, LCD_BACKGROUND, BLACK);
  GUI_DisString_EN(360, 100, "CLOSED", &Font20, LCD_BACKGROUND, BLACK);
  GUI_DisString_EN(360, 120, "CLOSED", &Font20, LCD_BACKGROUND, BLACK);
}
/*********************************************************************************************************
  END FILE
*********************************************************************************************************/

Can you give a link to the pressure sensor and state how you are applying pressure to test it ?
This formula implies some significant pressures, if the device outputs anything like up to 5 volts:

float pressure_bar = ((3.0*((float)voltage-0.45))*1000000.0)/10e5;

what happens if you try this ?

float pressure_bar = 3.0*((float)voltage-0.45) ;  // 10e5 = 10 * 10^5 =  1,000,000

If you are simply testing the ability of your program to display a float, simply hard code the pressure at a reasonable value say 2.3456 ) to see what happens. By default, Serial.print displays floats to 2 decimal places.

I have a T-fitting with a classic pressure gauge on one side and the sensor on the other with a tube connected to a piston. I can load it and see the gauze needle moving nicely. I did that to calibrate the readings with the gauge. When I’m taking photos they are >2Mb and I can’t upload. I will try to download on my pc and edit to have smaller size and send it.

OK. I see the device. It is a 3 wire device and handles 1.2 MPa (12 bar).
The formula you used originally would reduce the resolution to give you effectively an integer result.

If you are still looking for a library for the screen, I decided to write one after I found the one supplied to be missing a few things, and quite slow.

Thank you MHotchin.
6v6gt any advice on the diodes you’re youse in the circuit?