Arduino and Visual Basic Part 2 Receiving Data From the Arduino. This post continues from Arduino and Visual Basic Part 1 Receiving Data From the Arduino. Learn how to use an analog thermistor to measure temperature on the Arduino. Output readings to an LCD or the serial monitor in Celsius or Fahrenheit. Arduino i About the Tutorial Arduino is a prototype platform opensource based on an easytouse hardware and software. It consists of a circuit board, which can. This post continues from Arduino and Visual Basic Part 1 Receiving Data From the Arduino. In the previous post we received a stream of data from the Arduino and. A NEWFullfeatured GPSNMEA Parser for Arduino. TinyGPS is a new Arduino library for parsing NMEA data streams provided by GPS modules. Like its predecessor. Secret Arduino Voltmeter Measure Battery Voltage A little known feature of Arduinos and many other AVR chips is the ability to measure the internal 1. In the previous post we received a stream of data from the Arduino and displayed it inside a Visual Basic text box. This is all well and good but we did not know what the data was, we simply received it and displayed it. The next step is to send data that has some kind of meaning and display it in an appropriate field. This could be a temperature, a wind speed, a switch state or anything else. In the following example I am using a 1 wire temperature probe its actually got 2 wires, a potentiometer and a button switch. Commands or Codes. To identify which values are which we will use a simple code attached to the actual value B for button switch. P for potentiometer. T for temperature. So we know when we have a complete data segment or code we will use start and end markers, lt and. The Visual Basic app will ignore anything not inside the markers. The button switch only has 2 states HIGH or LOW pressed or not pressed so a single character can be used for the value. In this example H for HIGH and L for LOW. The full codes are lt BH, button switch HIGH or pressedlt BL, button swtich LOW or not pressed. The potentiometer gives a value between 0 and 1. Arduino Serial Write Float' title='Arduino Serial Write Float' />Arduino Serial Write FloatTo make things a little easier the example uses ascii characters for the value 1. Of course this means the value has to be converted to a string before sending. Pnnnn, P for potentiometer and nnnn the value of the potentiometerlt P0. P1. 02. 3, potentiometer value of 1. In line with keeping things simple, an integer is used to store the value of the temperature probe you would normally use a float. This means we can treat it the same as the potentiometer and use a string of 4 characters for the value 0. Tnnnn, T for temperature and nnnn the value of the temperature probelt T0. T0. 40. 0, temperature probe value of 4. The Arduino Set Up. Set up the Arduino with the following The temperature probe is connected to A0. The potentiometer is on A1. The button switch is connected to D4. Circuit Diagram. Arduino Sketch. The Arduino sketch polls the values of the pins and then, if the value has changed, creates the code and then sends the code out over the serial connection. Sketch Arduino to Visual Basic 0. Receiving Data From the Arduino. Read pin state value and send to a host computer over a serial connection. This is a one way communication Arduino to a host computer. No data is received from the computer. A0 a 2 wire temperature probe sending raw data only. Not the actual temperature. A1 a potentiometer. D4 button switch. The above can be changed to something else. It should noted that no data is sent until something changes. The sketch can be expanded so that an initial value is sent. When DEGUG is TRUE send an newline to the serial monitorconst boolean DEBUG true. Pin A0 const byte pot. Pin A1 const byte button. Switch. Pin 4. unsignedint old. Temp. Val 0 unsignedint new. Temp. Val 0 unsignedint old. Pot. Val 0 unsignedint new. Pot. Val 0. boolean old. Button. Switch. State false. Button. Switch. State false. I am only using 4 digitschar number. String1. 0. void setup set the button switch pin to input. Modebutton. Switch. Pin, INPUT. open serial communication. Serial. begin9. 60. Serial. printlnAdruino is ready. Serial. println. Temp. Val analog. Readtemp. Pin. new. Pot. Val analog. Readpot. Pin. new. Button. Switch. State digital. Readbutton. Switch. Pin. ifnew. Temp. Val old. Temp. Val. Temp. Val new. Temp. Val. Number new. Temp. Val,4. Serial. printlt T. Serial. printnumber. String. Serial. print ifDEBUG Serial. Nic Noc Enfermagem here. The pot I am using jitters 1 so I only using changes of 2 or more. Pot. Val old. Pot. Val 1. old. Pot. Val new. Pot. Val. format. Number new. Pot. Val,4. Serial. P. Serial. String. Serial. print ifDEBUG Serial. Button. Switch. State old. Button. Switch. State. Button. Switch. State new. Button. Switch. State ifold. Button. Switch. State true. Serial. printlt BH else. Conductor Del Libro Manual. Serial. printlt BL. DEBUG Serial. println. Numberunsignedint number, byte digits formats a number in to a string and copies it to the global char array number. String pads the start of the string with 0 characters number the integer to convert to a string digits the number of digits to use. String1. 00 strcpynumber. String, temp. String. String,1. 0. create a string of 0 characters to pad the number. Zeros digits strlentemp. String ifnum. Zeros 0forint i1 i lt num. Zeros istrcatnumber. String,0. strcatnumber. String,temp. String. Load the sketch and open the serial monitor. You should get something like the following Press the button switch and you should get Turn the potentiometer and you should see something similar to Now that the Arduino side is working the Visual Basic app is next. We can use the Visual Basic app from Arduino and Visual Basic Part 1 Receiving Data From the Arduino as the starting point but we need to make some changes. Unlike the previous example, the data is now inside start and end markers and we we need to determine what data we are receiving. Visual Basic App. The program is fairly simple It waits for the user to select a COM port and click the connect button. It then makes a connection the Arduino. Checks for incoming serial data. Parses the data. Updates the form. Here is a screen shot of the Visual Basic App in action. Visual Basic Program. Here is the main form. The form is the same one used in the previous example. New labels have been added to show the temperature, the potentiometer value and the switch state. I have also included labels to show the timer interval and the number of commands processed. I have left the text box and use it to display the current command. You can also use the text box for debugging. The code. Arduino and Visual Basic Part 2 Receiving Data From the Arduino. An example of receiving data from an Arduino using start and end markers. Imports System. IO. Ports. Public Class Form. Dim com. PORT As. String. Dim received. Data As. String Dim command. Count As. Integer 0. Private. Sub Form. LoadBy. Val sender As System. Object, By. Val e As System. Event. Args Handles My. Base. Load. Timer. Enabled False. Timer. Speedlbl. Text Timer speed Timer. Interval. com. PORT For. Each sp As. String. In My. Computer. Ports. Serial. Port. Names. PortCombo. Box. Items. Addsp. Next. End. Sub. Private. Sub com. PortCombo. BoxSelected. Index. Changedsender As. Object, e As Event. Args Handles com. PortCombo. Box. Selected. Index. Changed. If com. PortCombo. Box. Selected. Item lt Then. PORT com. PortCombo. Box. Selected. Item. End. If. End. Sub. Private. Sub connectBTNClicksender As. Object, e As Event. Args Handles connectBTN. Click. If connectBTN. Text Connect Then. If com. PORT lt Then. Serial. Port. 1. Close. Serial. Port. 1. Port. Name com. PORT. Serial. Port. 1. Baud. Rate 9. Serial. Port. 1. Data. Bits 8. Serial. Port. Parity Parity. None. Serial. Port. Stop. Bits Stop. Bits. One. Serial. Port. 1. Handshake Handshake. None. Serial. Port. Encoding System. Text. Encoding. Default very important Serial. Port. 1. Read. Timeout 1. Serial. Port. 1. Open.