Arduino Tutorial 06: Processing

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello Daniel just here and welcome to my sixth Arduino tutorial from my Arduino tutorial series today I will talk about processing development environment I will give an example where I will use the processing development environment to control the Arduino board and vice versa processing is an open-source programming language and integrated development environment it is largely graphic based so it's ideal for Electronic Arts new media art and visual design communities you can download it from its official website similar to the Arduino development environment and just extract it on your computer also you can find a lot of examples and tutorials for using it processing looks similar to the Arduino development environment because actually the Arduino programming language is based on processing ok so for the example we are going to do first we have to make a code using the Arduino developing environment and upload it to the Arduino board that code will enable interaction between the processing development environment and the Arduino board using the serial communication after that using the processing development environment we will make an application for controlling the Arduino board ok so I will use the exactly same code we develop in the previous tutorial so the previous tutorial was for serial communication and I highly recommend it watching it because that's the base in order to understand the communication between the Arduino and the processing so first I will give a quick overview for this code that we are going to use to program the Arduino card so here for the first example we'll use this code and this code we will first define the the two bins that we are going to use that will be for the LED and for the button and in the setup we will initialize them as an output ET and input and also we will start the serial communication now in the loop we will build our program first we will start with this if statement here and this this means that we will see if something is a valuable in the in the serial port or if we have sent something from the computer to the Arduino and there is a data for transferring this statement will be true and the following code will execute it and here we are reading that value or what we have typed in the serial monitor and according to that we will turn on or off the LED so we type 1 the LED will turn on and if we type 0 the LED will turn off and for the second part here we we have a we will read the button state or whether the button is pressed or not and we we have here we are sending data from the arduino to the computer when the button is pressed and the we will print that on the serial monitor so using this code we are demonstrating the serial communication between the computer and the Arduino card so now instead of using the Arduino serial monitor for controlling this commands will connect the Arduino board to the processing development environment and using the serial communication we will control these commands with processing okay so first we need to import the library for serial communication you do it like this we need to do this because the serial library is not a default library here in processing like it was in the hard we know also we need to create object from type serial I will name it my port and as drink I will name it my text and here we will put the values we're getting from the serial port from the Arduino does the des detects a button is pressed and we will get that when the button is pressed actually okay now in the setup first we will set a resolution for the graphical window here in processing so using this size we will set the resolution 300 by 300 pixels okay and now we have to initialize the serial port just like we were doing in the Arduino with serial dot begin function here is a bit different we do it like this here we set the name of our comfort from my computer of my Arjun is connected to comport for you should you should checks what's a pure comfort or but this is only for Windows for Linux and Mac this here is a bit different this is the bar right okay so and here I will use the buffer until function and what this does is it's buffering and when we win waiting until we get something or in our case that the backslash n which is a special character character that indicates a newline so this means when we'll hold the button what we will get in the Arduino serial monitor is the text button is pressed and it will always be in a new line because we are using the function println so that means here in the processing we will read the values from the serial port until there is a new line in our case that will be the the text button is pressed okay now test for the setup okay so now we will look for a serial event we do it like this and now so when there is a serial event or a data camp coming to the processing we will read that and put it into the my text variable as a string so write my text variable we'll get the value coming from the serial port using this read string until function which will read what's in the serial port until there is a new line and that means we will read the button is pressed text that is coming from the Arduino when the button is pressed okay now in the draw function here this is actually repeating all the time and this is what it updates the graphical screen first we will set the background I will set the black background and now I will set the text on the screen using this function text and we will set the text in the variable my text and this will be the starting coordinates for the text okay and now I will reset the value of the variable so that when we release the button there will be no text on the screen okay and for the second part for the control of the LEDs will make these if statements mouse press and mouse button go to the left so what this means is mouse press is a reserved variable that gets the value whether the mouse is pressed or not and the mouse button indicates a whether that's the left or the right button so if we press the left button on the screen we will send to the serial port character 1 and that will turn on the LED and if we send zero that bill will make to get it to turn off so if we press the right click we will send to the serial port a character zero and that will turn all of the le so let's see how this work let's make quick overview of the codes with these lines here the write functions we are transmitting data from processing and through the serial port we receive that data into arduino using the serial dot read function using the serial dot println function we are transmitting data from arduino and through the serial port we receive that data into processing using the red string until function so here when I will press the Run button the application will start this is the graphical window and we set a black background and now when I will click on the Left button the LED turns on and with the right click of the button the LED turns off and we can also notice that the eric's LED on the Arduino card flashes that piece that the Arduino is receiving data from the computer through the serial communication port and here when we will press the button we can see the text button is pressed and also see the TX TX LED flashes that means that the Arduino is transmitting data to the serial port to the computer if you have any questions you can ask them in the comment section and also if you like my videos please subscribe like and share them
Info
Channel: How To Mechatronics
Views: 108,516
Rating: 4.9419298 out of 5
Keywords: Processing (Programming Language), Arduino (Brand), Software (Industry), Tutorial (Media Genre), Arduino Tutorial, Serial Communication
Id: yOMglntmmnA
Channel Id: undefined
Length: 13min 42sec (822 seconds)
Published: Mon Feb 02 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.