Fuelab Prodigy Series Pump and Driver via Arduino

Discussion in 'Automotive Electronics' started by rennie1080, Jul 31, 2018.

  1. rennie1080

    Thread Starter Member

    Apr 10, 2017
    37
    0
    Ron , thank you so much, I add oil pressure sensor, flowmeter to the system. I will share the results.
     
  2. Reloadron

    Distinguished Member

    Jan 15, 2015
    3,280
    1,449
    Thanks and I would be curious.

    Ron
     
  3. rennie1080

    Thread Starter Member

    Apr 10, 2017
    37
    0
    Ron, by the way the flowmeter I will add ( macnaught mx12s-2b ) series. Its sensor type is open collector npn hall effect sensor. Macnaught Mx12s-2sb . open collector npn term is confused me. Can I write code for this flowmeter as like normal hall effect sensor ? After it count the flow, I want to reset the counts info on lcd by using a button. How should I wire button ? ( analog input for button is suitable ? )
    upload_2018-8-3_11-11-24.png
     
  4. Reloadron

    Distinguished Member

    Jan 15, 2015
    3,280
    1,449
    If you look at your data sheet you will see pin 1 is your + supply voltage, pin 2 is unused, pin 3 is your common and pin 4 is your Vout pulses. Note how pin 4 has a 3.3 K Ohm resistor tied to it. Open collector simply put means you get your out pulses off pin 4 and pin 4 is tied to power through a 3.3 K resistor. Just means the internal output circuit is a NPN transistor with the collector open so we place a resistor on that collector to generate our signal out pulses. You want to try powering it with 5 Volts so we get usable pulses for your Arduino.

    You also want to take note of the K-Factor which is 423.97 Pulses/Gallon, so each gallon passing through the sensor will produce 423.94 pulses or about 424 pulses. This is a pretty good tutorial using an Arduino to measure flow rate. In the example their K-Factor is 450 pulses per liter where yours will be 424 pulses per gallon. Take note of how the math functions work. Also, they went with a 10 K collector resistor which is more typical of what I would use but the 3.3 K suggested by the flow meter manufacturer should work fine.

    I have a few things going today but I'll try and run the code later and see what I get. I'll just simulate a flow meter into an Arduino Uno.

    Ron
     
  5. rennie1080

    Thread Starter Member

    Apr 10, 2017
    37
    0
    What do you think about this code ? There is flow and total flow. But I want to reset total flow by using push button . How I should do that ?


    Code (C):
    1. // initialize LCD lib with I2C serial communication protocol
    2. #include <Wire.h> //I2C lib
    3. #include <LCD.h>
    4. #include <LiquidCrystal_I2C.h>
    5. // LCD lib
    6. LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
    7.  
    8. int pot_pin = A0;
    9. int pump_pwm= 3;
    10.  
    11. int press_pin =A1;
    12.  
    13. int flowPin = 2;  //This is the input pin on the Arduino
    14.  
    15. double flowRate;    //This is the value we intend to calculate.
    16. double totalFlowRate;
    17. volatile int count; //This integer needs to be set as volatile to ensure it updates correctly during the interrupt process.
    18.  
    19.  
    20. int pot_init= 0;
    21. int pump_init= 0;
    22. int percentValue =0;
    23.  
    24.  
    25.  
    26. void setup() {
    27.  
    28.  
    29.   lcd.begin(20,4);  // A4 - A5 connection SDA - SCL
    30.   lcd.backlight();
    31.   pinMode(flowPin, INPUT);           //Sets the pin as an input
    32.   attachInterrupt(0, Flow, RISING);  //Configures interrupt 0 (pin 2 on the Arduino Nano) to run the function "Flow"
    33.  
    34.   Serial.begin(9600);
    35. }
    36.  
    37. void loop() {
    38. pressure_cal();
    39. pump_control();
    40. flow_control();
    41.  
    42.  
    43. }
    44.  
    45. void pressure_cal(void) {
    46.  
    47. float sensorVoltage = analogRead(press_pin);   // sensor voltage A0
    48. float psi = ((sensorVoltage-102)/204)*25;  // Offset    0 PSI= 0.5V=102 unit, 50 PSI= 2.5, 100 PSI= 4.5V, 1 PSI= 0.04V , +-0.4PSI approax. sensitivity
    49. // calibration
    50. float bar = psi*(0.0689475729);           // Conversion PSI to BAR
    51.  
    52. if(psi < 0)
    53.     psi = 0;
    54.  
    55.     if(bar<0);
    56.     bar=0;
    57. lcd.setCursor (0,2);
    58. lcd.print (psi);
    59. lcd.print (" PSI");
    60.  
    61. lcd.setCursor ( 0,3);
    62. lcd.print(bar);
    63. lcd.print( " BAR");
    64.  
    65. lcd.setCursor(0,1);
    66. lcd.print(sensorVoltage);
    67.  
    68. Serial.println (sensorVoltage);
    69. Serial.println(bar);
    70. Serial.println (psi);
    71.  
    72. delay (100);
    73. }
    74.  
    75. void pump_control(void)
    76.  
    77. {
    78. // read the analog in value:
    79.   pot_init = analogRead(pot_pin);
    80.   // map it to the range of the analog out:
    81.   pump_init = map(pot_init, 0, 1023, 0, 255);  //  Duty cycle between %20 - %90: speed control , duty cycle between %0 - %20: turned off  , duty cycle between %90 - %100: full speed
    82.   // map pump speed percent of full scale
    83.   percentValue = map (pump_init, 0, 255,0,100);
    84.   // change the analog out value:
    85.   analogWrite(pump_pwm, pump_init);
    86.  
    87.   // print the results to the Serial Monitor:
    88.   Serial.print("\t Speed Input = ");
    89.   Serial.print(pot_init);
    90.   Serial.print("\t Speed Output = ");
    91.   Serial.print(pump_init);
    92.   Serial.print("\t Pump Speed Percentage = ");
    93.   Serial.println(percentValue);
    94.   lcd.setCursor(0,0);        
    95.   lcd.print("Speed: ");
    96.   lcd.setCursor(8,0);        
    97.   lcd.print("%");        
    98. lcd.setCursor(9,0);        
    99. lcd.print(percentValue);        
    100.  
    101. //  delay after the last reading:
    102.   delay(2);
    103.  
    104. }
    105.  
    106.   void flow_control(void)  {
    107.  
    108.   count = 0;      // Reset the counter so we start counting from 0 again
    109.   interrupts();   //Enables interrupts on the Arduino
    110.   delay (1000);   //Wait 1 second
    111.   noInterrupts(); //Disable the interrupts on the Arduino
    112.   //Start the math
    113.   flowRate = (count * 2.36);        //Take counted pulses in the last second and multiply by 2.25mL
    114.   flowRate = flowRate * 60;         //Convert seconds to minutes, giving you mL / Minute
    115.   flowRate = flowRate / 1000;       //Convert mL to Liters, giving you Liters / Minute
    116.   totalFlowRate += flowRate;   // Add the liters passed in  second to the cumulative total
    117.  
    118.   Serial.println(flowRate);         //Print the variable flowRate to Serial
    119. lcd.setCursor(0,4);        
    120.   lcd.print("F: ");  
    121.    lcd.setCursor(3,4);      
    122. lcd.print(flowRate);
    123.    lcd.setCursor(8,4);      
    124.   lcd.print("lt/m");
    125.  
    126. lcd.setCursor(13,4);
    127. lcd.print("TF:");
    128. lcd.setCursor(16,4);
    129. lcd.print(totalFlowRate);
    130.  
    131. }
    132.  
    133. void Flow()
    134. {
    135.    count++; //Every time this function is called, increment "count" by 1
    136. }
    Moderators note : used code tags
     
  6. rennie1080

    Thread Starter Member

    Apr 10, 2017
    37
    0
    By the way, I will change the calculation for flow I have made a mistake because of 1/liter.

    flowRate = ( count * 8.93 ) ;
     
    Last edited: Aug 5, 2018
  7. Reloadron

    Distinguished Member

    Jan 15, 2015
    3,280
    1,449
    Before I forget when looking at flow you have a rate and the other is totalizer, so you have a rate mode and a totalizer mode.

    I am not an Arduino type but am a little familiar with them. I am not sure about how many functions you can get in that when measuring flow we use an interrupt which my understanding will slow things down. I am just not sure how well it will go.

    As to the code I can't get it to compile, have you gotten this code to compile? I am trying on an Arduino Uno board.

    Ron
     
  8. rennie1080

    Thread Starter Member

    Apr 10, 2017
    37
    0
    I sent wrong worng ( uncompleted alternative code ). I am adding the code you can try these. I can compile them with nano.

    Code (C):
    1.  
    2. // initialize LCD lib with I2C serial communication protocol
    3. #include <Wire.h> //I2C lib
    4. #include <LCD.h>
    5. #include <LiquidCrystal_I2C.h>
    6. // LCD lib
    7. LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
    8.  
    9. int pot_pin = A0;
    10. int pump_pwm= 3;
    11.  
    12. int press_pin =A1;
    13.  
    14. int flowPin = 2;  //This is the input pin on the Arduino
    15.  
    16. double flowRate;    //This is the value we intend to calculate.
    17. double totalFlowRate;
    18. volatile int count; //This integer needs to be set as volatile to ensure it updates correctly during the interrupt process.
    19.  
    20.  
    21. int pot_init= 0;
    22. int pump_init= 0;
    23. int percentValue =0;
    24.  
    25.  
    26.  
    27. void setup() {
    28.  
    29.  
    30.   lcd.begin(20,4);  // A4 - A5 connection SDA - SCL
    31.   lcd.backlight();
    32.   pinMode(flowPin, INPUT);           //Sets the pin as an input
    33.   attachInterrupt(0, Flow, RISING);  //Configures interrupt 0 (pin 2 on the Arduino Nano) to run the function "Flow"
    34.  
    35.   Serial.begin(9600);
    36. }
    37.  
    38. void loop() {
    39. pressure_cal();
    40. pump_control();
    41. flow_control();
    42.  
    43.  
    44. }
    45.  
    46. void pressure_cal(void) {
    47.  
    48. float sensorVoltage = analogRead(press_pin);   // sensor voltage A0
    49. float psi = ((sensorVoltage-102)/204)*25;  // Offset    0 PSI= 0.5V=102 unit, 50 PSI= 2.5, 100 PSI= 4.5V, 1 PSI= 0.04V , +-0.4PSI approax. sensitivity
    50. // calibration
    51. float bar = psi*(0.0689475729);           // Conversion PSI to BAR
    52.  
    53. if(psi < 0)
    54.     psi = 0;
    55.  
    56.     if(bar<0);
    57.     bar=0;
    58. lcd.setCursor (0,2);
    59. lcd.print (psi);
    60. lcd.print (" PSI");
    61.  
    62. lcd.setCursor ( 0,3);
    63. lcd.print(bar);
    64. lcd.print( " BAR");
    65.  
    66. lcd.setCursor(0,1);
    67. lcd.print(sensorVoltage);
    68.  
    69. Serial.println (sensorVoltage);
    70. Serial.println(bar);
    71. Serial.println (psi);
    72.  
    73. delay (100);
    74. }
    75.  
    76. void pump_control(void)
    77.  
    78. {
    79. // read the analog in value:
    80.   pot_init = analogRead(pot_pin);
    81.   // map it to the range of the analog out:
    82.   pump_init = map(pot_init, 0, 1023, 0, 255);  //  Duty cycle between %20 - %90: speed control , duty cycle between %0 - %20: turned off  , duty cycle between %90 - %100: full speed
    83.   // map pump speed percent of full scale
    84.   percentValue = map (pump_init, 0, 255,0,100);
    85.   // change the analog out value:
    86.   analogWrite(pump_pwm, pump_init);
    87.  
    88.   // print the results to the Serial Monitor:
    89.   Serial.print("\t Speed Input = ");
    90.   Serial.print(pot_init);
    91.   Serial.print("\t Speed Output = ");
    92.   Serial.print(pump_init);
    93.   Serial.print("\t Pump Speed Percentage = ");
    94.   Serial.println(percentValue);
    95.   lcd.setCursor(0,0);    
    96.   lcd.print("Speed: ");
    97.   lcd.setCursor(8,0);    
    98.   lcd.print("%");    
    99. lcd.setCursor(9,0);    
    100. lcd.print(percentValue);    
    101.  
    102. //  delay after the last reading:
    103.   delay(2);
    104.  
    105. }
    106.  
    107.   void flow_control(void)  {
    108.  
    109.   count = 0;      // Reset the counter so we start counting from 0 again
    110.   interrupts();   //Enables interrupts on the Arduino
    111.   delay (1000);   //Wait 1 second
    112.   noInterrupts(); //Disable the interrupts on the Arduino
    113.   //Start the math
    114.   flowRate = (count * 2.36);        //Take counted pulses in the last second and multiply by 2.25mL
    115.   flowRate = flowRate * 60;         //Convert seconds to minutes, giving you mL / Minute
    116.   flowRate = flowRate / 1000;       //Convert mL to Liters, giving you Liters / Minute
    117.   totalFlowRate += flowRate;   // Add the liters passed in  second to the cumulative total
    118.  
    119.   Serial.println(flowRate);         //Print the variable flowRate to Serial
    120. lcd.setCursor(0,4);    
    121.   lcd.print("F: ");
    122.    lcd.setCursor(3,4);  
    123. lcd.print(flowRate);
    124.    lcd.setCursor(8,4);  
    125.   lcd.print("lt/m");
    126.  
    127. lcd.setCursor(13,4);
    128. lcd.print("TF:");
    129. lcd.setCursor(16,4);
    130. lcd.print(totalFlowRate);
    131.  
    132. }
    133.  
    134. void Flow()
    135. {
    136.    count++; //Every time this function is called, increment "count" by 1
    137. }
    138.  
    I omit the LCD commands for second code. Maybe the reason why it couldnt compile is because of missing library.

    Code (C):
    1.  
    2. // initialize LCD lib with I2C serial communication protocol
    3. #include <Wire.h> //I2C lib
    4.  
    5.  
    6. int pot_pin = A0;
    7. int pump_pwm= 3;
    8.  
    9. int press_pin =A1;
    10.  
    11. int flowPin = 2;  //This is the input pin on the Arduino
    12.  
    13. double flowRate;    //This is the value we intend to calculate.
    14. double totalFlowRate;
    15. volatile int count; //This integer needs to be set as volatile to ensure it updates correctly during the interrupt process.
    16.  
    17.  
    18. int pot_init= 0;
    19. int pump_init= 0;
    20. int percentValue =0;
    21.  
    22.  
    23.  
    24. void setup() {
    25.  
    26.  
    27.   pinMode(flowPin, INPUT);           //Sets the pin as an input
    28.   attachInterrupt(0, Flow, RISING);  //Configures interrupt 0 (pin 2 on the Arduino Nano) to run the function "Flow"
    29.  
    30.   Serial.begin(9600);
    31. }
    32.  
    33. void loop() {
    34. pressure_cal();
    35. pump_control();
    36. flow_control();
    37.  
    38.  
    39. }
    40.  
    41. void pressure_cal(void) {
    42.  
    43. float sensorVoltage = analogRead(press_pin);   // sensor voltage A0
    44. float psi = ((sensorVoltage-102)/204)*25;  // Offset    0 PSI= 0.5V=102 unit, 50 PSI= 2.5, 100 PSI= 4.5V, 1 PSI= 0.04V , +-0.4PSI approax. sensitivity
    45. // calibration
    46. float bar = psi*(0.0689475729);           // Conversion PSI to BAR
    47.  
    48. if(psi < 0)
    49.     psi = 0;
    50.  
    51.     if(bar<0);
    52.     bar=0;
    53.  
    54. Serial.println (sensorVoltage);
    55. Serial.println(bar);
    56. Serial.println (psi);
    57.  
    58. delay (100);
    59. }
    60.  
    61. void pump_control(void)
    62.  
    63. {
    64. // read the analog in value:
    65.   pot_init = analogRead(pot_pin);
    66.   // map it to the range of the analog out:
    67.   pump_init = map(pot_init, 0, 1023, 0, 255);  //  Duty cycle between %20 - %90: speed control , duty cycle between %0 - %20: turned off  , duty cycle between %90 - %100: full speed
    68.   // map pump speed percent of full scale
    69.   percentValue = map (pump_init, 0, 255,0,100);
    70.   // change the analog out value:
    71.   analogWrite(pump_pwm, pump_init);
    72.  
    73.   // print the results to the Serial Monitor:
    74.   Serial.print("\t Speed Input = ");
    75.   Serial.print(pot_init);
    76.   Serial.print("\t Speed Output = ");
    77.   Serial.print(pump_init);
    78.   Serial.print("\t Pump Speed Percentage = ");
    79.   Serial.println(percentValue);
    80. //  delay after the last reading:
    81.   delay(2);
    82.  
    83. }
    84.  
    85.   void flow_control(void)  {
    86.  
    87.   count = 0;      // Reset the counter so we start counting from 0 again
    88.   interrupts();   //Enables interrupts on the Arduino
    89.   delay (1000);   //Wait 1 second
    90.   noInterrupts(); //Disable the interrupts on the Arduino
    91.   //Start the math
    92.   flowRate = (count * 2.36);        //Take counted pulses in the last second and multiply by 2.25mL
    93.   flowRate = flowRate * 60;         //Convert seconds to minutes, giving you mL / Minute
    94.   flowRate = flowRate / 1000;       //Convert mL to Liters, giving you Liters / Minute
    95.   totalFlowRate += flowRate;   // Add the liters passed in  second to the cumulative total
    96.  
    97.   Serial.println(flowRate);         //Print the variable flowRate to Serial
    98.  
    99. }
    100.  
    101. void Flow()
    102. {
    103.    count++; //Every time this function is called, increment "count" by 1
    104. }
    105.  
     
  9. Reloadron

    Distinguished Member

    Jan 15, 2015
    3,280
    1,449
    The second set of code did compile fine and I'll look at it later today. :)

    Ron
     
  10. rennie1080

    Thread Starter Member

    Apr 10, 2017
    37
    0
    When I use this code, lcd show other variables but no flowmeter variables. In serial port, it write pump and pressure sensor variables but then write 0. ( By the way if does not work, you add your lcd lib. I use LCD with I2C module )

    Code (C):
    1.  
    2. // initialize LCD lib with I2C serial communication protocol
    3. #include <Wire.h> //I2C lib
    4. #include <LCD.h>
    5. #include <LiquidCrystal_I2C.h>
    6.  // LCD lib
    7. LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
    8.  
    9. int pot_pin = A0;
    10. int pump_pwm= 3;
    11.  
    12. int press_pin =A1;
    13.  
    14. int flowPin = 2;  //This is the input pin on the Arduino
    15. byte resetButtonA = 11;
    16.  
    17. double flowRate;    //This is the value we intend to calculate.
    18.  
    19. volatile int count; //This integer needs to be set as volatile to ensure it updates correctly during the interrupt process.
    20.  
    21.  
    22. int pot_init= 0;
    23. int pump_init= 0;
    24. int percentValue =0;
    25. int totalFlowRate = 0;
    26.  
    27.  
    28. void setup() {
    29.  
    30.  
    31.   lcd.begin(20,4);  // A4 - A5 connection SDA - SCL
    32.   lcd.backlight();
    33.   pinMode(resetButtonA, INPUT);
    34.   digitalWrite(resetButtonA, HIGH);
    35.   pinMode(flowPin, INPUT);           //Sets the pin as an input
    36.   attachInterrupt(0, Flow, RISING);  //Configures interrupt 0 (pin 2 on the Arduino Nano) to run the function "Flow"
    37.    
    38.   Serial.begin(9600);
    39. }
    40.  
    41. void loop() {
    42. pressure_cal();
    43. pump_control();
    44. flow_control();
    45.  
    46.  
    47. }
    48.  
    49. void pressure_cal(void) {
    50.  
    51. float sensorVoltage = analogRead(press_pin);   // sensor voltage A0
    52. float psi = ((sensorVoltage-102)/204)*25;  // Offset    0 PSI= 0.5V=102 unit, 50 PSI= 2.5, 100 PSI= 4.5V, 1 PSI= 0.04V , +-0.4PSI approax. sensitivity
    53. // calibration
    54. float bar = psi*(0.0689475729);           // Conversion PSI to BAR
    55.  
    56. if(psi < 0)
    57.     psi = 0;
    58.  
    59.     if(bar<0);
    60.     bar=0;
    61. lcd.setCursor (0,1);
    62. lcd.print (psi);
    63. lcd.print (" PSI");
    64.  
    65. lcd.setCursor ( 0,2);
    66. lcd.print(bar);
    67. lcd.print( " BAR");
    68.  
    69. //lcd.setCursor(0,1);
    70. //lcd.print(sensorVoltage);
    71.  
    72. Serial.println (sensorVoltage);
    73. Serial.println(bar);
    74. Serial.println (psi);
    75.  
    76. delay (100);
    77. }
    78.  
    79. void pump_control(void)
    80.  
    81. {
    82.  // read the analog in value:
    83.   pot_init = analogRead(pot_pin);
    84.   // map it to the range of the analog out:
    85.   pump_init = map(pot_init, 0, 1023, 0, 255);  //  Duty cycle between %20 - %90: speed control , duty cycle between %0 - %20: turned off  , duty cycle between %90 - %100: full speed
    86.   // map pump speed percent of full scale
    87.   percentValue = map (pump_init, 0, 255,0,100);
    88.   // change the analog out value:
    89.   analogWrite(pump_pwm, pump_init);
    90.  
    91.   // print the results to the Serial Monitor:
    92.   Serial.print("\t Speed Input = ");
    93.   Serial.print(pot_init);
    94.   Serial.print("\t Speed Output = ");
    95.   Serial.print(pump_init);
    96.   Serial.print("\t Pump Speed Percentage = ");
    97.   Serial.println(percentValue);
    98.   lcd.setCursor(0,0);        
    99.   lcd.print("Speed: ");
    100.   lcd.setCursor(8,0);        
    101.   lcd.print("%");        
    102. lcd.setCursor(9,0);        
    103. lcd.print(percentValue);        
    104.  
    105.  //  delay after the last reading:
    106.   delay(2);
    107.  
    108. }
    109.  
    110.   void flow_control(void)  {
    111.  
    112.   count = 0;      // Reset the counter so we start counting from 0 again
    113.   interrupts();   //Enables interrupts on the Arduino
    114.   delay (1000);   //Wait 1 second
    115.   noInterrupts(); //Disable the interrupts on the Arduino
    116.  
    117.   /*  if(digitalRead(resetButtonA) == LOW)
    118.   {
    119.     totalFlowRate = 0;
    120.     lcd.setCursor(16, 3);
    121.     lcd.print("0");
    122.   }
    123.     else {
    124.     totalFlowRate += flowRate;
    125.     lcd.setCursor(16, 3);
    126.     lcd.print(totalFlowRate);
    127.    
    128.      
    129.     }   */
    130.    
    131.   //Start the math
    132.   flowRate = (count * 8.93);        //Take counted pulses in the last second and multiply by 8.93mL
    133.   flowRate = flowRate * 60;         //Convert seconds to minutes, giving you mL / Minute
    134.   flowRate = flowRate / 1000;       //Convert mL to Liters, giving you Liters / Minute
    135.   totalFlowRate += flowRate;   // Add the liters passed in  second to the cumulative total
    136.  
    137.   Serial.println(flowRate);         //Print the variable flowRate to Serial
    138.  lcd.setCursor(0,3);        
    139.   lcd.print("F: ");  
    140.    lcd.setCursor(3,3);      
    141. lcd.print(flowRate);
    142.    lcd.setCursor(8,3);      
    143.   lcd.print("lt/m");
    144.  
    145. lcd.setCursor(13,3);
    146. lcd.print("T:");
    147. lcd.setCursor(15,3);
    148. lcd.print(totalFlowRate);
    149.  
    150.  }
    151.  
    152. void Flow()
    153. {
    154.    count++; //Every time this function is called, increment "count" by 1
    155. }
    156.  
     
  11. Reloadron

    Distinguished Member

    Jan 15, 2015
    3,280
    1,449
    It won't compile on an Uno which is all I have to play around with. I would guess and it is purely a guess that some of the problems you have are a result of the interrupt. Again while not my forte the code should have a nice flow to it, stepping through what you want to do in a nice orderly fashion. You also may want to toss this out on the Arduino Boards for some input from those guys. What would also help is a good C++ programming type which I am not.

    Ron
     
  12. rennie1080

    Thread Starter Member

    Apr 10, 2017
    37
    0
    Ron,you are right. Because of interrupt, other function cannot go out from loop. I can not find how to solve this problem yet. I am trying to figure it out.
     
  13. Reloadron

    Distinguished Member

    Jan 15, 2015
    3,280
    1,449
    I had a feeling about that. I'll also look for a work around. I managed to find an old LCD display I was given a few years ago and after about 8 hours managed to get it to do something. Hopefully I can get it to actual;ly do more than tell me "Hello World". :) Anyway, there should be a work around for the interrupt issues, just need to figure it out.

    Ron
     
  14. rennie1080

    Thread Starter Member

    Apr 10, 2017
    37
    0
    with this code I can read variables from serial port but There some variables on LCD ( speed, psi and bar variables are on LCD but there are no changes for them. and I cannot see flowmeter variables on it ) I add also lcd library for arduino.

    Code (C):
    1.  
    2. #include <Wire.h> //I2C lib
    3. #include <LCD.h>
    4. #include <LiquidCrystal_I2C.h>
    5.  // LCD lib
    6. LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
    7.  
    8. const int pot_pin = A0;
    9. const int pump_pwm= 3;
    10.  
    11. int press_pin =A1;
    12.  
    13. //flowmeter parameters
    14. int flowPin = 2;  // input pin on arduino D2
    15.  
    16. double flowRate;   // value intented to calculate
    17. double flowR; // flow value in lt
    18. double totalFlow; // total output of flow from system
    19.  
    20. byte sensorInterrupt = 0; // interrupt 0 on D2 pin Arduino Nano
    21.  
    22. volatile int count; ////integer needs to be set as volatile to ensure it updates correctly during the interrupt process.
    23.  
    24. int pot_init= 0;
    25. int pump_init= 0;
    26. int percentValue =0;
    27.  
    28.  
    29.  
    30. void setup() {
    31.  
    32.   lcd.begin(20,4);  // A4 - A5 connection SDA - SCL
    33.   lcd.backlight();
    34.   Serial.begin(9600);
    35.    
    36.   pinMode( flowPin,INPUT); // Set D2 pin as an input
    37.   attachInterrupt(sensorInterrupt,Flow,RISING); // Configures interrupt 0 ( pin D2 on Arduino Nano ) to run function "Flow"
    38. }
    39. void flow_control(void) {
    40.   count = 0; // reset counter so it could start counting from 0
    41.   interrupts(); // enables interrupts on arduino nano
    42.   delay(1000); // wait 1000 msec
    43.   noInterrupts(); // disable interrupts on arduino nano
    44.    
    45.   //calculation for flowmeter
    46.   flowR = (count*8.93);   // 112 pulse/lt 423.84 pulse /gallon
    47.   flowRate= flowR*60;     // convert seconds to minutes, new unit is ml/minutes
    48.   flowRate= flowRate/1000; // convert ml to liters, new unit is lt/minutes
    49.   totalFlow += flowR;
    50.   // Print the flow rate for this second in litres / minute
    51.     Serial.print("Flow rate: ");
    52.     Serial.print(int(flowRate));  // Print the integer part of the variable
    53.     Serial.print("L/min");
    54.     Serial.print("\t");       // Print tab space
    55.  
    56.     // Print the cumulative total of litres flowed since starting
    57.     Serial.print("Output Liquid Quantity: ");      
    58.     Serial.print(totalFlow/1000);
    59.     Serial.println("L");
    60.  
    61. }
    62.  
    63. void Flow(void)
    64. {
    65.   count++; // every time this function is called, increment  "count" by 1
    66. }
    67.  
    68. void loop() {
    69.   pressure_cal();
    70.   pump_control();
    71.   flow_control();
    72.  
    73. }
    74.  
    75.  
    76. void pressure_cal(void) {
    77.  
    78.   float sensorVoltage = analogRead(press_pin);   // sensor voltage A0
    79.   float psi = ((sensorVoltage-102)/204)*25;  // Offset    0 PSI= 0.5V=102 unit, 50 PSI= 2.5, 100 PSI= 4.5V, 1 PSI= 0.04V
    80.   // calibration
    81.   float bar = psi*(0.0689475729);           // Conversion PSI to BAR
    82.  
    83.  
    84.   lcd.setCursor (0,1);
    85.   lcd.print (psi);
    86.   lcd.print (" PSI");
    87.  
    88.   lcd.setCursor ( 10,1);
    89.   lcd.print(bar);
    90.   lcd.print( " BAR");
    91.  
    92.   //lcd.setCursor(17,1);
    93.   //lcd.print(sensorVoltage);
    94.  
    95.  
    96.  
    97.   Serial.print("\t Sensor Value = ");
    98.   Serial.print(sensorVoltage);
    99.   Serial.print("\t Bar = ");
    100.   Serial.print(bar);
    101.   Serial.print("\t PSI = ");
    102.   Serial.println(psi);
    103.  
    104.   delay (100);
    105. }
    106.  
    107. void pump_control(void)
    108.  
    109. {
    110.   // read the analog in value:
    111.   pot_init = analogRead(pot_pin);
    112.   // map it to the range of the analog out:
    113.   pump_init = map(pot_init, 0, 1023, 50, 230);  //  duty cycle between %20 - %90: speed control , duty cycle between %0 - %20: turned off  , duty cycle between %90 - %100: full speed
    114.   // map pump speed percent of full scale
    115.   percentValue = map (pump_init, 50, 230,0,100);
    116.   // change the analog out value:
    117.   analogWrite(pump_pwm, pump_init);
    118.  
    119.   // print the results to the Serial Monitor:
    120.   Serial.print("\t Speed Input = ");
    121.   Serial.print(pot_init);
    122.   Serial.print("\t Speed Output = ");
    123.   Serial.print(pump_init);
    124.   Serial.print("\t Pump Speed Percentage = ");
    125.   Serial.println(percentValue);
    126.   lcd.setCursor(2,0);        
    127.   lcd.print("Speed: ");
    128.   lcd.setCursor(8,0);        
    129.   lcd.print("%");        
    130.   lcd.setCursor(9,0);        
    131.   lcd.print(percentValue);
    132.   lcd.print("     ");        
    133.  
    134.  //  delay after the last reading:
    135.   delay(10);
    136.  
    137. }
    138.  
    139.  
     
  15. Reloadron

    Distinguished Member

    Jan 15, 2015
    3,280
    1,449
    I am seeing what you are seeing. Reading about these LCD Libraries is enlightening as there are likely a few dozen libraries out there and most have bugs and no well defined manuals. Great! :) Your code compiles just fine, I have to read through this more.

    Ron
     
Loading...