2018
April Tuesday 24

Bookmark and Share

Related Articles...

MILWAUKEE WI Arduino Meet Up Make Space

WANTED: CORE TEAM MEMBER TO HELP START NON-PROFIT GROUP.

WANTED: Angle Investor Start-Up Funding

Large Industrial Zoned Arduino Make Space Acquired!

Email :

COASMailBox @ gmail.com

MILWAUKEE WI Raspberry Pi Meet Up Make Space

WANTED: CORE TEAM MEMBER TO HELP START NON-PROFIT GROUP.

WANTED: Angle Investor Start-Up Funding

Large Industrial Zoned Raspberry Pi Make Space Acquired!

Email :

COASMailBox @ gmail.com

MILWAUKEE WI Internet of Things (IoT) Meet Up Make Space

WANTED: CORE TEAM MEMBER TO HELP START NON-PROFIT GROUP.

WANTED: Angle Investor Start-Up Funding

Large Industrial Zoned Make Space Acquired!

Full Advanced Fabrication Facility, machine Shop, Welding, Electronics Lab Equipment Acquired!

Email :

COASMailBox @ gmail.com

MILWAUKEE WI Machine Repair, & Installation  - Tier 1 Business Support

Machine Technician Mechanic 20+ Years  Personal Experienced In Industrial Factory Machine Servicing, Rebuilding, Installation And Repair - Plus A 35+ Years Experienced Computer Engineer Service Technician Team Ready For Your Outsourced Market Advantage Needs!

Hartung Industrial - Member - CGI Science & Technology Group

Email :

COASMailBox @ gmail.com

2017 REVIEW

 

Arduino & RS232 Serial Communciations

2017 OCTOBER | by Gene Casanova

Senoir Systems Engineer


A Tutoria, To Enlighten On How To Communicate With A Computer From An Arduion, Using A MAX3323 RS-232 Driver/Receiver IC Chip, And A Software Serial Connection On An Arduino.


Materials Needed

  1. A computer system with a software terminal application.
    1. Example: A UNIX-Based or UNIX-Like computer operating system is best to use; like LINUX (Ubuntu Desktop) etc.., FreeBSD, Or MAC OS X ("terminal" application) are best to use.
  2. A Serial Breadboard cable
  3. A MAX3323 chip (or similar)
  4. 4 x 1uf capacitors
  5. Solderless breadboard
  6. Jumper leades (wires)
  7. An Arduino Microcontroller Module
  8. Optional: a light emitting diode (LED) = used for circuit feedback

Build The Serial Port Circuit

Arduino PCB With Long IC1 MCU

  1. Insert the MAX3323 IC chip in the breadboard.
  2. Connect a lead to the Postive + power rail of the breadboard.
  3. Connect the + lead from the breadboard to the 5V Power pin on the Arduino systembaord.
  4. Connect a lead to the Negative - ground power rail of the breadboard.
  5. Connect the - lead from the breadboard to the "GND" Power pin (ground) on the Arduino systembaord.
  6. Connect a lead to pin 15 on the MAX233 IC chip.
    1. MAXIUM MAX3323E IC Chip Drawing
  7. Connect the lead from pin 15, on the MAX232 IC chip to the - power rail of the breadboard.
  8. Connect MAX232 IC pins 16, 14, 13, 12, and 11 to the breadboard + power rail.
  9. Connect Optional Feedback LED
    1. Connect the anode lead of a LED to the Arduino systembaord DIGITAL pin13.
    2. Connect the collector of the LED to the Arduino systembaord DIGITAL "GND" pin (ground).
  10. Connect a 1uF capacitor between pin 1 and pin 3 (-) on the MAX232 IC chip.
  11. Connect a 1uF capacitor between pin 4 and pin 5 (-) on the MAX232 IC chip.
  12. Connect a 1uF capacitor between pin 2 on the MAX232 IC chip and the breadboard - (ground) power rail.
  13. Connect a 1uF capacitor between pin 6 on the MAX232 IC chip and the breadboard - (ground) power rail.
    1. WARNING ----- When using polarized capacitors, make sure the negative pin is connect to the negative votage (pin 3, pin 5, and ground power rail).
  14. Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines.
    1. For this tutorial, Arduino pin 6 will be used for Rx (receiving), and pin 7 for Tx (transmitting).
    2. Connect a lead between Arduino DITAL pin 7, and pin 10 on the MAX3323 IC chip (Max232 signal input pin "TIN1").
    3. Connect a lead between Arduino DITAL pin 6, and pin 9 on the MAX3323 IC chip (Max232 signal input pin "TOUT1").
    4. NOTICE - Use color wired to colorcode the wiring - suggest using TX wire Green, RX wire Blue, +5v wires are red, GND wires are black.

DB-9 Serial Connection

DB9 Serial Port Connection Pinouts

A DB9 Serial Cable

  1. Start with a high quality, industry standard, female DB9 connector.
  2. Pick three different colors of wire, one for TX, one for RX, and one for ground.
  3. Strip back insulation on the serial cable power leads, at a distance to allow slipping a short piece of heatshrink tubing over outter shell and inside leads.  After soldering leads to DB connector pins, slip the heatshrink tubing over teh solder joint and heat to seal and electrically insulate the joints.
  4. Carefully solder TX wire to pin 2 on DB9 connector.
  5. Solder RX wire to pin 3 on DB9 connector.
  6. Solder GND ground to pin 5 on DB9 connector.
  7. Connect DB9 connector pins 1 and 6 to pin 4.
  8. Connect DB9 connector pin 7 to pin 8.
  9. Enclose the DB9 connector in a backshell.
    1. This shell is intended to protect the wries from strain and wear, and a place to grip with fingertips and push and pull the connector when mounting and dismounting.
  10. Connect the TX line comming from a RS232 port on a connected computer, to MAX232 pin 8 (R1IN).
  11. Connect the RX line comming from a RS232 port on a connected computer, to MAX232 to pin 7 (T1OUT).
  12. Connect the ground line from a RS232 port on a connected computer, to ground on the breadboard.
    1. Colorcoding leads: TX wires Green, RX wires Blue, +5v wires are red, GND wires are black.

