Arduino: Start Serial with only TX enabled

Created on 24 Aug 2016  路  6Comments  路  Source: esp8266/Arduino

Hardware

Hardware: NodeMCU v2
Core Version: Latest GIT

Description

Problem description

Settings in IDE

Module: NodeMCU
Upload Using: SERIAL
Reset Method: nodemcu

Sketch

#include "DHT.h"
#define DHTTYPE DHT22
#define DHTPIN D9  //  D9 is Serial RX
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  dht.begin();
}

void loop() {
  Serial.println(dht.readTemperature());
}

This is a stripped version of my code, which just describes the question.
I would like to use pin D9 for DHT (input), because I only use Serial for debugging output.
Is it possible to begin Serial with some parameter so it will only use it's TX pin and leave the RX pin free/available for other usage?

I do see this in the uart.h file, but I really don't know if/how I could make use of those:

#define UART_FULL     0
#define UART_RX_ONLY  1
#define UART_TX_ONLY  2

#define UART_TX_FIFO_SIZE 0x80

struct uart_;
typedef struct uart_ uart_t;

uart_t* uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size);
void uart_uninit(uart_t* uart);

void uart_swap(uart_t* uart, int tx_pin);
void uart_set_tx(uart_t* uart, int tx_pin);
void uart_set_pins(uart_t* uart, int tx, int rx);
bool uart_tx_enabled(uart_t* uart);
bool uart_rx_enabled(uart_t* uart);

Most helpful comment

Thanks @WereCatf
Yep, works now.
I can upload a new sketch with the DHT connected to D9 (RX) and use the DHT when running.
(only my DHT22 modules are getting crappy, sometimes they don't work at any pin anymore)

All 6 comments

Looking at the HardwareSerial.h it looks like Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY); would do the trick.

I tried this and it compiles and outputs my debugging:

  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY, 1);   //     void begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin);

But it seems that the D9 is still not usable, because the DHT still does not communicate.

Does it work if you try it on some other pin?

You're just a second faster than me.
Reverted back to D4 where it worked and that stopped working, so I guess I have another hardware issue now. Will come back later...

Thanks @WereCatf
Yep, works now.
I can upload a new sketch with the DHT connected to D9 (RX) and use the DHT when running.
(only my DHT22 modules are getting crappy, sometimes they don't work at any pin anymore)

Good to hear :)

Was this page helpful?
0 / 5 - 0 ratings