Cara Menghubungkan Visual Basik Ke Arduino

10.08.2019

Artikel kali ini akan melanjutkan tentang Arduino dan ESP8266, yang pada kesempatan kali ini saya akan mencoba menampilkan data sensor arduino pada aplikasi yang dibuat dengan Visual Basic, menggunakan software Visual Studio 2015 Cara Monitoring data Arduino ke Visual Basic ESP8266 ini adalah cara kerja program yang saya buat untuk menampilkan.

Cara Menghubungkan Visual Basik Ke Arduino

After creating the dropControllerBT app and realizing how much easier controlling the dropController device is through the app I started to think about creating a PC app. I haven’t done any PC programming for many years and so I looked at what various options are currently available. Visual Basic kept being recommended for ease of use and quick development. Visual Basic comes as part of Microsoft’s Visual Studio Suite and I initially download and played with Visual Studio Express which in turn lead to Visual Studio Community. Both are free for personal use.

Visual Studio Express is a striped down version of the larger packages and has some major limitations. Visual Studio 2013 Community, on the other hand, is a full featured IDE and development system free to use for students, open source contributors and small development teams. It includes several languages but for now I am only interested in Visual Basic.

Visual Studio 2013 Community is available for download at https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx. The download is just the installer which will download the main program from the internet. If, like me, you prefer an off line installer, you can get one at http://go.microsoft.com/?linkid=9863609

The main download page is at https://www.visualstudio.com/downloads/download-visual-studio-vs

After installing the software it took me a while and many Google searches before I started to figure out the IDE. For me, fully learning the IDE is beyond what I want and have time for but over the course of a weekend I managed to create my first working program. A simple example of receiving data from the Arduino.

Arduino to Visual Basic 2013 Communication

The example uses a very simply form and shows what ever it recieves from the Arduino in a text box.

The Arduino Sketch

The Arduino Sketch sends the string “1234” over the serial connection once every second. At the same time it blinks the built in LED on pin 13.

To test that the sketch is working you can open the serial monitor:
You are likely to be using a different COM port.

The Visual Basic Program

Here is the form:

The form includes:
– a drop down list that contains the available COM ports
– a Connect / Dis-connect button.
– a label to show if the timer is active or not
– a text box where the received data is displayed.
– a CLEAR button that clears the contents of the text box.

And here is the program:

The program in Detail

I am using two global variables; comPORT and receivedData. comPORT is the COM port selected by the user and should be the one the Arduino is connected to. receivedData is the data received on the selected COM port


When the program is first run, the Form1_Load() subroutine populates the COM port combo box / drop down list with the available COM ports. The program then waits for the user to pick one.


When the user selects a COM port, the value is copied to the variable comPORT. This is not really necessary as the selected value can be read from the combo box but I like to keep this kind of data in easy to use variables.


Sub connect_BTN_Click() triggers when the user clicks on the Connect button. The first thing the routine does is determine if the user is connecting or dis-connecting. The same button is used for both.
If connecting, and comPORT is not empty, then the serial port properties are set, the serial port is opened and the timer is started. To show that the timer is active the timer label is updated to “Timer: ON”.
If comPORT is empty a message is displayed telling the user to select a COM port first.
If dis-connecting, the serial port is closed, the timer is stopped and the timer label is updated to “Timer: OFF”.

The Timer label is there purely for debugging.

Visual basic 6.0


A timer is used to check for incoming data. The timer is set to trigger every 500ms or half a second and when triggered it calls the Timer1_Tick() routine. For this example 500ms is fast enough. For more complex tasks the timing may need to be adjusted.


Timer1_Tick() calls a second subroutine that checks to see if there is any serial data and if there is it then copies the incoming data to the receivedData variable.
receivedData is then added to the textbox.


The final subroutine, Sub clear_BTN_Click(), simply resets the contents of the text box.


Trouble Shooting

If you are not receiving data in the VB program but the Arduinos serial monitor works then on the serial port within VB, set “DtrEnable = true” and “RtsEnable = true”. Thank you Banause for the tip. This seems to be required for the Arduino Leonardo.


This is a very simple example that I used to learn the basics on making a serial connection between the Arduino and a computer. As such the code can be made much better.
– The COM port is left open all the time and for more complex applications it may be better to open and close the port as required.
– The application simply displays what ever data is received. There is no error checking. To make it more reliable and to ensure you have all the data it would be better if the data was enclosed in start and end tags and then parsed.

For more information on serial communication with the Arduino and using start and end makers take a look at Robin2’s Serial Input Basics on the Arduino forum.

The error messages were saying that the folder was corrupted and that I should download the folder again. Bomb squad game. Of course, this is the doing of the cheat websites, trying to trick people into filling in another survey.


Download

Download the Visual Basic project files and the Arduino sketch

ArduinoVisualBasicSerial.zip 87.82 KB

You will need to have Visual Studio installed to use the VB project files.

Cara Menghubungkan Visual Basik Ke Arduino Download


Next Steps

In part 2 we take this further. And in part 3 we start to control an Arduino


Sekarang saya akan mencoba mengirimkan data berupa angka random ke ThingSpeak menggunakan ESP8266.

Untuk cara menggunakan ThingSpeak dapat dilihat pada tutorial sebelumnya.

Alat yang dibutuhkan :

1. Arduino Uno
2. ESP8266 Module (ESP-01)

3. Breadboard
4. Resistor 1k, sorry gbrnya salah…

Berikut kode sketchnya :

Hasil yang terlihat pada ThingSpeak:

Ada data yang panjang dengan nilai yang sama dalam waktu yang panjang dikarenakan modul wifi sedang idle selama memcoba browsing coding di internet.

Proses yang terlihat di serial monitor:

Selamat belajar…

Selamat pusing…

Comments are closed.