Get Variable data from MYSQL table and assign it to PinMode (Digital Write and Read) on WiringPi (MCP23017)
-
Hello Everybody.
Im developing a circuit tester using several MCP23017 modules using I2C and WiringPi as main GPIO Library. So far so good as I was able to make everything work "manually" that means by manually assigning the GPIO to use on the MCP as Input or Output (PinMode). Idea is to use all MCP23017 modules to add those extra GPIOs (128) and use them as circuits testers (for wires or cable I use 1 pin as input and 1 pin as output, thats how I "test" a wire) Problem comes when I was looking for some automation such getting the data from a MySQL table (integers) then assign that value to the MCP pin that will act as Output or input. I have the following code which again as I said, WORKS but only when you manually assign the pin number (such 65, 66, 67, etc.) but when you store that value on MySQL table then loaded it back to QT5 it does not work. I used a QLabel to "see" if the values where imported correctly from MySQL and they are OK (used label_PinValue INP and Out for that) , but when saving or assigning those values to a variable (Circ1Input or Output) then assigning PinMode, then the Digital Write or Read. It does not work, just, nothing happens. Please see my code and hope you can help.CIRCUIT1: // table to get the values from: "MHT_new_FET_table" //first query (query) is to get value from output column and assign it to "circ1output" variable QSqlQuery query; //query to initialize the SQL query.prepare("SELECT output FROM MHT_new_FET_table WHERE circuit_number = 1");//select first output value from MHT FET table's output column query.exec(); //execute query query.first();//pull the result from query and select row and get value ready for assignation to variable int circ1output = query.value(0).toInt(); //convert value into an integer so now we can compare both circuits //second query (query2) will get value from input column and assign it to variable "circ1input" QSqlQuery query2; //query to initialize the SQL query2.prepare("SELECT input FROM MHT_new_FET_table WHERE circuit_number = 1");//select first input value from MHT FET table's output column query2.exec(); //execute query query2.first();//pull the result from query and select row and get value ready for assignation to variable int circ1input = query.value(0).toInt(); //convert value into an integer so now we can compare both circuits ui->label_pinValueOut->setNum(circ1output); //value reads as 65 ui->label_pinValueInp->setNum(circ1input); //value reads as 76 pinMode (circ1output, OUTPUT) ; //Output circuit 1 with variable value got from FET table output column (current value is 65 which goes on MCP23017 pin 1 pinMode (circ1input, INPUT) ; //Input circuit 1 with variable value got freom FET table input column (current value is 76 which goes on MCP23017 pin 9 digitalWrite(circ1output, HIGH); //we send the HI signal thru output pin so input pin can receive the signal. //logical part to decide if the signal is received on correct pin (input pin) it will pass, else it will fail. Then results will be recorded on database. in these case Im using a jumper wire connected from pin 65 to pin 76 on the MCP23017 and according to my code, icon should turn green (siCon), but it keeps on yellow so no read on pin. if (digitalRead(circ1input)== HIGH) { ui->label_c1->setPixmap(siCon); //if pass, then we change circuit Icon to green circuitCounter ++; //validated first circuit and add +1 to current circuitCounter variable. ui->lcdNumber->display(circuitCounter); //we show or display current circuits counter on lcd widget this will be increasing accordingly digitalWrite(circ1output, LOW); //turn off pin if (circuitCounter == circuitsToValidate){ goto FINISH; } if (circuitCounter < circuitsToValidate){ goto CIRCUIT2; } } else { ui->label_c1->setPixmap(openCon); //yellow icon tells that no continuity detected on pin. //Show popup window with open connection and to ensure correct terminal insertion and continue QMessageBox::warning(this,"OPEN CIRCUIT/TERMINAL NOT FULLY SEATED", "Please check terminal insertion or presence. Continue test"); goto CIRCUIT1; } } //End bracked Circuit 1
-
Hello Everybody.
Im developing a circuit tester using several MCP23017 modules using I2C and WiringPi as main GPIO Library. So far so good as I was able to make everything work "manually" that means by manually assigning the GPIO to use on the MCP as Input or Output (PinMode). Idea is to use all MCP23017 modules to add those extra GPIOs (128) and use them as circuits testers (for wires or cable I use 1 pin as input and 1 pin as output, thats how I "test" a wire) Problem comes when I was looking for some automation such getting the data from a MySQL table (integers) then assign that value to the MCP pin that will act as Output or input. I have the following code which again as I said, WORKS but only when you manually assign the pin number (such 65, 66, 67, etc.) but when you store that value on MySQL table then loaded it back to QT5 it does not work. I used a QLabel to "see" if the values where imported correctly from MySQL and they are OK (used label_PinValue INP and Out for that) , but when saving or assigning those values to a variable (Circ1Input or Output) then assigning PinMode, then the Digital Write or Read. It does not work, just, nothing happens. Please see my code and hope you can help.CIRCUIT1: // table to get the values from: "MHT_new_FET_table" //first query (query) is to get value from output column and assign it to "circ1output" variable QSqlQuery query; //query to initialize the SQL query.prepare("SELECT output FROM MHT_new_FET_table WHERE circuit_number = 1");//select first output value from MHT FET table's output column query.exec(); //execute query query.first();//pull the result from query and select row and get value ready for assignation to variable int circ1output = query.value(0).toInt(); //convert value into an integer so now we can compare both circuits //second query (query2) will get value from input column and assign it to variable "circ1input" QSqlQuery query2; //query to initialize the SQL query2.prepare("SELECT input FROM MHT_new_FET_table WHERE circuit_number = 1");//select first input value from MHT FET table's output column query2.exec(); //execute query query2.first();//pull the result from query and select row and get value ready for assignation to variable int circ1input = query.value(0).toInt(); //convert value into an integer so now we can compare both circuits ui->label_pinValueOut->setNum(circ1output); //value reads as 65 ui->label_pinValueInp->setNum(circ1input); //value reads as 76 pinMode (circ1output, OUTPUT) ; //Output circuit 1 with variable value got from FET table output column (current value is 65 which goes on MCP23017 pin 1 pinMode (circ1input, INPUT) ; //Input circuit 1 with variable value got freom FET table input column (current value is 76 which goes on MCP23017 pin 9 digitalWrite(circ1output, HIGH); //we send the HI signal thru output pin so input pin can receive the signal. //logical part to decide if the signal is received on correct pin (input pin) it will pass, else it will fail. Then results will be recorded on database. in these case Im using a jumper wire connected from pin 65 to pin 76 on the MCP23017 and according to my code, icon should turn green (siCon), but it keeps on yellow so no read on pin. if (digitalRead(circ1input)== HIGH) { ui->label_c1->setPixmap(siCon); //if pass, then we change circuit Icon to green circuitCounter ++; //validated first circuit and add +1 to current circuitCounter variable. ui->lcdNumber->display(circuitCounter); //we show or display current circuits counter on lcd widget this will be increasing accordingly digitalWrite(circ1output, LOW); //turn off pin if (circuitCounter == circuitsToValidate){ goto FINISH; } if (circuitCounter < circuitsToValidate){ goto CIRCUIT2; } } else { ui->label_c1->setPixmap(openCon); //yellow icon tells that no continuity detected on pin. //Show popup window with open connection and to ensure correct terminal insertion and continue QMessageBox::warning(this,"OPEN CIRCUIT/TERMINAL NOT FULLY SEATED", "Please check terminal insertion or presence. Continue test"); goto CIRCUIT1; } } //End bracked Circuit 1
@GARUCHIRAZUMAN said in Get Variable data from MYSQL table and assign it to PinMode (Digital Write and Read) on WiringPi (MCP23017):
query2.first();//pull the result from query and select row and get value ready for assignation to variable int circ1input = query.value(0).toInt(); //convert value into an integer so now we can compare both circuits
Please look at your code. You are assigning from
query
and notquery2
.ui->label_pinValueOut->setNum(circ1output); //value reads as 65 ui->label_pinValueInp->setNum(circ1input); //value reads as 76
I used a QLabel to "see" if the values where imported correctly from MySQL
I do not believe this: they both read the same, since they are both
query.value(0).toInt()
.While you are correcting it, please as a matter of course put in error checking for e.g.
prepare
/exec
/first()
calls. -
@JonB Correct, well nothing happens was not an accurate way to determine that code is not doing what it should. :)
And of course, I will follow your advice on error checks.Thank you so much, just cant believe it was just a Typo. I Should copy-paste less next time. ;)
Problem solved !