higgsino
Published © GPL3+

Huzzah Feather ESP8266 with MAX3232 as RS232 to wifi device

How to set up an RS232 serial port with this specific hardware, so you can then use it with any RS232 device.

BeginnerFull instructions provided7,112
Huzzah Feather ESP8266 with MAX3232 as RS232 to wifi device

Things used in this project

Hardware components

Adafruit Feather HUZZAH with ESP8266 WiFi
Adafruit Feather HUZZAH with ESP8266 WiFi
×1
MikroE MAX3232 Board
×1
BREADBOARD GENERAL PURPOSE 3 inch x 2 inch
×1
Null modem cable or DB9 connectors and make your own
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Wiring diagram

Shows connections to be made, same colour code wires as the photo of the real thing.

Physical layout and wiring

I made two identical boards (one as spare). Topside shows layout of parts, and bottom side shows wiring connections. Excuse my messy soldering. As long as it works ...

Code

RS232Dylos.ino

Arduino
Skeleton code to show how to communicate from a Huzzah Feather ESP8266 to an RS232 port using a MAX3232 Board. This code just reads whatever it gets on the RS232 port, and prints it to the USB serial port. But it would be easy to extend, to read and write to any RS232 device, and then say send the results over wi-fi.
/*
 * Use an ESP8266 Huzzah Feather and MAX3232 board from MikroE to communicate with an RS232 device 
 * (a Dylos DC1700 particulates monitor here, but could be anything) 
 * 
 * This board has only one UART; Pins labelled Rx and Tx are shared with the USB port, so we have to use SoftwareSerial.
 * We choose pins 4 and 5 because they are the only two available that have no standard use for other things.
 * (ESP32 has 3 separate UARTs and would have been easier).
 * The MAX3232 should be soldered to +3 V, GND and pins 4 and 5 (opposite corner to the power pins). 
 * I checked extensively: what the MAX3232 calls Rx is the channel that *transmits* to the remote device; 
 * what it labels as Tx is the channel that receives from the other device. In other words, they are named
 * as labelled on the other device. A null modem cable is needed from MAX3232 to Dylos (with Rx and Tx crossed).
 * You connect Huzzah Feather Tx = pin 4 to Tx on the MAX3232; Huzzah Feather Rx = pin 5 to Rx on the MAX3232.
 */
#include <SoftwareSerial.h>
const byte txPin = 4;
const byte rxPin = 5;
SoftwareSerial max3232(rxPin, txPin);
  
void setup() {

  Serial.begin(9600L);

  pinMode(txPin, OUTPUT);
  pinMode(rxPin, INPUT);

  max3232.begin(9600);
  
  while (!max3232.isListening()) {
    Serial.println("Waiting for MAX3232 to start listening...");
    delay(1000);
  }
  Serial.println("Good, MAX3232 is listening");

}


void loop() {

  Serial.println("Waiting for data on Dylos");

  for (int loops = 0; loops < 120; ++loops) {
    if (max3232.available()) break;
    delay(1000);
  }

  char result[100] = "-1, -1";
  if (max3232.available()) {
    Serial.println("reading Max3232...");
    int i = 0;
    while (max3232.available()) {
      result[i++] = max3232.read();
    }
    result[i] = '\n'; // Just to check it is terminated
  }
  else {
    Serial.println("Timed out");
  }
  
  Serial.println(result);
  
}

Credits

higgsino

higgsino

0 projects • 0 followers

Comments