You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello reader! My project involves filling a tank with a liquid called ox and fu. I have to make sure the pipelines and tank are at certain pressures. Using Nanpy, the Pi tells the Arduino to measure pressures and to trigger relays which triggers solenoid valves as well.
My problem is that my program runs well but will eventually result in a timeout error (error outlined in below).
I have a system consisting of the following: Raspberry Pi 3 Model B, Arduino Mega 2560 Rev3, powered USB hub, Sainsmart 16-channel relay module, 5 pressure transducers and 7 solenoid valves. The setup is below.
The connections are as follows:
*Pi3 to powered USB hub to Mega via USB
*Mega connected to pressure transducers (pins A0 to A4) and relay board (pins 22 to 38)
*relay board connected to solenoids.
I apologize for the long code. I removed a lot of the other essential parts and reduced it to its absolute core.
Your Python code
fromnanpyimport (ArduinoApi, SerialManager)
fromtimeimportsleepfromtimeitimportdefault_timerastimerimporttimeimportdatetimeimportRPi.GPIOasGPIOimportsysimportnumpyimportrandomfromthreadingimportThreadimportcurses#connect to arduinoconnection=SerialManager('/dev/ttyACM1', 9600)
a=ArduinoApi(connection=connection)
#start timerstart_time=time.time() #needed to measure runtime before program crashes :(#curses optionsstdscr=curses.initscr()#for the non-blocking text#This allows the program to continue running after waiting for input for a limited amount of time.stdscr.nodelay(1) #set input to non-blocking mode.curses.noecho() #echoing of input characters is turned offstdscr.nodelay(1) #set getch() non-blocking#Used to zero the pressure transducers.globalzero_ptzero_pt=False# allows the safety solenoids to vent when tanks are overpressurized.auto_safety='YES'#arms the system and powers the solenoids armed='OFF'#setting the pinmodes for the Sainsmart 16 channel relay board.a.pinMode(34, a.OUTPUT) #fuel safety solenoidsa.digitalWrite(34, 1)
a.pinMode(29, a.OUTPUT) #Oxygen safety solenoidsa.digitalWrite(29, 1)
sleep(0.1)
a.pinMode(31, a.OUTPUT) #Arming relaya.digitalWrite(31, 1)
sleep(0.1)
a.pinMode(22, a.OUTPUT) # Normally CLOSED solenoid (Main Pressure Solenoid).a.digitalWrite(22, 1)
sleep(0.1)
a.pinMode(23, a.OUTPUT) # Normally OPEN solenoid. (Venting Open Solenoid).a.digitalWrite(23, 1)
sleep(0.1)
a.pinMode(24, a.OUTPUT) # Normally OPEN solenoid. (Venting Close Solenoid).a.digitalWrite(24, 1)
sleep(0.1)
a.pinMode(25, a.OUTPUT) # Normally OPEN solenoid. (Mainshut Solenoid).a.digitalWrite(25, 1)
sleep(0.1)
a.pinMode(26, a.OUTPUT) # Normally OPEN solenoid. (Mainopen Solenoid).a.digitalWrite(26, 1)
sleep(0.1)
a.pinMode(27, a.OUTPUT) #Oxygen Pump Heatera.digitalWrite(27, 1)
sleep(0.1)
a.pinMode(28, a.OUTPUT) #Fuel Pump Heatera.digitalWrite(28, 1)
sleep(0.1)
a.pinMode(30, a.OUTPUT)
a.digitalWrite(30, 1)
sleep(0.1)
a.pinMode(32, a.OUTPUT)
a.digitalWrite(32, 1)
sleep(0.1)
a.pinMode(33, a.OUTPUT)
a.digitalWrite(33, 1)
sleep(0.1)
sleep(0.1)
a.pinMode(35, a.OUTPUT)
a.digitalWrite(35, 1)
sleep(0.1)
a.pinMode(36, a.OUTPUT)
a.digitalWrite(36, 1)
sleep(0.1)
a.pinMode(37, a.OUTPUT)
a.digitalWrite(37, 1)
#defining functions to operate solenoids#Arduino digital channels 22 to 37. HIGH (1) in arduino corresponds to off on relay board#Currently, the pressure transducers have not been zeroed.#***Pressurization Functions***defpresson(): #The D2061-LN2-C203 is normally closed. 0Ard => 1Relay => Open Valve.press=22a.digitalWrite(press,0) #Open Valve## print "Pressurizing ox and fu ON"defpressoff(): #The D2061-LN2-C203 is normally closed. 1Ard => 0Relay => Closed Valve.press=22a.digitalWrite(press,1) #Close Valve## print"Pressurizing ox and fu OFF"#***Venting Functions***defventopenon(): #The A3021-T-T0-C203 is normally closed. 0Ard => 1Relay => Open Valveventopen=24a.digitalWrite(ventopen,0)
## print "Venting ox and fu (Solenoid ON)"defventopenoff():
ventopen=24a.digitalWrite(ventopen,1)
## print "Venting ox and fu (Solenoid OFF)"defventcloseon():
ventclose=23a.digitalWrite(ventclose,0)
## print "NOT Venting ox and fu (Solenoid ON)"defventcloseoff():
ventclose=23a.digitalWrite(ventclose,1)
## print "NOT Venting ox and fu (Solenoid OFF)"#***Main Valve Functions***defmainshuton():
mainshut=25a.digitalWrite(mainshut, 0)
## print "main shut ON"defmainshutoff():
mainshut=25a.digitalWrite(mainshut, 1)
## print "main shut OFF"defmainopenon():
mainopen=26a.digitalWrite(mainopen, 0)
## print "\n main open ON \n"defmainopenoff():
mainopen=26a.digitalWrite(mainopen, 1)
## print "\n main open OFF \n"## Safety solenoidsdefoxsafetyoff():
oxsafety=29a.digitalWrite(oxsafety,0) #close the LOX safety## print "\n Ox safety CLOSED"defoxsafetyon():
oxsafety=29a.digitalWrite(oxsafety,1) #open the LOX safety## print "\n Ox safety OPENED"deffusafetyoff():
fusafety=34a.digitalWrite(fusafety,0) #close the PP safety## print "\n PP safety CLOSED"deffusafetyon():
fusafety=34a.digitalWrite(fusafety,1) #open the PP safety## print "\n PP safety OPENED"# Arming Relaydefarmingon():
arming=31a.digitalWrite(arming, 0)
globalarmedarmed='ON'## print "arming on"defarmingoff():
arming=31a.digitalWrite(arming, 1)
globalarmedarmed='OFF'## print "arming off"#Pump Heatersdefoxheateron():
oxheater=27a.digitalWrite(oxheater, 0)
## print "Oxygen pump heater ON."defoxheateroff():
oxheater=27a.digitalWrite(oxheater, 1)
## print "Oxygen pump heater OFF."deffuheateron():
fuheater=28a.digitalWrite(fuheater,0)
## print "Fuel pump heater ON."deffuheateroff():
fuheater=28a.digitalWrite(fuheater,1)
## print "Fuel pump heater OFF"#Combination functions.defwaitenter():
try:
input("Press Enter to Continue")
exceptSyntaxError:
passdefmainopen(): #Opens the main valvemainopenon()
sleep (1.0)
mainopenoff()
defmainclose(): #Closes the main valvesmainshuton()
sleep(1.0)
mainshutoff()
defventopen(): #Opens the venting valvesventopenon()
sleep(1.0)
ventopenoff()
defventclose(): #Closes the venting valvesventcloseon()
sleep(1.0)
ventcloseoff()
defpurge(): #Purge the linepurgeon()
sleep(1)
purgeoff()
defsleepmes(secs):
print"wait ",
printsecs,
print" seconds"sleep(secs)
#***Pressure Transducer Functions***#These are the functions needed to measure the pressure from the pressure transducer.defpress_volt(x, in_min, in_max, out_min, out_max):
return (x-in_min)*(out_max-out_min)/(in_max-in_min)+out_mindefpsiox_measure():
PT1_slope=23.81173PT1_intercept=-0.60496PT1_volt_correct=0.0038PT1_voltage=press_volt(a.analogRead(0), 0.0, 1023.0, 0.0, 5.0)+PT1_volt_correctreturnPT1_voltage*PT1_slope+PT1_intercept# [psi] A0 pin, PT1## return PT1_voltage## return a.analogRead(0)defpsifu_measure():
PT2_slope=24.10409PT2_intercept=-0.95421PT2_volt_correct=0.0186PT2_voltage=press_volt(a.analogRead(1), 0.0, 1023.0, 0.0, 5.0)+PT2_volt_correctreturnPT2_voltage*PT2_slope+PT2_intercept# [psi] A1 pin, PT2## return PT2_voltage## return a.analogRead(1)defpsiox_pump_measure():
PT3_slope=277.962127PT3_intercept=-130.83277PT3_volt_correct=0.021531378PT3_voltage=press_volt(a.analogRead(2), 0.0, 1023.0, 0.0, 5.0)+PT3_volt_correctreturnPT3_voltage*PT3_slope+PT3_intercept# [psi] A2 pin, PT3## return PT3_voltage## return a.analogRead(2)defpsifu_pump_measure():
PT4_slope=281.237104PT4_intercept=-139.852626PT4_volt_correct=0.015977517PT4_voltage=press_volt(a.analogRead(3), 0.0, 1023.0, 0.0, 5.0)+PT4_volt_correctreturnPT4_voltage*PT4_slope+PT4_intercept# [psi] A3 pin, PT4## return PT4_voltage## return a.analogRead(3)defpsichamb_measure():
PT5_slope=279.899666PT5_intercept=-136.618869PT5_volt_correct=0.020039101PT5_voltage=press_volt(a.analogRead(4), 0.0, 1023.0, 0.0, 5.0)+PT5_volt_correctreturnPT5_voltage*PT5_slope+PT5_intercept# [psi] A4 pin, PT5## return PT5_voltage## return a.analogRead(4)deftimer(first_time):
end_time=time.time()
time_period= (end_time-first_time)/60#time in minutesreturntime_period# ------------------------MAIN FUNCTION===================fopen=open('LogData'+str(time.strftime("%m%d%y%H%M")),'w') #will create new file named LogDataMMDDYYHHMMfappend=open('LogData'+str(time.strftime("%m%d%y%H%M")),'a') #defines fappend to append data to log filefname='LogData'+str(time.strftime("%m%d%y%H%M")) #static file nameprint"Log file opened in ~/pi/Teststand: LogData"+str(time.strftime("%m%d%y%H%M"))
#write a header for each log entryfappend.write('Log Data Date: ')
fappend.write(str(time.strftime("%c"))) #formatted time and datefappend.write('\n')
print_once=Truetry:
whileTrue:
# Zero the pressure transducers or print the values as they are.ifzero_pt==True:
psiox=psiox_measure() -z_psioxpsifu=psifu_measure() -z_psifupsioxpump=psiox_pump_measure() -z_psioxpumppsifupump=psifu_pump_measure() -z_psifupumppsichamb=psichamb_measure() -z_psichambelse:
psiox=psiox_measure()
psifu=psifu_measure()
psioxpump=psiox_pump_measure()
psifupump=psifu_pump_measure()
psichamb=psichamb_measure()
#calculate the elapsed time elapsed_time=timer(start_time)
#Safety release valves.ifauto_safety=='YES':
#Keep the valves open if tank is overpressurized if (psiox>=50andarmed=='ON') or (psifu>=50andarmed=='ON'):
oxsafetyon()
fusafetyon()
sleep(0.1)
#Keep the valves closed if tank is not overpressurizedelif (psiox<=50andarmed=='ON') or (psifu<=50andarmed=='ON'):
oxsafetyoff()
fusafetyoff()
sleep(0.1)
elifauto_safety=='NO':
oxsafetyon()
fusafetyon()
stdscr.addstr(0,0, "%d oxtankpress[psi]"%int(psiox))
stdscr.addstr(1,0, "%d futankpress[psi]"%int(psifu))
stdscr.addstr(2,0, "%d oxpumppress[psi]"%int(psioxpump))
stdscr.addstr(3,0, "%d fupumppress[psi]"%int(psifupump))
stdscr.addstr(4,0, "%d psichambpress[psi]"%int(psichamb))
stdscr.addstr(5,0, "%.2f time elapsed [min]"%elapsed_time)
#Printing the pressure valuesifprint_once==True:
fappend.write(" oxtankpress[psi] \t futankpress[psi] \t oxpumppress[psi] \\t fupumppress[psi] \t psichambpress[psi] \t elapsed time[min]\n")
print_once=Falsefappend.write(str(psiox))
fappend.write(" \t\t ")
fappend.write(str(psifu))
fappend.write(" \t\t ")
fappend.write(str(psioxpump))
fappend.write(" \t\t ")
fappend.write(str(psifupump))
fappend.write(" \t ")
fappend.write(str(psichamb))
fappend.write(" \t ")
fappend.write(str(elapsed_time))
fappend.write(" \t ")
#Print the Options menu
(y_win, x_win) =stdscr.getmaxyx()
mid_screen=int(x_win/2)
stdscr.addstr(7, mid_screen-8, "***Main Menu***")
stdscr.addstr(8, 0, "1=Armed \t 2=Unarmed \t 3=Open Vent \t 4=Close Vent")
stdscr.addstr(9, 0, "5=Open Main \t 6=Close Main \t 7=Pressurization")
stdscr.addstr(10,0, "8=Pressure Stopped\t 9=Ox/Fu Safety OPEN \t 10=Ox/Fu Safety CLOSED")
stdscr.addstr(11,0, "11=Zero Pressures \t 12= Pump Heaters ON \t 13= Pump Heaters OFF")
stdscr.addstr(12,0, "14= Auto Safety ON \t 15= Auto Safety OFF\t 16=")
sleep(1) #Wait to get command responsecmd=stdscr.getstr() #get the command response#Command option responsesifcmd=='1':
armingon()
stdscr.addstr(15,0,"Arming ON ")
elifcmd=='2':
oxsafetyon()
sleep(0.1)
fusafetyon()
armingoff()
stdscr.addstr(15,0,"Arming OFF ")
elifcmd=='3':
ventopen()
stdscr.addstr(15,0,"Vent OPEN ")
elifcmd=='4':
ventclose()
stdscr.addstr(15,0,"Vent CLOSE ")
elifcmd=='5':
mainopen()
stdscr.addstr(15,0,"Main OPEN ")
elifcmd=='6':
mainclose()
stdscr.addstr(15,0,"Main CLOSED ")
elifcmd=='7':
presson()
stdscr.addstr(15,0,"Pressurizing ")
elifcmd=='8':
pressoff()
stdscr.addstr(15,0,"Pressured Stopped ")
elifcmd=='9':
oxsafetyon()
sleep(0.1)
fusafetyon()
stdscr.addstr(15,0,"Ox/Fu Safety OPEN ")
elifcmd=='10':
ifarmed=='ON':
oxsafetyoff()
sleep(0.1)
fusafetyoff()
stdscr.addstr(15,0,"Ox/Fu Safety CLOSED ")
elifarmed=='OFF':
stdscr.addstr(15,0, "Solenoids are not yet armed! ")
elifcmd=='11':
zero_pt=Truez_psiox=psiox_measure()
z_psifu=psifu_measure()
z_psioxpump=psiox_pump_measure()
z_psifupump=psifu_pump_measure()
z_psichamb=psichamb_measure()
stdscr.addstr(15,0, "All Pressures Zeroed ")
elifcmd=='12':
oxheateron()
fuheateron()
stdscr.addstr(15,0, "Ox/Fu Pump Heater ON ")
elifcmd=='13':
oxheateroff()
fuheateroff()
stdscr.addstr(15,0, "Ox/Fu Pump Heater OFF ")
elifcmd=='14':
auto_safety='YES'stdscr.addstr(15,0, "Auto Safety ON ")
elifcmd=='15':
auto_safety='NO'stdscr.addstr(15,0, "Auto Safety OFF ")
elifcmd=='q':
breakfinally:
pressoff()
armingoff()
curses.endwin()
Your log messages
File "10secfiretest_debug_RevD.py", line 472, in <module>
pressoff()
File "10secfiretest_debug_RevD.py", line 130, in pressoff
a.digitalWrite(press,1) #Close Valve
File "/usr/local/lib/python2.7/dist-packages/nanpy/arduinoboard.py", line 125, in wrapper
return _call(cls_name, 0, call_pars, connection=connection)
File "/usr/local/lib/python2.7/dist-packages/nanpy/arduinoboard.py", line 47, in _call
ret = return_value(connection)
File "/usr/local/lib/python2.7/dist-packages/nanpy/arduinoboard.py", line 16, in return_value
return connection.readline().replace('\r\n', '')
File "/usr/local/lib/python2.7/dist-packages/nanpy/serialmanager.py", line 101, in readline
raise SerialManagerError('Serial timeout!')
nanpy.serialmanager.SerialManagerError: Serial timeout!
...
Your cfg.h
#defineUSE_Info 1
#pragma once
// only for ESP8266#defineUSE_WIFI_CONNECTION 0
// for WIFI connection#defineWIFI_SSID "***"
#defineWIFI_PASSWORD "***"
// for serial connection#defineBAUDRATE 9600
// info about existence of other features#defineUSE_Info 1
// definitions: MCU type, frequency, Arduino version,// EEPROM size, RAM size, pin count, build time,..#defineUSE_Define 1
// low level mapping of pins and ports#defineUSE_ArduinoCore 1
// read, write RAM#defineUSE_RAM 1
// read, write EEPROM#defineUSE_EEPROM 1
// read, write AVR registers#defineUSE_Register 0
// watchdog and reset#defineUSE_Watchdog 0
#defineUSE_Tone 0
#defineUSE_LiquidCrystal 0
// I2C#defineUSE_Wire 0
#defineUSE_Servo 0
#defineUSE_Stepper 0
// frequency counter, USE_Tone should be off!#defineUSE_Counter 0
///////////////////////////////////////////////////////////////////////// external libraries should be installed for the following features:///////////////////////////////////////////////////////////////////////// https://github.com/PaulStoffregen/OneWire#defineUSE_OneWire 0
// https://github.com/milesburton/Arduino-Temperature-Control-Library#defineUSE_DallasTemperature 0
#defineUSE_CapacitiveSensor 0
// https://github.com/adafruit/DHT-sensor-library#defineUSE_DHT 0
// https://bitbucket.org/fmalpartida/new-liquidcrystal#defineUSE_LiquidCrystal_I2C 0
// https://www.adafruit.com/products/1429#defineUSE_TLC5947 0
As I have said before the program operates well. It shows the pressure readings in real time while giving me the option to input commands without an input block. I have noticed that when I adjust sleep() [the one before input options] by giving it 4 seconds the program is very stable and can run for an error without error but the time to accept the command is longer of course. When I decrease the value, the program has a higher tendency to fail early.
Currently, I am at a loss of what to do. I would very much appreciate any input any of you could give.
Thank you for your time.
Your hardware
Arduino board: Arduino Mega 2560
Additional hardware: Raspberry Pi 3
Additional hardware: Sainsmart 16 Channel Relay
Additional hardware: 5 Pressure Transducers
Additional hardware: 7 Valve Solenoids'
The text was updated successfully, but these errors were encountered:
Hello reader! My project involves filling a tank with a liquid called ox and fu. I have to make sure the pipelines and tank are at certain pressures. Using Nanpy, the Pi tells the Arduino to measure pressures and to trigger relays which triggers solenoid valves as well.
My problem is that my program runs well but will eventually result in a timeout error (error outlined in below).
I have a system consisting of the following: Raspberry Pi 3 Model B, Arduino Mega 2560 Rev3, powered USB hub, Sainsmart 16-channel relay module, 5 pressure transducers and 7 solenoid valves. The setup is below.
The connections are as follows:
*Pi3 to powered USB hub to Mega via USB
*Mega connected to pressure transducers (pins A0 to A4) and relay board (pins 22 to 38)
*relay board connected to solenoids.
I apologize for the long code. I removed a lot of the other essential parts and reduced it to its absolute core.
Your Python code
Your log messages
Your cfg.h
As I have said before the program operates well. It shows the pressure readings in real time while giving me the option to input commands without an input block. I have noticed that when I adjust sleep() [the one before input options] by giving it 4 seconds the program is very stable and can run for an error without error but the time to accept the command is longer of course. When I decrease the value, the program has a higher tendency to fail early.
Currently, I am at a loss of what to do. I would very much appreciate any input any of you could give.
Thank you for your time.
Your hardware
Arduino Mega 2560
Raspberry Pi 3
Sainsmart 16 Channel Relay
5 Pressure Transducers
7 Valve Solenoids
'The text was updated successfully, but these errors were encountered: