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);
}
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.
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.
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.
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.
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.
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();
}
}
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.