Go Down

Topic: Is it possible to write a delay from Visual Basic (Read 3035 times) previous topic - next topic

jon5221

Jul 18, 2015, 04:12 am Last Edit: Jul 18, 2015, 04:13 am by jon5221
Hello, I'm working on a small project for school where I'm creating a GUI from Visual Basic C# controlling a few LED's on my Arduino UNO by turning them on or off. So far so good, but I would also like to have the ability to modify the delay time from the same VB app so that I can get them to blink. Is this even possible from VB?


I've looked exhaustively through here...

http://playground.arduino.cc/Main/InterfacingWithSoftware

and all over the internet, but I can't find anything on writing a delay.

Robin2

You can send any data you want to from VB (or any other PC language). The trick is to get the Arduino to interpret it correctly.

How will the Arduino know that a number (say 5375) is intended as a time interval ?

You need to decide a strategy for the Arduino and then make the VB program compatible with that. The examples in serial input basics should be useful.

By the way you CANNOT use the delay() function in the Arduino for what you are talking about. You need to use millis() to manage the timing as illustrated in several things at a time.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

PaulS

Quote
Visual Basic C#
Go wash your mouth out with soap for linking those two languages that way.
The art of getting good answers lies in asking good questions.

jon5221

#3
Jul 18, 2015, 08:49 pm Last Edit: Jul 18, 2015, 08:54 pm by jon5221
By the way you CANNOT use the delay() function in the Arduino for what you are talking about.
Thank you for the reply and the information, much appreciated! And I apologize as I said a "few" LED's when I am actually focusing on adjusting just one LED at the moment.

You can send any data you want to from VB (or any other PC language). The trick is to get the Arduino to interpret it correctly.
Can this data be permanently written, though?

For Example, here is what I made using Amtel Studio and then flashed the Arduino with the ".hex" file using avrdude.

Code: [Select]

/*
 * Blink_LED.c
 *
 * Created: 7/16/2015 11:11:01 PM
 *  Author: Jon
 */

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{

DDRB = 0b00000001;  // Pin B0(8) Output, All others are Input
PORTB = 0b00000000;  // All Pins are OFF

while(1)
{
PORTB = 0b00000001;   // Pin B0 is ON
_delay_ms(1000);  // 1 Second Delay
PORTB = 0b00000000;   // Pin B0 is OFF
_delay_ms(1000);  // 1 Second Delay
}
}


This works well and permanently writes it, but Amtel Studio won't allow me to create a custom GUI (to the best of my knowledge) to manipulate the _delay_ms(); at a later time down the road without going back into Amtel Studio. I can use Amtel Studio at home, but I cannot install it on my Lab PC at school.

Basically, I would like to have the ability to open a custom made GUI from any other location, edit the delay and have it permanently write the new delay again when needed.

All other options I've found out there for making a custom GUI (again, to the best of my knowledge) seem to be limited to controlling the Microcontroller in real-time only, and once the power is removed, it's back to the original delay state it was originally flashed with.

Not sure if there are any other programming solutions I'm overlooking...

Either way, thanks again!




Go wash your mouth out with soap for linking those two languages that way.
I'll get right on that.  ;)

Robin2

#4
Jul 18, 2015, 09:53 pm Last Edit: Jul 18, 2015, 09:54 pm by Robin2
Go wash your mouth out with soap for linking those two languages that way.
Jeez, I thought they were the two sides of the same Seattle coin ?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

jon5221

I'm not looking to just pass information to and from only to be lost after re-powering the Arduino.

Robin, I've read what you linked earlier and I was still unable to find the answer I'm looking for. I just need to know if Serial Input from within VB can write static information permanently to the Arduino or not?

Robin2

I just need to know if Serial Input from within VB can write static information permanently to the Arduino or not?
You did not mention "permanently" before.

If you want data to be remembered when the Arduino powers down you must save it in the EEPROM. Get your Arduino to receive it and then to write the value to the EEPROM. When the Arduino restarts it must read the value from the EEPROM.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MartynC

I have a project that may help (or may not) Arduino and Visual Basic: Controlling an Arduino The Arduino sketch is written in the Arduino IDE and the PC program is written is Visual Basic 2013.

The data sent to the Arduino is within start and end markers and I use Robin2's recvWithStartEndMarkers() function to get the actual data/command. All you would need to do is send the delay value to the Arduino, then write the value to eeprom and then change the actual delay.

On start up, your sketch would need to check eeprom for a delay value and then set the actual delay. I would also add a default value in case there is no value in eeprom.


 



jon5221

#8
Jul 21, 2015, 04:29 am Last Edit: Jul 21, 2015, 04:31 am by jon5221
Get your Arduino to receive it and then to write the value to the EEPROM. When the Arduino restarts it must read the value from the EEPROM.
The data sent to the Arduino is within start and end markers and I use Robin2's recvWithStartEndMarkers() function to get the actual data/command. All you would need to do is send the delay value to the Arduino, then write the value to eeprom and then change the actual delay.

On start up, your sketch would need to check eeprom for a delay value and then set the actual delay. I would also add a default value in case there is no value in eeprom.
Thanks to you both, that is exactly what I was looking for.

And a big thanks to you MartynC, looking over the code in your project helped explain a lot for me

amitshishodia

Thanks to you both, that is exactly what I was looking for.

And a big thanks to you MartynC, looking over the code in your project helped explain a lot for me
My problem also same. i want whatever i change in my arduino code (like delay or other) through visual basic it permanently upload in my board.

eg: when led is turn on with visual basic then disconnect the device after that reconnect the device led remains in on condition.

Robin2

@amitshishodia, please don't ask the same question in two places. You have an answer in your own Thread.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

JelleSiemonsma

#11
Jul 28, 2019, 10:31 am Last Edit: Jul 28, 2019, 10:32 am by JelleSiemonsma
Install visual studio community 2017, install vsmicro for the arduino sketch (all freeware), buy a mega board, a serial to usb converter, some wire, a resistor and a LED. Download the standard AFSM software from my website and write the code in less than a half a day... the AFSM uses standard messages to communicate between a PC and the board, i would use  "markers" for updating the timer values... www.jbsiemonsma.nl. Have fun!

Go Up