REMOTING SIX SENSORS ON ONE TWISTED PAIR - PART 7

Post any questions you may have about our current range of USB data loggers
Post Reply
Glovisol
Advanced User
Advanced User
Posts: 0
Joined: Sat May 11, 2013 10:03 am
Location: San Marzano Oliveto, Asti, Italy

REMOTING SIX SENSORS ON ONE TWISTED PAIR - PART 7

Post by Glovisol »

7. COMPLETE SIX CHANNEL COMM SYSTEM

Here below the uploaded WORD sketch files for six channel translation @ 8 Bit. Detailed descriptions are already included in the files as text. Additional information as follows.

7.1 GENERAL

a) This software has been tested and works faultlessly with the following Arduino IDE versions: 1.0.5_2 ERW - 1.0.6 – 1.6.7 – 1.7.8. The ERW edition (OS Windows XP only) is very convenient as far as the handling of the Serial Monitor is concerned and is recommended if Micro Arduino 1 is used. Versions 1.0.5_2 ERW and 1.0.6 can co-exist on the same PC. On the contrary installation of versions 1.6.7 or 1.7.8 will automatically delete all previous or different versions.

b) IDE versions 1.6.7 and 1.7.8 are said to be compatible with Arduino M0 or Arduino M0 PRO. To date (following a week of tests) I have been unable to make a Micro Arduino M0 reliably work at all, so that I have doubts on the workable state of the drivers for this device at the moment.

c) The sketches work fine with a Serial Monitor speed of 115200 Baud and with an RS485 speed of 57600 Baud over a coaxial or twisted pair simulator (see Part 5) equivalent to 3,300 ft.

d) The number of Iterations can be over 4 billion and I have tested Recycle Time down to 500 Millis. (nominally 0.5”, but is really 0.35” with my Master Micro).The times given in the Master Serial Monitor are only approximate and valid for the individual Arduino. Time can be calibrated with a stopwatch, if necessary, by inserting a calibration factor in: “float R = (t)”.

7.2 INTEGER/DATA MANIPULATION IN THE SYSTEM

This information important to understand how the System manipulates Data. The path for Data starts at the Analog input pins of the Slave Micro, A0, A1,……A5, where the sensors are connected and travels backwards to the Master. With reference to the Slave sketch, once the Master has interrogated the Slave with the Sync Byte 123, the Slave Micro reads the input pins: “sensorValue_0 = analogRead (analogInPin0)” and so on, with 10Bit resolution, referred to the voltage Reference used.

Example 1
Slave Analog Reference (DEFAULT): 5V = 5000 mV
10 Bit = 1023 levels.
Single level = 5000/1023 = 4.8876
analogInPin0 = 1860mV
sensorValue_0 = 1860/4.8876 = 380 out of 1023 or, equivalently: 1860*0.2046 = 380 out of 1023.

Example 2
Slave Analog Reference (EXTERNAL): 2.5V = 2500 mV
10 Bit = 1023 levels.
Single level = 2500/1023 = 2.4438
analogInPin0 = 2135mV
sensorValue_0 = 2135/2.4438 = 874 out of 1023 or, equivalently: 2135*0.4092 = 874 out of 1023.

At this point our data to be transmitted ranges from 0 to 1023, but our serial transmission system () to the RS485 chips only handles an 8 Bit range, from 0 to 255. The Slave sketch now maps the 0-1024 range into the 0-255 range with the map function, as shown in the examples.


Example 1
sensorValue_0 = map (380, 0, 1023, 0, 255) --- 380:1023 = X : 255 --- X =(380*255/1023) = 95; sensorValue_0 = 95

Example 2
sensorValue_0 = map (874, 0, 1023, 0, 255) --- 874:1023 = X : 255 --- X =(874*255/1023) = 218; sensorValue_0 = 218

The Slave now locally prints the mapped Sensor Values to the local Serial Monitor and transmits them to the Master unit.

Data travels over the RS485 twisted wireline in this 8 Bit format and reaches the Master. With reference to the Master sketch, the Master Micro must now convert the Data to an analogue voltage readable by the Data Logger. First it reads the data , then it writes it as PWM percentage on the output pin connected to the Data Logger’s input and finally converts it for printing it out on the Master Serial Monitor. The function analogWrite automatically converts the 0-255 code into an equivalent 0-100% PWM percentage, referred to the local Reference voltage and writes this PWM to the output pin, as shown in the examples.

Example 1
Master Analog Reference (DEFAULT): 5V = 5000 mV
sensorValue_0 = RS485Serial.read = 95
analogwrite(analogOutPin0, sensorValue_0) --- 255 : 95 = 100 : X
X = (95*100/255) = 37.25% PWM.
Therefore the OutputPin0 will output, when filtered, an equivalent voltage V0 = 0.3725*5000 = 1860 mV.
Data is converted for printing to the Serial Monitor by multiplying it for the step value:
cal = 5000/255 = 19.61
float Vy0 = (sensorValue_0 * cal) = 95 * 19.61 = 1860 mV. The cal value can be adjusted in order to correct the composite calibration error of the two Arduino Micros.


Example 2
Master Analog Reference (EXTERNAL): 2.5V = 2500 mV
sensorValue_0 = RS485Serial.read = 218
analogwrite(analogOutPin0, sensorValue_0) --- 255 : 218 = 100 : X
X = (218*100/255) = 85.49% PWM.
Therefore the OutputPin0 will output, when filtered, an equivalent voltage V0 = 0.8549*2500 = 2135 mV.
Data is converted for printing to the Serial Monitor by multiplying it for the step value:
cal = 2500/255 = 9.8
float Vy0 = (sensorValue_0 * cal) = 218 * 9.8 = 2135 mV. The cal value can be adjusted in order to correct the composite calibration error of the two Arduino Micros.



7.3 SYSTEM OPERATION

a) Once you have the System wired and tested with the demo sketches, as explained in the previous posts, proceed as follows.
b) Note that, as downloaded, System is set for analogReference(DEFAULT) = 5V.
c) Open the Arduino IDE on a NEW blank page.
d) Download one sketch file, copy the entire content and paste it to the blank Arduino File.
e) Load Master and Slave files and open the Serial Monitors.
f) In the Master sketch write: k = desired number of iterations. (60 written in); t = Recycle time (1200 written in); cal = 19.61 (in the sketch cal = 19.86 to calibrate the System).
g) On the Serial Monitors you see the following:

Master:
RS485 DATA LOGGER COMMUNICATIONS
Stand-By/Reset = a; Start = b; Press RESET to Stop (note RESET on monitor only available with the ERW IDE)

Slave:
SERIAL RS485 DATA LOGGER SLAVE READY

Now enter “b” on the Master Serial Monitor and the System will start iterating. Sensor values will be shown on both Monitors.

Once the pre-set number of iterations is reached, System will stop. You can re-set both Master & Slave by entering “a” on the Master Serial Monitor. Appropriate messages will appear on both monitors.

If there are transmission/reception problems and the Sync Byte appears different from “123”, Sytem will stop automatically and

ALARM – ERROR OR NO CONNECTION TO SLAVE

will appear on the Master Serial Monitor. In this case the Master sketch must be re-loaded to resume operation.
Attachments
sketch_MASTER_485_7_2.doc
(52 KiB) Downloaded 507 times
sketch_SLAVE_485_7_2.doc
SLAVE SKETCH
(46 KiB) Downloaded 533 times
Last edited by Glovisol on Thu Feb 25, 2016 7:22 am, edited 10 times in total.

Glovisol
Advanced User
Advanced User
Posts: 0
Joined: Sat May 11, 2013 10:03 am
Location: San Marzano Oliveto, Asti, Italy

Re: REMOTING SIX SENSORS ON ONE TWISTED PAIR - PART 7

Post by Glovisol »

Automatic RESET caused by a missing Sync Byte
Automatic RESET caused by a missing Sync Byte
RS485 COMM SYSTEM AUTOMATIC RESET OPTION IN "ALARM"

In the previously posted Master sketch Ver. 7.2 (SKETCH_MASTER_RS485_7_2) an alarm triggers when the SyncByte (123) returned by the Slave is wrong or missing. The effect of this alarm is to shut down the Master unit. To resume operation, one has to re-load the Master sketch. This procedure can be inconvenient in some cases.

Ver. 7.3 (SKETCH_MASTER_RS485_7_3) automatically resets the Master unit when this alarm triggers, thereby avoiding the re-load operation. The few modifications are shown in blue. The alarm situation is shown in the enclosed screen shot. Note Serial Monitor used "Putty" in place of the usual Arduino S.M.
Attachments
sketch_MASTER_485_7_3.doc
(54 KiB) Downloaded 492 times
Last edited by Glovisol on Thu Feb 25, 2016 7:25 am, edited 2 times in total.

Glovisol
Advanced User
Advanced User
Posts: 0
Joined: Sat May 11, 2013 10:03 am
Location: San Marzano Oliveto, Asti, Italy

Re: REMOTING SIX SENSORS ON ONE TWISTED PAIR - PART 7

Post by Glovisol »

The Screen shows the new Serial Monitor output & sketch modification
The Screen shows the new Serial Monitor output & sketch modification
SPURIOUS TRIGGERING PROBLEM OF THE "OUT OF SYNC ALARM", ANALYSIS AND SOLUTION


The RS485 COMM System has been under extensive testing for several days now and from time to time, in random fashion, the "ALARM - ERROR OR NO CONNECTION TO SLAVE" would trigger, stopping the flow of data from Slave to Master. The strange thing was that the Sync Byte appeared to be missing always in the back path Slave to Master and never in the path Master to Slave, so that spurious alarm triggering (not dependent on a real lack of the Sync pulse) was suspected.

To verify what was happening, the Master sketch was modified as follows. AUTO RESET was removed and a counter was introduced to detect and record the hypotetical return Sync pulses missing.

=======================================================================
Serial.println(Vy5);

Serial.print(“===NUMBER OF OUT OF SYNCS = “);
Serial. println(s);
delay(10);

}
else
{

/* This counter counts and records the “OUT OF SYNC” conditions
and prints them, to assess transmission line reliability.*/

for(int s = 0; s < k; s++);
Serial.println("===OUT OF SYNC===");
delay(2000);

}
}
}
}
}
} //End of Iteration - Iteration re-starts.


=============================================================

After a testing period of two days, with 10<t<10,000 Millis, not one missing pulse was ever detected. It was therefore concluded that the random alarm condition was generated by an internal glitch of the Micro. In short, the AUTO RESET is best removed, because, even if a real condition of one or two Sync pulses missing happens, it is better to carry on with data collection, rather than stop it, considering that, in a run, hundreds or thousands of samples may be collected. In any case missing sync pulses are detected by the System and can point to an unreliable and/or noisy transmission line.

The modified sketch, Ver. 7.4, is included. All tests were done with the 3,300 ft simulator line. System has been tested with RECYCLE TIME t between 10 and 10,000 Millis without a single transmission failure.
Attachments
sketch_MASTER_485_7_4.doc
(55 KiB) Downloaded 488 times
Last edited by Glovisol on Thu Feb 25, 2016 7:29 am, edited 1 time in total.

Glovisol
Advanced User
Advanced User
Posts: 0
Joined: Sat May 11, 2013 10:03 am
Location: San Marzano Oliveto, Asti, Italy

Re: REMOTING SIX SENSORS ON ONE TWISTED PAIR - PART 7

Post by Glovisol »

System operation in OOS condition demonstrated here
System operation in OOS condition demonstrated here
OPTIMUM COMM SYSTEM OPERATION FOR THE"OUT OF SYNC" CONDITION

FINAL IDE GUIDANCE: IDE 1.0.6 and ERW 1.0.5 work well with Windows XP, but there are problems when using Windows 7 and up. With W7 and up it is advisable to use IDE 1.6.7. In any case my advice is to stay with Windows XP and IDE 1.0.6: as soon as you go higher you experience the annoying problem of COMMs, which often get lost, making uploads very frustrating at times.

After a comprehensive series of tests, the Master sketch has been further simplified and refined. The difficult to reproduce "Out Of Sync" (OOS) condition has been achieved and the programmed behaviour of the System demonstrated. With the modified sketch Ver. 7_5 (uploaded below) the Master detects the OOS condition and stores the number of occourrences until the next sketch upload. This datum is very useful to assess the conditions and performance of the transmission line.

The Master screen shows the System working normally, then printing out a number of OOS conditions and finally getting back to a normal situation. To demonstrate this mode of operation, two different Syncs have been written in the Slave sketch and switched during a transmission run. To allow this, iteration time"t" in the Master has been set to 6000 Millis (medium long time)
and the characters //interdict shifted between Sync = 123 (true) and Sync = 112(false) in the Slave. The shift required also a quick re-load in the Slave with the System in operation, which caused a long delay: this is the reason why there are more "Out Of Syncs" than bargained for, because the Master continued receiving false Syncs while the Slave was re-loading.

To conclude, System operation is now excellent: even if the Sync is temporarily lost, data flow from Slave to Master is never interrupted, providing continous feed to the Data Logger.
Sketches 7_5 for Master and 7_2 for Slave provide the best and most reliable system operation.
Attachments
sketch_MASTER_485_7_5.doc
sketch Master, OPTIMISED VERSION
(55.5 KiB) Downloaded 478 times
Screen shows sketch modification FOR TESTING ONLY!!
Screen shows sketch modification FOR TESTING ONLY!!
Last edited by Glovisol on Sun Feb 28, 2016 7:51 am, edited 2 times in total.

Glovisol
Advanced User
Advanced User
Posts: 0
Joined: Sat May 11, 2013 10:03 am
Location: San Marzano Oliveto, Asti, Italy

Re: REMOTING SIX SENSORS ON ONE TWISTED PAIR - PART 7

Post by Glovisol »

ERRATA CORRIGE

In the previous posting, by error, I downloaded an early version of sketch_RS485_MASTER_7_5 which properly counts and stores the OOS, but does not print them out at the end. Version sketch_RS485_MASTER_7_5_b is complete because it prints the number of OOS as well, if they have happened at all. In case of physical transmission line interruption the System of course stops and operation automatically resumes as soon as line continuity is restored.

Apologies,

glovisol
Attachments
sketch_MASTER_485_7_5_b.doc
(56.5 KiB) Downloaded 485 times
Last edited by Glovisol on Wed Feb 24, 2016 2:36 pm, edited 1 time in total.

Glovisol
Advanced User
Advanced User
Posts: 0
Joined: Sat May 11, 2013 10:03 am
Location: San Marzano Oliveto, Asti, Italy

Re: REMOTING SIX SENSORS ON ONE TWISTED PAIR - PART 7

Post by Glovisol »

DETECTION, RECORDING & DISPLAY OF OUT OF SYNC CONDITIONS (OOS)

In order to verify System operation in worst case conditions, the wireline simulator was adjusted for a length of 3,800 ft to obtain OOS conditions caused by weak ongoing signals over the transmission line and a test was done with the following parameters:

Number of iterations k = 20,000
Recycle time t = 1000 Millis
Approximate Total Data Acquisition time: 5 hours.

The enclosed screen shows the Serial Monitor display at the expiration of the Data Acquisition time: there were 42 OOS, or approx. 1 OOS every 476 Iterations. This software and method provides an immediate evaluation of transmission medium quality and reliability.
Serial Monitor display at the end of 20,000 iterations
Serial Monitor display at the end of 20,000 iterations

Glovisol
Advanced User
Advanced User
Posts: 0
Joined: Sat May 11, 2013 10:03 am
Location: San Marzano Oliveto, Asti, Italy

Re: REMOTING SIX SENSORS ON ONE TWISTED PAIR - PART 7

Post by Glovisol »

ERRATA CORRIGE

The following sketches:

sketch_MASTER_485_7_2
sketch_MASTER_485_7_3
sketch_MASTER_485_7_4
sketch_MASTER_485_7_5

had the following small, but extremely significant mistake which nullified all instructions following the line below:

int powerPin = 4; /* Used for command of external device. Level HIGH in operation; level LOW in Stand-By.*/

The error being that the closing */ was missing. All sketches have now been corrected and re-uploaded. This difficulty is due to the transcription from the Arduino IDE to WORD. In Arduino such error would become immediately apparent. In WORD, being treated as text, only a keen eye can discover the errors.

Apologies,

glovisol

Glovisol
Advanced User
Advanced User
Posts: 0
Joined: Sat May 11, 2013 10:03 am
Location: San Marzano Oliveto, Asti, Italy

Re: REMOTING SIX SENSORS ON ONE TWISTED PAIR - PART 7

Post by Glovisol »

The RS485 COMM System, as explained in previous Parts 1 to 6, consists of a Master unit (LOCAL) and of a Slave unit (REMOTE). The Slave unit accepts up to 6 sensors, each with an output voltage range 0 - 2.5 V. The Slave reads the sensors with a 10 Bit resolution and through an RS485 Modem, transmits the encoded data at 8 Bit to the Master unit via a twisted pair wire line with a lenght up to 3300 to 4000 ft. The Master unit decodes the 6 channels with 8 Bit resolution and makes them available in analogue format to any Data Acquisition logger having an input voltage range of 0 to 2.5 V.

I have designed the System for the following hardware: Picotech Models USB DrDAQ and USB 1012, but any DA having the stated input range can be served by the System. Master unit and Slave unit consist of standard Arduino 1 Micros, RS485 Modems based on the MAX 485 Chip and ad hoc designed and built Arduino shields, as described in detail in my posts.

The only System limitation is the 8 Bit resolution, but as soon as tech documentation for the Arduino M0 Pro will become available, it will be possible to go up to 12 Bit resolution with some software modification.

In posts of Parts 10 & 11 you will find System specifications and details of the System working with said Data acquisition loggers.

Cheers,

Glovisol

Post Reply