Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Serial Communication using ‘Processing’ – Open Source Language

By Ganesh Selvaraj November 6, 2013

Processing is a Java based open source programming language and IDE (Integrated development environment) used for writing and running programs on a computer.
The main advantage of Processing is that it allows people with less or no knowledge on programming also to learn programming easily and become experts. Processing accomplishes this by providing numerous examples and tutorials pre-loaded in the software itself.
What we will use Processing is for letting our development board (Arduino/ ATmega8 Dev. Board/ ATmega16 dev. board) to communicate with the PC/ Laptop running Processing.
Software Requirements
      1.      PC/ Laptop running Windows 7/XP
      2.      Java Development Kit 7 (Download at www.oracle.com)
      3.       Processing 2.0 or above (Download at http://processing.org/download)
Hardware Required (For Testing)
1.      Arduino/ ATmega16 / ATmega8 Development board running at 16MHz
      2.      1 x LED
      3.      1 x 330 ohms resistor
      4.      USB to UART adapter  
Processing Development Environment (PDE)
Launch the software and now what you see is the Processing Development Environment. And yes it looks like a color changed Arduino IDE. It consists of a text editor, a compiler, and a display window
Screenshot showing different sections of Processing Development Environment on Windows
Fig. 1: Screenshot showing different sections of Processing Development Environment on Windows

Access Example Codes
Click on File menu
Screenshot of File Menu on PDE
Fig. 2: Screenshot of File Menu on PDE
You’ll find “Examples”. Click on that and a new window will pop-up.
Screenshot of Examples Window on PDE
Fig. 3: Screenshot of Examples Window on PDE
Here you will find number of examples which teaches how to use each and every functions present in the software. And the best part is that it has been categorized very neatly so we can easily find what we want.
Running an Example code
We’ll basically we are interested in making our computer communicate with our development board so let us start with a program related to serial communication first.
Go to Examples->Libraries->serial and double-click “SimpleWrite” to open the program
Screenshot showing navigation to libraries related to serial communication on PDE
Fig. 4: Screenshot showing navigation to libraries related to serial communication on PDE
 
Screenshot of SimpleWrite Library on PDE
Fig. 5: Screenshot of SimpleWrite Library on PDE
Now of course the program is 100% correct but it needs a small change to run according to our need. We need to change the COM Port number depending upon which COM port your device (Arduino/ ATmega8/ ATmega16 dev. board) is connected to.
For this, first find the following line in the program
String portName = Serial.list()[0];
Now replace “Serial.list()[0]” with the COM port number to which the development board is connected. In my case it was connected to COM9 so I edited it like this:
String portName = “COM9”;

 Processing Codes and Setup

What the processing Code does?
Well basically it starts a serial communication with the device connected at the COM port mentioned by us. Then it continuously sends the character “H” (if the mouse pointer is on the rectangle) or “L” (if the mouse pointer is moved away from the rectangle) to the device.
Now let us look into the code for our development board which would be used to test the processing code.
Note:The code for Arduino is given within the processing code as comments below the actual code. Scroll a bit down in the example program and you will find it there.
Screenshot of Arduino Code on SimpleWrite Library
Fig. 6: Screenshot of Arduino Code on SimpleWrite Library

 

ATmega16 Code Explanation
       ·         Initialize the USART function of the controller with required baud rate.
       ·         Set PORTB’s first pin (i.e. PB0) as output.
       ·         Enter into an infinite loop.
       ·         Read a character from the RX line using the “BlueRdChar()” function.
       ·         If the character received is “L” then turn OFF the LED at PB0 or if the character is “H” then turn ON the LED.
Setup Instruction
     1.      Burn the given “Test.hex” file into the microcontroller or use the given c program to compile and generate the hex file on your own using a suitable complier like WINAVR with ATMEL STUDIO/AVR STUDIO or other software.
Since our board is supposed to run at 16MHz make sure the fuses of the IC are set as follows:
High fuse=0xC9
Low fuse=0xFF

 

(Warning: Be very careful while programming the fuse bits. If you set it with wrong values then the microcontroller may be permanently disabled.)
      2.      Connect the development board to the computer. Then RUN the code by clicking on the following symbol.
Image of Run Symbol
  Fig. 7: Image of Run Symbol
     3.      Now hover the mouse pointer over the rectangle and if everything is done correctly then you should see the LED connected to the development board turn ON.
This is just an example code and there is lot more you can do with this software which I would be showing you in the next tutorial.

 

Project Source Code

###

*******************C Program****************** /*
 * proces.c
 *
 * Created: 10/19/2013 7:22:03 PM
 *  Author: GANESH SELVARAJ
 */ 


#define F_CPU 16000000UL

#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

#include<avr/io.h>
#include<util/delay.h>


void BlueInit()
{
UCSRB |= (1 << RXEN) | (1 << TXEN); // Enable transmission and reception

UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1);
// Use 8-bit character sizes

UBRRL = BAUD_PRESCALE;

UBRRH = (BAUD_PRESCALE >> 8);

}

void BlueWrChar(unsigned char d)
{
while ((UCSRA & (1 << UDRE)) == 0); // wait till UDR is ready

UDR = d; // send data
}

unsigned int BlueRdChar()
{
while ((UCSRA & (1 << RXC)) == 0); // wait until data has been received

return(UDR); // return the byte
}

void BlueWrString(const char *msg)
{

BlueWrChar('r');
BlueWrChar('n');
while(*msg!='')
{
BlueWrChar(*msg);
msg++;
}

}

 

int main()
{
DDRB=(1<<PB0);
unsi/* This the simplewrite code (modified) which can be found in the example codes section

of the software */

import processing.serial.*;

Serial myPort; // Create object from Serial class
int val; // Data received from the serial port

void setup()
{
size(200, 200);

String portName = "COM9";
myPort = new Serial(this, portName, 9600);
}

void draw() {
background(255);
if (mouseOverRect() == true) { // If mouse is over square,
fill(204); // change color and
myPort.write('H'); // send an H to indicate mouse is over square
}
else { // If mouse is not over square,
fill(0); // change color and
myPort.write('L'); // send an L otherwise
}
rect(50, 50, 100, 100); // Draw a square
}

boolean mouseOverRect() { // Test if mouse is over square
return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}


gned char value;

_delay_ms(50); // delay of 50 mili seconds
BlueInit(); // initialization of USART
while(1)
{
value=BlueRdChar(); // get data from serial port
if(value=='H')
PORTB=(1<<PB0);
else if(value=='L')
PORTB=(0<<PB0);
_delay_ms(100);

}
return 0;
}

********************Processing Code**************************


 

###

 


Circuit Diagrams

Circuit-Diagram-Arduino-PC-Serial-Communication-Using-Processing

Project Video


Filed Under: Electronic Projects
Tagged With: open source langauge, processing, serial communication
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Why need use TOPmetal Stacking?
  • Industrial Relay Board Design for Motorcycle Use
  • Why do fill dummy(logic)on the chip(layout)
  • connector model question
  • Color Laser printer, printing pcb layout on transparant sheet

RSS Electro-Tech-Online.com Discussions

  • Faulty heat air gun (dc motor) - problem to locate fault due to Intermittent fault [unrepairable]
  • using a RTC in SF basic
  • Dismantling a WestinghouseRoku TV ?
  • Does US electric code allow branching ?
  • My Advanced Realistic Humanoid Robots Project

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe