GUI tutorial and ideas ?

Status
Not open for further replies.

gony

Well-known member
hello ,
my project is basically self- running , it responds to inputs .
BUT , i want to have the ability to over-ride the routine and for example , set an output to HIGH (manually) while it was supposed to be low .

what is the proper way to do it ? i can connect a push-button and write some code for it , but i would prefer something more comfortable because different people will operate on my project and it should be more friendly than a pushbutton - for that i thought of GUI like labview, is there anything like that for teensy ? on the web i found some remarks but nothing clear , except a video (youtube) but it is ment for raspberry pi (i don't know what that means)


thank you!!!
 
The default option is the ili9341 and relatives like this one
https://www.pjrc.com/store/display_ili9341_touch.html
or all the normal online places - suggest not buying the cheapest possible at first since the dead on arrival rate will be high (>5% out of my buys) and it's good if you have a known good unit as a starting place.
At the most basic gui you do a clear and then print like you would the serial terminal, and change the font colour for active options.
Various other GUI options can sit on top of the LCD library, trading complexity in learning the library for needing to write lower level code.

There are also much more expensive LCDs with internal controllers where you program them from a PC and they then run a serial interface to your microcontroller giving button state information but managing the pretty parts internally.
 
I'm really not sure what you are aiming for
  • some graphical output with a touchscreen so that the user can interact with your application, or
  • a way of graphically "programming" your application?
LabView can do both, which is probably why I'm confused now.
 
what i want :
in my project the teensy receives inputs non-stop and responds accordingly with outputs (depending on the inputs ) - what i want is to have a button on the screen that when pressed , it bypasses the inputs that are given and sends a certain output (which i'll define ) , than resume normal behaviour (receiving inputs , sending outputs accordingly )
 
Sounds fairly straight forward.

Just separate the input from the manual inputs and set the code to compare.


quick and dirty example, you will probably need a few extra things to prevent unwanted states. And there is probably more efficient ways of doing the below.
Code:
if(override == 1){
output1 = manualoutput1;
}
else{
output1 = digitalread(pinx);
}
 
yes but my question is about how to make an option of pressing a button . NOT physical button like with GND and all that , but something like a window on the computer screen that has a little square you click on and it modifies the new output , maybe further i would want to have another button with the option to change duration of the output pulse , but first things first - how do i make that window ?
 
yes but my question is about how to make an option of pressing a button . NOT physical button like with GND and all that , but something like a window on the computer screen that has a little square you click on and it modifies the new output , maybe further i would want to have another button with the option to change duration of the output pulse , but first things first - how do i make that window ?

First thing first,
decide first, if you are allergic to miscrosoft or not.
If not, you can download Visual Studio Community Edition, if you are, then I know QtCreator as a multiplatform tool.
Both allow you to create a GUI and interact with Teensy using Serial libraries. Others may exits.

In addition, both system would even allow you to use then as IDE for Teensy programming (after some tweaking of the preferences)

However, if you are looking for a GUI on Teensy + touchscreen, ignore my post
 
ok so i found some videos on youtube about using labview with arduino and i thought it might be what i'm looking for , so i downloaded LVIFA but when i tried to upload it to the arduino sketch i had some problems ("error this chip is not supported" etc ) . i think it has got to do with the fact i'm using teensy and not arduino , buti haven't seen any labview for teensy anywhere.
any ideas?

**edit**
WMXZ - i have just seen your post . i'm not allergic to microsoft but should i be ? i'm very inexperienced in all this !
but i am working in a lab so i don't mind paying money for the best option ( community edition sounded amateur , but just guessing)

last thing , i'm not looking for a touchscreen , just the option to modify certain outputs at non dependent timing
 
Community edition means only it is free for private use (or so). but for business, you will get a professional and enterprise version.

So you are looking for a GUI on a PC and not on the Teensy, right?
are you planning to generate a stand-alone version of it?

From your OP this is not clear to me, where your input is made.
 
i'll start from the beginning -
its a project for an experimental lab . i have inputs coming from the experiment computer to the teensy , than all sorts of things happen ( according to what was the input ) and than the teensy sends output back to the experimental computer . the connection between the experimental computer and the teensy happen through 2 National Instrument cards .

all of this happens automatically and i don't need any GUI for it , just let it run . BUT , i want to have an option that the person who runs the experiment ( a person who is not familiar with teensy/coding) could click a button on the screen (same screen on which the arduino IDE runs , and the experiment ) which will set one of the outputs (which is already being controlled by the teensy code) to HIGH .

Code:
void reward(void) {
  if (!digitalReadFast(3)) {
    switch (GPIOB_PDIR & 0xF) {
        case 4: // reward command received
           rewardON = GPIOC_PDIR;
           //Serial.println(GPIOC_PDIR);
           //Serial.println(rewardON);
           GPIOE_PDOR= 0x2000000;
           //digitalWriteFast(34, HIGH);//reward
           rewardTime = 0;//start counting until stop
           break;
       case 1:
          //Serial.println("markerIFtest - GPIOC_PDIR-");
          //Serial.println(GPIOC_PDIR,BIN);
          GPIOD_PDOR= ((GPIOC_PDIR >>1) & 0xFF) | ((GPIOC_PDIR<<4) & 0xE000);
          //Serial.println(GPIOD_PDOR,BIN);
          isMarkerOn=1;
          //Serial.println("GPIOD_PDOR-");
         //Serial.println(GPIOD_PDOR,BIN);
         markerTime = 0;//start counting until stop
    }
  }
}

as you can see , when i receive in PORT B the value 4 , the teensy automatically sends a certain output through PORT E . so i want to have another manual option of setting the same output in PORT E , by clicking a button.
 
So, you need an option in your Teensy program that receives and decodes a command via USB/Serial line.
At that point you should test your program by simulating a GUI button, by sending that command from the Teesnsy Serial Monitor.
If you choose HWSerial you can simply open a Serial terminal to interact with your Teensy program.
Last you create a GUI (say even with LabVIEW) that sends the command upon Button press.
Does this make sense?
 
not really . i understand the general lines but not actual actions i should take .
your saying i can somehow create a command that will go through the serial monitor ?

maybe you can explain in more detail or the best option would be to help me find a link to a tutorial or another thread it'd been discussed thoroughly ?
i can't seem to find something good but perhaps i'm using the wrong keywords
 
not really . i understand the general lines but not actual actions i should take .
your saying i can somehow create a command that will go through the serial monitor ?

maybe you can explain in more detail or the best option would be to help me find a link to a tutorial or another thread it'd been discussed thoroughly ?
i can't seem to find something good but perhaps i'm using the wrong keywords

May be that I do not understand your system setup.
you are saying
when i receive in PORT B the value 4 , the teensy automatically sends a certain output through PORT E . so i want to have another manual option of setting the same output in PORT E , by clicking a button

which means that you want to simulate "reception in Port B of value 4" by pressing a button on a PC that is connected to Teensy.
So either reception of value 4 in Port B OR button press generates output through port E.

So PC has to comunicate with Teensy. Typically this would be a serial protocol (either USB_serial or HW-serial).
This communication requires SW on the PC to generate a command upon Button press and in the Teensy that reacts to this command by sensing something through port E.

If you use USB-Serial, you can use TeensyMonitor, otherwise you could use any Serial Terminal program (e.g Putty)

My suggestion is to first solve the SW part in the teensy (reacting to command from PC) and once this is working to address the GUI (Button on PC) in a second instance.

In order to test I would simulate the PC command with a Serial monitor:
Assume Button press would send character "p" to Teensy, then typing into serial monitor the character "p" should be understood by teensy as a command to generate output on Port E.

So your first task is to modify Teensy program to listen to Serial line and whenever the character "p" is arriving to send output to Port E.
Once you are happy with your modified Teensy program, then it is time to thing about PC GUI.

Does this makes more sense?
 
haha yes!
some clarification : i don't want the button to simulate the value 4 in port B , because (lets call it auto mode) in auto mode in addition to the value 4 , there is a value in port C which determines the amount of time port E will be set high . in my desired manual option , i would have a click-button to set the port E high and a scale to set the amount of time it will be high .

Code:
So PC has to comunicate with Teensy. Typically this would be a serial protocol (either USB_serial or HW-serial).
This communication requires SW on the PC to generate a command upon Button press and in the Teensy that reacts to this command by sensing something through port E.

If you use USB-Serial, you can use TeensyMonitor, otherwise you could use any Serial Terminal program (e.g Putty)

how do i know what are my features ? if i have SW on the pc and if i use USB-Serial ?

Code:
So your first task is to modify Teensy program to listen to Serial line and whenever the character "p" is arriving to send output to Port E. 
Once you are happy with your modified Teensy program, then it is time to thing about PC GUI.
so what you are saying basically is i should first write a code that reads out of the serial monitor ( i'm guessing i'll use Serial.write/read for that ? ) and when it reads a certain character , it initiates my desired function ?
 
i started experimenting with Serial.read and got results , but when i tried Serial.parseInt iv'e got this error message :
Error while setting serial port parameters: 9,600 N 8 1

i got this message many times before but it was always related to the teensy itself or baud rate , this time i'm sure it's got to do with the parseInt because when i use Serial.read the program runs fine , prints and sends the data as i want .

the entire code -

Code:
// PTA (12 13) = [3 4] // ready signal and XS2
// PTB (0 1 2 3) = [16 17 19 18] // For address bits
// PTC (0 1 2 3 4 5 6 7 8 9 10 11) = [15 22 23 9 10 13 11 12 35 36 37 38] // For digital inputs from NI cards
// PTD (0 1 2 3 4 5 6 7 13 14 15 ) = [2 14 7 8 6 20 21 5 51 52 54] // For digital output to marker
// PTE (25) = [34] // for digital output to reward

byte inputPins[] = {3, 4, 16, 17, 19, 18, 15, 22, 23, 9, 10, 13, 11, 12, 35, 36, 37, 38};
byte outputPIns[] = {2, 14, 7, 8, 6, 20, 21, 5, 34, 51 ,52 ,54};
int isMarkerOn = 0;// set to 1 when marker activated , and to 0 when deactivated
//unsigned long T1;
unsigned long rewardON = 0;
elapsedMillis rewardTime;
elapsedMicros markerTime;
IntervalTimer myTimerOne;
IntervalTimer myTimerTwo;

void reward(void) {
  if (!digitalReadFast(3)) {
    switch (GPIOB_PDIR & 0xF) {
        case 4: // reward command received
           rewardON = GPIOC_PDIR;
           //Serial.println(GPIOC_PDIR);
           //Serial.println(rewardON);
           GPIOE_PDOR= 0x2000000;
           //digitalWriteFast(34, HIGH);//reward
           rewardTime = 0;//start counting until stop
           break;
       case 1:
          //Serial.println("markerIFtest - GPIOC_PDIR-");
          //Serial.println(GPIOC_PDIR,BIN);
          GPIOD_PDOR= ((GPIOC_PDIR >>1) & 0xFF) | ((GPIOC_PDIR<<4) & 0xE000);
          //Serial.println(GPIOD_PDOR,BIN);
          isMarkerOn=1;
          //Serial.println("GPIOD_PDOR-");
         //Serial.println(GPIOD_PDOR,BIN);
         markerTime = 0;//start counting until stop
    }
  }
}

void ManualReward(void) {
  if (Serial.available()) {
    rewardON = Serial.parseInt();
    //int rewardON = Serial.parseInt();
    Serial.println(rewardON);
    GPIOE_PDOR= 0x2000000;
    rewardTime = 0;//start counting until stop
    
    
  }
}


//void reward(void) {
  //if (!digitalReadFast(3)  && ((GPIOB_PDIR & 0xF) == 4)){// reward command received
    // rewardON = GPIOC_PDIR;
     //Serial.println("rewardIFtest - GPIOC_PDIR-");
     //Serial.println(GPIOC_PDIR);
     //Serial.println(rewardON);
     //digitalWriteFast(34,HIGH);
     //GPIOE_PDOR |= (1<<25 ); // set bit 25 in PORTB to 1 ,reward
    // Serial.println(GPIOE_PDOR,BIN);
     //rewardTime = 0;//start counting until stop
//  }
//}

//void marker(void) {
  //if (!digitalReadFast(3) && ((GPIOB_PDIR & 0xF) == 1)){//marker command received
    //Serial.println("markerIFtest - GPIOC_PDIR-");
    //Serial.println(GPIOC_PDIR,BIN);
    //GPIOD_PDOR |= (GPIOC_PDIR >>1) & 0x7FF;
   // Serial.println(GPIOD_PDOR,BIN);
   // isMarkerOn=1;
    //Serial.println("GPIOD_PDOR-");
    //Serial.println(GPIOD_PDOR,BIN);
   // markerTime = 0;//start counting until stop
    
 // }
//}

void setup() {
  Serial.begin(9600);
  //Serial.println("enter reward time [ms]");
  //Serial.setTimeout(10);
  pinMode(34,OUTPUT); 
  for (int pinnum = 0; pinnum < 18; pinnum++) {
      //pinMode(inputPins[pinnum], INPUT_PULLDOWN);
      pinMode(inputPins[pinnum], INPUT);
  }
  for (int pinnum = 0; pinnum < 12; pinnum++) {
    pinMode(outputPIns[pinnum], OUTPUT);
  }
  myTimerOne.priority(0);
  myTimerOne.begin(reward,1);
  myTimerTwo.priority(1);
  myTimerTwo.begin(ManualReward,100000);
}

void loop() {
  //T1=micros();
  if ( GPIOE_PDOR>>25 && rewardTime > rewardON) {//if the reward output is being sent for the input time
    //digitalWriteFast(34,LOW);
    GPIOE_PDOR = 0x0;//stop reward
      }
  if (isMarkerOn == 1 && markerTime > 25){//if the marker message is being sent for 25us (maybe the interval is too long\short for some devices)
    GPIOD_PDOR = 0x00;//stop marker 
    isMarkerOn=0;
    //Serial.println(micros()-T1);
  }
 }

the function void ManualReward (void) is being called every 100 ms . if something is being sent through the monitor , its supposed to be red (using praseInt) and than turn on a pin in port E for the amount of time that was red in the monitor .
for example i type and send "200" , than pin E25 is set HIGH for 200 ms .
what happens is as follows :

i type and send , press enter .

the number disappears .

there is a delay of 1 second more or less .

the monitor starts shifting from online to offline and the error message starts printing repeatedly
Error while setting serial port parameters: 9,600 N 8 1
Error while setting serial port parameters: 9,600 N 8 1
...

any ideas ?
 
Status
Not open for further replies.
Back
Top