FINISH


Program The Arduino

After the serial communciations circuit has been built, the Ardunio must be programmed for serial communication.

This example program (logic process) will wait for, and respond to, a character at the serial recieving pin (port), and then, send the character out in uppercase, to the transmit pin (port).

A very basic serial communcation program; useful for testing serial communication circuits and more advanced programing development.

Upload the following C source code to the Arduino microcontroller systembaord:

// SERIAL COMMUNICATIONS BASICS
// Edited By Gene Casanova 2017
// Created August 23 2006
// By Heather Dewey-Hagborg
// http://www.arduino.cc

#include <ctype.h>

#define bit9600Delay 100
#define halfBit9600Delay 50
#define bit4800Delay 188 
#define halfBit4800Delay 94 

byte rx = 6;
byte tx = 7;
byte SWval;

void setup() {
  pinMode(rx,INPUT);
  pinMode(tx,OUTPUT);
  digitalWrite(tx,HIGH);
  delay(2);
  digitalWrite(13,HIGH); // Enable LED @ pin 13
  SWprint('h'); // Send Character "h"
  SWprint('i'); // Send Character "i"
  SWprint(10); // Send 'Carriage Return' Character
}

void SWprint(int data)
{
  byte mask;
  // Startbit
  digitalWrite(tx,LOW);
  delayMicroseconds(bit9600Delay);
  for (mask = 0x01; mask>0; mask <<= 1) {
    if (data & mask){ // choose bit
     digitalWrite(tx,HIGH); // send 1
    }
    else{
     digitalWrite(tx,LOW); // send 0
    }
    delayMicroseconds(bit9600Delay);
  }
  // Stop bit
  digitalWrite(tx, HIGH);
  delayMicroseconds(bit9600Delay);
}

int SWread()
{
  byte val = 0;
  while (digitalRead(rx));
   // Wait for Start bit
  if (digitalRead(rx) == LOW) {
    delayMicroseconds(halfBit9600Delay);
    for (int offset = 0; offset < 8; offset++) {
     delayMicroseconds(bit9600Delay);
     val |= digitalRead(rx) << offset;
    }
     // Wait for Stop bit + extra
    delayMicroseconds(bit9600Delay); 
    delayMicroseconds(bit9600Delay);
    return val;
  }
}

void loop()
{
    SWval = SWread(); 
    SWprint(toupper(SWval));
}

Open a serial terminal application on the connected computer.

Set serial communications to: 9600 baud, 8 data bits, 1 stop bit, no parity, no hardware flow control.

Press the reset button on the arduino board.

The word "hi" should appear in the terminal window, followed by a new line.

Try typing a lowercase character in the terminal.

The chracter should be returned to the terminal application and appear in teh terminal window.  This process is referred to as an echo.  The Arduino is receiving and then sending back the recevied character.... a process described in serial communications as an "echo".

If this worked, Congratulations!

Your serial connection is working as planned.

You can now use your new RS232 Serial to Computer connection, to print debugging statements sent from your code, and to send commands to a microcontroller; on a breadboard or inbedded in a device enabked with serial port communications.


More.....

UART

Universal Asynchronous Receiver/Transmitter (UART); a serial protocol.  UART is one of the first and simplest protocols to transmit one bit at-a-time over a communciation path/link.

UART can be used for serial communication between computers.  UART is asynchronous, and enables simultaneous communication in both directions ("Full Deplex" commincations).


Commucating Over USB Port

Use the Serial Library to communicate from the Arduino systemboard through the USB port to a connected computer.  A software library is a collection of premade processes written in a computer programming language. The Serial Library enables writting programs for Arduino communcate through a serial communcstion link.


A Basic Arduino Serial Sketch

/*
 * Hello World!
 * Sketch for Arduino. 
 * This Arduino "sketch" illustrates how to send data out the USB port to
 * a computer connected to the Arduino USB port.
 */
void setup()                    // Execute once, when the sketch starts.
{
  Serial.begin(9600);           // Serial.begin() from Serial library.
								 // Establish a USB port connection with a baud rate of 9600bps.

  Serial.println("Hello world!");  // send content between double quotes "" and one line break character. 
}

The Arduino requires void setup(){} and void loop().

"Serial.begin()" is a library procedure-reference.  "Serial" is the name of a library and "begin" is the name of a procedure inside the library.

If no library name is given, then it means the procedure is in the 'default' collection of procedures we use.

Serial."println"() - "println" stands for "print line".  This process sends the content between the "" double quotes to the default Arduino USB serial port.


Use The Technology Wisely & Keep It Simple

- Cheers!

Gene Casanova


Need More?   Need Help? ........Software, Network, System & Data Center Builder & Developer | Development Services Available - Freelance Small Jobs; To Outsourced Long Term Service Provider Contract Labor Available.

CGI Computer Wares | EST 1979

Send E-MailCONTACT: [click]@CGIComputerWares.com