Single wire UART Communication

Hello,
I would like to set up a single wire UART communication with a sensor using my Arduino Uno. To do this, I have set up Rx and Tx as open collectors with a 4.7kOhm pull-up resistor and a diode and written the following program. Unfortunately, no matter what I send to the sensor, I only get FF, 11111111 , 255, 0 in the serial monitor as a response, so I assume that my code is wrong. The sensor I want to communicate with uses 3,3V on the data line and the 57600Baud are over a distance of 15 cm.

#include <OneWire.h>

OneWire  sensor(0);


byte data[12]; // buffer for data


void setup()
{
  
  Serial.begin(57600);
  sensor.reset();
  sensor.begin(57600);
  sensor.write(0x3C);
  sensor.write(0x56);
  sensor.write(0x0D);
  
  for (int i = 0; i < 9; i++) 
  {
    data[i] = sensor.read();
  }
  for (byte i = 0; i < 9; i = i++) 
  {
  Serial.println(data[i],HEX);
  Serial.println(data[i],BIN);
  Serial.println(data[i]);
  Serial.println(i);

  }
  delay(10000);
}

My open-collector circuit

why don't you share with us what the sensor is and a link to its spec?

if this is really a Serial device and it supports 5V communication, you don't need this.


EDIT: is this a oneWire sensor or a Serial device?

There is no official data sheet. It is a sensor that is used in such coating thickness gauges (link). I got the information from the manufacturer. Its halve duplex over a Single wire.

Sensor

Do you have another Arduino board ?
Then you could check sending and receiving in separate tests.

Do you have a oscilloscope or a logic analyzer ?

You also could send something without the sensor and then receive it with the same Arduino board.
It is normal to have a number of test-sketches before making the final sketch. Keep the test-sketches as small and as simple as possible. Don't include OneWire.

The Arduino Uno uses pin 0 and 1 for the Serial Monitor and for uploading a sketch. Are you sure that you want to use those pins ?

Do you have a Leonardo board ? That board has a spare Serial port that you can use for the sensor.

The sensor has Bluetooth and a USB connector. I can not read anything about a Serial or 1-Wire interface.

not enough info to help out... would need a datasheet...

Thanks for the answer.

I have no other Arduino board, no oscilloscope, no logic analyser.

How can I send and receive something with the same Arduino board?

I don't have a leonardo board. I have the Arduino UNO R3

The actual sensor is only the front part, the back part is only for bluetooth and usb communication. The actual sensor has 3 connections: GND, 3.3V, Data. The manufacturer has given me the above information.

It might help me to find out why I only get this answer (picture), no matter what I enter.
image

This question needs to be answered. I now see a mix of single wire UART (the hardware) and OneWire software. Unsurprisngly it doesn't work. which is it? Determine this and consistently implement it.

Which exact information ?

Its halve duplex over a Single wire

Did they also mention a baud rate for example? That would hint to UART

Sorry I'm new to the area and don't know that much about it yet. The sensor communicates serially via a single wire (half duplex).

Information that i have:

Baud rate 57600
half duplex over single wire
Serial device

Personally i would whip up oscilloscope to see if that dataline from sensor actually does something. Meaning you can see it do something that resembles your idea of 1's and 0's...

Does sensor also use open collector driver?

Also you do realise uarts usual rest state is outputting High? Signaling as continuous zero state- also known as serial break. This might require you to take into account that uarts are normally inverting bit to signal. high output=0, low output = 1. open collector drivers flip this again so you might read wrong.

OK

connect the sensor's Tx pin to pin 2 on your UNO
connect the sensor's GND to GND on your UNO
connect the sensor's 3.3V to 3.3V on your UNO (hopefully it doesn't require lots of current).

and upload this code

#include <SoftwareSerial.h>

SoftwareSerial sensorSerial(2, 3); // Receive on 2, we will ignore 3

void setup() {
  Serial.begin(115200); Serial.println();
  sensorSerial.begin(57600);
}

void loop() {
  int r = sensorSerial.read();
  if (r != -1) {
    byte rb = r;
    Serial.print(F("0x"));
    if (rb < 0x10) Serial.write('0');
    Serial.print(rb, HEX);
    if (isalnum(rb)) {
      Serial.print(F("\t'"));
      Serial.write(rb);
      Serial.write('\'');
    }
    Serial.println();
  }
}

Now open the Serial monitor at 115200 bauds.

➜ Do you see anything?

1 Like

Thats what I see

image

The sensor also has an open collector output. Yes, I am aware that I could read something wrong. It would be nice if I could read something from the sensor at all, as I don't think the current answers are coming from the sensor.

We would like to see for ourselves that the SmarTest sensor has this half-duplex communication with a full specification of the protocol.

So it appears the sensor does not send anything on the Serial line - or at least not something that can be recognized.

Are you seeing a continuous flow of "nothing" ?
did you set the Serial monitor to 115200?

yes i set the Serial monitor to 115200 and there is a flow of nothing.

there is nothing in my code printing stuff if nothing is received and if something is received, it should print first the HEX value.

are you 100% sure that nothing is connected to pin 0 and 1 ?

Why are you attempting to communicate at 115k baud?