user23427: I have a sensor that communicates via serial communication. CTi Sensors TILT-05. It transmits an ASCII string with data separated by commas. I want to be able to read the incoming ASCII data in the Arduino IDE's Serial Monitor in real time (the device is an accelerometer).
I am struggling to convey this in the code. Currently, I have the sensor's RX connected to an Arduino Uno's TX port (digital 1) and sensor TX-> Arduino RX (digital 0). The sensor is powered and grounded via the Arduino.
I have searched for serial communication methods but can't find any that seem to work. How can I receive and interpret the incoming data from the sensor?



user2944: You don't mention the sensor brand or a datasheet so this will be a very general answer to the problem.
Firstly, how you have the sensor connected now should just spool info into the Serial monitor of the Arduino IDE without any code on the Arduino.
What are the data speed and the exact way the Serial comes out from the sensor?
If you want to interpret the data as it is coming through you should use Software Serial as you can't relay info to the PC with an Arduino's RX TX lines connected to something else.
What you can do is below(Untested):
#include <SoftwareSerial.h>

SoftwareSerial mySer(3, 4); //RX TX

//these are char areay because its from Serial
char accel[3] = {'0'};
uint8_t place = 0;

// array to print in sync with the accelerometer values array
const char* SerialText[3] = {
   "\nX Axis: ",
   "\nY Axis: ",
   "\nZ Axis: ",
};


char inData = '0';
char separator = ','; // separator you described



void setup(){
//set to the normal baud, mines for the example
     Serial.begin(9600); 

     mySer.begin(9600);

}//~ end setup

void loop(){

    if(mySer.available()){

     inData = mySer.read(); // get the value at the instance of the serial data being there

        if(inData != separator){
          accel[place] = inData;
          Serial.print(SerialText[place]); // print the current values identifier
          Serial.print(accel[place]); // print value
          place++; // increment for the next time
     }
   }

if(place >= 3) place = 0;
}//~ end loop

The above gives this output at the moment, with an input of $CSACC,-0156.4,-0226.3,+0981.2*49
X Axis: $
Y Axis: C
Z Axis: S
X Axis: A
Y Axis: C
Z Axis: C
X Axis:  
Y Axis: -
Z Axis:  
X Axis: 0
Y Axis: 1
Z Axis: 5
X Axis: 6
Y Axis: .
Z Axis: 4
X Axis:  
Y Axis: -
Z Axis:  
X Axis: 0
Y Axis: 2
Z Axis: 2
X Axis: 6
Y Axis: .
Z Axis: 3
X Axis: +
Y Axis: 0
Z Axis: 9
X Axis: 8
Y Axis: 1
Z Axis: .
X Axis: 2
Y Axis: *
Z Axis: 4
X Axis: 9
Y Axis:  
Z Axis: 
X Axis: 

The code doesn't filter this the way it should but is a stepping stone. I will update it to do it properly when I have a chance.

23427: <p>I have a sensor that communicates via serial communication. <a href="http://ctisensors.com/wp-content/uploads/2016/03/TILT-05-UserManual-01b.pdf" rel="nofollow noreferrer">CTi Sensors TILT-05</a>. It transmits an ASCII string with data separated by commas. I want to be able to read the incoming ASCII data in the Arduino IDE's Serial Monitor in real time (the device is an accelerometer).</p>

<p>I am struggling to convey this in the code. Currently, I have the sensor's RX connected to an Arduino Uno's TX port (digital 1) and sensor TX-> Arduino RX (digital 0). The sensor is powered and grounded via the Arduino.</p>

<p>I have searched for serial communication methods but can't find any that seem to work. How can I receive and interpret the incoming data from the sensor?</p>

<p><a href="https://i.stack.imgur.com/FIZ8K.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FIZ8K.jpg" alt="Basic setup. Not complicated at all, just need some clarification."></a>
<a href="https://i.stack.imgur.com/rKT4n.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rKT4n.jpg" alt="Closer view of the connections."></a></p>
 2944: <p>You don't mention the sensor brand or a datasheet so this will be a very general answer to the problem.</p>

<p>Firstly, how you have the sensor connected now should just spool info into the Serial monitor of the Arduino IDE without any code on the Arduino.</p>

<p>What are the data speed and the exact way the Serial comes out from the sensor?</p>

<p>If you want to interpret the data as it is coming through you should use Software Serial as you can't relay info to the PC with an Arduino's RX TX lines connected to something else.</p>

<p>What you can do is below(<strong><em>Untested</em></strong>):</p>



<pre class="lang-cpp prettyprint-override"><code>#include &lt;SoftwareSerial.h&gt;

SoftwareSerial mySer(3, 4); //RX TX

//these are char areay because its from Serial
char accel[3] = {'0'};
uint8_t place = 0;

// array to print in sync with the accelerometer values array
const char* SerialText[3] = {
   "\nX Axis: ",
   "\nY Axis: ",
   "\nZ Axis: ",
};


char inData = '0';
char separator = ','; // separator you described



void setup(){
//set to the normal baud, mines for the example
     Serial.begin(9600); 

     mySer.begin(9600);

}//~ end setup

void loop(){

    if(mySer.available()){

     inData = mySer.read(); // get the value at the instance of the serial data being there

        if(inData != separator){
          accel[place] = inData;
          Serial.print(SerialText[place]); // print the current values identifier
          Serial.print(accel[place]); // print value
          place++; // increment for the next time
     }
   }

if(place &gt;= 3) place = 0;
}//~ end loop
</code></pre>

<p>The above gives this output at the moment, with an input of <code>$CSACC,-0156.4,-0226.3,+0981.2*49</code></p>

<pre class="lang-cpp prettyprint-override"><code>X Axis: $
Y Axis: C
Z Axis: S
X Axis: A
Y Axis: C
Z Axis: C
X Axis:  
Y Axis: -
Z Axis:  
X Axis: 0
Y Axis: 1
Z Axis: 5
X Axis: 6
Y Axis: .
Z Axis: 4
X Axis:  
Y Axis: -
Z Axis:  
X Axis: 0
Y Axis: 2
Z Axis: 2
X Axis: 6
Y Axis: .
Z Axis: 3
X Axis: +
Y Axis: 0
Z Axis: 9
X Axis: 8
Y Axis: 1
Z Axis: .
X Axis: 2
Y Axis: *
Z Axis: 4
X Axis: 9
Y Axis:  
Z Axis: 
X Axis: 
</code></pre>

<p>The code doesn't filter this the way it should but is a stepping stone. I will update it to do it properly when I have a chance.</p>
