Posts

Showing posts with the label file

Serial Communication Tutorial (Part 3)

Image
In the previous two parts of the this tutorial, we went through a number of simple sketches to get you acquainted with the way that the Arduino handles various data types when passed through the Serial COM port. Here are the main themes from part ONE : Stage One:   Echoing data with the Arduino Stage Two: Using Delimiters to split data. Stage Three: Arduino Maths, simple addition Stage Four: Sending a double to an Arduino, and then doubling it. Stage Five: Sending Sensor data from the Arduino to the Serial Monitor Here are the main themes from Part TWO : Stage Six: ......A simple Processing Sketch Stage Seven:  Arduino and Processing join forces for more fun Stage Eight: A simple project that shows Serial communication from Arduino to Processing In Part Three - we will reverse the direction of communication and get Processing to send data to the Arduino via a USB cable, Stage Nine: A simple processing sketch that switches an LED on the Arduino Stage Ten:   A processing...

Reading from a Text File and Sending to Arduino

Image
The following tutorial will demonstrate how to Read values from a Text file (.txt, .csv) to blink 1 of 9 LEDs attached to an Arduino. It uses the combination of an Arduino and Processing program to process the file. The Processing program will read the text file in real time, only sending new information to the Arduino. Components Required Arduino UNO Breadboard 9 LEDs 9 x 330 ohm resistors Wires to connect the circuit USB connection cable : to connect the computer to the Arduino A computer : to run the processing sketch, and to compile / upload the Arduino sketch Processing Program installed on computer Arduino Program installed on the computer A comma separated text file (*.txt). Arduino Layout The Text File Open Notepad or equivalent text file editor, and paste the following data into it. 1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1 Save the file on your hard drive. In my case, I have chosen to save the file at this location. D:/mySensorData.txt It should look like the follow...

Reading a text or CSV file using the Processing language

Image
In a previous post , I showed you how to export data to a text file. Now I will show you how to import it back into your Processing program. This will come in handy later on. This is what my data looks like in the text file: There are many ways to import text from a text file, and there are many ways to store the data within your code after you have imported it. Feel free to make mention of your method in the comments, however, this one definitely works, and is doing what I want it to do. I have decided to store each line within an ArrayList . The first column is stored in another ArrayList by splitting the data into bits using splitTokens . Most of the file reading code was taken from  this Java site , and seems to work quite fine with the Processing programming language . I have taken bits and pieces of code from various places, and added my own flavour. Here is a snippet of the data after import. ...

How to append text to a txt file using Processing

Image
Sometimes it would be useful to have a function to save data to a text file. I plan to save some of my Arduino sensor data to a text file using the Processing language . Ninety percent of the following code comes from this forum posting . Thank goodness for the internet, and for people like PhiLho and Cedric. I modified their code and ended up with this (to suit my own project): Processing Sketch 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 /* =====================================================================      Project : Append data to a text file       Author : ScottC      Created : 16 Nov 2011  (Updated 26 Aug 2014)  Description : Use the Processi...