How to send value to Arduino from TrackBarWithIndicator (slider)?

Support forum for MegunoLink
Mike6000
Posts: 1
Joined: Sat Dec 01, 2018 2:07 pm

Sat Dec 01, 2018 2:16 pm

Hi How can I send a value to Arduino from TrackBarWithIndicator?

I tried:

Code: Select all

float tmp = MyPanel.GetValue(F("TrackBarWithIndicator1"), "Value");
but that doesnt even compile on the Arduino side.

On the pc side I set up this ValueChangesCommandLine [TrackBarWithIndicator1.Value]

What I am trying to do is to set some float variables in Arduino from 6 sliders in the Megunio user interface on my PC.

Info: I am using Teensy and the MegunoLink.h include works fine. I am also able to send data from the Arduino (Teensy) to the PC plotting the data in a time plot. I am using the demo version of Meguno. Is Menunolink a discontinued product or is it under current and active development by the way?

Please give some example code on how to send data from PC to Arduino.
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Sun Dec 02, 2018 1:07 am

Hi Mike, check out this example which is part of our library
https://github.com/Megunolink/MLP/blob/ ... apBack.ino

We also include an example megunolink project which you can use to see the example in action.
https://github.com/Megunolink/MLP/tree/ ... erSnapBack

Basically this example will receive the slider value and store it in the variable SliderValue. You can then do what you want with it. In your application you just need to duplicate this 5 more times with further sliders.

This example is set to return the sliders back to the 0 position after the user drops the setting. You probably dont want this so just remove this line.
MyPanel.SetNumber("MySlider", 0); //Return the slider to zero position

Cheers
Phil
hugh
Posts: 14
Joined: Sat Dec 31, 2016 4:59 pm

Sun Dec 02, 2018 4:07 pm

Hi, Sorry if I am hijacking the thread, but I am also interested in this.

Please can you show some example code to return the string from a text box? I have been all through the documentation and whilst there are lots of examples of setting values in controls, I can't find any examples of reading the control values into an Arduino program.

Regards, Hugh
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Mon Dec 03, 2018 8:02 am

Hi Hugh, if you are using the Arduino library you need to use this command
Panel.GetValue(F("MyNumber"), F("Value"));

Where "MyNumber" is the name of your control and "Value" is the name of the property you want.

As an example. Lets say you have a textbox called "IPTextBox1" and its "Text" property is currently set to and displaying "hello". Then when you send this message to MegunoLink
Panel.GetValue(F("IPTextBox1"), F("Text"));

MegunoLink will respond with this message
{UI|set|IPTextBox1.Text=hello}

You would then need to decode this message yourself which could be tricky.



A better option is probably to use a Message Library like the time sync example
https://www.megunolink.com/documentatio ... egunolink/

Then you could generate whatever message you want to be replied whenever you call the command. For example you could take the text from a text box and include a ! at the start and \r\n at the end and use our command handler to process the message.

Ill try to set some time aside to generate an example for you guys.
Cheers
Phil
hugh
Posts: 14
Joined: Sat Dec 31, 2016 4:59 pm

Mon Dec 03, 2018 8:15 pm

Hi Phil,

Thanks for the reply. Unfortunately I still don't understand. What I am hoping for is to use similar code to the way in which I set a controls properties like the example below.

InterfacePanel shutterData("myConsole"); //Create an InterfacePanel variable and pass the channel name

shutterData.SetText("conDatHome", "AT HOME");

So, something like:

myString = shutterData.GetText("conDatHome", value);

or perhaps

myString = shutterData.GetText("conDatHome", text);

and for a numeric based control

myNumber = shutterData.GetValue("conNumericControl", value)

Then I can cope with either parsing the returned string or converting it to a numeric format. Is this - or can this be made to be possible?

Thanks, Hugh
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Tue Dec 04, 2018 8:29 am

Hi Hugh, unfortunately that is not how it works. We cant sit there waiting for a serial message to arrive as we wont know what the start and end looks like. You would need to use something like our command handler which looks for an ! at the start and a \r\n at the end.

So if you requested the text from a text box it would work if that text was something like "!Temp 50\r\n" and you were running our command handler. We would detect the ! and \r\n and then process the command allowing you to get the number 50 out.

Its much better if you can push your settings over to the arduino rather than it requesting them.

I'll still try build an example for you over the weekend.
Cheers
Phil
hugh
Posts: 14
Joined: Sat Dec 31, 2016 4:59 pm

Tue Dec 04, 2018 8:38 pm

Hi Phil,

Thanks for the explanation. To clarify from my side, I have attached the MegUnoLink application I am using. Basically this is a controller for an astronomical observatory where I am controlling the dome rotation azimuth and opening / closing the shutter. Both are moved using stepper motors and I use the Accelstepper library to control the motors.

If you look at the SETUP tab, I have the facility to set various parameters that alter the speeds, distances etc. For each parameter I can set a numeric value and, by pressing the adjacent button, transfer the value to my Arduino. The new value will be used for the remainder of the session. There is also a button that allows me to make the change permanent by saving the revised value into the Arduino EEPROM. So far so good, but when I tested this I realised that the 'natural' way of using it was to go down the list of up/down controls, setting the values I wanted then saving them all by pressing the Save To EEPROM button. Which didn't work of course because as I hadn't pressed the individual setting buttons, all I was saving was the unchanged, existing settings. That's when I decided what I wanted the Save To EEPROM button to do was to read the values in the numeric controls, set the values in the struct I use to hold the parameters and only then save the struct to EEPROM.

If you can think of a way to manage this, I would be very grateful.

Regards, Hugh

Oh Dear - The system won't let me attach my MegUno app as a .mlx file - or indeed as a .txt file. How can I send you my code?
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Wed Dec 05, 2018 5:00 am

Hi Hugh, send it to support@megunolink.com

Cheers
Phil
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Wed Dec 05, 2018 5:05 am

Ha I replied before giving advice. Can you combine your EEPROM save message to include all of your settings. i.e.

Say you had two numeric up down controls (IPNumericUpDown1 and IPNumericUpDown2). You could send them all in the message to save to the eeprom.

So message would be
!EEPROM [IPNumericUpDown1.Value] [IPNumericUpDown2.Value]\r\n

And that would send say !EEPROM 50 34\r\n which the command handler could process as usual and trigger an EEPROM save once the variable have been pulled out.

Does that make sense?

Cheers
Phil
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Wed Dec 05, 2018 5:07 am

See this example for help
https://github.com/Megunolink/MLP/blob/ ... meters.ino

The function SetTurtleCount pulls an integer out as a parameter. You simply call NextParameterAsInteger() twice to get each parameter then write these to the eeprom.
Post Reply