22 Sep 2009CPOL
Arduino Serial Input Basics

These notes explain the basics of getting two computers talking to each other using. See the Arduino serial lab, the Serial Input to the P5.js IDE lab or the Serial Communication with Node.js lab for more on sending serial from Arduino to another computer. I'd like start this thread for introducing samples about Arduino and Small Basic. At first, I will introduce an Arduino simulation program written by Tryhest (NCH457 - with a little modification). Input Pullup Serial (ARDUINO Examples Digital) Nonki Takahashi. Friday, September 1, 2017 9:57 AM. Digital Input from a ESP8266 NodeMCU Development Board. There will be many occasions in your projects where you want measure a high or low input. This high or low input may source from a switch or it may be a signal from another device.

How to use Visual Basic with the Arduino 2009 board.

Introduction

I have an Arduino 2009 board setup with a simple temperature monitor: http://arduino.cc/en/Main/ArduinoBoardDuemilanove. I wanted to use Visual Basic to communicate with the board and build a graphics display page. Arduino provides interface code for various other languages. There is also a very professional interface to Visual Basic available using Fermata written by Andrew Craigie: http://www.acraigie.com/programming/firmatavb/default.html. This is written so that a component can be added to the toolbox. This component can then be simply dragged onto any form to make it available to code within your project. Using this method hides the actual interface code from the Visual Basic programmer. There is an extra layer of code below your program.

The Firmata library implements the Firmata protocol for communicating with software on the host computer. As such, the library must be included in the Arduino board firmware, using up scarce program storage: http://arduino.cc/en/Reference/Firmata. As I did not need most of the methods available with this application and wanted to make the program as simple as possible, I decided to write my own code for the interface.

All the functions are in classes as this brings discipline to the coding.

Program requirements

The Arduino board samples the temperature every 10 seconds. After 6 such samples (1 minute), the board checks the serial input. If it is sent 'SSSSSS', it will send the sample value on the serial output. If not, the sample will be stored on EEPROM. So, if the user's computer is not sending 'SSSSSS', the samples will be stored on the EEPROM until it is full (1024 bytes).

If the serial input is 'U', all (if any) of the stored EEPROM samples will be sent on the serial output. So the user's computer will at the start send a 'U' to check for and then upload stored samples. After that, it will look for a sample using 'SSSSSS' every 1 minute.

On closing, the user computer will save the samples in a user folder. These previously stored samples will be available to the user to view at any time the program is running.

Serial connection

The Arduino uses a FTDI USB to serial port chip. This enables the board to appear as a serial port via a USB connection. When first connected, I direct Windows to the FTDI driver. After loading the driver, my computer allocated com8 for the Arduino. Communication then is just a matter of sending and receiving strings on com8.

Upload_stored class

Arduino Serial Input Basics Chart

When the user form loads, I upload any stored samples available. As this runs before the form is activated, I let this code run on the form's thread.

The serial input code is enclosed in nested Try Catch blocks. The outer block is for if com8 is being used by another program or the Arduino is not connected. The next block catches if a response is not available within 20 seconds. The inner block catches any loss of connection every 100 msec.

Input

Read_current class

The serial code is very similar to upload_stored, but as we now need to access the form during serial communication, this code is run on its own thread. This complicates the program as Windows controls are not thread safe. This means that we have to bend over backwards to use them from a thread we start. This involves using a delegate subroutine that will run on a thread that owns the underlying handle of the form. This is achieved using the Invoke (delegate) method: http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx.

In a class, we can reference a label as form.label2, but we cannot do the same with form.invoke .It will compile OK, but give a runtime error of no handle available. We have to create an instance of the form in the class and then reference that in the code.

We instantiate the class by:

Display class

Arduino Wait For Serial Input

This uses simple graphics on a bitmap to display the temperature samples.

Display_files class

This displays 24 (or less) hour samples that have been saved by the program. The date time for the samples are used as for the file names so that the time and date can be displayed on the graphics.

Arduino firmware

The C++ code is shown here with comments. The Arduino sketch is include in the zip file:

Arduino hardware

Arduino Read Serial Input

The schematic is drawn using Eagle: http://www.cadsoft.de/download.htm. The files are in the zip file.

Arduino Serial Input Basics Free

The bread board picture is drawn using Peeble: http://rev-ed.co.uk/picaxe/pebble/. The files are in the zip file.

Input

Serial Input Arduino

Arduino Serial Input Basics Download

Hi all, this is my first instructable documenting the creation of my project, the Arduino UNO BASIC shield which turns the Arduino UNO into a computer running the BASIC programming language.
As microcontrollers are essentially low performance computers on a chip (they have a processor, RAM and ROM) they can be used to create small computer systems. The aim of this project was to use AVR microcontrollers to create a computer capable of running the BASIC programming lanuage.
During learning about the Arduino and creating various sketches, I came across the TinyBASIC project which turns the Arduino into a computer by running a BASIC interpreter. After testing the TinyBASIC sketch on my Arduino UNO, I found the available program memory to TinyBASIC to be fairly low at around 1KB which led me to purchasing an ATmega 1284P. After successfully getting TinyBASIC to run on the 1284P, I found the program memory available to be more than 13KB meaning more than a 13x increase in available memory compared to the Arduino UNO.
Being able to run TinyBASIC on the 1284P then led me to think about standalone computers based on the 1284P and TinyBASIC. I alerted the TinyBASIC sketch to include the TVout library and the PS/2 keyboard library but it would not work (due to the PS/2 library and TVout library not being compatible with each other) meaning I needed a second AVR running either the PS/2 library or the TVout library to allow the computer to function correctly.
I decided to use the Arduino UNO which is based on the ATmega 328 to run the TVout sketch while the 1284P would run the TinyBASIC sketch (with the PS/2 library included); it was done this way around to give TinyBASIC the maximum amount of SRAM possible as TVout requires a RAM buffer.
I knew from previous projects that TVout runs fine on the Arduino UNO and after testing TinyBASIC with the PS/2 library on the 1284P (which worked correctly) I decided to place all components on an Arduino UNO shield.