Shervin Oloumi
Published

Interfacing the Onion Omega2 and Arduino Uno via UART

Bring the versatility of the Arduino Uno to the powerful world of IoT with the Onion Omega board. Make any Arduino project IoT compatible.

IntermediateProtip1 hour9,699
Interfacing the Onion Omega2 and Arduino Uno via UART

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Omega2
Onion Corporation Omega2
×1
Resistor 3.3k Ohm
×1
Resistor 1.7k Ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Hardware setup

Code

arduino_serial.ino

Arduino
This it the code for programming the Arduino Uno board to setup the UART communication. This code monitors the receiving pin of the arduino and relays the messages to the USB serial port (which can be viewed using the "serial monitor" tool of the Arduino IDE). Additionally, the code relays messages sent from the serial monitor tool to the programmed transmitter port of the Arduino, which means you can use the serial monitor tool to send messages to the Omega2. In a more practical setup, you would send those values directly to the transmitter pin for delivery to the Omega2.
#include <SoftwareSerial.h>

SoftwareSerial gtSerial(8, 7); // Arduino RX, Arduino TX

void setup() {
  Serial.begin(9600);    // serial / USB port
  gtSerial.begin(9600);  // software serial port
}

byte rx_byte = 0;        // stores received byte

void loop() {
  // check if byte available from USB port
  if (Serial.available()) {
    rx_byte = Serial.read();
    // send a byte to the software serial port
    gtSerial.write(rx_byte);
  }

  // check if byte available on the software serial port
  if (gtSerial.available()) {
    // get the byte from the software serial port
    rx_byte = gtSerial.read();
    Serial.write(rx_byte);
  }
}

python_serial.py

Python
This is a Python script for monitoring the receiver pin of the Omega2, when interfacing with the Arduino Uno board. Please note: this is just a sample code that receives one-digit integers. This will have to be modified to work with your specific application. For instance, you may want to implement a send function to send commands to the Arduino board or add cloud connectivity to the code using MQTT.
import serial

ser = serial.Serial('/dev/ttyS1', 9600, timeout = None)

while True:
        input = ser.read()
        print(int(input))

Credits

Shervin Oloumi

Shervin Oloumi

1 project • 7 followers
Creative Engineer.

Comments