Skip to content

ffich/UNOQ_DoubleBridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UNOQ DoubleBridge

Repository that implement the UNO Q DoubleBridge.

Install script

mkdir -p /home/arduino/ArduinoApps/DoubleBridge && \
curl -L https://github.com/ffich/UNOQ_DoubleBridge/archive/refs/heads/main.tar.gz \
| tar -xz --strip-components=2 -C /home/arduino/ArduinoApps/DoubleBridge UNOQ_DoubleBridge-main/DoubleBridge

UNOQ TCP Control Server + Node-RED Integration

This project provides a robust and extensible control infrastructure for Arduino UNO Q, based on:

  • Node-RED for automation logic and UI/dashboard
  • Python (App Lab) as a TCP control server
  • Bridge for communication with the MCU sketch
  • JSON line-based protocol over TCP

The goal is to create a clean, scalable, and production-ready bridge between high-level automation (Node-RED) and low-level hardware control (UNO Q).


System Architecture

image

Data Flow

  1. Node-RED
    • Builds JSON commands
    • Sends them via TCP
  2. Python App Lab Server
    • Receives and validates JSON
    • Dispatches commands to the Bridge
    • Sends structured JSON responses back
  3. UNO Q Sketch
    • Executes hardware operations (GPIO, ADC, LED Matrix)

Communication Protocol

  • Transport: TCP
  • Format: JSON
  • Message termination: newline (\n) -- mandatory
  • Model: request → response

Example

{"cmd":"set_io","pin":"D13","value":true}

(with \n appended at the end)


Implemented Features


1. Digital GPIO Control

Set Digital Output

Command:

{ "cmd": "set_io", "pin": "D13", "value": true }

Python Action:

Bridge.call("set_pin_by_name", pin, True)

Response:

{
  "ok": true,
  "event": "io_updated",
  "pin": "D13",
  "value": true
}

Get Digital Input

Command:

{ "cmd": "get_io", "pin": "D13" }

Python Action:

Bridge.call("get_pin_by_name", pin)

Response:

{
  "ok": true,
  "event": "io_status",
  "pin": "D13",
  "value": true
}

2. Global Digital Control (Set All Outputs)

This command allows enabling or disabling all digital outputs at once.

Command:

{ "cmd": "set_all_io", "value": false }

Python Action:

Bridge.call("set_all_io", False)

Response:

{
  "ok": true,
  "event": "io_all_updated",
  "value": false
}

3. LED Matrix Text Output

The UNO Q LED Matrix is driven using the standard Arduino UNO R4 LED Matrix library.

Command

{
  "cmd": "led_matrix_print",
  "text": "HELLO UNO Q"
}

Python

Bridge.call("led_matrix_print", text)

Response

{
  "ok": true,
  "event": "led_matrix_updated",
  "text": "HELLO UNO Q"
}

4. Analog Input Reading

Analog inputs are read using a Bridge function implemented on the MCU:

int get_an_pin_by_name(String pin);

Command

{ "cmd": "get_an", "pin": "A0" }

Python

Bridge.call("get_an_pin_by_name", pin)

Response

{
  "ok": true,
  "event": "an_value",
  "pin": "A0",
  "value": 734
}

5. Digital Pin Direction Control ⭐ NEW

This feature allows configuring the direction of a GPIO pin (input/output) at runtime.

Command

{ "cmd": "set_io_dir", "pin": "D13", "value": true }

Where:

  • pin is the pin name (string)
  • value is the direction:
    • true → OUTPUT
    • false → INPUT

Python

Bridge.call("set_pin_direction_by_name", pin, value)

Response

{
  "ok": true,
  "event": "io_dir_updated",
  "pin": "D13",
  "value": true
}

TCP Server Robustness

The Python TCP server is designed to be fault-tolerant and production-safe:

  • Handles:
    • Invalid JSON
    • Missing newline termination
    • Socket timeouts
    • Bridge runtime errors
  • Never blocks indefinitely
  • Always returns structured error responses

Error Examples

{ "ok": false, "error": "Invalid JSON" }
{ "ok": false, "error": "Timeout waiting for complete line" }
{ "ok": false, "error": "Bridge call set_all_io failed: ..." }

Node-RED Integration

Each command is encapsulated inside dedicated subflows:

  • ✅ Set IO via TCP
  • ✅ Get IO via TCP
  • ✅ Set All IO via TCP
  • ✅ LED Matrix Print via TCP
  • ✅ Get Analog via TCP
image

Each subflow:

  • Uses an environment variable PIN_NAME when needed
  • Automatically builds:
{ "cmd": "...", ... }
  • Sends data through a tcp request node

Node-RED Control Panel

A Node-RED sample control panel is also provided: image


Extensibility

This architecture allows you to easily add:

  • PWM outputs
  • DAC control
  • I²C / SPI via Bridge
  • Advanced LED effects
  • State synchronization
  • Safe boot modes
  • Remote diagnostics

To add a new feature:

  1. Implement the function in the MCU sketch
  2. Add a new branch in handle_command (Python)
  3. Create a new Node-RED subflow

Conclusion

This project provides a clean, scalable, and industrial-grade control bridge between:

  • Automation layer: Node-RED
  • Control layer: Python App Lab
  • Hardware layer: Arduino UNO Q

It is designed to be:

  • ✅ Reliable
  • ✅ Scalable
  • ✅ Maintainable
  • ✅ Ready for dashboards and remote control

About

Repositgory that implement the UNOQ DoubleBridge.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors