• Author
    Posts
  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    #include “stone.h”

    extern unsigned char receive_over_flage;
    extern recive_group STONER;
    extern unsigned char STONE_RX_BUF[RX_LEN];

    String my_name;
    String box_text;
    int my_status;
    int btn_nums=0;
    char btn_numsc[10];

    void setup()
    {
    Serial.begin(115200);
    }

    void loop() {

    serial_receive();

    if (receive_over_flage == 1)
    {
    if(memcmp((char*)STONER.widget,”button1″,7)==0)
    btn_nums++;

    sprintf(btn_numsc,”%d”,btn_nums);
    set_value(“spin_box”, “spin_box1”, btn_numsc, “%02d”);
    receive_over_flage = 0;
    }

    }

  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62
  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62
  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    To detect when a button is pressed, you need to uncheck click_value on the software, then check press_UP_value or presS_down_value. When the screen presses the button, the library functions parse the button instruction and cache the button name and value separately. This code sets a value of +1 for each button press, and then sets this value directly into the spin_box control

  • David BittnerDavid Bittner
    Participant
    @davidcbittner
    Post count: 17

    thanks bowei zhang….. one other question. When I click the button I want to get the value that is currently in the spinbox. This I see works to set the value I need to also get the value too. I’d like to be able to get the values of other widgets too.

    Thanks

    David

  • David BittnerDavid Bittner
    Participant
    @davidcbittner
    Post count: 17

    bowei zhang, I wanted to try your example just to see it work. I am getting some errors when I try to compile this. I’m not familiar with some of these commands as I am somewhat new to the arduino. Thanks for your help.

    serial_receive();
    if (receive_over_flage == 1) {
    if(memcmp((char*)STONER.widget,” button1″,7)==0) {
    btn_nums++;

    sprintf(btn_numsc,”%d”,btn_nums);
    set_value(“spin_box”, “spin_box1”, btn_numsc, “%02d”);
    receive_over_flage = 0;
    }
    }

    ADXL335_angle_display:57:29: error: stray ‘\342’ in program
    if(memcmp(STONER.widget,” button2″,7)==0) {

  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    if(memcmp(STONER.widget,”button2″,7)==0)

    This code should have syntax errors and should be preceded by (char*) as in the example

  • David BittnerDavid Bittner
    Participant
    @davidcbittner
    Post count: 17

    I got it the problem was I cut and pasted your logic and did not notice it had the wrong double quotes when it pasted it

    I now have below and it compiles and loads and runs on my arduino but when i click my button nothing appears in my spinbox

    the button is named button2 and the click value is unchecked and the press down value is checked with a value of 1 in the box next to it. the spin box is labeled spin_box1 any ideas?

    thanks

    David

     

    #include “stone.h”

    extern unsigned char receive_over_flage;
    extern recive_group STONER;
    extern unsigned char STONE_RX_BUF[RX_LEN];

    int btn_nums=0;
    char btn_numsc[10];

    int my_status;

     

    void loop() {

    serial_receive();
    if (receive_over_flage == 1) {
    receive_over_flage = 0;

    if(memcmp((char*)STONER.widget,”button2″,6)==0) {
    btn_nums++;

    sprintf(btn_numsc,”test %d”,btn_nums);
    set_value(“spin_box”, “spin_box1”, btn_numsc, “%02d”);
    }
    }

    }

  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62
  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    To enable the spin_box set_value operation, add a line of spin_box code at this location in the stone_transport.cpp file

  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    sprintf(btn_numsc,”test %d”,btn_nums);

    So you’re storing test in the array, so instead of set_value, you’re using set_text

  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62
  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    if(memcmp((char*)STONER.widget,”button2″,6)==0)

    Isn’t button2 here 7 characters long?It should be

    if(memcmp((char*)STONER.widget,”button2″,7)==0)

  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    I think it should look something like this after I’ve changed the previous one

     

    #include “stone.h”

    extern unsigned char receive_over_flage;
    extern recive_group STONER;
    extern unsigned char STONE_RX_BUF[RX_LEN];

    int btn_nums=0;
    char btn_numsc[10];

    int my_status;

     

    void loop() {

    serial_receive();
    if (receive_over_flage == 1) {
    receive_over_flage = 0;

    if(memcmp((char*)STONER.widget,”button2″,7)==0) {
    btn_nums++;

    sprintf(btn_numsc,”test %d”,btn_nums);
    set_text(“spin_box”, “spin_box1”, btn_numsc);
    }
    }

    }

  • David BittnerDavid Bittner
    Participant
    @davidcbittner
    Post count: 17

    bowei zhang, Thank you for the example I got it working. It is working and now when I tap my button the spin box increments. My next question is how do I get the value from the spin box? It is incrementing fine thats not a problem anymore but what will happen is I am going to populate my spin box at startup with a number like 90. I will then use the spin box control to increment it to maybe 95. When I tap on my “Save” button I would like to get the new text value of the spin box so I can save it. I see in the UART instructions there is get_text function but I can’t get that to work either.

    Thanks again for all your help.

    David

  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    Don’t mention it,Spin_box control in the data changes will be automatically issued instructions, so generally do not need to use get_text, as follows

  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    If you set the spin_box input type to int, then the four bytes of 00 00 00 5B will be the data bit. The serial port library will store the four bytes of data in the variable STONER. Long_value. So all you need to do is assign this variable to your user variable

  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    //Here’s an example:

    #include “stone.h”

    extern unsigned char receive_over_flage;
    extern recive_group STONER;
    extern unsigned char STONE_RX_BUF[RX_LEN];

    String my_name;
    String box_text;
    int my_status;
    int btn_nums=0;
    char btn_numsc[10];

    long box_value;
    char box_numsc[10];

    void setup()
    {
    Serial.begin(115200);
    }

    void loop() {

    serial_receive();

    if (receive_over_flage == 1)
    {
    if(memcmp((char*)STONER.widget,”button1″,7)==0)
    {
    btn_nums++;
    sprintf(btn_numsc,”test%d”,btn_nums); //Converts floating point numbers to strings
    set_text(“spin_box”, “spin_box1″, btn_numsc);
    }

    if(memcmp((char*)STONER.widget,”spin_box1”,9)==0)
    {
    box_value=STONER.long_value;
    Serial.println(box_value);
    }

    receive_over_flage = 0;
    }

    }

  • David BittnerDavid Bittner
    Participant
    @davidcbittner
    Post count: 17

    bowei zhang, got it I understand now. It is working just as I need it too.

    One thing I noticed with the spin box. I have the font set pretty big so I can see it easily. when I tap the spin box and start to change the value whether I use input from the keyboard or use the arrows to change the value as soon as the spin box gets focus the font size reverts back to a smaller font making it real hard to see. Is there a way to stop this so the font size stays big? I included some pictures of my screen so you can see what I mean.

    Thank you

    David

     

    Attachments:
    You must be logged in to view attached files.
  • bowei zhangbowei zhang
    Participant
    @zbw3366
    Post count: 62

    This is set up on the app, there’s a state option, you can go to the selected state and then you can adjust the font again

  • David BittnerDavid Bittner
    Participant
    @davidcbittner
    Post count: 17

    bowei zhang, I see that now! That is very versatile I like that. Thank you very much for your help. I think that is all for now. Everything seems to be working exactly the way I want

    Regards

    David

  • FABIAN GARCESFABIAN
    Participant
    @user212
    Post count: 2

    Hi David,

    Quick question, do you have one of the 5V HMI models? If so, can you help me out on the connection (pin out) for the Arduino and HMI to connect? I have tried all types of tutorials and so far I have only been able to receive data. For some reason the data won’t send.

    Thank you in advance

  • David BittnerDavid Bittner
    Participant
    @davidcbittner
    Post count: 17

    Fabian, I have the STWC050LT-01 I got from Amazon https://www.amazon.com/dp/B09QKX4L5R?psc=1&ref=ppx_yo2ov_dt_b_product_details

    I took one of the cables (2 came with it) and cut off one end and crimped on a header so I could use some jumpers to hook it up. I am using an ArduinoUNO to do my testing. Here you can see the inner 2 wires on the ribbon cable are the TX and RX wires.

    One thing to note you can not have the arduino plugged in with the USB cable to program it at the same time you are trying to communicate with the LCD screen through the arduino.

    Let me know if this helps.

    David

     

     

     

    Attachments:
    You must be logged in to view attached files.
  • David BittnerDavid Bittner
    Participant
    @davidcbittner
    Post count: 17

    sorry I meant to send 2 pictures

     

    Attachments:
    You must be logged in to view attached files.

You must be logged in to reply to this topic.